From f0ca6150d8513f4d9ee96167732d804433d1e729 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 31 Dec 2014 12:32:43 +1100 Subject: [PATCH] refactor topic list header to use a raw template --- .../components/topic-list-header.js.es6 | 50 +------------------ .../topic-list-header-column.raw.hbs | 5 ++ .../components/topic-list-header.raw.hbs | 15 ++++++ .../views/topic-list-header-column.js.es6 | 38 ++++++++++++++ 4 files changed, 60 insertions(+), 48 deletions(-) create mode 100644 app/assets/javascripts/discourse/templates/components/topic-list-header-column.raw.hbs create mode 100644 app/assets/javascripts/discourse/templates/components/topic-list-header.raw.hbs create mode 100644 app/assets/javascripts/discourse/views/topic-list-header-column.js.es6 diff --git a/app/assets/javascripts/discourse/components/topic-list-header.js.es6 b/app/assets/javascripts/discourse/components/topic-list-header.js.es6 index 8742bdd4408..afdbe2e43b8 100644 --- a/app/assets/javascripts/discourse/components/topic-list-header.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-list-header.js.es6 @@ -5,6 +5,8 @@ export default Ember.Component.extend(StringBuffer, { rerenderTriggers: ['order', 'ascending'], + rawTemplate: 'components/topic-list-header.raw', + click: function(e) { var target = $(e.target); @@ -18,52 +20,4 @@ export default Ember.Component.extend(StringBuffer, { } }, - - renderColumn: function(buffer, options){ - var className = options.sortable ? "sortable " : ""; - className += options.order || ""; - - var sortIcon = ""; - if(this.get("order") === options.order && options.sortable){ - className += " sorting"; - sortIcon = " "; - } - - if(options.number){ - className += " num"; - } - - var name = options.forceName || I18n.t(options.name); - - buffer.push("" + name + sortIcon + ""); - }, - - renderString: function(buffer){ - var self = this; - - if(this.get('currentUser')){ - buffer.push(""); - if(this.get('canBulkSelect')){ - var title = I18n.t('topics.bulk.toggle'); - buffer.push(""); - } - buffer.push(""); - } - - var column = function(options){ - self.renderColumn(buffer, options); - }; - - column({name: 'topic.title', sortable: false, order: 'default'}); - - if(!this.get('hideCategory')) { - column({name: 'category_title', sortable: true, order: 'category'}); - } - - column({sortable: false, order: 'posters', name: 'users'}); - column({sortable: true, order: 'posts', name: 'posts', number: true}); - column({sortable: true, order: 'views', name: 'views', number: true}); - column({sortable: true, order: 'activity', name: 'activity', number: true}); - } - }); diff --git a/app/assets/javascripts/discourse/templates/components/topic-list-header-column.raw.hbs b/app/assets/javascripts/discourse/templates/components/topic-list-header-column.raw.hbs new file mode 100644 index 00000000000..91c8c5b460f --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/topic-list-header-column.raw.hbs @@ -0,0 +1,5 @@ +{{view.localizedName}} + {{~#if view.isSorting}} + + {{/if ~}} + diff --git a/app/assets/javascripts/discourse/templates/components/topic-list-header.raw.hbs b/app/assets/javascripts/discourse/templates/components/topic-list-header.raw.hbs new file mode 100644 index 00000000000..19f7c6e3be4 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/topic-list-header.raw.hbs @@ -0,0 +1,15 @@ +{{#if currentUser}} + + {{#if canBulkSelect}} + + {{/if}} + +{{/if}} +{{raw "components/topic-list-header-column" order='default' name='topic.title'}} +{{#unless parent.hideCategory}} + {{raw "components/topic-list-header-column" sortable='true' order='category' name='category_title'}} +{{/unless}} +{{raw "components/topic-list-header-column" order='posters' name='users'}} +{{raw "components/topic-list-header-column" sortable='true' number='true' order='posts' name='posts'}} +{{raw "components/topic-list-header-column" sortable='true' number='true' order='views' name='views'}} +{{raw "components/topic-list-header-column" sortable='true' number='true' order='activity' name='activity'}} diff --git a/app/assets/javascripts/discourse/views/topic-list-header-column.js.es6 b/app/assets/javascripts/discourse/views/topic-list-header-column.js.es6 new file mode 100644 index 00000000000..2e0703c9db2 --- /dev/null +++ b/app/assets/javascripts/discourse/views/topic-list-header-column.js.es6 @@ -0,0 +1,38 @@ +export default Ember.Object.extend({ + + localizedName: function(){ + if(this.forceName){ + return this.forceName; + } + + return I18n.t(this.name); + }.property(), + + sortClass: function(){ + return "fa fa-chevron-" + (this.parent.get("ascending") ? "up" : "down"); + }.property(), + + isSorting: function(){ + return this.sortable && this.parent.get("order") === this.order; + }.property(), + + className: function(){ + var name = []; + if(this.order){ + name.push(this.order); + } + if(this.sortable){ + name.push("sortable"); + + if(this.get("isSorting")){ + name.push("sorting"); + } + } + + if(this.number){ + name.push("num"); + } + + return name.join(' '); + }.property() +});