@@ -21,59 +21,76 @@ import pick from '../utilities/pick.js';
2121export class DataExportModel extends Observable {
2222 /**
2323 * Constructor
24- * @param {ObservableData<RemoteData<object []>> } items$ observable data used as source for export
25- * @param {function } onNoDataAction
24+ * @param {ObservableData<RemoteData<T []>> } items$ observable data used as source for export
25+ * @param {function } onDataNotAskedAction
2626 */
27- constructor ( items$ , onNoDataAction ) {
27+ constructor ( items$ , onDataNotAskedAction ) {
2828 super ( ) ;
2929
30- /** @type {ObservableData<RemoteData<object[]>> } */
3130 this . _items$ = items$ ;
3231 this . _items$ . bubbleTo ( this ) ;
3332
34- /** @type {string[] } */
3533 this . _selectedFields = [ ] ;
3634
37- /** @type {string } */
3835 this . _selectedExportType = 'JSON' ;
3936
40- /** @type {Observable } */
4137 this . _visualChange$ = new Observable ( ) ;
4238
4339 this . _exportName = 'data' ;
4440
4541 this . columnFormats = null ;
46- this . _onNoDataAction = onNoDataAction ;
42+ this . _onDataNotAskedAction = onDataNotAskedAction ;
4743
4844 this . _disabled = null ;
4945
5046 this . _totalExistingItemsCount = null ;
5147 }
5248
49+ /**
50+ * Get total number of items that model knows they exist
51+ * @return {number } totalExistingItemsCount
52+ */
5353 get totalExistingItemsCount ( ) {
5454 return this . _totalExistingItemsCount ;
5555 }
5656
57+ /**
58+ * Set total number of items that model should they exist
59+ * @param {number } totalExistingItemsCount count
60+ */
5761 setTotalExistingItemsCount ( totalExistingItemsCount ) {
5862 this . _totalExistingItemsCount = totalExistingItemsCount ;
5963 }
6064
65+ /**
66+ * State whether exporting is enabled
67+ * @return {boolean } if true disabled, otherwise enabled
68+ */
6169 get disabled ( ) {
6270 return this . _disabled ;
6371 }
6472
65- setDisabled ( value ) {
66- this . _disabled = value ;
73+ /**
74+ * Set whether exporting is enabled
75+ * @param {boolean } disabled if true disabled, otherwise enabled
76+ */
77+ setDisabled ( disabled ) {
78+ this . _disabled = disabled ;
6779 }
6880
6981 /**
70- *
82+ * If the model has no data to be exported, it calls for it via action function provided in constructor
83+ * @return {Promise<void>|null } promise if data were not asked for, null otherwise
7184 */
72- askForData ( ) {
73- this . items . match ( {
74- NotAsked : ( ) => this . _onNoDataAction ( ) ,
75- Other : ( ) => null ,
76- } ) ;
85+ callForData ( ) {
86+ if ( this . _onDataNotAskedAction ) {
87+ return this . items . match ( {
88+ NotAsked : ( ) => this . _onDataNotAskedAction ( ) ,
89+ Other : ( ) => null ,
90+ } ) ;
91+ } else {
92+ throw new Error ( 'onDataNotAskedAction was not provided' ) ;
93+ }
7794 }
7895
7996 /**
0 commit comments