@mescius/wijmo.rest 5.20242.20-nightly.d20240824.t020158 → 5.20242.20-nightly.d20240826.t020151
Sign up to get free protection for your applications and to get access to all the features.
- package/es2015-commonjs.js +2 -2
- package/es2015-esm.js +2 -2
- package/es5-esm.js +2 -2
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/package.json +2 -2
package/es2015-commonjs.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
*
|
3
|
-
* Wijmo Library 5.20242.20-nightly.
|
3
|
+
* Wijmo Library 5.20242.20-nightly.d20240826.t020151
|
4
4
|
* https://developer.mescius.com/wijmo
|
5
5
|
*
|
6
6
|
* Copyright(c) MESCIUS inc. All rights reserved.
|
@@ -11,4 +11,4 @@
|
|
11
11
|
*
|
12
12
|
*/
|
13
13
|
|
14
|
-
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,s){return new(i||(i=Promise))((function(r,o){function fulfilled(t){try{step(s.next(t))}catch(t){o(t)}}function rejected(t){try{step(s.throw(t))}catch(t){o(t)}}function step(t){t.done?r(t.value):new i((function(e){e(t.value)})).then(fulfilled,rejected)}step((s=s.apply(t,e||[])).next())}))},__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var i in t)Object.hasOwnProperty.call(t,i)&&(e[i]=t[i]);e.default=t;return e};Object.defineProperty(exports,"__esModule",{value:!0});const wijmo_1=require("@mescius/wijmo"),selfModule=__importStar(require("@mescius/wijmo.rest")),_MIN_DATA_WINDOW=100;class RestCollectionView extends wijmo_1.CollectionView{constructor(t){super();this._loading=!1;this._fields=null;this._keys=null;this._sortOnServer=!0;this._pageOnServer=!0;this._filterOnServer=!0;this._totalItemCount=0;this._aggregates="";this._groupOnServer=!0;this._groupLazyLoading=!1;this._virtualization=!1;this._start=0;this._end=_MIN_DATA_WINDOW;this._expandedGroups=[];this._groupItems=[];this._groupRefresh=!1;this._refresh=!1;this.loading=new wijmo_1.Event;this.loaded=new wijmo_1.Event;this.error=new wijmo_1.Event;t&&wijmo_1.copy(this,t);this.sortDescriptions.collectionChanged.addHandler(()=>{this.sortOnServer&&this._getData()});this._getData();(this._groupOnServer||this._virtualization)&&(this._data=[]);this._virtualization&&this.setWindow(this._start,_MIN_DATA_WINDOW);this._firstLoad=this._groupRefresh=!0}get totalGroupItemCount(){return this.groupOnServer?this._totalGroupItemCount:0}get groupOnServer(){return this._groupOnServer}set groupOnServer(t){if(t!=this._groupOnServer){this._groupOnServer=wijmo_1.asBoolean(t);this._getData()}}get groupLazyLoading(){return this._groupLazyLoading}set groupLazyLoading(t){t!=this._groupLazyLoading&&this._groupOnServer&&(this._groupLazyLoading=wijmo_1.asBoolean(t))}get virtualization(){return this._virtualization}set virtualization(t){t!=this.virtualization&&(this._virtualization=wijmo_1.asBoolean(t))}get fields(){return this._fields}set fields(t){if(this._fields!=t){this._fields=wijmo_1.asArray(t);this._getData()}}get sortOnServer(){return this._sortOnServer}set sortOnServer(t){if(t!=this._sortOnServer){this._sortOnServer=wijmo_1.asBoolean(t);this._getData()}}get pageOnServer(){return this._pageOnServer}set pageOnServer(t){if(t!=this._pageOnServer){this._pageOnServer=wijmo_1.asBoolean(t);this._getData()}}get filterOnServer(){return this._filterOnServer}set filterOnServer(t){if(t!=this._filterOnServer){this._filterOnServer=wijmo_1.asBoolean(t);this._getData()}}get requestHeaders(){return this._requestHeaders}set requestHeaders(t){this._requestHeaders=t}get aggregates(){return this._aggregates}set aggregates(t){wijmo_1.assert(this._groupOnServer,"groupOnServer should be enabled");wijmo_1.isString(t)&&t!=this._aggregates&&(this._aggregates=t)}updateFilterDefinition(t){if(this.filterOnServer){this._filterProvider=t;this._getData()}}lazyLoadGroup(t){if(this._groupLazyLoading){t.groups.length>0&&null==t.groups[0].name&&this._getData(t);0==t.groups.length&&t.isBottomLevel&&this._getData(t)}else wijmo_1.assert(this._groupLazyLoading,"groupLazyLoading should be enabled lazy load the groups.")}setWindow(t,e){this._toSetWindow&&clearTimeout(this._toSetWindow);this._toSetWindow=setTimeout(()=>{this._toSetWindow=null;this._performSetWindow(t,e)},50)}_getFilterGroupItems(t){let e=this._groupItems,i=t.items[0];for(let s=0;s<=t.level;s++){let t=this.groupDescriptions[s].propertyName;e=e.filter(e=>e.groupKey[t]==i[t])}return e}getGroupAggregate(t,e,i=wijmo_1.Aggregate.Sum){if(this.groupLazyLoading||this.virtualization){let s="",r=this._getFilterGroupItems(e);r&&0!=r.length&&r.length!=this._groupItems.length&&r[0].aggregates&&(s=wijmo_1.getAggregate(i,r,`aggregates.${t}`));return s}}get isLoading(){return this._loading}onLoading(t){this.loading.raise(this,t)}onLoaded(t){this.loaded.raise(this,t)}load(){this._getData()}onError(t){this.error.raise(this,t);return!t.cancel}_performRefresh(){this.isLoading||(this._refresh=!0);let t=this._canFilter,e=this._canSort;this._canFilter=!this._filterOnServer;this._canSort=!this._sortOnServer;super._performRefresh();this._canFilter=t;this._canSort=e}get totalItemCount(){return this.pageOnServer?this._totalItemCount:this._view.length}get pageCount(){return this.pageSize?Math.ceil(this.totalItemCount/this.pageSize):1}get pageSize(){return this._pgSz}set pageSize(t){if(t!=this._pgSz){this._pgSz=wijmo_1.asInt(t);if(this.pageOnServer){this._pgIdx=wijmo_1.clamp(this._pgIdx,0,this.pageCount-1);this._getData()}else this.refresh()}}onPageChanging(t){super.onPageChanging(t);this.pageOnServer&&!t.cancel&&this._getData();return!t.cancel}commitNew(){let t=this.currentAddItem;if(t)try{let e=this.addItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.commitNew()}commitEdit(){let t=this.currentEditItem;if(t&&!this.currentAddItem&&!this._sameContent(t,this._edtClone)&&this.items.indexOf(t)>-1)try{let e=this.patchItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.commitEdit()}remove(t){if(t&&t!=this.currentAddItem&&this.items.indexOf(t)>-1)try{let e=this.deleteItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.remove(t)}_getPageView(){return this.pageOnServer?this._view:super._getPageView()}_getData(t){this._toGetData&&clearTimeout(this._toGetData);this._toGetData=setTimeout(()=>__awaiter(this,void 0,void 0,(function*(){this._toGetData=null;this._loading=!0;this.onLoading();let e=null;if(this._groupOnServer||this._virtualization){let e=-1;this.currentPosition>-1&&(e=this.currentPosition);let i=this.groupDescriptions;this._data||(this._data=[]);let s,r=[];if((this._groupRefresh||this._groupLazyLoading&&(!t||!t.isBottomLevel))&&this._groupOnServer&&i.length>0){r=yield this.getGroupItems(t);t?this._updateSubGroups(t,r):this._groupItems=r;this._groupRefresh=!1}this._groupLazyLoading||(s=yield this.getItems());this._groupLazyLoading&&t&&t.isBottomLevel&&(s=yield this.getItems(t));this.deferUpdate(()=>__awaiter(this,void 0,void 0,(function*(){this._virtualization||this._groupLazyLoading||(this._data=s);if(this._groupLazyLoading&&!this._virtualization)if(t)this._loadSubGroupsData(t,r,s);else{this._data=new Array;const e=i[0].propertyName;for(let t=0;t<r.length;t++){let i=new Object,s=r[t].count;i[e]=r[t].groupKey[e];for(let t=0;t<s;t++)this._data.push(i)}this._expandedGroups.length>0&&(yield this._loadExpandedGroups(t))}this._virtualization&&!this._groupLazyLoading&&this._storeItems(s,!1);this.sourceCollection=this._data})));this.refresh();e>-1&&this.moveCurrentToPosition(e)}else{let t=null;try{let e=this.currentPosition;t=yield this.getItems();this.sourceCollection=t;this.refresh();e>-1&&this.moveCurrentToPosition(e);this.pageIndex>0&&this.pageIndex>=this.pageCount&&this.moveToLastPage()}catch(t){e=t}}this._loading=!1;this.onLoaded();e&&this._raiseError(e,!1)})),100)}_loadExpandedGroups(t){return __awaiter(this,void 0,void 0,(function*(){if(this._expandedGroups.length>0&&!t){let t=[];this._expandedGroups.forEach(e=>__awaiter(this,void 0,void 0,(function*(){e.isBottomLevel?t.push(this.getItems(e)):t.push(this.getGroupItems(e))})));return new Promise(e=>{Promise.all(t).then(t=>{for(let e=0;e<this._expandedGroups.length;e++)if(this._expandedGroups[e].isBottomLevel)this._loadSubGroupsData(this._expandedGroups[e],[],t[e]);else{this._updateSubGroups(this._expandedGroups[e],t[e]);this._loadSubGroupsData(this._expandedGroups[e],t[e],[])}e(!0)}).catch(t=>{e(!1)})})}}))}_updateSubGroups(t,e){let i=this._getFilterGroupItems(t);if(1==i.length){for(let t=0;t<e.length;t++)e[t].groupKey=Object.assign({},i[0].groupKey,e[t].groupKey);let t=this._groupItems.indexOf(i[0]);this._groupItems.splice(t,1,...e)}else console.error("unable to find exact match for targetted group")}_loadSubGroupsData(t,e,i){let s=this.groupDescriptions,r=this._data;for(let e=0;e<=(t.isBottomLevel?s.length-1:t.level);e++){const i=s[e].propertyName,o=t.items[e][i];r=r.filter(t=>t[i]===o)}let o=this._data.indexOf(r[0]);r=JSON.parse(JSON.stringify(r));if(t.isBottomLevel)for(let t=0;t<i.length;t++)Object.assign(r[t],i[t]);else{let i=t.groups[0].groupDescription.propertyName,s=0;for(let t=0;t<e.length;t++){s+=t>0?e[t-1].count:0;for(let o=0;o<e[t].count;o++)r[s+o][i]=e[t].groupKey[i]}}this._data.splice(o,r.length,...r)}_updateExpandedGroups(t,e){if(!this._loading){let i=this._expandedGroups.filter(e=>e._path.indexOf(t._path)>-1);if(e)this._expandedGroups.push(t);else if(i.length>0)for(let t=0;t<i.length;t++)this._expandedGroups.splice(this._expandedGroups.indexOf(i[t]),1)}}_storeItems(t,e){return __awaiter(this,void 0,void 0,(function*(){if(this._refresh||this._data.length!=this.totalItemCount||this.groups&&this.groups.length!=this._totalGroupItemCount){if(this._data.length!=this.totalItemCount&&this.groups&&this.groups.length>0){this._groupRefresh=!0;this._getData()}this._data.length=this.totalItemCount;if(this._groupOnServer&&this._groupItems.length>0&&this.groupDescriptions.length>0){let t=JSON.parse(JSON.stringify(this.groups)),e=0;for(let t=0;t<this._groupItems.length;t++){let i=Object.keys(this._groupItems[t].groupKey);for(let s=0;s<this._groupItems[t].count;s++){let s=new wijmo_1._NullValue(e);i.forEach(e=>{s[e]=this._groupItems[t].groupKey[e]});this._data[e]=s;e++}}if(0!=this.groups.length&&this.groups.length<t.length){let e=this._data[this._start],i=this.groupDescriptions.length,s=this.groupDescriptions[i-1].propertyName,r=this.groups.findIndex(t=>t.name==e[s]),o=t.findIndex(t=>t.name==e[s]);this._start+=r-o;this._getData()}}else for(let t=0;t<this._data.length;t++)this._data[t]=new wijmo_1._NullValue(t);this._refresh=!1}e||(this._loadOffset=0);let i=this._loadOffset+(this._start||0);for(let e=0;e<t.length;e++)this._data[e+i]=t[e];this._loadOffset+=t.length;setTimeout(()=>{this._firstLoad&&this.currentPosition<0&&t.length&&this.moveCurrentToFirst();this._firstLoad=!1})}))}_performSetWindow(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}t=wijmo_1.asInt(t);e=wijmo_1.asInt(e);wijmo_1.assert(t<=e,"start must be <= end.");let i=t<this._start,s=this._data;this._start=this._end=t;for(let i=t;i<=e&&i<s.length;i++)if(s[i]instanceof wijmo_1._NullValue){this._start=i;break}for(let t=e;t>=this._start&&t<s.length;t--)if(s[t]instanceof wijmo_1._NullValue){this._end=t;break}if(this._start!=this._end||s[this._start]instanceof wijmo_1._NullValue){i&&(this._start=Math.max(0,this._end-this._fetchSize()+1));this._getData()}}_fetchSize(){return Math.max(this._end-this._start+1,this.pageSize,_MIN_DATA_WINDOW)}_raiseError(t,e){if(this.onError(new RESTErrorEventArgs(t))){e&&this._getData();throw"Server Error: "+t}}get requestCanceled(){this._requestCanceled||(this._requestCanceled=new wijmo_1.Event);return this._requestCanceled}onRequestCanceled(t){this.requestCanceled.raise(this,t)}getGroupItems(t){throw"This method is virtual: it should be overridden"}getItems(t){throw"This method is virtual: it should be overridden"}addItem(t){throw"This method is virtual: it should be overridden"}patchItem(t){throw"This method is virtual: it should be overridden"}deleteItem(t){throw"This method is virtual: it should be overridden"}}exports.RestCollectionView=RestCollectionView;class RESTErrorEventArgs extends wijmo_1.CancelEventArgs{constructor(t){super();this._error=t}get error(){return this._error}}exports.RESTErrorEventArgs=RESTErrorEventArgs;wijmo_1._registerModule("wijmo.rest",selfModule);
|
14
|
+
"use strict";var __awaiter=this&&this.__awaiter||function(t,e,i,s){return new(i||(i=Promise))((function(r,o){function fulfilled(t){try{step(s.next(t))}catch(t){o(t)}}function rejected(t){try{step(s.throw(t))}catch(t){o(t)}}function step(t){t.done?r(t.value):new i((function(e){e(t.value)})).then(fulfilled,rejected)}step((s=s.apply(t,e||[])).next())}))},__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var i in t)Object.hasOwnProperty.call(t,i)&&(e[i]=t[i]);e.default=t;return e};Object.defineProperty(exports,"__esModule",{value:!0});const wijmo_1=require("@mescius/wijmo"),selfModule=__importStar(require("@mescius/wijmo.rest")),_MIN_DATA_WINDOW=100;class RestCollectionView extends wijmo_1.CollectionView{constructor(t){super();this._loading=!1;this._fields=null;this._keys=null;this._sortOnServer=!0;this._pageOnServer=!0;this._filterOnServer=!0;this._totalItemCount=0;this._aggregates="";this._groupOnServer=!0;this._groupLazyLoading=!1;this._virtualization=!1;this._start=0;this._end=_MIN_DATA_WINDOW;this._expandedGroups=[];this._groupItems=[];this._groupRefresh=!1;this._refresh=!1;this.loading=new wijmo_1.Event;this.loaded=new wijmo_1.Event;this.error=new wijmo_1.Event;t&&wijmo_1.copy(this,t);this.sortDescriptions.collectionChanged.addHandler(()=>{this.sortOnServer&&this._getData()});this._getData();(this._groupOnServer||this._virtualization)&&(this._data=[]);this._virtualization&&this.setWindow(this._start,_MIN_DATA_WINDOW);this._firstLoad=this._groupRefresh=!0}get totalGroupItemCount(){return this.groupOnServer?this._totalGroupItemCount:0}get groupOnServer(){return this._groupOnServer}set groupOnServer(t){if(t!=this._groupOnServer){this._groupOnServer=wijmo_1.asBoolean(t);this._getData()}}get groupLazyLoading(){return this._groupLazyLoading}set groupLazyLoading(t){t!=this._groupLazyLoading&&this._groupOnServer&&(this._groupLazyLoading=wijmo_1.asBoolean(t))}get virtualization(){return this._virtualization}set virtualization(t){t!=this.virtualization&&(this._virtualization=wijmo_1.asBoolean(t))}get fields(){return this._fields}set fields(t){if(this._fields!=t){this._fields=wijmo_1.asArray(t);this._getData()}}get sortOnServer(){return this._sortOnServer}set sortOnServer(t){if(t!=this._sortOnServer){this._sortOnServer=wijmo_1.asBoolean(t);this._getData()}}get pageOnServer(){return this._pageOnServer}set pageOnServer(t){if(t!=this._pageOnServer){this._pageOnServer=wijmo_1.asBoolean(t);this._getData()}}get filterOnServer(){return this._filterOnServer}set filterOnServer(t){if(t!=this._filterOnServer){this._filterOnServer=wijmo_1.asBoolean(t);this._getData()}}get requestHeaders(){return this._requestHeaders}set requestHeaders(t){this._requestHeaders=t}get aggregates(){return this._aggregates}set aggregates(t){wijmo_1.assert(this._groupOnServer,"groupOnServer should be enabled");wijmo_1.isString(t)&&t!=this._aggregates&&(this._aggregates=t)}updateFilterDefinition(t){if(this.filterOnServer){this._filterProvider=t;this._getData()}}lazyLoadGroup(t){if(this._groupLazyLoading){t.groups.length>0&&null==t.groups[0].name&&this._getData(t);0==t.groups.length&&t.isBottomLevel&&this._getData(t)}else wijmo_1.assert(this._groupLazyLoading,"groupLazyLoading should be enabled lazy load the groups.")}setWindow(t,e){this._toSetWindow&&clearTimeout(this._toSetWindow);this._toSetWindow=setTimeout(()=>{this._toSetWindow=null;this._performSetWindow(t,e)},50)}_getFilterGroupItems(t){let e=this._groupItems,i=t.items[0];for(let s=0;s<=t.level;s++){let t=this.groupDescriptions[s].propertyName;e=e.filter(e=>e.groupKey[t]==i[t])}return e}getGroupAggregate(t,e,i=wijmo_1.Aggregate.Sum){if(this.groupOnServer&&(this.groupLazyLoading||this.virtualization||this.groupDescriptions.length>0&&this._groupItems.length>0)){let s="",r=this._getFilterGroupItems(e);r&&0!=r.length&&r.length!=this._groupItems.length&&r[0].aggregates&&(s=wijmo_1.getAggregate(i,r,`aggregates.${t}`));return s}}get isLoading(){return this._loading}onLoading(t){this.loading.raise(this,t)}onLoaded(t){this.loaded.raise(this,t)}load(){this._getData()}onError(t){this.error.raise(this,t);return!t.cancel}_performRefresh(){this.isLoading||(this._refresh=!0);let t=this._canFilter,e=this._canSort;this._canFilter=!this._filterOnServer;this._canSort=!this._sortOnServer;super._performRefresh();this._canFilter=t;this._canSort=e}get totalItemCount(){return this.pageOnServer?this._totalItemCount:this._view.length}get pageCount(){return this.pageSize?Math.ceil(this.totalItemCount/this.pageSize):1}get pageSize(){return this._pgSz}set pageSize(t){if(t!=this._pgSz){this._pgSz=wijmo_1.asInt(t);if(this.pageOnServer){this._pgIdx=wijmo_1.clamp(this._pgIdx,0,this.pageCount-1);this._getData()}else this.refresh()}}onPageChanging(t){super.onPageChanging(t);this.pageOnServer&&!t.cancel&&this._getData();return!t.cancel}commitNew(){let t=this.currentAddItem;if(t)try{let e=this.addItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.commitNew()}commitEdit(){let t=this.currentEditItem;if(t&&!this.currentAddItem&&!this._sameContent(t,this._edtClone)&&this.items.indexOf(t)>-1)try{let e=this.patchItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.commitEdit()}remove(t){if(t&&t!=this.currentAddItem&&this.items.indexOf(t)>-1)try{let e=this.deleteItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.remove(t)}_getPageView(){return this.pageOnServer?this._view:super._getPageView()}_getData(t){this._toGetData&&clearTimeout(this._toGetData);this._toGetData=setTimeout(()=>__awaiter(this,void 0,void 0,(function*(){this._toGetData=null;this._loading=!0;this.onLoading();let e=null;if(this._groupOnServer||this._virtualization){let e=-1;this.currentPosition>-1&&(e=this.currentPosition);let i=this.groupDescriptions;this._data||(this._data=[]);let s,r=[];if((this._groupRefresh||this._groupLazyLoading&&(!t||!t.isBottomLevel))&&this._groupOnServer&&i.length>0){r=yield this.getGroupItems(t);t?this._updateSubGroups(t,r):this._groupItems=r;this._groupRefresh=!1}this._groupLazyLoading||(s=yield this.getItems());this._groupLazyLoading&&t&&t.isBottomLevel&&(s=yield this.getItems(t));this.deferUpdate(()=>__awaiter(this,void 0,void 0,(function*(){this._virtualization||this._groupLazyLoading||(this._data=s);if(this._groupLazyLoading&&!this._virtualization)if(t)this._loadSubGroupsData(t,r,s);else{this._data=new Array;const e=i[0].propertyName;for(let t=0;t<r.length;t++){let i=new Object,s=r[t].count;i[e]=r[t].groupKey[e];for(let t=0;t<s;t++)this._data.push(i)}this._expandedGroups.length>0&&(yield this._loadExpandedGroups(t))}this._virtualization&&!this._groupLazyLoading&&this._storeItems(s,!1);this.sourceCollection=this._data})));this.refresh();e>-1&&this.moveCurrentToPosition(e)}else{let t=null;try{let e=this.currentPosition;t=yield this.getItems();this.sourceCollection=t;this.refresh();e>-1&&this.moveCurrentToPosition(e);this.pageIndex>0&&this.pageIndex>=this.pageCount&&this.moveToLastPage()}catch(t){e=t}}this._loading=!1;this.onLoaded();e&&this._raiseError(e,!1)})),100)}_loadExpandedGroups(t){return __awaiter(this,void 0,void 0,(function*(){if(this._expandedGroups.length>0&&!t){let t=[];this._expandedGroups.forEach(e=>__awaiter(this,void 0,void 0,(function*(){e.isBottomLevel?t.push(this.getItems(e)):t.push(this.getGroupItems(e))})));return new Promise(e=>{Promise.all(t).then(t=>{for(let e=0;e<this._expandedGroups.length;e++)if(this._expandedGroups[e].isBottomLevel)this._loadSubGroupsData(this._expandedGroups[e],[],t[e]);else{this._updateSubGroups(this._expandedGroups[e],t[e]);this._loadSubGroupsData(this._expandedGroups[e],t[e],[])}e(!0)}).catch(t=>{e(!1)})})}}))}_updateSubGroups(t,e){let i=this._getFilterGroupItems(t);if(1==i.length){for(let t=0;t<e.length;t++)e[t].groupKey=Object.assign({},i[0].groupKey,e[t].groupKey);let t=this._groupItems.indexOf(i[0]);this._groupItems.splice(t,1,...e)}else console.error("unable to find exact match for targetted group")}_loadSubGroupsData(t,e,i){let s=this.groupDescriptions,r=this._data;for(let e=0;e<=(t.isBottomLevel?s.length-1:t.level);e++){const i=s[e].propertyName,o=t.items[e][i];r=r.filter(t=>t[i]===o)}let o=this._data.indexOf(r[0]);r=JSON.parse(JSON.stringify(r));if(t.isBottomLevel)for(let t=0;t<i.length;t++)Object.assign(r[t],i[t]);else{let i=t.groups[0].groupDescription.propertyName,s=0;for(let t=0;t<e.length;t++){s+=t>0?e[t-1].count:0;for(let o=0;o<e[t].count;o++)r[s+o][i]=e[t].groupKey[i]}}this._data.splice(o,r.length,...r)}_updateExpandedGroups(t,e){if(!this._loading){let i=this._expandedGroups.filter(e=>e._path.indexOf(t._path)>-1);if(e)this._expandedGroups.push(t);else if(i.length>0)for(let t=0;t<i.length;t++)this._expandedGroups.splice(this._expandedGroups.indexOf(i[t]),1)}}_storeItems(t,e){return __awaiter(this,void 0,void 0,(function*(){if(this._refresh||this._data.length!=this.totalItemCount||this.groups&&this.groups.length!=this._totalGroupItemCount){if(this._data.length!=this.totalItemCount&&this.groups&&this.groups.length>0){this._groupRefresh=!0;this._getData()}this._data.length=this.totalItemCount;if(this._groupOnServer&&this._groupItems.length>0&&this.groupDescriptions.length>0){let t=JSON.parse(JSON.stringify(this.groups)),e=0;for(let t=0;t<this._groupItems.length;t++){let i=Object.keys(this._groupItems[t].groupKey);for(let s=0;s<this._groupItems[t].count;s++){let s=new wijmo_1._NullValue(e);i.forEach(e=>{s[e]=this._groupItems[t].groupKey[e]});this._data[e]=s;e++}}if(0!=this.groups.length&&this.groups.length<t.length){let e=this._data[this._start],i=this.groupDescriptions.length,s=this.groupDescriptions[i-1].propertyName,r=this.groups.findIndex(t=>t.name==e[s]),o=t.findIndex(t=>t.name==e[s]);this._start+=r-o;this._getData()}}else for(let t=0;t<this._data.length;t++)this._data[t]=new wijmo_1._NullValue(t);this._refresh=!1}e||(this._loadOffset=0);let i=this._loadOffset+(this._start||0);for(let e=0;e<t.length;e++)this._data[e+i]=t[e];this._loadOffset+=t.length;setTimeout(()=>{this._firstLoad&&this.currentPosition<0&&t.length&&this.moveCurrentToFirst();this._firstLoad=!1})}))}_performSetWindow(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}t=wijmo_1.asInt(t);e=wijmo_1.asInt(e);wijmo_1.assert(t<=e,"start must be <= end.");let i=t<this._start,s=this._data;this._start=this._end=t;for(let i=t;i<=e&&i<s.length;i++)if(s[i]instanceof wijmo_1._NullValue){this._start=i;break}for(let t=e;t>=this._start&&t<s.length;t--)if(s[t]instanceof wijmo_1._NullValue){this._end=t;break}if(this._start!=this._end||s[this._start]instanceof wijmo_1._NullValue){i&&(this._start=Math.max(0,this._end-this._fetchSize()+1));this._getData()}}_fetchSize(){return Math.max(this._end-this._start+1,this.pageSize,_MIN_DATA_WINDOW)}_raiseError(t,e){if(this.onError(new RESTErrorEventArgs(t))){e&&this._getData();throw"Server Error: "+t}}get requestCanceled(){this._requestCanceled||(this._requestCanceled=new wijmo_1.Event);return this._requestCanceled}onRequestCanceled(t){this.requestCanceled.raise(this,t)}getGroupItems(t){throw"This method is virtual: it should be overridden"}getItems(t){throw"This method is virtual: it should be overridden"}addItem(t){throw"This method is virtual: it should be overridden"}patchItem(t){throw"This method is virtual: it should be overridden"}deleteItem(t){throw"This method is virtual: it should be overridden"}}exports.RestCollectionView=RestCollectionView;class RESTErrorEventArgs extends wijmo_1.CancelEventArgs{constructor(t){super();this._error=t}get error(){return this._error}}exports.RESTErrorEventArgs=RESTErrorEventArgs;wijmo_1._registerModule("wijmo.rest",selfModule);
|
package/es2015-esm.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
*
|
3
|
-
* Wijmo Library 5.20242.20-nightly.
|
3
|
+
* Wijmo Library 5.20242.20-nightly.d20240826.t020151
|
4
4
|
* https://developer.mescius.com/wijmo
|
5
5
|
*
|
6
6
|
* Copyright(c) MESCIUS inc. All rights reserved.
|
@@ -11,4 +11,4 @@
|
|
11
11
|
*
|
12
12
|
*/
|
13
13
|
|
14
|
-
var __awaiter=this&&this.__awaiter||function(t,e,i,s){return new(i||(i=Promise))((function(r,o){function fulfilled(t){try{step(s.next(t))}catch(t){o(t)}}function rejected(t){try{step(s.throw(t))}catch(t){o(t)}}function step(t){t.done?r(t.value):new i((function(e){e(t.value)})).then(fulfilled,rejected)}step((s=s.apply(t,e||[])).next())}))};import{asArray,asBoolean,asInt,copy,clamp,CollectionView,Event,CancelEventArgs,assert,isString,getAggregate,_NullValue,Aggregate,_registerModule}from"@mescius/wijmo";import*as selfModule from"@mescius/wijmo.rest";const _MIN_DATA_WINDOW=100;export class RestCollectionView extends CollectionView{constructor(t){super();this._loading=!1;this._fields=null;this._keys=null;this._sortOnServer=!0;this._pageOnServer=!0;this._filterOnServer=!0;this._totalItemCount=0;this._aggregates="";this._groupOnServer=!0;this._groupLazyLoading=!1;this._virtualization=!1;this._start=0;this._end=_MIN_DATA_WINDOW;this._expandedGroups=[];this._groupItems=[];this._groupRefresh=!1;this._refresh=!1;this.loading=new Event;this.loaded=new Event;this.error=new Event;t&©(this,t);this.sortDescriptions.collectionChanged.addHandler(()=>{this.sortOnServer&&this._getData()});this._getData();(this._groupOnServer||this._virtualization)&&(this._data=[]);this._virtualization&&this.setWindow(this._start,_MIN_DATA_WINDOW);this._firstLoad=this._groupRefresh=!0}get totalGroupItemCount(){return this.groupOnServer?this._totalGroupItemCount:0}get groupOnServer(){return this._groupOnServer}set groupOnServer(t){if(t!=this._groupOnServer){this._groupOnServer=asBoolean(t);this._getData()}}get groupLazyLoading(){return this._groupLazyLoading}set groupLazyLoading(t){t!=this._groupLazyLoading&&this._groupOnServer&&(this._groupLazyLoading=asBoolean(t))}get virtualization(){return this._virtualization}set virtualization(t){t!=this.virtualization&&(this._virtualization=asBoolean(t))}get fields(){return this._fields}set fields(t){if(this._fields!=t){this._fields=asArray(t);this._getData()}}get sortOnServer(){return this._sortOnServer}set sortOnServer(t){if(t!=this._sortOnServer){this._sortOnServer=asBoolean(t);this._getData()}}get pageOnServer(){return this._pageOnServer}set pageOnServer(t){if(t!=this._pageOnServer){this._pageOnServer=asBoolean(t);this._getData()}}get filterOnServer(){return this._filterOnServer}set filterOnServer(t){if(t!=this._filterOnServer){this._filterOnServer=asBoolean(t);this._getData()}}get requestHeaders(){return this._requestHeaders}set requestHeaders(t){this._requestHeaders=t}get aggregates(){return this._aggregates}set aggregates(t){assert(this._groupOnServer,"groupOnServer should be enabled");isString(t)&&t!=this._aggregates&&(this._aggregates=t)}updateFilterDefinition(t){if(this.filterOnServer){this._filterProvider=t;this._getData()}}lazyLoadGroup(t){if(this._groupLazyLoading){t.groups.length>0&&null==t.groups[0].name&&this._getData(t);0==t.groups.length&&t.isBottomLevel&&this._getData(t)}else assert(this._groupLazyLoading,"groupLazyLoading should be enabled lazy load the groups.")}setWindow(t,e){this._toSetWindow&&clearTimeout(this._toSetWindow);this._toSetWindow=setTimeout(()=>{this._toSetWindow=null;this._performSetWindow(t,e)},50)}_getFilterGroupItems(t){let e=this._groupItems,i=t.items[0];for(let s=0;s<=t.level;s++){let t=this.groupDescriptions[s].propertyName;e=e.filter(e=>e.groupKey[t]==i[t])}return e}getGroupAggregate(t,e,i=Aggregate.Sum){if(this.groupLazyLoading||this.virtualization){let s="",r=this._getFilterGroupItems(e);r&&0!=r.length&&r.length!=this._groupItems.length&&r[0].aggregates&&(s=getAggregate(i,r,`aggregates.${t}`));return s}}get isLoading(){return this._loading}onLoading(t){this.loading.raise(this,t)}onLoaded(t){this.loaded.raise(this,t)}load(){this._getData()}onError(t){this.error.raise(this,t);return!t.cancel}_performRefresh(){this.isLoading||(this._refresh=!0);let t=this._canFilter,e=this._canSort;this._canFilter=!this._filterOnServer;this._canSort=!this._sortOnServer;super._performRefresh();this._canFilter=t;this._canSort=e}get totalItemCount(){return this.pageOnServer?this._totalItemCount:this._view.length}get pageCount(){return this.pageSize?Math.ceil(this.totalItemCount/this.pageSize):1}get pageSize(){return this._pgSz}set pageSize(t){if(t!=this._pgSz){this._pgSz=asInt(t);if(this.pageOnServer){this._pgIdx=clamp(this._pgIdx,0,this.pageCount-1);this._getData()}else this.refresh()}}onPageChanging(t){super.onPageChanging(t);this.pageOnServer&&!t.cancel&&this._getData();return!t.cancel}commitNew(){let t=this.currentAddItem;if(t)try{let e=this.addItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.commitNew()}commitEdit(){let t=this.currentEditItem;if(t&&!this.currentAddItem&&!this._sameContent(t,this._edtClone)&&this.items.indexOf(t)>-1)try{let e=this.patchItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.commitEdit()}remove(t){if(t&&t!=this.currentAddItem&&this.items.indexOf(t)>-1)try{let e=this.deleteItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.remove(t)}_getPageView(){return this.pageOnServer?this._view:super._getPageView()}_getData(t){this._toGetData&&clearTimeout(this._toGetData);this._toGetData=setTimeout(()=>__awaiter(this,void 0,void 0,(function*(){this._toGetData=null;this._loading=!0;this.onLoading();let e=null;if(this._groupOnServer||this._virtualization){let e=-1;this.currentPosition>-1&&(e=this.currentPosition);let i=this.groupDescriptions;this._data||(this._data=[]);let s,r=[];if((this._groupRefresh||this._groupLazyLoading&&(!t||!t.isBottomLevel))&&this._groupOnServer&&i.length>0){r=yield this.getGroupItems(t);t?this._updateSubGroups(t,r):this._groupItems=r;this._groupRefresh=!1}this._groupLazyLoading||(s=yield this.getItems());this._groupLazyLoading&&t&&t.isBottomLevel&&(s=yield this.getItems(t));this.deferUpdate(()=>__awaiter(this,void 0,void 0,(function*(){this._virtualization||this._groupLazyLoading||(this._data=s);if(this._groupLazyLoading&&!this._virtualization)if(t)this._loadSubGroupsData(t,r,s);else{this._data=new Array;const e=i[0].propertyName;for(let t=0;t<r.length;t++){let i=new Object,s=r[t].count;i[e]=r[t].groupKey[e];for(let t=0;t<s;t++)this._data.push(i)}this._expandedGroups.length>0&&(yield this._loadExpandedGroups(t))}this._virtualization&&!this._groupLazyLoading&&this._storeItems(s,!1);this.sourceCollection=this._data})));this.refresh();e>-1&&this.moveCurrentToPosition(e)}else{let t=null;try{let e=this.currentPosition;t=yield this.getItems();this.sourceCollection=t;this.refresh();e>-1&&this.moveCurrentToPosition(e);this.pageIndex>0&&this.pageIndex>=this.pageCount&&this.moveToLastPage()}catch(t){e=t}}this._loading=!1;this.onLoaded();e&&this._raiseError(e,!1)})),100)}_loadExpandedGroups(t){return __awaiter(this,void 0,void 0,(function*(){if(this._expandedGroups.length>0&&!t){let t=[];this._expandedGroups.forEach(e=>__awaiter(this,void 0,void 0,(function*(){e.isBottomLevel?t.push(this.getItems(e)):t.push(this.getGroupItems(e))})));return new Promise(e=>{Promise.all(t).then(t=>{for(let e=0;e<this._expandedGroups.length;e++)if(this._expandedGroups[e].isBottomLevel)this._loadSubGroupsData(this._expandedGroups[e],[],t[e]);else{this._updateSubGroups(this._expandedGroups[e],t[e]);this._loadSubGroupsData(this._expandedGroups[e],t[e],[])}e(!0)}).catch(t=>{e(!1)})})}}))}_updateSubGroups(t,e){let i=this._getFilterGroupItems(t);if(1==i.length){for(let t=0;t<e.length;t++)e[t].groupKey=Object.assign({},i[0].groupKey,e[t].groupKey);let t=this._groupItems.indexOf(i[0]);this._groupItems.splice(t,1,...e)}else console.error("unable to find exact match for targetted group")}_loadSubGroupsData(t,e,i){let s=this.groupDescriptions,r=this._data;for(let e=0;e<=(t.isBottomLevel?s.length-1:t.level);e++){const i=s[e].propertyName,o=t.items[e][i];r=r.filter(t=>t[i]===o)}let o=this._data.indexOf(r[0]);r=JSON.parse(JSON.stringify(r));if(t.isBottomLevel)for(let t=0;t<i.length;t++)Object.assign(r[t],i[t]);else{let i=t.groups[0].groupDescription.propertyName,s=0;for(let t=0;t<e.length;t++){s+=t>0?e[t-1].count:0;for(let o=0;o<e[t].count;o++)r[s+o][i]=e[t].groupKey[i]}}this._data.splice(o,r.length,...r)}_updateExpandedGroups(t,e){if(!this._loading){let i=this._expandedGroups.filter(e=>e._path.indexOf(t._path)>-1);if(e)this._expandedGroups.push(t);else if(i.length>0)for(let t=0;t<i.length;t++)this._expandedGroups.splice(this._expandedGroups.indexOf(i[t]),1)}}_storeItems(t,e){return __awaiter(this,void 0,void 0,(function*(){if(this._refresh||this._data.length!=this.totalItemCount||this.groups&&this.groups.length!=this._totalGroupItemCount){if(this._data.length!=this.totalItemCount&&this.groups&&this.groups.length>0){this._groupRefresh=!0;this._getData()}this._data.length=this.totalItemCount;if(this._groupOnServer&&this._groupItems.length>0&&this.groupDescriptions.length>0){let t=JSON.parse(JSON.stringify(this.groups)),e=0;for(let t=0;t<this._groupItems.length;t++){let i=Object.keys(this._groupItems[t].groupKey);for(let s=0;s<this._groupItems[t].count;s++){let s=new _NullValue(e);i.forEach(e=>{s[e]=this._groupItems[t].groupKey[e]});this._data[e]=s;e++}}if(0!=this.groups.length&&this.groups.length<t.length){let e=this._data[this._start],i=this.groupDescriptions.length,s=this.groupDescriptions[i-1].propertyName,r=this.groups.findIndex(t=>t.name==e[s]),o=t.findIndex(t=>t.name==e[s]);this._start+=r-o;this._getData()}}else for(let t=0;t<this._data.length;t++)this._data[t]=new _NullValue(t);this._refresh=!1}e||(this._loadOffset=0);let i=this._loadOffset+(this._start||0);for(let e=0;e<t.length;e++)this._data[e+i]=t[e];this._loadOffset+=t.length;setTimeout(()=>{this._firstLoad&&this.currentPosition<0&&t.length&&this.moveCurrentToFirst();this._firstLoad=!1})}))}_performSetWindow(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}t=asInt(t);e=asInt(e);assert(t<=e,"start must be <= end.");let i=t<this._start,s=this._data;this._start=this._end=t;for(let i=t;i<=e&&i<s.length;i++)if(s[i]instanceof _NullValue){this._start=i;break}for(let t=e;t>=this._start&&t<s.length;t--)if(s[t]instanceof _NullValue){this._end=t;break}if(this._start!=this._end||s[this._start]instanceof _NullValue){i&&(this._start=Math.max(0,this._end-this._fetchSize()+1));this._getData()}}_fetchSize(){return Math.max(this._end-this._start+1,this.pageSize,_MIN_DATA_WINDOW)}_raiseError(t,e){if(this.onError(new RESTErrorEventArgs(t))){e&&this._getData();throw"Server Error: "+t}}get requestCanceled(){this._requestCanceled||(this._requestCanceled=new Event);return this._requestCanceled}onRequestCanceled(t){this.requestCanceled.raise(this,t)}getGroupItems(t){throw"This method is virtual: it should be overridden"}getItems(t){throw"This method is virtual: it should be overridden"}addItem(t){throw"This method is virtual: it should be overridden"}patchItem(t){throw"This method is virtual: it should be overridden"}deleteItem(t){throw"This method is virtual: it should be overridden"}}export class RESTErrorEventArgs extends CancelEventArgs{constructor(t){super();this._error=t}get error(){return this._error}}_registerModule("wijmo.rest",selfModule);
|
14
|
+
var __awaiter=this&&this.__awaiter||function(t,e,i,s){return new(i||(i=Promise))((function(r,o){function fulfilled(t){try{step(s.next(t))}catch(t){o(t)}}function rejected(t){try{step(s.throw(t))}catch(t){o(t)}}function step(t){t.done?r(t.value):new i((function(e){e(t.value)})).then(fulfilled,rejected)}step((s=s.apply(t,e||[])).next())}))};import{asArray,asBoolean,asInt,copy,clamp,CollectionView,Event,CancelEventArgs,assert,isString,getAggregate,_NullValue,Aggregate,_registerModule}from"@mescius/wijmo";import*as selfModule from"@mescius/wijmo.rest";const _MIN_DATA_WINDOW=100;export class RestCollectionView extends CollectionView{constructor(t){super();this._loading=!1;this._fields=null;this._keys=null;this._sortOnServer=!0;this._pageOnServer=!0;this._filterOnServer=!0;this._totalItemCount=0;this._aggregates="";this._groupOnServer=!0;this._groupLazyLoading=!1;this._virtualization=!1;this._start=0;this._end=_MIN_DATA_WINDOW;this._expandedGroups=[];this._groupItems=[];this._groupRefresh=!1;this._refresh=!1;this.loading=new Event;this.loaded=new Event;this.error=new Event;t&©(this,t);this.sortDescriptions.collectionChanged.addHandler(()=>{this.sortOnServer&&this._getData()});this._getData();(this._groupOnServer||this._virtualization)&&(this._data=[]);this._virtualization&&this.setWindow(this._start,_MIN_DATA_WINDOW);this._firstLoad=this._groupRefresh=!0}get totalGroupItemCount(){return this.groupOnServer?this._totalGroupItemCount:0}get groupOnServer(){return this._groupOnServer}set groupOnServer(t){if(t!=this._groupOnServer){this._groupOnServer=asBoolean(t);this._getData()}}get groupLazyLoading(){return this._groupLazyLoading}set groupLazyLoading(t){t!=this._groupLazyLoading&&this._groupOnServer&&(this._groupLazyLoading=asBoolean(t))}get virtualization(){return this._virtualization}set virtualization(t){t!=this.virtualization&&(this._virtualization=asBoolean(t))}get fields(){return this._fields}set fields(t){if(this._fields!=t){this._fields=asArray(t);this._getData()}}get sortOnServer(){return this._sortOnServer}set sortOnServer(t){if(t!=this._sortOnServer){this._sortOnServer=asBoolean(t);this._getData()}}get pageOnServer(){return this._pageOnServer}set pageOnServer(t){if(t!=this._pageOnServer){this._pageOnServer=asBoolean(t);this._getData()}}get filterOnServer(){return this._filterOnServer}set filterOnServer(t){if(t!=this._filterOnServer){this._filterOnServer=asBoolean(t);this._getData()}}get requestHeaders(){return this._requestHeaders}set requestHeaders(t){this._requestHeaders=t}get aggregates(){return this._aggregates}set aggregates(t){assert(this._groupOnServer,"groupOnServer should be enabled");isString(t)&&t!=this._aggregates&&(this._aggregates=t)}updateFilterDefinition(t){if(this.filterOnServer){this._filterProvider=t;this._getData()}}lazyLoadGroup(t){if(this._groupLazyLoading){t.groups.length>0&&null==t.groups[0].name&&this._getData(t);0==t.groups.length&&t.isBottomLevel&&this._getData(t)}else assert(this._groupLazyLoading,"groupLazyLoading should be enabled lazy load the groups.")}setWindow(t,e){this._toSetWindow&&clearTimeout(this._toSetWindow);this._toSetWindow=setTimeout(()=>{this._toSetWindow=null;this._performSetWindow(t,e)},50)}_getFilterGroupItems(t){let e=this._groupItems,i=t.items[0];for(let s=0;s<=t.level;s++){let t=this.groupDescriptions[s].propertyName;e=e.filter(e=>e.groupKey[t]==i[t])}return e}getGroupAggregate(t,e,i=Aggregate.Sum){if(this.groupOnServer&&(this.groupLazyLoading||this.virtualization||this.groupDescriptions.length>0&&this._groupItems.length>0)){let s="",r=this._getFilterGroupItems(e);r&&0!=r.length&&r.length!=this._groupItems.length&&r[0].aggregates&&(s=getAggregate(i,r,`aggregates.${t}`));return s}}get isLoading(){return this._loading}onLoading(t){this.loading.raise(this,t)}onLoaded(t){this.loaded.raise(this,t)}load(){this._getData()}onError(t){this.error.raise(this,t);return!t.cancel}_performRefresh(){this.isLoading||(this._refresh=!0);let t=this._canFilter,e=this._canSort;this._canFilter=!this._filterOnServer;this._canSort=!this._sortOnServer;super._performRefresh();this._canFilter=t;this._canSort=e}get totalItemCount(){return this.pageOnServer?this._totalItemCount:this._view.length}get pageCount(){return this.pageSize?Math.ceil(this.totalItemCount/this.pageSize):1}get pageSize(){return this._pgSz}set pageSize(t){if(t!=this._pgSz){this._pgSz=asInt(t);if(this.pageOnServer){this._pgIdx=clamp(this._pgIdx,0,this.pageCount-1);this._getData()}else this.refresh()}}onPageChanging(t){super.onPageChanging(t);this.pageOnServer&&!t.cancel&&this._getData();return!t.cancel}commitNew(){let t=this.currentAddItem;if(t)try{let e=this.addItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.commitNew()}commitEdit(){let t=this.currentEditItem;if(t&&!this.currentAddItem&&!this._sameContent(t,this._edtClone)&&this.items.indexOf(t)>-1)try{let e=this.patchItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.commitEdit()}remove(t){if(t&&t!=this.currentAddItem&&this.items.indexOf(t)>-1)try{let e=this.deleteItem(t);e&&e.then&&e.then(()=>this.refresh())}catch(t){this._raiseError(t,!0)}super.remove(t)}_getPageView(){return this.pageOnServer?this._view:super._getPageView()}_getData(t){this._toGetData&&clearTimeout(this._toGetData);this._toGetData=setTimeout(()=>__awaiter(this,void 0,void 0,(function*(){this._toGetData=null;this._loading=!0;this.onLoading();let e=null;if(this._groupOnServer||this._virtualization){let e=-1;this.currentPosition>-1&&(e=this.currentPosition);let i=this.groupDescriptions;this._data||(this._data=[]);let s,r=[];if((this._groupRefresh||this._groupLazyLoading&&(!t||!t.isBottomLevel))&&this._groupOnServer&&i.length>0){r=yield this.getGroupItems(t);t?this._updateSubGroups(t,r):this._groupItems=r;this._groupRefresh=!1}this._groupLazyLoading||(s=yield this.getItems());this._groupLazyLoading&&t&&t.isBottomLevel&&(s=yield this.getItems(t));this.deferUpdate(()=>__awaiter(this,void 0,void 0,(function*(){this._virtualization||this._groupLazyLoading||(this._data=s);if(this._groupLazyLoading&&!this._virtualization)if(t)this._loadSubGroupsData(t,r,s);else{this._data=new Array;const e=i[0].propertyName;for(let t=0;t<r.length;t++){let i=new Object,s=r[t].count;i[e]=r[t].groupKey[e];for(let t=0;t<s;t++)this._data.push(i)}this._expandedGroups.length>0&&(yield this._loadExpandedGroups(t))}this._virtualization&&!this._groupLazyLoading&&this._storeItems(s,!1);this.sourceCollection=this._data})));this.refresh();e>-1&&this.moveCurrentToPosition(e)}else{let t=null;try{let e=this.currentPosition;t=yield this.getItems();this.sourceCollection=t;this.refresh();e>-1&&this.moveCurrentToPosition(e);this.pageIndex>0&&this.pageIndex>=this.pageCount&&this.moveToLastPage()}catch(t){e=t}}this._loading=!1;this.onLoaded();e&&this._raiseError(e,!1)})),100)}_loadExpandedGroups(t){return __awaiter(this,void 0,void 0,(function*(){if(this._expandedGroups.length>0&&!t){let t=[];this._expandedGroups.forEach(e=>__awaiter(this,void 0,void 0,(function*(){e.isBottomLevel?t.push(this.getItems(e)):t.push(this.getGroupItems(e))})));return new Promise(e=>{Promise.all(t).then(t=>{for(let e=0;e<this._expandedGroups.length;e++)if(this._expandedGroups[e].isBottomLevel)this._loadSubGroupsData(this._expandedGroups[e],[],t[e]);else{this._updateSubGroups(this._expandedGroups[e],t[e]);this._loadSubGroupsData(this._expandedGroups[e],t[e],[])}e(!0)}).catch(t=>{e(!1)})})}}))}_updateSubGroups(t,e){let i=this._getFilterGroupItems(t);if(1==i.length){for(let t=0;t<e.length;t++)e[t].groupKey=Object.assign({},i[0].groupKey,e[t].groupKey);let t=this._groupItems.indexOf(i[0]);this._groupItems.splice(t,1,...e)}else console.error("unable to find exact match for targetted group")}_loadSubGroupsData(t,e,i){let s=this.groupDescriptions,r=this._data;for(let e=0;e<=(t.isBottomLevel?s.length-1:t.level);e++){const i=s[e].propertyName,o=t.items[e][i];r=r.filter(t=>t[i]===o)}let o=this._data.indexOf(r[0]);r=JSON.parse(JSON.stringify(r));if(t.isBottomLevel)for(let t=0;t<i.length;t++)Object.assign(r[t],i[t]);else{let i=t.groups[0].groupDescription.propertyName,s=0;for(let t=0;t<e.length;t++){s+=t>0?e[t-1].count:0;for(let o=0;o<e[t].count;o++)r[s+o][i]=e[t].groupKey[i]}}this._data.splice(o,r.length,...r)}_updateExpandedGroups(t,e){if(!this._loading){let i=this._expandedGroups.filter(e=>e._path.indexOf(t._path)>-1);if(e)this._expandedGroups.push(t);else if(i.length>0)for(let t=0;t<i.length;t++)this._expandedGroups.splice(this._expandedGroups.indexOf(i[t]),1)}}_storeItems(t,e){return __awaiter(this,void 0,void 0,(function*(){if(this._refresh||this._data.length!=this.totalItemCount||this.groups&&this.groups.length!=this._totalGroupItemCount){if(this._data.length!=this.totalItemCount&&this.groups&&this.groups.length>0){this._groupRefresh=!0;this._getData()}this._data.length=this.totalItemCount;if(this._groupOnServer&&this._groupItems.length>0&&this.groupDescriptions.length>0){let t=JSON.parse(JSON.stringify(this.groups)),e=0;for(let t=0;t<this._groupItems.length;t++){let i=Object.keys(this._groupItems[t].groupKey);for(let s=0;s<this._groupItems[t].count;s++){let s=new _NullValue(e);i.forEach(e=>{s[e]=this._groupItems[t].groupKey[e]});this._data[e]=s;e++}}if(0!=this.groups.length&&this.groups.length<t.length){let e=this._data[this._start],i=this.groupDescriptions.length,s=this.groupDescriptions[i-1].propertyName,r=this.groups.findIndex(t=>t.name==e[s]),o=t.findIndex(t=>t.name==e[s]);this._start+=r-o;this._getData()}}else for(let t=0;t<this._data.length;t++)this._data[t]=new _NullValue(t);this._refresh=!1}e||(this._loadOffset=0);let i=this._loadOffset+(this._start||0);for(let e=0;e<t.length;e++)this._data[e+i]=t[e];this._loadOffset+=t.length;setTimeout(()=>{this._firstLoad&&this.currentPosition<0&&t.length&&this.moveCurrentToFirst();this._firstLoad=!1})}))}_performSetWindow(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}t=asInt(t);e=asInt(e);assert(t<=e,"start must be <= end.");let i=t<this._start,s=this._data;this._start=this._end=t;for(let i=t;i<=e&&i<s.length;i++)if(s[i]instanceof _NullValue){this._start=i;break}for(let t=e;t>=this._start&&t<s.length;t--)if(s[t]instanceof _NullValue){this._end=t;break}if(this._start!=this._end||s[this._start]instanceof _NullValue){i&&(this._start=Math.max(0,this._end-this._fetchSize()+1));this._getData()}}_fetchSize(){return Math.max(this._end-this._start+1,this.pageSize,_MIN_DATA_WINDOW)}_raiseError(t,e){if(this.onError(new RESTErrorEventArgs(t))){e&&this._getData();throw"Server Error: "+t}}get requestCanceled(){this._requestCanceled||(this._requestCanceled=new Event);return this._requestCanceled}onRequestCanceled(t){this.requestCanceled.raise(this,t)}getGroupItems(t){throw"This method is virtual: it should be overridden"}getItems(t){throw"This method is virtual: it should be overridden"}addItem(t){throw"This method is virtual: it should be overridden"}patchItem(t){throw"This method is virtual: it should be overridden"}deleteItem(t){throw"This method is virtual: it should be overridden"}}export class RESTErrorEventArgs extends CancelEventArgs{constructor(t){super();this._error=t}get error(){return this._error}}_registerModule("wijmo.rest",selfModule);
|
package/es5-esm.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
*
|
3
|
-
* Wijmo Library 5.20242.20-nightly.
|
3
|
+
* Wijmo Library 5.20242.20-nightly.d20240826.t020151
|
4
4
|
* https://developer.mescius.com/wijmo
|
5
5
|
*
|
6
6
|
* Copyright(c) MESCIUS inc. All rights reserved.
|
@@ -11,4 +11,4 @@
|
|
11
11
|
*
|
12
12
|
*/
|
13
13
|
|
14
|
-
var __extends=this&&this.__extends||function(){var extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){extendStatics(t,e);function __(){this.constructor=t}t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(o,n){function fulfilled(t){try{step(i.next(t))}catch(t){n(t)}}function rejected(t){try{step(i.throw(t))}catch(t){n(t)}}function step(t){t.done?o(t.value):new r((function(e){e(t.value)})).then(fulfilled,rejected)}step((i=i.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){var r,i,o,n,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function verb(n){return function(a){return function step(n){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,i&&(o=2&n[0]?i.return:n[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,n[1])).done)return o;(i=0,o)&&(n=[2&n[0],o.value]);switch(n[0]){case 0:case 1:o=n;break;case 4:s.label++;return{value:n[1],done:!1};case 5:s.label++;i=n[1];n=[0];continue;case 7:n=s.ops.pop();s.trys.pop();continue;default:if(!(o=s.trys,o=o.length>0&&o[o.length-1])&&(6===n[0]||2===n[0])){s=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){s.label=n[1];break}if(6===n[0]&&s.label<o[1]){s.label=o[1];o=n;break}if(o&&s.label<o[2]){s.label=o[2];s.ops.push(n);break}o[2]&&s.ops.pop();s.trys.pop();continue}n=e.call(t,s)}catch(t){n=[6,t];i=0}finally{r=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,a])}}};import{asArray,asBoolean,asInt,copy,clamp,CollectionView,Event,CancelEventArgs,assert,isString,getAggregate,_NullValue,Aggregate,_registerModule}from"@mescius/wijmo";import*as selfModule from"@mescius/wijmo.rest";var _MIN_DATA_WINDOW=100,RestCollectionView=function(t){__extends(RestCollectionView,t);function RestCollectionView(e){var r=t.call(this)||this;r._loading=!1;r._fields=null;r._keys=null;r._sortOnServer=!0;r._pageOnServer=!0;r._filterOnServer=!0;r._totalItemCount=0;r._aggregates="";r._groupOnServer=!0;r._groupLazyLoading=!1;r._virtualization=!1;r._start=0;r._end=_MIN_DATA_WINDOW;r._expandedGroups=[];r._groupItems=[];r._groupRefresh=!1;r._refresh=!1;r.loading=new Event;r.loaded=new Event;r.error=new Event;e&©(r,e);r.sortDescriptions.collectionChanged.addHandler((function(){r.sortOnServer&&r._getData()}));r._getData();(r._groupOnServer||r._virtualization)&&(r._data=[]);r._virtualization&&r.setWindow(r._start,_MIN_DATA_WINDOW);r._firstLoad=r._groupRefresh=!0;return r}Object.defineProperty(RestCollectionView.prototype,"totalGroupItemCount",{get:function(){return this.groupOnServer?this._totalGroupItemCount:0},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"groupOnServer",{get:function(){return this._groupOnServer},set:function(t){if(t!=this._groupOnServer){this._groupOnServer=asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"groupLazyLoading",{get:function(){return this._groupLazyLoading},set:function(t){t!=this._groupLazyLoading&&this._groupOnServer&&(this._groupLazyLoading=asBoolean(t))},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"virtualization",{get:function(){return this._virtualization},set:function(t){t!=this.virtualization&&(this._virtualization=asBoolean(t))},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"fields",{get:function(){return this._fields},set:function(t){if(this._fields!=t){this._fields=asArray(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"sortOnServer",{get:function(){return this._sortOnServer},set:function(t){if(t!=this._sortOnServer){this._sortOnServer=asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageOnServer",{get:function(){return this._pageOnServer},set:function(t){if(t!=this._pageOnServer){this._pageOnServer=asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"filterOnServer",{get:function(){return this._filterOnServer},set:function(t){if(t!=this._filterOnServer){this._filterOnServer=asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"requestHeaders",{get:function(){return this._requestHeaders},set:function(t){this._requestHeaders=t},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"aggregates",{get:function(){return this._aggregates},set:function(t){assert(this._groupOnServer,"groupOnServer should be enabled");isString(t)&&t!=this._aggregates&&(this._aggregates=t)},enumerable:!0,configurable:!0});RestCollectionView.prototype.updateFilterDefinition=function(t){if(this.filterOnServer){this._filterProvider=t;this._getData()}};RestCollectionView.prototype.lazyLoadGroup=function(t){if(this._groupLazyLoading){t.groups.length>0&&null==t.groups[0].name&&this._getData(t);0==t.groups.length&&t.isBottomLevel&&this._getData(t)}else assert(this._groupLazyLoading,"groupLazyLoading should be enabled lazy load the groups.")};RestCollectionView.prototype.setWindow=function(t,e){var r=this;this._toSetWindow&&clearTimeout(this._toSetWindow);this._toSetWindow=setTimeout((function(){r._toSetWindow=null;r._performSetWindow(t,e)}),50)};RestCollectionView.prototype._getFilterGroupItems=function(t){for(var e=this._groupItems,r=t.items[0],_loop_1=function(t){var o=i.groupDescriptions[t].propertyName;e=e.filter((function(t){return t.groupKey[o]==r[o]}))},i=this,o=0;o<=t.level;o++)_loop_1(o);return e};RestCollectionView.prototype.getGroupAggregate=function(t,e,r){void 0===r&&(r=Aggregate.Sum);if(this.groupLazyLoading||this.virtualization){var i="",o=this._getFilterGroupItems(e);o&&0!=o.length&&o.length!=this._groupItems.length&&o[0].aggregates&&(i=getAggregate(r,o,"aggregates."+t));return i}};Object.defineProperty(RestCollectionView.prototype,"isLoading",{get:function(){return this._loading},enumerable:!0,configurable:!0});RestCollectionView.prototype.onLoading=function(t){this.loading.raise(this,t)};RestCollectionView.prototype.onLoaded=function(t){this.loaded.raise(this,t)};RestCollectionView.prototype.load=function(){this._getData()};RestCollectionView.prototype.onError=function(t){this.error.raise(this,t);return!t.cancel};RestCollectionView.prototype._performRefresh=function(){this.isLoading||(this._refresh=!0);var e=this._canFilter,r=this._canSort;this._canFilter=!this._filterOnServer;this._canSort=!this._sortOnServer;t.prototype._performRefresh.call(this);this._canFilter=e;this._canSort=r};Object.defineProperty(RestCollectionView.prototype,"totalItemCount",{get:function(){return this.pageOnServer?this._totalItemCount:this._view.length},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageCount",{get:function(){return this.pageSize?Math.ceil(this.totalItemCount/this.pageSize):1},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageSize",{get:function(){return this._pgSz},set:function(t){if(t!=this._pgSz){this._pgSz=asInt(t);if(this.pageOnServer){this._pgIdx=clamp(this._pgIdx,0,this.pageCount-1);this._getData()}else this.refresh()}},enumerable:!0,configurable:!0});RestCollectionView.prototype.onPageChanging=function(e){t.prototype.onPageChanging.call(this,e);this.pageOnServer&&!e.cancel&&this._getData();return!e.cancel};RestCollectionView.prototype.commitNew=function(){var e=this,r=this.currentAddItem;if(r)try{var i=this.addItem(r);i&&i.then&&i.then((function(){return e.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.commitNew.call(this)};RestCollectionView.prototype.commitEdit=function(){var e=this,r=this.currentEditItem;if(r&&!this.currentAddItem&&!this._sameContent(r,this._edtClone)&&this.items.indexOf(r)>-1)try{var i=this.patchItem(r);i&&i.then&&i.then((function(){return e.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.commitEdit.call(this)};RestCollectionView.prototype.remove=function(e){var r=this;if(e&&e!=this.currentAddItem&&this.items.indexOf(e)>-1)try{var i=this.deleteItem(e);i&&i.then&&i.then((function(){return r.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.remove.call(this,e)};RestCollectionView.prototype._getPageView=function(){return this.pageOnServer?this._view:t.prototype._getPageView.call(this)};RestCollectionView.prototype._getData=function(t){var e=this;this._toGetData&&clearTimeout(this._toGetData);this._toGetData=setTimeout((function(){return __awaiter(e,void 0,void 0,(function(){var e,r,i,o,n,s,a,u=this;return __generator(this,(function(l){switch(l.label){case 0:this._toGetData=null;this._loading=!0;this.onLoading();e=null;if(this._groupOnServer||this._virtualization)return[3,5];r=null;l.label=1;case 1:l.trys.push([1,3,,4]);o=this.currentPosition;return[4,this.getItems()];case 2:r=l.sent();this.sourceCollection=r;this.refresh();o>-1&&this.moveCurrentToPosition(o);this.pageIndex>0&&this.pageIndex>=this.pageCount&&this.moveToLastPage();return[3,4];case 3:i=l.sent();e=i;return[3,4];case 4:return[3,12];case 5:o=-1;this.currentPosition>-1&&(o=this.currentPosition);n=this.groupDescriptions;this._data||(this._data=[]);s=[];return(this._groupRefresh||!(!this._groupLazyLoading||t&&t.isBottomLevel))&&this._groupOnServer&&n.length>0?[4,this.getGroupItems(t)]:[3,7];case 6:s=l.sent();t?this._updateSubGroups(t,s):this._groupItems=s;this._groupRefresh=!1;l.label=7;case 7:return this._groupLazyLoading?[3,9]:[4,this.getItems()];case 8:a=l.sent();l.label=9;case 9:return this._groupLazyLoading&&t&&t.isBottomLevel?[4,this.getItems(t)]:[3,11];case 10:a=l.sent();l.label=11;case 11:this.deferUpdate((function(){return __awaiter(u,void 0,void 0,(function(){var e,r,i,o,u;return __generator(this,(function(l){switch(l.label){case 0:this._virtualization||this._groupLazyLoading||(this._data=a);if(!this._groupLazyLoading||this._virtualization)return[3,4];if(t)return[3,3];this._data=new Array;e=n[0].propertyName;for(r=0;r<s.length;r++){i=new Object,o=s[r].count;i[e]=s[r].groupKey[e];for(u=0;u<o;u++)this._data.push(i)}return this._expandedGroups.length>0?[4,this._loadExpandedGroups(t)]:[3,2];case 1:l.sent();l.label=2;case 2:return[3,4];case 3:this._loadSubGroupsData(t,s,a);l.label=4;case 4:this._virtualization&&!this._groupLazyLoading&&this._storeItems(a,!1);this.sourceCollection=this._data;return[2]}}))}))}));this.refresh();o>-1&&this.moveCurrentToPosition(o);l.label=12;case 12:this._loading=!1;this.onLoaded();e&&this._raiseError(e,!1);return[2]}}))}))}),100)};RestCollectionView.prototype._loadExpandedGroups=function(t){return __awaiter(this,void 0,void 0,(function(){var e,r=this;return __generator(this,(function(i){if(this._expandedGroups.length>0&&!t){e=[];this._expandedGroups.forEach((function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(r){t.isBottomLevel?e.push(this.getItems(t)):e.push(this.getGroupItems(t));return[2]}))}))}));return[2,new Promise((function(t){Promise.all(e).then((function(e){for(var i=0;i<r._expandedGroups.length;i++)if(r._expandedGroups[i].isBottomLevel)r._loadSubGroupsData(r._expandedGroups[i],[],e[i]);else{r._updateSubGroups(r._expandedGroups[i],e[i]);r._loadSubGroupsData(r._expandedGroups[i],e[i],[])}t(!0)})).catch((function(e){t(!1)}))}))]}return[2]}))}))};RestCollectionView.prototype._updateSubGroups=function(t,e){var r,i=this._getFilterGroupItems(t);if(1==i.length){for(var o=0;o<e.length;o++)e[o].groupKey=__assign({},i[0].groupKey,e[o].groupKey);var n=this._groupItems.indexOf(i[0]);(r=this._groupItems).splice.apply(r,[n,1].concat(e))}else console.error("unable to find exact match for targetted group")};RestCollectionView.prototype._loadSubGroupsData=function(t,e,r){for(var i,o=this.groupDescriptions,n=this._data,_loop_2=function(e){var r=o[e].propertyName,i=t.items[e][r];n=n.filter((function(t){return t[r]===i}))},s=0;s<=(t.isBottomLevel?o.length-1:t.level);s++)_loop_2(s);var a=this._data.indexOf(n[0]);n=JSON.parse(JSON.stringify(n));if(t.isBottomLevel)for(s=0;s<r.length;s++)Object.assign(n[s],r[s]);else for(var u=t.groups[0].groupDescription.propertyName,l=0,s=0;s<e.length;s++){l+=s>0?e[s-1].count:0;for(var h=0;h<e[s].count;h++)n[l+h][u]=e[s].groupKey[u]}(i=this._data).splice.apply(i,[a,n.length].concat(n))};RestCollectionView.prototype._updateExpandedGroups=function(t,e){if(!this._loading){var r=this._expandedGroups.filter((function(e){return e._path.indexOf(t._path)>-1}));if(e)this._expandedGroups.push(t);else if(r.length>0)for(var i=0;i<r.length;i++)this._expandedGroups.splice(this._expandedGroups.indexOf(r[i]),1)}};RestCollectionView.prototype._storeItems=function(t,e){return __awaiter(this,void 0,void 0,(function(){var r,i,o,n,s,a,u,l,h,p,c,g=this;return __generator(this,(function(_){if(this._refresh||this._data.length!=this.totalItemCount||this.groups&&this.groups.length!=this._totalGroupItemCount){if(this._data.length!=this.totalItemCount&&this.groups&&this.groups.length>0){this._groupRefresh=!0;this._getData()}this._data.length=this.totalItemCount;if(this._groupOnServer&&this._groupItems.length>0&&this.groupDescriptions.length>0){r=JSON.parse(JSON.stringify(this.groups));i=0;o=function(t){for(var e=Object.keys(n._groupItems[t].groupKey),_loop_4=function(r){var o=new _NullValue(i);e.forEach((function(e){o[e]=g._groupItems[t].groupKey[e]}));n._data[i]=o;i++},r=0;r<n._groupItems[t].count;r++)_loop_4()};n=this;for(c=0;c<this._groupItems.length;c++)o(c);if(0!=this.groups.length&&this.groups.length<r.length){s=this._data[this._start];a=this.groupDescriptions.length;u=this.groupDescriptions[a-1].propertyName;l=this.groups.findIndex((function(t){return t.name==s[u]}));h=r.findIndex((function(t){return t.name==s[u]}));this._start+=l-h;this._getData()}}else for(c=0;c<this._data.length;c++)this._data[c]=new _NullValue(c);this._refresh=!1}e||(this._loadOffset=0);p=this._loadOffset+(this._start||0);for(c=0;c<t.length;c++)this._data[c+p]=t[c];this._loadOffset+=t.length;setTimeout((function(){g._firstLoad&&g.currentPosition<0&&t.length&&g.moveCurrentToFirst();g._firstLoad=!1}));return[2]}))}))};RestCollectionView.prototype._performSetWindow=function(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}t=asInt(t);e=asInt(e);assert(t<=e,"start must be <= end.");var r=t<this._start,i=this._data;this._start=this._end=t;for(var o=t;o<=e&&o<i.length;o++)if(i[o]instanceof _NullValue){this._start=o;break}for(o=e;o>=this._start&&o<i.length;o--)if(i[o]instanceof _NullValue){this._end=o;break}if(this._start!=this._end||i[this._start]instanceof _NullValue){r&&(this._start=Math.max(0,this._end-this._fetchSize()+1));this._getData()}};RestCollectionView.prototype._fetchSize=function(){return Math.max(this._end-this._start+1,this.pageSize,_MIN_DATA_WINDOW)};RestCollectionView.prototype._raiseError=function(t,e){if(this.onError(new RESTErrorEventArgs(t))){e&&this._getData();throw"Server Error: "+t}};Object.defineProperty(RestCollectionView.prototype,"requestCanceled",{get:function(){this._requestCanceled||(this._requestCanceled=new Event);return this._requestCanceled},enumerable:!0,configurable:!0});RestCollectionView.prototype.onRequestCanceled=function(t){this.requestCanceled.raise(this,t)};RestCollectionView.prototype.getGroupItems=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.getItems=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.addItem=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.patchItem=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.deleteItem=function(t){throw"This method is virtual: it should be overridden"};return RestCollectionView}(CollectionView);export{RestCollectionView};var RESTErrorEventArgs=function(t){__extends(RESTErrorEventArgs,t);function RESTErrorEventArgs(e){var r=t.call(this)||this;r._error=e;return r}Object.defineProperty(RESTErrorEventArgs.prototype,"error",{get:function(){return this._error},enumerable:!0,configurable:!0});return RESTErrorEventArgs}(CancelEventArgs);export{RESTErrorEventArgs};_registerModule("wijmo.rest",selfModule);
|
14
|
+
var __extends=this&&this.__extends||function(){var extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){extendStatics(t,e);function __(){this.constructor=t}t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(o,n){function fulfilled(t){try{step(i.next(t))}catch(t){n(t)}}function rejected(t){try{step(i.throw(t))}catch(t){n(t)}}function step(t){t.done?o(t.value):new r((function(e){e(t.value)})).then(fulfilled,rejected)}step((i=i.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){var r,i,o,n,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function verb(n){return function(a){return function step(n){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,i&&(o=2&n[0]?i.return:n[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,n[1])).done)return o;(i=0,o)&&(n=[2&n[0],o.value]);switch(n[0]){case 0:case 1:o=n;break;case 4:s.label++;return{value:n[1],done:!1};case 5:s.label++;i=n[1];n=[0];continue;case 7:n=s.ops.pop();s.trys.pop();continue;default:if(!(o=s.trys,o=o.length>0&&o[o.length-1])&&(6===n[0]||2===n[0])){s=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){s.label=n[1];break}if(6===n[0]&&s.label<o[1]){s.label=o[1];o=n;break}if(o&&s.label<o[2]){s.label=o[2];s.ops.push(n);break}o[2]&&s.ops.pop();s.trys.pop();continue}n=e.call(t,s)}catch(t){n=[6,t];i=0}finally{r=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,a])}}};import{asArray,asBoolean,asInt,copy,clamp,CollectionView,Event,CancelEventArgs,assert,isString,getAggregate,_NullValue,Aggregate,_registerModule}from"@mescius/wijmo";import*as selfModule from"@mescius/wijmo.rest";var _MIN_DATA_WINDOW=100,RestCollectionView=function(t){__extends(RestCollectionView,t);function RestCollectionView(e){var r=t.call(this)||this;r._loading=!1;r._fields=null;r._keys=null;r._sortOnServer=!0;r._pageOnServer=!0;r._filterOnServer=!0;r._totalItemCount=0;r._aggregates="";r._groupOnServer=!0;r._groupLazyLoading=!1;r._virtualization=!1;r._start=0;r._end=_MIN_DATA_WINDOW;r._expandedGroups=[];r._groupItems=[];r._groupRefresh=!1;r._refresh=!1;r.loading=new Event;r.loaded=new Event;r.error=new Event;e&©(r,e);r.sortDescriptions.collectionChanged.addHandler((function(){r.sortOnServer&&r._getData()}));r._getData();(r._groupOnServer||r._virtualization)&&(r._data=[]);r._virtualization&&r.setWindow(r._start,_MIN_DATA_WINDOW);r._firstLoad=r._groupRefresh=!0;return r}Object.defineProperty(RestCollectionView.prototype,"totalGroupItemCount",{get:function(){return this.groupOnServer?this._totalGroupItemCount:0},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"groupOnServer",{get:function(){return this._groupOnServer},set:function(t){if(t!=this._groupOnServer){this._groupOnServer=asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"groupLazyLoading",{get:function(){return this._groupLazyLoading},set:function(t){t!=this._groupLazyLoading&&this._groupOnServer&&(this._groupLazyLoading=asBoolean(t))},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"virtualization",{get:function(){return this._virtualization},set:function(t){t!=this.virtualization&&(this._virtualization=asBoolean(t))},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"fields",{get:function(){return this._fields},set:function(t){if(this._fields!=t){this._fields=asArray(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"sortOnServer",{get:function(){return this._sortOnServer},set:function(t){if(t!=this._sortOnServer){this._sortOnServer=asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageOnServer",{get:function(){return this._pageOnServer},set:function(t){if(t!=this._pageOnServer){this._pageOnServer=asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"filterOnServer",{get:function(){return this._filterOnServer},set:function(t){if(t!=this._filterOnServer){this._filterOnServer=asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"requestHeaders",{get:function(){return this._requestHeaders},set:function(t){this._requestHeaders=t},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"aggregates",{get:function(){return this._aggregates},set:function(t){assert(this._groupOnServer,"groupOnServer should be enabled");isString(t)&&t!=this._aggregates&&(this._aggregates=t)},enumerable:!0,configurable:!0});RestCollectionView.prototype.updateFilterDefinition=function(t){if(this.filterOnServer){this._filterProvider=t;this._getData()}};RestCollectionView.prototype.lazyLoadGroup=function(t){if(this._groupLazyLoading){t.groups.length>0&&null==t.groups[0].name&&this._getData(t);0==t.groups.length&&t.isBottomLevel&&this._getData(t)}else assert(this._groupLazyLoading,"groupLazyLoading should be enabled lazy load the groups.")};RestCollectionView.prototype.setWindow=function(t,e){var r=this;this._toSetWindow&&clearTimeout(this._toSetWindow);this._toSetWindow=setTimeout((function(){r._toSetWindow=null;r._performSetWindow(t,e)}),50)};RestCollectionView.prototype._getFilterGroupItems=function(t){for(var e=this._groupItems,r=t.items[0],_loop_1=function(t){var o=i.groupDescriptions[t].propertyName;e=e.filter((function(t){return t.groupKey[o]==r[o]}))},i=this,o=0;o<=t.level;o++)_loop_1(o);return e};RestCollectionView.prototype.getGroupAggregate=function(t,e,r){void 0===r&&(r=Aggregate.Sum);if(this.groupOnServer&&(this.groupLazyLoading||this.virtualization||this.groupDescriptions.length>0&&this._groupItems.length>0)){var i="",o=this._getFilterGroupItems(e);o&&0!=o.length&&o.length!=this._groupItems.length&&o[0].aggregates&&(i=getAggregate(r,o,"aggregates."+t));return i}};Object.defineProperty(RestCollectionView.prototype,"isLoading",{get:function(){return this._loading},enumerable:!0,configurable:!0});RestCollectionView.prototype.onLoading=function(t){this.loading.raise(this,t)};RestCollectionView.prototype.onLoaded=function(t){this.loaded.raise(this,t)};RestCollectionView.prototype.load=function(){this._getData()};RestCollectionView.prototype.onError=function(t){this.error.raise(this,t);return!t.cancel};RestCollectionView.prototype._performRefresh=function(){this.isLoading||(this._refresh=!0);var e=this._canFilter,r=this._canSort;this._canFilter=!this._filterOnServer;this._canSort=!this._sortOnServer;t.prototype._performRefresh.call(this);this._canFilter=e;this._canSort=r};Object.defineProperty(RestCollectionView.prototype,"totalItemCount",{get:function(){return this.pageOnServer?this._totalItemCount:this._view.length},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageCount",{get:function(){return this.pageSize?Math.ceil(this.totalItemCount/this.pageSize):1},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageSize",{get:function(){return this._pgSz},set:function(t){if(t!=this._pgSz){this._pgSz=asInt(t);if(this.pageOnServer){this._pgIdx=clamp(this._pgIdx,0,this.pageCount-1);this._getData()}else this.refresh()}},enumerable:!0,configurable:!0});RestCollectionView.prototype.onPageChanging=function(e){t.prototype.onPageChanging.call(this,e);this.pageOnServer&&!e.cancel&&this._getData();return!e.cancel};RestCollectionView.prototype.commitNew=function(){var e=this,r=this.currentAddItem;if(r)try{var i=this.addItem(r);i&&i.then&&i.then((function(){return e.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.commitNew.call(this)};RestCollectionView.prototype.commitEdit=function(){var e=this,r=this.currentEditItem;if(r&&!this.currentAddItem&&!this._sameContent(r,this._edtClone)&&this.items.indexOf(r)>-1)try{var i=this.patchItem(r);i&&i.then&&i.then((function(){return e.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.commitEdit.call(this)};RestCollectionView.prototype.remove=function(e){var r=this;if(e&&e!=this.currentAddItem&&this.items.indexOf(e)>-1)try{var i=this.deleteItem(e);i&&i.then&&i.then((function(){return r.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.remove.call(this,e)};RestCollectionView.prototype._getPageView=function(){return this.pageOnServer?this._view:t.prototype._getPageView.call(this)};RestCollectionView.prototype._getData=function(t){var e=this;this._toGetData&&clearTimeout(this._toGetData);this._toGetData=setTimeout((function(){return __awaiter(e,void 0,void 0,(function(){var e,r,i,o,n,s,a,u=this;return __generator(this,(function(l){switch(l.label){case 0:this._toGetData=null;this._loading=!0;this.onLoading();e=null;if(this._groupOnServer||this._virtualization)return[3,5];r=null;l.label=1;case 1:l.trys.push([1,3,,4]);o=this.currentPosition;return[4,this.getItems()];case 2:r=l.sent();this.sourceCollection=r;this.refresh();o>-1&&this.moveCurrentToPosition(o);this.pageIndex>0&&this.pageIndex>=this.pageCount&&this.moveToLastPage();return[3,4];case 3:i=l.sent();e=i;return[3,4];case 4:return[3,12];case 5:o=-1;this.currentPosition>-1&&(o=this.currentPosition);n=this.groupDescriptions;this._data||(this._data=[]);s=[];return(this._groupRefresh||!(!this._groupLazyLoading||t&&t.isBottomLevel))&&this._groupOnServer&&n.length>0?[4,this.getGroupItems(t)]:[3,7];case 6:s=l.sent();t?this._updateSubGroups(t,s):this._groupItems=s;this._groupRefresh=!1;l.label=7;case 7:return this._groupLazyLoading?[3,9]:[4,this.getItems()];case 8:a=l.sent();l.label=9;case 9:return this._groupLazyLoading&&t&&t.isBottomLevel?[4,this.getItems(t)]:[3,11];case 10:a=l.sent();l.label=11;case 11:this.deferUpdate((function(){return __awaiter(u,void 0,void 0,(function(){var e,r,i,o,u;return __generator(this,(function(l){switch(l.label){case 0:this._virtualization||this._groupLazyLoading||(this._data=a);if(!this._groupLazyLoading||this._virtualization)return[3,4];if(t)return[3,3];this._data=new Array;e=n[0].propertyName;for(r=0;r<s.length;r++){i=new Object,o=s[r].count;i[e]=s[r].groupKey[e];for(u=0;u<o;u++)this._data.push(i)}return this._expandedGroups.length>0?[4,this._loadExpandedGroups(t)]:[3,2];case 1:l.sent();l.label=2;case 2:return[3,4];case 3:this._loadSubGroupsData(t,s,a);l.label=4;case 4:this._virtualization&&!this._groupLazyLoading&&this._storeItems(a,!1);this.sourceCollection=this._data;return[2]}}))}))}));this.refresh();o>-1&&this.moveCurrentToPosition(o);l.label=12;case 12:this._loading=!1;this.onLoaded();e&&this._raiseError(e,!1);return[2]}}))}))}),100)};RestCollectionView.prototype._loadExpandedGroups=function(t){return __awaiter(this,void 0,void 0,(function(){var e,r=this;return __generator(this,(function(i){if(this._expandedGroups.length>0&&!t){e=[];this._expandedGroups.forEach((function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(r){t.isBottomLevel?e.push(this.getItems(t)):e.push(this.getGroupItems(t));return[2]}))}))}));return[2,new Promise((function(t){Promise.all(e).then((function(e){for(var i=0;i<r._expandedGroups.length;i++)if(r._expandedGroups[i].isBottomLevel)r._loadSubGroupsData(r._expandedGroups[i],[],e[i]);else{r._updateSubGroups(r._expandedGroups[i],e[i]);r._loadSubGroupsData(r._expandedGroups[i],e[i],[])}t(!0)})).catch((function(e){t(!1)}))}))]}return[2]}))}))};RestCollectionView.prototype._updateSubGroups=function(t,e){var r,i=this._getFilterGroupItems(t);if(1==i.length){for(var o=0;o<e.length;o++)e[o].groupKey=__assign({},i[0].groupKey,e[o].groupKey);var n=this._groupItems.indexOf(i[0]);(r=this._groupItems).splice.apply(r,[n,1].concat(e))}else console.error("unable to find exact match for targetted group")};RestCollectionView.prototype._loadSubGroupsData=function(t,e,r){for(var i,o=this.groupDescriptions,n=this._data,_loop_2=function(e){var r=o[e].propertyName,i=t.items[e][r];n=n.filter((function(t){return t[r]===i}))},s=0;s<=(t.isBottomLevel?o.length-1:t.level);s++)_loop_2(s);var a=this._data.indexOf(n[0]);n=JSON.parse(JSON.stringify(n));if(t.isBottomLevel)for(s=0;s<r.length;s++)Object.assign(n[s],r[s]);else for(var u=t.groups[0].groupDescription.propertyName,l=0,s=0;s<e.length;s++){l+=s>0?e[s-1].count:0;for(var h=0;h<e[s].count;h++)n[l+h][u]=e[s].groupKey[u]}(i=this._data).splice.apply(i,[a,n.length].concat(n))};RestCollectionView.prototype._updateExpandedGroups=function(t,e){if(!this._loading){var r=this._expandedGroups.filter((function(e){return e._path.indexOf(t._path)>-1}));if(e)this._expandedGroups.push(t);else if(r.length>0)for(var i=0;i<r.length;i++)this._expandedGroups.splice(this._expandedGroups.indexOf(r[i]),1)}};RestCollectionView.prototype._storeItems=function(t,e){return __awaiter(this,void 0,void 0,(function(){var r,i,o,n,s,a,u,l,h,p,c,g=this;return __generator(this,(function(_){if(this._refresh||this._data.length!=this.totalItemCount||this.groups&&this.groups.length!=this._totalGroupItemCount){if(this._data.length!=this.totalItemCount&&this.groups&&this.groups.length>0){this._groupRefresh=!0;this._getData()}this._data.length=this.totalItemCount;if(this._groupOnServer&&this._groupItems.length>0&&this.groupDescriptions.length>0){r=JSON.parse(JSON.stringify(this.groups));i=0;o=function(t){for(var e=Object.keys(n._groupItems[t].groupKey),_loop_4=function(r){var o=new _NullValue(i);e.forEach((function(e){o[e]=g._groupItems[t].groupKey[e]}));n._data[i]=o;i++},r=0;r<n._groupItems[t].count;r++)_loop_4()};n=this;for(c=0;c<this._groupItems.length;c++)o(c);if(0!=this.groups.length&&this.groups.length<r.length){s=this._data[this._start];a=this.groupDescriptions.length;u=this.groupDescriptions[a-1].propertyName;l=this.groups.findIndex((function(t){return t.name==s[u]}));h=r.findIndex((function(t){return t.name==s[u]}));this._start+=l-h;this._getData()}}else for(c=0;c<this._data.length;c++)this._data[c]=new _NullValue(c);this._refresh=!1}e||(this._loadOffset=0);p=this._loadOffset+(this._start||0);for(c=0;c<t.length;c++)this._data[c+p]=t[c];this._loadOffset+=t.length;setTimeout((function(){g._firstLoad&&g.currentPosition<0&&t.length&&g.moveCurrentToFirst();g._firstLoad=!1}));return[2]}))}))};RestCollectionView.prototype._performSetWindow=function(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}t=asInt(t);e=asInt(e);assert(t<=e,"start must be <= end.");var r=t<this._start,i=this._data;this._start=this._end=t;for(var o=t;o<=e&&o<i.length;o++)if(i[o]instanceof _NullValue){this._start=o;break}for(o=e;o>=this._start&&o<i.length;o--)if(i[o]instanceof _NullValue){this._end=o;break}if(this._start!=this._end||i[this._start]instanceof _NullValue){r&&(this._start=Math.max(0,this._end-this._fetchSize()+1));this._getData()}};RestCollectionView.prototype._fetchSize=function(){return Math.max(this._end-this._start+1,this.pageSize,_MIN_DATA_WINDOW)};RestCollectionView.prototype._raiseError=function(t,e){if(this.onError(new RESTErrorEventArgs(t))){e&&this._getData();throw"Server Error: "+t}};Object.defineProperty(RestCollectionView.prototype,"requestCanceled",{get:function(){this._requestCanceled||(this._requestCanceled=new Event);return this._requestCanceled},enumerable:!0,configurable:!0});RestCollectionView.prototype.onRequestCanceled=function(t){this.requestCanceled.raise(this,t)};RestCollectionView.prototype.getGroupItems=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.getItems=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.addItem=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.patchItem=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.deleteItem=function(t){throw"This method is virtual: it should be overridden"};return RestCollectionView}(CollectionView);export{RestCollectionView};var RESTErrorEventArgs=function(t){__extends(RESTErrorEventArgs,t);function RESTErrorEventArgs(e){var r=t.call(this)||this;r._error=e;return r}Object.defineProperty(RESTErrorEventArgs.prototype,"error",{get:function(){return this._error},enumerable:!0,configurable:!0});return RESTErrorEventArgs}(CancelEventArgs);export{RESTErrorEventArgs};_registerModule("wijmo.rest",selfModule);
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
*
|
3
|
-
* Wijmo Library 5.20242.20-nightly.
|
3
|
+
* Wijmo Library 5.20242.20-nightly.d20240826.t020151
|
4
4
|
* https://developer.mescius.com/wijmo
|
5
5
|
*
|
6
6
|
* Copyright(c) MESCIUS inc. All rights reserved.
|
@@ -11,4 +11,4 @@
|
|
11
11
|
*
|
12
12
|
*/
|
13
13
|
|
14
|
-
"use strict";var __extends=this&&this.__extends||function(){var extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){extendStatics(t,e);function __(){this.constructor=t}t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(o,n){function fulfilled(t){try{step(i.next(t))}catch(t){n(t)}}function rejected(t){try{step(i.throw(t))}catch(t){n(t)}}function step(t){t.done?o(t.value):new r((function(e){e(t.value)})).then(fulfilled,rejected)}step((i=i.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){var r,i,o,n,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function verb(n){return function(a){return function step(n){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,i&&(o=2&n[0]?i.return:n[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,n[1])).done)return o;(i=0,o)&&(n=[2&n[0],o.value]);switch(n[0]){case 0:case 1:o=n;break;case 4:s.label++;return{value:n[1],done:!1};case 5:s.label++;i=n[1];n=[0];continue;case 7:n=s.ops.pop();s.trys.pop();continue;default:if(!(o=s.trys,o=o.length>0&&o[o.length-1])&&(6===n[0]||2===n[0])){s=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){s.label=n[1];break}if(6===n[0]&&s.label<o[1]){s.label=o[1];o=n;break}if(o&&s.label<o[2]){s.label=o[2];s.ops.push(n);break}o[2]&&s.ops.pop();s.trys.pop();continue}n=e.call(t,s)}catch(t){n=[6,t];i=0}finally{r=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,a])}}},__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);e.default=t;return e};Object.defineProperty(exports,"__esModule",{value:!0});var wijmo_1=require("@mescius/wijmo"),selfModule=__importStar(require("@mescius/wijmo.rest")),_MIN_DATA_WINDOW=100,RestCollectionView=function(t){__extends(RestCollectionView,t);function RestCollectionView(e){var r=t.call(this)||this;r._loading=!1;r._fields=null;r._keys=null;r._sortOnServer=!0;r._pageOnServer=!0;r._filterOnServer=!0;r._totalItemCount=0;r._aggregates="";r._groupOnServer=!0;r._groupLazyLoading=!1;r._virtualization=!1;r._start=0;r._end=_MIN_DATA_WINDOW;r._expandedGroups=[];r._groupItems=[];r._groupRefresh=!1;r._refresh=!1;r.loading=new wijmo_1.Event;r.loaded=new wijmo_1.Event;r.error=new wijmo_1.Event;e&&wijmo_1.copy(r,e);r.sortDescriptions.collectionChanged.addHandler((function(){r.sortOnServer&&r._getData()}));r._getData();(r._groupOnServer||r._virtualization)&&(r._data=[]);r._virtualization&&r.setWindow(r._start,_MIN_DATA_WINDOW);r._firstLoad=r._groupRefresh=!0;return r}Object.defineProperty(RestCollectionView.prototype,"totalGroupItemCount",{get:function(){return this.groupOnServer?this._totalGroupItemCount:0},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"groupOnServer",{get:function(){return this._groupOnServer},set:function(t){if(t!=this._groupOnServer){this._groupOnServer=wijmo_1.asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"groupLazyLoading",{get:function(){return this._groupLazyLoading},set:function(t){t!=this._groupLazyLoading&&this._groupOnServer&&(this._groupLazyLoading=wijmo_1.asBoolean(t))},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"virtualization",{get:function(){return this._virtualization},set:function(t){t!=this.virtualization&&(this._virtualization=wijmo_1.asBoolean(t))},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"fields",{get:function(){return this._fields},set:function(t){if(this._fields!=t){this._fields=wijmo_1.asArray(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"sortOnServer",{get:function(){return this._sortOnServer},set:function(t){if(t!=this._sortOnServer){this._sortOnServer=wijmo_1.asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageOnServer",{get:function(){return this._pageOnServer},set:function(t){if(t!=this._pageOnServer){this._pageOnServer=wijmo_1.asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"filterOnServer",{get:function(){return this._filterOnServer},set:function(t){if(t!=this._filterOnServer){this._filterOnServer=wijmo_1.asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"requestHeaders",{get:function(){return this._requestHeaders},set:function(t){this._requestHeaders=t},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"aggregates",{get:function(){return this._aggregates},set:function(t){wijmo_1.assert(this._groupOnServer,"groupOnServer should be enabled");wijmo_1.isString(t)&&t!=this._aggregates&&(this._aggregates=t)},enumerable:!0,configurable:!0});RestCollectionView.prototype.updateFilterDefinition=function(t){if(this.filterOnServer){this._filterProvider=t;this._getData()}};RestCollectionView.prototype.lazyLoadGroup=function(t){if(this._groupLazyLoading){t.groups.length>0&&null==t.groups[0].name&&this._getData(t);0==t.groups.length&&t.isBottomLevel&&this._getData(t)}else wijmo_1.assert(this._groupLazyLoading,"groupLazyLoading should be enabled lazy load the groups.")};RestCollectionView.prototype.setWindow=function(t,e){var r=this;this._toSetWindow&&clearTimeout(this._toSetWindow);this._toSetWindow=setTimeout((function(){r._toSetWindow=null;r._performSetWindow(t,e)}),50)};RestCollectionView.prototype._getFilterGroupItems=function(t){for(var e=this._groupItems,r=t.items[0],_loop_1=function(t){var o=i.groupDescriptions[t].propertyName;e=e.filter((function(t){return t.groupKey[o]==r[o]}))},i=this,o=0;o<=t.level;o++)_loop_1(o);return e};RestCollectionView.prototype.getGroupAggregate=function(t,e,r){void 0===r&&(r=wijmo_1.Aggregate.Sum);if(this.groupLazyLoading||this.virtualization){var i="",o=this._getFilterGroupItems(e);o&&0!=o.length&&o.length!=this._groupItems.length&&o[0].aggregates&&(i=wijmo_1.getAggregate(r,o,"aggregates."+t));return i}};Object.defineProperty(RestCollectionView.prototype,"isLoading",{get:function(){return this._loading},enumerable:!0,configurable:!0});RestCollectionView.prototype.onLoading=function(t){this.loading.raise(this,t)};RestCollectionView.prototype.onLoaded=function(t){this.loaded.raise(this,t)};RestCollectionView.prototype.load=function(){this._getData()};RestCollectionView.prototype.onError=function(t){this.error.raise(this,t);return!t.cancel};RestCollectionView.prototype._performRefresh=function(){this.isLoading||(this._refresh=!0);var e=this._canFilter,r=this._canSort;this._canFilter=!this._filterOnServer;this._canSort=!this._sortOnServer;t.prototype._performRefresh.call(this);this._canFilter=e;this._canSort=r};Object.defineProperty(RestCollectionView.prototype,"totalItemCount",{get:function(){return this.pageOnServer?this._totalItemCount:this._view.length},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageCount",{get:function(){return this.pageSize?Math.ceil(this.totalItemCount/this.pageSize):1},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageSize",{get:function(){return this._pgSz},set:function(t){if(t!=this._pgSz){this._pgSz=wijmo_1.asInt(t);if(this.pageOnServer){this._pgIdx=wijmo_1.clamp(this._pgIdx,0,this.pageCount-1);this._getData()}else this.refresh()}},enumerable:!0,configurable:!0});RestCollectionView.prototype.onPageChanging=function(e){t.prototype.onPageChanging.call(this,e);this.pageOnServer&&!e.cancel&&this._getData();return!e.cancel};RestCollectionView.prototype.commitNew=function(){var e=this,r=this.currentAddItem;if(r)try{var i=this.addItem(r);i&&i.then&&i.then((function(){return e.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.commitNew.call(this)};RestCollectionView.prototype.commitEdit=function(){var e=this,r=this.currentEditItem;if(r&&!this.currentAddItem&&!this._sameContent(r,this._edtClone)&&this.items.indexOf(r)>-1)try{var i=this.patchItem(r);i&&i.then&&i.then((function(){return e.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.commitEdit.call(this)};RestCollectionView.prototype.remove=function(e){var r=this;if(e&&e!=this.currentAddItem&&this.items.indexOf(e)>-1)try{var i=this.deleteItem(e);i&&i.then&&i.then((function(){return r.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.remove.call(this,e)};RestCollectionView.prototype._getPageView=function(){return this.pageOnServer?this._view:t.prototype._getPageView.call(this)};RestCollectionView.prototype._getData=function(t){var e=this;this._toGetData&&clearTimeout(this._toGetData);this._toGetData=setTimeout((function(){return __awaiter(e,void 0,void 0,(function(){var e,r,i,o,n,s,a,u=this;return __generator(this,(function(l){switch(l.label){case 0:this._toGetData=null;this._loading=!0;this.onLoading();e=null;if(this._groupOnServer||this._virtualization)return[3,5];r=null;l.label=1;case 1:l.trys.push([1,3,,4]);o=this.currentPosition;return[4,this.getItems()];case 2:r=l.sent();this.sourceCollection=r;this.refresh();o>-1&&this.moveCurrentToPosition(o);this.pageIndex>0&&this.pageIndex>=this.pageCount&&this.moveToLastPage();return[3,4];case 3:i=l.sent();e=i;return[3,4];case 4:return[3,12];case 5:o=-1;this.currentPosition>-1&&(o=this.currentPosition);n=this.groupDescriptions;this._data||(this._data=[]);s=[];return(this._groupRefresh||!(!this._groupLazyLoading||t&&t.isBottomLevel))&&this._groupOnServer&&n.length>0?[4,this.getGroupItems(t)]:[3,7];case 6:s=l.sent();t?this._updateSubGroups(t,s):this._groupItems=s;this._groupRefresh=!1;l.label=7;case 7:return this._groupLazyLoading?[3,9]:[4,this.getItems()];case 8:a=l.sent();l.label=9;case 9:return this._groupLazyLoading&&t&&t.isBottomLevel?[4,this.getItems(t)]:[3,11];case 10:a=l.sent();l.label=11;case 11:this.deferUpdate((function(){return __awaiter(u,void 0,void 0,(function(){var e,r,i,o,u;return __generator(this,(function(l){switch(l.label){case 0:this._virtualization||this._groupLazyLoading||(this._data=a);if(!this._groupLazyLoading||this._virtualization)return[3,4];if(t)return[3,3];this._data=new Array;e=n[0].propertyName;for(r=0;r<s.length;r++){i=new Object,o=s[r].count;i[e]=s[r].groupKey[e];for(u=0;u<o;u++)this._data.push(i)}return this._expandedGroups.length>0?[4,this._loadExpandedGroups(t)]:[3,2];case 1:l.sent();l.label=2;case 2:return[3,4];case 3:this._loadSubGroupsData(t,s,a);l.label=4;case 4:this._virtualization&&!this._groupLazyLoading&&this._storeItems(a,!1);this.sourceCollection=this._data;return[2]}}))}))}));this.refresh();o>-1&&this.moveCurrentToPosition(o);l.label=12;case 12:this._loading=!1;this.onLoaded();e&&this._raiseError(e,!1);return[2]}}))}))}),100)};RestCollectionView.prototype._loadExpandedGroups=function(t){return __awaiter(this,void 0,void 0,(function(){var e,r=this;return __generator(this,(function(i){if(this._expandedGroups.length>0&&!t){e=[];this._expandedGroups.forEach((function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(r){t.isBottomLevel?e.push(this.getItems(t)):e.push(this.getGroupItems(t));return[2]}))}))}));return[2,new Promise((function(t){Promise.all(e).then((function(e){for(var i=0;i<r._expandedGroups.length;i++)if(r._expandedGroups[i].isBottomLevel)r._loadSubGroupsData(r._expandedGroups[i],[],e[i]);else{r._updateSubGroups(r._expandedGroups[i],e[i]);r._loadSubGroupsData(r._expandedGroups[i],e[i],[])}t(!0)})).catch((function(e){t(!1)}))}))]}return[2]}))}))};RestCollectionView.prototype._updateSubGroups=function(t,e){var r,i=this._getFilterGroupItems(t);if(1==i.length){for(var o=0;o<e.length;o++)e[o].groupKey=__assign({},i[0].groupKey,e[o].groupKey);var n=this._groupItems.indexOf(i[0]);(r=this._groupItems).splice.apply(r,[n,1].concat(e))}else console.error("unable to find exact match for targetted group")};RestCollectionView.prototype._loadSubGroupsData=function(t,e,r){for(var i,o=this.groupDescriptions,n=this._data,_loop_2=function(e){var r=o[e].propertyName,i=t.items[e][r];n=n.filter((function(t){return t[r]===i}))},s=0;s<=(t.isBottomLevel?o.length-1:t.level);s++)_loop_2(s);var a=this._data.indexOf(n[0]);n=JSON.parse(JSON.stringify(n));if(t.isBottomLevel)for(s=0;s<r.length;s++)Object.assign(n[s],r[s]);else for(var u=t.groups[0].groupDescription.propertyName,l=0,s=0;s<e.length;s++){l+=s>0?e[s-1].count:0;for(var h=0;h<e[s].count;h++)n[l+h][u]=e[s].groupKey[u]}(i=this._data).splice.apply(i,[a,n.length].concat(n))};RestCollectionView.prototype._updateExpandedGroups=function(t,e){if(!this._loading){var r=this._expandedGroups.filter((function(e){return e._path.indexOf(t._path)>-1}));if(e)this._expandedGroups.push(t);else if(r.length>0)for(var i=0;i<r.length;i++)this._expandedGroups.splice(this._expandedGroups.indexOf(r[i]),1)}};RestCollectionView.prototype._storeItems=function(t,e){return __awaiter(this,void 0,void 0,(function(){var r,i,o,n,s,a,u,l,h,p,c,_=this;return __generator(this,(function(g){if(this._refresh||this._data.length!=this.totalItemCount||this.groups&&this.groups.length!=this._totalGroupItemCount){if(this._data.length!=this.totalItemCount&&this.groups&&this.groups.length>0){this._groupRefresh=!0;this._getData()}this._data.length=this.totalItemCount;if(this._groupOnServer&&this._groupItems.length>0&&this.groupDescriptions.length>0){r=JSON.parse(JSON.stringify(this.groups));i=0;o=function(t){for(var e=Object.keys(n._groupItems[t].groupKey),_loop_4=function(r){var o=new wijmo_1._NullValue(i);e.forEach((function(e){o[e]=_._groupItems[t].groupKey[e]}));n._data[i]=o;i++},r=0;r<n._groupItems[t].count;r++)_loop_4()};n=this;for(c=0;c<this._groupItems.length;c++)o(c);if(0!=this.groups.length&&this.groups.length<r.length){s=this._data[this._start];a=this.groupDescriptions.length;u=this.groupDescriptions[a-1].propertyName;l=this.groups.findIndex((function(t){return t.name==s[u]}));h=r.findIndex((function(t){return t.name==s[u]}));this._start+=l-h;this._getData()}}else for(c=0;c<this._data.length;c++)this._data[c]=new wijmo_1._NullValue(c);this._refresh=!1}e||(this._loadOffset=0);p=this._loadOffset+(this._start||0);for(c=0;c<t.length;c++)this._data[c+p]=t[c];this._loadOffset+=t.length;setTimeout((function(){_._firstLoad&&_.currentPosition<0&&t.length&&_.moveCurrentToFirst();_._firstLoad=!1}));return[2]}))}))};RestCollectionView.prototype._performSetWindow=function(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}t=wijmo_1.asInt(t);e=wijmo_1.asInt(e);wijmo_1.assert(t<=e,"start must be <= end.");var r=t<this._start,i=this._data;this._start=this._end=t;for(var o=t;o<=e&&o<i.length;o++)if(i[o]instanceof wijmo_1._NullValue){this._start=o;break}for(o=e;o>=this._start&&o<i.length;o--)if(i[o]instanceof wijmo_1._NullValue){this._end=o;break}if(this._start!=this._end||i[this._start]instanceof wijmo_1._NullValue){r&&(this._start=Math.max(0,this._end-this._fetchSize()+1));this._getData()}};RestCollectionView.prototype._fetchSize=function(){return Math.max(this._end-this._start+1,this.pageSize,_MIN_DATA_WINDOW)};RestCollectionView.prototype._raiseError=function(t,e){if(this.onError(new RESTErrorEventArgs(t))){e&&this._getData();throw"Server Error: "+t}};Object.defineProperty(RestCollectionView.prototype,"requestCanceled",{get:function(){this._requestCanceled||(this._requestCanceled=new wijmo_1.Event);return this._requestCanceled},enumerable:!0,configurable:!0});RestCollectionView.prototype.onRequestCanceled=function(t){this.requestCanceled.raise(this,t)};RestCollectionView.prototype.getGroupItems=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.getItems=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.addItem=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.patchItem=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.deleteItem=function(t){throw"This method is virtual: it should be overridden"};return RestCollectionView}(wijmo_1.CollectionView);exports.RestCollectionView=RestCollectionView;var RESTErrorEventArgs=function(t){__extends(RESTErrorEventArgs,t);function RESTErrorEventArgs(e){var r=t.call(this)||this;r._error=e;return r}Object.defineProperty(RESTErrorEventArgs.prototype,"error",{get:function(){return this._error},enumerable:!0,configurable:!0});return RESTErrorEventArgs}(wijmo_1.CancelEventArgs);exports.RESTErrorEventArgs=RESTErrorEventArgs;wijmo_1._registerModule("wijmo.rest",selfModule);
|
14
|
+
"use strict";var __extends=this&&this.__extends||function(){var extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){extendStatics(t,e);function __(){this.constructor=t}t.prototype=null===e?Object.create(e):(__.prototype=e.prototype,new __)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,i=arguments.length;r<i;r++){e=arguments[r];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t}).apply(this,arguments)},__awaiter=this&&this.__awaiter||function(t,e,r,i){return new(r||(r=Promise))((function(o,n){function fulfilled(t){try{step(i.next(t))}catch(t){n(t)}}function rejected(t){try{step(i.throw(t))}catch(t){n(t)}}function step(t){t.done?o(t.value):new r((function(e){e(t.value)})).then(fulfilled,rejected)}step((i=i.apply(t,e||[])).next())}))},__generator=this&&this.__generator||function(t,e){var r,i,o,n,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return n={next:verb(0),throw:verb(1),return:verb(2)},"function"==typeof Symbol&&(n[Symbol.iterator]=function(){return this}),n;function verb(n){return function(a){return function step(n){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,i&&(o=2&n[0]?i.return:n[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,n[1])).done)return o;(i=0,o)&&(n=[2&n[0],o.value]);switch(n[0]){case 0:case 1:o=n;break;case 4:s.label++;return{value:n[1],done:!1};case 5:s.label++;i=n[1];n=[0];continue;case 7:n=s.ops.pop();s.trys.pop();continue;default:if(!(o=s.trys,o=o.length>0&&o[o.length-1])&&(6===n[0]||2===n[0])){s=0;continue}if(3===n[0]&&(!o||n[1]>o[0]&&n[1]<o[3])){s.label=n[1];break}if(6===n[0]&&s.label<o[1]){s.label=o[1];o=n;break}if(o&&s.label<o[2]){s.label=o[2];s.ops.push(n);break}o[2]&&s.ops.pop();s.trys.pop();continue}n=e.call(t,s)}catch(t){n=[6,t];i=0}finally{r=o=0}if(5&n[0])throw n[1];return{value:n[0]?n[1]:void 0,done:!0}}([n,a])}}},__importStar=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);e.default=t;return e};Object.defineProperty(exports,"__esModule",{value:!0});var wijmo_1=require("@mescius/wijmo"),selfModule=__importStar(require("@mescius/wijmo.rest")),_MIN_DATA_WINDOW=100,RestCollectionView=function(t){__extends(RestCollectionView,t);function RestCollectionView(e){var r=t.call(this)||this;r._loading=!1;r._fields=null;r._keys=null;r._sortOnServer=!0;r._pageOnServer=!0;r._filterOnServer=!0;r._totalItemCount=0;r._aggregates="";r._groupOnServer=!0;r._groupLazyLoading=!1;r._virtualization=!1;r._start=0;r._end=_MIN_DATA_WINDOW;r._expandedGroups=[];r._groupItems=[];r._groupRefresh=!1;r._refresh=!1;r.loading=new wijmo_1.Event;r.loaded=new wijmo_1.Event;r.error=new wijmo_1.Event;e&&wijmo_1.copy(r,e);r.sortDescriptions.collectionChanged.addHandler((function(){r.sortOnServer&&r._getData()}));r._getData();(r._groupOnServer||r._virtualization)&&(r._data=[]);r._virtualization&&r.setWindow(r._start,_MIN_DATA_WINDOW);r._firstLoad=r._groupRefresh=!0;return r}Object.defineProperty(RestCollectionView.prototype,"totalGroupItemCount",{get:function(){return this.groupOnServer?this._totalGroupItemCount:0},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"groupOnServer",{get:function(){return this._groupOnServer},set:function(t){if(t!=this._groupOnServer){this._groupOnServer=wijmo_1.asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"groupLazyLoading",{get:function(){return this._groupLazyLoading},set:function(t){t!=this._groupLazyLoading&&this._groupOnServer&&(this._groupLazyLoading=wijmo_1.asBoolean(t))},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"virtualization",{get:function(){return this._virtualization},set:function(t){t!=this.virtualization&&(this._virtualization=wijmo_1.asBoolean(t))},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"fields",{get:function(){return this._fields},set:function(t){if(this._fields!=t){this._fields=wijmo_1.asArray(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"sortOnServer",{get:function(){return this._sortOnServer},set:function(t){if(t!=this._sortOnServer){this._sortOnServer=wijmo_1.asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageOnServer",{get:function(){return this._pageOnServer},set:function(t){if(t!=this._pageOnServer){this._pageOnServer=wijmo_1.asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"filterOnServer",{get:function(){return this._filterOnServer},set:function(t){if(t!=this._filterOnServer){this._filterOnServer=wijmo_1.asBoolean(t);this._getData()}},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"requestHeaders",{get:function(){return this._requestHeaders},set:function(t){this._requestHeaders=t},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"aggregates",{get:function(){return this._aggregates},set:function(t){wijmo_1.assert(this._groupOnServer,"groupOnServer should be enabled");wijmo_1.isString(t)&&t!=this._aggregates&&(this._aggregates=t)},enumerable:!0,configurable:!0});RestCollectionView.prototype.updateFilterDefinition=function(t){if(this.filterOnServer){this._filterProvider=t;this._getData()}};RestCollectionView.prototype.lazyLoadGroup=function(t){if(this._groupLazyLoading){t.groups.length>0&&null==t.groups[0].name&&this._getData(t);0==t.groups.length&&t.isBottomLevel&&this._getData(t)}else wijmo_1.assert(this._groupLazyLoading,"groupLazyLoading should be enabled lazy load the groups.")};RestCollectionView.prototype.setWindow=function(t,e){var r=this;this._toSetWindow&&clearTimeout(this._toSetWindow);this._toSetWindow=setTimeout((function(){r._toSetWindow=null;r._performSetWindow(t,e)}),50)};RestCollectionView.prototype._getFilterGroupItems=function(t){for(var e=this._groupItems,r=t.items[0],_loop_1=function(t){var o=i.groupDescriptions[t].propertyName;e=e.filter((function(t){return t.groupKey[o]==r[o]}))},i=this,o=0;o<=t.level;o++)_loop_1(o);return e};RestCollectionView.prototype.getGroupAggregate=function(t,e,r){void 0===r&&(r=wijmo_1.Aggregate.Sum);if(this.groupOnServer&&(this.groupLazyLoading||this.virtualization||this.groupDescriptions.length>0&&this._groupItems.length>0)){var i="",o=this._getFilterGroupItems(e);o&&0!=o.length&&o.length!=this._groupItems.length&&o[0].aggregates&&(i=wijmo_1.getAggregate(r,o,"aggregates."+t));return i}};Object.defineProperty(RestCollectionView.prototype,"isLoading",{get:function(){return this._loading},enumerable:!0,configurable:!0});RestCollectionView.prototype.onLoading=function(t){this.loading.raise(this,t)};RestCollectionView.prototype.onLoaded=function(t){this.loaded.raise(this,t)};RestCollectionView.prototype.load=function(){this._getData()};RestCollectionView.prototype.onError=function(t){this.error.raise(this,t);return!t.cancel};RestCollectionView.prototype._performRefresh=function(){this.isLoading||(this._refresh=!0);var e=this._canFilter,r=this._canSort;this._canFilter=!this._filterOnServer;this._canSort=!this._sortOnServer;t.prototype._performRefresh.call(this);this._canFilter=e;this._canSort=r};Object.defineProperty(RestCollectionView.prototype,"totalItemCount",{get:function(){return this.pageOnServer?this._totalItemCount:this._view.length},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageCount",{get:function(){return this.pageSize?Math.ceil(this.totalItemCount/this.pageSize):1},enumerable:!0,configurable:!0});Object.defineProperty(RestCollectionView.prototype,"pageSize",{get:function(){return this._pgSz},set:function(t){if(t!=this._pgSz){this._pgSz=wijmo_1.asInt(t);if(this.pageOnServer){this._pgIdx=wijmo_1.clamp(this._pgIdx,0,this.pageCount-1);this._getData()}else this.refresh()}},enumerable:!0,configurable:!0});RestCollectionView.prototype.onPageChanging=function(e){t.prototype.onPageChanging.call(this,e);this.pageOnServer&&!e.cancel&&this._getData();return!e.cancel};RestCollectionView.prototype.commitNew=function(){var e=this,r=this.currentAddItem;if(r)try{var i=this.addItem(r);i&&i.then&&i.then((function(){return e.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.commitNew.call(this)};RestCollectionView.prototype.commitEdit=function(){var e=this,r=this.currentEditItem;if(r&&!this.currentAddItem&&!this._sameContent(r,this._edtClone)&&this.items.indexOf(r)>-1)try{var i=this.patchItem(r);i&&i.then&&i.then((function(){return e.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.commitEdit.call(this)};RestCollectionView.prototype.remove=function(e){var r=this;if(e&&e!=this.currentAddItem&&this.items.indexOf(e)>-1)try{var i=this.deleteItem(e);i&&i.then&&i.then((function(){return r.refresh()}))}catch(t){this._raiseError(t,!0)}t.prototype.remove.call(this,e)};RestCollectionView.prototype._getPageView=function(){return this.pageOnServer?this._view:t.prototype._getPageView.call(this)};RestCollectionView.prototype._getData=function(t){var e=this;this._toGetData&&clearTimeout(this._toGetData);this._toGetData=setTimeout((function(){return __awaiter(e,void 0,void 0,(function(){var e,r,i,o,n,s,a,u=this;return __generator(this,(function(l){switch(l.label){case 0:this._toGetData=null;this._loading=!0;this.onLoading();e=null;if(this._groupOnServer||this._virtualization)return[3,5];r=null;l.label=1;case 1:l.trys.push([1,3,,4]);o=this.currentPosition;return[4,this.getItems()];case 2:r=l.sent();this.sourceCollection=r;this.refresh();o>-1&&this.moveCurrentToPosition(o);this.pageIndex>0&&this.pageIndex>=this.pageCount&&this.moveToLastPage();return[3,4];case 3:i=l.sent();e=i;return[3,4];case 4:return[3,12];case 5:o=-1;this.currentPosition>-1&&(o=this.currentPosition);n=this.groupDescriptions;this._data||(this._data=[]);s=[];return(this._groupRefresh||!(!this._groupLazyLoading||t&&t.isBottomLevel))&&this._groupOnServer&&n.length>0?[4,this.getGroupItems(t)]:[3,7];case 6:s=l.sent();t?this._updateSubGroups(t,s):this._groupItems=s;this._groupRefresh=!1;l.label=7;case 7:return this._groupLazyLoading?[3,9]:[4,this.getItems()];case 8:a=l.sent();l.label=9;case 9:return this._groupLazyLoading&&t&&t.isBottomLevel?[4,this.getItems(t)]:[3,11];case 10:a=l.sent();l.label=11;case 11:this.deferUpdate((function(){return __awaiter(u,void 0,void 0,(function(){var e,r,i,o,u;return __generator(this,(function(l){switch(l.label){case 0:this._virtualization||this._groupLazyLoading||(this._data=a);if(!this._groupLazyLoading||this._virtualization)return[3,4];if(t)return[3,3];this._data=new Array;e=n[0].propertyName;for(r=0;r<s.length;r++){i=new Object,o=s[r].count;i[e]=s[r].groupKey[e];for(u=0;u<o;u++)this._data.push(i)}return this._expandedGroups.length>0?[4,this._loadExpandedGroups(t)]:[3,2];case 1:l.sent();l.label=2;case 2:return[3,4];case 3:this._loadSubGroupsData(t,s,a);l.label=4;case 4:this._virtualization&&!this._groupLazyLoading&&this._storeItems(a,!1);this.sourceCollection=this._data;return[2]}}))}))}));this.refresh();o>-1&&this.moveCurrentToPosition(o);l.label=12;case 12:this._loading=!1;this.onLoaded();e&&this._raiseError(e,!1);return[2]}}))}))}),100)};RestCollectionView.prototype._loadExpandedGroups=function(t){return __awaiter(this,void 0,void 0,(function(){var e,r=this;return __generator(this,(function(i){if(this._expandedGroups.length>0&&!t){e=[];this._expandedGroups.forEach((function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(r){t.isBottomLevel?e.push(this.getItems(t)):e.push(this.getGroupItems(t));return[2]}))}))}));return[2,new Promise((function(t){Promise.all(e).then((function(e){for(var i=0;i<r._expandedGroups.length;i++)if(r._expandedGroups[i].isBottomLevel)r._loadSubGroupsData(r._expandedGroups[i],[],e[i]);else{r._updateSubGroups(r._expandedGroups[i],e[i]);r._loadSubGroupsData(r._expandedGroups[i],e[i],[])}t(!0)})).catch((function(e){t(!1)}))}))]}return[2]}))}))};RestCollectionView.prototype._updateSubGroups=function(t,e){var r,i=this._getFilterGroupItems(t);if(1==i.length){for(var o=0;o<e.length;o++)e[o].groupKey=__assign({},i[0].groupKey,e[o].groupKey);var n=this._groupItems.indexOf(i[0]);(r=this._groupItems).splice.apply(r,[n,1].concat(e))}else console.error("unable to find exact match for targetted group")};RestCollectionView.prototype._loadSubGroupsData=function(t,e,r){for(var i,o=this.groupDescriptions,n=this._data,_loop_2=function(e){var r=o[e].propertyName,i=t.items[e][r];n=n.filter((function(t){return t[r]===i}))},s=0;s<=(t.isBottomLevel?o.length-1:t.level);s++)_loop_2(s);var a=this._data.indexOf(n[0]);n=JSON.parse(JSON.stringify(n));if(t.isBottomLevel)for(s=0;s<r.length;s++)Object.assign(n[s],r[s]);else for(var u=t.groups[0].groupDescription.propertyName,l=0,s=0;s<e.length;s++){l+=s>0?e[s-1].count:0;for(var h=0;h<e[s].count;h++)n[l+h][u]=e[s].groupKey[u]}(i=this._data).splice.apply(i,[a,n.length].concat(n))};RestCollectionView.prototype._updateExpandedGroups=function(t,e){if(!this._loading){var r=this._expandedGroups.filter((function(e){return e._path.indexOf(t._path)>-1}));if(e)this._expandedGroups.push(t);else if(r.length>0)for(var i=0;i<r.length;i++)this._expandedGroups.splice(this._expandedGroups.indexOf(r[i]),1)}};RestCollectionView.prototype._storeItems=function(t,e){return __awaiter(this,void 0,void 0,(function(){var r,i,o,n,s,a,u,l,h,p,c,_=this;return __generator(this,(function(g){if(this._refresh||this._data.length!=this.totalItemCount||this.groups&&this.groups.length!=this._totalGroupItemCount){if(this._data.length!=this.totalItemCount&&this.groups&&this.groups.length>0){this._groupRefresh=!0;this._getData()}this._data.length=this.totalItemCount;if(this._groupOnServer&&this._groupItems.length>0&&this.groupDescriptions.length>0){r=JSON.parse(JSON.stringify(this.groups));i=0;o=function(t){for(var e=Object.keys(n._groupItems[t].groupKey),_loop_4=function(r){var o=new wijmo_1._NullValue(i);e.forEach((function(e){o[e]=_._groupItems[t].groupKey[e]}));n._data[i]=o;i++},r=0;r<n._groupItems[t].count;r++)_loop_4()};n=this;for(c=0;c<this._groupItems.length;c++)o(c);if(0!=this.groups.length&&this.groups.length<r.length){s=this._data[this._start];a=this.groupDescriptions.length;u=this.groupDescriptions[a-1].propertyName;l=this.groups.findIndex((function(t){return t.name==s[u]}));h=r.findIndex((function(t){return t.name==s[u]}));this._start+=l-h;this._getData()}}else for(c=0;c<this._data.length;c++)this._data[c]=new wijmo_1._NullValue(c);this._refresh=!1}e||(this._loadOffset=0);p=this._loadOffset+(this._start||0);for(c=0;c<t.length;c++)this._data[c+p]=t[c];this._loadOffset+=t.length;setTimeout((function(){_._firstLoad&&_.currentPosition<0&&t.length&&_.moveCurrentToFirst();_._firstLoad=!1}));return[2]}))}))};RestCollectionView.prototype._performSetWindow=function(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}t=wijmo_1.asInt(t);e=wijmo_1.asInt(e);wijmo_1.assert(t<=e,"start must be <= end.");var r=t<this._start,i=this._data;this._start=this._end=t;for(var o=t;o<=e&&o<i.length;o++)if(i[o]instanceof wijmo_1._NullValue){this._start=o;break}for(o=e;o>=this._start&&o<i.length;o--)if(i[o]instanceof wijmo_1._NullValue){this._end=o;break}if(this._start!=this._end||i[this._start]instanceof wijmo_1._NullValue){r&&(this._start=Math.max(0,this._end-this._fetchSize()+1));this._getData()}};RestCollectionView.prototype._fetchSize=function(){return Math.max(this._end-this._start+1,this.pageSize,_MIN_DATA_WINDOW)};RestCollectionView.prototype._raiseError=function(t,e){if(this.onError(new RESTErrorEventArgs(t))){e&&this._getData();throw"Server Error: "+t}};Object.defineProperty(RestCollectionView.prototype,"requestCanceled",{get:function(){this._requestCanceled||(this._requestCanceled=new wijmo_1.Event);return this._requestCanceled},enumerable:!0,configurable:!0});RestCollectionView.prototype.onRequestCanceled=function(t){this.requestCanceled.raise(this,t)};RestCollectionView.prototype.getGroupItems=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.getItems=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.addItem=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.patchItem=function(t){throw"This method is virtual: it should be overridden"};RestCollectionView.prototype.deleteItem=function(t){throw"This method is virtual: it should be overridden"};return RestCollectionView}(wijmo_1.CollectionView);exports.RestCollectionView=RestCollectionView;var RESTErrorEventArgs=function(t){__extends(RESTErrorEventArgs,t);function RESTErrorEventArgs(e){var r=t.call(this)||this;r._error=e;return r}Object.defineProperty(RESTErrorEventArgs.prototype,"error",{get:function(){return this._error},enumerable:!0,configurable:!0});return RESTErrorEventArgs}(wijmo_1.CancelEventArgs);exports.RESTErrorEventArgs=RESTErrorEventArgs;wijmo_1._registerModule("wijmo.rest",selfModule);
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@mescius/wijmo.rest",
|
3
|
-
"version": "5.20242.20-nightly.
|
3
|
+
"version": "5.20242.20-nightly.d20240826.t020151",
|
4
4
|
"description": "UI library for pure JS, Angular, React, Vue and more...",
|
5
5
|
"author": "MESCIUS inc",
|
6
6
|
"license": "Commercial",
|
7
7
|
"main": "./index.js",
|
8
8
|
"types": "./index.d.ts",
|
9
9
|
"dependencies": {
|
10
|
-
"@mescius/wijmo": "5.20242.20-nightly.
|
10
|
+
"@mescius/wijmo": "5.20242.20-nightly.d20240826.t020151"
|
11
11
|
},
|
12
12
|
"homepage": "https://developer.mescius.com/wijmo",
|
13
13
|
"bugs": {
|