From cda2d121c0a6069c96d59e539a589781e19c2fa7 Mon Sep 17 00:00:00 2001 From: london89 Date: Thu, 2 Nov 2023 10:48:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D1=80=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=92=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B0=202=20=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Возможность разделения кнопки Включения на 2 разные Вкл/Выкл --- templates/yandexhome/devices_edit.html | 107 +++++++++++++++++++------ 1 file changed, 83 insertions(+), 24 deletions(-) diff --git a/templates/yandexhome/devices_edit.html b/templates/yandexhome/devices_edit.html index 1ce8bb6..101bffd 100644 --- a/templates/yandexhome/devices_edit.html +++ b/templates/yandexhome/devices_edit.html @@ -190,7 +190,7 @@ var traits = tryParseJSON(traits_json); if (traits !== false) { traits_list = traits; - for (key in traits_list) { + for (key in traits_list) { if (traits_list.hasOwnProperty(key)) { // Делаем неактивными пункты в списке выбора метрик. $('#select_trait').find('[value='+traits_list[key].type+']').prop('disabled', true); @@ -220,6 +220,12 @@ instance_list[linked_type].parameters.range['precision'] = precision_value; } } + if (instance_list[linked_type].capability === 'on_off') { + if (typeof(capabilities[key].parameters['split']) != 'undefined' && capabilities[key].parameters['split'] !== null) { + split = capabilities[key].parameters['split']; + instance_list[linked_type].parameters['split'] = split; + } + } } } saveInstanceList(); @@ -237,25 +243,50 @@ } //Доделано SmoKE xD, я сам нихера не понимаю, что тут написано, но работает! -function addReportable(prop_name) { - traits = tryParseJSON($('#traits_json').val()); - - //Чекаем есть или нет в масссиве - //if(typeof traits[prop_name]['reportable'] === 'undefined') { - if(!traits[prop_name]['reportable']) { - traits[prop_name]['reportable'] = true; - //Красим кнопку - $('.reportableBtn#'+prop_name+'>i').attr('style', 'color:green;'); - } else { - traits[prop_name]['reportable'] = false; - //Красим кнопку - $('.reportableBtn#'+prop_name+'>i').attr('style', 'color: #959595;'); - } - //} - - - //Запишем обратно в поле - $('#traits_json').val(JSON.stringify(traits)); +//London тоже руку приложил, тож нихера не понял + +function addReportable(prop_name,split = false) { + traits = tryParseJSON($('#traits_json').val()); + if (prop_name == 'on') { + instance = tryParseJSON($('#instance_json').val()); + } + if (!split) { + if(!traits[prop_name]['reportable']) { + traits[prop_name]['reportable'] = true; + //Красим кнопку + $('.reportableBtn#'+prop_name+'>i').attr('style', 'color:green;'); + if (prop_name == 'on') { + if(instance[prop_name]['parameters']['split']) { + instance[prop_name]['parameters']['split'] = false; + $('.splitBtn#'+prop_name+'>i').attr('style', 'color: #959595;'); + } + } + } else { + traits[prop_name]['reportable'] = false; + //Красим кнопку + $('.reportableBtn#'+prop_name+'>i').attr('style', 'color: #959595;'); + } + } else { + if(!instance[prop_name]['parameters']['split']) { + instance[prop_name]['parameters']['split'] = true; + //Красим кнопку + $('.splitBtn#'+prop_name+'>i').attr('style', 'color:green;'); + if (traits[prop_name]['reportable']) { + traits[prop_name]['reportable'] = false; + $('.reportableBtn#'+prop_name+'>i').attr('style', 'color: #959595;'); + } + } else { + instance[prop_name]['parameters']['split'] = false; + //Красим кнопку + $('.splitBtn#'+prop_name+'>i').attr('style', 'color: #959595;'); + } + + } + //Запишем обратно в поле + $('#traits_json').val(JSON.stringify(traits)); + if (prop_name == 'on') { + $('#instance_json').val(JSON.stringify(instance)); + } } function renderTraitsTable() { @@ -268,8 +299,25 @@ let linked_property = traits_list[key].linked_property; let linked_description = traits_list[key].description; let reportable = traits_list[key].reportable; + let split = false; + if (key == 'on') { + let capabilities = dev_config.capabilities; + if (capabilities.length > 0) { + for (key2 in capabilities) { + if (typeof(capabilities[key2].parameters.instance) != 'undefined' && capabilities[key2].parameters.instance !== null) { + let linked_type = capabilities[key2].parameters.instance; + if (instance_list[linked_type].capability === 'on_off') { + if (typeof(capabilities[key2].parameters['split']) != 'undefined' && capabilities[key2].parameters['split'] !== null) { + split = capabilities[key2].parameters['split']; + instance_list[linked_type].parameters['split'] = split; + } + } + } + } + } + } // Формируем строки в таблице метрик. - addTraitRow(linked_type, linked_description, linked_object, linked_property, reportable); + addTraitRow(linked_type, linked_description, linked_object, linked_property, reportable, split); objects_list[linked_object] = ''; } } @@ -322,7 +370,7 @@ } } -function addTraitRow(linked_type, linked_description, linked_object, linked_property, reportable = false) { +function addTraitRow(linked_type, linked_description, linked_object, linked_property, reportable = false, split = false) { // Строка с наименование метрики. let row = $(''); $('#traits_table').append(row); @@ -354,10 +402,21 @@ renderPropertySelectbox('linked_property' + linked_type, linked_object, linked_property); - var reportable_color = (reportable) ? "color: green" : 'color: #959595;'; + var reportable_color = (reportable) ? "color: green" : 'color: #959595;'; + + let split_options = ''; + if (instance_list[linked_type].capability === 'on_off') { +//console.log(split); + if (typeof(instance_list[linked_type].parameters) != 'undefined' && instance_list[linked_type].parameters !== null) { + var split_color = (split) ? "color: green" : 'color: #959595;'; + split_options = + ``; + } + } + // Кнопка удаления метрики. - row.append($(`[#if SKILL_ACCESS_TOKEN != ''#][#endif#]`)); + row.append($(`[#if SKILL_ACCESS_TOKEN != ''#][#endif#]${split_options}`)); } function addTrait() {