From c6ffe7d29ead77d261b20bfd4ea30b16949e14c7 Mon Sep 17 00:00:00 2001 From: Seyi Adebajo Date: Mon, 13 Feb 2017 14:55:51 -0800 Subject: [PATCH] DSS-5868 Adds Component: dataset-schema --- .../app/components/dataset-schema.js | 65 +++++++++++++++ .../templates/components/dataset-schema.hbs | 79 +++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 wherehows-web/app/components/dataset-schema.js create mode 100644 wherehows-web/app/templates/components/dataset-schema.hbs diff --git a/wherehows-web/app/components/dataset-schema.js b/wherehows-web/app/components/dataset-schema.js new file mode 100644 index 0000000000..4497a3c136 --- /dev/null +++ b/wherehows-web/app/components/dataset-schema.js @@ -0,0 +1,65 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + buildJsonView: function(){ + var dataset = this.get("dataset"); + var schema = JSON.parse(dataset.schema) + setTimeout(function() { + $("#json-viewer").JSONView(schema) + }, 500); + }, + actions: { + getSchema: function(){ + var _this = this + var id = _this.get('dataset.id') + var columnUrl = 'api/v1/datasets/' + id + "/columns"; + _this.set("isTable", true); + _this.set("isJSON", false); + $.get(columnUrl, function(data) { + if (data && data.status == "ok") + { + if (data.columns && (data.columns.length > 0)) + { + _this.set("hasSchemas", true); + data.columns = data.columns.map(function(item, idx){ + item.commentHtml = marked(item.comment).htmlSafe() + return item + }) + _this.set("schemas", data.columns); + setTimeout(initializeColumnTreeGrid, 500); + } + else + { + _this.set("hasSchemas", false); + } + } + else + { + _this.set("hasSchemas", false); + } + }); + }, + setView: function (view) { + switch (view) { + case "tabular": + this.set('isTable', true); + this.set('isJSON', false); + $('#json-viewer').hide(); + $('#json-table').show(); + break; + case "json": + this.set('isTable', false); + this.set('isJSON', true); + this.buildJsonView(); + $('#json-table').hide(); + $('#json-viewer').show(); + break; + default: + this.set('isTable', true); + this.set('isJSON', false); + $('#json-viewer').hide(); + $('#json-table').show(); + } + } + } +}); diff --git a/wherehows-web/app/templates/components/dataset-schema.hbs b/wherehows-web/app/templates/components/dataset-schema.hbs new file mode 100644 index 0000000000..a7d2375c30 --- /dev/null +++ b/wherehows-web/app/templates/components/dataset-schema.hbs @@ -0,0 +1,79 @@ +{{#if hasSchemas}} +
+
+
+ + +
+
+
+ + + + + + + + + + + + + + + {{#each schemas as |schema|}} + + + + + + + + + + + {{/each}} + +
ColumnData TypeNIPD Default Comments + +
{{schema.fieldName}}{{schema.dataType}} + {{#if schema.nullable}} + + {{/if}} + + {{#if schema.indexed}} + + {{/if}} + + {{#if schema.partitioned}} + + {{/if}} + + {{#if schema.distributed}} + + {{/if}} + +
+ {{#schema-comment schema=schema datasetId=dataset.id fieldId=schema.id}}{{/schema-comment}} + {{schema.commentHtml}} +
+
+ {{schema.commentCount}} +
+ +{{else}} +
+{{/if}} \ No newline at end of file