From 0904ad55373b1615410a95ff0072aa6d7d142071 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 10 Nov 2016 13:33:31 -0500 Subject: [PATCH] Migrate `createViewWithBodyClass` helper to components --- .../discourse/components/d-section.js.es6 | 45 +++ .../discourse/lib/create-view.js.es6 | 15 - .../javascripts/discourse/templates/about.hbs | 176 ++++----- .../discourse/templates/badges/index.hbs | 30 +- .../discourse/templates/full-page-search.hbs | 236 ++++++------ .../templates/navigation/default.hbs | 12 +- .../templates/{user => }/preferences.hbs | 4 +- .../javascripts/discourse/templates/tags.hbs | 14 +- .../discourse/templates/user-invited-show.hbs | 198 +++++----- .../discourse/templates/user/activity.hbs | 8 +- .../discourse/templates/user/badges.hbs | 4 +- .../discourse/templates/user/messages.hbs | 5 +- .../templates/user/notifications.hbs | 4 +- .../discourse/templates/user/summary.hbs | 348 +++++++++--------- .../javascripts/discourse/templates/users.hbs | 84 ++--- .../javascripts/discourse/views/about.js.es6 | 3 - .../discourse/views/badges-index.js.es6 | 4 - .../discourse/views/full-page-search.js.es6 | 5 - .../discourse/views/navigation-default.js.es6 | 3 - .../discourse/views/preferences.js.es6 | 6 - .../javascripts/discourse/views/tags.js.es6 | 3 - .../discourse/views/user-activity.js.es6 | 3 - .../discourse/views/user-badges.js.es6 | 4 - .../discourse/views/user-invited-show.js.es6 | 3 - .../discourse/views/user-messages.js.es6 | 3 - .../discourse/views/user-notifications.js.es6 | 3 - .../discourse/views/user-summary.js.es6 | 3 - .../javascripts/discourse/views/users.js.es6 | 3 - test/javascripts/acceptance/about-test.js.es6 | 1 + .../javascripts/acceptance/badges-test.js.es6 | 1 + ...es-test.js.es6 => preferences-test.js.es6} | 1 + .../acceptance/search-full-test.js.es6 | 2 + test/javascripts/acceptance/tags-test.js.es6 | 11 + .../acceptance/topic-discovery-test.js.es6 | 1 + .../acceptance/user-anonymous-test.js.es6 | 11 + test/javascripts/acceptance/user-test.js.es6 | 25 +- test/javascripts/acceptance/users-test.js.es6 | 1 + .../helpers/create-pretender.js.es6 | 21 ++ 38 files changed, 683 insertions(+), 621 deletions(-) create mode 100644 app/assets/javascripts/discourse/components/d-section.js.es6 delete mode 100644 app/assets/javascripts/discourse/lib/create-view.js.es6 rename app/assets/javascripts/discourse/templates/{user => }/preferences.hbs (99%) delete mode 100644 app/assets/javascripts/discourse/views/about.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/badges-index.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/full-page-search.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/navigation-default.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/preferences.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/tags.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/user-activity.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/user-badges.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/user-invited-show.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/user-messages.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/user-notifications.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/user-summary.js.es6 delete mode 100644 app/assets/javascripts/discourse/views/users.js.es6 rename test/javascripts/acceptance/{user-preferences-test.js.es6 => preferences-test.js.es6} (88%) create mode 100644 test/javascripts/acceptance/tags-test.js.es6 diff --git a/app/assets/javascripts/discourse/components/d-section.js.es6 b/app/assets/javascripts/discourse/components/d-section.js.es6 new file mode 100644 index 00000000000..1bb1942003e --- /dev/null +++ b/app/assets/javascripts/discourse/components/d-section.js.es6 @@ -0,0 +1,45 @@ +import DiscourseURL from 'discourse/lib/url'; + +// 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(); + + const pageClass = this.get('pageClass'); + if (pageClass) { + $('body').addClass(`${pageClass}-page`); + } + + const bodyClass = this.get('bodyClass'); + if (bodyClass) { + $('body').addClass(bodyClass); + } + + if (this.get('scrollTop') === "false") { + return; + } + + if (DiscourseURL.isJumpScheduled()) { return; } + Ember.run.scheduleOnce('afterRender', this, this._scrollTop); + }, + + willDestroyElement() { + this._super(); + const pageClass = this.get('pageClass'); + if (pageClass) { + $('body').removeClass(`${pageClass}-page`); + } + + const bodyClass = this.get('bodyClass'); + if (bodyClass) { + $('body').removeClass(bodyClass); + } + } +}); diff --git a/app/assets/javascripts/discourse/lib/create-view.js.es6 b/app/assets/javascripts/discourse/lib/create-view.js.es6 deleted file mode 100644 index 854fa42fbe0..00000000000 --- a/app/assets/javascripts/discourse/lib/create-view.js.es6 +++ /dev/null @@ -1,15 +0,0 @@ -import { on } from 'ember-addons/ember-computed-decorators'; - -export function createViewWithBodyClass(body_class) { - return Ember.View.extend({ - @on("didInsertElement") - addBodyClass() { - $('body').addClass(body_class); - }, - - @on("willDestroyElement") - removeBodyClass() { - $('body').removeClass(body_class); - } - }); -} diff --git a/app/assets/javascripts/discourse/templates/about.hbs b/app/assets/javascripts/discourse/templates/about.hbs index 3d8f993ba08..480b10c0fde 100644 --- a/app/assets/javascripts/discourse/templates/about.hbs +++ b/app/assets/javascripts/discourse/templates/about.hbs @@ -1,97 +1,99 @@ -
-
+{{#d-section pageClass="about"}} +
+
- - -
-

{{i18n 'about.title' title=model.title}}

-

{{model.description}}

-
- - {{#if model.admins}} -
-

{{i18n 'about.our_admins'}}

- - {{#each model.admins as |a|}} - {{user-info user=a}} - {{/each}} -
+ +
+

{{i18n 'about.title' title=model.title}}

+

{{model.description}}

- {{/if}} - {{#if model.moderators}} -
-

{{i18n 'about.our_moderators'}}

+ {{#if model.admins}} +
+

{{i18n 'about.our_admins'}}

-
- {{#each model.moderators as |m|}} - {{user-info user=m}} + {{#each model.admins as |a|}} + {{user-info user=a}} {{/each}} -
-
+
+ +
+ {{/if}} + + {{#if model.moderators}} +
+

{{i18n 'about.our_moderators'}}

+ +
+ {{#each model.moderators as |m|}} + {{user-info user=m}} + {{/each}} +
+
+
+ {{/if}} + +
+

{{i18n 'about.stats'}}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 {{i18n 'about.stat.all_time'}}{{i18n 'about.stat.last_7_days'}}{{i18n 'about.stat.last_30_days'}}
{{i18n 'about.topic_count'}}{{number model.stats.topic_count}}{{number model.stats.topics_7_days}}{{number model.stats.topics_30_days}}
{{i18n 'about.post_count'}}{{number model.stats.post_count}}{{number model.stats.posts_7_days}}{{number model.stats.posts_30_days}}
{{i18n 'about.user_count'}}{{number model.stats.user_count}}{{number model.stats.users_7_days}}{{number model.stats.users_30_days}}
{{i18n 'about.active_user_count'}}{{number model.stats.active_users_7_days}}{{number model.stats.active_users_30_days}}
{{i18n 'about.like_count'}}{{number model.stats.like_count}}{{number model.stats.likes_7_days}}{{number model.stats.likes_30_days}}
- {{/if}} -
-

{{i18n 'about.stats'}}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 {{i18n 'about.stat.all_time'}}{{i18n 'about.stat.last_7_days'}}{{i18n 'about.stat.last_30_days'}}
{{i18n 'about.topic_count'}}{{number model.stats.topic_count}}{{number model.stats.topics_7_days}}{{number model.stats.topics_30_days}}
{{i18n 'about.post_count'}}{{number model.stats.post_count}}{{number model.stats.posts_7_days}}{{number model.stats.posts_30_days}}
{{i18n 'about.user_count'}}{{number model.stats.user_count}}{{number model.stats.users_7_days}}{{number model.stats.users_30_days}}
{{i18n 'about.active_user_count'}}{{number model.stats.active_users_7_days}}{{number model.stats.active_users_30_days}}
{{i18n 'about.like_count'}}{{number model.stats.like_count}}{{number model.stats.likes_7_days}}{{number model.stats.likes_30_days}}
-
- - {{#if contactInfo}} -
-

{{i18n 'about.contact'}}

-

{{{contactInfo}}}

-
- {{/if}} + {{#if contactInfo}} +
+

{{i18n 'about.contact'}}

+

{{{contactInfo}}}

+
+ {{/if}} +
-
+{{/d-section}} diff --git a/app/assets/javascripts/discourse/templates/badges/index.hbs b/app/assets/javascripts/discourse/templates/badges/index.hbs index a5aac17b23a..b30725693b3 100644 --- a/app/assets/javascripts/discourse/templates/badges/index.hbs +++ b/app/assets/javascripts/discourse/templates/badges/index.hbs @@ -1,17 +1,19 @@ -
-

{{i18n 'badges.title'}}

+{{#d-section pageClass="badges"}} +
+

{{i18n 'badges.title'}}

-
- {{#each badgeGroups as |bg|}} -
-
-

{{bg.badgeGrouping.displayName}}

+
+ {{#each badgeGroups as |bg|}} +
+
+

{{bg.badgeGrouping.displayName}}

+
+ + {{#each bg.badges as |b|}} + {{badge-card badge=b navigateOnClick="true"}} + {{/each}}
- - {{#each bg.badges as |b|}} - {{badge-card badge=b navigateOnClick="true"}} - {{/each}} -
- {{/each}} + {{/each}} +
-
+{{/d-section}} diff --git a/app/assets/javascripts/discourse/templates/full-page-search.hbs b/app/assets/javascripts/discourse/templates/full-page-search.hbs index dc5572f8287..edaf9172db9 100644 --- a/app/assets/javascripts/discourse/templates/full-page-search.hbs +++ b/app/assets/javascripts/discourse/templates/full-page-search.hbs @@ -1,132 +1,134 @@ -