diff --git a/app/components/code-highlighter.js b/app/components/code-highlighter.js new file mode 100644 index 0000000..37a6aab --- /dev/null +++ b/app/components/code-highlighter.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; +/* global hljs */ + +export default Ember.Component.extend({ + tagName: 'pre', + + classNames: ['code-highlighter'], + + didRender() { + let codeBlock = this.$().find('code')[0]; + + hljs.highlightBlock(codeBlock); + } +}); diff --git a/app/index.html b/app/index.html index 69edb1a..870fcd7 100644 --- a/app/index.html +++ b/app/index.html @@ -8,6 +8,7 @@ {{content-for 'head'}} + {{content-for 'head-footer'}} diff --git a/app/pods/cluster/template.hbs b/app/pods/cluster/template.hbs index 55126e6..9b1053b 100644 --- a/app/pods/cluster/template.hbs +++ b/app/pods/cluster/template.hbs @@ -57,7 +57,12 @@ {{/if}} {{/dashboard-module}} - {{#dashboard-module label='Search Indexes'}} + {{#dashboard-module label='Search Overview'}} + {{#link-to 'search-schema.create' model.id class='btn btn-small btn-primary'}} + + Create new search schema + {{/link-to}} + {{#if model.searchIndexes}} {{search-indexes indexes=model.searchIndexes}} {{else}} diff --git a/app/pods/search-index/template.hbs b/app/pods/search-index/template.hbs index 16b2da7..89c0eff 100644 --- a/app/pods/search-index/template.hbs +++ b/app/pods/search-index/template.hbs @@ -22,7 +22,7 @@ Schema - {{#link-to 'search-schema' model.cluster.id model.schema.name}} + {{#link-to 'search-schema' model.cluster.id model.schema.name class='btn btn-small btn-primary'}} {{model.schema.name}} {{/link-to}} diff --git a/app/pods/search-schema/create/controller.js b/app/pods/search-schema/create/controller.js new file mode 100644 index 0000000..436c2bd --- /dev/null +++ b/app/pods/search-schema/create/controller.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + schemaName: '', + schemaContent: '' +}); diff --git a/app/pods/search-schema/create/route.js b/app/pods/search-schema/create/route.js new file mode 100644 index 0000000..d98db72 --- /dev/null +++ b/app/pods/search-schema/create/route.js @@ -0,0 +1,49 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model(params) { + return this.explorer.getCluster(params.clusterId, this.store); + }, + + actions: { + createSchema: function(clusterId, schemaName, schemaContent) { + let self = this; + let xmlDoc = null; + let url = `/riak/clusters/${clusterId}/search/schema/${schemaName}`; + + try { + xmlDoc = Ember.$.parseXML(schemaContent); + } catch(error) { + // TODO: Put in proper error messaging + alert('Invalid XML. Please check and make sure schema is valid xml.'); + return; + } + + if (!Ember.$(xmlDoc).find('schema').attr('name')) { + // TODO: Put in proper error messaging + alert('Solr requires that the schema tag has a name attribute. Please update your xml.'); + return; + } + + if (!Ember.$(xmlDoc).find('schema').attr('version')) { + // TODO: Put in proper error messaging + alert('Solr requires that the schema tag has a version attribute. Please update your xml.'); + return; + } + + return Ember.$.ajax({ + type: 'PUT', + url: url, + contentType: 'application/xml', + processData: false, + data: xmlDoc + }).then(function(data) { + self.transitionTo('search-schema', clusterId, schemaName); + }, function(error) { + // TODO: Put in proper error messaging + alert('Something went wrong, schema was not saved.'); + }); + } + } + +}); diff --git a/app/pods/search-schema/create/template.hbs b/app/pods/search-schema/create/template.hbs new file mode 100644 index 0000000..c5c033f --- /dev/null +++ b/app/pods/search-schema/create/template.hbs @@ -0,0 +1,34 @@ +
+ {{breadcrumb-component + clusterId=model.clusterId + pageTitle='create schema' + }} + {{view-label + pre-label='Create Schema'}} +
+ +{{#dashboard-module}} +
+ + + Create Schema + + + {{#link-to 'cluster' model.clusterId class='cancel schema-action' }} + + Cancel + {{/link-to}} +
+ +
+
+ + {{input value=schemaName class='form-control'}} +
+ +
+ + {{textarea value=schemaContent rows=10 class='form-control'}} +
+
+{{/dashboard-module}} diff --git a/app/pods/search-schema/edit/model.js b/app/pods/search-schema/edit/model.js deleted file mode 100644 index ca6bd1b..0000000 --- a/app/pods/search-schema/edit/model.js +++ /dev/null @@ -1,5 +0,0 @@ -import DS from 'ember-data'; - -export default DS.Model.extend({ - -}); diff --git a/app/pods/search-schema/edit/template.hbs b/app/pods/search-schema/edit/template.hbs index 74e89b7..95446bc 100644 --- a/app/pods/search-schema/edit/template.hbs +++ b/app/pods/search-schema/edit/template.hbs @@ -21,8 +21,11 @@ {{/link-to}} - {{content-editable - value=model.content - type="html" - tagName="pre"}} +
+        
+            {{content-editable
+            value=model.content
+            type="html"}}
+        
+    
{{/dashboard-module}} diff --git a/app/pods/search-schema/route.js b/app/pods/search-schema/route.js index af3d837..8863598 100644 --- a/app/pods/search-schema/route.js +++ b/app/pods/search-schema/route.js @@ -3,13 +3,20 @@ import $ from 'jquery'; export default Ember.Route.extend({ model(params) { + let self = this; + return this.explorer.getCluster(params.clusterId, this.store) .then(function(cluster){ - return cluster.get('searchSchemas').findBy('name', params.searchSchemaId); + let schema = cluster.get('searchSchemas').findBy('name', params.searchSchemaId); + + if (!schema) { + schema = self.explorer.createSchema(params.searchSchemaId, cluster, self.store); + } + + return schema; }); }, - // TODO: Move to init??? afterModel(model, transition) { return Ember.$.ajax({ type: 'GET', diff --git a/app/pods/search-schema/template.hbs b/app/pods/search-schema/template.hbs index fe182bb..f64b380 100644 --- a/app/pods/search-schema/template.hbs +++ b/app/pods/search-schema/template.hbs @@ -14,8 +14,12 @@ Edit Schema {{/link-to}} + + + View Raw + -
+    {{#code-highlighter language-type='XML'}}
         {{model.content}}
-    
+ {{/code-highlighter}} {{/dashboard-module}} diff --git a/app/router.js b/app/router.js index 8a74cc3..c1ff7f8 100644 --- a/app/router.js +++ b/app/router.js @@ -30,6 +30,8 @@ export default Router.map(function() { this.route('service-not-found'); }); this.route('search-index', { path: '/cluster/:clusterId/index/:searchIndexId' }); - this.route('search-schema', { path: '/cluster/:clusterId/schema/:searchSchemaId' }); - this.route('search-schema.edit', { path: '/cluster/:clusterId/schema/:searchSchemaId/edit' }); + + this.route('search-schema', { path: '/cluster/:clusterId/schema/:searchSchemaId' }); + this.route('search-schema.edit', { path: '/cluster/:clusterId/schema/:searchSchemaId/edit' }); + this.route('search-schema.create', { path: '/cluster/:clusterId/schema/create' }); }); diff --git a/app/styles/app.scss b/app/styles/app.scss index fd4b342..52e518d 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -25,6 +25,8 @@ @import "components/cluster-resource-link"; @import "components/pagination-component"; @import "components/schema-actions"; +@import "components/code-highlter"; +@import "components/content-editable"; // View specific styling @import "views/object-counter-container"; diff --git a/app/styles/components/_code-highlter.scss b/app/styles/components/_code-highlter.scss new file mode 100644 index 0000000..16da0c1 --- /dev/null +++ b/app/styles/components/_code-highlter.scss @@ -0,0 +1,10 @@ +.code-highlighter { + padding: 0; + margin: 0; + border: none; + background: none; + + code { + border-radius: 4px; + } +} diff --git a/app/styles/components/_content-editable.scss b/app/styles/components/_content-editable.scss new file mode 100644 index 0000000..d8fbde3 --- /dev/null +++ b/app/styles/components/_content-editable.scss @@ -0,0 +1,18 @@ +// Don't focus when inside of a code block +code { + .ember-content-editable { + margin-top: -50px; // Not sure why this space is being added to the component + min-height: 100px; + + &:focus { + outline: none; + } + } +} + +pre.editable { + background: #FFF; + border-color: #000; + border-radius: 0px; +} + diff --git a/app/styles/components/_schema-actions.scss b/app/styles/components/_schema-actions.scss index 2fecfd9..21fc856 100644 --- a/app/styles/components/_schema-actions.scss +++ b/app/styles/components/_schema-actions.scss @@ -19,4 +19,12 @@ .update { @extend .btn-primary; } + + .create { + @extend .btn-primary; + } + + .raw { + @extend .btn-primary; + } } diff --git a/app/templates/components/code-highlighter.hbs b/app/templates/components/code-highlighter.hbs new file mode 100644 index 0000000..803f55c --- /dev/null +++ b/app/templates/components/code-highlighter.hbs @@ -0,0 +1,4 @@ + + {{yield}} + + diff --git a/app/templates/components/search-indexes.hbs b/app/templates/components/search-indexes.hbs index 5778a0f..d970830 100644 --- a/app/templates/components/search-indexes.hbs +++ b/app/templates/components/search-indexes.hbs @@ -11,7 +11,7 @@ {{link.link-index searchIndex=index}} - {{#link-to 'search-schema' index.cluster.id index.schema.name}} + {{#link-to 'search-schema' index.cluster.id index.schema.name class='btn btn-small btn-primary'}} {{index.schema.name}} {{/link-to}} diff --git a/ember-cli-build.js b/ember-cli-build.js index 7599b05..9582b7a 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -19,7 +19,7 @@ module.exports = function(defaults) { // please specify an object with the list of modules as keys // along with the exports of each module as its value. app.import('bower_components/highlightjs/highlight.pack.js'); - app.import('bower_components/highlightjs/styles/darkula.css'); + app.import('bower_components/highlightjs/styles/default.css'); return app.toTree(); }; diff --git a/tests/integration/components/code-highlighter-test.js b/tests/integration/components/code-highlighter-test.js new file mode 100644 index 0000000..d82936d --- /dev/null +++ b/tests/integration/components/code-highlighter-test.js @@ -0,0 +1,26 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('code-highlighter', 'Integration | Component | code highlighter', { + integration: true +}); + +test('it renders', function(assert) { + assert.expect(2); + + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.render(hbs`{{code-highlighter}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#code-highlighter}} + template block text + {{/code-highlighter}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); diff --git a/tests/unit/pods/search-schema/edit/model-test.js b/tests/unit/pods/search-schema/edit/model-test.js deleted file mode 100644 index 603aee2..0000000 --- a/tests/unit/pods/search-schema/edit/model-test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { moduleForModel, test } from 'ember-qunit'; - -moduleForModel('search-schema/edit', 'Unit | Model | search schema/edit', { - // Specify the other units that are required for this test. - needs: [] -}); - -test('it exists', function(assert) { - var model = this.subject(); - // var store = this.store(); - assert.ok(!!model); -}); diff --git a/tests/unit/pods/search-schema/edit/route-test.js b/tests/unit/pods/search-schema/edit/route-test.js deleted file mode 100644 index 31b91c6..0000000 --- a/tests/unit/pods/search-schema/edit/route-test.js +++ /dev/null @@ -1,11 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('route:search-schema/edit', 'Unit | Route | search schema/edit', { - // Specify the other units that are required for this test. - // needs: ['controller:foo'] -}); - -test('it exists', function(assert) { - var route = this.subject(); - assert.ok(route); -});