From 4033465cb4e81178d44fc6663540c1f1b10fbbb1 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 13 Aug 2017 11:42:41 +0100 Subject: [PATCH 1/3] Small fixes to the data extension interface - removed mention to a missing .less file - fixed the position of the Reset button in the preview dialog - fixed the error for empty property selections --- .../webapp/modules/core/MOD-INF/controller.js | 1 - .../dialogs/extend-data-preview-dialog.js | 42 +++++++++---------- .../extend-data-preview-dialog.html | 4 +- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/main/webapp/modules/core/MOD-INF/controller.js b/main/webapp/modules/core/MOD-INF/controller.js index 4489d0c97..0a42b2c33 100644 --- a/main/webapp/modules/core/MOD-INF/controller.js +++ b/main/webapp/modules/core/MOD-INF/controller.js @@ -370,7 +370,6 @@ function init() { "styles/index/default-importing-sources.less", "styles/views/data-table-view.less", // for the preview table's styles - "styles/views/extend-data-preview-dialog.less", "styles/index/fixed-width-parser-ui.less", "styles/index/xml-parser-ui.less", "styles/index/json-parser-ui.less" diff --git a/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js b/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js index bdb5d5fdc..89d906f23 100644 --- a/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js +++ b/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js @@ -107,16 +107,6 @@ ExtendReconciledDataPreviewDialog.getAllProperties = function(url, typeID, onDon id: property.id, name: property.name }; - /*if ("id2" in property) { - property2.expected = property.schema2; - property2.properties = [{ - id: property.id2, - name: property.name2, - expected: property.expects - }]; - } else { - property2.expected = property.expects; - } */ allProperties.push(property2); } allProperties.sort(function(a, b) { return a.name.localeCompare(b.name); }); @@ -183,19 +173,25 @@ ExtendReconciledDataPreviewDialog.prototype._update = function() { columnName: this._column.name }; - $.post( - "command/core/preview-extend-data?" + $.param(params), - { - rowIndices: JSON.stringify(this._rowIndices), - extension: JSON.stringify(this._extension) - }, - function(data) { - self._renderPreview(data); - }, - "json" - ).fail(function(data) { - console.log(data); - }); + if(this._extension.properties.length == 0) { + // if the column selection is empty, reset the view + this._elmts.previewContainer.empty(); + } else { + // otherwise, refresh the preview + $.post( + "command/core/preview-extend-data?" + $.param(params), + { + rowIndices: JSON.stringify(this._rowIndices), + extension: JSON.stringify(this._extension) + }, + function(data) { + self._renderPreview(data); + }, + "json" + ).fail(function(data) { + console.log(data); + }); + } }; ExtendReconciledDataPreviewDialog.prototype._addProperty = function(p) { diff --git a/main/webapp/modules/core/scripts/views/data-table/extend-data-preview-dialog.html b/main/webapp/modules/core/scripts/views/data-table/extend-data-preview-dialog.html index f92e09fb9..0f16248fb 100644 --- a/main/webapp/modules/core/scripts/views/data-table/extend-data-preview-dialog.html +++ b/main/webapp/modules/core/scripts/views/data-table/extend-data-preview-dialog.html @@ -5,7 +5,7 @@ Add Property Preview - +
@@ -23,4 +23,4 @@ - \ No newline at end of file + From 81fa6093f40fa56b400ca799a45ba6a1cc6f7467 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 13 Aug 2017 17:41:18 +0100 Subject: [PATCH 2/3] Better error reporting in data extension - when trying to use the operation on a non-reconciled column - when using it with a service that does not support the protocol --- .../modules/core/langs/translation-en.json | 2 + .../dialogs/extend-data-preview-dialog.js | 39 +++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index ae836fb8d..37a9d6028 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -510,6 +510,8 @@ "remove-prop": "remove", "configure-prop": "configure", "no-settings": "No settings are available for this property.", + "extend-not-reconciled": "This operation is only available on reconciled columns.", + "extend-not-supported": "This reconciliation service does not support data extension. Try removing the service and adding it again. If the problem persists, contact the service provider.", "add-col-fetch": "Add column by fetching URLs based on column", "throttle-delay": "Throttle delay", "milli": "milliseconds", diff --git a/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js b/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js index 89d906f23..f31652f18 100644 --- a/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js +++ b/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js @@ -62,19 +62,19 @@ function ExtendReconciledDataPreviewDialog(column, columnIndex, rowIndices, onDo DialogSystem.dismissUntil(self._level - 1); }); - var dismissBusy = DialogSystem.showBusy(); var type = (column.reconConfig) && (column.reconConfig.type) ? column.reconConfig.type.id : ""; this._proposePropertiesUrl = null; this._fetchColumnUrl = null; this._serviceMetadata = null; + var extend = null; if ("reconConfig" in column) { var service = column.reconConfig.service; this._service = service; var serviceMetadata = ReconciliationManager.getServiceFromUrl(service); this._serviceMetadata = serviceMetadata; if ("extend" in serviceMetadata) { - var extend = serviceMetadata.extend; + extend = serviceMetadata.extend; if ("propose_properties" in extend) { var endpoint = extend.propose_properties; this._proposePropertiesUrl = endpoint.service_url + endpoint.service_path; @@ -82,10 +82,17 @@ function ExtendReconciledDataPreviewDialog(column, columnIndex, rowIndices, onDo } } - ExtendReconciledDataPreviewDialog.getAllProperties(this._proposePropertiesUrl, type, function(properties) { - dismissBusy(); - self._show(properties); - }); + if (this._serviceMetadata === null) { + alert($.i18n._('core-views')["extend-not-reconciled"]); + } else if(extend === null) { + alert($.i18n._('core-views')["extend-not-supported"]); + } else { + var dismissBusy = DialogSystem.showBusy(); + ExtendReconciledDataPreviewDialog.getAllProperties(this._proposePropertiesUrl, type, function(properties) { + dismissBusy(); + self._show(properties); + }); + } } ExtendReconciledDataPreviewDialog.getAllProperties = function(url, typeID, onDone) { @@ -189,7 +196,7 @@ ExtendReconciledDataPreviewDialog.prototype._update = function() { }, "json" ).fail(function(data) { - console.log(data); + alert($.i18n._("core-views")["internal-err"]); }); } }; @@ -292,7 +299,7 @@ ExtendReconciledDataPreviewDialog.prototype._renderPreview = function(data) { ExtendReconciledDataPreviewDialog.prototype._removeProperty = function(id) { for(var i = this._extension.properties.length - 1; i >= 0; i--) { var property = this._extension.properties[i]; - if (property.id == id) { + if (property.id === id) { this._extension.properties.splice(i, 1); } } @@ -302,7 +309,7 @@ ExtendReconciledDataPreviewDialog.prototype._removeProperty = function(id) { ExtendReconciledDataPreviewDialog.prototype._findProperty = function(id) { var properties = this._extension.properties; for(var i = properties.length - 1; i >= 0; i--) { - if (properties[i].id == id) { + if (properties[i].id === id) { return properties[i]; } } @@ -332,7 +339,7 @@ ExtendReconciledDataPreviewDialog.prototype._constrainProperty = function(id) { } var tr = $(''); var td = $('').attr('title', field.help_text).appendTo(tr); - if (field.type == 'select') { + if (field.type === 'select') { var fieldLabel = $('').text(field.label+':').appendTo(td); td.append($('
')); for(var j = 0; j < field.choices.length; j++) { @@ -343,21 +350,21 @@ ExtendReconciledDataPreviewDialog.prototype._constrainProperty = function(id) { 'value', choice.value).attr( 'name', field.name).appendTo(labelElem); - if (choice.value == currentValue) { + if (choice.value === currentValue) { inputElem.attr('checked', 'checked'); } labelElem.append(' '+choice.name); td.append('
'); } td.append(fieldHTML); - } else if (field.type == 'checkbox') { + } else if (field.type === 'checkbox') { var label = $('').attr('for', field.name).appendTo(td); var input = $('').attr('name', field.name).appendTo(label); - if (currentValue == 'on') { + if (currentValue === 'on') { input.attr('checked','checked'); } label.append(' '+field.label); - } else if (field.type == 'number' || field.type == 'text') { + } else if (field.type === 'number' || field.type == 'text') { var label = $('').attr('for', field.name).appendTo(td); label.append(field.label+': '); var input = $('').attr( @@ -371,7 +378,7 @@ ExtendReconciledDataPreviewDialog.prototype._constrainProperty = function(id) { } } - if (table.children().length == 0) { + if (table.children().length === 0) { var tr = $('').appendTo(table); $('').text($.i18n._('core-views')['no-settings']).appendTo(tr); } @@ -409,7 +416,7 @@ ExtendReconciledDataPreviewDialog.prototype._constrainProperty = function(id) { self._update(); } catch (e) { - //console.log(e); + alert($.i18n._("core-views")["internal-err"]); } }); From f2612b0d125dd983e438405b2997799fa514e170 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 13 Aug 2017 17:48:18 +0100 Subject: [PATCH 3/3] Make codacy happy --- .../dialogs/extend-data-preview-dialog.js | 154 +++++++++--------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js b/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js index f31652f18..063a94ae3 100644 --- a/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js +++ b/main/webapp/modules/core/scripts/dialogs/extend-data-preview-dialog.js @@ -55,7 +55,7 @@ function ExtendReconciledDataPreviewDialog(column, columnIndex, rowIndices, onDo self._onDone(self._extension, self._service, self._serviceMetadata.identifierSpace, - self._serviceMetadata.schemaSpace); + self._serviceMetadata.schemaSpace); } }); this._elmts.cancelButton.click(function() { @@ -76,7 +76,7 @@ function ExtendReconciledDataPreviewDialog(column, columnIndex, rowIndices, onDo if ("extend" in serviceMetadata) { extend = serviceMetadata.extend; if ("propose_properties" in extend) { - var endpoint = extend.propose_properties; + var endpoint = extend.propose_properties; this._proposePropertiesUrl = endpoint.service_url + endpoint.service_path; } } @@ -101,32 +101,32 @@ ExtendReconciledDataPreviewDialog.getAllProperties = function(url, typeID, onDon } else { var done = false; $.getJSON( - url +"?type=" + typeID + "&callback=?", - null, - function(data) { - if (done) return; - done = true; + url +"?type=" + typeID + "&callback=?", + null, + function(data) { + if (done) return; + done = true; - var allProperties = []; - for (var i = 0; i < data.properties.length; i++) { - var property = data.properties[i]; - var property2 = { - id: property.id, - name: property.name - }; - allProperties.push(property2); - } - allProperties.sort(function(a, b) { return a.name.localeCompare(b.name); }); + var allProperties = []; + for (var i = 0; i < data.properties.length; i++) { + var property = data.properties[i]; + var property2 = { + id: property.id, + name: property.name + }; + allProperties.push(property2); + } + allProperties.sort(function(a, b) { return a.name.localeCompare(b.name); }); - onDone(allProperties); - } + onDone(allProperties); + } ); window.setTimeout(function() { - if (done) return; + if (done) return; - done = true; - onDone([]); + done = true; + onDone([]); }, 7000); // time to give up? } }; @@ -172,7 +172,7 @@ ExtendReconciledDataPreviewDialog.prototype._show = function(properties) { ExtendReconciledDataPreviewDialog.prototype._update = function() { this._elmts.previewContainer.empty().html( - '
'); + '
'); var self = this; var params = { @@ -180,23 +180,23 @@ ExtendReconciledDataPreviewDialog.prototype._update = function() { columnName: this._column.name }; - if(this._extension.properties.length == 0) { + if(this._extension.properties.length === 0) { // if the column selection is empty, reset the view this._elmts.previewContainer.empty(); } else { // otherwise, refresh the preview $.post( - "command/core/preview-extend-data?" + $.param(params), - { - rowIndices: JSON.stringify(this._rowIndices), - extension: JSON.stringify(this._extension) - }, - function(data) { - self._renderPreview(data); - }, - "json" + "command/core/preview-extend-data?" + $.param(params), + { + rowIndices: JSON.stringify(this._rowIndices), + extension: JSON.stringify(this._extension) + }, + function(data) { + self._renderPreview(data); + }, + "json" ).fail(function(data) { - alert($.i18n._("core-views")["internal-err"]); + alert($.i18n._("core-views")["internal-err"]); }); } }; @@ -284,8 +284,8 @@ ExtendReconciledDataPreviewDialog.prototype._renderPreview = function(data) { if (cell !== null) { if ($.isPlainObject(cell)) { $('').attr("href", - this._serviceMetadata.identifierSpace + cell.id - ).attr("target", "_blank").text(cell.name).appendTo(td); + this._serviceMetadata.identifierSpace + cell.id + ).attr("target", "_blank").text(cell.name).appendTo(td); } else { $('').text(cell).appendTo(td); } @@ -331,50 +331,50 @@ ExtendReconciledDataPreviewDialog.prototype._constrainProperty = function(id) { var table = $('
'); if (fields != null) { for(var i = 0; i < fields.length; i++) { - var field = fields[i]; + var field = fields[i]; var fieldHTML = ''; - var currentValue = field.default; + var currentValue = field.default; if (property.settings != null && property.settings[field.name] != null) { currentValue = property.settings[field.name]; } - var tr = $(''); - var td = $('').attr('title', field.help_text).appendTo(tr); - if (field.type === 'select') { - var fieldLabel = $('').text(field.label+':').appendTo(td); - td.append($('
')); - for(var j = 0; j < field.choices.length; j++) { - var choice = field.choices[j]; - var labelElem = $('').attr('for', field.name+'_'+choice.value).appendTo(td); - var inputElem = $('').attr( - 'id', field.name+'_'+choice.value).attr( - 'value', choice.value).attr( - 'name', field.name).appendTo(labelElem); + var tr = $(''); + var td = $('').attr('title', field.help_text).appendTo(tr); + if (field.type === 'select') { + var fieldLabel = $('').text(field.label+':').appendTo(td); + td.append($('
')); + for(var j = 0; j < field.choices.length; j++) { + var choice = field.choices[j]; + var labelElem = $('').attr('for', field.name+'_'+choice.value).appendTo(td); + var inputElem = $('').attr( + 'id', field.name+'_'+choice.value).attr( + 'value', choice.value).attr( + 'name', field.name).appendTo(labelElem); - if (choice.value === currentValue) { - inputElem.attr('checked', 'checked'); - } + if (choice.value === currentValue) { + inputElem.attr('checked', 'checked'); + } labelElem.append(' '+choice.name); td.append('
'); - } - td.append(fieldHTML); - } else if (field.type === 'checkbox') { - var label = $('').attr('for', field.name).appendTo(td); - var input = $('').attr('name', field.name).appendTo(label); - if (currentValue === 'on') { - input.attr('checked','checked'); - } - label.append(' '+field.label); + } + td.append(fieldHTML); + } else if (field.type === 'checkbox') { + var label = $('').attr('for', field.name).appendTo(td); + var input = $('').attr('name', field.name).appendTo(label); + if (currentValue === 'on') { + input.attr('checked','checked'); + } + label.append(' '+field.label); } else if (field.type === 'number' || field.type == 'text') { - var label = $('').attr('for', field.name).appendTo(td); - label.append(field.label+': '); - var input = $('').attr( - 'name', field.name).attr( - 'type', field.type).attr( - 'value', currentValue).appendTo(label); - } - if (tr.children().length > 0) { - table.append(tr); - } + var label = $('').attr('for', field.name).appendTo(td); + label.append(field.label+': '); + var input = $('').attr( + 'name', field.name).attr( + 'type', field.type).attr( + 'value', currentValue).appendTo(label); + } + if (tr.children().length > 0) { + table.append(tr); + } } } @@ -404,19 +404,19 @@ ExtendReconciledDataPreviewDialog.prototype._constrainProperty = function(id) { try { if (fields != null) { var elem = $(bodyElmts.form[0]); - var ar = elem.serializeArray(); - var settings = {}; + var ar = elem.serializeArray(); + var settings = {}; for(var i = 0; i < ar.length; i++) { settings[ar[i].name] = ar[i].value; - } - property.settings = settings; + } + property.settings = settings; } dismiss(); self._update(); } catch (e) { - alert($.i18n._("core-views")["internal-err"]); + alert($.i18n._("core-views")["internal-err"]); } });