Skip to content

Commit

Permalink
Schema CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
paultannenbaum committed Dec 18, 2015
1 parent 465d6f0 commit e977147
Show file tree
Hide file tree
Showing 22 changed files with 207 additions and 42 deletions.
14 changes: 14 additions & 0 deletions app/components/code-highlighter.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
1 change: 1 addition & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
{{content-for 'head'}}
<link rel="stylesheet" href="assets/ember-riak-explorer.css">
<link rel="stylesheet" href="assets/vendor.css">
{{content-for 'head-footer'}}
</head>
<body>
Expand Down
7 changes: 6 additions & 1 deletion app/pods/cluster/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
Create new search schema
{{/link-to}}

{{#if model.searchIndexes}}
{{search-indexes indexes=model.searchIndexes}}
{{else}}
Expand Down
2 changes: 1 addition & 1 deletion app/pods/search-index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<tr>
<td class="key">Schema</td>
<td class="value">
{{#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}}
</td>
Expand Down
6 changes: 6 additions & 0 deletions app/pods/search-schema/create/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Ember from 'ember';

export default Ember.Controller.extend({
schemaName: '',
schemaContent: ''
});
49 changes: 49 additions & 0 deletions app/pods/search-schema/create/route.js
Original file line number Diff line number Diff line change
@@ -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.');
});
}
}

});
34 changes: 34 additions & 0 deletions app/pods/search-schema/create/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class='view-header'>
{{breadcrumb-component
clusterId=model.clusterId
pageTitle='create schema'
}}
{{view-label
pre-label='Create Schema'}}
</div>

{{#dashboard-module}}
<div class="schema-actions">
<span class="create schema-action" {{action 'createSchema' model.clusterId schemaName schemaContent}}>
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Create Schema
</span>

{{#link-to 'cluster' model.clusterId class='cancel schema-action' }}
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
Cancel
{{/link-to}}
</div>

<form>
<div class="form-group">
<label>Schema Name</label>
{{input value=schemaName class='form-control'}}
</div>

<div class="form-group">
<label>Schema XML</label>
{{textarea value=schemaContent rows=10 class='form-control'}}
</div>
</form>
{{/dashboard-module}}
5 changes: 0 additions & 5 deletions app/pods/search-schema/edit/model.js

This file was deleted.

11 changes: 7 additions & 4 deletions app/pods/search-schema/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
{{/link-to}}
</div>

{{content-editable
value=model.content
type="html"
tagName="pre"}}
<pre class="editable">
<code>
{{content-editable
value=model.content
type="html"}}
</code>
</pre>
{{/dashboard-module}}
11 changes: 9 additions & 2 deletions app/pods/search-schema/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 6 additions & 2 deletions app/pods/search-schema/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Edit Schema
{{/link-to}}
<a href={{model.url}} target="_blank" class='raw schema-action'>
<span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span>
View Raw
</a>
</div>
<pre>
{{#code-highlighter language-type='XML'}}
{{model.content}}
</pre>
{{/code-highlighter}}
{{/dashboard-module}}
6 changes: 4 additions & 2 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
2 changes: 2 additions & 0 deletions app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
10 changes: 10 additions & 0 deletions app/styles/components/_code-highlter.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.code-highlighter {
padding: 0;
margin: 0;
border: none;
background: none;

code {
border-radius: 4px;
}
}
18 changes: 18 additions & 0 deletions app/styles/components/_content-editable.scss
Original file line number Diff line number Diff line change
@@ -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;
}

8 changes: 8 additions & 0 deletions app/styles/components/_schema-actions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@
.update {
@extend .btn-primary;
}

.create {
@extend .btn-primary;
}

.raw {
@extend .btn-primary;
}
}
4 changes: 4 additions & 0 deletions app/templates/components/code-highlighter.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<code class={{language-type}}>
{{yield}}
</code>

2 changes: 1 addition & 1 deletion app/templates/components/search-indexes.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<tr>
<td>{{link.link-index searchIndex=index}}</td>
<td>
{{#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}}
</td>
Expand Down
2 changes: 1 addition & 1 deletion ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
26 changes: 26 additions & 0 deletions tests/integration/components/code-highlighter-test.js
Original file line number Diff line number Diff line change
@@ -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');
});
12 changes: 0 additions & 12 deletions tests/unit/pods/search-schema/edit/model-test.js

This file was deleted.

11 changes: 0 additions & 11 deletions tests/unit/pods/search-schema/edit/route-test.js

This file was deleted.

0 comments on commit e977147

Please sign in to comment.