From a9ed15e11ac11371ba3ab73fa571879e6c89259d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 11 Nov 2016 16:31:08 -0500 Subject: [PATCH] FIX: Remove more of those pesky View classes --- .../disable-custom-stylesheets.js.es6} | 12 ++-- .../controllers/admin-backups-index.js.es6 | 6 +- .../javascripts/admin/templates/admin.hbs | 4 +- .../admin/templates/backups-index.hbs | 7 +- .../javascripts/admin/templates/backups.hbs | 66 ++++++++++--------- .../admin/views/admin-backups.js.es6 | 25 ------- .../admin/views/admin-customize-colors.js.es6 | 3 - .../discourse-common/resolver.js.es6 | 41 +++--------- .../hide-modal-trigger.js.es6} | 0 .../initializers/live-development.js.es6 | 19 ------ .../discourse/routes/loading.js.es6 | 1 - .../discourse/templates/hide-modal.hbs | 1 + .../discourse/templates/loading.hbs | 1 + .../discourse/views/loading.js.es6 | 8 --- test/javascripts/acceptance/topic-test.js.es6 | 1 - 15 files changed, 65 insertions(+), 130 deletions(-) rename app/assets/javascripts/admin/{views/admin.js.es6 => components/disable-custom-stylesheets.js.es6} (53%) delete mode 100644 app/assets/javascripts/admin/views/admin-backups.js.es6 delete mode 100644 app/assets/javascripts/admin/views/admin-customize-colors.js.es6 rename app/assets/javascripts/discourse/{views/hide-modal.js.es6 => components/hide-modal-trigger.js.es6} (100%) delete mode 100644 app/assets/javascripts/discourse/routes/loading.js.es6 create mode 100644 app/assets/javascripts/discourse/templates/hide-modal.hbs create mode 100644 app/assets/javascripts/discourse/templates/loading.hbs delete mode 100644 app/assets/javascripts/discourse/views/loading.js.es6 diff --git a/app/assets/javascripts/admin/views/admin.js.es6 b/app/assets/javascripts/admin/components/disable-custom-stylesheets.js.es6 similarity index 53% rename from app/assets/javascripts/admin/views/admin.js.es6 rename to app/assets/javascripts/admin/components/disable-custom-stylesheets.js.es6 index fc4a611fe47..f4d86899d08 100644 --- a/app/assets/javascripts/admin/views/admin.js.es6 +++ b/app/assets/javascripts/admin/components/disable-custom-stylesheets.js.es6 @@ -1,12 +1,14 @@ -export default Ember.View.extend({ - _disableCustomStylesheets: function() { +export default Ember.Component.extend({ + willInsertElement() { + this._super(); if (this.session.get("disableCustomCSS")) { $("link.custom-css").attr("rel", ""); this.session.set("disableCustomCSS", false); } - }.on("willInsertElement"), + }, - _enableCustomStylesheets: function() { + willDestroyElement() { + this._super(); $("link.custom-css").attr("rel", "stylesheet"); - }.on("willDestroyElement") + } }); diff --git a/app/assets/javascripts/admin/controllers/admin-backups-index.js.es6 b/app/assets/javascripts/admin/controllers/admin-backups-index.js.es6 index 605ebe83af1..558b9b4973e 100644 --- a/app/assets/javascripts/admin/controllers/admin-backups-index.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-backups-index.js.es6 @@ -1,3 +1,4 @@ +import DiscourseURL from 'discourse/lib/url'; import { ajax } from 'discourse/lib/ajax'; export default Ember.Controller.extend({ @@ -35,8 +36,11 @@ export default Ember.Controller.extend({ } else { this._toggleReadOnlyMode(false); } - } + }, + download(backup) { + DiscourseURL.redirectTo(backup.get('link')); + } }, _toggleReadOnlyMode(enable) { diff --git a/app/assets/javascripts/admin/templates/admin.hbs b/app/assets/javascripts/admin/templates/admin.hbs index e29125aec3d..77904edc48b 100644 --- a/app/assets/javascripts/admin/templates/admin.hbs +++ b/app/assets/javascripts/admin/templates/admin.hbs @@ -1,4 +1,4 @@ -
+{{#disable-custom-stylesheets class="container"}}
@@ -34,4 +34,4 @@
-
+{{/disable-custom-stylesheets}} diff --git a/app/assets/javascripts/admin/templates/backups-index.hbs b/app/assets/javascripts/admin/templates/backups-index.hbs index 308e73f0fdb..a8220a4e1ac 100644 --- a/app/assets/javascripts/admin/templates/backups-index.hbs +++ b/app/assets/javascripts/admin/templates/backups-index.hbs @@ -19,7 +19,12 @@ {{human-size backup.size}}
- {{fa-icon "download"}}{{i18n 'admin.backups.operations.download.label'}} + {{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}} {{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"}} diff --git a/app/assets/javascripts/admin/templates/backups.hbs b/app/assets/javascripts/admin/templates/backups.hbs index 7562754c08c..ea8bc189873 100644 --- a/app/assets/javascripts/admin/templates/backups.hbs +++ b/app/assets/javascripts/admin/templates/backups.hbs @@ -1,35 +1,37 @@ -
-
- +
+
+
+ +
+
+ {{#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}} +
-
- {{#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}} -
-
-
- {{outlet}} +
+ {{outlet}} +
diff --git a/app/assets/javascripts/admin/views/admin-backups.js.es6 b/app/assets/javascripts/admin/views/admin-backups.js.es6 deleted file mode 100644 index a779f4971d2..00000000000 --- a/app/assets/javascripts/admin/views/admin-backups.js.es6 +++ /dev/null @@ -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") - -}); diff --git a/app/assets/javascripts/admin/views/admin-customize-colors.js.es6 b/app/assets/javascripts/admin/views/admin-customize-colors.js.es6 deleted file mode 100644 index ac5df78af58..00000000000 --- a/app/assets/javascripts/admin/views/admin-customize-colors.js.es6 +++ /dev/null @@ -1,3 +0,0 @@ -export default Ember.View.extend({ - templateName: 'admin/templates/customize_colors' -}); diff --git a/app/assets/javascripts/discourse-common/resolver.js.es6 b/app/assets/javascripts/discourse-common/resolver.js.es6 index a3068b91b1e..2462c791eb1 100644 --- a/app/assets/javascripts/discourse-common/resolver.js.es6 +++ b/app/assets/javascripts/discourse-common/resolver.js.es6 @@ -6,29 +6,12 @@ var get = Ember.get; var LOADING_WHITELIST = ['badges', 'userActivity', 'userPrivateMessages', 'admin', 'adminFlags', 'user', 'preferences', 'adminEmail', 'adminUsersList']; -var _dummyRoute; -var _loadingView; - - const _options = {}; export function setResolverOption(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) { const nameParts = fullName.split(":"), type = nameParts[0], fullNameWithoutType = nameParts[1], @@ -113,7 +96,7 @@ export function buildResolver(baseName) { }, resolveView(parsedName) { - return this.findLoadingView(parsedName) || this.customResolve(parsedName) || this._super(parsedName); + return this.customResolve(parsedName) || this._super(parsedName); }, resolveHelper(parsedName) { @@ -135,7 +118,13 @@ export function buildResolver(baseName) { }, 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) { @@ -143,22 +132,10 @@ export function buildResolver(baseName) { this.findPluginTemplate(parsedName) || this.findMobileTemplate(parsedName) || this.findTemplate(parsedName) || + this.findLoadingTemplate(parsedName) || 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) { var pluginParsedName = this.parseName(parsedName.fullName.replace("template:", "template:javascripts/")); return this.findTemplate(pluginParsedName); diff --git a/app/assets/javascripts/discourse/views/hide-modal.js.es6 b/app/assets/javascripts/discourse/components/hide-modal-trigger.js.es6 similarity index 100% rename from app/assets/javascripts/discourse/views/hide-modal.js.es6 rename to app/assets/javascripts/discourse/components/hide-modal-trigger.js.es6 diff --git a/app/assets/javascripts/discourse/initializers/live-development.js.es6 b/app/assets/javascripts/discourse/initializers/live-development.js.es6 index a3c8afa51a3..f73172e154e 100644 --- a/app/assets/javascripts/discourse/initializers/live-development.js.es6 +++ b/app/assets/javascripts/discourse/initializers/live-development.js.es6 @@ -1,4 +1,3 @@ -import loadScript from 'discourse/lib/load-script'; import DiscourseURL from 'discourse/lib/url'; // Use the message bus for live reloading of components for faster development. @@ -47,24 +46,6 @@ export default { if (me === "refresh") { // Refresh if necessary 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 { $('link').each(function() { // TODO: stop bundling css in DEV please diff --git a/app/assets/javascripts/discourse/routes/loading.js.es6 b/app/assets/javascripts/discourse/routes/loading.js.es6 deleted file mode 100644 index 9d032c9e3ba..00000000000 --- a/app/assets/javascripts/discourse/routes/loading.js.es6 +++ /dev/null @@ -1 +0,0 @@ -export default Ember.Route.extend(); diff --git a/app/assets/javascripts/discourse/templates/hide-modal.hbs b/app/assets/javascripts/discourse/templates/hide-modal.hbs new file mode 100644 index 00000000000..69c2e656d9f --- /dev/null +++ b/app/assets/javascripts/discourse/templates/hide-modal.hbs @@ -0,0 +1 @@ +{{hide-modal-trigger}} diff --git a/app/assets/javascripts/discourse/templates/loading.hbs b/app/assets/javascripts/discourse/templates/loading.hbs new file mode 100644 index 00000000000..7b998117e8e --- /dev/null +++ b/app/assets/javascripts/discourse/templates/loading.hbs @@ -0,0 +1 @@ +{{loading-spinner}} diff --git a/app/assets/javascripts/discourse/views/loading.js.es6 b/app/assets/javascripts/discourse/views/loading.js.es6 deleted file mode 100644 index 2d6227695fb..00000000000 --- a/app/assets/javascripts/discourse/views/loading.js.es6 +++ /dev/null @@ -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); - } -})); diff --git a/test/javascripts/acceptance/topic-test.js.es6 b/test/javascripts/acceptance/topic-test.js.es6 index b3141c129af..ea8471d71c5 100644 --- a/test/javascripts/acceptance/topic-test.js.es6 +++ b/test/javascripts/acceptance/topic-test.js.es6 @@ -10,7 +10,6 @@ test("Share Popup", () => { click("[data-share-url]:eq(0)"); andThen(() => { 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');