Skip to content

Commit

Permalink
Search Schema model, associations, and views
Browse files Browse the repository at this point in the history
  • Loading branch information
paultannenbaum committed Dec 18, 2015
1 parent c0e3334 commit d501ad4
Show file tree
Hide file tree
Showing 25 changed files with 359 additions and 60 deletions.
2 changes: 1 addition & 1 deletion app/adapters/search-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var SearchIndexAdapter = DS.RESTAdapter.extend({
let url = this.buildURL(type.modelName, null, null, 'query', query);

let promise = this.ajax(url, 'GET').then(function(indexes) {

indexes.forEach(function(index) {
index.id = `${query.clusterId}/${index.name}`;
});
Expand All @@ -23,3 +22,4 @@ var SearchIndexAdapter = DS.RESTAdapter.extend({
});

export default SearchIndexAdapter;

7 changes: 7 additions & 0 deletions app/pods/cluster/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ var Cluster = DS.Model.extend({
*/
searchIndexes: DS.hasMany('search-index', { async: true }),

/**
* Search schemas created on the cluster
* @property searchSchemas
* @type Array<BucketType>
*/
searchSchemas: DS.hasMany('search-schema', { async: true }),

/**
* Is this cluster in Dev Mode? Set in the Explorer config file.
* Dev mode allows expensive operations like list keys, delete bucket, etc.
Expand Down
4 changes: 1 addition & 3 deletions app/pods/cluster/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@

{{#dashboard-module label='Search Indexes'}}
{{#if model.searchIndexes}}
{{search-indexes
indexes=model.searchIndexes
clusterProxyUrl=model.proxyUrl}}
{{search-indexes indexes=model.searchIndexes}}
{{else}}
<p>No search indexes found</p>
{{/if}}
Expand Down
36 changes: 17 additions & 19 deletions app/pods/search-index/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ import DS from 'ember-data';

var SearchIndex = DS.Model.extend({
/**
* Riak cluster in the search index wascreated on
* Riak cluster the search index was created on
*
* @property cluster
* @type {DS.Model} Cluster
* @writeOnce
*/
cluster: DS.belongsTo('cluster'),
cluster: DS.belongsTo('cluster', { async: true }),

/**
* Schema the search index is using
*
* @property schema
* @type {DS.Model} Search Schema
* @writeOnce
*/
schema: DS.belongsTo('search-schema', { async: true }),

/**
* Returns the search index name/id
Expand All @@ -25,11 +34,12 @@ var SearchIndex = DS.Model.extend({
nVal: DS.attr('number', {defaultValue: 3}),

/**
* Name of the schema the index is using
* @property schema
* @type String
* Holds the value of the schema name that index is using.
* Temporary hack until basho-labs/riak_explorer#89 is completed
* @property nVal
* @type Integer
*/
schema: DS.attr('string'),
schemaRef: DS.attr('string'),

/**
* Ember.Array of bucket types on the current cluster using the index
Expand All @@ -40,19 +50,7 @@ var SearchIndex = DS.Model.extend({
let bucketTypes = this.get('cluster').get('bucketTypes');

return bucketTypes.filterBy('index.name', this.get('name'));
}.property('cluster.bucketTypes'),

/**
* Returns a formatted schema url
* @property schemaUrl
* @type String
*/
schemaUrl: function() {
let proxyURL = this.get('cluster').get('proxyUrl');
let schema = this.get('schema');

return `${proxyURL}/search/schema/${schema}`;
}.property('schema', 'cluster.proxyUrl')
}.property('cluster.bucketTypes')
});

export default SearchIndex;
4 changes: 3 additions & 1 deletion app/pods/search-index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
<tr>
<td class="key">Schema</td>
<td class="value">
<a href={{model.schemaUrl}}>{{model.schema}}</a>
{{#link-to 'search-schema' model.cluster.id model.schema.name}}
{{model.schema.name}}
{{/link-to}}
</td>
</tr>
<tr>
Expand Down
5 changes: 5 additions & 0 deletions app/pods/search-schema/edit/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import DS from 'ember-data';

export default DS.Model.extend({

});
55 changes: 55 additions & 0 deletions app/pods/search-schema/edit/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Ember from 'ember';

export default Ember.Route.extend({
model(params) {
return this.explorer.getCluster(params.clusterId, this.store)
.then(function(cluster){
return cluster.get('searchSchemas').findBy('name', params.searchSchemaId);
});
},

afterModel(model, transition) {
if (!model.get('content')) {
return Ember.$.ajax({
type: 'GET',
url: model.get('url'),
dataType: 'xml'
}).then(function(data) {
let xmlString = (new XMLSerializer()).serializeToString(data);
model.set('content', xmlString);
});
}
},

actions: {
updateSchema: function(schema) {
let xmlString = schema.get('content');
let self = this;
let xmlDoc = null;
let clusterId = schema.get('cluster').get('id');
let schemaId = schema.get('name');

try {
xmlDoc = Ember.$.parseXML(xmlString);
} catch(error) {
// TODO: Put in proper error messaging
alert('Invalid XML. Please check and make sure schema is valid xml.');
return;
}

return Ember.$.ajax({
type: 'PUT',
url: schema.get('url'),
contentType: 'application/xml',
processData: false,
data: xmlDoc
}).then(function(data) {
self.transitionTo('search-schema', clusterId, schemaId);
}, function(error) {
// TODO: Put in proper error messaging
alert('Something went wrong, schema was not saved.');
self.transitionTo('search-schema', clusterId, schemaId);
});
}
}
});
28 changes: 28 additions & 0 deletions app/pods/search-schema/edit/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div class='view-header'>
{{breadcrumb-component
clusterId=model.cluster.id
pageTitle=model.name
}}
{{view-label
pre-label='Search Schema'
label=model.name}}
</div>

{{#dashboard-module}}
<div class="schema-actions">
<span class="update schema-action" {{action 'updateSchema' model}}>
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Update Schema
</span>

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

{{content-editable
value=model.content
type="html"
tagName="pre"}}
{{/dashboard-module}}
28 changes: 28 additions & 0 deletions app/pods/search-schema/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import DS from 'ember-data';

export default DS.Model.extend({
/**
* Riak cluster the search schema was created on
*
* @property cluster
* @type {DS.Model} Cluster
* @writeOnce
*/
cluster: DS.belongsTo('cluster', { async: true }),

name: DS.attr('string'),

content: DS.attr(),

/**
* Returns a formatted schema url
* @method url
* @returns String
*/
url: function() {
let proxyURL = this.get('cluster').get('proxyUrl');
let name = this.get('name');

return `${proxyURL}/search/schema/${name}`;
}.property('name', 'cluster.proxyUrl')
});
23 changes: 23 additions & 0 deletions app/pods/search-schema/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Ember from 'ember';
import $ from 'jquery';

export default Ember.Route.extend({
model(params) {
return this.explorer.getCluster(params.clusterId, this.store)
.then(function(cluster){
return cluster.get('searchSchemas').findBy('name', params.searchSchemaId);
});
},

// TODO: Move to init???
afterModel(model, transition) {
return Ember.$.ajax({
type: 'GET',
url: model.get('url'),
dataType: 'xml'
}).then(function(data) {
let xmlString = (new XMLSerializer()).serializeToString(data);
model.set('content', xmlString);
});
}
});
21 changes: 21 additions & 0 deletions app/pods/search-schema/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class='view-header'>
{{breadcrumb-component
clusterId=model.cluster.id
pageTitle=model.name
}}
{{view-label
pre-label='Search Schema'
label=model.name}}
</div>

{{#dashboard-module}}
<div class="schema-actions">
{{#link-to 'search-schema.edit' model.cluster.id model.name class='edit schema-action' }}
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
Edit Schema
{{/link-to}}
</div>
<pre>
{{model.content}}
</pre>
{{/dashboard-module}}
2 changes: 2 additions & 0 deletions app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ 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' });
});
2 changes: 1 addition & 1 deletion app/routes/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default Ember.Route.extend({
error: function(error) {
// An error has occurred that wasn't handled by any route.
console.log('Unknown error: %O', error);
this.transitionTo('errors.unknown');
this.transitionTo('error.unknown');
}
},

Expand Down
8 changes: 8 additions & 0 deletions app/serializers/search-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,13 @@ export default ApplicationSerializer.extend({
};

return this._super(store, primaryModelClass, newPayload, id, requestType);
},

// TODO: Remove once basho-labs/riak_explorer#89 is completed
normalize(modelClass, resourceHash, prop) {
resourceHash.schema_ref = resourceHash.schema;
delete resourceHash.schema;

return this._super(modelClass, resourceHash, prop);
}
});
Loading

0 comments on commit d501ad4

Please sign in to comment.