From e70cfd441e6fc663f363dc41d711bd27ec94b65e Mon Sep 17 00:00:00 2001 From: roll Date: Thu, 15 Mar 2018 13:03:26 +0300 Subject: [PATCH 01/18] Added raw schema editor integration example/workflow --- .../form_snippets/resource_schema.html | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ckanext/validation/templates/scheming/form_snippets/resource_schema.html b/ckanext/validation/templates/scheming/form_snippets/resource_schema.html index 08815301..072d953e 100644 --- a/ckanext/validation/templates/scheming/form_snippets/resource_schema.html +++ b/ckanext/validation/templates/scheming/form_snippets/resource_schema.html @@ -54,7 +54,24 @@ ) }} - + {# Schema Editor #} +
+ {# TODO: put into fanstatic/vendor? #} + + {# TODO: put into fanstatic/js/module-resource-schema? #} + {# Actual field containing the value #} {% set existing_value = h.scheming_display_json_value(value, indent=None) if is_json else value %} From 838435eb5f1b9f53840db959aeb15aca142e4a45 Mon Sep 17 00:00:00 2001 From: roll Date: Sun, 1 Apr 2018 17:10:45 +0300 Subject: [PATCH 02/18] Updated tableschema-ui integration --- .../fanstatic/js/module-resource-schema.js | 43 ++++++++++++++++++- .../form_snippets/resource_schema.html | 34 +++++++-------- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/ckanext/validation/fanstatic/js/module-resource-schema.js b/ckanext/validation/fanstatic/js/module-resource-schema.js index 19266ec7..57ed6c55 100644 --- a/ckanext/validation/fanstatic/js/module-resource-schema.js +++ b/ckanext/validation/fanstatic/js/module-resource-schema.js @@ -86,6 +86,23 @@ this.ckan.module('resource-schema', function($) { .on('click', this._onFromJSON); $('.controls', this.buttons_div).append(this.button_json); + // Button to start schema editing + this.schema_editor = null + this.source = null + this.source_file = null + this.schema_file = null + this.div_modal = $('#field-schema-modal') + this.div_editor = $('#field-schema-editor') + this.button_edit = $('' + + '' + + this._('Edit') + '') + .prop('title', this._('Edit the schema in the visual editor')) + .on('click', this._onEditSchemaClick); + $('.controls', this.buttons_div).append(this.button_edit); + var onFieldImageUploadChange = function(ev) {this.source_file = ev.target.files[0]} + $('#field-image-upload').change(onFieldImageUploadChange.bind(this)) + this.field_source_input = $('#field-image-url') + var removeText = this._('Clear'); // Change the clear file upload button too @@ -121,6 +138,7 @@ this.ckan.module('resource-schema', function($) { } else { this._showOnlyButtons(); } + }, /* Update the `this.label` text @@ -173,6 +191,7 @@ this.ckan.module('resource-schema', function($) { this.field_url_input.val(''); this.field_url_input.prop('readonly', false); + this.schema_file = null this.field_schema_input.val(''); this._updateUrlLabel(this._('Data Schema')); @@ -227,9 +246,11 @@ this.ckan.module('resource-schema', function($) { } }, - _onInputChange: function() { + _onInputChange: function(ev) { var file_name = this.field_upload_input.val().split(/^C:\\fakepath\\/).pop(); + this.schema_file = ev.target.files[0] + this.field_url_input.val(file_name); this.field_url_input.prop('readonly', true); @@ -253,6 +274,26 @@ this.ckan.module('resource-schema', function($) { return url; // filename }, + _onEditSchemaClick: function() { + var component = tableschemaUI.EditorSchema + var element = this.div_editor[0] + var source = this.source_file || this.field_source_input.val() + var schema = this.schema_file || this.field_schema_input.val() + var onSave = function (schema, error) { + console.log(schema) + if (!error) this.field_schema_input.val(JSON.stringify(schema, null, 2)) + this.div_modal.modal('hide') + this.schema_editor.dispose() + this.schema_editor = null + } + var props = { + source: source, + schema: schema, + onSave: onSave.bind(this), + } + this.schema_editor = tableschemaUI.render(component, props, element) + this.div_modal.modal('show') + } }; }); diff --git a/ckanext/validation/templates/scheming/form_snippets/resource_schema.html b/ckanext/validation/templates/scheming/form_snippets/resource_schema.html index 072d953e..3f8e3a62 100644 --- a/ckanext/validation/templates/scheming/form_snippets/resource_schema.html +++ b/ckanext/validation/templates/scheming/form_snippets/resource_schema.html @@ -55,23 +55,23 @@ }} {# Schema Editor #} -
- {# TODO: put into fanstatic/vendor? #} - - {# TODO: put into fanstatic/js/module-resource-schema? #} - + {# TODO: move to fanstatic/vendor (minified?) #} + +