@syncfusion/ej2-data
Advanced tools
Comparing version 15.4.17 to 15.4.20
/*! | ||
* filename: ej2-data.umd.min.js | ||
* version : 15.4.17 | ||
* version : 15.4.20 | ||
* Copyright Syncfusion Inc. 2001 - 2017. All rights reserved. | ||
@@ -11,4 +11,4 @@ * Use of this code is subject to the terms of our license. | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@syncfusion/ej2-base"));else if("function"==typeof define&&define.amd)define(["@syncfusion/ej2-base"],t);else{var r=t("object"==typeof exports?require("@syncfusion/ej2-base"):e["@syncfusion/ej2-base"]);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){var n,o;n=[r,t,r(1),r(4),r(5),r(3)],void 0!==(o=function(e,t,r,n,o,a){"use strict";function s(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0}),s(r),s(n),s(o),s(a)}.apply(t,n))&&(e.exports=o)},function(e,t,r){var n,o;n=[r,t,r(2),r(2),r(3),r(4),r(5)],void 0!==(o=function(e,t,r,n,o,a,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t,r){var i=this;this.dateParse=!0,this.requests=[],e||this.dataSource||(e=[]),r=r||e.adaptor;var u;return e instanceof Array?u={json:e,offline:!0}:"object"==typeof e?(e.json||(e.json=[]),u={url:e.url,insertUrl:e.insertUrl,removeUrl:e.removeUrl,updateUrl:e.updateUrl,crudUrl:e.crudUrl,batchUrl:e.batchUrl,json:e.json,headers:e.headers,accept:e.accept,data:e.data,timeTillExpiration:e.timeTillExpiration,cachingPageSize:e.cachingPageSize,enableCaching:e.enableCaching,requestType:e.requestType,key:e.key,crossDomain:e.crossDomain,jsonp:e.jsonp,dataType:e.dataType,offline:void 0!==e.offline?e.offline:!(e.adaptor instanceof s.RemoteSaveAdaptor)&&!e.url,requiresFormat:e.requiresFormat}):o.DataUtil.throwError("DataManager: Invalid arguments"),void 0!==u.requiresFormat||o.DataUtil.isCors()||(u.requiresFormat=!!n.isNullOrUndefined(u.crossDomain)||u.crossDomain),void 0===u.dataType&&(u.dataType="json"),this.dataSource=u,this.defaultQuery=t,u.url&&u.offline&&!u.json.length?(this.isDataAvailable=!1,this.adaptor=r||new s.ODataAdaptor,this.dataSource.offline=!1,this.ready=this.executeQuery(t||new a.Query),this.ready.then(function(e){i.dataSource.offline=!0,i.isDataAvailable=!0,u.json=e.result,i.adaptor=new s.JsonAdaptor})):this.adaptor=u.offline?new s.JsonAdaptor:new s.ODataAdaptor,!u.jsonp&&this.adaptor instanceof s.ODataAdaptor&&(u.jsonp="callback"),this.adaptor=r||this.adaptor,u.enableCaching&&(this.adaptor=new s.CacheAdaptor(this.adaptor,u.timeTillExpiration,u.cachingPageSize)),this}return e.prototype.setDefaultQuery=function(e){return this.defaultQuery=e,this},e.prototype.executeLocal=function(t){this.defaultQuery||t instanceof a.Query||o.DataUtil.throwError("DataManager - executeLocal() : A query is required to execute"),this.dataSource.json||o.DataUtil.throwError("DataManager - executeLocal() : Json data is required to execute"),t=t||this.defaultQuery;var r=this.adaptor.processQuery(this,t);if(t.subQuery){var s=t.subQuery.fromTable,i=t.subQuery.lookups,u=t.requiresCounts?r.result:r;i&&i instanceof Array&&o.DataUtil.buildHierarchy(t.subQuery.fKey,s,u,i,t.subQuery.key);for(var c=0;c<u.length;c++)u[c][s]instanceof Array&&(u[c]=n.extend({},{},u[c]),u[c][s]=this.adaptor.processResponse(t.subQuery.using(new e(u[c][s].slice(0))).executeLocal(),this,t))}return this.adaptor.processResponse(r,this,t)},e.prototype.executeQuery=function(t,r,n,s){var i=this;"function"==typeof t&&(n,n=r,r=t,t=null),t||(t=this.defaultQuery),t instanceof a.Query||o.DataUtil.throwError("DataManager - executeQuery() : A query is required to execute");var c=new u,l={query:t};if(this.dataSource.offline||void 0===this.dataSource.url)e.nextTick(function(){var r=i.executeLocal(t);l=e.getDeferedArgs(t,r,l),c.resolve(l)});else{var p=this.adaptor.processQuery(this,t);this.makeRequest(p,c,l,t)}return c.promise},e.getDeferedArgs=function(e,t,r){return e.requiresCounts?(r.result=t.result,r.count=t.count,r.aggregates=t.aggregates):r.result=t,r},e.nextTick=function(e){(window.setImmediate||window.setTimeout)(e,0)},e.prototype.extendRequest=function(e,t,r){return n.extend({},{type:"GET",dataType:this.dataSource.dataType,crossDomain:this.dataSource.crossDomain,jsonp:this.dataSource.jsonp,cache:!0,processData:!1,onSuccess:t,onFailure:r},e)},e.prototype.makeRequest=function(e,t,n,a){var s=this,i=!!a.subQuerySelector,c=function(e){n.error=e,t.reject(n)},l=function(e,r,o,a,s,i,u){n.xhr=o,n.count=r?parseInt(r.toString(),10):0,n.result=e,n.request=a,n.aggregates=i,n.actual=s,n.virtualSelectRecords=u,t.resolve(n)},p=function(e,t){var r=new u,p={parent:n};a.subQuery.isChild=!0;var d=s.adaptor.processQuery(s,a.subQuery,e?s.adaptor.processResponse(e):t),h=s.makeRequest(d,r,p,a.subQuery);return i||r.then(function(t){e&&(o.DataUtil.buildHierarchy(a.subQuery.fKey,a.subQuery.fromTable,e,t,a.subQuery.key),l(e,t.count,t.xhr))},c),h},d=function(e,t){-1===t.httpRequest.getResponseHeader("Content-Type").indexOf("xml")&&s.dateParse&&(e=o.DataUtil.parse.parseJson(e));var r=s.adaptor.processResponse(e,s,a,t.httpRequest,t),n=0,u=null,c=e.virtualSelectRecords;if(a.requiresCounts&&(n=r.count,u=r.aggregates,r=r.result),!a.subQuery)return void l(r,n,t.httpRequest,t.type,e,u,c);i||p(r,t)},h=this.extendRequest(e,d,c),f=new r.Ajax(h);if(f.beforeSend=function(){s.beforeSend(f.httpRequest,f)},h=f.send(),this.requests.push(f),i){var g=void 0,y=a.subQuerySelector.call(this,{query:a.subQuery,parent:a});y&&y.length?(g=Promise.all([h,p(null,y)]),g.then(function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=e[0],n=s.adaptor.processResponse(r[0],s,a,s.requests[0].httpRequest,s.requests[0]),u=0;a.requiresCounts&&(u=n.count,n=n.result);var c=s.adaptor.processResponse(r[1],s,a.subQuery,s.requests[1].httpRequest,s.requests[1]);u=0,a.subQuery.requiresCounts&&(u=c.count,c=c.result),o.DataUtil.buildHierarchy(a.subQuery.fKey,a.subQuery.fromTable,n,c,a.subQuery.key),i=!1,l(n,u,s.requests[0].httpRequest)})):i=!1}return h},e.prototype.beforeSend=function(e,t){this.adaptor.beforeSend(this,e,t);for(var r,n=this.dataSource.headers,o=0;n&&o<n.length;o++){r=[];for(var a=Object.keys(n[o]),s=0,i=a;s<i.length;s++){var u=i[s];r.push(u),e.setRequestHeader(u,n[o][u])}}},e.prototype.saveChanges=function(e,t,n,o){var s=this;n instanceof a.Query&&(o=n,n=null);var i={url:n,key:t||this.dataSource.key},c=this.adaptor.batchRequest(this,e,i,o);if(this.dataSource.offline)return c;var l=new u,p=new r.Ajax(c);return p.beforeSend=function(){s.beforeSend(p.httpRequest,p)},p.onSuccess=function(t,r){l.resolve(s,[s.adaptor.processResponse(t,s,null,r.httpRequest,r,e)])},p.onFailure=function(e){l.reject([{error:e}])},p.send(),l.promise},e.prototype.insert=function(e,t,r,n){e=o.DataUtil.parse.replacer(e),t instanceof a.Query&&(r=t,t=null);var s=this.adaptor.insert(this,e,t,r,n);return this.dataSource.offline?s:this.doAjaxRequest(s)},e.prototype.remove=function(e,t,r,n){"object"==typeof t&&(t=t[e]),r instanceof a.Query&&(n=r,r=null);var o=this.adaptor.remove(this,e,t,r,n);return this.dataSource.offline?o:this.doAjaxRequest(o)},e.prototype.update=function(e,t,r,n){t=o.DataUtil.parse.replacer(t,!this.dataSource.offline),r instanceof a.Query&&(n=r,r=null);var s=this.adaptor.update(this,e,t,r,n);return this.dataSource.offline?s:this.doAjaxRequest(s)},e.prototype.doAjaxRequest=function(e){var t=this,a=new u;e=n.extend({},{type:"POST",contentType:"application/json; charset=utf-8",processData:!1},e);var s=new r.Ajax(e);return s.beforeSend=function(){t.beforeSend(s.httpRequest,s)},s.onSuccess=function(e,r){try{o.DataUtil.parse.parseJson(e)}catch(t){e=[]}e=t.adaptor.processResponse(o.DataUtil.parse.parseJson(e),t,null,r.httpRequest,r),a.resolve(t,[{record:e,dataManager:t}])},s.onFailure=function(e){a.reject([{error:e}])},s.send(),a.promise},e}();t.DataManager=i;var u=function(){function e(){var e=this;this.promise=new Promise(function(t,r){e.resolve=t,e.reject=r}),this.then=this.promise.then.bind(this.promise),this.catch=this.promise.catch.bind(this.promise)}return e}();t.Deferred=u}.apply(t,n))&&(e.exports=o)},function(t,r){t.exports=e},function(e,t,r){var n,o;n=[r,t,r(2),r(1),r(4)],void 0!==(o=function(e,t,r,n,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var a={GroupGuid:"{271bbba0-1ee7}"},s=function(){function e(){}return e.getValue=function(e,t){return"function"==typeof e?e.call(t||{}):e},e.endsWith=function(e,t){return e.slice(-t.length)===t},e.startsWith=function(e,t){return e.slice(0,t.length)===t},e.fnSort=function(e){return e=e?e.toLowerCase():"ascending","ascending"===e?this.fnAscending:this.fnDescending},e.fnAscending=function(e,t){return null===t||void 0===t?-1:"string"==typeof e?e.localeCompare(t):null===e||void 0===e?1:e-t},e.fnDescending=function(e,t){return null===t||void 0===t?1:"string"==typeof e?-1*e.localeCompare(t):null===e||void 0===e?-1:t-e},e.extractFields=function(e,t){var r={};if(1===t.length)return this.getObject(t[0],e);for(var n=0;n<t.length;n++)r[t[n].replace(".","_")]=this.getObject(t[n],e);return r},e.select=function(e,t){for(var r=[],n=0;n<e.length;n++)r.push(this.extractFields(e[n],t));return r},e.group=function(t,n,o,s,i,u){s=s||1;var c=t;if(c.GroupGuid===a.GroupGuid){for(var l=this,p=0;p<c.length;p++)!function(e){if(r.isNullOrUndefined(i))c[e].items=l.group(c[e].items,n,o,c.level+1,null,u),c[e].count=c[e].items.length;else{var t=-1,a=i.filter(function(t){return t.key===c[e].key});t=i.indexOf(a[0]),c[e].items=l.group(c[e].items,n,o,c.level+1,i[t].items,u),c[e].count=i[t].count}}(p);return c.childLevels+=1,c}var d={},h=[];h.GroupGuid=a.GroupGuid,h.level=s,h.childLevels=0,h.records=c;for(var f=this,g=0;g<c.length;g++)!function(e){var t=f.getVal(c,e,n);if(r.isNullOrUndefined(u)||(t=u(t,n)),!d[t]&&(d[t]={key:t,count:0,items:[],aggregates:{},field:n},h.push(d[t]),!r.isNullOrUndefined(i))){var o=i.filter(function(e){return e.key===d[t].key});d[t].count=o[0].count}d[t].count=r.isNullOrUndefined(i)?d[t].count+=1:d[t].count,d[t].items.push(c[e])}(g);if(o&&o.length)for(var g=0;g<h.length;g++)!function(t){for(var n={},a=void 0,s=o,u=0;u<o.length;u++)if(a=e.aggregates[o[u].type],r.isNullOrUndefined(i))a&&(n[s[u].field+" - "+s[u].type]=a(h[t].items,s[u].field));else{var c=i.filter(function(e){return e.key===h[t].key});a&&(n[s[u].field+" - "+s[u].type]=a(c[0].items,s[u].field))}h[t].aggregates=n}(g);return h},e.buildHierarchy=function(e,t,r,n,o){var a,s,i={};for(n.result&&(n=n.result),n.GroupGuid&&this.throwError("DataManager: Do not have support Grouping in hierarchy"),a=0;a<n.length;a++){var u=this.getObject(e,n[a]);s=i[u]||(i[u]=[]),s.push(n[a])}for(a=0;a<r.length;a++){var u=this.getObject(o||e,r[a]);r[a][t]=i[u]}},e.getFieldList=function(e,t,r){if(void 0===r&&(r=""),void 0===t||null===t)return this.getFieldList(e,[],r);for(var n=e,o=Object.keys(e),a=0,s=o;a<s.length;a++){var i=s[a];"object"!=typeof n[i]||n[i]instanceof Array?t.push(r+i):this.getFieldList(n[i],t,r+i+".")}return t},e.getObject=function(e,t){if(!e)return t;if(-1===e.indexOf("."))return t[e];for(var r=t,n=e.split("."),o=0;o<n.length&&null!=r;o++)r=r[n[o]];return r},e.sort=function(e,t,r){if(e.length<=1)return e;var n=parseInt((e.length/2).toString(),10),o=e.slice(0,n),a=e.slice(n);return o=this.sort(o,t,r),a=this.sort(a,t,r),this.merge(o,a,t,r)},e.merge=function(e,t,r,n){for(var o,a=[];e.length>0||t.length>0;)o=e.length>0&&t.length>0?n?n(this.getVal(e,0,r),this.getVal(t,0,r))<=0?e:t:e[0][r]<e[0][r]?e:t:e.length>0?e:t,a.push(o.shift());return a},e.getVal=function(e,t,r){return r?this.getObject(r,e[t]):e[t]},e.toLowerCase=function(e){return e?"string"==typeof e?e.toLowerCase():e.toString():0===e||!1===e?e.toString():""},e.callAdaptorFunction=function(e,t,r,n){if(t in e){var o=e[t](r,n);this.fnOperators.isnull(o)||(r=o)}return r},e.isPlainObject=function(e){return!!e&&e.constructor===Object},e.isCors=function(){var e=null;try{e=new window.XMLHttpRequest}catch(e){}return!!e&&"withCredentials"in e},e.getGuid=function(e){var t;return(e||"")+"00000000-0000-4000-0000-000000000000".replace(/0/g,function(e,r){if("crypto"in window&&"getRandomValues"in crypto){var n=new Uint8Array(1);window.crypto.getRandomValues(n),t=n[0]%16|0}else t=16*Math.random()|0;return"0123456789abcdef"[19===r?3&t|8:t]})},e.isNull=function(e){return void 0===e||null===e},e.getItemFromComparer=function(t,n,o){var a,s,i,u=0,c="string"==typeof e.getVal(t,0,n);if(t.length)for(;r.isNullOrUndefined(a)&&u<t.length;)a=e.getVal(t,u,n),i=t[u++];for(;u<t.length;u++)s=e.getVal(t,u,n),r.isNullOrUndefined(s)||(c&&(a=+a,s=+s),o(a,s)>0&&(a=s,i=t[u]));return i},e}();s.serverTimezoneOffset=0,s.throwError=function(e){try{throw new Error(e)}catch(e){throw e.message+"\n"+e.stack}},s.aggregates={sum:function(e,t){for(var r,n=0,o="number"!=typeof s.getVal(e,0,t),a=0;a<e.length;a++)r=s.getVal(e,a,t),isNaN(r)||null===r||(o&&(r=+r),n+=r);return n},average:function(e,t){return s.aggregates.sum(e,t)/e.length},min:function(e,t){var r;return"function"==typeof t&&(r=t,t=null),s.getObject(t,s.getItemFromComparer(e,t,r||s.fnAscending))},max:function(e,t){var r;return"function"==typeof t&&(r=t,t=null),s.getObject(t,s.getItemFromComparer(e,t,r||s.fnDescending))},truecount:function(e,t){return new n.DataManager(e).executeLocal((new o.Query).where(t,"equal",!0,!0)).length},falsecount:function(e,t){return new n.DataManager(e).executeLocal((new o.Query).where(t,"equal",!1,!0)).length},count:function(e,t){return e.length}},s.operatorSymbols={"<":"lessthan",">":"greaterthan","<=":"lessthanorequal",">=":"greaterthanorequal","==":"equal","!=":"notequal","*=":"contains","$=":"endswith","^=":"startswith"},s.odBiOperator={"<":" lt ",">":" gt ","<=":" le ",">=":" ge ","==":" eq ","!=":" ne ",lessthan:" lt ",lessthanorequal:" le ",greaterthan:" gt ",greaterthanorequal:" ge ",equal:" eq ",notequal:" ne "},s.odUniOperator={"$=":"endswith","^=":"startswith","*=":"substringof",endswith:"endswith",startswith:"startswith",contains:"substringof"},s.odv4UniOperator={"$=":"endswith","^=":"startswith","*=":"contains",endswith:"endswith",startswith:"startswith",contains:"contains"},s.fnOperators={equal:function(e,t,r){return r?s.toLowerCase(e)===s.toLowerCase(t):e===t},notequal:function(e,t,r){return!s.fnOperators.equal(e,t,r)},lessthan:function(e,t,r){return r?s.toLowerCase(e)<s.toLowerCase(t):e<t},greaterthan:function(e,t,r){return r?s.toLowerCase(e)>s.toLowerCase(t):e>t},lessthanorequal:function(e,t,r){return r?s.toLowerCase(e)<=s.toLowerCase(t):e<=t},greaterthanorequal:function(e,t,r){return r?s.toLowerCase(e)>=s.toLowerCase(t):e>=t},contains:function(e,t,n){return n?!r.isNullOrUndefined(e)&&!r.isNullOrUndefined(t)&&-1!==s.toLowerCase(e).indexOf(s.toLowerCase(t)):!r.isNullOrUndefined(e)&&!r.isNullOrUndefined(t)&&-1!==e.toString().indexOf(t)},notnull:function(e){return null!==e},isnull:function(e){return null===e},startswith:function(e,t,r){return r?e&&t&&s.startsWith(e.toLowerCase(),t.toLowerCase()):e&&t&&s.startsWith(e,t)},endswith:function(e,t,r){return r?e&&t&&s.endsWith(e.toLowerCase(),t.toLowerCase()):e&&t&&s.endsWith(e,t)},processSymbols:function(e){var t=s.operatorSymbols[e];if(t){return s.fnOperators[t]}return s.throwError("Query - Process Operator : Invalid operator")},processOperator:function(e){var t=s.fnOperators[e];return t||s.fnOperators.processSymbols(e)}},s.parse={parseJson:function(e){return"string"==typeof e?e=JSON.parse(e,s.parse.jsonReviver):e instanceof Array?s.parse.iterateAndReviveArray(e):"object"==typeof e&&s.parse.iterateAndReviveJson(e),e},iterateAndReviveArray:function(e){for(var t=0;t<e.length;t++)"object"==typeof e[t]?s.parse.iterateAndReviveJson(e[t]):"string"!=typeof e[t]||/^[\s]*\[|^[\s]*\{|\"/g.test(e[t])?e[t]=s.parse.parseJson(e[t]):e[t]=s.parse.jsonReviver("",e[t])},iterateAndReviveJson:function(e){for(var t,r=Object.keys(e),n=0,o=r;n<o.length;n++){var a=o[n];s.startsWith(a,"__")||(t=e[a],"object"==typeof t?t instanceof Array?s.parse.iterateAndReviveArray(t):t&&s.parse.iterateAndReviveJson(t):e[a]=s.parse.jsonReviver(e[a],t))}},jsonReviver:function(e,t){var r=t;if("string"==typeof t){var n=/^\/Date\(([+-]?[0-9]+)([+-][0-9]{4})?\)\/$/.exec(t);if(n)return s.parse.jsonReplacer({value:new Date(parseInt(n[1],10))},!1).value;if(/^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*){1})([zZ]|([+\-])(\d\d):?(\d\d))?$/.test(t)){var o=r.split(/[^0-9]/);t=s.parse.jsonReplacer({value:new Date(parseInt(o[0],10),parseInt(o[1],10)-1,parseInt(o[2],10),parseInt(o[3],10),parseInt(o[4],10),parseInt(o[5],10))},!1).value}}return t},isJson:function(e){return"string"==typeof e[0]?e:s.parse.parseJson(e)},isGuid:function(e){return null!=/[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}/i.exec(e)},replacer:function(e,t){return s.isPlainObject(e)?s.parse.jsonReplacer(e,t):e instanceof Array?s.parse.arrayReplacer(e):e instanceof Date?s.parse.jsonReplacer({val:e},t).val:e},jsonReplacer:function(e,t){void 0===t&&(t=!0);for(var r,n=Object.keys(e),o=0,a=n;o<a.length;o++){var i=a[o];if((r=e[i])instanceof Date){var u=r,c=+u-6e4*u.getTimezoneOffset();e[i]=new Date(c-36e5*s.serverTimezoneOffset),t&&(e[i]=e[i].toJSON())}}return e},arrayReplacer:function(e){for(var t=0;t<e.length;t++)s.isPlainObject(e[t])?e[t]=s.parse.jsonReplacer(e[t]):e[t]instanceof Date&&(e[t]=s.parse.jsonReplacer({date:e[t]}).date);return e}},t.DataUtil=s}.apply(t,n))&&(e.exports=o)},function(e,t,r){var n,o;n=[r,t,r(3)],void 0!==(o=function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){return this.subQuery=null,this.isChild=!1,this.queries=[],this.key="",this.fKey="","string"==typeof e?this.fromTable=e:e&&e instanceof Array&&(this.lookups=e),this.expands=[],this.sortedColumns=[],this.groupedColumns=[],this.subQuery=null,this.isChild=!1,this.params=[],this}return e.prototype.setKey=function(e){return this.key=e,this},e.prototype.using=function(e){return this.dataManager=e,this},e.prototype.execute=function(e,t,n,o){return e=e||this.dataManager,e?e.executeQuery(this,t,n,o):r.DataUtil.throwError('Query - execute() : dataManager needs to be is set using "using" function or should be passed as argument')},e.prototype.executeLocal=function(e){return e=e||this.dataManager,e?e.executeLocal(this):r.DataUtil.throwError('Query - executeLocal() : dataManager needs to be is set using "using" function or should be passed as argument')},e.prototype.clone=function(){var t=new e;return t.queries=this.queries.slice(0),t.key=this.key,t.isChild=this.isChild,t.dataManager=this.dataManager,t.fromTable=this.fromTable,t.params=this.params.slice(0),t.expands=this.expands.slice(0),t.sortedColumns=this.sortedColumns.slice(0),t.groupedColumns=this.groupedColumns.slice(0),t.subQuerySelector=this.subQuerySelector,t.subQuery=this.subQuery,t.fKey=this.fKey,t.requiresCounts=this.requiresCounts,t},e.prototype.from=function(e){return this.fromTable=e,this},e.prototype.addParams=function(e,t){return"function"==typeof t?this.params.push({key:e,fn:t}):this.params.push({key:e,value:t}),this},e.prototype.expand=function(e){return this.expands="string"==typeof e?[].slice.call([e],0):e.slice(0),this},e.prototype.where=function(e,t,r,n){t=t?t.toLowerCase():null;var a=null;return"string"==typeof e?a=new o(e,t,r,n):e instanceof o&&(a=e),this.queries.push({fn:"onWhere",e:a}),this},e.prototype.search=function(e,t,n,o){"string"==typeof t&&(t=[t]),n=n||"contains";var a=r.DataUtil.fnOperators[n];return this.queries.push({fn:"onSearch",e:{fieldNames:t,operator:n,searchKey:e,ignoreCase:o,comparer:a}}),this},e.prototype.sortBy=function(t,n,o){var a,s,i="ascending";if("string"==typeof t&&r.DataUtil.endsWith(t.toLowerCase()," desc")&&(t=t.replace(/ desc$/i,""),n="descending"),n&&"string"!=typeof n||(i=n?n.toLowerCase():"ascending",n=r.DataUtil.fnSort(n)),o){a=e.filterQueries(this.queries,"onSortBy");for(var u=0;u<a.length;u++)if("string"==typeof(s=a[u].e.fieldName)){if(s===t)return this}else if(s instanceof Array)for(var c=0;c<s.length;c++)if(s[c]===t||t.toLowerCase()===s[c]+" desc")return this}return this.queries.push({fn:"onSortBy",e:{fieldName:t,comparer:n,direction:i}}),this},e.prototype.sortByDesc=function(e){return this.sortBy(e,"descending")},e.prototype.group=function(e,t,r){return this.sortBy(e,null,!0),this.queries.push({fn:"onGroup",e:{fieldName:e,comparer:t||null,format:r||null}}),this},e.prototype.page=function(e,t){return this.queries.push({fn:"onPage",e:{pageIndex:e,pageSize:t}}),this},e.prototype.range=function(e,t){return this.queries.push({fn:"onRange",e:{start:e,end:t}}),this},e.prototype.take=function(e){return this.queries.push({fn:"onTake",e:{nos:e}}),this},e.prototype.skip=function(e){return this.queries.push({fn:"onSkip",e:{nos:e}}),this},e.prototype.select=function(e){return"string"==typeof e&&(e=[].slice.call([e],0)),this.queries.push({fn:"onSelect",e:{fieldNames:e}}),this},e.prototype.hierarchy=function(e,t){return this.subQuerySelector=t,this.subQuery=e,this},e.prototype.foreignKey=function(e){return this.fKey=e,this},e.prototype.requiresCount=function(){return this.requiresCounts=!0,this},e.prototype.aggregate=function(e,t){return this.queries.push({fn:"onAggregates",e:{field:t,type:e}}),this},e.filterQueries=function(e,t){return e.filter(function(e){return e.fn===t})},e.filterQueryLists=function(e,t){for(var r=e.filter(function(e){return-1!==t.indexOf(e.fn)}),n={},o=0;o<r.length;o++)n[r[o].fn]||(n[r[o].fn]=r[o].e);return n},e}();t.Query=n;var o=function(){function e(t,n,o,a){return void 0===a&&(a=!1),this.isComplex=!1,"string"==typeof t?(this.field=t,this.operator=n.toLowerCase(),this.value=o,this.ignoreCase=a,this.isComplex=!1,this.comparer=r.DataUtil.fnOperators.processOperator(this.operator)):(t instanceof e&&o instanceof e||o instanceof Array)&&(this.isComplex=!0,this.condition=n.toLowerCase(),this.predicates=[t],o instanceof Array?[].push.apply(this.predicates,o):this.predicates.push(o)),this}return e.and=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e.combinePredicates([].slice.call(t,0),"and")},e.prototype.and=function(t,r,n,o){return e.combine(this,t,r,n,"and",o)},e.or=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e.combinePredicates([].slice.call(t,0),"or")},e.prototype.or=function(t,r,n,o){return e.combine(this,t,r,n,"or",o)},e.fromJson=function(e){if(e instanceof Array){for(var t=[],r=0,n=e.length;r<n;r++)t.push(this.fromJSONData(e[r]));return t}var o=e;return this.fromJSONData(o)},e.prototype.validate=function(e){var t,n,o=this.predicates?this.predicates:[];if(!this.isComplex&&this.comparer)return this.comparer.call(this,r.DataUtil.getObject(this.field,e),this.value,this.ignoreCase);t="and"===this.condition;for(var a=0;a<o.length;a++)if(n=o[a].validate(e),t){if(!n)return!1}else if(n)return!0;return t},e.prototype.toJson=function(){var e,t;if(this.isComplex){e=[],t=this.predicates;for(var r=0;r<t.length;r++)e.push(t[r].toJson())}return{isComplex:this.isComplex,field:this.field,operator:this.operator,value:this.value,ignoreCase:this.ignoreCase,condition:this.condition,predicates:e}},e.combinePredicates=function(t,r){if(1===t.length){if(!(t[0]instanceof Array))return t[0];t=t[0]}return new e(t[0],r,t.slice(1))},e.combine=function(t,n,o,a,s,i){return n instanceof e?e[s](t,n):"string"==typeof n?e[s](t,new e(n,o,a,i)):r.DataUtil.throwError("Predicate - "+s+" : invalid arguments")},e.fromJSONData=function(t){for(var r=t.predicates||[],n=r.length,o=[],a=0;a<n;a++)o.push(this.fromJSONData(r[a]));return t.isComplex?new e(o[0],t.condition,o.slice(1)):new e(t.field,t.operator,t.value,t.ignoreCase)},e}();t.Predicate=o}.apply(t,n))&&(e.exports=o)},function(e,t,r){var n,o,a=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();n=[r,t,r(2),r(3),r(4)],void 0!==(o=function(e,t,r,n,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(t){this.options={from:"table",requestType:"json",sortBy:"sorted",select:"select",skip:"skip",group:"group",take:"take",search:"search",count:"requiresCounts",where:"where",aggregates:"aggregates"},this.type=e,this.dataSource=t,this.pvt={}}return e.prototype.processResponse=function(e,t,r,n){return e},e}();t.Adaptor=s;var i=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.processQuery=function(e,t){for(var r,n,o=e.dataSource.json.slice(0),a=o.length,s=!0,i={},u=0;u<t.queries.length;u++)n=t.queries[u],r=this[n.fn].call(this,o,n.e,t),"onAggregates"===n.fn?i[n.e.field+" - "+n.e.type]=r:o=void 0!==r?r:o,"onPage"!==n.fn&&"onSkip"!==n.fn&&"onTake"!==n.fn&&"onRange"!==n.fn||(s=!1),s&&(a=o.length);return t.requiresCounts&&(o={result:o,count:a,aggregates:i}),o},t.prototype.batchRequest=function(e,t,r){var n;for(n=0;n<t.addedRecords.length;n++)this.insert(e,t.addedRecords[n]);for(n=0;n<t.changedRecords.length;n++)this.update(e,r.key,t.changedRecords[n]);for(n=0;n<t.deletedRecords.length;n++)this.remove(e,r.key,t.deletedRecords[n]);return t},t.prototype.onWhere=function(e,t){return e&&e.length?e.filter(function(e){if(t)return t.validate(e)}):e},t.prototype.onAggregates=function(e,t){var r=n.DataUtil.aggregates[t.type];return e&&r&&0!==e.length?r(e,t.field):null},t.prototype.onSearch=function(e,t){return e&&e.length?(0===t.fieldNames.length&&n.DataUtil.getFieldList(e[0],t.fieldNames),e.filter(function(e){for(var r=0;r<t.fieldNames.length;r++)if(t.comparer.call(e,n.DataUtil.getObject(t.fieldNames[r],e),t.searchKey,t.ignoreCase))return!0;return!1})):e},t.prototype.onSortBy=function(e,t,r){if(!e||!e.length)return e;var o,a=n.DataUtil.getValue(t.fieldName,r);if(!a)return e.sort(t.comparer);if(a instanceof Array){a=a.slice(0);for(var s=a.length-1;s>=0;s--)a[s]&&(o=t.comparer,n.DataUtil.endsWith(a[s]," desc")&&(o=n.DataUtil.fnSort("descending"),a[s]=a[s].replace(" desc","")),e=n.DataUtil.sort(e,a[s],o));return e}return n.DataUtil.sort(e,a,t.comparer)},t.prototype.onGroup=function(e,t,r){if(!e||!e.length)return e;var a=o.Query.filterQueries(r.queries,"onAggregates"),s=[];if(a.length)for(var i=void 0,u=0;u<a.length;u++)i=a[u].e,s.push({type:i.type,field:n.DataUtil.getValue(i.field,r)});return n.DataUtil.group(e,n.DataUtil.getValue(t.fieldName,r),s,null,null,t.comparer)},t.prototype.onPage=function(e,t,r){var o=n.DataUtil.getValue(t.pageSize,r),a=(n.DataUtil.getValue(t.pageIndex,r)-1)*o,s=a+o;return e&&e.length?e.slice(a,s):e},t.prototype.onRange=function(e,t){return e&&e.length?e.slice(n.DataUtil.getValue(t.start),n.DataUtil.getValue(t.end)):e},t.prototype.onTake=function(e,t){return e&&e.length?e.slice(0,n.DataUtil.getValue(t.nos)):e},t.prototype.onSkip=function(e,t){return e&&e.length?e.slice(n.DataUtil.getValue(t.nos)):e},t.prototype.onSelect=function(e,t){return e&&e.length?n.DataUtil.select(e,n.DataUtil.getValue(t.fieldNames)):e},t.prototype.insert=function(e,t,n,o,a){return r.isNullOrUndefined(a)?e.dataSource.json.push(t):e.dataSource.json.splice(a,0,t)},t.prototype.remove=function(e,t,r,n){var o,a=e.dataSource.json;for("object"==typeof r&&(r=r[t]),o=0;o<a.length&&a[o][t]!==r;o++);return o!==a.length?a.splice(o,1):null},t.prototype.update=function(e,t,n,o){var a,s=e.dataSource.json,i=n[t];for(a=0;a<s.length&&s[a][t]!==i;a++);return a<s.length?r.merge(s[a],n):null},t}(s);t.JsonAdaptor=i;var u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.processQuery=function(e,t,r){var a,s,i=this.getQueryRequest(t),u=o.Query.filterQueryLists(t.queries,["onSelect","onPage","onSkip","onTake","onRange"]),c=t.params,l=e.dataSource.url,p=null,d=this.options,h={sorts:[],groups:[],filters:[],searches:[],aggregates:[]};"onPage"in u?(a=u.onPage,s=n.DataUtil.getValue(a.pageIndex,t),p=n.DataUtil.getValue(a.pageSize,t),s=(s-1)*p):"onRange"in u&&(a=u.onRange,s=a.start,p=a.end-a.start);for(var f=0;f<i.sorts.length;f++)a=n.DataUtil.getValue(i.sorts[f].e.fieldName,t),h.sorts.push(n.DataUtil.callAdaptorFunction(this,"onEachSort",{name:a,direction:i.sorts[f].e.direction},t));r&&(a=this.getFiltersFrom(r,t))&&h.filters.push(n.DataUtil.callAdaptorFunction(this,"onEachWhere",a.toJson(),t));for(var f=0;f<i.filters.length;f++){h.filters.push(n.DataUtil.callAdaptorFunction(this,"onEachWhere",i.filters[f].e.toJson(),t));for(var g="object"==typeof h.filters[f]?Object.keys(h.filters[f]):[],y=0,v=g;y<v.length;y++){var m=v[y];n.DataUtil.isNull(h[m])&&delete h[m]}}for(var f=0;f<i.searches.length;f++)a=i.searches[f].e,h.searches.push(n.DataUtil.callAdaptorFunction(this,"onEachSearch",{fields:a.fieldNames,operator:a.operator,key:a.searchKey,ignoreCase:a.ignoreCase},t));for(var f=0;f<i.groups.length;f++)h.groups.push(n.DataUtil.getValue(i.groups[f].e.fieldName,t));for(var f=0;f<i.aggregates.length;f++)a=i.aggregates[f].e,h.aggregates.push({type:a.type,field:n.DataUtil.getValue(a.field,t)});var S={};this.getRequestQuery(d,t,u,h,S),n.DataUtil.callAdaptorFunction(this,"addParams",{dm:e,query:t,params:c,reqParams:S});for(var b=Object.keys(S),D=0,q=b;D<q.length;D++){var m=q[D];(n.DataUtil.isNull(S[m])||""===S[m]||0===S[m].length)&&delete S[m]}d.skip in S&&d.take in S||null===p||(S[d.skip]=n.DataUtil.callAdaptorFunction(this,"onSkip",s,t),S[d.take]=n.DataUtil.callAdaptorFunction(this,"onTake",p,t));var C=this.pvt;return this.pvt={},"json"===this.options.requestType?{data:JSON.stringify(S),url:l,pvtData:C,type:"POST",contentType:"application/json; charset=utf-8"}:(a=this.convertToQueryString(S,t,e),a=(-1!==e.dataSource.url.indexOf("?")?"&":"/")+a,{type:"GET",url:a.length?l.replace(/\/*$/,a):l,pvtData:C})},t.prototype.getRequestQuery=function(e,t,r,o,a){var s=a;s[e.from]=t.fromTable,e.expand&&(s[e.expand]=t.expands),s[e.select]="onSelect"in r?n.DataUtil.callAdaptorFunction(this,"onSelect",n.DataUtil.getValue(r.onSelect.fieldNames,t),t):"",s[e.count]=t.requiresCounts?n.DataUtil.callAdaptorFunction(this,"onCount",t.requiresCounts,t):"",s[e.search]=o.searches.length?n.DataUtil.callAdaptorFunction(this,"onSearch",o.searches,t):"",s[e.skip]="onSkip"in r?n.DataUtil.callAdaptorFunction(this,"onSkip",n.DataUtil.getValue(r.onSkip.nos,t),t):"",s[e.take]="onTake"in r?n.DataUtil.callAdaptorFunction(this,"onTake",n.DataUtil.getValue(r.onTake.nos,t),t):"",s[e.where]=o.filters.length||o.searches.length?n.DataUtil.callAdaptorFunction(this,"onWhere",o.filters,t):"",s[e.sortBy]=o.sorts.length?n.DataUtil.callAdaptorFunction(this,"onSortBy",o.sorts,t):"",s[e.group]=o.groups.length?n.DataUtil.callAdaptorFunction(this,"onGroup",o.groups,t):"",s[e.aggregates]=o.aggregates.length?n.DataUtil.callAdaptorFunction(this,"onAggregates",o.aggregates,t):"",s.param=[]},t.prototype.convertToQueryString=function(e,t,r){return""},t.prototype.processResponse=function(e,t,r,o,a,s){var i=a,u=i.pvtData||{},c=e.groupDs;if(o&&o.getResponseHeader("Content-Type")&&-1!==o.getResponseHeader("Content-Type").indexOf("xml"))return r.requiresCounts?{result:[],count:0}:[];var l=JSON.parse(i.data);if(l&&"batch"===l.action&&e.addedRecords)return s.addedRecords=e.addedRecords,s;e.d&&(e=e.d);var p={};return"count"in e&&(p.count=e.count),p.result=e.result?e.result:e,this.getAggregateResult(u,e,p,c),n.DataUtil.isNull(p.count)?p.result:{result:p.result,count:p.count,aggregates:p.aggregates}},t.prototype.onGroup=function(e){return this.pvt.groups=e,e},t.prototype.onAggregates=function(e){this.pvt.aggregates=e},t.prototype.batchRequest=function(e,t,r){return{type:"POST",url:e.dataSource.batchUrl||e.dataSource.crudUrl||e.dataSource.removeUrl||e.dataSource.url,contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({changed:t.changedRecords,added:t.addedRecords,deleted:t.deletedRecords,action:"batch",table:r[void 0],key:r[void 0]})}},t.prototype.beforeSend=function(e,t){},t.prototype.insert=function(e,t,r){return{url:e.dataSource.insertUrl||e.dataSource.crudUrl||e.dataSource.url,data:JSON.stringify({value:t,table:r,action:"insert" | ||
})}},t.prototype.remove=function(e,t,r,n){return{type:"POST",url:e.dataSource.removeUrl||e.dataSource.crudUrl||e.dataSource.url,data:JSON.stringify({key:r,keyColumn:t,table:n,action:"remove"})}},t.prototype.update=function(e,t,r,n){return{type:"POST",url:e.dataSource.updateUrl||e.dataSource.crudUrl||e.dataSource.url,data:JSON.stringify({value:r,action:"update",keyColumn:t,key:r[t],table:n})}},t.prototype.getFiltersFrom=function(e,t){var r,a=t.fKey,s=a,i=t.key,u=[];"object"!=typeof e[0]&&(s=null);for(var c=0;c<e.length;c++)r="object"==typeof e[0]?n.DataUtil.getObject(i||s,e[c]):e[c],u.push(new o.Predicate(a,"equal",r));return o.Predicate.or(u)},t.prototype.getAggregateResult=function(e,t,o,a){var s=t;if(t&&t.result&&(s=t.result),e&&e.aggregates&&e.aggregates.length){var i=e.aggregates,u=void 0,c=s,l={};t.aggregate&&(c=t.aggregate);for(var p=0;p<i.length;p++)(u=n.DataUtil.aggregates[i[p].type])&&(l[i[p].field+" - "+i[p].type]=u(c,i[p].field));o.aggregates=l}if(e&&e.groups&&e.groups.length){for(var d=e.groups,p=0;p<d.length;p++){r.isNullOrUndefined(a)||(a=n.DataUtil.group(a,d[p])),s=n.DataUtil.group(s,d[p],e.aggregates,null,a)}o.result=s}return o},t.prototype.getQueryRequest=function(e){var t={sorts:[],groups:[],filters:[],searches:[],aggregates:[]};return t.sorts=o.Query.filterQueries(e.queries,"onSortBy"),t.groups=o.Query.filterQueries(e.queries,"onGroup"),t.filters=o.Query.filterQueries(e.queries,"onWhere"),t.searches=o.Query.filterQueries(e.queries,"onSearch"),t.aggregates=o.Query.filterQueries(e.queries,"onAggregates"),t},t.prototype.addParams=function(e){var t=e.reqParams;e.params.length&&(t.params={});for(var r=0,n=e.params;r<n.length;r++){var o=n[r];if(t[o.key])throw new Error("Query() - addParams: Custom Param is conflicting other request arguments");t[o.key]=o.value,o.fn&&(t[o.key]=o.fn.call(e.query,o.key,e.query,e.dm)),t.params[o.key]=t[o.key]}},t}(s);t.UrlAdaptor=u;var c=function(e){function t(){var t=e.call(this)||this;return t.options=r.extend({},t.options,{requestType:"get",accept:"application/json;odata=light;q=1,application/json;odata=verbose;q=0.5",multipartAccept:"multipart/mixed",sortBy:"$orderby",select:"$select",skip:"$skip",take:"$top",count:"$inlinecount",where:"$filter",expand:"$expand",batch:"$batch",changeSet:"--changeset_",batchPre:"batch_",contentId:"Content-Id: ",batchContent:"Content-Type: multipart/mixed; boundary=",changeSetContent:"Content-Type: application/http\nContent-Transfer-Encoding: binary ",batchChangeSetContentType:"Content-Type: application/json; charset=utf-8 "}),t.getModuleName=r.getValue("getModulename",t),t}return a(t,e),t.prototype.onPredicate=function(e,o,a){var s,i,u="",c=e.value,l=typeof c,p=e.field?t.getField(e.field):null;if(c instanceof Date&&(c="datetime'"+n.DataUtil.parse.replacer(c)+"'"),"string"===l&&(c="'"+c+"'",a&&(p="cast("+p+", 'Edm.String')"),n.DataUtil.parse.isGuid(c)&&(i="guid"),e.ignoreCase&&(i||(p="tolower("+p+")"),c=c.toLowerCase())),s=n.DataUtil.odBiOperator[e.operator])return u+=p,u+=s,i&&(u+=i),u+c;if(r.isNullOrUndefined(this.getModuleName)?s=n.DataUtil.odUniOperator[e.operator]:"ODataV4Adaptor"===this.getModuleName()&&(s=n.DataUtil.odv4UniOperator[e.operator]),"substringof"===s){var d=c;c=p,p=d}return u+=s+"(",u+=p+",",i&&(u+=i),u+=c+")"},t.prototype.onComplexPredicate=function(e,t,r){for(var n=[],o=0;o<e.predicates.length;o++)n.push("("+this.onEachWhere(e.predicates[o],t,r)+")");return n.join(" "+e.condition+" ")},t.prototype.onEachWhere=function(e,t,r){return e.isComplex?this.onComplexPredicate(e,t,r):this.onPredicate(e,t,r)},t.prototype.onWhere=function(e){return this.pvt.search&&e.push(this.onEachWhere(this.pvt.search,null,!0)),e.join(" and ")},t.prototype.onEachSearch=function(e){e.fields&&0===e.fields.length&&n.DataUtil.throwError("Query() - Search : oData search requires list of field names to search");for(var t=this.pvt.search||[],r=0;r<e.fields.length;r++)t.push(new o.Predicate(e.fields[r],e.operator,e.key,e.ignoreCase));this.pvt.search=t},t.prototype.onSearch=function(e){return this.pvt.search=o.Predicate.or(this.pvt.search),""},t.prototype.onEachSort=function(e){var r=[];if(e.name instanceof Array)for(var n=0;n<e.name.length;n++)r.push(t.getField(e.name[n])+("descending"===e.direction?" desc":""));else r.push(t.getField(e.name)+("descending"===e.direction?" desc":""));return r.join(",")},t.prototype.onSortBy=function(e){return e.reverse().join(",")},t.prototype.onGroup=function(e){return this.pvt.groups=e,[]},t.prototype.onSelect=function(e){for(var r=0;r<e.length;r++)e[r]=t.getField(e[r]);return e.join(",")},t.prototype.onAggregates=function(e){return this.pvt.aggregates=e,""},t.prototype.onCount=function(e){return!0===e?"allpages":""},t.prototype.beforeSend=function(e,t,r){n.DataUtil.endsWith(r.url,this.options.batch)&&"post"===r.type.toLowerCase()?(t.setRequestHeader("Accept",this.options.multipartAccept),t.setRequestHeader("DataServiceVersion","2.0"),t.overrideMimeType("text/plain; charset=x-user-defined")):t.setRequestHeader("Accept",this.options.accept),t.setRequestHeader("DataServiceVersion","2.0"),t.setRequestHeader("MaxDataServiceVersion","2.0")},t.prototype.processResponse=function(e,t,o,a,s,i){if(!r.isNullOrUndefined(e.d)){var u=o&&o.requiresCounts?e.d.results:e.d;if(!r.isNullOrUndefined(u))for(var c=0;c<u.length;c++)r.isNullOrUndefined(u[c].__metadata)||delete u[c].__metadata}var l=s&&s.pvtData,p=this.processBatchResponse(e,o,a,s,i);if(p)return p;var d=a&&s.getResponseHeader("DataServiceVersion"),h=null,f=d&&parseInt(d,10)||2;if(o&&o.requiresCounts){(e.__count||e["odata.count"])&&(h=e.__count||e["odata.count"]),e.d&&(e=e.d),(e.__count||e["odata.count"])&&(h=e.__count||e["odata.count"])}3===f&&e.value&&(e=e.value),e.d&&(e=e.d),f<3&&e.results&&(e=e.results);var g={};return g.count=h,g.result=e,this.getAggregateResult(l,e,g),n.DataUtil.isNull(h)?g.result:{result:g.result,count:g.count,aggregates:g.aggregates}},t.prototype.convertToQueryString=function(e,t,r){var n=[],o=e.table||"";delete e.table,r.dataSource.requiresFormat&&(e.$format="json");for(var a=Object.keys(e),s=0,i=a;s<i.length;s++){var u=i[s];n.push(u+"="+e[u])}return n=n.join("&"),r.dataSource.url&&-1!==r.dataSource.url.indexOf("?")&&!o?n:n.length?o+"?"+n:o||""},t.prototype.insert=function(e,t,r){return{url:e.dataSource.url.replace(/\/*$/,r?"/"+r:""),data:JSON.stringify(t)}},t.prototype.remove=function(e,t,r,n){return{type:"DELETE",url:e.dataSource.url.replace(/\/*$/,n?"/"+n:"")+"("+r+")"}},t.prototype.update=function(e,t,r,n){return{type:"PUT",url:e.dataSource.url.replace(/\/*$/,n?"/"+n:"")+"("+r[t]+")",data:JSON.stringify(r),accept:this.options.accept}},t.prototype.batchRequest=function(e,t,r){var o=r.guid=n.DataUtil.getGuid(this.options.batchPre),a=e.dataSource.url.replace(/\/*$/,"/"+this.options.batch),s={url:r.url,key:r.key,cid:1,cSet:n.DataUtil.getGuid(this.options.changeSet)},i="--"+o+"\n";return i+="Content-Type: multipart/mixed; boundary="+s.cSet.replace("--","")+"\n",this.pvt.changeSet=0,i+=this.generateInsertRequest(t.addedRecords,s),i+=this.generateUpdateRequest(t.changedRecords,s),i+=this.generateDeleteRequest(t.deletedRecords,s),i+=s.cSet+"--\n",i+="--"+o+"--",{type:"POST",url:a,dataType:"json",contentType:"multipart/mixed; charset=UTF-8;boundary="+o,data:i}},t.prototype.generateDeleteRequest=function(e,t){if(!e)return"";var r={method:"DELETE ",url:function(e,t,r){return"("+e[t][r]+")"},data:function(e,t){return""}};return this.generateBodyContent(e,t,r)+"\n"},t.prototype.generateInsertRequest=function(e,t){if(!e)return"";var r={method:"POST ",url:function(e,t,r){return""},data:function(e,t){return JSON.stringify(e[t])+"\n\n"}};return this.generateBodyContent(e,t,r)},t.prototype.generateUpdateRequest=function(e,t){if(!e)return"";var r={method:"PUT ",url:function(e,t,r){return"("+e[t][r]+")"},data:function(e,t){return JSON.stringify(e[t])+"\n\n"}};return this.generateBodyContent(e,t,r)},t.getField=function(e){return e.replace(/\./g,"/")},t.prototype.generateBodyContent=function(e,t,r){for(var n="",o=0;o<e.length;o++)n+="\n"+t.cSet+"\n",n+=this.options.changeSetContent+"\n\n",n+=r.method,n+=t.url+r.url(e,o,t.key)+" HTTP/1.1\n",n+="Accept: "+this.options.accept+"\n",n+="Content-Id: "+this.pvt.changeSet+++"\n",n+=this.options.batchChangeSetContentType+"\n\n",n+=r.data(e,o);return n},t.prototype.processBatchResponse=function(e,t,o,a,s){if(o&&o.getResponseHeader("Content-Type")&&-1!==o.getResponseHeader("Content-Type").indexOf("xml"))return t.requiresCounts?{result:[],count:0}:[];if(a&&this.options.batch&&n.DataUtil.endsWith(a.url,this.options.batch)&&"post"===a.type.toLowerCase()){var i=o.getResponseHeader("Content-Type"),u=void 0,c=void 0;if(i=i.substring(i.indexOf("=batchresponse")+1),e=e.split(i),e.length<2)return{};e=e[1];var l=/(?:\bContent-Type.+boundary=)(changesetresponse.+)/i.exec(e);l&&e.replace(l[0],"");var p=l?l[1]:"";e=e.split(p);for(var d=e.length;d>-1;d--)/\bContent-ID:/i.test(e[d])&&/\bHTTP.+201/.test(e[d])&&(u=parseInt(/\bContent-ID: (\d+)/i.exec(e[d])[1],10),s.addedRecords[u]&&(c=n.DataUtil.parse.parseJson(/^\{.+\}/m.exec(e[d])[0]),r.extend({},s.addedRecords[u],this.processResponse(c))));return s}return null},t}(u);t.ODataAdaptor=c;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.options=r.extend({},t.options,{requestType:"get",accept:"application/json, text/javascript, */*; q=0.01",multipartAccept:"multipart/mixed",sortBy:"$orderby",select:"$select",skip:"$skip",take:"$top",count:"$count",search:"$search",where:"$filter",expand:"$expand",batch:"$batch",changeSet:"--changeset_",batchPre:"batch_",contentId:"Content-Id: ",batchContent:"Content-Type: multipart/mixed; boundary=",changeSetContent:"Content-Type: application/http\nContent-Transfer-Encoding: binary ",batchChangeSetContentType:"Content-Type: application/json; charset=utf-8 "}),t}return a(t,e),t.prototype.getModulename=function(){return"ODataV4Adaptor"},t.prototype.onCount=function(e){return!0===e?"true":""},t.prototype.onPredicate=function(t,r,n){var o="",a=t.value,s=a instanceof Date;return o=e.prototype.onPredicate.call(this,t,r,n),s&&(o=o.replace(/datetime'(.*)'$/,"$1")),o},t.prototype.onEachSearch=function(e){var t=this.pvt.searches||[];t.push(e.key),this.pvt.searches=t},t.prototype.onSearch=function(e){return this.pvt.searches.join(" OR ")},t.prototype.beforeSend=function(e,t,r){t.setRequestHeader("Accept",this.options.accept)},t.prototype.processResponse=function(t,r,o,a,s,i){var u=s&&s.pvtData,c=e.prototype.processBatchResponse.call(this,t,o,a,s,i);if(c)return c;var l=null;o&&o.requiresCounts&&"@odata.count"in t&&(l=t["@odata.count"]),t=t.value;var p={};return p.count=l,p.result=t,this.getAggregateResult(u,t,p),n.DataUtil.isNull(l)?p.result:{result:p.result,count:l,aggregates:p.aggregates}},t}(c);t.ODataV4Adaptor=l;var p=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.insert=function(e,t,r){return{type:"POST",url:e.dataSource.url,data:JSON.stringify(t)}},t.prototype.remove=function(e,t,r,n){return{type:"DELETE",url:e.dataSource.url+"/"+r,data:JSON.stringify(r)}},t.prototype.update=function(e,t,r,n){return{type:"PUT",url:e.dataSource.url,data:JSON.stringify(r)}},t.prototype.beforeSend=function(e,t,r){t.setRequestHeader("Accept","application/json, text/javascript, */*; q=0.01")},t.prototype.processResponse=function(e,t,r,o,a,s){var i=a&&a.pvtData,u=null,c={};if(a&&"post"!==a.type.toLowerCase()){var l=o&&a.getResponseHeader("DataServiceVersion"),p=l&&parseInt(l,10)||2;r&&r.requiresCounts&&(n.DataUtil.isNull(e.Count)||(u=e.Count)),p<3&&e.Items&&(e=e.Items),c.count=u,c.result=e,this.getAggregateResult(i,e,c)}return c.result=c.result||e,n.DataUtil.isNull(u)?c.result:{result:c.result,count:c.count,aggregates:c.aggregates}},t}(c);t.WebApiAdaptor=p;var d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.processQuery=function(e,t,r){var o=(new u).processQuery(e,t,r),a=n.DataUtil.parse.parseJson(o.data),s={};if(a.param)for(var i=0;i<a.param.length;i++){var c=a.param[i],l=Object.keys(c)[0];s[l]=c[l]}s.value=a;return{data:JSON.stringify(s),url:o.url,pvtData:o.pvtData,type:"POST",contentType:"application/json; charset=utf-8"}},t}(u);t.WebMethodAdaptor=d;var h=function(e){function t(){var t=e.call(this)||this;return r.setValue("beforeSend",u.prototype.beforeSend,t),r.setValue("insert",u.prototype.insert,t),r.setValue("update",u.prototype.update,t),r.setValue("remove",u.prototype.remove,t),t}return a(t,e),t.prototype.batchRequest=function(e,t,r){var n;for(n=0;n<t.addedRecords.length;n++)i.prototype.insert(e,t.addedRecords[n]);for(n=0;n<t.changedRecords.length;n++)i.prototype.update(e,r.key,t.changedRecords[n]);for(n=0;n<t.deletedRecords.length;n++)i.prototype.remove(e,r.key,t.deletedRecords[n]);return{type:"POST",url:e.dataSource.batchUrl||e.dataSource.crudUrl||e.dataSource.url,contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({changed:t.changedRecords,added:t.addedRecords,deleted:t.deletedRecords,action:"batch",table:r.url,key:r.key})}},t}(i);t.RemoteSaveAdaptor=h;var f=function(e){function t(t,o,a){var s=e.call(this)||this;s.isCrudAction=!1,s.isInsertAction=!1,r.isNullOrUndefined(t)||(s.cacheAdaptor=t),s.pageSize=a,s.guidId=n.DataUtil.getGuid("cacheAdaptor");var i={keys:[],results:[]};window.localStorage.setItem(s.guidId,JSON.stringify(i));var u=s.guidId;return r.isNullOrUndefined(o)||setInterval(function(){var e;e=n.DataUtil.parse.parseJson(window.localStorage.getItem(u));for(var t=[],r=0;r<e.results.length;r++){var a=+new Date,s=+new Date(e.results[r].timeStamp);e.results[r].timeStamp=a-s,a-s>o&&t.push(r)}for(var r=0;r<t.length;r++)e.results.splice(t[r],1),e.keys.splice(t[r],1);window.localStorage.removeItem(u),window.localStorage.setItem(u,JSON.stringify(e))},o),s}return a(t,e),t.prototype.generateKey=function(e,t){var r=this.getQueryRequest(t),n=o.Query.filterQueryLists(t.queries,["onSelect","onPage","onSkip","onTake","onRange"]),a=e;"onPage"in n&&(a+=n.onPage.pageIndex),r.sorts.forEach(function(e){a+=e.e.direction+e.e.fieldName}),r.groups.forEach(function(e){a+=e.e.fieldName}),r.searches.forEach(function(e){a+=e.e.searchKey});for(var s=0;s<r.filters.length;s++){var i=r.filters[s];if(i.e.isComplex){var u=t.clone();u.queries=[];for(var c=0;c<i.e.predicates.length;c++)u.queries.push({fn:"onWhere",e:i.e.predicates[c],filter:t.queries.filter});a+=i.e.condition+this.generateKey(e,u)}else a+=i.e.field+i.e.operator+i.e.value}return a},t.prototype.processQuery=function(e,t,r){var o,a=this.generateKey(e.dataSource.url,t);o=n.DataUtil.parse.parseJson(window.localStorage.getItem(this.guidId));var s=o?o.results[o.keys.indexOf(a)]:null;return null==s||this.isCrudAction||this.isInsertAction?(this.isCrudAction=null,this.isInsertAction=null,this.cacheAdaptor.processQuery.apply(this.cacheAdaptor,[].slice.call(arguments,0))):s},t.prototype.processResponse=function(e,t,r,o,a,s){if(this.isInsertAction||a&&this.cacheAdaptor.options.batch&&n.DataUtil.endsWith(a.url,this.cacheAdaptor.options.batch)&&"post"===a.type.toLowerCase())return this.cacheAdaptor.processResponse(e,t,r,o,a,s);e=this.cacheAdaptor.processResponse.apply(this.cacheAdaptor,[].slice.call(arguments,0));var i=r?this.generateKey(t.dataSource.url,r):t.dataSource.url,u={};u=n.DataUtil.parse.parseJson(window.localStorage.getItem(this.guidId));var c=u.keys.indexOf(i);for(-1!==c&&(u.results.splice(c,1),u.keys.splice(c,1)),u.results[u.keys.push(i)-1]={keys:i,result:e.result,timeStamp:new Date,count:e.count};u.results.length>this.pageSize;)u.results.splice(0,1),u.keys.splice(0,1);return window.localStorage.setItem(this.guidId,JSON.stringify(u)),e},t.prototype.beforeSend=function(e,t,r){n.DataUtil.endsWith(r.url,this.cacheAdaptor.options.batch)&&"post"===r.type.toLowerCase()&&t.setRequestHeader("Accept",this.cacheAdaptor.options.multipartAccept),e.dataSource.crossDomain||t.setRequestHeader("Accept",this.cacheAdaptor.options.accept)},t.prototype.update=function(e,t,r,n){return this.isCrudAction=!0,this.cacheAdaptor.update(e,t,r,n)},t.prototype.insert=function(e,t,r){return this.isInsertAction=!0,this.cacheAdaptor.insert(e,t,r)},t.prototype.remove=function(e,t,r,n){return this.isCrudAction=!0,this.cacheAdaptor.remove(e,t,r,n)},t.prototype.batchRequest=function(e,t,r){return this.cacheAdaptor.batchRequest(e,t,r)},t}(u);t.CacheAdaptor=f}.apply(t,n))&&(e.exports=o)}])}); | ||
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@syncfusion/ej2-base"));else if("function"==typeof define&&define.amd)define(["@syncfusion/ej2-base"],t);else{var r=t("object"==typeof exports?require("@syncfusion/ej2-base"):e["@syncfusion/ej2-base"]);for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){var n,o;n=[r,t,r(1),r(4),r(5),r(3)],void 0!==(o=function(e,t,r,n,o,a){"use strict";function s(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0}),s(r),s(n),s(o),s(a)}.apply(t,n))&&(e.exports=o)},function(e,t,r){var n,o;n=[r,t,r(2),r(2),r(3),r(4),r(5)],void 0!==(o=function(e,t,r,n,o,a,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t,r){var i=this;this.dateParse=!0,this.requests=[],e||this.dataSource||(e=[]),r=r||e.adaptor;var u;return e instanceof Array?u={json:e,offline:!0}:"object"==typeof e?(e.json||(e.json=[]),u={url:e.url,insertUrl:e.insertUrl,removeUrl:e.removeUrl,updateUrl:e.updateUrl,crudUrl:e.crudUrl,batchUrl:e.batchUrl,json:e.json,headers:e.headers,accept:e.accept,data:e.data,timeTillExpiration:e.timeTillExpiration,cachingPageSize:e.cachingPageSize,enableCaching:e.enableCaching,requestType:e.requestType,key:e.key,crossDomain:e.crossDomain,jsonp:e.jsonp,dataType:e.dataType,offline:void 0!==e.offline?e.offline:!(e.adaptor instanceof s.RemoteSaveAdaptor)&&!e.url,requiresFormat:e.requiresFormat}):o.DataUtil.throwError("DataManager: Invalid arguments"),void 0!==u.requiresFormat||o.DataUtil.isCors()||(u.requiresFormat=!!n.isNullOrUndefined(u.crossDomain)||u.crossDomain),void 0===u.dataType&&(u.dataType="json"),this.dataSource=u,this.defaultQuery=t,u.url&&u.offline&&!u.json.length?(this.isDataAvailable=!1,this.adaptor=r||new s.ODataAdaptor,this.dataSource.offline=!1,this.ready=this.executeQuery(t||new a.Query),this.ready.then(function(e){i.dataSource.offline=!0,i.isDataAvailable=!0,u.json=e.result,i.adaptor=new s.JsonAdaptor})):this.adaptor=u.offline?new s.JsonAdaptor:new s.ODataAdaptor,!u.jsonp&&this.adaptor instanceof s.ODataAdaptor&&(u.jsonp="callback"),this.adaptor=r||this.adaptor,u.enableCaching&&(this.adaptor=new s.CacheAdaptor(this.adaptor,u.timeTillExpiration,u.cachingPageSize)),this}return e.prototype.setDefaultQuery=function(e){return this.defaultQuery=e,this},e.prototype.executeLocal=function(t){this.defaultQuery||t instanceof a.Query||o.DataUtil.throwError("DataManager - executeLocal() : A query is required to execute"),this.dataSource.json||o.DataUtil.throwError("DataManager - executeLocal() : Json data is required to execute"),t=t||this.defaultQuery;var r=this.adaptor.processQuery(this,t);if(t.subQuery){var s=t.subQuery.fromTable,i=t.subQuery.lookups,u=t.isCountRequired?r.result:r;i&&i instanceof Array&&o.DataUtil.buildHierarchy(t.subQuery.fKey,s,u,i,t.subQuery.key);for(var c=0;c<u.length;c++)u[c][s]instanceof Array&&(u[c]=n.extend({},{},u[c]),u[c][s]=this.adaptor.processResponse(t.subQuery.using(new e(u[c][s].slice(0))).executeLocal(),this,t))}return this.adaptor.processResponse(r,this,t)},e.prototype.executeQuery=function(t,r,n,s){var i=this;"function"==typeof t&&(n,n=r,r=t,t=null),t||(t=this.defaultQuery),t instanceof a.Query||o.DataUtil.throwError("DataManager - executeQuery() : A query is required to execute");var c=new u,l={query:t};if(this.dataSource.offline||void 0===this.dataSource.url)e.nextTick(function(){var r=i.executeLocal(t);l=e.getDeferedArgs(t,r,l),c.resolve(l)});else{var p=this.adaptor.processQuery(this,t);this.makeRequest(p,c,l,t)}return c.promise},e.getDeferedArgs=function(e,t,r){return e.isCountRequired?(r.result=t.result,r.count=t.count,r.aggregates=t.aggregates):r.result=t,r},e.nextTick=function(e){(window.setImmediate||window.setTimeout)(e,0)},e.prototype.extendRequest=function(e,t,r){return n.extend({},{type:"GET",dataType:this.dataSource.dataType,crossDomain:this.dataSource.crossDomain,jsonp:this.dataSource.jsonp,cache:!0,processData:!1,onSuccess:t,onFailure:r},e)},e.prototype.makeRequest=function(e,t,n,a){var s=this,i=!!a.subQuerySelector,c=function(e){n.error=e,t.reject(n)},l=function(e,r,o,a,s,i,u){n.xhr=o,n.count=r?parseInt(r.toString(),10):0,n.result=e,n.request=a,n.aggregates=i,n.actual=s,n.virtualSelectRecords=u,t.resolve(n)},p=function(e,t){var r=new u,p={parent:n};a.subQuery.isChild=!0;var d=s.adaptor.processQuery(s,a.subQuery,e?s.adaptor.processResponse(e):t),f=s.makeRequest(d,r,p,a.subQuery);return i||r.then(function(t){e&&(o.DataUtil.buildHierarchy(a.subQuery.fKey,a.subQuery.fromTable,e,t,a.subQuery.key),l(e,t.count,t.xhr))},c),f},d=function(e,t){-1===t.httpRequest.getResponseHeader("Content-Type").indexOf("xml")&&s.dateParse&&(e=o.DataUtil.parse.parseJson(e));var r=s.adaptor.processResponse(e,s,a,t.httpRequest,t),n=0,u=null,c=e.virtualSelectRecords;if(a.isCountRequired&&(n=r.count,u=r.aggregates,r=r.result),!a.subQuery)return void l(r,n,t.httpRequest,t.type,e,u,c);i||p(r,t)},f=this.extendRequest(e,d,c),h=new r.Ajax(f);if(h.beforeSend=function(){s.beforeSend(h.httpRequest,h)},f=h.send(),f.catch(function(e){return!0}),this.requests.push(h),i){var g=void 0,y=a.subQuerySelector.call(this,{query:a.subQuery,parent:a});y&&y.length?(g=Promise.all([f,p(null,y)]),g.then(function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=e[0],n=s.adaptor.processResponse(r[0],s,a,s.requests[0].httpRequest,s.requests[0]),u=0;a.isCountRequired&&(u=n.count,n=n.result);var c=s.adaptor.processResponse(r[1],s,a.subQuery,s.requests[1].httpRequest,s.requests[1]);u=0,a.subQuery.isCountRequired&&(u=c.count,c=c.result),o.DataUtil.buildHierarchy(a.subQuery.fKey,a.subQuery.fromTable,n,c,a.subQuery.key),i=!1,l(n,u,s.requests[0].httpRequest)})):i=!1}return f},e.prototype.beforeSend=function(e,t){this.adaptor.beforeSend(this,e,t);for(var r,n=this.dataSource.headers,o=0;n&&o<n.length;o++){r=[];for(var a=Object.keys(n[o]),s=0,i=a;s<i.length;s++){var u=i[s];r.push(u),e.setRequestHeader(u,n[o][u])}}},e.prototype.saveChanges=function(e,t,n,o){var s=this;n instanceof a.Query&&(o=n,n=null);var i={url:n,key:t||this.dataSource.key},c=this.adaptor.batchRequest(this,e,i,o);if(this.dataSource.offline)return c;var l=new u,p=new r.Ajax(c);return p.beforeSend=function(){s.beforeSend(p.httpRequest,p)},p.onSuccess=function(t,r){l.resolve(s,[s.adaptor.processResponse(t,s,null,r.httpRequest,r,e)])},p.onFailure=function(e){l.reject([{error:e}])},p.send().catch(function(e){return!0}),l.promise},e.prototype.insert=function(e,t,r,n){e=o.DataUtil.parse.replacer(e),t instanceof a.Query&&(r=t,t=null);var s=this.adaptor.insert(this,e,t,r,n);return this.dataSource.offline?s:this.doAjaxRequest(s)},e.prototype.remove=function(e,t,r,n){"object"==typeof t&&(t=t[e]),r instanceof a.Query&&(n=r,r=null);var o=this.adaptor.remove(this,e,t,r,n);return this.dataSource.offline?o:this.doAjaxRequest(o)},e.prototype.update=function(e,t,r,n){t=o.DataUtil.parse.replacer(t,!this.dataSource.offline),r instanceof a.Query&&(n=r,r=null);var s=this.adaptor.update(this,e,t,r,n);return this.dataSource.offline?s:this.doAjaxRequest(s)},e.prototype.doAjaxRequest=function(e){var t=this,a=new u;e=n.extend({},{type:"POST",contentType:"application/json; charset=utf-8",processData:!1},e);var s=new r.Ajax(e);return s.beforeSend=function(){t.beforeSend(s.httpRequest,s)},s.onSuccess=function(e,r){try{o.DataUtil.parse.parseJson(e)}catch(t){e=[]}e=t.adaptor.processResponse(o.DataUtil.parse.parseJson(e),t,null,r.httpRequest,r),a.resolve(t,[{record:e,dataManager:t}])},s.onFailure=function(e){a.reject([{error:e}])},s.send().catch(function(e){return!0}),a.promise},e}();t.DataManager=i;var u=function(){function e(){var e=this;this.promise=new Promise(function(t,r){e.resolve=t,e.reject=r}),this.then=this.promise.then.bind(this.promise),this.catch=this.promise.catch.bind(this.promise)}return e}();t.Deferred=u}.apply(t,n))&&(e.exports=o)},function(t,r){t.exports=e},function(e,t,r){var n,o;n=[r,t,r(2),r(1),r(4)],void 0!==(o=function(e,t,r,n,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var a={GroupGuid:"{271bbba0-1ee7}"},s=function(){function e(){}return e.getValue=function(e,t){return"function"==typeof e?e.call(t||{}):e},e.endsWith=function(e,t){return e.slice(-t.length)===t},e.startsWith=function(e,t){return e.slice(0,t.length)===t},e.fnSort=function(e){return e=e?e.toLowerCase():"ascending","ascending"===e?this.fnAscending:this.fnDescending},e.fnAscending=function(e,t){return null===t||void 0===t?-1:"string"==typeof e?e.localeCompare(t):null===e||void 0===e?1:e-t},e.fnDescending=function(e,t){return null===t||void 0===t?1:"string"==typeof e?-1*e.localeCompare(t):null===e||void 0===e?-1:t-e},e.extractFields=function(e,t){var r={};if(1===t.length)return this.getObject(t[0],e);for(var n=0;n<t.length;n++)r[t[n].replace(".","_")]=this.getObject(t[n],e);return r},e.select=function(e,t){for(var r=[],n=0;n<e.length;n++)r.push(this.extractFields(e[n],t));return r},e.group=function(t,n,o,s,i,u){s=s||1;var c=t;if(c.GroupGuid===a.GroupGuid){for(var l=this,p=0;p<c.length;p++)!function(e){if(r.isNullOrUndefined(i))c[e].items=l.group(c[e].items,n,o,c.level+1,null,u),c[e].count=c[e].items.length;else{var t=-1,a=i.filter(function(t){return t.key===c[e].key});t=i.indexOf(a[0]),c[e].items=l.group(c[e].items,n,o,c.level+1,i[t].items,u),c[e].count=i[t].count}}(p);return c.childLevels+=1,c}var d={},f=[];f.GroupGuid=a.GroupGuid,f.level=s,f.childLevels=0,f.records=c;for(var h=this,g=0;g<c.length;g++)!function(e){var t=h.getVal(c,e,n);if(r.isNullOrUndefined(u)||(t=u(t,n)),!d[t]&&(d[t]={key:t,count:0,items:[],aggregates:{},field:n},f.push(d[t]),!r.isNullOrUndefined(i))){var o=i.filter(function(e){return e.key===d[t].key});d[t].count=o[0].count}d[t].count=r.isNullOrUndefined(i)?d[t].count+=1:d[t].count,d[t].items.push(c[e])}(g);if(o&&o.length)for(var g=0;g<f.length;g++)!function(t){for(var n={},a=void 0,s=o,u=0;u<o.length;u++)if(a=e.aggregates[o[u].type],r.isNullOrUndefined(i))a&&(n[s[u].field+" - "+s[u].type]=a(f[t].items,s[u].field));else{var c=i.filter(function(e){return e.key===f[t].key});a&&(n[s[u].field+" - "+s[u].type]=a(c[0].items,s[u].field))}f[t].aggregates=n}(g);return f},e.buildHierarchy=function(e,t,r,n,o){var a,s,i={};for(n.result&&(n=n.result),n.GroupGuid&&this.throwError("DataManager: Do not have support Grouping in hierarchy"),a=0;a<n.length;a++){var u=this.getObject(e,n[a]);s=i[u]||(i[u]=[]),s.push(n[a])}for(a=0;a<r.length;a++){var u=this.getObject(o||e,r[a]);r[a][t]=i[u]}},e.getFieldList=function(e,t,r){if(void 0===r&&(r=""),void 0===t||null===t)return this.getFieldList(e,[],r);for(var n=e,o=Object.keys(e),a=0,s=o;a<s.length;a++){var i=s[a];"object"!=typeof n[i]||n[i]instanceof Array?t.push(r+i):this.getFieldList(n[i],t,r+i+".")}return t},e.getObject=function(e,t){if(!e)return t;if(-1===e.indexOf("."))return t[e];for(var r=t,n=e.split("."),o=0;o<n.length&&null!=r;o++)r=r[n[o]];return r},e.sort=function(e,t,r){if(e.length<=1)return e;var n=parseInt((e.length/2).toString(),10),o=e.slice(0,n),a=e.slice(n);return o=this.sort(o,t,r),a=this.sort(a,t,r),this.merge(o,a,t,r)},e.merge=function(e,t,r,n){for(var o,a=[];e.length>0||t.length>0;)o=e.length>0&&t.length>0?n?n(this.getVal(e,0,r),this.getVal(t,0,r))<=0?e:t:e[0][r]<e[0][r]?e:t:e.length>0?e:t,a.push(o.shift());return a},e.getVal=function(e,t,r){return r?this.getObject(r,e[t]):e[t]},e.toLowerCase=function(e){return e?"string"==typeof e?e.toLowerCase():e.toString():0===e||!1===e?e.toString():""},e.callAdaptorFunction=function(e,t,r,n){if(t in e){var o=e[t](r,n);this.fnOperators.isnull(o)||(r=o)}return r},e.isPlainObject=function(e){return!!e&&e.constructor===Object},e.isCors=function(){var e=null;try{e=new window.XMLHttpRequest}catch(e){}return!!e&&"withCredentials"in e},e.getGuid=function(e){var t;return(e||"")+"00000000-0000-4000-0000-000000000000".replace(/0/g,function(e,r){if("crypto"in window&&"getRandomValues"in crypto){var n=new Uint8Array(1);window.crypto.getRandomValues(n),t=n[0]%16|0}else t=16*Math.random()|0;return"0123456789abcdef"[19===r?3&t|8:t]})},e.isNull=function(e){return void 0===e||null===e},e.getItemFromComparer=function(t,n,o){var a,s,i,u=0,c="string"==typeof e.getVal(t,0,n);if(t.length)for(;r.isNullOrUndefined(a)&&u<t.length;)a=e.getVal(t,u,n),i=t[u++];for(;u<t.length;u++)s=e.getVal(t,u,n),r.isNullOrUndefined(s)||(c&&(a=+a,s=+s),o(a,s)>0&&(a=s,i=t[u]));return i},e.distinct=function(t,n,o){o=!r.isNullOrUndefined(o)&&o;var a,s=[],i={};return t.forEach(function(r,u){(a=e.getVal(t,u,n))in i||(s.push(o?t[u]:a),i[a]=1)}),s},e.serverTimezoneOffset=0,e.throwError=function(e){try{throw new Error(e)}catch(e){throw e.message+"\n"+e.stack}},e.aggregates={sum:function(t,r){for(var n,o=0,a="number"!=typeof e.getVal(t,0,r),s=0;s<t.length;s++)n=e.getVal(t,s,r),isNaN(n)||null===n||(a&&(n=+n),o+=n);return o},average:function(t,r){return e.aggregates.sum(t,r)/t.length},min:function(t,r){var n;return"function"==typeof r&&(n=r,r=null),e.getObject(r,e.getItemFromComparer(t,r,n||e.fnAscending))},max:function(t,r){var n;return"function"==typeof r&&(n=r,r=null),e.getObject(r,e.getItemFromComparer(t,r,n||e.fnDescending))},truecount:function(e,t){return new n.DataManager(e).executeLocal((new o.Query).where(t,"equal",!0,!0)).length},falsecount:function(e,t){return new n.DataManager(e).executeLocal((new o.Query).where(t,"equal",!1,!0)).length},count:function(e,t){return e.length}},e.operatorSymbols={"<":"lessthan",">":"greaterthan","<=":"lessthanorequal",">=":"greaterthanorequal","==":"equal","!=":"notequal","*=":"contains","$=":"endswith","^=":"startswith"},e.odBiOperator={"<":" lt ",">":" gt ","<=":" le ",">=":" ge ","==":" eq ","!=":" ne ",lessthan:" lt ",lessthanorequal:" le ",greaterthan:" gt ",greaterthanorequal:" ge ",equal:" eq ",notequal:" ne "},e.odUniOperator={"$=":"endswith","^=":"startswith","*=":"substringof",endswith:"endswith",startswith:"startswith",contains:"substringof"},e.odv4UniOperator={"$=":"endswith","^=":"startswith","*=":"contains",endswith:"endswith",startswith:"startswith",contains:"contains"},e.fnOperators={equal:function(t,r,n){return n?e.toLowerCase(t)===e.toLowerCase(r):t===r},notequal:function(t,r,n){return!e.fnOperators.equal(t,r,n)},lessthan:function(t,r,n){return n?e.toLowerCase(t)<e.toLowerCase(r):t<r},greaterthan:function(t,r,n){return n?e.toLowerCase(t)>e.toLowerCase(r):t>r},lessthanorequal:function(t,r,n){return n?e.toLowerCase(t)<=e.toLowerCase(r):t<=r},greaterthanorequal:function(t,r,n){return n?e.toLowerCase(t)>=e.toLowerCase(r):t>=r},contains:function(t,n,o){return o?!r.isNullOrUndefined(t)&&!r.isNullOrUndefined(n)&&-1!==e.toLowerCase(t).indexOf(e.toLowerCase(n)):!r.isNullOrUndefined(t)&&!r.isNullOrUndefined(n)&&-1!==t.toString().indexOf(n)},notnull:function(e){return null!==e},isnull:function(e){return null===e},startswith:function(t,r,n){return n?t&&r&&e.startsWith(t.toLowerCase(),r.toLowerCase()):t&&r&&e.startsWith(t,r)},endswith:function(t,r,n){return n?t&&r&&e.endsWith(t.toLowerCase(),r.toLowerCase()):t&&r&&e.endsWith(t,r)},processSymbols:function(t){var r=e.operatorSymbols[t];if(r){return e.fnOperators[r]}return e.throwError("Query - Process Operator : Invalid operator")},processOperator:function(t){var r=e.fnOperators[t];return r||e.fnOperators.processSymbols(t)}},e.parse={parseJson:function(t){return"string"==typeof t?t=JSON.parse(t,e.parse.jsonReviver):t instanceof Array?e.parse.iterateAndReviveArray(t):"object"==typeof t&&e.parse.iterateAndReviveJson(t),t},iterateAndReviveArray:function(t){for(var r=0;r<t.length;r++)"object"==typeof t[r]?e.parse.iterateAndReviveJson(t[r]):"string"!=typeof t[r]||/^[\s]*\[|^[\s]*\{|\"/g.test(t[r])?t[r]=e.parse.parseJson(t[r]):t[r]=e.parse.jsonReviver("",t[r])},iterateAndReviveJson:function(t){for(var r,n=Object.keys(t),o=0,a=n;o<a.length;o++){var s=a[o];e.startsWith(s,"__")||(r=t[s],"object"==typeof r?r instanceof Array?e.parse.iterateAndReviveArray(r):r&&e.parse.iterateAndReviveJson(r):t[s]=e.parse.jsonReviver(t[s],r))}},jsonReviver:function(t,r){var n=r;if("string"==typeof r){var o=/^\/Date\(([+-]?[0-9]+)([+-][0-9]{4})?\)\/$/.exec(r);if(o)return e.parse.jsonReplacer({value:new Date(parseInt(o[1],10))},!1).value;if(/^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*){1})([zZ]|([+\-])(\d\d):?(\d\d))?$/.test(r)){var a=n.split(/[^0-9]/);r=e.parse.jsonReplacer({value:new Date(parseInt(a[0],10),parseInt(a[1],10)-1,parseInt(a[2],10),parseInt(a[3],10),parseInt(a[4],10),parseInt(a[5],10))},!1).value}}return r},isJson:function(t){return"string"==typeof t[0]?t:e.parse.parseJson(t)},isGuid:function(e){return null!=/[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}/i.exec(e)},replacer:function(t,r){return e.isPlainObject(t)?e.parse.jsonReplacer(t,r):t instanceof Array?e.parse.arrayReplacer(t):t instanceof Date?e.parse.jsonReplacer({val:t},r).val:t},jsonReplacer:function(t,r){void 0===r&&(r=!0);for(var n,o=Object.keys(t),a=0,s=o;a<s.length;a++){var i=s[a];if((n=t[i])instanceof Date){var u=n,c=+u-6e4*u.getTimezoneOffset();t[i]=new Date(c-36e5*e.serverTimezoneOffset),r&&(t[i]=t[i].toJSON())}}return t},arrayReplacer:function(t){for(var r=0;r<t.length;r++)e.isPlainObject(t[r])?t[r]=e.parse.jsonReplacer(t[r]):t[r]instanceof Date&&(t[r]=e.parse.jsonReplacer({date:t[r]}).date);return t}},e}();t.DataUtil=s}.apply(t,n))&&(e.exports=o)},function(e,t,r){var n,o;n=[r,t,r(3)],void 0!==(o=function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e){return this.subQuery=null,this.isChild=!1,this.queries=[],this.key="",this.fKey="","string"==typeof e?this.fromTable=e:e&&e instanceof Array&&(this.lookups=e),this.expands=[],this.sortedColumns=[],this.groupedColumns=[],this.subQuery=null,this.isChild=!1,this.params=[],this}return e.prototype.setKey=function(e){return this.key=e,this},e.prototype.using=function(e){return this.dataManager=e,this},e.prototype.execute=function(e,t,n,o){return e=e||this.dataManager,e?e.executeQuery(this,t,n,o):r.DataUtil.throwError('Query - execute() : dataManager needs to be is set using "using" function or should be passed as argument')},e.prototype.executeLocal=function(e){return e=e||this.dataManager,e?e.executeLocal(this):r.DataUtil.throwError('Query - executeLocal() : dataManager needs to be is set using "using" function or should be passed as argument')},e.prototype.clone=function(){var t=new e;return t.queries=this.queries.slice(0),t.key=this.key,t.isChild=this.isChild,t.dataManager=this.dataManager,t.fromTable=this.fromTable,t.params=this.params.slice(0),t.expands=this.expands.slice(0),t.sortedColumns=this.sortedColumns.slice(0),t.groupedColumns=this.groupedColumns.slice(0),t.subQuerySelector=this.subQuerySelector,t.subQuery=this.subQuery,t.fKey=this.fKey,t.isCountRequired=this.isCountRequired,t},e.prototype.from=function(e){return this.fromTable=e,this},e.prototype.addParams=function(e,t){return"function"==typeof t?this.params.push({key:e,fn:t}):this.params.push({key:e,value:t}),this},e.prototype.expand=function(e){return this.expands="string"==typeof e?[].slice.call([e],0):e.slice(0),this},e.prototype.where=function(e,t,r,n){t=t?t.toLowerCase():null;var a=null;return"string"==typeof e?a=new o(e,t,r,n):e instanceof o&&(a=e),this.queries.push({fn:"onWhere",e:a}),this},e.prototype.search=function(e,t,n,o){"string"==typeof t&&(t=[t]),n=n||"contains";var a=r.DataUtil.fnOperators[n];return this.queries.push({fn:"onSearch",e:{fieldNames:t,operator:n,searchKey:e,ignoreCase:o,comparer:a}}),this},e.prototype.sortBy=function(t,n,o){var a,s,i="ascending";if("string"==typeof t&&r.DataUtil.endsWith(t.toLowerCase()," desc")&&(t=t.replace(/ desc$/i,""),n="descending"),n&&"string"!=typeof n||(i=n?n.toLowerCase():"ascending",n=r.DataUtil.fnSort(n)),o){a=e.filterQueries(this.queries,"onSortBy");for(var u=0;u<a.length;u++)if("string"==typeof(s=a[u].e.fieldName)){if(s===t)return this}else if(s instanceof Array)for(var c=0;c<s.length;c++)if(s[c]===t||t.toLowerCase()===s[c]+" desc")return this}return this.queries.push({fn:"onSortBy",e:{fieldName:t,comparer:n,direction:i}}),this},e.prototype.sortByDesc=function(e){return this.sortBy(e,"descending")},e.prototype.group=function(e,t,r){return this.sortBy(e,null,!0),this.queries.push({fn:"onGroup",e:{fieldName:e,comparer:t||null,format:r||null}}),this},e.prototype.page=function(e,t){return this.queries.push({fn:"onPage",e:{pageIndex:e,pageSize:t}}),this},e.prototype.range=function(e,t){return this.queries.push({fn:"onRange",e:{start:e,end:t}}),this},e.prototype.take=function(e){return this.queries.push({fn:"onTake",e:{nos:e}}),this},e.prototype.skip=function(e){return this.queries.push({fn:"onSkip",e:{nos:e}}),this},e.prototype.select=function(e){return"string"==typeof e&&(e=[].slice.call([e],0)),this.queries.push({fn:"onSelect",e:{fieldNames:e}}),this},e.prototype.hierarchy=function(e,t){return this.subQuerySelector=t,this.subQuery=e,this},e.prototype.foreignKey=function(e){return this.fKey=e,this},e.prototype.requiresCount=function(){return this.isCountRequired=!0,this},e.prototype.aggregate=function(e,t){return this.queries.push({fn:"onAggregates",e:{field:t,type:e}}),this},e.filterQueries=function(e,t){return e.filter(function(e){return e.fn===t})},e.filterQueryLists=function(e,t){for(var r=e.filter(function(e){return-1!==t.indexOf(e.fn)}),n={},o=0;o<r.length;o++)n[r[o].fn]||(n[r[o].fn]=r[o].e);return n},e}();t.Query=n;var o=function(){function e(t,n,o,a){return void 0===a&&(a=!1),this.isComplex=!1,"string"==typeof t?(this.field=t,this.operator=n.toLowerCase(),this.value=o,this.ignoreCase=a,this.isComplex=!1,this.comparer=r.DataUtil.fnOperators.processOperator(this.operator)):(t instanceof e&&o instanceof e||o instanceof Array)&&(this.isComplex=!0,this.condition=n.toLowerCase(),this.predicates=[t],o instanceof Array?[].push.apply(this.predicates,o):this.predicates.push(o)),this}return e.and=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e.combinePredicates([].slice.call(t,0),"and")},e.prototype.and=function(t,r,n,o){return e.combine(this,t,r,n,"and",o)},e.or=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e.combinePredicates([].slice.call(t,0),"or")},e.prototype.or=function(t,r,n,o){return e.combine(this,t,r,n,"or",o)},e.fromJson=function(e){if(e instanceof Array){for(var t=[],r=0,n=e.length;r<n;r++)t.push(this.fromJSONData(e[r]));return t}var o=e;return this.fromJSONData(o)},e.prototype.validate=function(e){var t,n,o=this.predicates?this.predicates:[];if(!this.isComplex&&this.comparer)return this.comparer.call(this,r.DataUtil.getObject(this.field,e),this.value,this.ignoreCase);t="and"===this.condition;for(var a=0;a<o.length;a++)if(n=o[a].validate(e),t){if(!n)return!1}else if(n)return!0;return t},e.prototype.toJson=function(){var e,t;if(this.isComplex){e=[],t=this.predicates;for(var r=0;r<t.length;r++)e.push(t[r].toJson())}return{isComplex:this.isComplex,field:this.field,operator:this.operator,value:this.value,ignoreCase:this.ignoreCase,condition:this.condition,predicates:e}},e.combinePredicates=function(t,r){if(1===t.length){if(!(t[0]instanceof Array))return t[0];t=t[0]}return new e(t[0],r,t.slice(1))},e.combine=function(t,n,o,a,s,i){return n instanceof e?e[s](t,n):"string"==typeof n?e[s](t,new e(n,o,a,i)):r.DataUtil.throwError("Predicate - "+s+" : invalid arguments")},e.fromJSONData=function(t){for(var r=t.predicates||[],n=r.length,o=[],a=0;a<n;a++)o.push(this.fromJSONData(r[a]));return t.isComplex?new e(o[0],t.condition,o.slice(1)):new e(t.field,t.operator,t.value,t.ignoreCase)},e}();t.Predicate=o}.apply(t,n))&&(e.exports=o)},function(e,t,r){var n,o,a=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}();n=[r,t,r(2),r(3),r(4)],void 0!==(o=function(e,t,r,n,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(t){this.options={from:"table",requestType:"json",sortBy:"sorted",select:"select",skip:"skip",group:"group",take:"take",search:"search",count:"requiresCounts",where:"where",aggregates:"aggregates"},this.type=e,this.dataSource=t,this.pvt={}}return e.prototype.processResponse=function(e,t,r,n){return e},e}();t.Adaptor=s;var i=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.processQuery=function(e,t){for(var r,n,o=e.dataSource.json.slice(0),a=o.length,s=!0,i={},u=0;u<t.queries.length;u++)n=t.queries[u],r=this[n.fn].call(this,o,n.e,t),"onAggregates"===n.fn?i[n.e.field+" - "+n.e.type]=r:o=void 0!==r?r:o,"onPage"!==n.fn&&"onSkip"!==n.fn&&"onTake"!==n.fn&&"onRange"!==n.fn||(s=!1),s&&(a=o.length);return t.isCountRequired&&(o={result:o,count:a,aggregates:i}),o},t.prototype.batchRequest=function(e,t,r){var n;for(n=0;n<t.addedRecords.length;n++)this.insert(e,t.addedRecords[n]);for(n=0;n<t.changedRecords.length;n++)this.update(e,r.key,t.changedRecords[n]);for(n=0;n<t.deletedRecords.length;n++)this.remove(e,r.key,t.deletedRecords[n]);return t},t.prototype.onWhere=function(e,t){return e&&e.length?e.filter(function(e){if(t)return t.validate(e)}):e},t.prototype.onAggregates=function(e,t){var r=n.DataUtil.aggregates[t.type];return e&&r&&0!==e.length?r(e,t.field):null},t.prototype.onSearch=function(e,t){return e&&e.length?(0===t.fieldNames.length&&n.DataUtil.getFieldList(e[0],t.fieldNames),e.filter(function(e){for(var r=0;r<t.fieldNames.length;r++)if(t.comparer.call(e,n.DataUtil.getObject(t.fieldNames[r],e),t.searchKey,t.ignoreCase))return!0;return!1})):e},t.prototype.onSortBy=function(e,t,r){if(!e||!e.length)return e;var o,a=n.DataUtil.getValue(t.fieldName,r);if(!a)return e.sort(t.comparer);if(a instanceof Array){a=a.slice(0);for(var s=a.length-1;s>=0;s--)a[s]&&(o=t.comparer,n.DataUtil.endsWith(a[s]," desc")&&(o=n.DataUtil.fnSort("descending"),a[s]=a[s].replace(" desc","")),e=n.DataUtil.sort(e,a[s],o));return e}return n.DataUtil.sort(e,a,t.comparer)},t.prototype.onGroup=function(e,t,r){if(!e||!e.length)return e;var a=o.Query.filterQueries(r.queries,"onAggregates"),s=[];if(a.length)for(var i=void 0,u=0;u<a.length;u++)i=a[u].e,s.push({type:i.type,field:n.DataUtil.getValue(i.field,r)});return n.DataUtil.group(e,n.DataUtil.getValue(t.fieldName,r),s,null,null,t.comparer)},t.prototype.onPage=function(e,t,r){var o=n.DataUtil.getValue(t.pageSize,r),a=(n.DataUtil.getValue(t.pageIndex,r)-1)*o,s=a+o;return e&&e.length?e.slice(a,s):e},t.prototype.onRange=function(e,t){return e&&e.length?e.slice(n.DataUtil.getValue(t.start),n.DataUtil.getValue(t.end)):e},t.prototype.onTake=function(e,t){return e&&e.length?e.slice(0,n.DataUtil.getValue(t.nos)):e},t.prototype.onSkip=function(e,t){return e&&e.length?e.slice(n.DataUtil.getValue(t.nos)):e},t.prototype.onSelect=function(e,t){return e&&e.length?n.DataUtil.select(e,n.DataUtil.getValue(t.fieldNames)):e},t.prototype.insert=function(e,t,n,o,a){return r.isNullOrUndefined(a)?e.dataSource.json.push(t):e.dataSource.json.splice(a,0,t)},t.prototype.remove=function(e,t,r,n){var o,a=e.dataSource.json;for("object"==typeof r&&(r=r[t]),o=0;o<a.length&&a[o][t]!==r;o++);return o!==a.length?a.splice(o,1):null},t.prototype.update=function(e,t,n,o){var a,s=e.dataSource.json,i=n[t];for(a=0;a<s.length&&s[a][t]!==i;a++);return a<s.length?r.merge(s[a],n):null},t}(s);t.JsonAdaptor=i;var u=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.processQuery=function(e,t,r){var a,s,i=this.getQueryRequest(t),u=o.Query.filterQueryLists(t.queries,["onSelect","onPage","onSkip","onTake","onRange"]),c=t.params,l=e.dataSource.url,p=null,d=this.options,f={sorts:[],groups:[],filters:[],searches:[],aggregates:[]};"onPage"in u?(a=u.onPage,s=n.DataUtil.getValue(a.pageIndex,t),p=n.DataUtil.getValue(a.pageSize,t),s=(s-1)*p):"onRange"in u&&(a=u.onRange,s=a.start,p=a.end-a.start);for(var h=0;h<i.sorts.length;h++)a=n.DataUtil.getValue(i.sorts[h].e.fieldName,t),f.sorts.push(n.DataUtil.callAdaptorFunction(this,"onEachSort",{name:a,direction:i.sorts[h].e.direction},t));r&&(a=this.getFiltersFrom(r,t))&&f.filters.push(n.DataUtil.callAdaptorFunction(this,"onEachWhere",a.toJson(),t));for(var h=0;h<i.filters.length;h++){f.filters.push(n.DataUtil.callAdaptorFunction(this,"onEachWhere",i.filters[h].e.toJson(),t));for(var g="object"==typeof f.filters[h]?Object.keys(f.filters[h]):[],y=0,v=g;y<v.length;y++){var m=v[y];n.DataUtil.isNull(f[m])&&delete f[m]}}for(var h=0;h<i.searches.length;h++)a=i.searches[h].e,f.searches.push(n.DataUtil.callAdaptorFunction(this,"onEachSearch",{fields:a.fieldNames,operator:a.operator,key:a.searchKey,ignoreCase:a.ignoreCase},t));for(var h=0;h<i.groups.length;h++)f.groups.push(n.DataUtil.getValue(i.groups[h].e.fieldName,t));for(var h=0;h<i.aggregates.length;h++)a=i.aggregates[h].e,f.aggregates.push({type:a.type,field:n.DataUtil.getValue(a.field,t)});var S={};this.getRequestQuery(d,t,u,f,S),n.DataUtil.callAdaptorFunction(this,"addParams",{dm:e,query:t,params:c,reqParams:S});for(var b=Object.keys(S),D=0,R=b;D<R.length;D++){var m=R[D];(n.DataUtil.isNull(S[m])||""===S[m]||0===S[m].length)&&delete S[m]}d.skip in S&&d.take in S||null===p||(S[d.skip]=n.DataUtil.callAdaptorFunction(this,"onSkip",s,t),S[d.take]=n.DataUtil.callAdaptorFunction(this,"onTake",p,t));var q=this.pvt;return this.pvt={},"json"===this.options.requestType?{data:JSON.stringify(S),url:l,pvtData:q,type:"POST",contentType:"application/json; charset=utf-8"}:(a=this.convertToQueryString(S,t,e),a=(-1!==e.dataSource.url.indexOf("?")?"&":"/")+a,{type:"GET",url:a.length?l.replace(/\/*$/,a):l,pvtData:q})},t.prototype.getRequestQuery=function(e,t,r,o,a){var s=a;s[e.from]=t.fromTable,e.expand&&(s[e.expand]=t.expands),s[e.select]="onSelect"in r?n.DataUtil.callAdaptorFunction(this,"onSelect",n.DataUtil.getValue(r.onSelect.fieldNames,t),t):"",s[e.count]=t.isCountRequired?n.DataUtil.callAdaptorFunction(this,"onCount",t.isCountRequired,t):"",s[e.search]=o.searches.length?n.DataUtil.callAdaptorFunction(this,"onSearch",o.searches,t):"",s[e.skip]="onSkip"in r?n.DataUtil.callAdaptorFunction(this,"onSkip",n.DataUtil.getValue(r.onSkip.nos,t),t):"",s[e.take]="onTake"in r?n.DataUtil.callAdaptorFunction(this,"onTake",n.DataUtil.getValue(r.onTake.nos,t),t):"",s[e.where]=o.filters.length||o.searches.length?n.DataUtil.callAdaptorFunction(this,"onWhere",o.filters,t):"",s[e.sortBy]=o.sorts.length?n.DataUtil.callAdaptorFunction(this,"onSortBy",o.sorts,t):"",s[e.group]=o.groups.length?n.DataUtil.callAdaptorFunction(this,"onGroup",o.groups,t):"",s[e.aggregates]=o.aggregates.length?n.DataUtil.callAdaptorFunction(this,"onAggregates",o.aggregates,t):"",s.param=[]},t.prototype.convertToQueryString=function(e,t,r){return""},t.prototype.processResponse=function(e,t,r,o,a,s){var i=a,u=i.pvtData||{},c=e.groupDs;if(o&&o.getResponseHeader("Content-Type")&&-1!==o.getResponseHeader("Content-Type").indexOf("xml"))return r.isCountRequired?{result:[],count:0}:[];var l=JSON.parse(i.data);if(l&&"batch"===l.action&&e.addedRecords)return s.addedRecords=e.addedRecords,s;e.d&&(e=e.d);var p={};return"count"in e&&(p.count=e.count),p.result=e.result?e.result:e,this.getAggregateResult(u,e,p,c),n.DataUtil.isNull(p.count)?p.result:{result:p.result,count:p.count,aggregates:p.aggregates}},t.prototype.onGroup=function(e){return this.pvt.groups=e,e},t.prototype.onAggregates=function(e){this.pvt.aggregates=e},t.prototype.batchRequest=function(e,t,r){return{type:"POST",url:e.dataSource.batchUrl||e.dataSource.crudUrl||e.dataSource.removeUrl||e.dataSource.url,contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({changed:t.changedRecords,added:t.addedRecords, | ||
deleted:t.deletedRecords,action:"batch",table:r[void 0],key:r[void 0]})}},t.prototype.beforeSend=function(e,t){},t.prototype.insert=function(e,t,r){return{url:e.dataSource.insertUrl||e.dataSource.crudUrl||e.dataSource.url,data:JSON.stringify({value:t,table:r,action:"insert"})}},t.prototype.remove=function(e,t,r,n){return{type:"POST",url:e.dataSource.removeUrl||e.dataSource.crudUrl||e.dataSource.url,data:JSON.stringify({key:r,keyColumn:t,table:n,action:"remove"})}},t.prototype.update=function(e,t,r,n){return{type:"POST",url:e.dataSource.updateUrl||e.dataSource.crudUrl||e.dataSource.url,data:JSON.stringify({value:r,action:"update",keyColumn:t,key:r[t],table:n})}},t.prototype.getFiltersFrom=function(e,t){var r,a=t.fKey,s=a,i=t.key,u=[];"object"!=typeof e[0]&&(s=null);for(var c=0;c<e.length;c++)r="object"==typeof e[0]?n.DataUtil.getObject(i||s,e[c]):e[c],u.push(new o.Predicate(a,"equal",r));return o.Predicate.or(u)},t.prototype.getAggregateResult=function(e,t,o,a){var s=t;if(t&&t.result&&(s=t.result),e&&e.aggregates&&e.aggregates.length){var i=e.aggregates,u=void 0,c=s,l={};t.aggregate&&(c=t.aggregate);for(var p=0;p<i.length;p++)(u=n.DataUtil.aggregates[i[p].type])&&(l[i[p].field+" - "+i[p].type]=u(c,i[p].field));o.aggregates=l}if(e&&e.groups&&e.groups.length){for(var d=e.groups,p=0;p<d.length;p++){r.isNullOrUndefined(a)||(a=n.DataUtil.group(a,d[p])),s=n.DataUtil.group(s,d[p],e.aggregates,null,a)}o.result=s}return o},t.prototype.getQueryRequest=function(e){var t={sorts:[],groups:[],filters:[],searches:[],aggregates:[]};return t.sorts=o.Query.filterQueries(e.queries,"onSortBy"),t.groups=o.Query.filterQueries(e.queries,"onGroup"),t.filters=o.Query.filterQueries(e.queries,"onWhere"),t.searches=o.Query.filterQueries(e.queries,"onSearch"),t.aggregates=o.Query.filterQueries(e.queries,"onAggregates"),t},t.prototype.addParams=function(e){var t=e.reqParams;e.params.length&&(t.params={});for(var r=0,n=e.params;r<n.length;r++){var o=n[r];if(t[o.key])throw new Error("Query() - addParams: Custom Param is conflicting other request arguments");t[o.key]=o.value,o.fn&&(t[o.key]=o.fn.call(e.query,o.key,e.query,e.dm)),t.params[o.key]=t[o.key]}},t}(s);t.UrlAdaptor=u;var c=function(e){function t(){var t=e.call(this)||this;return t.options=r.extend({},t.options,{requestType:"get",accept:"application/json;odata=light;q=1,application/json;odata=verbose;q=0.5",multipartAccept:"multipart/mixed",sortBy:"$orderby",select:"$select",skip:"$skip",take:"$top",count:"$inlinecount",where:"$filter",expand:"$expand",batch:"$batch",changeSet:"--changeset_",batchPre:"batch_",contentId:"Content-Id: ",batchContent:"Content-Type: multipart/mixed; boundary=",changeSetContent:"Content-Type: application/http\nContent-Transfer-Encoding: binary ",batchChangeSetContentType:"Content-Type: application/json; charset=utf-8 "}),t.getModuleName=r.getValue("getModulename",t),t}return a(t,e),t.prototype.onPredicate=function(e,o,a){var s,i,u="",c=e.value,l=typeof c,p=e.field?t.getField(e.field):null;if(c instanceof Date&&(c="datetime'"+n.DataUtil.parse.replacer(c)+"'"),"string"===l&&(c="'"+c+"'",a&&(p="cast("+p+", 'Edm.String')"),n.DataUtil.parse.isGuid(c)&&(i="guid"),e.ignoreCase&&(i||(p="tolower("+p+")"),c=c.toLowerCase())),s=n.DataUtil.odBiOperator[e.operator])return u+=p,u+=s,i&&(u+=i),u+c;if(r.isNullOrUndefined(this.getModuleName)?s=n.DataUtil.odUniOperator[e.operator]:"ODataV4Adaptor"===this.getModuleName()&&(s=n.DataUtil.odv4UniOperator[e.operator]),"substringof"===s){var d=c;c=p,p=d}return u+=s+"(",u+=p+",",i&&(u+=i),u+=c+")"},t.prototype.onComplexPredicate=function(e,t,r){for(var n=[],o=0;o<e.predicates.length;o++)n.push("("+this.onEachWhere(e.predicates[o],t,r)+")");return n.join(" "+e.condition+" ")},t.prototype.onEachWhere=function(e,t,r){return e.isComplex?this.onComplexPredicate(e,t,r):this.onPredicate(e,t,r)},t.prototype.onWhere=function(e){return this.pvt.search&&e.push(this.onEachWhere(this.pvt.search,null,!0)),e.join(" and ")},t.prototype.onEachSearch=function(e){e.fields&&0===e.fields.length&&n.DataUtil.throwError("Query() - Search : oData search requires list of field names to search");for(var t=this.pvt.search||[],r=0;r<e.fields.length;r++)t.push(new o.Predicate(e.fields[r],e.operator,e.key,e.ignoreCase));this.pvt.search=t},t.prototype.onSearch=function(e){return this.pvt.search=o.Predicate.or(this.pvt.search),""},t.prototype.onEachSort=function(e){var r=[];if(e.name instanceof Array)for(var n=0;n<e.name.length;n++)r.push(t.getField(e.name[n])+("descending"===e.direction?" desc":""));else r.push(t.getField(e.name)+("descending"===e.direction?" desc":""));return r.join(",")},t.prototype.onSortBy=function(e){return e.reverse().join(",")},t.prototype.onGroup=function(e){return this.pvt.groups=e,[]},t.prototype.onSelect=function(e){for(var r=0;r<e.length;r++)e[r]=t.getField(e[r]);return e.join(",")},t.prototype.onAggregates=function(e){return this.pvt.aggregates=e,""},t.prototype.onCount=function(e){return!0===e?"allpages":""},t.prototype.beforeSend=function(e,t,r){n.DataUtil.endsWith(r.url,this.options.batch)&&"post"===r.type.toLowerCase()?(t.setRequestHeader("Accept",this.options.multipartAccept),t.setRequestHeader("DataServiceVersion","2.0"),t.overrideMimeType("text/plain; charset=x-user-defined")):t.setRequestHeader("Accept",this.options.accept),t.setRequestHeader("DataServiceVersion","2.0"),t.setRequestHeader("MaxDataServiceVersion","2.0")},t.prototype.processResponse=function(e,t,o,a,s,i){if(!r.isNullOrUndefined(e.d)){var u=o&&o.isCountRequired?e.d.results:e.d;if(!r.isNullOrUndefined(u))for(var c=0;c<u.length;c++)r.isNullOrUndefined(u[c].__metadata)||delete u[c].__metadata}var l=s&&s.pvtData,p=this.processBatchResponse(e,o,a,s,i);if(p)return p;var d=a&&s.getResponseHeader("DataServiceVersion"),f=null,h=d&&parseInt(d,10)||2;if(o&&o.isCountRequired){(e.__count||e["odata.count"])&&(f=e.__count||e["odata.count"]),e.d&&(e=e.d),(e.__count||e["odata.count"])&&(f=e.__count||e["odata.count"])}3===h&&e.value&&(e=e.value),e.d&&(e=e.d),h<3&&e.results&&(e=e.results);var g={};return g.count=f,g.result=e,this.getAggregateResult(l,e,g),n.DataUtil.isNull(f)?g.result:{result:g.result,count:g.count,aggregates:g.aggregates}},t.prototype.convertToQueryString=function(e,t,r){var n=[],o=e.table||"";delete e.table,r.dataSource.requiresFormat&&(e.$format="json");for(var a=Object.keys(e),s=0,i=a;s<i.length;s++){var u=i[s];n.push(u+"="+e[u])}return n=n.join("&"),r.dataSource.url&&-1!==r.dataSource.url.indexOf("?")&&!o?n:n.length?o+"?"+n:o||""},t.prototype.insert=function(e,t,r){return{url:e.dataSource.url.replace(/\/*$/,r?"/"+r:""),data:JSON.stringify(t)}},t.prototype.remove=function(e,t,r,n){return{type:"DELETE",url:e.dataSource.url.replace(/\/*$/,n?"/"+n:"")+"("+r+")"}},t.prototype.update=function(e,t,r,n){return{type:"PUT",url:e.dataSource.url.replace(/\/*$/,n?"/"+n:"")+"("+r[t]+")",data:JSON.stringify(r),accept:this.options.accept}},t.prototype.batchRequest=function(e,t,r){var o=r.guid=n.DataUtil.getGuid(this.options.batchPre),a=e.dataSource.url.replace(/\/*$/,"/"+this.options.batch),s={url:r.url,key:r.key,cid:1,cSet:n.DataUtil.getGuid(this.options.changeSet)},i="--"+o+"\n";return i+="Content-Type: multipart/mixed; boundary="+s.cSet.replace("--","")+"\n",this.pvt.changeSet=0,i+=this.generateInsertRequest(t.addedRecords,s),i+=this.generateUpdateRequest(t.changedRecords,s),i+=this.generateDeleteRequest(t.deletedRecords,s),i+=s.cSet+"--\n",i+="--"+o+"--",{type:"POST",url:a,dataType:"json",contentType:"multipart/mixed; charset=UTF-8;boundary="+o,data:i}},t.prototype.generateDeleteRequest=function(e,t){if(!e)return"";var r={method:"DELETE ",url:function(e,t,r){return"("+e[t][r]+")"},data:function(e,t){return""}};return this.generateBodyContent(e,t,r)+"\n"},t.prototype.generateInsertRequest=function(e,t){if(!e)return"";var r={method:"POST ",url:function(e,t,r){return""},data:function(e,t){return JSON.stringify(e[t])+"\n\n"}};return this.generateBodyContent(e,t,r)},t.prototype.generateUpdateRequest=function(e,t){if(!e)return"";var r={method:"PUT ",url:function(e,t,r){return"("+e[t][r]+")"},data:function(e,t){return JSON.stringify(e[t])+"\n\n"}};return this.generateBodyContent(e,t,r)},t.getField=function(e){return e.replace(/\./g,"/")},t.prototype.generateBodyContent=function(e,t,r){for(var n="",o=0;o<e.length;o++)n+="\n"+t.cSet+"\n",n+=this.options.changeSetContent+"\n\n",n+=r.method,n+=t.url+r.url(e,o,t.key)+" HTTP/1.1\n",n+="Accept: "+this.options.accept+"\n",n+="Content-Id: "+this.pvt.changeSet+++"\n",n+=this.options.batchChangeSetContentType+"\n\n",n+=r.data(e,o);return n},t.prototype.processBatchResponse=function(e,t,o,a,s){if(o&&o.getResponseHeader("Content-Type")&&-1!==o.getResponseHeader("Content-Type").indexOf("xml"))return t.isCountRequired?{result:[],count:0}:[];if(a&&this.options.batch&&n.DataUtil.endsWith(a.url,this.options.batch)&&"post"===a.type.toLowerCase()){var i=o.getResponseHeader("Content-Type"),u=void 0,c=void 0;if(i=i.substring(i.indexOf("=batchresponse")+1),e=e.split(i),e.length<2)return{};e=e[1];var l=/(?:\bContent-Type.+boundary=)(changesetresponse.+)/i.exec(e);l&&e.replace(l[0],"");var p=l?l[1]:"";e=e.split(p);for(var d=e.length;d>-1;d--)/\bContent-ID:/i.test(e[d])&&/\bHTTP.+201/.test(e[d])&&(u=parseInt(/\bContent-ID: (\d+)/i.exec(e[d])[1],10),s.addedRecords[u]&&(c=n.DataUtil.parse.parseJson(/^\{.+\}/m.exec(e[d])[0]),r.extend({},s.addedRecords[u],this.processResponse(c))));return s}return null},t}(u);t.ODataAdaptor=c;var l=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.options=r.extend({},t.options,{requestType:"get",accept:"application/json, text/javascript, */*; q=0.01",multipartAccept:"multipart/mixed",sortBy:"$orderby",select:"$select",skip:"$skip",take:"$top",count:"$count",search:"$search",where:"$filter",expand:"$expand",batch:"$batch",changeSet:"--changeset_",batchPre:"batch_",contentId:"Content-Id: ",batchContent:"Content-Type: multipart/mixed; boundary=",changeSetContent:"Content-Type: application/http\nContent-Transfer-Encoding: binary ",batchChangeSetContentType:"Content-Type: application/json; charset=utf-8 "}),t}return a(t,e),t.prototype.getModulename=function(){return"ODataV4Adaptor"},t.prototype.onCount=function(e){return!0===e?"true":""},t.prototype.onPredicate=function(t,r,n){var o="",a=t.value,s=a instanceof Date;return o=e.prototype.onPredicate.call(this,t,r,n),s&&(o=o.replace(/datetime'(.*)'$/,"$1")),o},t.prototype.onEachSearch=function(e){var t=this.pvt.searches||[];t.push(e.key),this.pvt.searches=t},t.prototype.onSearch=function(e){return this.pvt.searches.join(" OR ")},t.prototype.beforeSend=function(e,t,r){t.setRequestHeader("Accept",this.options.accept)},t.prototype.processResponse=function(t,r,o,a,s,i){var u=s&&s.pvtData,c=e.prototype.processBatchResponse.call(this,t,o,a,s,i);if(c)return c;var l=null;o&&o.isCountRequired&&"@odata.count"in t&&(l=t["@odata.count"]),t=t.value;var p={};return p.count=l,p.result=t,this.getAggregateResult(u,t,p),n.DataUtil.isNull(l)?p.result:{result:p.result,count:l,aggregates:p.aggregates}},t}(c);t.ODataV4Adaptor=l;var p=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.insert=function(e,t,r){return{type:"POST",url:e.dataSource.url,data:JSON.stringify(t)}},t.prototype.remove=function(e,t,r,n){return{type:"DELETE",url:e.dataSource.url+"/"+r,data:JSON.stringify(r)}},t.prototype.update=function(e,t,r,n){return{type:"PUT",url:e.dataSource.url,data:JSON.stringify(r)}},t.prototype.beforeSend=function(e,t,r){t.setRequestHeader("Accept","application/json, text/javascript, */*; q=0.01")},t.prototype.processResponse=function(e,t,r,o,a,s){var i=a&&a.pvtData,u=null,c={};if(a&&"post"!==a.type.toLowerCase()){var l=o&&a.getResponseHeader("DataServiceVersion"),p=l&&parseInt(l,10)||2;r&&r.isCountRequired&&(n.DataUtil.isNull(e.Count)||(u=e.Count)),p<3&&e.Items&&(e=e.Items),c.count=u,c.result=e,this.getAggregateResult(i,e,c)}return c.result=c.result||e,n.DataUtil.isNull(u)?c.result:{result:c.result,count:c.count,aggregates:c.aggregates}},t}(c);t.WebApiAdaptor=p;var d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return a(t,e),t.prototype.processQuery=function(e,t,r){var o=(new u).processQuery(e,t,r),a=n.DataUtil.parse.parseJson(o.data),s={};if(a.param)for(var i=0;i<a.param.length;i++){var c=a.param[i],l=Object.keys(c)[0];s[l]=c[l]}s.value=a;return{data:JSON.stringify(s),url:o.url,pvtData:o.pvtData,type:"POST",contentType:"application/json; charset=utf-8"}},t}(u);t.WebMethodAdaptor=d;var f=function(e){function t(){var t=e.call(this)||this;return r.setValue("beforeSend",u.prototype.beforeSend,t),r.setValue("insert",u.prototype.insert,t),r.setValue("update",u.prototype.update,t),r.setValue("remove",u.prototype.remove,t),t}return a(t,e),t.prototype.batchRequest=function(e,t,r){var n;for(n=0;n<t.addedRecords.length;n++)i.prototype.insert(e,t.addedRecords[n]);for(n=0;n<t.changedRecords.length;n++)i.prototype.update(e,r.key,t.changedRecords[n]);for(n=0;n<t.deletedRecords.length;n++)i.prototype.remove(e,r.key,t.deletedRecords[n]);return{type:"POST",url:e.dataSource.batchUrl||e.dataSource.crudUrl||e.dataSource.url,contentType:"application/json; charset=utf-8",dataType:"json",data:JSON.stringify({changed:t.changedRecords,added:t.addedRecords,deleted:t.deletedRecords,action:"batch",table:r.url,key:r.key})}},t}(i);t.RemoteSaveAdaptor=f;var h=function(e){function t(t,o,a){var s=e.call(this)||this;s.isCrudAction=!1,s.isInsertAction=!1,r.isNullOrUndefined(t)||(s.cacheAdaptor=t),s.pageSize=a,s.guidId=n.DataUtil.getGuid("cacheAdaptor");var i={keys:[],results:[]};window.localStorage.setItem(s.guidId,JSON.stringify(i));var u=s.guidId;return r.isNullOrUndefined(o)||setInterval(function(){var e;e=n.DataUtil.parse.parseJson(window.localStorage.getItem(u));for(var t=[],r=0;r<e.results.length;r++){var a=+new Date,s=+new Date(e.results[r].timeStamp);e.results[r].timeStamp=a-s,a-s>o&&t.push(r)}for(var r=0;r<t.length;r++)e.results.splice(t[r],1),e.keys.splice(t[r],1);window.localStorage.removeItem(u),window.localStorage.setItem(u,JSON.stringify(e))},o),s}return a(t,e),t.prototype.generateKey=function(e,t){var r=this.getQueryRequest(t),n=o.Query.filterQueryLists(t.queries,["onSelect","onPage","onSkip","onTake","onRange"]),a=e;"onPage"in n&&(a+=n.onPage.pageIndex),r.sorts.forEach(function(e){a+=e.e.direction+e.e.fieldName}),r.groups.forEach(function(e){a+=e.e.fieldName}),r.searches.forEach(function(e){a+=e.e.searchKey});for(var s=0;s<r.filters.length;s++){var i=r.filters[s];if(i.e.isComplex){var u=t.clone();u.queries=[];for(var c=0;c<i.e.predicates.length;c++)u.queries.push({fn:"onWhere",e:i.e.predicates[c],filter:t.queries.filter});a+=i.e.condition+this.generateKey(e,u)}else a+=i.e.field+i.e.operator+i.e.value}return a},t.prototype.processQuery=function(e,t,r){var o,a=this.generateKey(e.dataSource.url,t);o=n.DataUtil.parse.parseJson(window.localStorage.getItem(this.guidId));var s=o?o.results[o.keys.indexOf(a)]:null;return null==s||this.isCrudAction||this.isInsertAction?(this.isCrudAction=null,this.isInsertAction=null,this.cacheAdaptor.processQuery.apply(this.cacheAdaptor,[].slice.call(arguments,0))):s},t.prototype.processResponse=function(e,t,r,o,a,s){if(this.isInsertAction||a&&this.cacheAdaptor.options.batch&&n.DataUtil.endsWith(a.url,this.cacheAdaptor.options.batch)&&"post"===a.type.toLowerCase())return this.cacheAdaptor.processResponse(e,t,r,o,a,s);e=this.cacheAdaptor.processResponse.apply(this.cacheAdaptor,[].slice.call(arguments,0));var i=r?this.generateKey(t.dataSource.url,r):t.dataSource.url,u={};u=n.DataUtil.parse.parseJson(window.localStorage.getItem(this.guidId));var c=u.keys.indexOf(i);for(-1!==c&&(u.results.splice(c,1),u.keys.splice(c,1)),u.results[u.keys.push(i)-1]={keys:i,result:e.result,timeStamp:new Date,count:e.count};u.results.length>this.pageSize;)u.results.splice(0,1),u.keys.splice(0,1);return window.localStorage.setItem(this.guidId,JSON.stringify(u)),e},t.prototype.beforeSend=function(e,t,r){n.DataUtil.endsWith(r.url,this.cacheAdaptor.options.batch)&&"post"===r.type.toLowerCase()&&t.setRequestHeader("Accept",this.cacheAdaptor.options.multipartAccept),e.dataSource.crossDomain||t.setRequestHeader("Accept",this.cacheAdaptor.options.accept)},t.prototype.update=function(e,t,r,n){return this.isCrudAction=!0,this.cacheAdaptor.update(e,t,r,n)},t.prototype.insert=function(e,t,r){return this.isInsertAction=!0,this.cacheAdaptor.insert(e,t,r)},t.prototype.remove=function(e,t,r,n){return this.isCrudAction=!0,this.cacheAdaptor.remove(e,t,r,n)},t.prototype.batchRequest=function(e,t,r){return this.cacheAdaptor.batchRequest(e,t,r)},t}(u);t.CacheAdaptor=h}.apply(t,n))&&(e.exports=o)}])}); | ||
//# sourceMappingURL=ej2-data.umd.min.js.map |
@@ -0,1 +1,4 @@ | ||
/** | ||
* Data modules | ||
*/ | ||
export * from './manager'; | ||
@@ -2,0 +5,0 @@ export * from './query'; |
@@ -6,5 +6,16 @@ import { Ajax } from '@syncfusion/ej2-base'; | ||
import { ODataAdaptor, JsonAdaptor, CacheAdaptor, RemoteSaveAdaptor } from './adaptors'; | ||
var DataManager = (function () { | ||
/** | ||
* DataManager is used to manage and manipulate relational data. | ||
*/ | ||
var DataManager = /** @class */ (function () { | ||
/** | ||
* Constructor for DataManager class | ||
* @param {DataOptions|JSON[]} dataSource? | ||
* @param {Query} query? | ||
* @param {AdaptorOptions|string} adaptor? | ||
* @hidden | ||
*/ | ||
function DataManager(dataSource, query, adaptor) { | ||
var _this = this; | ||
/** @hidden */ | ||
this.dateParse = true; | ||
@@ -86,2 +97,6 @@ this.requests = []; | ||
} | ||
/** | ||
* Overrides DataManager's default query with given query. | ||
* @param {Query} query - Defines the new default query. | ||
*/ | ||
DataManager.prototype.setDefaultQuery = function (query) { | ||
@@ -91,2 +106,6 @@ this.defaultQuery = query; | ||
}; | ||
/** | ||
* Executes the given query with local data source. | ||
* @param {Query} query - Defines the query to retrieve data. | ||
*/ | ||
DataManager.prototype.executeLocal = function (query) { | ||
@@ -104,3 +123,3 @@ if (!this.defaultQuery && !(query instanceof Query)) { | ||
var lookup = query.subQuery.lookups; | ||
var res = query.requiresCounts ? result.result : | ||
var res = query.isCountRequired ? result.result : | ||
result; | ||
@@ -119,2 +138,10 @@ if (lookup && lookup instanceof Array) { | ||
}; | ||
/** | ||
* Executes the given query with either local or remote data source. | ||
* It will be executed as asynchronously and returns Promise object which will be resolved or rejected after action completed. | ||
* @param {Query|Function} query - Defines the query to retrieve data. | ||
* @param {Function} done - Defines the callback function and triggers when the Promise is resolved. | ||
* @param {Function} fail - Defines the callback function and triggers when the Promise is rejected. | ||
* @param {Function} always - Defines the callback function and triggers when the Promise is resolved or rejected. | ||
*/ | ||
DataManager.prototype.executeQuery = function (query, done, fail, always) { | ||
@@ -150,3 +177,3 @@ var _this = this; | ||
DataManager.getDeferedArgs = function (query, result, args) { | ||
if (query.requiresCounts) { | ||
if (query.isCountRequired) { | ||
args.result = result.result; | ||
@@ -218,3 +245,3 @@ args.count = result.count; | ||
var virtualRecords = data[virtualSelectRecords]; | ||
if (query.requiresCounts) { | ||
if (query.isCountRequired) { | ||
count = result.count; | ||
@@ -238,2 +265,3 @@ aggregates = result.aggregates; | ||
req = ajax.send(); | ||
req.catch(function (e) { return true; }); // to handle failure remote requests. | ||
this.requests.push(ajax); | ||
@@ -253,3 +281,3 @@ if (isSelector) { | ||
var count = 0; | ||
if (query.requiresCounts) { | ||
if (query.isCountRequired) { | ||
count = pResult.count; | ||
@@ -260,3 +288,3 @@ pResult = pResult.result; | ||
count = 0; | ||
if (query.subQuery.requiresCounts) { | ||
if (query.subQuery.isCountRequired) { | ||
count = cResult.count; | ||
@@ -290,2 +318,11 @@ cResult = cResult.result; | ||
}; | ||
/** | ||
* Save bulk changes to the given table name. | ||
* User can add a new record, edit an existing record, and delete a record at the same time. | ||
* If the datasource from remote, then updated in a single post. | ||
* @param {Object} changes - Defines the CrudOptions. | ||
* @param {string} key - Defines the column field. | ||
* @param {string|Query} tableName - Defines the table name. | ||
* @param {Query} query - Sets default query for the DataManager. | ||
*/ | ||
DataManager.prototype.saveChanges = function (changes, key, tableName, query) { | ||
@@ -316,5 +353,11 @@ var _this = this; | ||
}; | ||
ajax.send(); | ||
ajax.send().catch(function (e) { return true; }); // to handle the failure requests. | ||
return deff.promise; | ||
}; | ||
/** | ||
* Inserts new record in the given table. | ||
* @param {Object} data - Defines the data to insert. | ||
* @param {string|Query} tableName - Defines the table name. | ||
* @param {Query} query - Sets default query for the DataManager. | ||
*/ | ||
DataManager.prototype.insert = function (data, tableName, query, position) { | ||
@@ -332,2 +375,9 @@ data = DataUtil.parse.replacer(data); | ||
}; | ||
/** | ||
* Removes data from the table with the given key. | ||
* @param {string} keyField - Defines the column field. | ||
* @param {Object} value - Defines the value to find the data in the specified column. | ||
* @param {string|Query} tableName - Defines the table name | ||
* @param {Query} query - Sets default query for the DataManager. | ||
*/ | ||
DataManager.prototype.remove = function (keyField, value, tableName, query) { | ||
@@ -347,2 +397,9 @@ if (typeof value === 'object') { | ||
}; | ||
/** | ||
* Updates existing record in the given table. | ||
* @param {string} keyField - Defines the column field. | ||
* @param {Object} value - Defines the value to find the data in the specified column. | ||
* @param {string|Query} tableName - Defines the table name | ||
* @param {Query} query - Sets default query for the DataManager. | ||
*/ | ||
DataManager.prototype.update = function (keyField, value, tableName, query) { | ||
@@ -385,3 +442,3 @@ value = DataUtil.parse.replacer(value, !this.dataSource.offline); | ||
}; | ||
ajax.send(); | ||
ajax.send().catch(function (e) { return true; }); // to handle the failure requests. | ||
return defer.promise; | ||
@@ -392,5 +449,11 @@ }; | ||
export { DataManager }; | ||
var Deferred = (function () { | ||
/** | ||
* Deferred is used to handle asynchronous operation. | ||
*/ | ||
var Deferred = /** @class */ (function () { | ||
function Deferred() { | ||
var _this = this; | ||
/** | ||
* Promise is an object that represents a value that may not be available yet, but will be resolved at some point in the future. | ||
*/ | ||
this.promise = new Promise(function (resolve, reject) { | ||
@@ -400,3 +463,9 @@ _this.resolve = resolve; | ||
}); | ||
/** | ||
* Defines the callback function triggers when the Deferred object is resolved. | ||
*/ | ||
this.then = this.promise.then.bind(this.promise); | ||
/** | ||
* Defines the callback function triggers when the Deferred object is rejected. | ||
*/ | ||
this.catch = this.promise.catch.bind(this.promise); | ||
@@ -403,0 +472,0 @@ } |
import { DataUtil } from './util'; | ||
var Query = (function () { | ||
/** | ||
* Query class is used to build query which is used by the DataManager to communicate with datasource. | ||
*/ | ||
var Query = /** @class */ (function () { | ||
/** | ||
* Constructor for Query class. | ||
* @param {string|string[]} from? | ||
* @hidden | ||
*/ | ||
function Query(from) { | ||
/** @hidden */ | ||
this.subQuery = null; | ||
/** @hidden */ | ||
this.isChild = false; | ||
@@ -23,2 +33,6 @@ this.queries = []; | ||
} | ||
/** | ||
* Sets the primary key. | ||
* @param {string} field - Defines the column field. | ||
*/ | ||
Query.prototype.setKey = function (field) { | ||
@@ -28,2 +42,6 @@ this.key = field; | ||
}; | ||
/** | ||
* Sets default DataManager to execute query. | ||
* @param {DataManager} dataManager - Defines the DataManager. | ||
*/ | ||
Query.prototype.using = function (dataManager) { | ||
@@ -33,2 +51,17 @@ this.dataManager = dataManager; | ||
}; | ||
/** | ||
* Executes query with the given DataManager. | ||
* @param {DataManager} dataManager - Defines the DataManager. | ||
* @param {Function} done - Defines the success callback. | ||
* @param {Function} fail - Defines the failure callback. | ||
* @param {Function} always - Defines the callback which will be invoked on either success or failure. | ||
* | ||
* <pre> | ||
* let dataManager: DataManager = new DataManager([{ ID: '10' }, { ID: '2' }, { ID: '1' }, { ID: '20' }]); | ||
* let query: Query = new Query(); | ||
* query.sortBy('ID', (x: string, y: string): number => { return parseInt(x, 10) - parseInt(y, 10) }); | ||
* let promise: Promise< Object > = query.execute(dataManager); | ||
* promise.then((e: { result: Object }) => { }); | ||
* </pre> | ||
*/ | ||
Query.prototype.execute = function (dataManager, done, fail, always) { | ||
@@ -41,2 +74,6 @@ dataManager = dataManager || this.dataManager; | ||
}; | ||
/** | ||
* Executes query with the local datasource. | ||
* @param {DataManager} dataManager - Defines the DataManager. | ||
*/ | ||
Query.prototype.executeLocal = function (dataManager) { | ||
@@ -49,2 +86,5 @@ dataManager = dataManager || this.dataManager; | ||
}; | ||
/** | ||
* Creates deep copy of the Query object. | ||
*/ | ||
Query.prototype.clone = function () { | ||
@@ -64,5 +104,9 @@ var cloned = new Query(); | ||
cloned.fKey = this.fKey; | ||
cloned.requiresCounts = this.requiresCounts; | ||
cloned.isCountRequired = this.isCountRequired; | ||
return cloned; | ||
}; | ||
/** | ||
* Specifies the name of table to retrieve data in query execution. | ||
* @param {string} tableName - Defines the table name. | ||
*/ | ||
Query.prototype.from = function (tableName) { | ||
@@ -72,2 +116,7 @@ this.fromTable = tableName; | ||
}; | ||
/** | ||
* Adds additional parameter which will be sent along with the request which will be generated while DataManager execute. | ||
* @param {string} key - Defines the key of additional parameter. | ||
* @param {Function|string} value - Defines the value for the key. | ||
*/ | ||
Query.prototype.addParams = function (key, value) { | ||
@@ -82,2 +131,6 @@ if (typeof value === 'function') { | ||
}; | ||
/** | ||
* Expands the related table. | ||
* @param {string|Object[]} tables | ||
*/ | ||
Query.prototype.expand = function (tables) { | ||
@@ -92,2 +145,10 @@ if (typeof tables === 'string') { | ||
}; | ||
/** | ||
* Filter data with given filter criteria. | ||
* @param {string|Predicate} fieldName - Defines the column field or Predicate. | ||
* @param {string} operator - Defines the operator how to filter data. | ||
* @param {string|number|boolean} value - Defines the values to match with data. | ||
* @param {boolean} ignoreCase - If ignore case set to false, then filter data with exact match or else | ||
* filter data with case insensitive. | ||
*/ | ||
Query.prototype.where = function (fieldName, operator, value, ignoreCase) { | ||
@@ -108,2 +169,10 @@ operator = operator ? (operator).toLowerCase() : null; | ||
}; | ||
/** | ||
* Search data with given search criteria. | ||
* @param {string|number|boolean} searchKey - Defines the search key. | ||
* @param {string|string[]} fieldNames - Defines the collection of column fields. | ||
* @param {string} operator - Defines the operator how to search data. | ||
* @param {boolean} ignoreCase - If ignore case set to false, then filter data with exact match or else | ||
* filter data with case insensitive. | ||
*/ | ||
Query.prototype.search = function (searchKey, fieldNames, operator, ignoreCase) { | ||
@@ -127,2 +196,8 @@ if (typeof fieldNames === 'string') { | ||
}; | ||
/** | ||
* Sort the data with given sort criteria. | ||
* By default, sort direction is ascending. | ||
* @param {string|string[]} fieldName - Defines the single or collection of column fields. | ||
* @param {string|Function} comparer - Defines the sort direction or custom sort comparer function. | ||
*/ | ||
Query.prototype.sortBy = function (fieldName, comparer, isFromGroup) { | ||
@@ -168,5 +243,13 @@ var order = 'ascending'; | ||
}; | ||
/** | ||
* Sorts data in descending order. | ||
* @param {string} fieldName - Defines the column field. | ||
*/ | ||
Query.prototype.sortByDesc = function (fieldName) { | ||
return this.sortBy(fieldName, 'descending'); | ||
}; | ||
/** | ||
* Groups data with the given field name. | ||
* @param {string} fieldName - Defines the column field. | ||
*/ | ||
Query.prototype.group = function (fieldName, fn, format) { | ||
@@ -184,2 +267,7 @@ this.sortBy(fieldName, null, true); | ||
}; | ||
/** | ||
* Gets data based on the given page index and size. | ||
* @param {number} pageIndex - Defines the current page index. | ||
* @param {number} pageSize - Defines the no of records per page. | ||
*/ | ||
Query.prototype.page = function (pageIndex, pageSize) { | ||
@@ -195,2 +283,7 @@ this.queries.push({ | ||
}; | ||
/** | ||
* Gets data based on the given start and end index. | ||
* @param {number} start - Defines the start index of the datasource. | ||
* @param {number} end - Defines the end index of the datasource. | ||
*/ | ||
Query.prototype.range = function (start, end) { | ||
@@ -206,2 +299,6 @@ this.queries.push({ | ||
}; | ||
/** | ||
* Gets data from the top of the data source based on given number of records count. | ||
* @param {number} nos - Defines the no of records to retrieve from datasource. | ||
*/ | ||
Query.prototype.take = function (nos) { | ||
@@ -216,2 +313,6 @@ this.queries.push({ | ||
}; | ||
/** | ||
* Skips data with given number of records count from the top of the data source. | ||
* @param {number} nos - Defines the no of records skip in the datasource. | ||
*/ | ||
Query.prototype.skip = function (nos) { | ||
@@ -224,2 +325,6 @@ this.queries.push({ | ||
}; | ||
/** | ||
* Selects specified columns from the data source. | ||
* @param {string|string[]} fieldNames - Defines the collection of column fields. | ||
*/ | ||
Query.prototype.select = function (fieldNames) { | ||
@@ -235,2 +340,7 @@ if (typeof fieldNames === 'string') { | ||
}; | ||
/** | ||
* Gets the records in hierarchical relationship from two tables. It requires the foreign key to relate two tables. | ||
* @param {Query} query - Defines the query to relate two tables. | ||
* @param {Function} selectorFn - Defines the custom function to select records. | ||
*/ | ||
Query.prototype.hierarchy = function (query, selectorFn) { | ||
@@ -241,2 +351,6 @@ this.subQuerySelector = selectorFn; | ||
}; | ||
/** | ||
* Sets the foreign key which is used to get data from the related table. | ||
* @param {string} key - Defines the foreign key. | ||
*/ | ||
Query.prototype.foreignKey = function (key) { | ||
@@ -246,6 +360,15 @@ this.fKey = key; | ||
}; | ||
/** | ||
* It is used to get total number of records in the DataManager execution result. | ||
*/ | ||
Query.prototype.requiresCount = function () { | ||
this.requiresCounts = true; | ||
this.isCountRequired = true; | ||
return this; | ||
}; | ||
//type - sum, avg, min, max | ||
/** | ||
* Aggregate the data with given type and field name. | ||
* @param {string} type - Defines the aggregate type. | ||
* @param {string} field - Defines the column field to aggregate. | ||
*/ | ||
Query.prototype.aggregate = function (type, field) { | ||
@@ -258,2 +381,8 @@ this.queries.push({ | ||
}; | ||
/** | ||
* Pass array of filterColumn query for performing filter operation. | ||
* @param {QueryOptions[]} queries | ||
* @param {string} name | ||
* @hidden | ||
*/ | ||
Query.filterQueries = function (queries, name) { | ||
@@ -264,2 +393,8 @@ return queries.filter(function (q) { | ||
}; | ||
/** | ||
* To get the list of queries which is already filtered in current data source. | ||
* @param {Object[]} queries | ||
* @param {string[]} singles | ||
* @hidden | ||
*/ | ||
Query.filterQueryLists = function (queries, singles) { | ||
@@ -280,5 +415,18 @@ var filtered = queries.filter(function (q) { | ||
export { Query }; | ||
var Predicate = (function () { | ||
/** | ||
* Predicate class is used to generate complex filter criteria. | ||
* This will be used by DataManager to perform multiple filtering operation. | ||
*/ | ||
var Predicate = /** @class */ (function () { | ||
/** | ||
* Constructor for Predicate class. | ||
* @param {string|Predicate} field | ||
* @param {string} operator | ||
* @param {string|number|boolean|Predicate|Predicate[]} value | ||
* @param {boolean=false} ignoreCase | ||
* @hidden | ||
*/ | ||
function Predicate(field, operator, value, ignoreCase) { | ||
if (ignoreCase === void 0) { ignoreCase = false; } | ||
/** @hidden */ | ||
this.isComplex = false; | ||
@@ -306,2 +454,6 @@ if (typeof field === 'string') { | ||
} | ||
/** | ||
* Adds n-number of new predicates on existing predicate with “and” condition. | ||
* @param {Object[]} args - Defines the collection of predicates. | ||
*/ | ||
Predicate.and = function () { | ||
@@ -314,5 +466,17 @@ var args = []; | ||
}; | ||
/** | ||
* Adds new predicate on existing predicate with “and” condition. | ||
* @param {string} field - Defines the column field. | ||
* @param {string} operator - Defines the operator how to filter data. | ||
* @param {string} value - Defines the values to match with data. | ||
* @param {boolean} ignoreCase? - If ignore case set to false, then filter data with exact match or else | ||
* filter data with case insensitive. | ||
*/ | ||
Predicate.prototype.and = function (field, operator, value, ignoreCase) { | ||
return Predicate.combine(this, field, operator, value, 'and', ignoreCase); | ||
}; | ||
/** | ||
* Adds n-number of new predicates on existing predicate with “or” condition. | ||
* @param {Object[]} args - Defines the collection of predicates. | ||
*/ | ||
Predicate.or = function () { | ||
@@ -325,5 +489,17 @@ var args = []; | ||
}; | ||
/** | ||
* Adds new predicate on existing predicate with “or” condition. | ||
* @param {string} field - Defines the column field. | ||
* @param {string} operator - Defines the operator how to filter data. | ||
* @param {string} value - Defines the values to match with data. | ||
* @param {boolean} ignoreCase? - If ignore case set to false, then filter data with exact match or else | ||
* filter data with case insensitive. | ||
*/ | ||
Predicate.prototype.or = function (field, operator, value, ignoreCase) { | ||
return Predicate.combine(this, field, operator, value, 'or', ignoreCase); | ||
}; | ||
/** | ||
* Converts plain JavaScript object to Predicate object. | ||
* @param {Predicate[]|Predicate} json - Defines single or collection of Predicate. | ||
*/ | ||
Predicate.fromJson = function (json) { | ||
@@ -340,2 +516,6 @@ if (json instanceof Array) { | ||
}; | ||
/** | ||
* Validate the record based on the predicates. | ||
* @param {Object} record - Defines the datasource record. | ||
*/ | ||
Predicate.prototype.validate = function (record) { | ||
@@ -364,2 +544,6 @@ var predicate = this.predicates ? this.predicates : []; | ||
}; | ||
/** | ||
* Converts predicates to plain JavaScript. | ||
* This method is uses Json stringify when serializing Predicate object. | ||
*/ | ||
Predicate.prototype.toJson = function () { | ||
@@ -366,0 +550,0 @@ var predicates; |
@@ -5,5 +5,16 @@ import { isNullOrUndefined } from '@syncfusion/ej2-base'; | ||
var consts = { GroupGuid: '{271bbba0-1ee7}' }; | ||
var DataUtil = (function () { | ||
/** | ||
* Data manager common utility methods. | ||
* @hidden | ||
*/ | ||
var DataUtil = /** @class */ (function () { | ||
function DataUtil() { | ||
} | ||
/** | ||
* Returns the value by invoking the provided parameter function. | ||
* If the paramater is not of type function then it will be returned as it is. | ||
* @param {Function|string|string[]|number} value | ||
* @param {Object} inst? | ||
* @hidden | ||
*/ | ||
DataUtil.getValue = function (value, inst) { | ||
@@ -15,8 +26,23 @@ if (typeof value === 'function') { | ||
}; | ||
/** | ||
* Returns true if the input string ends with given string. | ||
* @param {string} input | ||
* @param {string} substr | ||
*/ | ||
DataUtil.endsWith = function (input, substr) { | ||
return input.slice(-substr.length) === substr; | ||
}; | ||
/** | ||
* Returns true if the input string starts with given string. | ||
* @param {string} str | ||
* @param {string} startstr | ||
*/ | ||
DataUtil.startsWith = function (input, start) { | ||
return input.slice(0, start.length) === start; | ||
}; | ||
/** | ||
* To return the sorting function based on the string. | ||
* @param {string} order | ||
* @hidden | ||
*/ | ||
DataUtil.fnSort = function (order) { | ||
@@ -29,2 +55,8 @@ order = order ? order.toLowerCase() : 'ascending'; | ||
}; | ||
/** | ||
* Comparer function which is used to sort the data in ascending order. | ||
* @param {string|number} x | ||
* @param {string|number} y | ||
* @returns number | ||
*/ | ||
DataUtil.fnAscending = function (x, y) { | ||
@@ -42,2 +74,8 @@ if (y === null || y === undefined) { | ||
}; | ||
/** | ||
* Comparer function which is used to sort the data in descending order. | ||
* @param {string|number} x | ||
* @param {string|number} y | ||
* @returns number | ||
*/ | ||
DataUtil.fnDescending = function (x, y) { | ||
@@ -65,2 +103,7 @@ if (y === null || y === undefined) { | ||
}; | ||
/** | ||
* Select objects by given fields from jsonArray. | ||
* @param {Object[]} jsonArray | ||
* @param {string[]} fields | ||
*/ | ||
DataUtil.select = function (jsonArray, fields) { | ||
@@ -73,2 +116,11 @@ var newData = []; | ||
}; | ||
/** | ||
* Group the input data based on the field name. | ||
* It also performs aggregation of the grouped records based on the aggregates paramater. | ||
* @param {Object[]} jsonArray | ||
* @param {string} field? | ||
* @param {Object[]} agg? | ||
* @param {number} level? | ||
* @param {Object[]} groupDs? | ||
*/ | ||
DataUtil.group = function (jsonArray, field, aggregates, level, groupDs, format) { | ||
@@ -158,2 +210,12 @@ level = level || 1; | ||
}; | ||
/** | ||
* It is used to categorize the multiple items based on a specific field in jsonArray. | ||
* The hierarchical queries are commonly required when you use foreign key binding. | ||
* @param {string} fKey | ||
* @param {string} from | ||
* @param {Object[]} source | ||
* @param {Group} lookup? | ||
* @param {string} pKey? | ||
* @hidden | ||
*/ | ||
DataUtil.buildHierarchy = function (fKey, from, source, lookup, pKey) { | ||
@@ -179,2 +241,9 @@ var i; | ||
}; | ||
/** | ||
* The method used to get the field names which started with specified characters. | ||
* @param {Object} obj | ||
* @param {string[]} fields? | ||
* @param {string} prefix? | ||
* @hidden | ||
*/ | ||
DataUtil.getFieldList = function (obj, fields, prefix) { | ||
@@ -200,2 +269,8 @@ if (prefix === undefined) { | ||
}; | ||
/** | ||
* Gets the value of the property in the given object. | ||
* The complex object can be accessed by providing the field names concatenated with dot(.). | ||
* @param {string} nameSpace - The name of the property to be accessed. | ||
* @param {Object} from - Defines the source object. | ||
*/ | ||
DataUtil.getObject = function (nameSpace, from) { | ||
@@ -218,2 +293,8 @@ if (!nameSpace) { | ||
}; | ||
/** | ||
* Sort the given data based on the field and comparer. | ||
* @param {Object[]} ds - Defines the input data. | ||
* @param {string} field - Defines the field to be sorted. | ||
* @param {Function} comparer - Defines the comparer function used to sort the records. | ||
*/ | ||
DataUtil.sort = function (ds, field, comparer) { | ||
@@ -255,2 +336,10 @@ if (ds.length <= 1) { | ||
}; | ||
/** | ||
* To perform the filter operation with specified adaptor and returns the result. | ||
* @param {Object} adaptor | ||
* @param {string} fnName | ||
* @param {Object} param1? | ||
* @param {Object} param2? | ||
* @hidden | ||
*/ | ||
DataUtil.callAdaptorFunction = function (adaptor, fnName, param1, param2) { | ||
@@ -265,5 +354,12 @@ if (fnName in adaptor) { | ||
}; | ||
/** | ||
* Checks wheather the given input is a plain object or not. | ||
* @param {Object|Object[]} obj | ||
*/ | ||
DataUtil.isPlainObject = function (obj) { | ||
return (!!obj) && (obj.constructor === Object); | ||
}; | ||
/** | ||
* Returns true when the browser cross origin request. | ||
*/ | ||
DataUtil.isCors = function () { | ||
@@ -276,5 +372,10 @@ var xhr = null; | ||
catch (e) { | ||
// No exception handling | ||
} | ||
return !!xhr && ('withCredentials' in xhr); | ||
}; | ||
/** | ||
* Generate random GUID value which will be prefixed with the given value. | ||
* @param {string} prefix | ||
*/ | ||
DataUtil.getGuid = function (prefix) { | ||
@@ -295,5 +396,18 @@ var hexs = '0123456789abcdef'; | ||
}; | ||
/** | ||
* Checks wheather the given value is null or not. | ||
* @param {string|Object} val | ||
* @returns boolean | ||
*/ | ||
DataUtil.isNull = function (val) { | ||
return val === undefined || val === null; | ||
}; | ||
/** | ||
* To get the required items from collection of objects. | ||
* @param {Object[]} array | ||
* @param {string} field | ||
* @param {Function} comparer | ||
* @returns Object | ||
* @hidden | ||
*/ | ||
DataUtil.getItemFromComparer = function (array, field, comparer) { | ||
@@ -327,293 +441,499 @@ var keyVal; | ||
}; | ||
return DataUtil; | ||
}()); | ||
export { DataUtil }; | ||
DataUtil.serverTimezoneOffset = 0; | ||
DataUtil.throwError = function (error) { | ||
try { | ||
throw new Error(error); | ||
} | ||
catch (e) { | ||
throw e.message + '\n' + e.stack; | ||
} | ||
}; | ||
DataUtil.aggregates = { | ||
sum: function (ds, field) { | ||
var result = 0; | ||
/** | ||
* To get distinct values of Array or Array of Objects. | ||
* @param {Object[]} json | ||
* @param {string} field | ||
* @param {boolean} requiresCompleteRecord | ||
* @returns Object[] | ||
* * distinct array of objects is return when requiresCompleteRecord set as true. | ||
* @hidden | ||
*/ | ||
DataUtil.distinct = function (json, fieldName, requiresCompleteRecord) { | ||
requiresCompleteRecord = isNullOrUndefined(requiresCompleteRecord) ? false : requiresCompleteRecord; | ||
var result = []; | ||
var val; | ||
var castRequired = typeof DataUtil.getVal(ds, 0, field) !== 'number'; | ||
for (var i = 0; i < ds.length; i++) { | ||
val = DataUtil.getVal(ds, i, field); | ||
if (!isNaN(val) && val !== null) { | ||
if (castRequired) { | ||
val = +val; | ||
} | ||
result += val; | ||
var tmp = {}; | ||
json.forEach(function (data, index) { | ||
val = DataUtil.getVal(json, index, fieldName); | ||
if (!(val in tmp)) { | ||
result.push(!requiresCompleteRecord ? val : json[index]); | ||
tmp[val] = 1; | ||
} | ||
} | ||
}); | ||
return result; | ||
}, | ||
average: function (ds, field) { | ||
return DataUtil.aggregates.sum(ds, field) / ds.length; | ||
}, | ||
min: function (ds, field) { | ||
var comparer; | ||
if (typeof field === 'function') { | ||
comparer = field; | ||
field = null; | ||
}; | ||
/** | ||
* Specifies the value which will be used to adjust the date value to server timezone. | ||
* @default 0 | ||
*/ | ||
DataUtil.serverTimezoneOffset = 0; | ||
/** | ||
* Throw error with the given string as message. | ||
* @param {string} er | ||
*/ | ||
DataUtil.throwError = function (error) { | ||
try { | ||
throw new Error(error); | ||
} | ||
return DataUtil.getObject(field, DataUtil.getItemFromComparer(ds, field, comparer || DataUtil.fnAscending)); | ||
}, | ||
max: function (ds, field) { | ||
var comparer; | ||
if (typeof field === 'function') { | ||
comparer = field; | ||
field = null; | ||
catch (e) { | ||
throw e.message + '\n' + e.stack; | ||
} | ||
return DataUtil.getObject(field, DataUtil.getItemFromComparer(ds, field, comparer || DataUtil.fnDescending)); | ||
}, | ||
truecount: function (ds, field) { | ||
return new DataManager(ds).executeLocal(new Query().where(field, 'equal', true, true)).length; | ||
}, | ||
falsecount: function (ds, field) { | ||
return new DataManager(ds).executeLocal(new Query().where(field, 'equal', false, true)).length; | ||
}, | ||
count: function (ds, field) { | ||
return ds.length; | ||
} | ||
}; | ||
DataUtil.operatorSymbols = { | ||
'<': 'lessthan', | ||
'>': 'greaterthan', | ||
'<=': 'lessthanorequal', | ||
'>=': 'greaterthanorequal', | ||
'==': 'equal', | ||
'!=': 'notequal', | ||
'*=': 'contains', | ||
'$=': 'endswith', | ||
'^=': 'startswith' | ||
}; | ||
DataUtil.odBiOperator = { | ||
'<': ' lt ', | ||
'>': ' gt ', | ||
'<=': ' le ', | ||
'>=': ' ge ', | ||
'==': ' eq ', | ||
'!=': ' ne ', | ||
'lessthan': ' lt ', | ||
'lessthanorequal': ' le ', | ||
'greaterthan': ' gt ', | ||
'greaterthanorequal': ' ge ', | ||
'equal': ' eq ', | ||
'notequal': ' ne ' | ||
}; | ||
DataUtil.odUniOperator = { | ||
'$=': 'endswith', | ||
'^=': 'startswith', | ||
'*=': 'substringof', | ||
'endswith': 'endswith', | ||
'startswith': 'startswith', | ||
'contains': 'substringof' | ||
}; | ||
DataUtil.odv4UniOperator = { | ||
'$=': 'endswith', | ||
'^=': 'startswith', | ||
'*=': 'contains', | ||
'endswith': 'endswith', | ||
'startswith': 'startswith', | ||
'contains': 'contains' | ||
}; | ||
DataUtil.fnOperators = { | ||
equal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) === DataUtil.toLowerCase(expected); | ||
}; | ||
DataUtil.aggregates = { | ||
/** | ||
* Calculate sum of the given field in the data. | ||
* @param {Object[]} ds | ||
* @param {string} field | ||
*/ | ||
sum: function (ds, field) { | ||
var result = 0; | ||
var val; | ||
var castRequired = typeof DataUtil.getVal(ds, 0, field) !== 'number'; | ||
for (var i = 0; i < ds.length; i++) { | ||
val = DataUtil.getVal(ds, i, field); | ||
if (!isNaN(val) && val !== null) { | ||
if (castRequired) { | ||
val = +val; | ||
} | ||
result += val; | ||
} | ||
} | ||
return result; | ||
}, | ||
/** | ||
* Calculate average value of the given field in the data. | ||
* @param {Object[]} ds | ||
* @param {string} field | ||
*/ | ||
average: function (ds, field) { | ||
return DataUtil.aggregates.sum(ds, field) / ds.length; | ||
}, | ||
/** | ||
* Returns the min value of the data based on the field. | ||
* @param {Object[]} ds | ||
* @param {string|Function} field | ||
*/ | ||
min: function (ds, field) { | ||
var comparer; | ||
if (typeof field === 'function') { | ||
comparer = field; | ||
field = null; | ||
} | ||
return DataUtil.getObject(field, DataUtil.getItemFromComparer(ds, field, comparer || DataUtil.fnAscending)); | ||
}, | ||
/** | ||
* Returns the max value of the data based on the field. | ||
* @param {Object[]} ds | ||
* @param {string} field | ||
* @returns number | ||
*/ | ||
max: function (ds, field) { | ||
var comparer; | ||
if (typeof field === 'function') { | ||
comparer = field; | ||
field = null; | ||
} | ||
return DataUtil.getObject(field, DataUtil.getItemFromComparer(ds, field, comparer || DataUtil.fnDescending)); | ||
}, | ||
/** | ||
* Returns the total number of true value present in the data based on the given boolean field name. | ||
* @param {Object[]} ds | ||
* @param {string} field | ||
*/ | ||
truecount: function (ds, field) { | ||
return new DataManager(ds).executeLocal(new Query().where(field, 'equal', true, true)).length; | ||
}, | ||
/** | ||
* Returns the total number of false value present in the data based on the given boolean field name. | ||
* @param {Object[]} ds | ||
* @param {string} field | ||
*/ | ||
falsecount: function (ds, field) { | ||
return new DataManager(ds).executeLocal(new Query().where(field, 'equal', false, true)).length; | ||
}, | ||
/** | ||
* Returns the length of the given data. | ||
* @param {Object[]} ds | ||
* @param {string} field? | ||
* @returns number | ||
*/ | ||
count: function (ds, field) { | ||
return ds.length; | ||
} | ||
return actual === expected; | ||
}, | ||
notequal: function (actual, expected, ignoreCase) { | ||
return !DataUtil.fnOperators.equal(actual, expected, ignoreCase); | ||
}, | ||
lessthan: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) < DataUtil.toLowerCase(expected); | ||
} | ||
return actual < expected; | ||
}, | ||
greaterthan: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) > DataUtil.toLowerCase(expected); | ||
} | ||
return actual > expected; | ||
}, | ||
lessthanorequal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) <= DataUtil.toLowerCase(expected); | ||
} | ||
return actual <= expected; | ||
}, | ||
greaterthanorequal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) >= DataUtil.toLowerCase(expected); | ||
} | ||
return actual >= expected; | ||
}, | ||
contains: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
}; | ||
/** | ||
* Specifies the Object with filter operators. | ||
*/ | ||
DataUtil.operatorSymbols = { | ||
'<': 'lessthan', | ||
'>': 'greaterthan', | ||
'<=': 'lessthanorequal', | ||
'>=': 'greaterthanorequal', | ||
'==': 'equal', | ||
'!=': 'notequal', | ||
'*=': 'contains', | ||
'$=': 'endswith', | ||
'^=': 'startswith' | ||
}; | ||
/** | ||
* Specifies the Object with filter operators which will be used for OData filter query generation. | ||
* * It will be used for date/number type filter query. | ||
*/ | ||
DataUtil.odBiOperator = { | ||
'<': ' lt ', | ||
'>': ' gt ', | ||
'<=': ' le ', | ||
'>=': ' ge ', | ||
'==': ' eq ', | ||
'!=': ' ne ', | ||
'lessthan': ' lt ', | ||
'lessthanorequal': ' le ', | ||
'greaterthan': ' gt ', | ||
'greaterthanorequal': ' ge ', | ||
'equal': ' eq ', | ||
'notequal': ' ne ' | ||
}; | ||
/** | ||
* Specifies the Object with filter operators which will be used for OData filter query generation. | ||
* It will be used for string type filter query. | ||
*/ | ||
DataUtil.odUniOperator = { | ||
'$=': 'endswith', | ||
'^=': 'startswith', | ||
'*=': 'substringof', | ||
'endswith': 'endswith', | ||
'startswith': 'startswith', | ||
'contains': 'substringof' | ||
}; | ||
/** | ||
* Specifies the Object with filter operators which will be used for ODataV4 filter query generation. | ||
* It will be used for string type filter query. | ||
*/ | ||
DataUtil.odv4UniOperator = { | ||
'$=': 'endswith', | ||
'^=': 'startswith', | ||
'*=': 'contains', | ||
'endswith': 'endswith', | ||
'startswith': 'startswith', | ||
'contains': 'contains' | ||
}; | ||
DataUtil.fnOperators = { | ||
/** | ||
* Returns true when the actual input is equal to the given input. | ||
* @param {string|number|boolean} actual | ||
* @param {string|number|boolean} expected | ||
* @param {boolean} ignoreCase? | ||
*/ | ||
equal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) === DataUtil.toLowerCase(expected); | ||
} | ||
return actual === expected; | ||
}, | ||
/** | ||
* Returns true when the actual input is not equal to the given input. | ||
* @param {string|number|boolean} actual | ||
* @param {string|number|boolean} expected | ||
* @param {boolean} ignoreCase? | ||
*/ | ||
notequal: function (actual, expected, ignoreCase) { | ||
return !DataUtil.fnOperators.equal(actual, expected, ignoreCase); | ||
}, | ||
/** | ||
* Returns true when the actual input is less than to the given input. | ||
* @param {string|number|boolean} actual | ||
* @param {string|number|boolean} expected | ||
* @param {boolean} ignoreCase? | ||
*/ | ||
lessthan: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) < DataUtil.toLowerCase(expected); | ||
} | ||
return actual < expected; | ||
}, | ||
/** | ||
* Returns true when the actual input is greater than to the given input. | ||
* @param {string|number|boolean} actual | ||
* @param {string|number|boolean} expected | ||
* @param {boolean} ignoreCase? | ||
*/ | ||
greaterthan: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) > DataUtil.toLowerCase(expected); | ||
} | ||
return actual > expected; | ||
}, | ||
/** | ||
* Returns true when the actual input is less than or equal to the given input. | ||
* @param {string|number|boolean} actual | ||
* @param {string|number|boolean} expected | ||
* @param {boolean} ignoreCase? | ||
*/ | ||
lessthanorequal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) <= DataUtil.toLowerCase(expected); | ||
} | ||
return actual <= expected; | ||
}, | ||
/** | ||
* Returns true when the actual input is greater than or equal to the given input. | ||
* @param {string|number|boolean} actual | ||
* @param {string|number|boolean} expected | ||
* @param {boolean} ignoreCase? | ||
*/ | ||
greaterthanorequal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) >= DataUtil.toLowerCase(expected); | ||
} | ||
return actual >= expected; | ||
}, | ||
/** | ||
* Returns true when the actual input contains the given string. | ||
* @param {string|number} actual | ||
* @param {string|number} expected | ||
* @param {boolean} ignoreCase? | ||
*/ | ||
contains: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return !isNullOrUndefined(actual) && !isNullOrUndefined(expected) && | ||
DataUtil.toLowerCase(actual).indexOf(DataUtil.toLowerCase(expected)) !== -1; | ||
} | ||
return !isNullOrUndefined(actual) && !isNullOrUndefined(expected) && | ||
DataUtil.toLowerCase(actual).indexOf(DataUtil.toLowerCase(expected)) !== -1; | ||
} | ||
return !isNullOrUndefined(actual) && !isNullOrUndefined(expected) && | ||
actual.toString().indexOf(expected) !== -1; | ||
}, | ||
notnull: function (actual) { | ||
return actual !== null; | ||
}, | ||
isnull: function (actual) { | ||
return actual === null; | ||
}, | ||
startswith: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return actual && expected && DataUtil.startsWith(actual.toLowerCase(), expected.toLowerCase()); | ||
} | ||
return actual && expected && DataUtil.startsWith(actual, expected); | ||
}, | ||
endswith: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return actual && expected && DataUtil.endsWith(actual.toLowerCase(), expected.toLowerCase()); | ||
} | ||
return actual && expected && DataUtil.endsWith(actual, expected); | ||
}, | ||
processSymbols: function (operator) { | ||
var fnName = DataUtil.operatorSymbols[operator]; | ||
if (fnName) { | ||
var fn = DataUtil.fnOperators[fnName]; | ||
return fn; | ||
} | ||
return DataUtil.throwError('Query - Process Operator : Invalid operator'); | ||
}, | ||
processOperator: function (operator) { | ||
var fn = DataUtil.fnOperators[operator]; | ||
if (fn) { | ||
return fn; | ||
} | ||
return DataUtil.fnOperators.processSymbols(operator); | ||
} | ||
}; | ||
DataUtil.parse = { | ||
parseJson: function (jsonText) { | ||
if (typeof jsonText === 'string') { | ||
jsonText = JSON.parse(jsonText, DataUtil.parse.jsonReviver); | ||
} | ||
else if (jsonText instanceof Array) { | ||
DataUtil.parse.iterateAndReviveArray(jsonText); | ||
} | ||
else if (typeof jsonText === 'object') { | ||
DataUtil.parse.iterateAndReviveJson(jsonText); | ||
} | ||
return jsonText; | ||
}, | ||
iterateAndReviveArray: function (array) { | ||
for (var i = 0; i < array.length; i++) { | ||
if (typeof array[i] === 'object') { | ||
DataUtil.parse.iterateAndReviveJson(array[i]); | ||
actual.toString().indexOf(expected) !== -1; | ||
}, | ||
/** | ||
* Returns true when the given input value is not null. | ||
* @param {string|number} actual | ||
* @returns boolean | ||
*/ | ||
notnull: function (actual) { | ||
return actual !== null; | ||
}, | ||
/** | ||
* Returns true when the given input value is null. | ||
* @param {string|number} actual | ||
* @returns boolean | ||
*/ | ||
isnull: function (actual) { | ||
return actual === null; | ||
}, | ||
/** | ||
* Returns true when the actual input starts with the given string | ||
* @param {string} actual | ||
* @param {string} expected | ||
* @param {boolean} ignoreCase? | ||
*/ | ||
startswith: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return actual && expected && DataUtil.startsWith(actual.toLowerCase(), expected.toLowerCase()); | ||
} | ||
else if (typeof array[i] === 'string' && !/^[\s]*\[|^[\s]*\{|\"/g.test(array[i])) { | ||
array[i] = DataUtil.parse.jsonReviver('', array[i]); | ||
return actual && expected && DataUtil.startsWith(actual, expected); | ||
}, | ||
/** | ||
* Returns true when the actual input ends with the given string. | ||
* @param {string} actual | ||
* @param {string} expected | ||
* @param {boolean} ignoreCase? | ||
*/ | ||
endswith: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return actual && expected && DataUtil.endsWith(actual.toLowerCase(), expected.toLowerCase()); | ||
} | ||
else { | ||
array[i] = DataUtil.parse.parseJson(array[i]); | ||
return actual && expected && DataUtil.endsWith(actual, expected); | ||
}, | ||
/** | ||
* It will return the filter operator based on the filter symbol. | ||
* @param {string} operator | ||
* @hidden | ||
*/ | ||
processSymbols: function (operator) { | ||
var fnName = DataUtil.operatorSymbols[operator]; | ||
if (fnName) { | ||
var fn = DataUtil.fnOperators[fnName]; | ||
return fn; | ||
} | ||
return DataUtil.throwError('Query - Process Operator : Invalid operator'); | ||
}, | ||
/** | ||
* It will return the valid filter operator based on the specified operators. | ||
* @param {string} operator | ||
* @hidden | ||
*/ | ||
processOperator: function (operator) { | ||
var fn = DataUtil.fnOperators[operator]; | ||
if (fn) { | ||
return fn; | ||
} | ||
return DataUtil.fnOperators.processSymbols(operator); | ||
} | ||
}, | ||
iterateAndReviveJson: function (json) { | ||
var value; | ||
var keys = Object.keys(json); | ||
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) { | ||
var prop = keys_2[_i]; | ||
if (DataUtil.startsWith(prop, '__')) { | ||
continue; | ||
}; | ||
/** | ||
* To perform the parse operation on JSON data, like convert to string from JSON or convert to JSON from string. | ||
*/ | ||
DataUtil.parse = { | ||
/** | ||
* Parse the given string to the plain JavaScript object. | ||
* @param {string|Object|Object[]} jsonText | ||
*/ | ||
parseJson: function (jsonText) { | ||
if (typeof jsonText === 'string') { | ||
jsonText = JSON.parse(jsonText, DataUtil.parse.jsonReviver); | ||
} | ||
value = json[prop]; | ||
if (typeof value === 'object') { | ||
if (value instanceof Array) { | ||
DataUtil.parse.iterateAndReviveArray(value); | ||
else if (jsonText instanceof Array) { | ||
DataUtil.parse.iterateAndReviveArray(jsonText); | ||
} | ||
else if (typeof jsonText === 'object') { | ||
DataUtil.parse.iterateAndReviveJson(jsonText); | ||
} | ||
return jsonText; | ||
}, | ||
/** | ||
* It will perform on array of values. | ||
* @param {string[]|Object[]} array | ||
* @hidden | ||
*/ | ||
iterateAndReviveArray: function (array) { | ||
for (var i = 0; i < array.length; i++) { | ||
if (typeof array[i] === 'object') { | ||
DataUtil.parse.iterateAndReviveJson(array[i]); | ||
} | ||
else if (value) { | ||
DataUtil.parse.iterateAndReviveJson(value); | ||
else if (typeof array[i] === 'string' && !/^[\s]*\[|^[\s]*\{|\"/g.test(array[i])) { | ||
array[i] = DataUtil.parse.jsonReviver('', array[i]); | ||
} | ||
else { | ||
array[i] = DataUtil.parse.parseJson(array[i]); | ||
} | ||
} | ||
else { | ||
json[prop] = DataUtil.parse.jsonReviver(json[prop], value); | ||
}, | ||
/** | ||
* It will perform on JSON values | ||
* @param {JSON} json | ||
* @hidden | ||
*/ | ||
iterateAndReviveJson: function (json) { | ||
var value; | ||
var keys = Object.keys(json); | ||
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) { | ||
var prop = keys_2[_i]; | ||
if (DataUtil.startsWith(prop, '__')) { | ||
continue; | ||
} | ||
value = json[prop]; | ||
if (typeof value === 'object') { | ||
if (value instanceof Array) { | ||
DataUtil.parse.iterateAndReviveArray(value); | ||
} | ||
else if (value) { | ||
DataUtil.parse.iterateAndReviveJson(value); | ||
} | ||
} | ||
else { | ||
json[prop] = DataUtil.parse.jsonReviver(json[prop], value); | ||
} | ||
} | ||
} | ||
}, | ||
jsonReviver: function (field, value) { | ||
var dupValue = value; | ||
if (typeof value === 'string') { | ||
var ms = /^\/Date\(([+-]?[0-9]+)([+-][0-9]{4})?\)\/$/.exec(value); | ||
if (ms) { | ||
return DataUtil.parse.jsonReplacer({ value: new Date(parseInt(ms[1], 10)) }, false).value; | ||
}, | ||
/** | ||
* It will perform on JSON values | ||
* @param {string} field | ||
* @param {string|Date} value | ||
* @hidden | ||
*/ | ||
jsonReviver: function (field, value) { | ||
var dupValue = value; | ||
if (typeof value === 'string') { | ||
var ms = /^\/Date\(([+-]?[0-9]+)([+-][0-9]{4})?\)\/$/.exec(value); | ||
if (ms) { | ||
return DataUtil.parse.jsonReplacer({ value: new Date(parseInt(ms[1], 10)) }, false).value; | ||
} | ||
else if (/^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*){1})([zZ]|([+\-])(\d\d):?(\d\d))?$/.test(value)) { | ||
var arr = dupValue.split(/[^0-9]/); | ||
value = DataUtil.parse.jsonReplacer({ | ||
value: new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, parseInt(arr[2], 10), parseInt(arr[3], 10), parseInt(arr[4], 10), parseInt(arr[5], 10)) | ||
}, false).value; | ||
} | ||
} | ||
else if (/^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*){1})([zZ]|([+\-])(\d\d):?(\d\d))?$/.test(value)) { | ||
var arr = dupValue.split(/[^0-9]/); | ||
value = DataUtil.parse.jsonReplacer({ | ||
value: new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, parseInt(arr[2], 10), parseInt(arr[3], 10), parseInt(arr[4], 10), parseInt(arr[5], 10)) | ||
}, false).value; | ||
return value; | ||
}, | ||
/** | ||
* Check wheather the given value is JSON or not. | ||
* @param {Object[]} jsonData | ||
*/ | ||
isJson: function (jsonData) { | ||
if (typeof jsonData[0] === 'string') { | ||
return jsonData; | ||
} | ||
} | ||
return value; | ||
}, | ||
isJson: function (jsonData) { | ||
if (typeof jsonData[0] === 'string') { | ||
return jsonData; | ||
} | ||
return DataUtil.parse.parseJson(jsonData); | ||
}, | ||
isGuid: function (value) { | ||
var regex = /[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}/i; | ||
var match = regex.exec(value); | ||
return match != null; | ||
}, | ||
replacer: function (value, stringify) { | ||
if (DataUtil.isPlainObject(value)) { | ||
return DataUtil.parse.jsonReplacer(value, stringify); | ||
} | ||
if (value instanceof Array) { | ||
return DataUtil.parse.arrayReplacer(value); | ||
} | ||
if (value instanceof Date) { | ||
return DataUtil.parse.jsonReplacer({ val: value }, stringify).val; | ||
} | ||
return value; | ||
}, | ||
jsonReplacer: function (val, stringify) { | ||
if (stringify === void 0) { stringify = true; } | ||
var value; | ||
var keys = Object.keys(val); | ||
for (var _i = 0, keys_3 = keys; _i < keys_3.length; _i++) { | ||
var prop = keys_3[_i]; | ||
value = val[prop]; | ||
if (!(value instanceof Date)) { | ||
continue; | ||
return DataUtil.parse.parseJson(jsonData); | ||
}, | ||
/** | ||
* Checks wheather the given value is GUID or not. | ||
* @param {string} value | ||
*/ | ||
isGuid: function (value) { | ||
var regex = /[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}/i; | ||
var match = regex.exec(value); | ||
return match != null; | ||
}, | ||
/** | ||
* The method used to replace the value based on the type. | ||
* @param {Object} value | ||
* @param {boolean} stringify | ||
* @hidden | ||
*/ | ||
replacer: function (value, stringify) { | ||
if (DataUtil.isPlainObject(value)) { | ||
return DataUtil.parse.jsonReplacer(value, stringify); | ||
} | ||
var d = value; | ||
var unixstamp = +d - (d.getTimezoneOffset() * 60000); | ||
val[prop] = new Date(unixstamp - (DataUtil.serverTimezoneOffset * 3600000)); | ||
if (stringify) { | ||
val[prop] = val[prop].toJSON(); | ||
if (value instanceof Array) { | ||
return DataUtil.parse.arrayReplacer(value); | ||
} | ||
} | ||
return val; | ||
}, | ||
arrayReplacer: function (val) { | ||
for (var i = 0; i < val.length; i++) { | ||
if (DataUtil.isPlainObject(val[i])) { | ||
val[i] = DataUtil.parse.jsonReplacer(val[i]); | ||
if (value instanceof Date) { | ||
return DataUtil.parse.jsonReplacer({ val: value }, stringify).val; | ||
} | ||
else if (val[i] instanceof Date) { | ||
val[i] = DataUtil.parse.jsonReplacer({ date: val[i] }).date; | ||
return value; | ||
}, | ||
/** | ||
* It will replace the JSON value. | ||
* @param {string} key | ||
* @param {Object} val | ||
* @hidden | ||
*/ | ||
jsonReplacer: function (val, stringify) { | ||
if (stringify === void 0) { stringify = true; } | ||
var value; | ||
var keys = Object.keys(val); | ||
for (var _i = 0, keys_3 = keys; _i < keys_3.length; _i++) { | ||
var prop = keys_3[_i]; | ||
value = val[prop]; | ||
if (!(value instanceof Date)) { | ||
continue; | ||
} | ||
var d = value; | ||
var unixstamp = +d - (d.getTimezoneOffset() * 60000); | ||
val[prop] = new Date(unixstamp - (DataUtil.serverTimezoneOffset * 3600000)); | ||
if (stringify) { | ||
val[prop] = val[prop].toJSON(); | ||
} | ||
} | ||
return val; | ||
}, | ||
/** | ||
* It will replace the Array of value. | ||
* @param {string} key | ||
* @param {Object[]} val | ||
* @hidden | ||
*/ | ||
arrayReplacer: function (val) { | ||
for (var i = 0; i < val.length; i++) { | ||
if (DataUtil.isPlainObject(val[i])) { | ||
val[i] = DataUtil.parse.jsonReplacer(val[i]); | ||
} | ||
else if (val[i] instanceof Date) { | ||
val[i] = DataUtil.parse.jsonReplacer({ date: val[i] }).date; | ||
} | ||
} | ||
return val; | ||
} | ||
return val; | ||
} | ||
}; | ||
}; | ||
return DataUtil; | ||
}()); | ||
export { DataUtil }; |
{ | ||
"name": "@syncfusion/ej2-data", | ||
"version": "15.4.17", | ||
"version": "15.4.20", | ||
"description": "Essential JS 2 DataManager", | ||
@@ -9,3 +9,3 @@ "author": "Syncfusion Inc.", | ||
"dependencies": { | ||
"@syncfusion/ej2-base": "^15.4.17" | ||
"@syncfusion/ej2-base": "^15.4.20" | ||
}, | ||
@@ -12,0 +12,0 @@ "devDependencies": { |
@@ -154,3 +154,3 @@ import { Ajax } from '@syncfusion/ej2-base'; | ||
* @param {Object} data | ||
* @param {number} �position | ||
* @param {number} position | ||
*/ | ||
@@ -157,0 +157,0 @@ insert(dm: DataManager, data: Object, tableName?: string, query?: Query, position?: number): Object; |
@@ -67,3 +67,3 @@ var __extends = (this && this.__extends) || (function () { | ||
} | ||
if (query.requiresCounts) { | ||
if (query.isCountRequired) { | ||
result = { | ||
@@ -334,3 +334,3 @@ result: result, | ||
util_1.DataUtil.callAdaptorFunction(this, 'onSelect', util_1.DataUtil.getValue(singles.onSelect.fieldNames, query), query) : ''; | ||
req[options.count] = query.requiresCounts ? util_1.DataUtil.callAdaptorFunction(this, 'onCount', query.requiresCounts, query) : ''; | ||
req[options.count] = query.isCountRequired ? util_1.DataUtil.callAdaptorFunction(this, 'onCount', query.isCountRequired, query) : ''; | ||
req[options.search] = request.searches.length ? util_1.DataUtil.callAdaptorFunction(this, 'onSearch', request.searches, query) : ''; | ||
@@ -358,3 +358,3 @@ req[options.skip] = 'onSkip' in singles ? | ||
xhr.getResponseHeader('Content-Type').indexOf('xml') !== -1) { | ||
return (query.requiresCounts ? { result: [], count: 0 } : []); | ||
return (query.isCountRequired ? { result: [], count: 0 } : []); | ||
} | ||
@@ -680,3 +680,3 @@ var d = JSON.parse(requests.data); | ||
if (!ej2_base_1.isNullOrUndefined(data.d)) { | ||
var dataCopy = (query && query.requiresCounts) ? data.d.results : data.d; | ||
var dataCopy = (query && query.isCountRequired) ? data.d.results : data.d; | ||
var metaData = '__metadata'; | ||
@@ -699,3 +699,3 @@ if (!ej2_base_1.isNullOrUndefined(dataCopy)) { | ||
var version = (versionCheck && parseInt(versionCheck, 10)) || 2; | ||
if (query && query.requiresCounts) { | ||
if (query && query.isCountRequired) { | ||
var oDataCount = '__count'; | ||
@@ -850,3 +850,3 @@ if (data[oDataCount] || data['odata.count']) { | ||
if (xhr && xhr.getResponseHeader('Content-Type') && xhr.getResponseHeader('Content-Type').indexOf('xml') !== -1) { | ||
return (query.requiresCounts ? { result: [], count: 0 } : []); | ||
return (query.isCountRequired ? { result: [], count: 0 } : []); | ||
} | ||
@@ -949,3 +949,3 @@ if (request && this.options.batch && util_1.DataUtil.endsWith(request.url, this.options.batch) && request.type.toLowerCase() === 'post') { | ||
var dataCount = '@odata.count'; | ||
if (query && query.requiresCounts) { | ||
if (query && query.isCountRequired) { | ||
if (dataCount in data) { | ||
@@ -1002,3 +1002,3 @@ count = data[dataCount]; | ||
var version = (versionCheck && parseInt(versionCheck, 10)) || 2; | ||
if (query && query.requiresCounts) { | ||
if (query && query.isCountRequired) { | ||
if (!util_1.DataUtil.isNull(data.Count)) { | ||
@@ -1005,0 +1005,0 @@ count = data.Count; |
@@ -27,3 +27,3 @@ import { Ajax } from '@syncfusion/ej2-base'; | ||
*/ | ||
constructor(dataSource?: DataOptions | JSON[], query?: Query, adaptor?: AdaptorOptions | string); | ||
constructor(dataSource?: DataOptions | JSON[] | Object[], query?: Query, adaptor?: AdaptorOptions | string); | ||
/** | ||
@@ -30,0 +30,0 @@ * Overrides DataManager's default query with given query. |
@@ -99,3 +99,3 @@ define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "./util", "./query", "./adaptors"], function (require, exports, ej2_base_1, ej2_base_2, util_1, query_1, adaptors_1) { | ||
var lookup = query.subQuery.lookups; | ||
var res = query.requiresCounts ? result.result : | ||
var res = query.isCountRequired ? result.result : | ||
result; | ||
@@ -144,3 +144,3 @@ if (lookup && lookup instanceof Array) { | ||
DataManager.getDeferedArgs = function (query, result, args) { | ||
if (query.requiresCounts) { | ||
if (query.isCountRequired) { | ||
args.result = result.result; | ||
@@ -212,3 +212,3 @@ args.count = result.count; | ||
var virtualRecords = data[virtualSelectRecords]; | ||
if (query.requiresCounts) { | ||
if (query.isCountRequired) { | ||
count = result.count; | ||
@@ -232,2 +232,3 @@ aggregates = result.aggregates; | ||
req = ajax.send(); | ||
req.catch(function (e) { return true; }); | ||
this.requests.push(ajax); | ||
@@ -247,3 +248,3 @@ if (isSelector) { | ||
var count = 0; | ||
if (query.requiresCounts) { | ||
if (query.isCountRequired) { | ||
count = pResult.count; | ||
@@ -254,3 +255,3 @@ pResult = pResult.result; | ||
count = 0; | ||
if (query.subQuery.requiresCounts) { | ||
if (query.subQuery.isCountRequired) { | ||
count = cResult.count; | ||
@@ -309,3 +310,3 @@ cResult = cResult.result; | ||
}; | ||
ajax.send(); | ||
ajax.send().catch(function (e) { return true; }); | ||
return deff.promise; | ||
@@ -376,3 +377,3 @@ }; | ||
}; | ||
ajax.send(); | ||
ajax.send().catch(function (e) { return true; }); | ||
return defer.promise; | ||
@@ -379,0 +380,0 @@ }; |
@@ -32,3 +32,3 @@ import { DataManager } from './manager'; | ||
/** @hidden */ | ||
requiresCounts: boolean; | ||
isCountRequired: boolean; | ||
/** @hidden */ | ||
@@ -35,0 +35,0 @@ dataManager: DataManager; |
@@ -61,3 +61,3 @@ define(["require", "exports", "./util"], function (require, exports, util_1) { | ||
cloned.fKey = this.fKey; | ||
cloned.requiresCounts = this.requiresCounts; | ||
cloned.isCountRequired = this.isCountRequired; | ||
return cloned; | ||
@@ -231,3 +231,3 @@ }; | ||
Query.prototype.requiresCount = function () { | ||
this.requiresCounts = true; | ||
this.isCountRequired = true; | ||
return this; | ||
@@ -234,0 +234,0 @@ }; |
@@ -180,2 +180,12 @@ /** | ||
static getItemFromComparer(array: Object[], field: string, comparer: Function): Object; | ||
/** | ||
* To get distinct values of Array or Array of Objects. | ||
* @param {Object[]} json | ||
* @param {string} field | ||
* @param {boolean} requiresCompleteRecord | ||
* @returns Object[] | ||
* * distinct array of objects is return when requiresCompleteRecord set as true. | ||
* @hidden | ||
*/ | ||
static distinct(json: Object[], fieldName: string, requiresCompleteRecord?: boolean): Object[]; | ||
} | ||
@@ -182,0 +192,0 @@ /** |
550
src/util.js
@@ -313,294 +313,308 @@ define(["require", "exports", "@syncfusion/ej2-base", "./manager", "./query"], function (require, exports, ej2_base_1, manager_1, query_1) { | ||
}; | ||
return DataUtil; | ||
}()); | ||
DataUtil.serverTimezoneOffset = 0; | ||
DataUtil.throwError = function (error) { | ||
try { | ||
throw new Error(error); | ||
} | ||
catch (e) { | ||
throw e.message + '\n' + e.stack; | ||
} | ||
}; | ||
DataUtil.aggregates = { | ||
sum: function (ds, field) { | ||
var result = 0; | ||
DataUtil.distinct = function (json, fieldName, requiresCompleteRecord) { | ||
requiresCompleteRecord = ej2_base_1.isNullOrUndefined(requiresCompleteRecord) ? false : requiresCompleteRecord; | ||
var result = []; | ||
var val; | ||
var castRequired = typeof DataUtil.getVal(ds, 0, field) !== 'number'; | ||
for (var i = 0; i < ds.length; i++) { | ||
val = DataUtil.getVal(ds, i, field); | ||
if (!isNaN(val) && val !== null) { | ||
if (castRequired) { | ||
val = +val; | ||
} | ||
result += val; | ||
var tmp = {}; | ||
json.forEach(function (data, index) { | ||
val = DataUtil.getVal(json, index, fieldName); | ||
if (!(val in tmp)) { | ||
result.push(!requiresCompleteRecord ? val : json[index]); | ||
tmp[val] = 1; | ||
} | ||
} | ||
}); | ||
return result; | ||
}, | ||
average: function (ds, field) { | ||
return DataUtil.aggregates.sum(ds, field) / ds.length; | ||
}, | ||
min: function (ds, field) { | ||
var comparer; | ||
if (typeof field === 'function') { | ||
comparer = field; | ||
field = null; | ||
}; | ||
DataUtil.serverTimezoneOffset = 0; | ||
DataUtil.throwError = function (error) { | ||
try { | ||
throw new Error(error); | ||
} | ||
return DataUtil.getObject(field, DataUtil.getItemFromComparer(ds, field, comparer || DataUtil.fnAscending)); | ||
}, | ||
max: function (ds, field) { | ||
var comparer; | ||
if (typeof field === 'function') { | ||
comparer = field; | ||
field = null; | ||
catch (e) { | ||
throw e.message + '\n' + e.stack; | ||
} | ||
return DataUtil.getObject(field, DataUtil.getItemFromComparer(ds, field, comparer || DataUtil.fnDescending)); | ||
}, | ||
truecount: function (ds, field) { | ||
return new manager_1.DataManager(ds).executeLocal(new query_1.Query().where(field, 'equal', true, true)).length; | ||
}, | ||
falsecount: function (ds, field) { | ||
return new manager_1.DataManager(ds).executeLocal(new query_1.Query().where(field, 'equal', false, true)).length; | ||
}, | ||
count: function (ds, field) { | ||
return ds.length; | ||
} | ||
}; | ||
DataUtil.operatorSymbols = { | ||
'<': 'lessthan', | ||
'>': 'greaterthan', | ||
'<=': 'lessthanorequal', | ||
'>=': 'greaterthanorequal', | ||
'==': 'equal', | ||
'!=': 'notequal', | ||
'*=': 'contains', | ||
'$=': 'endswith', | ||
'^=': 'startswith' | ||
}; | ||
DataUtil.odBiOperator = { | ||
'<': ' lt ', | ||
'>': ' gt ', | ||
'<=': ' le ', | ||
'>=': ' ge ', | ||
'==': ' eq ', | ||
'!=': ' ne ', | ||
'lessthan': ' lt ', | ||
'lessthanorequal': ' le ', | ||
'greaterthan': ' gt ', | ||
'greaterthanorequal': ' ge ', | ||
'equal': ' eq ', | ||
'notequal': ' ne ' | ||
}; | ||
DataUtil.odUniOperator = { | ||
'$=': 'endswith', | ||
'^=': 'startswith', | ||
'*=': 'substringof', | ||
'endswith': 'endswith', | ||
'startswith': 'startswith', | ||
'contains': 'substringof' | ||
}; | ||
DataUtil.odv4UniOperator = { | ||
'$=': 'endswith', | ||
'^=': 'startswith', | ||
'*=': 'contains', | ||
'endswith': 'endswith', | ||
'startswith': 'startswith', | ||
'contains': 'contains' | ||
}; | ||
DataUtil.fnOperators = { | ||
equal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) === DataUtil.toLowerCase(expected); | ||
}; | ||
DataUtil.aggregates = { | ||
sum: function (ds, field) { | ||
var result = 0; | ||
var val; | ||
var castRequired = typeof DataUtil.getVal(ds, 0, field) !== 'number'; | ||
for (var i = 0; i < ds.length; i++) { | ||
val = DataUtil.getVal(ds, i, field); | ||
if (!isNaN(val) && val !== null) { | ||
if (castRequired) { | ||
val = +val; | ||
} | ||
result += val; | ||
} | ||
} | ||
return result; | ||
}, | ||
average: function (ds, field) { | ||
return DataUtil.aggregates.sum(ds, field) / ds.length; | ||
}, | ||
min: function (ds, field) { | ||
var comparer; | ||
if (typeof field === 'function') { | ||
comparer = field; | ||
field = null; | ||
} | ||
return DataUtil.getObject(field, DataUtil.getItemFromComparer(ds, field, comparer || DataUtil.fnAscending)); | ||
}, | ||
max: function (ds, field) { | ||
var comparer; | ||
if (typeof field === 'function') { | ||
comparer = field; | ||
field = null; | ||
} | ||
return DataUtil.getObject(field, DataUtil.getItemFromComparer(ds, field, comparer || DataUtil.fnDescending)); | ||
}, | ||
truecount: function (ds, field) { | ||
return new manager_1.DataManager(ds).executeLocal(new query_1.Query().where(field, 'equal', true, true)).length; | ||
}, | ||
falsecount: function (ds, field) { | ||
return new manager_1.DataManager(ds).executeLocal(new query_1.Query().where(field, 'equal', false, true)).length; | ||
}, | ||
count: function (ds, field) { | ||
return ds.length; | ||
} | ||
return actual === expected; | ||
}, | ||
notequal: function (actual, expected, ignoreCase) { | ||
return !DataUtil.fnOperators.equal(actual, expected, ignoreCase); | ||
}, | ||
lessthan: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) < DataUtil.toLowerCase(expected); | ||
} | ||
return actual < expected; | ||
}, | ||
greaterthan: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) > DataUtil.toLowerCase(expected); | ||
} | ||
return actual > expected; | ||
}, | ||
lessthanorequal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) <= DataUtil.toLowerCase(expected); | ||
} | ||
return actual <= expected; | ||
}, | ||
greaterthanorequal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) >= DataUtil.toLowerCase(expected); | ||
} | ||
return actual >= expected; | ||
}, | ||
contains: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
}; | ||
DataUtil.operatorSymbols = { | ||
'<': 'lessthan', | ||
'>': 'greaterthan', | ||
'<=': 'lessthanorequal', | ||
'>=': 'greaterthanorequal', | ||
'==': 'equal', | ||
'!=': 'notequal', | ||
'*=': 'contains', | ||
'$=': 'endswith', | ||
'^=': 'startswith' | ||
}; | ||
DataUtil.odBiOperator = { | ||
'<': ' lt ', | ||
'>': ' gt ', | ||
'<=': ' le ', | ||
'>=': ' ge ', | ||
'==': ' eq ', | ||
'!=': ' ne ', | ||
'lessthan': ' lt ', | ||
'lessthanorequal': ' le ', | ||
'greaterthan': ' gt ', | ||
'greaterthanorequal': ' ge ', | ||
'equal': ' eq ', | ||
'notequal': ' ne ' | ||
}; | ||
DataUtil.odUniOperator = { | ||
'$=': 'endswith', | ||
'^=': 'startswith', | ||
'*=': 'substringof', | ||
'endswith': 'endswith', | ||
'startswith': 'startswith', | ||
'contains': 'substringof' | ||
}; | ||
DataUtil.odv4UniOperator = { | ||
'$=': 'endswith', | ||
'^=': 'startswith', | ||
'*=': 'contains', | ||
'endswith': 'endswith', | ||
'startswith': 'startswith', | ||
'contains': 'contains' | ||
}; | ||
DataUtil.fnOperators = { | ||
equal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) === DataUtil.toLowerCase(expected); | ||
} | ||
return actual === expected; | ||
}, | ||
notequal: function (actual, expected, ignoreCase) { | ||
return !DataUtil.fnOperators.equal(actual, expected, ignoreCase); | ||
}, | ||
lessthan: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) < DataUtil.toLowerCase(expected); | ||
} | ||
return actual < expected; | ||
}, | ||
greaterthan: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) > DataUtil.toLowerCase(expected); | ||
} | ||
return actual > expected; | ||
}, | ||
lessthanorequal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) <= DataUtil.toLowerCase(expected); | ||
} | ||
return actual <= expected; | ||
}, | ||
greaterthanorequal: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return DataUtil.toLowerCase(actual) >= DataUtil.toLowerCase(expected); | ||
} | ||
return actual >= expected; | ||
}, | ||
contains: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return !ej2_base_1.isNullOrUndefined(actual) && !ej2_base_1.isNullOrUndefined(expected) && | ||
DataUtil.toLowerCase(actual).indexOf(DataUtil.toLowerCase(expected)) !== -1; | ||
} | ||
return !ej2_base_1.isNullOrUndefined(actual) && !ej2_base_1.isNullOrUndefined(expected) && | ||
DataUtil.toLowerCase(actual).indexOf(DataUtil.toLowerCase(expected)) !== -1; | ||
} | ||
return !ej2_base_1.isNullOrUndefined(actual) && !ej2_base_1.isNullOrUndefined(expected) && | ||
actual.toString().indexOf(expected) !== -1; | ||
}, | ||
notnull: function (actual) { | ||
return actual !== null; | ||
}, | ||
isnull: function (actual) { | ||
return actual === null; | ||
}, | ||
startswith: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return actual && expected && DataUtil.startsWith(actual.toLowerCase(), expected.toLowerCase()); | ||
} | ||
return actual && expected && DataUtil.startsWith(actual, expected); | ||
}, | ||
endswith: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return actual && expected && DataUtil.endsWith(actual.toLowerCase(), expected.toLowerCase()); | ||
} | ||
return actual && expected && DataUtil.endsWith(actual, expected); | ||
}, | ||
processSymbols: function (operator) { | ||
var fnName = DataUtil.operatorSymbols[operator]; | ||
if (fnName) { | ||
var fn = DataUtil.fnOperators[fnName]; | ||
return fn; | ||
} | ||
return DataUtil.throwError('Query - Process Operator : Invalid operator'); | ||
}, | ||
processOperator: function (operator) { | ||
var fn = DataUtil.fnOperators[operator]; | ||
if (fn) { | ||
return fn; | ||
} | ||
return DataUtil.fnOperators.processSymbols(operator); | ||
} | ||
}; | ||
DataUtil.parse = { | ||
parseJson: function (jsonText) { | ||
if (typeof jsonText === 'string') { | ||
jsonText = JSON.parse(jsonText, DataUtil.parse.jsonReviver); | ||
} | ||
else if (jsonText instanceof Array) { | ||
DataUtil.parse.iterateAndReviveArray(jsonText); | ||
} | ||
else if (typeof jsonText === 'object') { | ||
DataUtil.parse.iterateAndReviveJson(jsonText); | ||
} | ||
return jsonText; | ||
}, | ||
iterateAndReviveArray: function (array) { | ||
for (var i = 0; i < array.length; i++) { | ||
if (typeof array[i] === 'object') { | ||
DataUtil.parse.iterateAndReviveJson(array[i]); | ||
actual.toString().indexOf(expected) !== -1; | ||
}, | ||
notnull: function (actual) { | ||
return actual !== null; | ||
}, | ||
isnull: function (actual) { | ||
return actual === null; | ||
}, | ||
startswith: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return actual && expected && DataUtil.startsWith(actual.toLowerCase(), expected.toLowerCase()); | ||
} | ||
else if (typeof array[i] === 'string' && !/^[\s]*\[|^[\s]*\{|\"/g.test(array[i])) { | ||
array[i] = DataUtil.parse.jsonReviver('', array[i]); | ||
return actual && expected && DataUtil.startsWith(actual, expected); | ||
}, | ||
endswith: function (actual, expected, ignoreCase) { | ||
if (ignoreCase) { | ||
return actual && expected && DataUtil.endsWith(actual.toLowerCase(), expected.toLowerCase()); | ||
} | ||
else { | ||
array[i] = DataUtil.parse.parseJson(array[i]); | ||
return actual && expected && DataUtil.endsWith(actual, expected); | ||
}, | ||
processSymbols: function (operator) { | ||
var fnName = DataUtil.operatorSymbols[operator]; | ||
if (fnName) { | ||
var fn = DataUtil.fnOperators[fnName]; | ||
return fn; | ||
} | ||
return DataUtil.throwError('Query - Process Operator : Invalid operator'); | ||
}, | ||
processOperator: function (operator) { | ||
var fn = DataUtil.fnOperators[operator]; | ||
if (fn) { | ||
return fn; | ||
} | ||
return DataUtil.fnOperators.processSymbols(operator); | ||
} | ||
}, | ||
iterateAndReviveJson: function (json) { | ||
var value; | ||
var keys = Object.keys(json); | ||
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) { | ||
var prop = keys_2[_i]; | ||
if (DataUtil.startsWith(prop, '__')) { | ||
continue; | ||
}; | ||
DataUtil.parse = { | ||
parseJson: function (jsonText) { | ||
if (typeof jsonText === 'string') { | ||
jsonText = JSON.parse(jsonText, DataUtil.parse.jsonReviver); | ||
} | ||
value = json[prop]; | ||
if (typeof value === 'object') { | ||
if (value instanceof Array) { | ||
DataUtil.parse.iterateAndReviveArray(value); | ||
else if (jsonText instanceof Array) { | ||
DataUtil.parse.iterateAndReviveArray(jsonText); | ||
} | ||
else if (typeof jsonText === 'object') { | ||
DataUtil.parse.iterateAndReviveJson(jsonText); | ||
} | ||
return jsonText; | ||
}, | ||
iterateAndReviveArray: function (array) { | ||
for (var i = 0; i < array.length; i++) { | ||
if (typeof array[i] === 'object') { | ||
DataUtil.parse.iterateAndReviveJson(array[i]); | ||
} | ||
else if (value) { | ||
DataUtil.parse.iterateAndReviveJson(value); | ||
else if (typeof array[i] === 'string' && !/^[\s]*\[|^[\s]*\{|\"/g.test(array[i])) { | ||
array[i] = DataUtil.parse.jsonReviver('', array[i]); | ||
} | ||
else { | ||
array[i] = DataUtil.parse.parseJson(array[i]); | ||
} | ||
} | ||
else { | ||
json[prop] = DataUtil.parse.jsonReviver(json[prop], value); | ||
}, | ||
iterateAndReviveJson: function (json) { | ||
var value; | ||
var keys = Object.keys(json); | ||
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) { | ||
var prop = keys_2[_i]; | ||
if (DataUtil.startsWith(prop, '__')) { | ||
continue; | ||
} | ||
value = json[prop]; | ||
if (typeof value === 'object') { | ||
if (value instanceof Array) { | ||
DataUtil.parse.iterateAndReviveArray(value); | ||
} | ||
else if (value) { | ||
DataUtil.parse.iterateAndReviveJson(value); | ||
} | ||
} | ||
else { | ||
json[prop] = DataUtil.parse.jsonReviver(json[prop], value); | ||
} | ||
} | ||
} | ||
}, | ||
jsonReviver: function (field, value) { | ||
var dupValue = value; | ||
if (typeof value === 'string') { | ||
var ms = /^\/Date\(([+-]?[0-9]+)([+-][0-9]{4})?\)\/$/.exec(value); | ||
if (ms) { | ||
return DataUtil.parse.jsonReplacer({ value: new Date(parseInt(ms[1], 10)) }, false).value; | ||
}, | ||
jsonReviver: function (field, value) { | ||
var dupValue = value; | ||
if (typeof value === 'string') { | ||
var ms = /^\/Date\(([+-]?[0-9]+)([+-][0-9]{4})?\)\/$/.exec(value); | ||
if (ms) { | ||
return DataUtil.parse.jsonReplacer({ value: new Date(parseInt(ms[1], 10)) }, false).value; | ||
} | ||
else if (/^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*){1})([zZ]|([+\-])(\d\d):?(\d\d))?$/.test(value)) { | ||
var arr = dupValue.split(/[^0-9]/); | ||
value = DataUtil.parse.jsonReplacer({ | ||
value: new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, parseInt(arr[2], 10), parseInt(arr[3], 10), parseInt(arr[4], 10), parseInt(arr[5], 10)) | ||
}, false).value; | ||
} | ||
} | ||
else if (/^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*){1})([zZ]|([+\-])(\d\d):?(\d\d))?$/.test(value)) { | ||
var arr = dupValue.split(/[^0-9]/); | ||
value = DataUtil.parse.jsonReplacer({ | ||
value: new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, parseInt(arr[2], 10), parseInt(arr[3], 10), parseInt(arr[4], 10), parseInt(arr[5], 10)) | ||
}, false).value; | ||
return value; | ||
}, | ||
isJson: function (jsonData) { | ||
if (typeof jsonData[0] === 'string') { | ||
return jsonData; | ||
} | ||
} | ||
return value; | ||
}, | ||
isJson: function (jsonData) { | ||
if (typeof jsonData[0] === 'string') { | ||
return jsonData; | ||
} | ||
return DataUtil.parse.parseJson(jsonData); | ||
}, | ||
isGuid: function (value) { | ||
var regex = /[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}/i; | ||
var match = regex.exec(value); | ||
return match != null; | ||
}, | ||
replacer: function (value, stringify) { | ||
if (DataUtil.isPlainObject(value)) { | ||
return DataUtil.parse.jsonReplacer(value, stringify); | ||
} | ||
if (value instanceof Array) { | ||
return DataUtil.parse.arrayReplacer(value); | ||
} | ||
if (value instanceof Date) { | ||
return DataUtil.parse.jsonReplacer({ val: value }, stringify).val; | ||
} | ||
return value; | ||
}, | ||
jsonReplacer: function (val, stringify) { | ||
if (stringify === void 0) { stringify = true; } | ||
var value; | ||
var keys = Object.keys(val); | ||
for (var _i = 0, keys_3 = keys; _i < keys_3.length; _i++) { | ||
var prop = keys_3[_i]; | ||
value = val[prop]; | ||
if (!(value instanceof Date)) { | ||
continue; | ||
return DataUtil.parse.parseJson(jsonData); | ||
}, | ||
isGuid: function (value) { | ||
var regex = /[A-Fa-f0-9]{8}(?:-[A-Fa-f0-9]{4}){3}-[A-Fa-f0-9]{12}/i; | ||
var match = regex.exec(value); | ||
return match != null; | ||
}, | ||
replacer: function (value, stringify) { | ||
if (DataUtil.isPlainObject(value)) { | ||
return DataUtil.parse.jsonReplacer(value, stringify); | ||
} | ||
var d = value; | ||
var unixstamp = +d - (d.getTimezoneOffset() * 60000); | ||
val[prop] = new Date(unixstamp - (DataUtil.serverTimezoneOffset * 3600000)); | ||
if (stringify) { | ||
val[prop] = val[prop].toJSON(); | ||
if (value instanceof Array) { | ||
return DataUtil.parse.arrayReplacer(value); | ||
} | ||
} | ||
return val; | ||
}, | ||
arrayReplacer: function (val) { | ||
for (var i = 0; i < val.length; i++) { | ||
if (DataUtil.isPlainObject(val[i])) { | ||
val[i] = DataUtil.parse.jsonReplacer(val[i]); | ||
if (value instanceof Date) { | ||
return DataUtil.parse.jsonReplacer({ val: value }, stringify).val; | ||
} | ||
else if (val[i] instanceof Date) { | ||
val[i] = DataUtil.parse.jsonReplacer({ date: val[i] }).date; | ||
return value; | ||
}, | ||
jsonReplacer: function (val, stringify) { | ||
if (stringify === void 0) { stringify = true; } | ||
var value; | ||
var keys = Object.keys(val); | ||
for (var _i = 0, keys_3 = keys; _i < keys_3.length; _i++) { | ||
var prop = keys_3[_i]; | ||
value = val[prop]; | ||
if (!(value instanceof Date)) { | ||
continue; | ||
} | ||
var d = value; | ||
var unixstamp = +d - (d.getTimezoneOffset() * 60000); | ||
val[prop] = new Date(unixstamp - (DataUtil.serverTimezoneOffset * 3600000)); | ||
if (stringify) { | ||
val[prop] = val[prop].toJSON(); | ||
} | ||
} | ||
return val; | ||
}, | ||
arrayReplacer: function (val) { | ||
for (var i = 0; i < val.length; i++) { | ||
if (DataUtil.isPlainObject(val[i])) { | ||
val[i] = DataUtil.parse.jsonReplacer(val[i]); | ||
} | ||
else if (val[i] instanceof Date) { | ||
val[i] = DataUtil.parse.jsonReplacer({ date: val[i] }).date; | ||
} | ||
} | ||
return val; | ||
} | ||
return val; | ||
} | ||
}; | ||
}; | ||
return DataUtil; | ||
}()); | ||
exports.DataUtil = DataUtil; | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1104435
16218