@@ -15,17 +15,30 @@ import { Observable } from '/js/src/index.js';
1515import { createCSVExport , createJSONExport } from '../utilities/export.js' ;
1616import pick from '../utilities/pick.js' ;
1717
18+ /**
19+ * @typedef FieldExportConfiguration
20+ *
21+ * @property {function|null } exportFormat
22+ */
23+
24+ /**
25+ * @typdef DataExportConfiguration
26+ *
27+ * @type {object<string, FieldExportConfiguration> } mapping: field name -> field export configuration
28+ */
29+
1830/**
1931 * Model handling export configuration and creation
2032 */
2133export class DataExportModel extends Observable {
2234 /**
2335 * Constructor
36+ *
2437 * @param {ObservableData<RemoteData<T[]>> } items$ observable data used as source for export
25- * @param {object<string, {exportFormat: function|null|undefined}> } fieldsFormatting defines selectable fields and their formatting
38+ * @param {DataExportConfiguration } dataExportConfiguration defines selectable fields and their formatting
2639 * @param {function } onDataNotAskedAction function to be called in case of missing data
2740 */
28- constructor ( items$ , fieldsFormatting , onDataNotAskedAction ) {
41+ constructor ( items$ , dataExportConfiguration , onDataNotAskedAction ) {
2942 super ( ) ;
3043
3144 this . _items$ = items$ ;
@@ -39,7 +52,7 @@ export class DataExportModel extends Observable {
3952
4053 this . _exportName = 'data' ;
4154
42- this . _fieldsFormatting = fieldsFormatting ;
55+ this . _dataExportConfiguration = dataExportConfiguration ;
4356 this . _onDataNotAskedAction = onDataNotAskedAction ;
4457
4558 this . _disabled = null ;
@@ -48,15 +61,17 @@ export class DataExportModel extends Observable {
4861 }
4962
5063 /**
51- * Get mapping of selecteble fields to their format functions
52- * @return {object<string, {exportFormat: function|null|undefined}> } mapping
64+ * Get data export configuration
65+ *
66+ * @return {DataExportConfiguration> } configuration
5367 */
54- get fieldsFormatting ( ) {
55- return this . _fieldsFormatting ;
68+ get dataExportConfiguration ( ) {
69+ return this . _dataExportConfiguration ;
5670 }
5771
5872 /**
5973 * Get total number of items that model knows they exist
74+ *
6075 * @return {number } totalExistingItemsCount
6176 */
6277 get totalExistingItemsCount ( ) {
@@ -113,6 +128,7 @@ export class DataExportModel extends Observable {
113128
114129 /**
115130 * Observable notified when the export configuration visually changes
131+ *
116132 * @return {Observable } the visual change observable
117133 */
118134 get visualChange$ ( ) {
@@ -121,6 +137,7 @@ export class DataExportModel extends Observable {
121137
122138 /**
123139 * Get export type selected by the user
140+ *
124141 * @return {string } export type
125142 */
126143 get selectedExportType ( ) {
@@ -129,6 +146,7 @@ export class DataExportModel extends Observable {
129146
130147 /**
131148 * Set export type
149+ *
132150 * @param {string } exportType export type
133151 * @return {void }
134152 */
@@ -140,6 +158,7 @@ export class DataExportModel extends Observable {
140158
141159 /**
142160 * Get selected fields
161+ *
143162 * @return {string[] } selected fields
144163 */
145164 get selectedFields ( ) {
@@ -148,6 +167,7 @@ export class DataExportModel extends Observable {
148167
149168 /**
150169 * Update selected fields from HTML options list
170+ *
151171 * @param {HTMLCollection|Array } selectedOptions options collection
152172 * @return {void }
153173 */
@@ -160,6 +180,7 @@ export class DataExportModel extends Observable {
160180
161181 /**
162182 * Create export using current items observable
183+ *
163184 * @return {Promise<void> } void
164185 */
165186 async createExport ( ) {
@@ -170,7 +191,7 @@ export class DataExportModel extends Observable {
170191 const formatted = items . map ( ( item ) => {
171192 const selectedEntries = Object . entries ( pick ( item , selectedFields ) ) ;
172193 const mappedEntries = selectedEntries . map ( ( [ key , value ] ) => {
173- const formatter = this . fieldsFormatting [ key ] ?. exportFormat || ( ( v ) => v ) ;
194+ const formatter = this . dataExportConfiguration [ key ] ?. exportFormat || ( ( v ) => v ) ;
174195 return [ key , formatter ( value , item ) ] ;
175196 } ) ;
176197
0 commit comments