@mescius/wijmo.rest 5.20242.20-nightly.d20240907.t020153 → 5.20242.20-nightly.d20240912.t020144
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 +20 -15
- 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.d20240912.t020144
|
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,r){return new(i||(i=Promise))((function(s,o){function fulfilled(t){try{step(r.next(t))}catch(t){o(t)}}function rejected(t){try{step(r.throw(t))}catch(t){o(t)}}function step(t){t.done?s(t.value):new i((function(e){e(t.value)})).then(fulfilled,rejected)}step((r=r.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,_overrideError=" method is virtual: it should be overridden";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 r=0;r<=t.level;r++){let t=this.groupDescriptions[r].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 r="",s=this._getFilterGroupItems(e);i!=wijmo_1.Aggregate.None&&s&&0!=s.length&&s.length!=this._groupItems.length&&s[0].aggregates&&s[0].aggregates.hasOwnProperty(t)&&(r=wijmo_1.getAggregate(i,s,`aggregates.${t}`));return r}}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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 r,s=[];if((this._groupRefresh||this._groupLazyLoading&&(!t||!t.isBottomLevel))&&this._groupOnServer&&i.length>0){s=yield this.getGroupItems(t);t?this._updateSubGroups(t,s):this._groupItems=s;this._groupRefresh=!1}this._groupLazyLoading||(r=yield this.getItems());this._groupLazyLoading&&t&&t.isBottomLevel&&(r=yield this.getItems(t));this.deferUpdate(()=>__awaiter(this,void 0,void 0,(function*(){this._virtualization||this._groupLazyLoading||(this._data=r);if(this._groupLazyLoading&&!this._virtualization)if(t)this._loadSubGroupsData(t,s,r);else{this._data=new Array;const e=i[0].propertyName;for(let t=0;t<s.length;t++){let i=new Object,r=s[t].count;i[e]=s[t].groupKey[e];for(let t=0;t<r;t++)this._data.push(i)}this._expandedGroups.length>0&&(yield this._loadExpandedGroups(t))}this._virtualization&&!this._groupLazyLoading&&this._storeItems(r,!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 r=this.groupDescriptions,s=this._data;for(let e=0;e<=(t.isBottomLevel?r.length-1:t.level);e++){const i=r[e].propertyName,o=t.items[e][i];s=s.filter(t=>t[i]===o)}let o=this._data.indexOf(s[0]);s=JSON.parse(JSON.stringify(s));if(t.isBottomLevel)for(let t=0;t<i.length;t++)Object.assign(s[t],i[t]);else{let i=t.groups[0].groupDescription.propertyName,r=0;for(let t=0;t<e.length;t++){r+=t>0?e[t-1].count:0;for(let o=0;o<e[t].count;o++)s[r+o][i]=e[t].groupKey[i]}}this._data.splice(o,s.length,...s)}_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&&this._refresh;t++){let i=Object.keys(this._groupItems[t].groupKey);for(let r=0;r<this._groupItems[t].count;r++){let r=new wijmo_1._NullValue(e);i.forEach(e=>{r[e]=this._groupItems[t].groupKey[e]});this._data[e]=r;e++}}if(0!=this.groups.length&&this.groups.length<t.length){let e=this._data[this._start],i=this.groupDescriptions.length,r=this.groupDescriptions[i-1].propertyName,s=this.groups.findIndex(t=>t.name==e[r]),o=t.findIndex(t=>t.name==e[r]);this._start+=s-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})}))}_isVirtualRefreshNeeded(t,e){t=wijmo_1.asInt(t);e=wijmo_1.asInt(e);wijmo_1.assert(t<=e,"start must be <= end.");let i=this._data;this._start=this._end=t;for(let r=t;r<=e&&r<i.length;r++)if(i[r]instanceof wijmo_1._NullValue){this._start=r;break}for(let t=e;t>=this._start&&t<i.length;t--)if(i[t]instanceof wijmo_1._NullValue){this._end=t;break}return this._start!=this._end||i[this._start]instanceof wijmo_1._NullValue}_performSetWindow(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}let i=t<this._start;if(this._isVirtualRefreshNeeded(t,e)){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"The getGroupItems"+_overrideError}getItems(t){throw"The getItems"+_overrideError}addItem(t){throw"The addItem"+_overrideError}patchItem(t){throw"The patchItem"+_overrideError}deleteItem(t){throw"The deleteItem"+_overrideError}}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,r){return new(i||(i=Promise))((function(s,o){function fulfilled(t){try{step(r.next(t))}catch(t){o(t)}}function rejected(t){try{step(r.throw(t))}catch(t){o(t)}}function step(t){t.done?s(t.value):new i((function(e){e(t.value)})).then(fulfilled,rejected)}step((r=r.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,_overrideError=" method is virtual: it should be overridden";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=!1;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 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 r=0;r<=t.level;r++){let t=this.groupDescriptions[r].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 r="",s=this._getFilterGroupItems(e);i!=wijmo_1.Aggregate.None&&s&&0!=s.length&&s.length!=this._groupItems.length&&s[0].aggregates&&s[0].aggregates.hasOwnProperty(t)&&(r=wijmo_1.getAggregate(i,s,`aggregates.${t}`));return r}}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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 r,s=[];if((this._groupRefresh||this._groupLazyLoading&&(!t||!t.isBottomLevel))&&this._groupOnServer&&i.length>0){s=yield this.getGroupItems(t);t?this._updateSubGroups(t,s):this._groupItems=s;this._groupRefresh=!1}this._groupLazyLoading||(r=yield this.getItems());this._groupLazyLoading&&t&&t.isBottomLevel&&(r=yield this.getItems(t));this.deferUpdate(()=>__awaiter(this,void 0,void 0,(function*(){this._virtualization||this._groupLazyLoading||(this._data=r);if(this._groupLazyLoading&&!this._virtualization)if(t)this._loadSubGroupsData(t,s,r);else{this._data=new Array;const e=i[0].propertyName;for(let t=0;t<s.length;t++){let i=new Object,r=s[t].count;i[e]=s[t].groupKey[e];for(let t=0;t<r;t++)this._data.push(i)}this._expandedGroups.length>0&&(yield this._loadExpandedGroups(t))}this._virtualization&&!this._groupLazyLoading&&this._storeItems(r,!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 r=this.groupDescriptions,s=this._data;for(let e=0;e<=(t.isBottomLevel?r.length-1:t.level);e++){const i=r[e].propertyName,o=t.items[e][i];s=s.filter(t=>t[i]===o)}let o=this._data.indexOf(s[0]);s=JSON.parse(JSON.stringify(s));if(t.isBottomLevel)for(let t=0;t<i.length;t++)Object.assign(s[t],i[t]);else{let i=t.groups[0].groupDescription.propertyName,r=0;for(let t=0;t<e.length;t++){r+=t>0?e[t-1].count:0;for(let o=0;o<e[t].count;o++)s[r+o][i]=e[t].groupKey[i]}}this._data.splice(o,s.length,...s)}_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&&this._refresh;t++){let i=Object.keys(this._groupItems[t].groupKey);for(let r=0;r<this._groupItems[t].count;r++){let r=new wijmo_1._NullValue(e);i.forEach(e=>{r[e]=this._groupItems[t].groupKey[e]});this._data[e]=r;e++}}if(0!=this.groups.length&&this.groups.length<t.length){let e=this._data[this._start],i=this.groupDescriptions.length,r=this.groupDescriptions[i-1].propertyName,s=this.groups.findIndex(t=>t.name==e[r]),o=t.findIndex(t=>t.name==e[r]);this._start+=s-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})}))}_isVirtualRefreshNeeded(t,e){t=wijmo_1.asInt(t);e=wijmo_1.asInt(e);wijmo_1.assert(t<=e,"start must be <= end.");let i=this._data;this._start=this._end=t;for(let r=t;r<=e&&r<i.length;r++)if(i[r]instanceof wijmo_1._NullValue){this._start=r;break}for(let t=e;t>=this._start&&t<i.length;t--)if(i[t]instanceof wijmo_1._NullValue){this._end=t;break}return this._start!=this._end||i[this._start]instanceof wijmo_1._NullValue}_performSetWindow(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}let i=t<this._start;if(this._isVirtualRefreshNeeded(t,e)){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"The getGroupItems"+_overrideError}getItems(t){throw"The getItems"+_overrideError}addItem(t){throw"The addItem"+_overrideError}patchItem(t){throw"The patchItem"+_overrideError}deleteItem(t){throw"The deleteItem"+_overrideError}}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.d20240912.t020144
|
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,r,i){return new(r||(r=Promise))((function(s,o){function fulfilled(t){try{step(i.next(t))}catch(t){o(t)}}function rejected(t){try{step(i.throw(t))}catch(t){o(t)}}function step(t){t.done?s(t.value):new r((function(e){e(t.value)})).then(fulfilled,rejected)}step((i=i.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,_overrideError=" method is virtual: it should be overridden";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,r=t.items[0];for(let i=0;i<=t.level;i++){let t=this.groupDescriptions[i].propertyName;e=e.filter(e=>e.groupKey[t]==r[t])}return e}getGroupAggregate(t,e,r=Aggregate.Sum){if(this.groupOnServer&&(this.groupLazyLoading||this.virtualization||this.groupDescriptions.length>0&&this._groupItems.length>0)){let i="",s=this._getFilterGroupItems(e);r!=Aggregate.None&&s&&0!=s.length&&s.length!=this._groupItems.length&&s[0].aggregates&&s[0].aggregates.hasOwnProperty(t)&&(i=getAggregate(r,s,`aggregates.${t}`));return i}}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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 r=this.groupDescriptions;this._data||(this._data=[]);let i,s=[];if((this._groupRefresh||this._groupLazyLoading&&(!t||!t.isBottomLevel))&&this._groupOnServer&&r.length>0){s=yield this.getGroupItems(t);t?this._updateSubGroups(t,s):this._groupItems=s;this._groupRefresh=!1}this._groupLazyLoading||(i=yield this.getItems());this._groupLazyLoading&&t&&t.isBottomLevel&&(i=yield this.getItems(t));this.deferUpdate(()=>__awaiter(this,void 0,void 0,(function*(){this._virtualization||this._groupLazyLoading||(this._data=i);if(this._groupLazyLoading&&!this._virtualization)if(t)this._loadSubGroupsData(t,s,i);else{this._data=new Array;const e=r[0].propertyName;for(let t=0;t<s.length;t++){let r=new Object,i=s[t].count;r[e]=s[t].groupKey[e];for(let t=0;t<i;t++)this._data.push(r)}this._expandedGroups.length>0&&(yield this._loadExpandedGroups(t))}this._virtualization&&!this._groupLazyLoading&&this._storeItems(i,!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 r=this._getFilterGroupItems(t);if(1==r.length){for(let t=0;t<e.length;t++)e[t].groupKey=Object.assign({},r[0].groupKey,e[t].groupKey);let t=this._groupItems.indexOf(r[0]);this._groupItems.splice(t,1,...e)}else console.error("unable to find exact match for targetted group")}_loadSubGroupsData(t,e,r){let i=this.groupDescriptions,s=this._data;for(let e=0;e<=(t.isBottomLevel?i.length-1:t.level);e++){const r=i[e].propertyName,o=t.items[e][r];s=s.filter(t=>t[r]===o)}let o=this._data.indexOf(s[0]);s=JSON.parse(JSON.stringify(s));if(t.isBottomLevel)for(let t=0;t<r.length;t++)Object.assign(s[t],r[t]);else{let r=t.groups[0].groupDescription.propertyName,i=0;for(let t=0;t<e.length;t++){i+=t>0?e[t-1].count:0;for(let o=0;o<e[t].count;o++)s[i+o][r]=e[t].groupKey[r]}}this._data.splice(o,s.length,...s)}_updateExpandedGroups(t,e){if(!this._loading){let r=this._expandedGroups.filter(e=>e._path.indexOf(t._path)>-1);if(e)this._expandedGroups.push(t);else if(r.length>0)for(let t=0;t<r.length;t++)this._expandedGroups.splice(this._expandedGroups.indexOf(r[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&&this._refresh;t++){let r=Object.keys(this._groupItems[t].groupKey);for(let i=0;i<this._groupItems[t].count;i++){let i=new _NullValue(e);r.forEach(e=>{i[e]=this._groupItems[t].groupKey[e]});this._data[e]=i;e++}}if(0!=this.groups.length&&this.groups.length<t.length){let e=this._data[this._start],r=this.groupDescriptions.length,i=this.groupDescriptions[r-1].propertyName,s=this.groups.findIndex(t=>t.name==e[i]),o=t.findIndex(t=>t.name==e[i]);this._start+=s-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 r=this._loadOffset+(this._start||0);for(let e=0;e<t.length;e++)this._data[e+r]=t[e];this._loadOffset+=t.length;setTimeout(()=>{this._firstLoad&&this.currentPosition<0&&t.length&&this.moveCurrentToFirst();this._firstLoad=!1})}))}_isVirtualRefreshNeeded(t,e){t=asInt(t);e=asInt(e);assert(t<=e,"start must be <= end.");let r=this._data;this._start=this._end=t;for(let i=t;i<=e&&i<r.length;i++)if(r[i]instanceof _NullValue){this._start=i;break}for(let t=e;t>=this._start&&t<r.length;t--)if(r[t]instanceof _NullValue){this._end=t;break}return this._start!=this._end||r[this._start]instanceof _NullValue}_performSetWindow(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}let r=t<this._start;if(this._isVirtualRefreshNeeded(t,e)){r&&(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"The getGroupItems"+_overrideError}getItems(t){throw"The getItems"+_overrideError}addItem(t){throw"The addItem"+_overrideError}patchItem(t){throw"The patchItem"+_overrideError}deleteItem(t){throw"The deleteItem"+_overrideError}}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,r,i){return new(r||(r=Promise))((function(s,o){function fulfilled(t){try{step(i.next(t))}catch(t){o(t)}}function rejected(t){try{step(i.throw(t))}catch(t){o(t)}}function step(t){t.done?s(t.value):new r((function(e){e(t.value)})).then(fulfilled,rejected)}step((i=i.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,_overrideError=" method is virtual: it should be overridden";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=!1;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 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,r=t.items[0];for(let i=0;i<=t.level;i++){let t=this.groupDescriptions[i].propertyName;e=e.filter(e=>e.groupKey[t]==r[t])}return e}getGroupAggregate(t,e,r=Aggregate.Sum){if(this.groupOnServer&&(this.groupLazyLoading||this.virtualization||this.groupDescriptions.length>0&&this._groupItems.length>0)){let i="",s=this._getFilterGroupItems(e);r!=Aggregate.None&&s&&0!=s.length&&s.length!=this._groupItems.length&&s[0].aggregates&&s[0].aggregates.hasOwnProperty(t)&&(i=getAggregate(r,s,`aggregates.${t}`));return i}}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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){let e=t.indexOf(_overrideError)>-1;this._raiseError(t,!e)}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 r=this.groupDescriptions;this._data||(this._data=[]);let i,s=[];if((this._groupRefresh||this._groupLazyLoading&&(!t||!t.isBottomLevel))&&this._groupOnServer&&r.length>0){s=yield this.getGroupItems(t);t?this._updateSubGroups(t,s):this._groupItems=s;this._groupRefresh=!1}this._groupLazyLoading||(i=yield this.getItems());this._groupLazyLoading&&t&&t.isBottomLevel&&(i=yield this.getItems(t));this.deferUpdate(()=>__awaiter(this,void 0,void 0,(function*(){this._virtualization||this._groupLazyLoading||(this._data=i);if(this._groupLazyLoading&&!this._virtualization)if(t)this._loadSubGroupsData(t,s,i);else{this._data=new Array;const e=r[0].propertyName;for(let t=0;t<s.length;t++){let r=new Object,i=s[t].count;r[e]=s[t].groupKey[e];for(let t=0;t<i;t++)this._data.push(r)}this._expandedGroups.length>0&&(yield this._loadExpandedGroups(t))}this._virtualization&&!this._groupLazyLoading&&this._storeItems(i,!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 r=this._getFilterGroupItems(t);if(1==r.length){for(let t=0;t<e.length;t++)e[t].groupKey=Object.assign({},r[0].groupKey,e[t].groupKey);let t=this._groupItems.indexOf(r[0]);this._groupItems.splice(t,1,...e)}else console.error("unable to find exact match for targetted group")}_loadSubGroupsData(t,e,r){let i=this.groupDescriptions,s=this._data;for(let e=0;e<=(t.isBottomLevel?i.length-1:t.level);e++){const r=i[e].propertyName,o=t.items[e][r];s=s.filter(t=>t[r]===o)}let o=this._data.indexOf(s[0]);s=JSON.parse(JSON.stringify(s));if(t.isBottomLevel)for(let t=0;t<r.length;t++)Object.assign(s[t],r[t]);else{let r=t.groups[0].groupDescription.propertyName,i=0;for(let t=0;t<e.length;t++){i+=t>0?e[t-1].count:0;for(let o=0;o<e[t].count;o++)s[i+o][r]=e[t].groupKey[r]}}this._data.splice(o,s.length,...s)}_updateExpandedGroups(t,e){if(!this._loading){let r=this._expandedGroups.filter(e=>e._path.indexOf(t._path)>-1);if(e)this._expandedGroups.push(t);else if(r.length>0)for(let t=0;t<r.length;t++)this._expandedGroups.splice(this._expandedGroups.indexOf(r[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&&this._refresh;t++){let r=Object.keys(this._groupItems[t].groupKey);for(let i=0;i<this._groupItems[t].count;i++){let i=new _NullValue(e);r.forEach(e=>{i[e]=this._groupItems[t].groupKey[e]});this._data[e]=i;e++}}if(0!=this.groups.length&&this.groups.length<t.length){let e=this._data[this._start],r=this.groupDescriptions.length,i=this.groupDescriptions[r-1].propertyName,s=this.groups.findIndex(t=>t.name==e[i]),o=t.findIndex(t=>t.name==e[i]);this._start+=s-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 r=this._loadOffset+(this._start||0);for(let e=0;e<t.length;e++)this._data[e+r]=t[e];this._loadOffset+=t.length;setTimeout(()=>{this._firstLoad&&this.currentPosition<0&&t.length&&this.moveCurrentToFirst();this._firstLoad=!1})}))}_isVirtualRefreshNeeded(t,e){t=asInt(t);e=asInt(e);assert(t<=e,"start must be <= end.");let r=this._data;this._start=this._end=t;for(let i=t;i<=e&&i<r.length;i++)if(r[i]instanceof _NullValue){this._start=i;break}for(let t=e;t>=this._start&&t<r.length;t--)if(r[t]instanceof _NullValue){this._end=t;break}return this._start!=this._end||r[this._start]instanceof _NullValue}_performSetWindow(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}let r=t<this._start;if(this._isVirtualRefreshNeeded(t,e)){r&&(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"The getGroupItems"+_overrideError}getItems(t){throw"The getItems"+_overrideError}addItem(t){throw"The addItem"+_overrideError}patchItem(t){throw"The patchItem"+_overrideError}deleteItem(t){throw"The deleteItem"+_overrideError}}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.d20240912.t020144
|
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,_overrideError=" method is virtual: it should be overridden",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);r!=Aggregate.None&&o&&0!=o.length&&o.length!=this._groupItems.length&&o[0].aggregates&&o[0].aggregates.hasOwnProperty(t)&&(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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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);return[2]}}))}))}));this.sourceCollection=this._data;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&&this._refresh;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._isVirtualRefreshNeeded=function(t,e){t=asInt(t);e=asInt(e);assert(t<=e,"start must be <= end.");var r=this._data;this._start=this._end=t;for(var i=t;i<=e&&i<r.length;i++)if(r[i]instanceof _NullValue){this._start=i;break}for(i=e;i>=this._start&&i<r.length;i--)if(r[i]instanceof _NullValue){this._end=i;break}return this._start!=this._end||r[this._start]instanceof _NullValue};RestCollectionView.prototype._performSetWindow=function(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}var r=t<this._start;if(this._isVirtualRefreshNeeded(t,e)){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"The getGroupItems"+_overrideError};RestCollectionView.prototype.getItems=function(t){throw"The getItems"+_overrideError};RestCollectionView.prototype.addItem=function(t){throw"The addItem"+_overrideError};RestCollectionView.prototype.patchItem=function(t){throw"The patchItem"+_overrideError};RestCollectionView.prototype.deleteItem=function(t){throw"The deleteItem"+_overrideError};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,_overrideError=" method is virtual: it should be overridden",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=!1;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,"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);r!=Aggregate.None&&o&&0!=o.length&&o.length!=this._groupItems.length&&o[0].aggregates&&o[0].aggregates.hasOwnProperty(t)&&(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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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);return[2]}}))}))}));this.sourceCollection=this._data;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&&this._refresh;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._isVirtualRefreshNeeded=function(t,e){t=asInt(t);e=asInt(e);assert(t<=e,"start must be <= end.");var r=this._data;this._start=this._end=t;for(var i=t;i<=e&&i<r.length;i++)if(r[i]instanceof _NullValue){this._start=i;break}for(i=e;i>=this._start&&i<r.length;i--)if(r[i]instanceof _NullValue){this._end=i;break}return this._start!=this._end||r[this._start]instanceof _NullValue};RestCollectionView.prototype._performSetWindow=function(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}var r=t<this._start;if(this._isVirtualRefreshNeeded(t,e)){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"The getGroupItems"+_overrideError};RestCollectionView.prototype.getItems=function(t){throw"The getItems"+_overrideError};RestCollectionView.prototype.addItem=function(t){throw"The addItem"+_overrideError};RestCollectionView.prototype.patchItem=function(t){throw"The patchItem"+_overrideError};RestCollectionView.prototype.deleteItem=function(t){throw"The deleteItem"+_overrideError};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
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
*
|
3
|
-
* Wijmo Library 5.20242.20-nightly.
|
3
|
+
* Wijmo Library 5.20242.20-nightly.d20240912.t020144
|
4
4
|
* https://developer.mescius.com/wijmo
|
5
5
|
*
|
6
6
|
* Copyright(c) MESCIUS inc. All rights reserved.
|
@@ -41,11 +41,13 @@ import { CollectionView, Event, EventArgs, CancelEventArgs, PageChangingEventArg
|
|
41
41
|
* <li><b>deleteItem</b>: Deletes an item fom the collection on the server.</li>
|
42
42
|
* </ul>
|
43
43
|
*
|
44
|
-
* By default, the class should perform
|
44
|
+
* By default, the class should perform sorting, filtering, and paging on the server.
|
45
45
|
*
|
46
46
|
* If the REST service does not support any of these operations, make sure the
|
47
|
-
* **
|
47
|
+
* **sortOnServer**, **pageOnServer**, or **filterOnServer** properties are set
|
48
48
|
* to **false**, and the corresponding operations will be performed on the client instead.
|
49
|
+
*
|
50
|
+
* The default value for **groupOnServer** property is false and should be set to true if the server-based grouping is required.
|
49
51
|
*/
|
50
52
|
export declare class RestCollectionView extends CollectionView {
|
51
53
|
_toGetData: any;
|
@@ -76,28 +78,30 @@ export declare class RestCollectionView extends CollectionView {
|
|
76
78
|
_refresh: boolean;
|
77
79
|
_requestCanceled: Event<RestCollectionView, EventArgs>;
|
78
80
|
/**
|
79
|
-
* Initializes a new instance of the @see:
|
81
|
+
* Initializes a new instance of the @see:RestCollectionView class.
|
80
82
|
*
|
81
83
|
* @param options JavaScript object containing initialization data (property
|
82
|
-
* values and event handlers) for the @see:
|
84
|
+
* values and event handlers) for the @see:RestCollectionView.
|
83
85
|
*/
|
84
86
|
constructor(options?: any);
|
85
|
-
/**
|
86
|
-
* Gets the total number of group items in the view.
|
87
|
-
*/
|
88
|
-
readonly totalGroupItemCount: number;
|
89
87
|
/**
|
90
88
|
* Gets or sets a value that determines whether grouping should be performed on
|
91
89
|
* the server or on the client.
|
90
|
+
*
|
91
|
+
* The default value for this property is false and should be enabled only when the Server API supports grouping.
|
92
92
|
*/
|
93
93
|
groupOnServer: boolean;
|
94
94
|
/**
|
95
95
|
* Gets or Sets a value that detemines whether the group data should be loaded
|
96
|
-
* on demand or at once
|
96
|
+
* on demand or at once.
|
97
|
+
*
|
98
|
+
* The default value for this property is false and should be set to true only when {@link:groupOnServer} is set to true.
|
97
99
|
*/
|
98
100
|
groupLazyLoading: boolean;
|
99
101
|
/**
|
100
|
-
* Gets or Set a value that determines whether the data should be loaded virtually or not
|
102
|
+
* Gets or Set a value that determines whether the data should be loaded virtually or not.
|
103
|
+
*
|
104
|
+
* The default value for this property is false and should be set to true only when {@link:groupOnServer} is set to true.
|
101
105
|
*/
|
102
106
|
virtualization: boolean;
|
103
107
|
/**
|
@@ -153,13 +157,13 @@ export declare class RestCollectionView extends CollectionView {
|
|
153
157
|
* ```typescript
|
154
158
|
* // instance of RestCollectionView / derived class from RestCollectionView
|
155
159
|
* let cv = new RestCollectionView({
|
156
|
-
* groupOnServer:true,
|
160
|
+
* groupOnServer: true,
|
157
161
|
* aggregates: `Sum(actualCost) as actualCost,Sum(quantity) as quantity`,
|
158
162
|
* groupDescriptions: [
|
159
|
-
*
|
163
|
+
* // group description to add groups
|
160
164
|
* new PropertyGroupDescription('productName'),
|
161
165
|
* new PropertyGroupDescription('transactionType')
|
162
|
-
*
|
166
|
+
* ]
|
163
167
|
* });
|
164
168
|
* ```
|
165
169
|
*/
|
@@ -174,7 +178,8 @@ export declare class RestCollectionView extends CollectionView {
|
|
174
178
|
updateFilterDefinition(filterProvider: any): void;
|
175
179
|
/**
|
176
180
|
* This method would allow to load the items for specified group {@link CollectionViewGroup} when {@link groupLazyLoading} is enabled.
|
177
|
-
* @param item {@link CollectionViewGroup} items to load the data
|
181
|
+
* @param item {@link CollectionViewGroup} items to load the data.
|
182
|
+
*
|
178
183
|
*/
|
179
184
|
lazyLoadGroup(item: CollectionViewGroup): void;
|
180
185
|
/**
|
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.d20240912.t020144
|
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,_overrideError=" method is virtual: it should be overridden",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);r!=wijmo_1.Aggregate.None&&o&&0!=o.length&&o.length!=this._groupItems.length&&o[0].aggregates&&o[0].aggregates.hasOwnProperty(t)&&(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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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);return[2]}}))}))}));this.sourceCollection=this._data;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]=c._groupItems[t].groupKey[e]}));n._data[i]=o;i++},r=0;r<n._groupItems[t].count;r++)_loop_4()};n=this;for(_=0;_<this._groupItems.length&&this._refresh;_++)o(_);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(_=0;_<this._data.length;_++)this._data[_]=new wijmo_1._NullValue(_);this._refresh=!1}e||(this._loadOffset=0);p=this._loadOffset+(this._start||0);for(_=0;_<t.length;_++)this._data[_+p]=t[_];this._loadOffset+=t.length;setTimeout((function(){c._firstLoad&&c.currentPosition<0&&t.length&&c.moveCurrentToFirst();c._firstLoad=!1}));return[2]}))}))};RestCollectionView.prototype._isVirtualRefreshNeeded=function(t,e){t=wijmo_1.asInt(t);e=wijmo_1.asInt(e);wijmo_1.assert(t<=e,"start must be <= end.");var r=this._data;this._start=this._end=t;for(var i=t;i<=e&&i<r.length;i++)if(r[i]instanceof wijmo_1._NullValue){this._start=i;break}for(i=e;i>=this._start&&i<r.length;i--)if(r[i]instanceof wijmo_1._NullValue){this._end=i;break}return this._start!=this._end||r[this._start]instanceof wijmo_1._NullValue};RestCollectionView.prototype._performSetWindow=function(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}var r=t<this._start;if(this._isVirtualRefreshNeeded(t,e)){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"The getGroupItems"+_overrideError};RestCollectionView.prototype.getItems=function(t){throw"The getItems"+_overrideError};RestCollectionView.prototype.addItem=function(t){throw"The addItem"+_overrideError};RestCollectionView.prototype.patchItem=function(t){throw"The patchItem"+_overrideError};RestCollectionView.prototype.deleteItem=function(t){throw"The deleteItem"+_overrideError};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,_overrideError=" method is virtual: it should be overridden",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=!1;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,"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);r!=wijmo_1.Aggregate.None&&o&&0!=o.length&&o.length!=this._groupItems.length&&o[0].aggregates&&o[0].aggregates.hasOwnProperty(t)&&(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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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){var o=t.indexOf(_overrideError)>-1;this._raiseError(t,!o)}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);return[2]}}))}))}));this.sourceCollection=this._data;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]=c._groupItems[t].groupKey[e]}));n._data[i]=o;i++},r=0;r<n._groupItems[t].count;r++)_loop_4()};n=this;for(_=0;_<this._groupItems.length&&this._refresh;_++)o(_);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(_=0;_<this._data.length;_++)this._data[_]=new wijmo_1._NullValue(_);this._refresh=!1}e||(this._loadOffset=0);p=this._loadOffset+(this._start||0);for(_=0;_<t.length;_++)this._data[_+p]=t[_];this._loadOffset+=t.length;setTimeout((function(){c._firstLoad&&c.currentPosition<0&&t.length&&c.moveCurrentToFirst();c._firstLoad=!1}));return[2]}))}))};RestCollectionView.prototype._isVirtualRefreshNeeded=function(t,e){t=wijmo_1.asInt(t);e=wijmo_1.asInt(e);wijmo_1.assert(t<=e,"start must be <= end.");var r=this._data;this._start=this._end=t;for(var i=t;i<=e&&i<r.length;i++)if(r[i]instanceof wijmo_1._NullValue){this._start=i;break}for(i=e;i>=this._start&&i<r.length;i--)if(r[i]instanceof wijmo_1._NullValue){this._end=i;break}return this._start!=this._end||r[this._start]instanceof wijmo_1._NullValue};RestCollectionView.prototype._performSetWindow=function(t,e){if(this._pendingReq){this._pendingReq.abort();this._pendingReq=null;this.onRequestCanceled()}var r=t<this._start;if(this._isVirtualRefreshNeeded(t,e)){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"The getGroupItems"+_overrideError};RestCollectionView.prototype.getItems=function(t){throw"The getItems"+_overrideError};RestCollectionView.prototype.addItem=function(t){throw"The addItem"+_overrideError};RestCollectionView.prototype.patchItem=function(t){throw"The patchItem"+_overrideError};RestCollectionView.prototype.deleteItem=function(t){throw"The deleteItem"+_overrideError};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.d20240912.t020144",
|
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.d20240912.t020144"
|
11
11
|
},
|
12
12
|
"homepage": "https://developer.mescius.com/wijmo",
|
13
13
|
"bugs": {
|