From f8377fec15712d2fb4d06fee733b0aaf6118497d Mon Sep 17 00:00:00 2001 From: Ivan Maslov Date: Sat, 2 Nov 2019 19:40:57 +0300 Subject: [PATCH] #Orchestrator+mGlobal.Modal.TableFilter.Show+mGlobal.Modal.ListFilter.Show Signed-off-by: Ivan Maslov --- Orchestrator/.idea/Orchestrator.iml | 2 +- Orchestrator/.idea/misc.xml | 4 + Orchestrator/Web/Index.xhtml | 245 +++++++++++++++++++++++++++- 3 files changed, 246 insertions(+), 5 deletions(-) create mode 100644 Orchestrator/.idea/misc.xml diff --git a/Orchestrator/.idea/Orchestrator.iml b/Orchestrator/.idea/Orchestrator.iml index 67116063..cf5d37ff 100644 --- a/Orchestrator/.idea/Orchestrator.iml +++ b/Orchestrator/.idea/Orchestrator.iml @@ -2,7 +2,7 @@ - + diff --git a/Orchestrator/.idea/misc.xml b/Orchestrator/.idea/misc.xml new file mode 100644 index 00000000..30b95ec7 --- /dev/null +++ b/Orchestrator/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Orchestrator/Web/Index.xhtml b/Orchestrator/Web/Index.xhtml index b9332158..982507d4 100644 --- a/Orchestrator/Web/Index.xhtml +++ b/Orchestrator/Web/Index.xhtml @@ -33,12 +33,47 @@ $('.main.menu .ui.dropdown').dropdown({ on: 'hover' }); + + function clone(obj) { + var copy; + + // Handle the 3 simple types, and null or undefined + if (null == obj || "object" != typeof obj) return obj; + + // Handle Date + if (obj instanceof Date) { + copy = new Date(); + copy.setTime(obj.getTime()); + return copy; + } + + // Handle Array + if (obj instanceof Array) { + copy = []; + for (var i = 0, len = obj.length; i < len; i++) { + copy[i] = clone(obj[i]); + } + return copy; + } + + // Handle Object + if (obj instanceof Object) { + copy = {}; + for (var attr in obj) { + if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]); + } + return copy; + } + + throw new Error("Unable to copy obj! Its type isn't supported."); + } + String.prototype.replaceAll = function(search, replace){ return this.split(search).join(replace); } mGlobal.GeneralGenerateHTMLCodeHandlebars=function(inInnerTemplateSelector,inData) { lHTMLTemplate=$(inInnerTemplateSelector)[0].innerHTML - console.log(lHTMLTemplate) + //console.log(lHTMLTemplate) //Компиляция var template = Handlebars.compile(lHTMLTemplate); //Вставка данных @@ -102,7 +137,7 @@ { var lResponseJSON=JSON.parse(lData) ///Отправить запрос на формирование таблицы - lHTMLCode=console.log("CMDRun result: "+lResponseJSON[0].result) + //lHTMLCode=console.log("CMDRun result: "+lResponseJSON[0].result) }, dataType: "text" }); @@ -132,7 +167,7 @@ { var lResponseJSON=JSON.parse(lData) ///Отправить запрос на формирование таблицы - lHTMLCode=console.log("CMDRun result: "+lResponseJSON[0].result) + //lHTMLCode=console.log("CMDRun result: "+lResponseJSON[0].result) }, dataType: "text" }); @@ -267,7 +302,7 @@ success: function(lData,l2,l3) { - console.log(lData) + //console.log(lData) }, dataType: "text" }); @@ -335,6 +370,152 @@ dataType: "text" }); } + + ///////////////// + ///Modal + /////////////////// + mGlobal.Modal={} + ///////////////////////////////////////////////////// + mGlobal.Modal.TableFilter={} + mGlobal.Modal.TableFilter.Show=function(inJSON) { + //{ + // "Title":"", + // "Headers":["Header1","Header2"], + // "Rows": [["Cell1","Cell2"],["Cell2-1","Cell2-2"]], + // "FilterOnKeyUp": "" //Fill here in function + //} + //Set js handler to Search field + inJSON["FilterOnKeyUp"]="mGlobal.Modal.TableFilter.FilterUpdate(this.value);" + ///Set value + mGlobal.Modal.TableFilter.mDataJSON = inJSON + //Render HTML + lHTMLCode=mGlobal.GeneralGenerateHTMLCodeHandlebars(".openrpa-handlebar-template-table-filter",inJSON); + ///Установить HTML код + $('.ui.modal.basic .content').html(lHTMLCode); + $('.ui.modal.basic').modal('show'); + } + //Service function + mGlobal.Modal.TableFilter.FilterUpdate=function(inFilterValue) { + //Get JSON, apply filter, clone data + lDataJSON = clone(mGlobal.Modal.TableFilter.mDataJSON) + delete lDataJSON["Rows"] + lDataJSON["Rows"]=[] + //Filter code [any occurence in the row is ok for push! ] + mGlobal.Modal.TableFilter.mDataJSON["Rows"].forEach( + function(inElement) { + lFlagElementAppend = false + inElement.forEach( + function(inElement2) { + if (String(inElement2).includes(inFilterValue)) { + lFlagElementAppend = true + } + } + ) + if (lFlagElementAppend) { + lDataJSON["Rows"].push(inElement) + } + } + ) + //Clear Filter Title property (fixed in html) + delete lDataJSON["FilterOnKeyUp"] + delete lDataJSON["Title"] + //Search the table element [replace only table html] + lElement = $('.ui.modals.active .content table.table')[0] + lElementParentElement = lElement.parentNode + lElement.parentNode.removeChild(lElement); + //Render HTML + lHTMLCode=mGlobal.GeneralGenerateHTMLCodeHandlebars(".openrpa-handlebar-template-table-filter",lDataJSON); + ///Установить HTML код + lElementParentElement.insertAdjacentHTML("beforeend",lHTMLCode); + } + ///////////////////////////////////////////////////////////// + mGlobal.Modal.ListFilter={} + mGlobal.Modal.ListFilter.Show=function(inJSON) { + //{ + // "Title":"", + // "List":[{"Header":"","Description":""}], + // "FilterOnKeyUp": "" //Fill here in function + //} + //Set js handler to Search field + inJSON["FilterOnKeyUp"]="mGlobal.Modal.ListFilter.FilterUpdate(this.value);" + ///Set value + mGlobal.Modal.ListFilter.mDataJSON = inJSON + //Render HTML + lHTMLCode=mGlobal.GeneralGenerateHTMLCodeHandlebars(".openrpa-handlebar-template-list-filter",inJSON); + ///Установить HTML код + $('.ui.modal.basic .content').html(lHTMLCode); + $('.ui.modal.basic').modal('show'); + } + //Service function + mGlobal.Modal.ListFilter.FilterUpdate=function(inFilterValue) { + //Get JSON, apply filter, clone data + lDataJSON = clone(mGlobal.Modal.ListFilter.mDataJSON) + delete lDataJSON["List"] + lDataJSON["List"]=[] + //Filter code [any occurence in the row is ok for push! ] + mGlobal.Modal.ListFilter.mDataJSON["List"].forEach( + function(inElement) { + lFlagElementAppend = false + if (String(inElement["Header"]).includes(inFilterValue)) { + lFlagElementAppend = true + } + if (String(inElement["Description"]).includes(inFilterValue)) { + lFlagElementAppend = true + } + if (lFlagElementAppend) { + lDataJSON["List"].push(inElement) + } + } + ) + //Clear Filter Title property (fixed in html) + delete lDataJSON["FilterOnKeyUp"] + delete lDataJSON["Title"] + //Search the table element [replace only table html] + lElement = $('.ui.modals.active .content div.ui.inverted.segment')[0] + lElementParentElement = lElement.parentNode + lElement.parentNode.removeChild(lElement); + //Render HTML + lHTMLCode=mGlobal.GeneralGenerateHTMLCodeHandlebars(".openrpa-handlebar-template-list-filter",lDataJSON); + ///Установить HTML код + lElementParentElement.insertAdjacentHTML("beforeend",lHTMLCode); + } + ///Test + lTestData = { + "Title":"Test", + "Columns":["Дата/Время","Статус","Клиент","Файл"], + "Rows":[ + ["2019.10.31 13:21","Успешно", "ООО БалтКам", "test.xml"], + ["2019.10.31 13:21","Успешно", "ООО Гренодер", "test.xml"], + ["2019.10.31 13:21","Успешно", "ООО БалтКам", "test.xml"], + ["2019.10.31 13:21","Успешно", "ООО Гренодер", "test.xml"], + ["2019.10.31 13:21","Отказ", "ООО Сударь", "test.xml"], + ["2019.10.31 13:21","Успешно", "ООО БалтКам", "test.xml"], + ["2019.10.31 13:21","Отказ", "ООО Гренодер", "test.xml"], + ["2019.10.31 13:21","Успешно", "ООО Гренодер", "test.xml"], + ["2019.10.31 13:21","Успешно", "ООО Сударь", "test.xml"], + ["2019.10.31 13:21","Успешно", "ООО БалтКам", "test.xml"], + ["2019.10.31 13:21","Успешно", "ООО Гренодер", "test.xml"], + ["2019.10.31 13:21","Отказ", "ООО Сударь", "test.xml"], + ["2019.10.31 13:21","Успешно", "ООО БалтКам", "test.xml"], + ["f","s"] + ] + } + //mGlobal.Modal.TableFilter.Show(lTestData) + ///Test + lTestData = { + "Title":"Test", + "List":[ + {"Header":"Head 09","Description":"Test 21.02.2019"}, + {"Header":"Head 09","Description":"Test 21.02.2019"}, + {"Header":"Head 09","Description":"Test 21.02.2019"}, + {"Header":"Head 09","Description":"TestNew 21.02.2019"}, + {"Header":"Head 09","Description":"Test 21.02.2019"}, + {"Header":"Head 09","Description":"TestNew 21.02.2019"}, + {"Header":"Head 09","Description":"Test 21.02.2019"}, + {"Header":"Head 09","Description":"Test 21.02.2019"} + ] + } + //mGlobal.Modal.ListFilter.Show(lTestData) }) ; @@ -547,6 +728,62 @@ + + +