From: Marcin Haba Date: Wed, 21 Jun 2023 06:32:41 +0000 (+0200) Subject: baculum: Add sorting by endtime and add endtime property to objects overview endpoint X-Git-Tag: Release-13.0.4~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20b4d2a73bb2a5060c65a06a6eb849548ea31868;p=thirdparty%2Fbacula.git baculum: Add sorting by endtime and add endtime property to objects overview endpoint --- diff --git a/gui/baculum/protected/API/Modules/ObjectManager.php b/gui/baculum/protected/API/Modules/ObjectManager.php index f035a452c..fea93c81a 100644 --- a/gui/baculum/protected/API/Modules/ObjectManager.php +++ b/gui/baculum/protected/API/Modules/ObjectManager.php @@ -34,6 +34,15 @@ use PDO; */ class ObjectManager extends APIModule { + + /** + * Allowed order columns for object overview. + */ + public static $overview_order_columns = [ + 'object' => ['objectname', 'endtime'], + 'general' => ['client', 'jobstatus', 'endtime'] + ]; + /** * Object result in job and object endpoint can be displayed in on of the two views: * - basic - display only base job and object properties @@ -167,9 +176,10 @@ LEFT JOIN Client USING (ClientId) ' $limit = is_int($limit_val) && $limit_val > 0 ? ' LIMIT ' . $limit_val : ''; $offset = is_int($offset_val) && $offset_val > 0 ? ' OFFSET ' . $offset_val : ''; + $sort_col_i = strtolower($sort_col); $db_params = $this->getModule('api_config')->getConfig('db'); if ($db_params['type'] === Database::PGSQL_TYPE) { - $sort_col = strtolower($sort_col); + $sort_col = $sort_col_i; } // default sorting for objects @@ -186,6 +196,10 @@ LEFT JOIN Client USING (ClientId) ' if (empty($sort_col)) { $sort_col = 'JobTDate'; + } elseif (in_array($sort_col_i, ObjectManager::$overview_order_columns['object'])) { + $obj_order .= sprintf(',%s %s', $sort_col, $sort_order); + } elseif (in_array($sort_col_i, ObjectManager::$overview_order_columns['general'])) { + $file_order .= sprintf(',%s %s', $sort_col, $sort_order); } $order = sprintf( 'ORDER BY %s %s ', @@ -233,6 +247,7 @@ LEFT JOIN Client USING (ClientId) ' Object.JobId AS jobid, JobTDate AS jobtdate, Job.StartTime AS starttime, + Job.EndTime AS endtime, ObjectCategory AS objectcategory, ObjectStatus AS objectstatus, ObjectSource AS objectsource, @@ -258,6 +273,7 @@ LEFT JOIN Client USING (ClientId) ' Job.Level AS level, JobTDate AS jobtdate, StartTime AS starttime, + EndTime AS endtime, JobStatus AS jobstatus, JobBytes AS jobbytes, JobFiles AS jobfiles @@ -293,6 +309,7 @@ LEFT JOIN Client USING (ClientId) ' Object.JobId AS jobid, JobTDate AS jobtdate, StartTime AS starttime, + EndTime AS endtime, ObjectCategory AS objectcategory, ObjectStatus AS objectstatus, ObjectSource AS objectsource, @@ -317,6 +334,7 @@ LEFT JOIN Client USING (ClientId) ' jobid, AAA.jobtdate, starttime, + endtime, objectcategory, objectstatus, objectsource, @@ -347,6 +365,7 @@ LEFT JOIN Client USING (ClientId) ' Job.Level AS level, JobTDate AS jobtdate, StartTime AS starttime, + EndTime AS endtime, JobStatus AS jobstatus, JobBytes AS jobbytes, JobFiles AS jobfiles @@ -370,6 +389,7 @@ LEFT JOIN Client USING (ClientId) ' level, AAA.jobtdate, starttime, + endtime, jobstatus, jobbytes, jobfiles diff --git a/gui/baculum/protected/API/Pages/API/ObjectsOverview.php b/gui/baculum/protected/API/Pages/API/ObjectsOverview.php index 4ec51f34e..5bb32df13 100644 --- a/gui/baculum/protected/API/Pages/API/ObjectsOverview.php +++ b/gui/baculum/protected/API/Pages/API/ObjectsOverview.php @@ -33,15 +33,6 @@ use Baculum\API\Modules\ObjectManager; */ class ObjectsOverview extends BaculumAPIServer { - /** - * Allowed order columns for object overview. - */ - private $overview_order_columns = [ - 'objectname', - 'client', - 'jobstatus' - ]; - public function get() { $misc = $this->getModule('misc'); $limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0; @@ -91,7 +82,7 @@ class ObjectsOverview extends BaculumAPIServer { if (!empty($order_by)) { $order_by_lc = strtolower($order_by); - if (!in_array($order_by_lc, $this->overview_order_columns)) { + if (!in_array($order_by_lc, ObjectManager::$overview_order_columns['object']) && !in_array($order_by_lc, ObjectManager::$overview_order_columns['general'])) { $this->output = ObjectError::MSG_ERROR_INVALID_PROPERTY; $this->error = ObjectError::ERROR_INVALID_PROPERTY; return; diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index cff09ffee..3bdbee747 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -8642,6 +8642,10 @@ "type": "string", "description": "Job start time" }, + "endtime": { + "type": "string", + "description": "Job end time" + }, "objectcategory": { "type": "string", "description": "Object category" @@ -8715,6 +8719,10 @@ "type": "string", "description": "Job start time" }, + "endtime": { + "type": "string", + "description": "Job end time" + }, "jobstatus": { "type": "string", "description": "Job status" @@ -8830,7 +8838,7 @@ "name": "order_by", "in": "query", "required": false, - "description": "Sort by selected object property (default jobtdate). There can be one from the following properties: objectname, client, jobstatus.", + "description": "Sort by selected object property (default jobtdate). There can be one from the following properties: objectname, client, jobstatus, endtime.", "schema": { "type": "string" }