From 05873f283ddcb8bb840dd944139f42ac71bead15 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Fri, 14 Jul 2017 22:17:40 +0100 Subject: [PATCH] Integration of constraints with service-defined forms --- .../recon/ReconciledDataExtensionJob.java | 6 +- .../dialogs/extend-data-preview-dialog.js | 107 ++++++++++++++---- .../extend-data-preview-dialog.less | 4 + 3 files changed, 92 insertions(+), 25 deletions(-) diff --git a/main/src/com/google/refine/model/recon/ReconciledDataExtensionJob.java b/main/src/com/google/refine/model/recon/ReconciledDataExtensionJob.java index c1441bd5a..541253a79 100644 --- a/main/src/com/google/refine/model/recon/ReconciledDataExtensionJob.java +++ b/main/src/com/google/refine/model/recon/ReconciledDataExtensionJob.java @@ -273,7 +273,11 @@ public class ReconciledDataExtensionJob { jsonWriter.object(); jsonWriter.key("id"); jsonWriter.value(property.getString("id")); - // TODO translate constraints as below + if (property.has("settings")) { + JSONObject settings = property.getJSONObject("settings"); + jsonWriter.key("settings"); + jsonWriter.value(settings); + } jsonWriter.endObject(); } jsonWriter.endArray(); 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 0651eeeac..fe3702014 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 @@ -183,6 +183,7 @@ ExtendReconciledDataPreviewDialog.prototype._update = function() { columnName: this._column.name }; + console.log(this._extension); $.post( "command/core/preview-extend-data?" + $.param(params), { @@ -320,26 +321,72 @@ ExtendReconciledDataPreviewDialog.prototype._constrainProperty = function(id) { var frame = DialogSystem.createDialog(); frame.width("500px"); - var header = $('
').addClass("dialog-header").text("Constrain " + id).appendTo(frame); + var header = $('
').addClass("dialog-header").text("Settings for " + id).appendTo(frame); var body = $('
').addClass("dialog-body").appendTo(frame); var footer = $('
').addClass("dialog-footer").appendTo(frame); - body.html( - '
' + + // by default we display an area where the user can input JSON + var form = ( '' + '' + - '
' + - 'Enter MQL query constraints as JSON' + + 'Enter query settings as JSON' + '
' + '' + - '
' + ''); + + // If the service metadata specifies fields, we build a proper form to make it more user-friendly + var fields = self._serviceMetadata.extend.property_settings; + if (fields != null) { + form = ''; + for(var i = 0; i < fields.length; i++) { + var field = fields[i]; + var fieldHTML = ''; + var currentValue = field.default; + if (property.settings != null && property.settings[field.name] != null) { + currentValue = property.settings[field.name]; + } + if (field.type == 'select') { + fieldHTML += ''+field.label+':
'; + for(var j = 0; j < field.choices.length; j++) { + var choice = field.choices[j]; + fieldHTML += '