From 54da6d02d28d90ceb8f857f87040da0017f92e05 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 4 Mar 2020 19:03:58 +0000 Subject: [PATCH] --- ayanova/src/components/gz-data-table.vue | 90 ++++++++++++++++++++---- 1 file changed, 78 insertions(+), 12 deletions(-) diff --git a/ayanova/src/components/gz-data-table.vue b/ayanova/src/components/gz-data-table.vue index 8d13338a..bf97317a 100644 --- a/ayanova/src/components/gz-data-table.vue +++ b/ayanova/src/components/gz-data-table.vue @@ -911,21 +911,87 @@ function loadFormSettings(vm) { // items.Add(fitem); */ //////////////////// // -function untokenizeListView(lv) { - //it has one or more tokens +function untokenizeListView(lvJson) { + //if it has one or more tokens //iterate the array and build a new array with substituted tokens with the correct date and time in them - //console.log(lv); - //console.log(JSON.parse(lv)); - console.log("test:past90days"); - console.log(relativeDatefilterCalculator.tokenToDates("*past90days*")); + console.log(lvJson); + + //format of a date token filter //[{"fld":"widgetname"},{"fld":"widgetstartdate","filter":{"items":[{"op":"=","value":"*past90days*","token":true}]}},{"fld":"widgetenddate"}] - if (lv == null) { - return lv; + if (lvJson == null) { + return lvJson; } //See if it has any date tokens - if (lv.indexOf('"token":true') == -1) { - return lv; + if (lvJson.indexOf('"token":true') == -1) { + return lvJson; } - return lv; -} + + console.log("WE HAVE TOKENS...PROCESSING..."); + //we have one or more tokens, substitute them in the filter array + var ret = []; + var lv = JSON.parse(lvJson); + + //iterate the incoming and copy to the outgoing directly + //except if a date token filter then substitute our own filter object in place + for (var ilv = 0; ilv < lv.length; ilv++) { + //listview object + var lvo = lv[ilv]; + //instantiate return object + var reto = {}; + //copy over field name to return object + reto.fld = lvo.fld; + //does it have a filter? + if (lvo.filter) { + //yes, so copy / transform as required + + //create an empty filter items array on return object + reto.filter = { items: [] }; + + //"any" property set? + if (lvo.filter.any) { + reto.filter.any = true; + } + + //iterate the filter items in the source lvo object + for (var j = 0; j < lvo.filter.items.length; j++) { + //get this filter item + var fi = lvo.filter.items[j]; + //no token shortcut + if (!fi.token) { + //just copy it out + reto.filter.items.push(fi); + } else { + //it has a date token so let's build it out + //filter item value contains the token, op is always equals + var filterDates = relativeDatefilterCalculator.tokenToDates(fi.value); + //create and add a new filter item for each not undefined value + //{ after: undefined, before: undefined } + //AFTER DATE? + if (filterDates.after) { + reto.filter.items.push({ + op: ">=", //GreaterThanOrEqualTo + value: filterDates.after + }); + } + //BEFORE DATE? + if (filterDates.before) { + reto.filter.items.push({ + op: "<=", //LessThanOrEqualTo + value: filterDates.before + }); + } + } + } + + //end of has filter if condition + } + + //push the return object into the return array + ret.push(reto); + //end of iterate lv loop + } + console.log("After processing:"); + console.log(JSON.stringify(ret)); + return JSON.stringify(ret); +} //[{"fld":"widgetname"},{"fld":"widgetstartdate","filter":{"items":[{"op":"=","value":"*past90days*","token":true}]}},{"fld":"widgetenddate"}]