-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search schema #58
Search schema #58
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
}); |
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: '' | ||
}); | ||
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.'); | ||
}); | ||
} | ||
} | ||
|
||
}); |
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}} |
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.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I've been thinking about that as well, that we need some either modal windows, or (better yet) some message/error divs under the crumb trail, etc. Alert is totally fine for now though. |
||
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); | ||
}); | ||
} | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<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> | ||
|
||
<pre class="editable"> | ||
<code> | ||
{{content-editable | ||
value=model.content | ||
type="html"}} | ||
</code> | ||
</pre> | ||
{{/dashboard-module}} |
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') | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Ember from 'ember'; | ||
import $ from 'jquery'; | ||
|
||
export default Ember.Route.extend({ | ||
model(params) { | ||
let self = this; | ||
|
||
return this.explorer.getCluster(params.clusterId, this.store) | ||
.then(function(cluster){ | ||
let schema = cluster.get('searchSchemas').findBy('name', params.searchSchemaId); | ||
|
||
if (!schema) { | ||
schema = self.explorer.createSchema(params.searchSchemaId, cluster, self.store); | ||
} | ||
|
||
return schema; | ||
}); | ||
}, | ||
|
||
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); | ||
}); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This holds the temporary values of the new schema until they are ready to be sent to the server.