@@ -56,8 +56,19 @@ export class OverviewPageModel extends Observable {
5656 this . _dataSource = new PaginatedRemoteDataSource ( ) ;
5757 this . _dataSource . pipe ( dataSourceObservable ) ;
5858
59- this . _observableItems = ObservableData . builder ( ) . initialValue ( RemoteData . loading ( ) ) . build ( ) ;
60- this . _observableItems . bubbleTo ( this ) ;
59+ this . _item$ = ObservableData . builder ( ) . initialValue ( RemoteData . loading ( ) ) . build ( ) ;
60+ this . _item$ . bubbleTo ( this ) ;
61+
62+ {
63+ const allDataSourceObservable = ObservableData . builder ( ) . initialValue ( RemoteData . loading ( ) ) . build ( ) ;
64+ allDataSourceObservable . observe ( ( ) => this . parseAllApiRemoteData ( allDataSourceObservable . getCurrent ( ) ) ) ;
65+
66+ this . _allDataSource = new PaginatedRemoteDataSource ( ) ;
67+ this . _allDataSource . pipe ( allDataSourceObservable ) ;
68+
69+ this . _allItems$ = ObservableData . builder ( ) . initialValue ( RemoteData . loading ( ) ) . build ( ) ;
70+ this . _allItems$ . bubbleTo ( this ) ;
71+ }
6172
6273 /**
6374 * @type {ObservableData<TableConfiguration> }
@@ -84,7 +95,7 @@ export class OverviewPageModel extends Observable {
8495 * @returns {void }
8596 */
8697 reset ( ) {
87- this . _observableItems . setCurrent ( RemoteData . notAsked ( ) ) ;
98+ this . _item$ . setCurrent ( RemoteData . notAsked ( ) ) ;
8899 this . _pagination . reset ( ) ;
89100 }
90101
@@ -102,8 +113,8 @@ export class OverviewPageModel extends Observable {
102113 const keepExisting = this . _pagination . currentPage > 1 && this . _pagination . isInfiniteScrollEnabled ;
103114
104115 remoteData . match ( {
105- NotAsked : ( ) => this . _observableItems . setCurrent ( RemoteData . notAsked ( ) ) ,
106- Loading : ( ) => this . _pagination . isInfiniteScrollEnabled ? null : this . _observableItems . setCurrent ( RemoteData . loading ( ) ) ,
116+ NotAsked : ( ) => this . _item$ . setCurrent ( RemoteData . notAsked ( ) ) ,
117+ Loading : ( ) => this . _pagination . isInfiniteScrollEnabled ? null : this . _item$ . setCurrent ( RemoteData . loading ( ) ) ,
107118 Success : ( { items, totalCount } ) => {
108119 const concatenateWith = keepExisting ? this . items . match ( {
109120 Success : ( payload ) => payload ,
@@ -112,9 +123,26 @@ export class OverviewPageModel extends Observable {
112123 Failure : ( ) => [ ] ,
113124 } ) : [ ] ;
114125 this . _pagination . itemsCount = totalCount ;
115- this . _observableItems . setCurrent ( RemoteData . success ( [ ...concatenateWith , ...this . processItems ( items ) ] ) ) ;
126+ this . _item$ . setCurrent ( RemoteData . success ( [ ...concatenateWith , ...this . processItems ( items ) ] ) ) ;
116127 } ,
117- Failure : ( error ) => this . _observableItems . setCurrent ( RemoteData . failure ( error ) ) ,
128+ Failure : ( error ) => this . _item$ . setCurrent ( RemoteData . failure ( error ) ) ,
129+ } ) ;
130+ }
131+
132+ /**
133+ * Parse the API remote data to extract the list of items
134+ *
135+ * @param {RemoteData<{items: T[], totalCount: number}, *> } remoteData the API remote data
136+ * @return {void }
137+ */
138+ parseAllApiRemoteData ( remoteData ) {
139+ remoteData . match ( {
140+ NotAsked : ( ) => this . _allItems$ . setCurrent ( RemoteData . notAsked ( ) ) ,
141+ Loading : ( ) => this . _allItems$ . setCurrent ( RemoteData . loading ( ) ) ,
142+ Success : ( { items } ) => {
143+ this . _allItems$ . setCurrent ( RemoteData . success ( this . processItems ( items ) ) ) ;
144+ } ,
145+ Failure : ( error ) => this . _allItems$ . setCurrent ( RemoteData . failure ( error ) ) ,
118146 } ) ;
119147 }
120148
@@ -130,14 +158,26 @@ export class OverviewPageModel extends Observable {
130158
131159 /**
132160 * Fetch all the relevant items from the API
161+ * it takes into account pagination parameters
133162 *
134163 * @return {Promise<void> } void
135164 */
136165 async load ( ) {
137166 const params = await this . getLoadParameters ( ) ;
167+ this . _allItems$ . setCurrent ( RemoteData . notAsked ( ) ) ;
138168 await this . _dataSource . fetch ( buildUrl ( this . getRootEndpoint ( ) , params ) ) ;
139169 }
140170
171+ /**
172+ * Fetch all the relevant items from the API
173+ * it does not take into account pagincation parameters
174+ *
175+ * @return {Promise<void> } void
176+ */
177+ async loadAll ( ) {
178+ await this . _allDataSource . fetch ( this . getRootEndpoint ( ) ) ;
179+ }
180+
141181 /**
142182 * Return the query params to use to get load the overview data
143183 *
@@ -163,7 +203,7 @@ export class OverviewPageModel extends Observable {
163203 * @return {RemoteData<T[]> } the items
164204 */
165205 get items ( ) {
166- return this . _observableItems . getCurrent ( ) ;
206+ return this . _item$ . getCurrent ( ) ;
167207 }
168208
169209 /**
@@ -200,4 +240,8 @@ export class OverviewPageModel extends Observable {
200240 get sortModel ( ) {
201241 return this . _sortModel ;
202242 }
243+
244+ hasAnyData ( ) {
245+ return this . _item$ . getCurrent ( ) . match ( { Success : ( { length = 0 } = { } ) => length > 0 , Other : ( ) => false } ) ;
246+ }
203247}
0 commit comments