diff --git a/app/assets/javascripts/discourse/controllers/group-index.js.es6 b/app/assets/javascripts/discourse/controllers/group-index.js.es6 index 7a5a5bf98ff..306ff8aa80b 100644 --- a/app/assets/javascripts/discourse/controllers/group-index.js.es6 +++ b/app/assets/javascripts/discourse/controllers/group-index.js.es6 @@ -1,27 +1,50 @@ -import { fmt } from 'discourse/lib/computed'; +import { popupAjaxError } from 'discourse/lib/ajax-error'; +import computed from 'ember-addons/ember-computed-decorators'; +import Group from 'discourse/models/group'; -export default Ember.ArrayController.extend({ - needs: ['group'], +export default Ember.Controller.extend({ loading: false, - emptyText: fmt('type', 'groups.empty.%@'), + limit: null, + offset: null, + + @computed('model.owners.[]') + isOwner(owners) { + if (this.get('currentUser.admin')) { + return true; + } + const currentUserId = this.get('currentUser.id'); + if (currentUserId) { + return !!owners.findBy('id', currentUserId); + } + }, actions: { - loadMore() { + removeMember(user) { + this.get('model').removeMember(user); + }, - if (this.get('loading')) { return; } - this.set('loading', true); - const posts = this.get('model'); - if (posts && posts.length) { - const beforePostId = posts[posts.length-1].get('id'); - const group = this.get('controllers.group.model'); - - const opts = { beforePostId, type: this.get('type') }; - group.findPosts(opts).then(newPosts => { - posts.addObjects(newPosts); - this.set('loading', false); - }); + addMembers() { + const usernames = this.get('usernames'); + if (usernames && usernames.length > 0) { + this.get('model').addMembers(usernames).then(() => this.set('usernames', [])).catch(popupAjaxError); } + }, + + loadMore() { + if (this.get("loading")) { return; } + if (this.get("model.members.length") >= this.get("model.user_count")) { return; } + + this.set("loading", true); + + Group.loadMembers(this.get("model.name"), this.get("model.members.length"), this.get("limit")).then(result => { + this.get("model.members").addObjects(result.members.map(member => Discourse.User.create(member))); + this.setProperties({ + loading: false, + user_count: result.meta.total, + limit: result.meta.limit, + offset: Math.min(result.meta.offset + result.meta.limit, result.meta.total) + }); + }); } } }); - diff --git a/app/assets/javascripts/discourse/controllers/group-posts.js.es6 b/app/assets/javascripts/discourse/controllers/group-posts.js.es6 new file mode 100644 index 00000000000..c9e791c1f1b --- /dev/null +++ b/app/assets/javascripts/discourse/controllers/group-posts.js.es6 @@ -0,0 +1,26 @@ +import { fmt } from 'discourse/lib/computed'; + +export default Ember.ArrayController.extend({ + needs: ['group'], + loading: false, + emptyText: fmt('type', 'groups.empty.%@'), + + actions: { + loadMore() { + + if (this.get('loading')) { return; } + this.set('loading', true); + const posts = this.get('model'); + if (posts && posts.length) { + const beforePostId = posts[posts.length-1].get('id'); + const group = this.get('controllers.group.model'); + + const opts = { beforePostId, type: this.get('type') }; + group.findPosts(opts).then(newPosts => { + posts.addObjects(newPosts); + this.set('loading', false); + }); + } + } + } +}); diff --git a/app/assets/javascripts/discourse/controllers/group.js.es6 b/app/assets/javascripts/discourse/controllers/group.js.es6 index b7dc7a80577..819047536ab 100644 --- a/app/assets/javascripts/discourse/controllers/group.js.es6 +++ b/app/assets/javascripts/discourse/controllers/group.js.es6 @@ -15,7 +15,7 @@ var Tab = Em.Object.extend({ export default Ember.Controller.extend({ counts: null, - showing: 'posts', + showing: 'members', @observes('counts') countsChanged() { @@ -35,10 +35,10 @@ export default Ember.Controller.extend({ }, tabs: [ - Tab.create({ name: 'posts', active: true, 'location': 'group.index' }), + Tab.create({ name: 'members', active: true, 'location': 'group.index' }), + Tab.create({ name: 'posts' }), Tab.create({ name: 'topics' }), Tab.create({ name: 'mentions' }), - Tab.create({ name: 'members' }), Tab.create({ name: 'messages' }), ] }); diff --git a/app/assets/javascripts/discourse/controllers/group/members.js.es6 b/app/assets/javascripts/discourse/controllers/group/members.js.es6 deleted file mode 100644 index 306ff8aa80b..00000000000 --- a/app/assets/javascripts/discourse/controllers/group/members.js.es6 +++ /dev/null @@ -1,50 +0,0 @@ -import { popupAjaxError } from 'discourse/lib/ajax-error'; -import computed from 'ember-addons/ember-computed-decorators'; -import Group from 'discourse/models/group'; - -export default Ember.Controller.extend({ - loading: false, - limit: null, - offset: null, - - @computed('model.owners.[]') - isOwner(owners) { - if (this.get('currentUser.admin')) { - return true; - } - const currentUserId = this.get('currentUser.id'); - if (currentUserId) { - return !!owners.findBy('id', currentUserId); - } - }, - - actions: { - removeMember(user) { - this.get('model').removeMember(user); - }, - - addMembers() { - const usernames = this.get('usernames'); - if (usernames && usernames.length > 0) { - this.get('model').addMembers(usernames).then(() => this.set('usernames', [])).catch(popupAjaxError); - } - }, - - loadMore() { - if (this.get("loading")) { return; } - if (this.get("model.members.length") >= this.get("model.user_count")) { return; } - - this.set("loading", true); - - Group.loadMembers(this.get("model.name"), this.get("model.members.length"), this.get("limit")).then(result => { - this.get("model.members").addObjects(result.members.map(member => Discourse.User.create(member))); - this.setProperties({ - loading: false, - user_count: result.meta.total, - limit: result.meta.limit, - offset: Math.min(result.meta.offset + result.meta.limit, result.meta.total) - }); - }); - } - } -}); diff --git a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 index adc3436d9b3..01b03f07264 100644 --- a/app/assets/javascripts/discourse/routes/app-route-map.js.es6 +++ b/app/assets/javascripts/discourse/routes/app-route-map.js.es6 @@ -49,9 +49,9 @@ export default function() { }); this.resource('group', { path: '/groups/:name' }, function() { + this.route('posts'); this.route('topics'); this.route('mentions'); - this.route('members'); this.route('messages'); }); diff --git a/app/assets/javascripts/discourse/routes/group-index.js.es6 b/app/assets/javascripts/discourse/routes/group-index.js.es6 index a7baf27a150..c6e00e80283 100644 --- a/app/assets/javascripts/discourse/routes/group-index.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-index.js.es6 @@ -1,24 +1,11 @@ -export function buildIndex(type) { - return Discourse.Route.extend({ - type, +export default Discourse.Route.extend({ + model() { + return this.modelFor("group"); + }, - model() { - return this.modelFor("group").findPosts({ type }); - }, - - setupController(controller, model) { - this.controllerFor('group-index').setProperties({ model, type }); - this.controllerFor("group").set("showing", type); - }, - - renderTemplate() { - this.render('group-index'); - }, - - actions: { - didTransition() { return true; } - } - }); -} - -export default buildIndex('posts'); + setupController(controller, model) { + this.controllerFor("group").set("showing", "members"); + controller.set("model", model); + model.findMembers(); + } +}); diff --git a/app/assets/javascripts/discourse/routes/group-members.js.es6 b/app/assets/javascripts/discourse/routes/group-members.js.es6 deleted file mode 100644 index c6e00e80283..00000000000 --- a/app/assets/javascripts/discourse/routes/group-members.js.es6 +++ /dev/null @@ -1,11 +0,0 @@ -export default Discourse.Route.extend({ - model() { - return this.modelFor("group"); - }, - - setupController(controller, model) { - this.controllerFor("group").set("showing", "members"); - controller.set("model", model); - model.findMembers(); - } -}); diff --git a/app/assets/javascripts/discourse/routes/group-mentions.js.es6 b/app/assets/javascripts/discourse/routes/group-mentions.js.es6 index d5c7471f518..2a12734dc18 100644 --- a/app/assets/javascripts/discourse/routes/group-mentions.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-mentions.js.es6 @@ -1,3 +1,3 @@ -import { buildIndex } from 'discourse/routes/group-index'; +import { buildGroupPage } from 'discourse/routes/group-posts'; -export default buildIndex('mentions'); +export default buildGroupPage('mentions'); diff --git a/app/assets/javascripts/discourse/routes/group-messages.js.es6 b/app/assets/javascripts/discourse/routes/group-messages.js.es6 index df27a3f793b..c800d6f7774 100644 --- a/app/assets/javascripts/discourse/routes/group-messages.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-messages.js.es6 @@ -1,3 +1,3 @@ -import { buildIndex } from 'discourse/routes/group-index'; +import { buildGroupPage } from 'discourse/routes/group-posts'; -export default buildIndex('messages'); +export default buildGroupPage('messages'); diff --git a/app/assets/javascripts/discourse/routes/group-posts.js.es6 b/app/assets/javascripts/discourse/routes/group-posts.js.es6 new file mode 100644 index 00000000000..fb60caa1e08 --- /dev/null +++ b/app/assets/javascripts/discourse/routes/group-posts.js.es6 @@ -0,0 +1,24 @@ +export function buildGroupPage(type) { + return Discourse.Route.extend({ + type, + + model() { + return this.modelFor("group").findPosts({ type }); + }, + + setupController(controller, model) { + this.controllerFor('group-posts').setProperties({ model, type }); + this.controllerFor("group").set("showing", type); + }, + + renderTemplate() { + this.render('group-posts'); + }, + + actions: { + didTransition() { return true; } + } + }); +} + +export default buildGroupPage('posts'); diff --git a/app/assets/javascripts/discourse/routes/group-topics.js.es6 b/app/assets/javascripts/discourse/routes/group-topics.js.es6 index 991bb7475a3..be4e87077e9 100644 --- a/app/assets/javascripts/discourse/routes/group-topics.js.es6 +++ b/app/assets/javascripts/discourse/routes/group-topics.js.es6 @@ -1,3 +1,3 @@ -import { buildIndex } from 'discourse/routes/group-index'; +import { buildGroupPage } from 'discourse/routes/group-posts'; -export default buildIndex('topics'); +export default buildGroupPage('topics'); diff --git a/app/assets/javascripts/discourse/templates/group-index.hbs b/app/assets/javascripts/discourse/templates/group-index.hbs index f38104880f4..41ad1fd9226 100644 --- a/app/assets/javascripts/discourse/templates/group-index.hbs +++ b/app/assets/javascripts/discourse/templates/group-index.hbs @@ -1 +1,45 @@ -{{group-post-stream posts=model emptyText=emptyText loadMore="loadMore"}} +{{#if model}} + {{#if isOwner}} +