FIX: Old Ember idioms

This commit is contained in:
Robin Ward 2016-11-09 11:58:18 -05:00
parent 414cda5578
commit 8d72e979a5
7 changed files with 32 additions and 24 deletions

View File

@ -1,18 +1,19 @@
import debounce from 'discourse/lib/debounce';
import highlightSyntax from 'discourse/lib/highlight-syntax';
import { bufferedRender } from 'discourse-common/lib/buffered-render';
export default Ember.Component.extend({
render(buffer) {
export default Ember.Component.extend(bufferedRender({
buildBuffer(buffer) {
buffer.push("<pre><code class='" + this.get('codeClass') + "'>");
buffer.push(Handlebars.Utils.escapeExpression(this.get('value')));
buffer.push("</code></pre>");
},
_refreshHighlight: debounce(function() {
this.rerender();
this.rerenderBuffer();
}, 50).observes('value'),
_applyHighlight: function() {
highlightSyntax(this.$());
}.on('didInsertElement')
});
}));

View File

@ -38,19 +38,26 @@ export default Ember.Component.extend({
boolTypes: [ {name: I18n.t('explorer.types.bool.true'), id: 'Y'}, {name: I18n.t('explorer.types.bool.false'), id: 'N'}, {name: I18n.t('explorer.types.bool.null_'), id: '#null'} ],
value: function(key, value, previousValue) {
if (arguments.length > 1) {
value: Ember.computed('params', 'info.identifier', {
get() {
return this.get('params')[this.get('info.identifier')];
},
set(key, value) {
this.get('params')[this.get('info.identifier')] = value.toString();
return value;
}
return this.get('params')[this.get('info.identifier')];
}.property('params', 'info.identifier'),
}),
valueBool: function(key, value, previousValue) {
if (arguments.length > 1) {
this.get('params')[this.get('info.identifier')] = (!!value).toString();
valueBool: Ember.computed('params', 'info.identifier', {
get() {
return this.get('params')[this.get('info.identifier')] !== 'false';
},
set(key, value) {
value = !!value;
this.get('params')[this.get('info.identifier')] = value.toString();
return value;
}
return this.get('params')[this.get('info.identifier')] !== 'false';
}.property('params', 'info.identifier'),
}),
valid: function() {
const type = this.get('info.type'),

View File

@ -1,5 +1,6 @@
import { ajax } from 'discourse/lib/ajax';
import Badge from 'discourse/models/badge';
import { getOwner } from 'discourse-common/lib/get-owner';
function randomIdShort() {
return 'xxxxxxxx'.replace(/[xy]/g, function() {
@ -66,7 +67,7 @@ const QueryResultComponent = Ember.Component.extend({
}.property('content', 'columns.@each'),
fallbackTemplate: function() {
return this.container.lookup('template:explorer/text.raw');
return getOwner(this).lookup('template:explorer/text.raw');
}.property(),
columnTemplates: function() {
@ -79,7 +80,8 @@ const QueryResultComponent = Ember.Component.extend({
if (self.get('content.colrender')[idx]) {
viewName = self.get('content.colrender')[idx];
}
return {name: viewName, template: self.container.lookup('template:explorer/' + viewName + '.raw')};
const template = getOwner(self).lookup('template:explorer/' + viewName + '.raw');
return {name: viewName, template };
});
}.property('content', 'columns.@each'),

View File

@ -1,7 +1,6 @@
import { categoryLinkHTML } from 'discourse/helpers/category-link';
import { autoUpdatingRelativeAge } from 'discourse/lib/formatter';
import { bufferedRender } from 'discourse-common/lib/buffered-render';
function icon_or_image_replacement(str, ctx) {
str = Ember.get(ctx.contexts[0], str);
@ -28,10 +27,10 @@ function bound_date_replacement(str, ctx) {
const esc = Handlebars.Utils.escapeExpression;
const QueryRowContentComponent = Ember.Component.extend({
const QueryRowContentComponent = Ember.Component.extend(bufferedRender({
tagName: "tr",
render: function(buffer) {
buildBuffer(buffer) {
const self = this;
const row = this.get('row');
const parent = self.get('parent');
@ -76,6 +75,6 @@ const QueryRowContentComponent = Ember.Component.extend({
buffer.push("<td>" + parts.join("</td><td>") + "</td>");
}
});
}));
export default QueryRowContentComponent;

View File

@ -5,7 +5,7 @@ import { ajax } from 'discourse/lib/ajax';
const NoQuery = Query.create({name: "No queries", fake: true});
export default Ember.ArrayController.extend({
export default Ember.Controller.extend({
queryParams: { selectedQueryId: "id" },
selectedQueryId: null,
showResults: false,
@ -44,7 +44,7 @@ export default Ember.ArrayController.extend({
}.observes('editing'),
addCreatedRecord(record) {
this.pushObject(record);
this.get('model').pushObject(record);
this.set('selectedQueryId', Ember.get(record, 'id'));
this.get('selectedItem').set('dirty', false);
this.set('showResults', false);

View File

@ -2,7 +2,6 @@ import { ajax } from 'discourse/lib/ajax';
export default Discourse.Route.extend({
controllerName: 'admin-plugins-explorer',
queryParams: { id: { replace: true } },
model() {
const p1 = this.store.findAll('query');

View File

@ -22,7 +22,7 @@
</tr>
</thead>
<tbody>
{{~#each row in rows}}
{{~#each rows as |row|}}
{{~query-row-content row=row columnTemplates=columnTemplates parent=controller}}
{{~/each}}
</tbody>