From 824c0b0f876b6406d8a13aaa7cf29102319d9efd Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 11 Nov 2014 15:58:47 -0500 Subject: [PATCH] FIX: Remove `grouped-each` helper. GroupedView is deprecated in Ember 1.9 --- .../discourse/helpers/grouped-each.js.es6 | 143 ------------------ .../mobile/components/basic-topic-list.hbs | 25 +-- .../discourse/templates/user/stream.hbs | 12 +- 3 files changed, 19 insertions(+), 161 deletions(-) delete mode 100644 app/assets/javascripts/discourse/helpers/grouped-each.js.es6 diff --git a/app/assets/javascripts/discourse/helpers/grouped-each.js.es6 b/app/assets/javascripts/discourse/helpers/grouped-each.js.es6 deleted file mode 100644 index 824ad38dba0..00000000000 --- a/app/assets/javascripts/discourse/helpers/grouped-each.js.es6 +++ /dev/null @@ -1,143 +0,0 @@ -var DiscourseGroupedEach = function(context, path, options) { - var self = this, - normalized = Ember.Handlebars.normalizePath(context, path, options.data); - - this.context = context; - this.path = path; - this.options = options; - this.template = options.fn; - this.containingView = options.data.view; - this.normalizedRoot = normalized.root; - this.normalizedPath = normalized.path; - this.content = this.lookupContent(); - this.destroyed = false; - - this.addContentObservers(); - this.addArrayObservers(); - - this.containingView.on('willClearRender', function() { - self.destroy(); - }); -}; - -DiscourseGroupedEach.prototype = { - contentWillChange: function() { - this.removeArrayObservers(); - }, - - contentDidChange: function() { - this.content = this.lookupContent(); - this.addArrayObservers(); - this.rerenderContainingView(); - }, - - contentArrayWillChange: Ember.K, - - contentArrayDidChange: function() { - this.rerenderContainingView(); - }, - - lookupContent: function() { - return Ember.Handlebars.get(this.normalizedRoot, this.normalizedPath, this.options); - }, - - addArrayObservers: function() { - if (!this.content) { return; } - - this.content.addArrayObserver(this, { - willChange: 'contentArrayWillChange', - didChange: 'contentArrayDidChange' - }); - }, - - removeArrayObservers: function() { - if (!this.content) { return; } - - this.content.removeArrayObserver(this, { - willChange: 'contentArrayWillChange', - didChange: 'contentArrayDidChange' - }); - }, - - addContentObservers: function() { - Ember.addBeforeObserver(this.normalizedRoot, this.normalizedPath, this, this.contentWillChange); - Ember.addObserver(this.normalizedRoot, this.normalizedPath, this, this.contentDidChange); - }, - - removeContentObservers: function() { - Ember.removeBeforeObserver(this.normalizedRoot, this.normalizedPath, this.contentWillChange); - Ember.removeObserver(this.normalizedRoot, this.normalizedPath, this.contentDidChange); - }, - - render: function() { - if (!this.content) { return; } - - var content = this.content, - contentLength = Em.get(content, 'length'), - data = this.options.data, - template = this.template, - keyword = this.options.hash.keyword; - - data.insideEach = true; - for (var i = 0; i < contentLength; i++) { - var row = content.objectAt(i); - var keywords = Em.get(data, 'keywords'); - if (!keywords) { - keywords = {}; - Em.set(data, 'keywords', keywords); - } - if (keyword) { - Em.set(keywords, keyword, row); - } - template(row, { data: data }); - } - }, - - rerenderContainingView: function() { - var self = this; - Ember.run.scheduleOnce('render', this, function() { - // It's possible it's been destroyed after we enqueued a re-render call. - if (!self.destroyed) { - self.containingView.rerender(); - } - }); - }, - - destroy: function() { - this.removeContentObservers(); - if (this.content) { - this.removeArrayObservers(); - } - this.destroyed = true; - } -}; - -function groupedEachHelper(path, options) { - if (arguments.length === 4) { - Ember.assert("If you pass more than one argument to the groupedEach helper, it must be in the form #groupedEach foo in bar", arguments[1] === "in"); - - var keywordName = arguments[0]; - - options = arguments[3]; - path = arguments[2]; - if (path === '') { path = "this"; } - - options.hash.keyword = keywordName; - } - - if (arguments.length === 1) { - options = path; - path = 'this'; - } - - options.hash.dataSourceBinding = path; - options.data.insideGroup = true; - new DiscourseGroupedEach(this, path, options).render(); -} - -Ember.Handlebars.registerHelper('groupedEach', function() { - Em.warn("The `groupedEach` helper is deprecated. Use `grouped-each` instead."); - return groupedEachHelper.apply(this, Array.prototype.slice.apply(arguments)); -}); - -Ember.Handlebars.registerHelper('grouped-each', groupedEachHelper); diff --git a/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs index 0c168e65210..78ba9006db0 100644 --- a/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs @@ -1,16 +1,17 @@ {{#if loaded}} {{#if topics}} - {{#grouped-each topic in topics}} + + {{#each topics}} - {{/grouped-each}} -
- {{else}} -
- {{i18n choose_topic.none_found}} + {{/each}} + + {{else}} +
+ {{i18n choose_topic.none_found}}
{{/if}} {{else}} diff --git a/app/assets/javascripts/discourse/templates/user/stream.hbs b/app/assets/javascripts/discourse/templates/user/stream.hbs index 212361ae661..ccb0df55747 100644 --- a/app/assets/javascripts/discourse/templates/user/stream.hbs +++ b/app/assets/javascripts/discourse/templates/user/stream.hbs @@ -1,4 +1,4 @@ -{{#grouped-each model.content}} +{{#each model.content}} -{{/grouped-each}} +{{/each}}