mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
work in progress ... groups
This commit is contained in:
@@ -1,10 +1,22 @@
|
||||
Discourse.AdminGroupsController = Ember.ArrayController.extend({
|
||||
itemController: 'adminGroup',
|
||||
edit: function(action){
|
||||
this.get('content').select(action);
|
||||
|
||||
edit: function(group){
|
||||
this.get('model').select(group);
|
||||
group.loadUsers();
|
||||
},
|
||||
|
||||
refreshAutoGroups: function(){
|
||||
var controller = this;
|
||||
|
||||
this.set('refreshingAutoGroups', true);
|
||||
Discourse.ajax('/admin/groups/refresh_automatic_groups', {type: 'POST'}).then(function(){
|
||||
controller.set('model', Discourse.Group.findAll());
|
||||
controller.set('refreshingAutoGroups',false);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Discourse.AdminGroupController = Ember.ObjectController.extend({
|
||||
Discourse.AdminGroupController = Ember.Controller.extend({
|
||||
|
||||
});
|
||||
|
||||
@@ -1,4 +1,34 @@
|
||||
Discourse.Group = Discourse.Model.extend({
|
||||
userCountDisplay: function(){
|
||||
var c = this.get('user_count');
|
||||
// don't display zero its ugly
|
||||
if(c > 0) {
|
||||
return c;
|
||||
}
|
||||
}.property('user_count'),
|
||||
|
||||
loadUsers: function() {
|
||||
var group = this;
|
||||
|
||||
Discourse.ajax('/admin/groups/' + this.get('id') + '/users').then(function(payload){
|
||||
var users = Em.A()
|
||||
payload.each(function(user){
|
||||
users.addObject(Discourse.User.create(user));
|
||||
});
|
||||
group.set('users', users)
|
||||
});
|
||||
},
|
||||
|
||||
usernames: function() {
|
||||
var users = this.get('users');
|
||||
var usernames = "";
|
||||
if(users) {
|
||||
usernames = $.map(users, function(user){
|
||||
return user.get('username');
|
||||
}).join(',')
|
||||
}
|
||||
return usernames;
|
||||
}.property('users')
|
||||
|
||||
});
|
||||
|
||||
@@ -6,19 +36,22 @@ Discourse.Group.reopenClass({
|
||||
findAll: function(){
|
||||
var list = Discourse.SelectableArray.create();
|
||||
|
||||
list.addObject(Discourse.Group.create({id: 1, name: "all mods", members: ["A","b","c"]}));
|
||||
list.addObject(Discourse.Group.create({id: 2, name: "other mods", members: ["A","b","c"]}));
|
||||
Discourse.ajax("/admin/groups").then(function(groups){
|
||||
groups.each(function(group){
|
||||
list.addObject(Discourse.Group.create(group));
|
||||
});
|
||||
});
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
find: function(id) {
|
||||
var promise = new Em.Deferred();
|
||||
|
||||
|
||||
setTimeout(function(){
|
||||
promise.resolve(Discourse.Group.create({id: 1, name: "all mods", members: ["A","b","c"]}));
|
||||
}, 1000);
|
||||
|
||||
|
||||
return promise;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
Discourse.AdminGroupsRoute = Discourse.Route.extend({
|
||||
model: function() {
|
||||
return Discourse.Group.findAll();
|
||||
},
|
||||
renderTemplate: function() {
|
||||
this.render('admin/templates/groups',{into: 'admin/templates/admin'});
|
||||
},
|
||||
|
||||
setupController: function(controller, model) {
|
||||
controller.set('model', Discourse.Group.findAll());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -3,20 +3,23 @@
|
||||
<div class='content-list span6'>
|
||||
<h3>{{i18n admin.groups.edit}}</h3>
|
||||
<ul>
|
||||
{{#each group in controller}}
|
||||
{{#each group in model}}
|
||||
<li>
|
||||
<a href="#" {{action "edit" group}} {{bindAttr class="group.active"}}>{{group.name}}</a>
|
||||
<a href="#" {{action "edit" group}} {{bindAttr class="group.active"}}>{{group.name}} <span class="count">{{group.userCountDisplay}}</span></a>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ul>
|
||||
<div>
|
||||
<button {{bindAttr disabled="refreshingAutoGroups"}} {{action "refreshAutoGroups"}}>Refresh Automatic Groups</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='content-editor'>
|
||||
{{#if content.active}}
|
||||
{{#with content.active}}
|
||||
<h3>{{name}}</h3>
|
||||
{{#if model.active}}
|
||||
{{#with model.active}}
|
||||
<h3>{{name}}</h3>
|
||||
{{view Discourse.UserSelector id="private-message-users" class="span8" placeholderKey="admin.groups.selector_placeholder" tabindex="1" usernamesBinding="usernames"}}
|
||||
<button>Save</button>
|
||||
<button {{bindAttr disabled="allowSave"}}>Save</button>
|
||||
|
||||
{{/with}}
|
||||
{{else}}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// this allows you to track the selected item in an array, ghetto for now
|
||||
Discourse.SelectableArray = Em.ArrayProxy.extend({
|
||||
content: [],
|
||||
init: function() {
|
||||
this.content = [];
|
||||
this._super();
|
||||
},
|
||||
selectIndex: function(index){
|
||||
this.select(this[index]);
|
||||
},
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
@import "foundation/mixins";
|
||||
@import "foundation/helpers";
|
||||
|
||||
|
||||
.content-list li a span.count {
|
||||
font-size: 12px;
|
||||
float: right;
|
||||
margin-right: 10px;
|
||||
background-color: #eee;
|
||||
padding: 2px 5px;
|
||||
border-radius: 5px;
|
||||
color: #555;
|
||||
}
|
||||
|
||||
.admin-content {
|
||||
margin-bottom: 50px;
|
||||
.admin-contents {
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
class Admin::GroupsController < Admin::AdminController
|
||||
def index
|
||||
groups = Group.order(:name).all
|
||||
render_serialized(groups, AdminGroupSerializer)
|
||||
end
|
||||
|
||||
def refresh_automatic_groups
|
||||
Group.refresh_automatic_groups!
|
||||
render json: "ok"
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def users
|
||||
group = Group.find(params[:group_id].to_i)
|
||||
render_serialized(group.users, BasicUserSerializer)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,11 +25,12 @@ class Group < ActiveRecord::Base
|
||||
id = AUTO_GROUPS[name]
|
||||
|
||||
unless group = self[name]
|
||||
group = Group.new(name: name.to_s, automatic: true)
|
||||
group = Group.new(name: "", automatic: true)
|
||||
group.id = id
|
||||
group.save!
|
||||
end
|
||||
|
||||
group.name = I18n.t("groups.default_names.#{name}")
|
||||
|
||||
real_ids = case name
|
||||
when :admins
|
||||
@@ -55,9 +56,15 @@ class Group < ActiveRecord::Base
|
||||
end
|
||||
|
||||
group.save!
|
||||
|
||||
# we want to ensure consistency
|
||||
Group.reset_counters(group.id, :group_users)
|
||||
end
|
||||
|
||||
def self.refresh_automatic_groups!(*args)
|
||||
if args.length == 0
|
||||
args = AUTO_GROUPS.map{|k,v| k}
|
||||
end
|
||||
args.each do |group|
|
||||
refresh_automatic_group!(group)
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class GroupUser < ActiveRecord::Base
|
||||
belongs_to :group
|
||||
belongs_to :group, counter_cache: "user_count"
|
||||
belongs_to :user
|
||||
end
|
||||
|
||||
3
app/serializers/admin_group_serializer.rb
Normal file
3
app/serializers/admin_group_serializer.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class AdminGroupSerializer < ApplicationSerializer
|
||||
attributes :id, :automatic, :name, :user_count
|
||||
end
|
||||
Reference in New Issue
Block a user