From a94f06ff7843bdd9b3904c73ad97e522f666ef11 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 10 Nov 2016 14:35:53 -0500 Subject: [PATCH] Remove the `ScrollTop` Mixin --- .../admin/components/site-setting.js.es6 | 3 +- .../admin/templates/badges-index.hbs | 4 +- .../admin/templates/badges-show.hbs | 4 +- .../templates/site-settings-category.hbs | 4 +- .../javascripts/admin/templates/user.hbs | 4 +- .../admin/views/admin-badges-index.js.es6 | 3 -- .../admin/views/admin-badges-show.js.es6 | 7 ---- .../javascripts/admin/views/admin-user.js.es6 | 1 - .../discourse/components/d-section.js.es6 | 10 +---- .../discourse/components/watch-read.js.es6 | 24 +++++++++++ .../discourse/controllers/static.js.es6 | 3 ++ .../discourse/mixins/scroll-top.js.es6 | 18 +++++++-- .../discourse/templates/static.hbs | 26 ++++++------ .../javascripts/discourse/templates/user.hbs | 6 +-- .../discourse/templates/user/activity.hbs | 2 +- .../javascripts/discourse/views/static.js.es6 | 40 ------------------- .../javascripts/discourse/views/user.js.es6 | 4 -- .../javascripts/acceptance/static-test.js.es6 | 4 ++ test/javascripts/acceptance/user-test.js.es6 | 1 + .../helpers/create-pretender.js.es6 | 4 +- 20 files changed, 77 insertions(+), 95 deletions(-) delete mode 100644 app/assets/javascripts/admin/views/admin-badges-index.js.es6 delete mode 100644 app/assets/javascripts/admin/views/admin-badges-show.js.es6 delete mode 100644 app/assets/javascripts/admin/views/admin-user.js.es6 create mode 100644 app/assets/javascripts/discourse/components/watch-read.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/static.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/user.js.es6 diff --git a/app/assets/javascripts/admin/components/site-setting.js.es6 b/app/assets/javascripts/admin/components/site-setting.js.es6 index 8b6601b4d37..662e4ef684c 100644 --- a/app/assets/javascripts/admin/components/site-setting.js.es6 +++ b/app/assets/javascripts/admin/components/site-setting.js.es6 @@ -1,12 +1,11 @@ import BufferedContent from 'discourse/mixins/buffered-content'; -import ScrollTop from 'discourse/mixins/scroll-top'; import SiteSetting from 'admin/models/site-setting'; import { propertyNotEqual } from 'discourse/lib/computed'; import computed from 'ember-addons/ember-computed-decorators'; const CustomTypes = ['bool', 'enum', 'list', 'url_list', 'host_list', 'category_list', 'value_list']; -export default Ember.Component.extend(BufferedContent, ScrollTop, { +export default Ember.Component.extend(BufferedContent, { classNameBindings: [':row', ':setting', 'setting.overridden', 'typeClass'], content: Ember.computed.alias('setting'), dirty: propertyNotEqual('buffered.value', 'setting.value'), diff --git a/app/assets/javascripts/admin/templates/badges-index.hbs b/app/assets/javascripts/admin/templates/badges-index.hbs index 6ee80748f81..c94f59fe105 100644 --- a/app/assets/javascripts/admin/templates/badges-index.hbs +++ b/app/assets/javascripts/admin/templates/badges-index.hbs @@ -1,4 +1,4 @@ -
+{{#d-section class="current-badge span13"}}

{{i18n 'admin.badges.none_selected'}}

@@ -6,4 +6,4 @@ {{fa-icon "plus"}} {{i18n 'admin.badges.new'}} {{/link-to}}
-
+{{/d-section}} diff --git a/app/assets/javascripts/admin/templates/badges-show.hbs b/app/assets/javascripts/admin/templates/badges-show.hbs index f29829eba55..e0ae7001df0 100644 --- a/app/assets/javascripts/admin/templates/badges-show.hbs +++ b/app/assets/javascripts/admin/templates/badges-show.hbs @@ -1,4 +1,4 @@ -
+{{#d-section class="current-badge span13"}}
@@ -143,7 +143,7 @@ {{/unless}}
-
+{{/d-section}} {{#if grant_count}}
diff --git a/app/assets/javascripts/admin/templates/site-settings-category.hbs b/app/assets/javascripts/admin/templates/site-settings-category.hbs index 3e8b088f692..2e44f80c38c 100644 --- a/app/assets/javascripts/admin/templates/site-settings-category.hbs +++ b/app/assets/javascripts/admin/templates/site-settings-category.hbs @@ -1,9 +1,9 @@ {{#if filteredContent}} -
+ {{#d-section class="form-horizontal settings"}} {{#each filteredContent as |setting|}} {{site-setting setting=setting saveAction="saveSetting"}} {{/each}} -
+ {{/d-section}} {{else}}
{{i18n 'admin.site_settings.no_results'}} diff --git a/app/assets/javascripts/admin/templates/user.hbs b/app/assets/javascripts/admin/templates/user.hbs index c24cd68950a..3b1c7742714 100644 --- a/app/assets/javascripts/admin/templates/user.hbs +++ b/app/assets/javascripts/admin/templates/user.hbs @@ -1 +1,3 @@ -{{outlet}} +{{#d-section}} + {{outlet}} +{{/d-section}} diff --git a/app/assets/javascripts/admin/views/admin-badges-index.js.es6 b/app/assets/javascripts/admin/views/admin-badges-index.js.es6 deleted file mode 100644 index f0b0ceb85d1..00000000000 --- a/app/assets/javascripts/admin/views/admin-badges-index.js.es6 +++ /dev/null @@ -1,3 +0,0 @@ -import ScrollTop from 'discourse/mixins/scroll-top'; - -export default Ember.View.extend(ScrollTop); diff --git a/app/assets/javascripts/admin/views/admin-badges-show.js.es6 b/app/assets/javascripts/admin/views/admin-badges-show.js.es6 deleted file mode 100644 index 55f7e0b64d8..00000000000 --- a/app/assets/javascripts/admin/views/admin-badges-show.js.es6 +++ /dev/null @@ -1,7 +0,0 @@ -import ScrollTop from 'discourse/mixins/scroll-top'; - -export default Ember.View.extend(ScrollTop, { - _scrollOnModelChange: function() { - this._scrollTop(); - }.observes('controller.model.id') -}); diff --git a/app/assets/javascripts/admin/views/admin-user.js.es6 b/app/assets/javascripts/admin/views/admin-user.js.es6 deleted file mode 100644 index 2bd2497f157..00000000000 --- a/app/assets/javascripts/admin/views/admin-user.js.es6 +++ /dev/null @@ -1 +0,0 @@ -export default Ember.View.extend(Discourse.ScrollTop); diff --git a/app/assets/javascripts/discourse/components/d-section.js.es6 b/app/assets/javascripts/discourse/components/d-section.js.es6 index 1bb1942003e..41e044f95eb 100644 --- a/app/assets/javascripts/discourse/components/d-section.js.es6 +++ b/app/assets/javascripts/discourse/components/d-section.js.es6 @@ -1,14 +1,9 @@ -import DiscourseURL from 'discourse/lib/url'; +import { scrollTop } from 'discourse/mixins/scroll-top'; // Can add a body class from within a component, also will scroll to the top automatically. export default Ember.Component.extend({ tagName: 'section', - _scrollTop() { - if (Ember.testing) { return; } - $(document).scrollTop(0); - }, - didInsertElement() { this._super(); @@ -26,8 +21,7 @@ export default Ember.Component.extend({ return; } - if (DiscourseURL.isJumpScheduled()) { return; } - Ember.run.scheduleOnce('afterRender', this, this._scrollTop); + scrollTop(); }, willDestroyElement() { diff --git a/app/assets/javascripts/discourse/components/watch-read.js.es6 b/app/assets/javascripts/discourse/components/watch-read.js.es6 new file mode 100644 index 00000000000..2a92380cbec --- /dev/null +++ b/app/assets/javascripts/discourse/components/watch-read.js.es6 @@ -0,0 +1,24 @@ +import isElementInViewport from "discourse/lib/is-element-in-viewport"; + +export default Ember.Component.extend({ + didInsertElement() { + this._super(); + const currentUser = this.currentUser; + if (!currentUser) { return; } + + const path = this.get('path'); + if (path === "faq" || path === "guidelines") { + $(window).on('load.faq resize.faq scroll.faq', () => { + const faqUnread = !currentUser.get('read_faq'); + if (faqUnread && isElementInViewport($(".contents p").last())) { + this.sendAction(); + } + }); + } + }, + + willDestroyElement() { + this._super(); + $(window).off('load.faq resize.faq scroll.faq'); + } +}); diff --git a/app/assets/javascripts/discourse/controllers/static.js.es6 b/app/assets/javascripts/discourse/controllers/static.js.es6 index 2c31b962c75..166a0676a7f 100644 --- a/app/assets/javascripts/discourse/controllers/static.js.es6 +++ b/app/assets/javascripts/discourse/controllers/static.js.es6 @@ -6,6 +6,9 @@ export default Ember.Controller.extend({ showLoginButton: Em.computed.equal("model.path", "login"), + @computed('model.path') + bodyClass: path => `static-${path}`, + @computed("model.path") showSignupButton() { return this.get("model.path") === "login" && this.get('application.canSignUp'); diff --git a/app/assets/javascripts/discourse/mixins/scroll-top.js.es6 b/app/assets/javascripts/discourse/mixins/scroll-top.js.es6 index 35af1d0eee9..5945c73a600 100644 --- a/app/assets/javascripts/discourse/mixins/scroll-top.js.es6 +++ b/app/assets/javascripts/discourse/mixins/scroll-top.js.es6 @@ -1,14 +1,24 @@ import DiscourseURL from 'discourse/lib/url'; +import { deprecated } from 'discourse/mixins/scroll-top'; + +const context = { + _scrollTop() { + if (Ember.testing) { return; } + $(document).scrollTop(0); + } +}; function scrollTop() { if (DiscourseURL.isJumpScheduled()) { return; } - Ember.run.schedule('afterRender', function() { - $(document).scrollTop(0); - }); + Ember.run.scheduleOnce('afterRender', context, context._scrollTop); } export default Ember.Mixin.create({ - _scrollTop: scrollTop.on('didInsertElement') + didInsertElement() { + deprecated('The `ScrollTop` mixin is deprecated. Replace it with a `{{d-section}}` component'); + this._super(); + scrollTop(); + } }); export { scrollTop }; diff --git a/app/assets/javascripts/discourse/templates/static.hbs b/app/assets/javascripts/discourse/templates/static.hbs index 91662eb3348..529b5ba149e 100644 --- a/app/assets/javascripts/discourse/templates/static.hbs +++ b/app/assets/javascripts/discourse/templates/static.hbs @@ -1,14 +1,16 @@ -
-
- {{plugin-outlet "above-static"}} - {{{model.html}}} +{{#d-section bodyClass=bodyClass class="container"}} + {{#watch-read action="markFaqRead" path=model.path}} +
+ {{plugin-outlet "above-static"}} + {{{model.html}}} - {{#if showSignupButton}} - {{d-button action="showCreateAccount" class="btn-primary sign-up-button" label="sign_up"}} - {{/if}} + {{#if showSignupButton}} + {{d-button action="showCreateAccount" class="btn-primary sign-up-button" label="sign_up"}} + {{/if}} - {{#if showLoginButton}} - {{d-button action="showLogin" class="btn-primary login-button" icon="user" label="log_in"}} - {{/if}} -
-
+ {{#if showLoginButton}} + {{d-button action="showLogin" class="btn-primary login-button" icon="user" label="log_in"}} + {{/if}} +
+ {{/watch-read}} +{{/d-section}} diff --git a/app/assets/javascripts/discourse/templates/user.hbs b/app/assets/javascripts/discourse/templates/user.hbs index 1d890517e24..fb22c218c36 100644 --- a/app/assets/javascripts/discourse/templates/user.hbs +++ b/app/assets/javascripts/discourse/templates/user.hbs @@ -1,5 +1,5 @@ -
-
+
+ {{#d-section class="user-main"}}
{{#unless collapsedInfo}} @@ -186,5 +186,5 @@
- + {{/d-section}}
diff --git a/app/assets/javascripts/discourse/templates/user/activity.hbs b/app/assets/javascripts/discourse/templates/user/activity.hbs index 72805bb8fd8..c5243f1ffb0 100644 --- a/app/assets/javascripts/discourse/templates/user/activity.hbs +++ b/app/assets/javascripts/discourse/templates/user/activity.hbs @@ -1,4 +1,4 @@ -{{#d-section pageClass="user-activity" class="user-nagivation" scrollTop="false"}} +{{#d-section pageClass="user-activity" class="user-navigation" scrollTop="false"}} {{#mobile-nav class='activity-nav' desktopClass='action-list activity-list nav-stacked' currentPath=currentPath}}
  • {{#link-to 'userActivity.index'}}{{i18n 'user.filters.all'}}{{/link-to}} diff --git a/app/assets/javascripts/discourse/views/static.js.es6 b/app/assets/javascripts/discourse/views/static.js.es6 deleted file mode 100644 index d075558a722..00000000000 --- a/app/assets/javascripts/discourse/views/static.js.es6 +++ /dev/null @@ -1,40 +0,0 @@ -import isElementInViewport from "discourse/lib/is-element-in-viewport"; -import ScrollTop from 'discourse/mixins/scroll-top'; -import { on } from 'ember-addons/ember-computed-decorators'; - -export default Ember.View.extend(ScrollTop, { - - @on('didInsertElement') - _addBodyClass() { - const path = this.get('controller.model.path'); - $('body').addClass(`static-${path}`); - }, - - @on('willDestroyElement') - _removeBodyClass() { - const path = this.get('controller.model.path'); - $('body').removeClass(`static-${path}`); - }, - - @on('didInsertElement') - _checkRead() { - const currentUser = this.get('controller.currentUser'); - if (currentUser) { - const path = this.get('controller.model.path'); - if (path === "faq" || path === "guidelines") { - const controller = this.get('controller'); - $(window).on('load.faq resize.faq scroll.faq', function() { - const faqUnread = !currentUser.get('read_faq'); - if (faqUnread && isElementInViewport($(".contents p").last())) { - controller.send('markFaqRead'); - } - }); - } - } - }, - - @on('willDestroyElement') - _stopChecking() { - $(window).off('load.faq resize.faq scroll.faq'); - } -}); diff --git a/app/assets/javascripts/discourse/views/user.js.es6 b/app/assets/javascripts/discourse/views/user.js.es6 deleted file mode 100644 index 0b358f18eef..00000000000 --- a/app/assets/javascripts/discourse/views/user.js.es6 +++ /dev/null @@ -1,4 +0,0 @@ -import ScrollTop from 'discourse/mixins/scroll-top'; - -export default Ember.View.extend(ScrollTop, { -}); diff --git a/test/javascripts/acceptance/static-test.js.es6 b/test/javascripts/acceptance/static-test.js.es6 index e3ad8afa386..26bc4e594bc 100644 --- a/test/javascripts/acceptance/static-test.js.es6 +++ b/test/javascripts/acceptance/static-test.js.es6 @@ -4,21 +4,25 @@ acceptance("Static"); test("Static Pages", () => { visit("/faq"); andThen(() => { + ok($('body.static-faq').length, "has the body class"); ok(exists(".body-page"), "The content is present"); }); visit("/guidelines"); andThen(() => { + ok($('body.static-guidelines').length, "has the body class"); ok(exists(".body-page"), "The content is present"); }); visit("/tos"); andThen(() => { + ok($('body.static-tos').length, "has the body class"); ok(exists(".body-page"), "The content is present"); }); visit("/privacy"); andThen(() => { + ok($('body.static-privacy').length, "has the body class"); ok(exists(".body-page"), "The content is present"); }); diff --git a/test/javascripts/acceptance/user-test.js.es6 b/test/javascripts/acceptance/user-test.js.es6 index 045750778e8..36bc916295e 100644 --- a/test/javascripts/acceptance/user-test.js.es6 +++ b/test/javascripts/acceptance/user-test.js.es6 @@ -28,5 +28,6 @@ test("Root URL - Viewing Self", () => { andThen(() => { ok($('body.user-summary-page').length, "has the body class"); equal(currentPath(), 'user.summary', "it defaults to summary"); + ok(exists('.container.viewing-self'), "has the viewing-self class"); }); }); diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6 index 54e33dcf43c..a9a6d769e44 100644 --- a/test/javascripts/helpers/create-pretender.js.es6 +++ b/test/javascripts/helpers/create-pretender.js.es6 @@ -65,9 +65,7 @@ export default function() { this.get('/users/eviltrout.json', () => { const json = fixturesByUrl['/users/eviltrout.json']; - if (loggedIn()) { - json.user.can_edit = true; - } + json.user.can_edit = loggedIn(); return response(json); });