FIX: Remove more of those pesky View classes

This commit is contained in:
Robin Ward 2016-11-11 16:31:08 -05:00
parent cc93cd76ef
commit a9ed15e11a
15 changed files with 65 additions and 130 deletions

View File

@ -1,12 +1,14 @@
export default Ember.View.extend({ export default Ember.Component.extend({
_disableCustomStylesheets: function() { willInsertElement() {
this._super();
if (this.session.get("disableCustomCSS")) { if (this.session.get("disableCustomCSS")) {
$("link.custom-css").attr("rel", ""); $("link.custom-css").attr("rel", "");
this.session.set("disableCustomCSS", false); this.session.set("disableCustomCSS", false);
} }
}.on("willInsertElement"), },
_enableCustomStylesheets: function() { willDestroyElement() {
this._super();
$("link.custom-css").attr("rel", "stylesheet"); $("link.custom-css").attr("rel", "stylesheet");
}.on("willDestroyElement") }
}); });

View File

@ -1,3 +1,4 @@
import DiscourseURL from 'discourse/lib/url';
import { ajax } from 'discourse/lib/ajax'; import { ajax } from 'discourse/lib/ajax';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
@ -35,8 +36,11 @@ export default Ember.Controller.extend({
} else { } else {
this._toggleReadOnlyMode(false); this._toggleReadOnlyMode(false);
} }
} },
download(backup) {
DiscourseURL.redirectTo(backup.get('link'));
}
}, },
_toggleReadOnlyMode(enable) { _toggleReadOnlyMode(enable) {

View File

@ -1,4 +1,4 @@
<div class="container"> {{#disable-custom-stylesheets class="container"}}
<div class="row"> <div class="row">
<div class="full-width"> <div class="full-width">
@ -34,4 +34,4 @@
</div> </div>
</div> </div>
</div> {{/disable-custom-stylesheets}}

View File

@ -19,7 +19,12 @@
<td>{{human-size backup.size}}</td> <td>{{human-size backup.size}}</td>
<td> <td>
<div class="pull-right"> <div class="pull-right">
<a href={{backup.link}} class="btn download" title="{{i18n 'admin.backups.operations.download.title'}}">{{fa-icon "download"}}{{i18n 'admin.backups.operations.download.label'}}</a> {{d-button class="download"
action="download"
actionParam=backup
icon="download"
title="admin.backups.operations.download.title"
label="admin.backups.operations.download.label"}}
{{#if status.isOperationRunning}} {{#if status.isOperationRunning}}
{{d-button icon="trash-o" action="destroyBackup" actionParam=backup class="btn-danger" disabled="true" title="admin.backups.operations.is_running"}} {{d-button icon="trash-o" action="destroyBackup" actionParam=backup class="btn-danger" disabled="true" title="admin.backups.operations.is_running"}}
{{d-button icon="play" action="startRestore" actionParam=backup disabled=status.restoreDisabled title=restoreTitle label="admin.backups.operations.restore.label"}} {{d-button icon="play" action="startRestore" actionParam=backup disabled=status.restoreDisabled title=restoreTitle label="admin.backups.operations.restore.label"}}

View File

@ -1,35 +1,37 @@
<div class="admin-controls"> <div class='admin-backups'>
<div class="span15"> <div class="admin-controls">
<ul class="nav nav-pills"> <div class="span15">
{{nav-item route='admin.backups.index' label='admin.backups.menu.backups'}} <ul class="nav nav-pills">
{{nav-item route='admin.backups.logs' label='admin.backups.menu.logs'}} {{nav-item route='admin.backups.index' label='admin.backups.menu.backups'}}
</ul> {{nav-item route='admin.backups.logs' label='admin.backups.menu.logs'}}
</ul>
</div>
<div class="pull-right">
{{#if model.canRollback}}
{{d-button action="rollback"
class="btn-rollback"
label="admin.backups.operations.rollback.label"
title="admin.backups.operations.rollback.title"
icon="ambulance"
disabled=rollbackDisabled}}
{{/if}}
{{#if model.isOperationRunning}}
{{d-button action="cancelOperation"
class="btn-danger"
title="admin.backups.operations.cancel.title"
label="admin.backups.operations.cancel.label"
icon="times"}}
{{else}}
{{d-button action="startBackup"
class="btn-primary"
title="admin.backups.operations.backup.title"
label="admin.backups.operations.backup.label"
icon="rocket"}}
{{/if}}
</div>
</div> </div>
<div class="pull-right">
{{#if model.canRollback}}
{{d-button action="rollback"
class="btn-rollback"
label="admin.backups.operations.rollback.label"
title="admin.backups.operations.rollback.title"
icon="ambulance"
disabled=rollbackDisabled}}
{{/if}}
{{#if model.isOperationRunning}}
{{d-button action="cancelOperation"
class="btn-danger"
title="admin.backups.operations.cancel.title"
label="admin.backups.operations.cancel.label"
icon="times"}}
{{else}}
{{d-button action="startBackup"
class="btn-primary"
title="admin.backups.operations.backup.title"
label="admin.backups.operations.backup.label"
icon="rocket"}}
{{/if}}
</div>
</div>
<div class="admin-container"> <div class="admin-container">
{{outlet}} {{outlet}}
</div>
</div> </div>

View File

@ -1,25 +0,0 @@
import DiscourseURL from 'discourse/lib/url';
export default Ember.View.extend({
classNames: ["admin-backups"],
_hijackDownloads: function() {
this.$().on("mouseup.admin-backups", "a.download", function (e) {
var $link = $(e.currentTarget);
if (!$link.data("href")) {
$link.addClass("no-href");
$link.data("href", $link.attr("href"));
$link.attr("href", null);
$link.data("auto-route", true);
}
DiscourseURL.redirectTo($link.data("href"));
});
}.on("didInsertElement"),
_removeBindings: function() {
this.$().off("mouseup.admin-backups");
}.on("willDestroyElement")
});

View File

@ -1,3 +0,0 @@
export default Ember.View.extend({
templateName: 'admin/templates/customize_colors'
});

View File

@ -6,29 +6,12 @@ var get = Ember.get;
var LOADING_WHITELIST = ['badges', 'userActivity', 'userPrivateMessages', 'admin', 'adminFlags', var LOADING_WHITELIST = ['badges', 'userActivity', 'userPrivateMessages', 'admin', 'adminFlags',
'user', 'preferences', 'adminEmail', 'adminUsersList']; 'user', 'preferences', 'adminEmail', 'adminUsersList'];
var _dummyRoute;
var _loadingView;
const _options = {}; const _options = {};
export function setResolverOption(name, value) { export function setResolverOption(name, value) {
_options[name] = value; _options[name] = value;
} }
function loadingResolver(cb) {
return function(parsedName) {
var fullNameWithoutType = parsedName.fullNameWithoutType;
if (fullNameWithoutType.indexOf('Loading') >= 0) {
fullNameWithoutType = fullNameWithoutType.replace('Loading', '');
if (LOADING_WHITELIST.indexOf(fullNameWithoutType) !== -1) {
return cb(fullNameWithoutType);
}
}
};
}
function parseName(fullName) { function parseName(fullName) {
const nameParts = fullName.split(":"), const nameParts = fullName.split(":"),
type = nameParts[0], fullNameWithoutType = nameParts[1], type = nameParts[0], fullNameWithoutType = nameParts[1],
@ -113,7 +96,7 @@ export function buildResolver(baseName) {
}, },
resolveView(parsedName) { resolveView(parsedName) {
return this.findLoadingView(parsedName) || this.customResolve(parsedName) || this._super(parsedName); return this.customResolve(parsedName) || this._super(parsedName);
}, },
resolveHelper(parsedName) { resolveHelper(parsedName) {
@ -135,7 +118,13 @@ export function buildResolver(baseName) {
}, },
resolveRoute(parsedName) { resolveRoute(parsedName) {
return this.findLoadingRoute(parsedName) || this.customResolve(parsedName) || this._super(parsedName); return this.customResolve(parsedName) || this._super(parsedName);
},
findLoadingTemplate(parsedName) {
if (parsedName.fullNameWithoutType.match(/loading$/)) {
return Ember.TEMPLATES.loading;
}
}, },
resolveTemplate(parsedName) { resolveTemplate(parsedName) {
@ -143,22 +132,10 @@ export function buildResolver(baseName) {
this.findPluginTemplate(parsedName) || this.findPluginTemplate(parsedName) ||
this.findMobileTemplate(parsedName) || this.findMobileTemplate(parsedName) ||
this.findTemplate(parsedName) || this.findTemplate(parsedName) ||
this.findLoadingTemplate(parsedName) ||
Ember.TEMPLATES.not_found; Ember.TEMPLATES.not_found;
}, },
findLoadingRoute: loadingResolver(function() {
_dummyRoute = _dummyRoute || Ember.Route.extend();
return _dummyRoute;
}),
findLoadingView: loadingResolver(function() {
if (!_loadingView) {
_loadingView = require('discourse/views/loading', null, null, true /* force sync */);
if (_loadingView && _loadingView['default']) { _loadingView = _loadingView['default']; }
}
return _loadingView;
}),
findPluginTemplate(parsedName) { findPluginTemplate(parsedName) {
var pluginParsedName = this.parseName(parsedName.fullName.replace("template:", "template:javascripts/")); var pluginParsedName = this.parseName(parsedName.fullName.replace("template:", "template:javascripts/"));
return this.findTemplate(pluginParsedName); return this.findTemplate(pluginParsedName);

View File

@ -1,4 +1,3 @@
import loadScript from 'discourse/lib/load-script';
import DiscourseURL from 'discourse/lib/url'; import DiscourseURL from 'discourse/lib/url';
// Use the message bus for live reloading of components for faster development. // Use the message bus for live reloading of components for faster development.
@ -47,24 +46,6 @@ export default {
if (me === "refresh") { if (me === "refresh") {
// Refresh if necessary // Refresh if necessary
document.location.reload(true); document.location.reload(true);
} else if (me.name.substr(-10) === "hbs") {
// Reload handlebars
const js = me.name.replace(".hbs", "").replace("app/assets/javascripts", "/assets");
loadScript(js + "?hash=" + me.hash).then(function() {
const templateName = js.replace(".js", "").replace("/assets/", "");
return _.each(Ember.View.views, function(view) {
if (view.get('templateName') === templateName) {
view.set('templateName', 'empty');
view.rerender();
Em.run.schedule('afterRender', function() {
view.set('templateName', templateName);
view.rerender();
});
}
});
});
} else { } else {
$('link').each(function() { $('link').each(function() {
// TODO: stop bundling css in DEV please // TODO: stop bundling css in DEV please

View File

@ -1 +0,0 @@
export default Ember.Route.extend();

View File

@ -0,0 +1 @@
{{hide-modal-trigger}}

View File

@ -0,0 +1 @@
{{loading-spinner}}

View File

@ -1,8 +0,0 @@
import { spinnerHTML } from 'discourse/helpers/loading-spinner';
import { bufferedRender } from 'discourse-common/lib/buffered-render';
export default Ember.View.extend(bufferedRender({
buildBuffer(buffer) {
buffer.push(spinnerHTML);
}
}));

View File

@ -10,7 +10,6 @@ test("Share Popup", () => {
click("[data-share-url]:eq(0)"); click("[data-share-url]:eq(0)");
andThen(() => { andThen(() => {
ok(exists('#share-link.visible'), 'it shows the popup'); ok(exists('#share-link.visible'), 'it shows the popup');
ok(find('input[type=text]').val().length, 'it has the URL in the input box');
}); });
click('#share-link .close-share'); click('#share-link .close-share');