Merge branch 'extend-data-fixes'

Conflicts:
	main/webapp/modules/core/langs/translation-en.json
This commit is contained in:
Antonin Delpeuch 2017-08-13 20:17:18 +01:00
commit 18b1942169
4 changed files with 106 additions and 102 deletions

View File

@ -370,7 +370,6 @@ function init() {
"styles/index/default-importing-sources.less", "styles/index/default-importing-sources.less",
"styles/views/data-table-view.less", // for the preview table's styles "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/fixed-width-parser-ui.less",
"styles/index/xml-parser-ui.less", "styles/index/xml-parser-ui.less",
"styles/index/json-parser-ui.less" "styles/index/json-parser-ui.less"

View File

@ -510,6 +510,8 @@
"remove-prop": "remove", "remove-prop": "remove",
"configure-prop": "configure", "configure-prop": "configure",
"no-settings": "No settings are available for this property.", "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", "add-col-fetch": "Add column by fetching URLs based on column",
"throttle-delay": "Throttle delay", "throttle-delay": "Throttle delay",
"milli": "milliseconds", "milli": "milliseconds",

View File

@ -55,37 +55,44 @@ function ExtendReconciledDataPreviewDialog(column, columnIndex, rowIndices, onDo
self._onDone(self._extension, self._onDone(self._extension,
self._service, self._service,
self._serviceMetadata.identifierSpace, self._serviceMetadata.identifierSpace,
self._serviceMetadata.schemaSpace); self._serviceMetadata.schemaSpace);
} }
}); });
this._elmts.cancelButton.click(function() { this._elmts.cancelButton.click(function() {
DialogSystem.dismissUntil(self._level - 1); DialogSystem.dismissUntil(self._level - 1);
}); });
var dismissBusy = DialogSystem.showBusy();
var type = (column.reconConfig) && (column.reconConfig.type) ? column.reconConfig.type.id : ""; var type = (column.reconConfig) && (column.reconConfig.type) ? column.reconConfig.type.id : "";
this._proposePropertiesUrl = null; this._proposePropertiesUrl = null;
this._fetchColumnUrl = null; this._fetchColumnUrl = null;
this._serviceMetadata = null; this._serviceMetadata = null;
var extend = null;
if ("reconConfig" in column) { if ("reconConfig" in column) {
var service = column.reconConfig.service; var service = column.reconConfig.service;
this._service = service; this._service = service;
var serviceMetadata = ReconciliationManager.getServiceFromUrl(service); var serviceMetadata = ReconciliationManager.getServiceFromUrl(service);
this._serviceMetadata = serviceMetadata; this._serviceMetadata = serviceMetadata;
if ("extend" in serviceMetadata) { if ("extend" in serviceMetadata) {
var extend = serviceMetadata.extend; extend = serviceMetadata.extend;
if ("propose_properties" in extend) { if ("propose_properties" in extend) {
var endpoint = extend.propose_properties; var endpoint = extend.propose_properties;
this._proposePropertiesUrl = endpoint.service_url + endpoint.service_path; this._proposePropertiesUrl = endpoint.service_url + endpoint.service_path;
} }
} }
} }
ExtendReconciledDataPreviewDialog.getAllProperties(this._proposePropertiesUrl, type, function(properties) { if (this._serviceMetadata === null) {
dismissBusy(); alert($.i18n._('core-views')["extend-not-reconciled"]);
self._show(properties); } 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) { ExtendReconciledDataPreviewDialog.getAllProperties = function(url, typeID, onDone) {
@ -94,42 +101,32 @@ ExtendReconciledDataPreviewDialog.getAllProperties = function(url, typeID, onDon
} else { } else {
var done = false; var done = false;
$.getJSON( $.getJSON(
url +"?type=" + typeID + "&callback=?", url +"?type=" + typeID + "&callback=?",
null, null,
function(data) { function(data) {
if (done) return; if (done) return;
done = true; done = true;
var allProperties = []; var allProperties = [];
for (var i = 0; i < data.properties.length; i++) { for (var i = 0; i < data.properties.length; i++) {
var property = data.properties[i]; var property = data.properties[i];
var property2 = { var property2 = {
id: property.id, id: property.id,
name: property.name name: property.name
}; };
/*if ("id2" in property) { allProperties.push(property2);
property2.expected = property.schema2; }
property2.properties = [{ allProperties.sort(function(a, b) { return a.name.localeCompare(b.name); });
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); });
onDone(allProperties); onDone(allProperties);
} }
); );
window.setTimeout(function() { window.setTimeout(function() {
if (done) return; if (done) return;
done = true; done = true;
onDone([]); onDone([]);
}, 7000); // time to give up? }, 7000); // time to give up?
} }
}; };
@ -175,7 +172,7 @@ ExtendReconciledDataPreviewDialog.prototype._show = function(properties) {
ExtendReconciledDataPreviewDialog.prototype._update = function() { ExtendReconciledDataPreviewDialog.prototype._update = function() {
this._elmts.previewContainer.empty().html( this._elmts.previewContainer.empty().html(
'<div bind="progressPanel" class="extend-data-preview-progress"><img src="images/large-spinner.gif" /></div>'); '<div bind="progressPanel" class="extend-data-preview-progress"><img src="images/large-spinner.gif" /></div>');
var self = this; var self = this;
var params = { var params = {
@ -183,19 +180,25 @@ ExtendReconciledDataPreviewDialog.prototype._update = function() {
columnName: this._column.name columnName: this._column.name
}; };
$.post( if(this._extension.properties.length === 0) {
"command/core/preview-extend-data?" + $.param(params), // if the column selection is empty, reset the view
{ this._elmts.previewContainer.empty();
rowIndices: JSON.stringify(this._rowIndices), } else {
extension: JSON.stringify(this._extension) // otherwise, refresh the preview
}, $.post(
function(data) { "command/core/preview-extend-data?" + $.param(params),
self._renderPreview(data); {
}, rowIndices: JSON.stringify(this._rowIndices),
"json" extension: JSON.stringify(this._extension)
).fail(function(data) { },
console.log(data); function(data) {
}); self._renderPreview(data);
},
"json"
).fail(function(data) {
alert($.i18n._("core-views")["internal-err"]);
});
}
}; };
ExtendReconciledDataPreviewDialog.prototype._addProperty = function(p) { ExtendReconciledDataPreviewDialog.prototype._addProperty = function(p) {
@ -281,8 +284,8 @@ ExtendReconciledDataPreviewDialog.prototype._renderPreview = function(data) {
if (cell !== null) { if (cell !== null) {
if ($.isPlainObject(cell)) { if ($.isPlainObject(cell)) {
$('<a>').attr("href", $('<a>').attr("href",
this._serviceMetadata.identifierSpace + cell.id this._serviceMetadata.identifierSpace + cell.id
).attr("target", "_blank").text(cell.name).appendTo(td); ).attr("target", "_blank").text(cell.name).appendTo(td);
} else { } else {
$('<span>').text(cell).appendTo(td); $('<span>').text(cell).appendTo(td);
} }
@ -296,7 +299,7 @@ ExtendReconciledDataPreviewDialog.prototype._renderPreview = function(data) {
ExtendReconciledDataPreviewDialog.prototype._removeProperty = function(id) { ExtendReconciledDataPreviewDialog.prototype._removeProperty = function(id) {
for(var i = this._extension.properties.length - 1; i >= 0; i--) { for(var i = this._extension.properties.length - 1; i >= 0; i--) {
var property = this._extension.properties[i]; var property = this._extension.properties[i];
if (property.id == id) { if (property.id === id) {
this._extension.properties.splice(i, 1); this._extension.properties.splice(i, 1);
} }
} }
@ -306,7 +309,7 @@ ExtendReconciledDataPreviewDialog.prototype._removeProperty = function(id) {
ExtendReconciledDataPreviewDialog.prototype._findProperty = function(id) { ExtendReconciledDataPreviewDialog.prototype._findProperty = function(id) {
var properties = this._extension.properties; var properties = this._extension.properties;
for(var i = properties.length - 1; i >= 0; i--) { for(var i = properties.length - 1; i >= 0; i--) {
if (properties[i].id == id) { if (properties[i].id === id) {
return properties[i]; return properties[i];
} }
} }
@ -328,54 +331,54 @@ ExtendReconciledDataPreviewDialog.prototype._constrainProperty = function(id) {
var table = $('<table></table>'); var table = $('<table></table>');
if (fields != null) { if (fields != null) {
for(var i = 0; i < fields.length; i++) { for(var i = 0; i < fields.length; i++) {
var field = fields[i]; var field = fields[i];
var fieldHTML = ''; var fieldHTML = '';
var currentValue = field.default; var currentValue = field.default;
if (property.settings != null && property.settings[field.name] != null) { if (property.settings != null && property.settings[field.name] != null) {
currentValue = property.settings[field.name]; currentValue = property.settings[field.name];
} }
var tr = $('<tr></tr>'); var tr = $('<tr></tr>');
var td = $('<td></td>').attr('title', field.help_text).appendTo(tr); var td = $('<td></td>').attr('title', field.help_text).appendTo(tr);
if (field.type == 'select') { if (field.type === 'select') {
var fieldLabel = $('<span></span>').text(field.label+':').appendTo(td); var fieldLabel = $('<span></span>').text(field.label+':').appendTo(td);
td.append($('<br/>')); td.append($('<br/>'));
for(var j = 0; j < field.choices.length; j++) { for(var j = 0; j < field.choices.length; j++) {
var choice = field.choices[j]; var choice = field.choices[j];
var labelElem = $('<label></label>').attr('for', field.name+'_'+choice.value).appendTo(td); var labelElem = $('<label></label>').attr('for', field.name+'_'+choice.value).appendTo(td);
var inputElem = $('<input type="radio" />').attr( var inputElem = $('<input type="radio" />').attr(
'id', field.name+'_'+choice.value).attr( 'id', field.name+'_'+choice.value).attr(
'value', choice.value).attr( 'value', choice.value).attr(
'name', field.name).appendTo(labelElem); 'name', field.name).appendTo(labelElem);
if (choice.value == currentValue) { if (choice.value === currentValue) {
inputElem.attr('checked', 'checked'); inputElem.attr('checked', 'checked');
} }
labelElem.append(' '+choice.name); labelElem.append(' '+choice.name);
td.append('<br/>'); td.append('<br/>');
} }
td.append(fieldHTML); td.append(fieldHTML);
} else if (field.type == 'checkbox') { } else if (field.type === 'checkbox') {
var label = $('<label></label>').attr('for', field.name).appendTo(td); var label = $('<label></label>').attr('for', field.name).appendTo(td);
var input = $('<input type="checkbox" />').attr('name', field.name).appendTo(label); var input = $('<input type="checkbox" />').attr('name', field.name).appendTo(label);
if (currentValue == 'on') { if (currentValue === 'on') {
input.attr('checked','checked'); input.attr('checked','checked');
} }
label.append(' '+field.label); label.append(' '+field.label);
} else if (field.type == 'number' || field.type == 'text') { } else if (field.type === 'number' || field.type == 'text') {
var label = $('<label></label>').attr('for', field.name).appendTo(td); var label = $('<label></label>').attr('for', field.name).appendTo(td);
label.append(field.label+': '); label.append(field.label+': ');
var input = $('<input />').attr( var input = $('<input />').attr(
'name', field.name).attr( 'name', field.name).attr(
'type', field.type).attr( 'type', field.type).attr(
'value', currentValue).appendTo(label); 'value', currentValue).appendTo(label);
} }
if (tr.children().length > 0) { if (tr.children().length > 0) {
table.append(tr); table.append(tr);
} }
} }
} }
if (table.children().length == 0) { if (table.children().length === 0) {
var tr = $('<tr></tr>').appendTo(table); var tr = $('<tr></tr>').appendTo(table);
$('<td></td>').text($.i18n._('core-views')['no-settings']).appendTo(tr); $('<td></td>').text($.i18n._('core-views')['no-settings']).appendTo(tr);
} }
@ -401,19 +404,19 @@ ExtendReconciledDataPreviewDialog.prototype._constrainProperty = function(id) {
try { try {
if (fields != null) { if (fields != null) {
var elem = $(bodyElmts.form[0]); var elem = $(bodyElmts.form[0]);
var ar = elem.serializeArray(); var ar = elem.serializeArray();
var settings = {}; var settings = {};
for(var i = 0; i < ar.length; i++) { for(var i = 0; i < ar.length; i++) {
settings[ar[i].name] = ar[i].value; settings[ar[i].name] = ar[i].value;
} }
property.settings = settings; property.settings = settings;
} }
dismiss(); dismiss();
self._update(); self._update();
} catch (e) { } catch (e) {
//console.log(e); alert($.i18n._("core-views")["internal-err"]);
} }
}); });

View File

@ -5,7 +5,7 @@
<tr> <tr>
<td width="300" height="1">Add Property</td> <td width="300" height="1">Add Property</td>
<td height="1">Preview</td> <td height="1">Preview</td>
<td height="1" width="1%"><button class="button" bind="resetButton">Reset</button></td> <td height="1" style="text-align: right"><button class="button" bind="resetButton">Reset</button></td>
</tr> </tr>
<tr> <tr>
<td style="vertical-align: top;" height="1"><div class="input-container"><input bind="addPropertyInput" /></div></td> <td style="vertical-align: top;" height="1"><div class="input-container"><input bind="addPropertyInput" /></div></td>
@ -23,4 +23,4 @@
<button class="button" bind="okButton">&nbsp;&nbsp;OK&nbsp;&nbsp;</button> <button class="button" bind="okButton">&nbsp;&nbsp;OK&nbsp;&nbsp;</button>
<button class="button" bind="cancelButton">Cancel</button> <button class="button" bind="cancelButton">Cancel</button>
</div> </div>
</div> </div>