1212 */
1313
1414import { buildUrl , RemoteData } from '/js/src/index.js' ;
15- import { createCSVExport , createJSONExport } from '../../../utilities/export.js' ;
1615import { TagFilterModel } from '../../../components/Filters/common/TagFilterModel.js' ;
1716import { debounce } from '../../../utilities/debounce.js' ;
1817import { DetectorsFilterModel } from '../../../components/Filters/RunsFilter/DetectorsFilterModel.js' ;
1918import { RunTypesFilterModel } from '../../../components/runTypes/RunTypesFilterModel.js' ;
2019import { EorReasonFilterModel } from '../../../components/Filters/RunsFilter/EorReasonFilterModel.js' ;
21- import pick from '../../../utilities/pick.js' ;
2220import { OverviewPageModel } from '../../../models/OverviewModel.js' ;
2321import { getRemoteDataSlice } from '../../../utilities/fetch/getRemoteDataSlice.js' ;
2422import { CombinationOperator } from '../../../components/Filters/common/CombinationOperatorChoiceModel.js' ;
@@ -35,6 +33,7 @@ import { RawTextFilterModel } from '../../../components/Filters/common/filters/R
3533import { RunDefinitionFilterModel } from '../../../components/Filters/RunsFilter/RunDefinitionFilterModel.js' ;
3634import { RUN_QUALITIES } from '../../../domain/enums/RunQualities.js' ;
3735import { SelectionFilterModel } from '../../../components/Filters/common/filters/SelectionFilterModel.js' ;
36+ import { DataExportModel } from '../../../models/DataExportModel.js' ;
3837
3938/**
4039 * Model representing handlers for runs page
@@ -100,10 +99,21 @@ export class RunsOverviewModel extends OverviewPageModel {
10099 const updateDebounceTime = ( ) => {
101100 this . _debouncedLoad = debounce ( this . load . bind ( this ) , model . inputDebounceTime ) ;
102101 } ;
102+
103+ this . _exportModel = new DataExportModel ( this . _observableItems ) ;
104+
103105 model . appConfiguration$ . observe ( ( ) => updateDebounceTime ( ) ) ;
104106 updateDebounceTime ( ) ;
105107 }
106108
109+ /**
110+ * Get export model
111+ * @return {DataExportModel } export model
112+ */
113+ get exportModel ( ) {
114+ return this . _exportModel ;
115+ }
116+
107117 /**
108118 * @inheritdoc
109119 */
@@ -119,55 +129,6 @@ export class RunsOverviewModel extends OverviewPageModel {
119129 super . load ( ) ;
120130 }
121131
122- /**
123- * Create the export with the variables set in the model, handling errors appropriately
124- * @param {object[] } runs The source content.
125- * @param {string } fileName The name of the file including the output format.
126- * @param {Object<string, Function<*, string>> } exportFormats defines how particular fields of data units will be formated
127- * @return {void }
128- */
129- async createRunsExport ( runs , fileName , exportFormats ) {
130- if ( runs . length > 0 ) {
131- const selectedRunsFields = this . getSelectedRunsFields ( ) || [ ] ;
132- runs = runs . map ( ( selectedRun ) => {
133- const entries = Object . entries ( pick ( selectedRun , selectedRunsFields ) ) ;
134- const formattedEntries = entries . map ( ( [ key , value ] ) => {
135- const formatExport = exportFormats [ key ] . exportFormat || ( ( identity ) => identity ) ;
136- return [ key , formatExport ( value , selectedRun ) ] ;
137- } ) ;
138- return Object . fromEntries ( formattedEntries ) ;
139- } ) ;
140- this . getSelectedExportType ( ) === 'CSV'
141- ? createCSVExport ( runs , `${ fileName } .csv` , 'text/csv;charset=utf-8;' )
142- : createJSONExport ( runs , `${ fileName } .json` , 'application/json' ) ;
143- } else {
144- this . _observableItems . setCurrent ( RemoteData . failure ( [
145- {
146- title : 'No data found' ,
147- detail : 'No valid runs were found for provided run number(s)' ,
148- } ,
149- ] ) ) ;
150- this . notify ( ) ;
151- }
152- }
153-
154- /**
155- * Get the field values that will be exported
156- * @return {Array } the field objects of the current export being created
157- */
158- getSelectedRunsFields ( ) {
159- return this . selectedRunsFields ;
160- }
161-
162- /**
163- * Get the output format of the export
164- *
165- * @return {string } the output format
166- */
167- getSelectedExportType ( ) {
168- return this . selectedExportType ;
169- }
170-
171132 /**
172133 * Returns all filtering, sorting and pagination settings to their default values
173134 * @param {boolean } [fetch = true] whether to refetch all data after filters have been reset
@@ -220,29 +181,6 @@ export class RunsOverviewModel extends OverviewPageModel {
220181 return this . _filteringModel ;
221182 }
222183
223- /**
224- * Set the export type parameter of the current export being created
225- * @param {string } selectedExportType Received string from the view
226- * @return {void }
227- */
228- setSelectedExportType ( selectedExportType ) {
229- this . selectedExportType = selectedExportType ;
230- this . notify ( ) ;
231- }
232-
233- /**
234- * Updates the selected fields ID array according to the HTML attributes of the options
235- *
236- * @param {HTMLCollection } selectedOptions The currently selected fields by the user,
237- * according to HTML specification
238- * @return {undefined }
239- */
240- setSelectedRunsFields ( selectedOptions ) {
241- this . selectedRunsFields = [ ] ;
242- [ ...selectedOptions ] . map ( ( selectedOption ) => this . selectedRunsFields . push ( selectedOption . value ) ) ;
243- this . notify ( ) ;
244- }
245-
246184 /**
247185 * Getter for the trigger values filter Set
248186 * @return {Set } set of trigger filter values
0 commit comments