mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Instance names can now be renamed on the WebUI (incl. inst 0)
Signed-off-by: Paulchen-Panther <Paulchen-Panter@protonmail.com>
This commit is contained in:
parent
a080c7151d
commit
3dee474356
@ -196,6 +196,10 @@ table label{margin:0}
|
||||
background-color:#d1322e;
|
||||
}
|
||||
|
||||
.modal-icon-edit{
|
||||
background-color:#3579b6;
|
||||
}
|
||||
|
||||
.overlay {
|
||||
background-image: url('/img/hyperion/hyperionwhitelogo.png');
|
||||
background-repeat: no-repeat;
|
||||
|
@ -35,6 +35,7 @@
|
||||
"general_btn_stop" : "Stop",
|
||||
"general_btn_continue": "Fortfahren",
|
||||
"general_btn_delete" : "Löschen",
|
||||
"general_btn_rename" : "Umbenennen",
|
||||
"general_btn_save": "Speichern",
|
||||
"general_btn_saverestart": "Speichern und neustarten",
|
||||
"general_btn_saveandreload": "Speichern und neu laden",
|
||||
@ -103,6 +104,15 @@
|
||||
"conf_general_impexp_l2": "Exportiere eine Konfiguration, indem du auf \"Exportieren\" klickst. Dein Browser startet einen Download.",
|
||||
"conf_general_impexp_impbtn": "Importieren",
|
||||
"conf_general_impexp_expbtn": "Exportieren",
|
||||
"conf_general_inst_title" : "LED Hardware Instanzverwaltung",
|
||||
"conf_general_inst_desc" : "Verwende mehrere LED Hardware gleichzeitig. Jede Instanz läuft unabhängig voneinander, wodurch unterschiedliche LED-Layouts und Kalibrierungseinstellungen möglich sind. Laufende Instanzen sind in der oberen Symbolleiste verfügbar.",
|
||||
"conf_general_inst_namehead" : "Instanzname",
|
||||
"conf_general_inst_actionhead" : "Aktionen",
|
||||
"conf_general_inst_name_title" : "Neuer Instanzname",
|
||||
"conf_general_createInst_btn" : "Instanz erstellen",
|
||||
"conf_general_inst_renreq_t" : "Gib in das untere Feld deinen neuen Instanznamen ein.",
|
||||
"conf_general_inst_delreq_h" : "LED Hardware Instanz löschen",
|
||||
"conf_general_inst_delreq_t" : "Bist du Dir sicher, das du die Instanz \"$1\" löschen möchtest? Alle Einstellungen zu dieser Instanz gehen verloren.",
|
||||
"conf_helptable_option": "Option",
|
||||
"conf_helptable_expl": "Erklärung",
|
||||
"conf_effect_path_intro": "Hier kannst du Ordner angeben, die beim Laden von Effekten berücksichtig werden sollen. Zusätzlich können Effekte anhand ihres Namens deaktiviert werden um sie aus Listen zu löschen.",
|
||||
|
@ -34,6 +34,7 @@
|
||||
"general_btn_stop" : "Stop",
|
||||
"general_btn_cancel" : "Cancel",
|
||||
"general_btn_delete" : "Delete",
|
||||
"general_btn_rename" : "Rename",
|
||||
"general_btn_continue" : "Continue",
|
||||
"general_btn_save" : "Save",
|
||||
"general_btn_saveandreload" : "Save and reload",
|
||||
@ -108,6 +109,7 @@
|
||||
"conf_general_inst_actionhead" : "Action",
|
||||
"conf_general_inst_name_title" : "New Instance name",
|
||||
"conf_general_createInst_btn" : "Create Instance",
|
||||
"conf_general_inst_renreq_t" : "Enter a new name for your instance in the field below.",
|
||||
"conf_general_inst_delreq_h" : "Delete LED Hardware instance",
|
||||
"conf_general_inst_delreq_t" : "Are you sure that you want to delete instance \"$1\"? All settings will be deleted too.",
|
||||
"conf_helptable_option" : "Option",
|
||||
|
@ -25,9 +25,21 @@ $(document).ready( function() {
|
||||
requestWriteConfig(conf_editor.getValue());
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Instance handling
|
||||
function handleInstanceRename(e)
|
||||
{
|
||||
var inst = e.currentTarget.id.split("_")[1];
|
||||
showInfoDialog('renInst', $.i18n('conf_general_inst_renreq_t'), getInstanceNameByIndex(inst));
|
||||
|
||||
$("#id_btn_ok").off().on('click', function(){
|
||||
requestInstanceRename(inst, $('#renInst_name').val())
|
||||
});
|
||||
|
||||
$('#renInst_name').off().on('input',function(e) {
|
||||
(e.currentTarget.value.length >= 5 && e.currentTarget.value != getInstanceNameByIndex(inst)) ? $('#id_btn_ok').attr('disabled', false) : $('#id_btn_ok').attr('disabled', true);
|
||||
});
|
||||
}
|
||||
|
||||
function handleInstanceStartStop(e)
|
||||
{
|
||||
var inst = e.currentTarget.id.split("_")[1];
|
||||
@ -38,7 +50,7 @@ $(document).ready( function() {
|
||||
function handleInstanceDelete(e)
|
||||
{
|
||||
var inst = e.currentTarget.id.split("_")[1];
|
||||
showInfoDialog('delplug',$.i18n('conf_general_inst_delreq_h'),$.i18n('conf_general_inst_delreq_t',getInstanceNameByIndex(inst)));
|
||||
showInfoDialog('delInst',$.i18n('conf_general_inst_delreq_h'),$.i18n('conf_general_inst_delreq_t',getInstanceNameByIndex(inst)));
|
||||
$("#id_btn_yes").off().on('click', function(){
|
||||
requestInstanceDelete(inst)
|
||||
});
|
||||
@ -51,29 +63,35 @@ $(document).ready( function() {
|
||||
for(var key in inst)
|
||||
{
|
||||
var startBtnColor = inst[key].running ? "success" : "danger";
|
||||
var startBtnIcon = inst[key].running ? "stop" : "play";
|
||||
var startBtnText = inst[key].running ? $.i18n('general_btn_stop') : $.i18n('general_btn_start');
|
||||
var startBtn = "-"
|
||||
var delBtn = "-";
|
||||
var renameBtn = '<button id="instren_'+inst[key].instance+'" type="button" class="btn btn-primary"><i class="fa fa-pencil"> '+$.i18n('general_btn_rename')+'</i></button>';
|
||||
var startBtn = ""
|
||||
var delBtn = "";
|
||||
if(inst[key].instance > 0)
|
||||
{
|
||||
delBtn = '<button id="instdel_'+inst[key].instance+'" type="button" class="btn btn-danger">'+$.i18n('general_btn_delete')+'</button>';
|
||||
startBtn = '<button id="inst_'+inst[key].instance+'" type="button" class="btn btn-'+startBtnColor+'">'+startBtnText+'</button>';
|
||||
delBtn = '<button id="instdel_'+inst[key].instance+'" type="button" class="btn btn-warning"><i class="fa fa-remove"> '+$.i18n('general_btn_delete')+'</i></button>';
|
||||
startBtn = '<button id="inst_'+inst[key].instance+'" type="button" class="btn btn-'+startBtnColor+'"><i class="fa fa-'+startBtnIcon+'"> '+startBtnText+'</i></button>';
|
||||
}
|
||||
$('.itbody').append(createTableRow([inst[key].friendly_name, startBtn, delBtn], false, true));
|
||||
$('.itbody').append(createTableRow([inst[key].friendly_name, renameBtn, startBtn, delBtn], false, true));
|
||||
$('#instren_'+inst[key].instance).off().on('click', handleInstanceRename);
|
||||
$('#inst_'+inst[key].instance).off().on('click', handleInstanceStartStop);
|
||||
$('#instdel_'+inst[key].instance).off().on('click', handleInstanceDelete);
|
||||
}
|
||||
}
|
||||
|
||||
createTable('ithead', 'itbody', 'itable');
|
||||
$('.ithead').html(createTableRow([$.i18n('conf_general_inst_namehead'), $.i18n('conf_general_inst_actionhead'), $.i18n('general_btn_delete')], true, true));
|
||||
$('.ithead').html(createTableRow([$.i18n('conf_general_inst_namehead'), "", $.i18n('conf_general_inst_actionhead'), ""], true, true));
|
||||
buildInstanceList();
|
||||
|
||||
$('#inst_name').off().on('input',function(e) {
|
||||
(e.currentTarget.value.length >= 5) ? $('#btn_create_inst').attr('disabled', false) : $('#btn_create_inst').attr('disabled', true);
|
||||
});
|
||||
|
||||
$('#btn_create_inst').off().on('click',function(e) {
|
||||
requestInstanceCreate($('#inst_name').val());
|
||||
$('#inst_name').val("");
|
||||
$('#btn_create_inst').attr('disabled', true)
|
||||
});
|
||||
|
||||
$(hyperion).off("instance-updated").on("instance-updated", function(event) {
|
||||
|
@ -190,6 +190,11 @@ function requestTokenDelete(id)
|
||||
sendToHyperion("authorize","deleteToken",'"id":"'+id+'"');
|
||||
}
|
||||
|
||||
function requestInstanceRename(inst, name)
|
||||
{
|
||||
sendToHyperion("instance", "saveName",'"instance": '+inst+', "name": "'+name+'"');
|
||||
}
|
||||
|
||||
function requestInstanceStartStop(inst, start)
|
||||
{
|
||||
if(start)
|
||||
|
@ -214,53 +214,69 @@ function setClassByBool(obj,enable,class1,class2)
|
||||
|
||||
function showInfoDialog(type,header,message)
|
||||
{
|
||||
if (type=="success"){
|
||||
if (type=="success")
|
||||
{
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-check modal-icon-check">');
|
||||
if(header == "")
|
||||
$('#id_body').append('<h4 style="font-weight:bold;text-transform:uppercase;">'+$.i18n('infoDialog_general_success_title')+'</h4>');
|
||||
$('#id_footer').html('<button type="button" class="btn btn-success" data-dismiss="modal">'+$.i18n('general_btn_ok')+'</button>');
|
||||
}
|
||||
else if (type=="warning"){
|
||||
else if (type=="warning")
|
||||
{
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-warning modal-icon-warning">');
|
||||
if(header == "")
|
||||
$('#id_body').append('<h4 style="font-weight:bold;text-transform:uppercase;">'+$.i18n('infoDialog_general_warning_title')+'</h4>');
|
||||
$('#id_footer').html('<button type="button" class="btn btn-warning" data-dismiss="modal">'+$.i18n('general_btn_ok')+'</button>');
|
||||
}
|
||||
else if (type=="error"){
|
||||
else if (type=="error")
|
||||
{
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-warning modal-icon-error">');
|
||||
if(header == "")
|
||||
$('#id_body').append('<h4 style="font-weight:bold;text-transform:uppercase;">'+$.i18n('infoDialog_general_error_title')+'</h4>');
|
||||
$('#id_footer').html('<button type="button" class="btn btn-danger" data-dismiss="modal">'+$.i18n('general_btn_ok')+'</button>');
|
||||
}
|
||||
else if (type == "select"){
|
||||
else if (type == "select")
|
||||
{
|
||||
$('#id_body').html('<img style="margin-bottom:20px" src="img/hyperion/hyperionlogo.png" alt="Redefine ambient light!">');
|
||||
$('#id_footer').html('<button type="button" id="id_btn_saveset" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-fw fa-save"></i>'+$.i18n('general_btn_saveandreload')+'</button>');
|
||||
$('#id_footer').append('<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>'+$.i18n('general_btn_cancel')+'</button>');
|
||||
}
|
||||
else if (type == "iswitch"){
|
||||
else if (type == "iswitch")
|
||||
{
|
||||
$('#id_body').html('<img style="margin-bottom:20px" src="img/hyperion/hyperionlogo.png" alt="Redefine ambient light!">');
|
||||
$('#id_footer').html('<button type="button" id="id_btn_saveset" class="btn btn-primary" data-dismiss="modal"><i class="fa fa-fw fa-exchange"></i>'+$.i18n('general_btn_iswitch')+'</button>');
|
||||
$('#id_footer').append('<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>'+$.i18n('general_btn_cancel')+'</button>');
|
||||
}
|
||||
else if (type == "uilock"){
|
||||
else if (type == "uilock")
|
||||
{
|
||||
$('#id_body').html('<img src="img/hyperion/hyperionlogo.png" alt="Redefine ambient light!">');
|
||||
$('#id_footer').html('<b>'+$.i18n('InfoDialog_nowrite_foottext')+'</b>');
|
||||
}
|
||||
else if (type == "import"){
|
||||
else if (type == "import")
|
||||
{
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-warning modal-icon-warning">');
|
||||
$('#id_footer').html('<button type="button" id="id_btn_import" class="btn btn-warning" data-dismiss="modal"><i class="fa fa-fw fa-save"></i>'+$.i18n('general_btn_saverestart')+'</button>');
|
||||
$('#id_footer').append('<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>'+$.i18n('general_btn_cancel')+'</button>');
|
||||
}
|
||||
else if (type == "delplug"){
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-warning modal-icon-warning">');
|
||||
else if (type == "delInst")
|
||||
{
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-remove modal-icon-warning">');
|
||||
$('#id_footer').html('<button type="button" id="id_btn_yes" class="btn btn-warning" data-dismiss="modal"><i class="fa fa-fw fa-trash"></i>'+$.i18n('general_btn_yes')+'</button>');
|
||||
$('#id_footer').append('<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>'+$.i18n('general_btn_cancel')+'</button>');
|
||||
}
|
||||
else if (type == "renInst")
|
||||
{
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-pencil modal-icon-edit"><br>');
|
||||
$('#id_body').append('<h4>'+header+'</h4>');
|
||||
$('#id_body').append('<input class="form-control" id="renInst_name" type="text" value="'+message+'">');
|
||||
$('#id_footer').html('<button type="button" id="id_btn_ok" class="btn btn-success" data-dismiss="modal" disabled><i class="fa fa-fw fa-save"></i>'+$.i18n('general_btn_ok')+'</button>');
|
||||
$('#id_footer').append('<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>'+$.i18n('general_btn_cancel')+'</button>');
|
||||
}
|
||||
else if (type == "checklist")
|
||||
{
|
||||
$('#id_body').html('<img style="margin-bottom:20px" src="img/hyperion/hyperionlogo.png" alt="Redefine ambient light!">');
|
||||
$('#id_body').append('<h4 style="font-weight:bold;text-transform:uppercase;">'+$.i18n('infoDialog_checklist_title')+'</h4>');
|
||||
$('#id_body').append(message);
|
||||
$('#id_body').append(header);
|
||||
$('#id_footer').html('<button type="button" class="btn btn-primary" data-dismiss="modal">'+$.i18n('general_btn_ok')+'</button>');
|
||||
}
|
||||
else if (type == "newToken")
|
||||
@ -275,8 +291,11 @@ function showInfoDialog(type,header,message)
|
||||
$('#id_footer').append('<button type="button" class="btn btn-danger" data-dismiss="modal" id="tok_deny_acc">'+$.i18n('general_btn_denyAccess')+'</button>');
|
||||
}
|
||||
|
||||
if(type != "renInst")
|
||||
{
|
||||
$('#id_body').append('<h4 style="font-weight:bold;text-transform:uppercase;">'+header+'</h4>');
|
||||
$('#id_body').append(message);
|
||||
}
|
||||
|
||||
if(type == "select" || type == "iswitch")
|
||||
$('#id_body').append('<select id="id_select" class="form-control" style="margin-top:10px;width:auto;"></select>');
|
||||
|
@ -80,10 +80,10 @@ typedef struct {
|
||||
#define STATIC_ASSERT(condition, message) \
|
||||
_Static_assert(condition, message)
|
||||
#else
|
||||
#define STATIC_ASSERT(condition, message) // FIXME
|
||||
#define STATIC_ASSERT(condition, message)
|
||||
#endif
|
||||
#else
|
||||
#define STATIC_ASSERT(condition, message) // FIXME
|
||||
#define STATIC_ASSERT(condition, message)
|
||||
#endif
|
||||
|
||||
STATIC_ASSERT(sizeof(PacketHeader) == 8, "PacketHeader has invalid size");
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
setTable("instances");
|
||||
createTable(QStringList()<<"instance INTEGER"<<"friendly_name TEXT"<<"enabled INTEGER DEFAULT 0"<<"last_use TEXT");
|
||||
|
||||
// create the first Hyperion instance index 0
|
||||
// start/create the first Hyperion instance index 0
|
||||
createInstance();
|
||||
|
||||
};
|
||||
@ -92,6 +92,12 @@ public:
|
||||
/// @return True on success else false (instance not found)
|
||||
///
|
||||
inline bool saveName(const quint8& inst, const QString& name)
|
||||
{
|
||||
VectorPair fcond;
|
||||
fcond.append(CPair("friendly_name",name));
|
||||
|
||||
// check duplicate
|
||||
if(!recordExists(fcond))
|
||||
{
|
||||
if(instanceExist(inst))
|
||||
{
|
||||
@ -102,6 +108,7 @@ public:
|
||||
|
||||
return updateRecord(cond, data);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -206,6 +213,10 @@ private:
|
||||
/// @brief Create first Hyperion instance entry, if index 0 is not found.
|
||||
///
|
||||
inline void createInstance()
|
||||
{
|
||||
if(instanceExist(0))
|
||||
setEnable(0, true);
|
||||
else
|
||||
{
|
||||
QVariantMap data;
|
||||
data["friendly_name"] = "First LED Hardware instance";
|
||||
@ -216,4 +227,5 @@ private:
|
||||
else
|
||||
throw std::runtime_error("Failed to create Hyperion root instance in db! This should never be the case...");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1297,10 +1297,17 @@ void JsonAPI::handleInstanceCommand(const QJsonObject & message, const QString &
|
||||
}
|
||||
|
||||
if(subc == "saveName")
|
||||
{
|
||||
if(_userAuthorized)
|
||||
{
|
||||
// silent fail
|
||||
_instanceManager->saveName(inst,name);
|
||||
if(_instanceManager->saveName(inst,name))
|
||||
sendSuccessReply(command+"-"+subc, tan);
|
||||
else
|
||||
sendErrorReply(QString("The instance name '%1' is already in use").arg(name), command+"-"+subc, tan);
|
||||
}
|
||||
else
|
||||
sendErrorReply("No Authorization",command+"-"+subc, tan);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user