diff --git a/public/js/components/Fetch.js b/public/js/components/Fetch.js index ce09b4efd..32d5616d0 100644 --- a/public/js/components/Fetch.js +++ b/public/js/components/Fetch.js @@ -65,9 +65,9 @@ export const CoreFetchCmpt = { if (apiFunctionResult instanceof Promise) { apiFunctionResult - .then(this.success) // on success - .catch(this.error) // on error - .then(this.finally); // finally in any case + .then(this.successHandler) // on success + .catch(this.errorHandler) // on error + .finally(this.finallyHandler); // finally in any case } else // otherwise display an error { @@ -90,19 +90,19 @@ export const CoreFetchCmpt = { /** * */ - success: function(response) { + successHandler: function(response) { this.$emit('dataFetched', response.data); // trigger the event dataFetched }, /** * */ - error: function(error) { + errorHandler: function(error) { this.setError(error.message); }, /** * */ - finally: function() { + finallyHandler: function() { this.loading = false; // loading ended } }, diff --git a/public/js/components/filter/Filter.js b/public/js/components/filter/Filter.js index d6a4d70fd..b67941075 100644 --- a/public/js/components/filter/Filter.js +++ b/public/js/components/filter/Filter.js @@ -37,12 +37,8 @@ export const CoreFilterCmpt = { }, data: function() { return { - // Tabulator - tabulator: null, - // FilterCmpt properties fields: null, - fieldsToDisplay: null, dataset: null, datasetMetadata: null, selectedFields: null, @@ -63,55 +59,50 @@ export const CoreFilterCmpt = { updated: function() { // let dataset = JSON.parse(JSON.stringify(this.dataset)); - let datasetMetadata = JSON.parse(JSON.stringify(this.datasetMetadata)); - let fieldsToDisplay = JSON.parse(JSON.stringify(this.fieldsToDisplay)); + let fields = JSON.parse(JSON.stringify(this.fields)); let selectedFields = JSON.parse(JSON.stringify(this.selectedFields)); // let columns = null; - // + // If the tabulator options has been provided and it contains the property columns if (this.tabulatorOptions != null && this.tabulatorOptions.hasOwnProperty('columns')) { columns = this.tabulatorOptions.columns; } - // If columns is not valid - if (!Array.isArray(columns) || (Array.isArray(columns) && columns.length < datasetMetadata.length)) + // If columns is not an array or it is an array with less elements then the array fields + if (!Array.isArray(columns) || (Array.isArray(columns) && columns.length < fields.length)) { - columns = []; // + columns = []; // set it as an empty array - // - for (let i = 0; i < datasetMetadata.length; i++) + // Loop throught all the retrieved columns from database + for (let i = 0; i < fields.length; i++) { - // - if (fieldsToDisplay.indexOf(datasetMetadata[i].name) != -1) - { - // - columns[i] = { - title: datasetMetadata[i].name, - field: datasetMetadata[i].name - }; - } + // Create a new column having the title equal to the field name + let column = { + title: fields[i], + field: fields[i] + }; + + // If the column has to be displayed or not + selectedFields.indexOf(fields[i]) >= 0 ? column.visible = true : column.visible = false; + + // Add the new column to the list of columns + columns.push(column); } } - else // + else // the property columns has been provided in the tabulator options { - let tmpColumns = []; - - // + // Loop throught the property columns of the tabulator options for (let i = 0; i < columns.length; i++) { - if (selectedFields.indexOf(columns[i].field) != -1) - { - tmpColumns.push(columns[i]); - } + // If the column has to be displayed or not + selectedFields.indexOf(columns[i].field) >= 0 ? columns[i].visible = true : columns[i].visible = false; } - - columns = tmpColumns; } - // + // Define a default tabulator options in case it was not provided let tabulatorOptions = { height: 500, layout: "fitColumns", @@ -120,29 +111,30 @@ export const CoreFilterCmpt = { reactiveData: true }; - // + // If it was provided if (this.tabulatorOptions != null) { + // Then copy it... tabulatorOptions = this.tabulatorOptions; + // ...and overwrite the properties data, reactiveData and columns tabulatorOptions.data = JSON.parse(JSON.stringify(this.dataset)); tabulatorOptions.reactiveData = true; tabulatorOptions.columns = columns; } - // - this.tabulator = new Tabulator( + // Start the tabulator with the buid options + let tabulator = new Tabulator( "#filterTableDataset", tabulatorOptions ); - // + // If event handlers have been provided if (Array.isArray(this.tabulatorEvents) && this.tabulatorEvents.length > 0) { - // + // Attach all the provided event handlers to the started tabulator for (let i = 0; i < this.tabulatorEvents.length; i++) { - // - this.tabulator.on(this.tabulatorEvents[i].event, this.tabulatorEvents[i].handler); + tabulator.on(this.tabulatorEvents[i].event, this.tabulatorEvents[i].handler); } } }, @@ -187,7 +179,6 @@ export const CoreFilterCmpt = { } this.notFilterFields = this.fields.filter(x => tmpFilterFields.indexOf(x) === -1); - this.setFieldsToDisplay(data); this.setSideMenu(data); } else @@ -195,36 +186,6 @@ export const CoreFilterCmpt = { console.error(CoreRESTClient.getError(response)); } }, - /** - * - */ - setFieldsToDisplay: function(data) { - - let arrayFieldsToDisplay = []; - - if (data.hasOwnProperty("selectedFields") && Array.isArray(data.selectedFields)) - { - if (data.hasOwnProperty("columnsAliases") && Array.isArray(data.columnsAliases)) - { - for (let sfc = 0; sfc< data.selectedFields.length; sfc++) - { - for (let fc = 0; fc< data.fields.length; fc++) - { - if (data.selectedFields[sfc] == data.fields[fc]) - { - arrayFieldsToDisplay[sfc] = data.columnsAliases[fc]; - } - } - } - } - else - { - arrayFieldsToDisplay = data.selectedFields; - } - } - - this.fieldsToDisplay = arrayFieldsToDisplay; - }, /** * Set the menu */ @@ -473,7 +434,7 @@ export const CoreFilterCmpt = {
-