Skip to content

Commit

Permalink
Fixed JS / PHP to correctly save new tags to the database
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Schläpfer committed Oct 12, 2023
1 parent 0241f17 commit a2ecdad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/Api/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

/**
Expand Down
13 changes: 9 additions & 4 deletions src/ProxmoxTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ 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) {
$model = $this->di['db']->dispense('service_proxmox_tag');
$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;
}

Expand All @@ -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;


Expand Down
2 changes: 0 additions & 2 deletions src/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
7 changes: 3 additions & 4 deletions src/html_admin/mod_serviceproxmox_storage.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit a2ecdad

Please sign in to comment.