diff --git a/src/Api/Admin.php b/src/Api/Admin.php index e94ccfc..2809a2d 100644 --- a/src/Api/Admin.php +++ b/src/Api/Admin.php @@ -1030,8 +1030,9 @@ public function service_get_tags($data) public function service_add_tag($data) { - $output = $this->getService()->save_tag($data); - return $output; + $added_tag = $this->getService()->save_tag($data); + return $added_tag; + } /** diff --git a/src/ProxmoxTemplates.php b/src/ProxmoxTemplates.php index 475d2d2..b1b7141 100644 --- a/src/ProxmoxTemplates.php +++ b/src/ProxmoxTemplates.php @@ -90,7 +90,6 @@ public function save_tag($data) // $data contains 'type' and 'tag' // search if the tag already exists - error_log('saving tag: ' . print_r($data)); $tag_exists = $this->di['db']->findOne('service_proxmox_tag', 'type=:type AND name=:name', array(':type' => $data['type'], ':name' => $data['tag'])); // and if not create it if (!$tag_exists) { @@ -98,9 +97,10 @@ public function save_tag($data) $model->type = $data['type']; $model->name = $data['tag']; $this->di['db']->store($model); + // return the tag that was just created. return $model; } - // return the tag that was just created + // return the tag that already exists return $tag_exists; } @@ -114,8 +114,13 @@ public function get_tags_by_storage($data) $storage = $this->di['db']->findOne('service_proxmox_storage', 'id=:id', array(':id' => $data['storageid'])); // return tags (saved in json format in $storage->storageclass) (F.ex ["ssd","hdd"]) // as well as the service_proxmox_tag id for each tag so there is a key value pair with id and name. - - $tags = json_decode($storage->storageclass, true); + // check if $storage->storageclass is not empty + if (empty($storage->storageclass)) { + // if empty return empty array + $tags = ""; + } else { + $tags = json_decode($storage->storageclass, true); + } return $tags; diff --git a/src/Service.php b/src/Service.php index bb5bbed..bf598ad 100644 --- a/src/Service.php +++ b/src/Service.php @@ -394,7 +394,6 @@ public function pmxdbbackup($data) 'service_proxmox_server', 'service_proxmox', 'service_proxmox_users', - 'service_proxmox_storageclass', 'service_proxmox_storage', 'service_proxmox_lxc_appliance', 'service_proxmox_vm_config_template', @@ -453,7 +452,6 @@ public function pmxdbbackup($data) 'service_proxmox_server', 'service_proxmox', 'service_proxmox_users', - 'service_proxmox_storageclass', 'service_proxmox_storage', 'service_proxmox_lxc_appliance', 'service_proxmox_vm_config_template', diff --git a/src/html_admin/mod_serviceproxmox_storage.html.twig b/src/html_admin/mod_serviceproxmox_storage.html.twig index 23366a9..d40c022 100644 --- a/src/html_admin/mod_serviceproxmox_storage.html.twig +++ b/src/html_admin/mod_serviceproxmox_storage.html.twig @@ -177,12 +177,11 @@ function saveTagToDatabase(tag, callback) { var Type = "storage"; - API.admin.post("serviceproxmox/service_add_tag", { type: Type, tag: tag }, function (response) { - console.log('Tag saved successfully:', response.tag); + API.admin.post("serviceproxmox/service_add_tag", { type: Type, tag: tag }, (response) => { if (callback) { - callback(response.tag); + callback(response); } - }, function (error) { + }, (error) => { console.log('Error occurred while saving tag: ' + error); }, false); }