user_groups: Convert members to a dict in frontend.

This commit is contained in:
Tim Abbott 2018-03-04 08:44:12 -08:00
parent 3a14317376
commit 0147826042
5 changed files with 16 additions and 8 deletions

View File

@ -1,3 +1,4 @@
zrequire('dict');
zrequire('settings_user_groups'); zrequire('settings_user_groups');
set_global('$', global.make_zjquery()); set_global('$', global.make_zjquery());
@ -28,7 +29,7 @@ set_global('people', {
id: 1, id: 1,
name: 'Mobile', name: 'Mobile',
description: 'All mobile people', description: 'All mobile people',
members: [2, 4], members: Dict.from_array([2, 4]),
}; };
var iago = { var iago = {
email: 'iago@zulip.com', email: 'iago@zulip.com',
@ -226,7 +227,7 @@ set_global('people', {
}; };
pills.onPillRemove = function (handler) { pills.onPillRemove = function (handler) {
realm_user_group.members = [2, 31]; realm_user_group.members = Dict.from_array([2, 31]);
fade_to_called = false; fade_to_called = false;
fade_out_called = false; fade_out_called = false;
handler(); handler();
@ -493,7 +494,7 @@ set_global('people', {
id: 1, id: 1,
name: 'Mobile', name: 'Mobile',
description: 'All mobile people', description: 'All mobile people',
members: [2, 4], members: Dict.from_array([2, 4]),
}; };
var fake_this = $.create('fake-#user-groups_click_save_member_changes'); var fake_this = $.create('fake-#user-groups_click_save_member_changes');
user_groups.get_user_group_from_id = function (id) { user_groups.get_user_group_from_id = function (id) {

View File

@ -1,12 +1,14 @@
set_global('blueslip', {}); set_global('blueslip', {});
set_global('page_params', {}); set_global('page_params', {});
zrequire('dict');
zrequire('user_groups'); zrequire('user_groups');
(function test_user_groups() { (function test_user_groups() {
var students = { var students = {
name: 'Students', name: 'Students',
id: 0, id: 0,
members: [1, 2],
}; };
global.page_params.realm_user_groups = [students]; global.page_params.realm_user_groups = [students];
@ -16,10 +18,12 @@ zrequire('user_groups');
var admins = { var admins = {
name: 'Admins', name: 'Admins',
id: 1, id: 1,
members: [3],
}; };
var all = { var all = {
name: 'Everyone', name: 'Everyone',
id: 2, id: 2,
members: [1, 2, 3],
}; };
user_groups.add(admins); user_groups.add(admins);

View File

@ -189,7 +189,7 @@ function show_user_group_info_popover(element, group, message) {
var args = { var args = {
group_name: group.name, group_name: group.name,
group_description: group.description, group_description: group.description,
members: sort_group_members(fetch_group_members(group.members)), members: sort_group_members(fetch_group_members(group.members.keys())),
}; };
elt.popover({ elt.popover({
placement: calculate_info_popover_placement(popover_size, elt), placement: calculate_info_popover_placement(popover_size, elt),

View File

@ -36,7 +36,7 @@ exports.populate_user_groups = function () {
var pill_container = $('.pill-container[data-group-pills="' + data.name + '"]'); var pill_container = $('.pill-container[data-group-pills="' + data.name + '"]');
var pills = input_pill(pill_container); var pills = input_pill(pill_container);
data.members.forEach(function (user_id) { data.members.keys().forEach(function (user_id) {
var user = people.get_person_from_user_id(user_id); var user = people.get_person_from_user_id(user_id);
if (user) { if (user) {
@ -47,7 +47,7 @@ exports.populate_user_groups = function () {
}); });
function update_save_state(draft_group) { function update_save_state(draft_group) {
var original_group = user_groups.get_user_group_from_id(data.id).members; var original_group = user_groups.get_user_group_from_id(data.id).members.keys();
var same_groups = _.isEqual(_.sortBy(draft_group), _.sortBy(original_group)); var same_groups = _.isEqual(_.sortBy(draft_group), _.sortBy(original_group));
var save_changes = pill_container.siblings('.save-member-changes'); var save_changes = pill_container.siblings('.save-member-changes');
var save_hidden = save_changes.css('display') === 'none'; var save_hidden = save_changes.css('display') === 'none';
@ -110,7 +110,7 @@ exports.populate_user_groups = function () {
$('#user-groups #' + data.id).on('click', '.save-member-changes', function () { $('#user-groups #' + data.id).on('click', '.save-member-changes', function () {
var draft_group = pills.keys(); var draft_group = pills.keys();
var group_data = user_groups.get_user_group_from_id(data.id); var group_data = user_groups.get_user_group_from_id(data.id);
var original_group = group_data.members; var original_group = group_data.members.keys();
var added = _.difference(draft_group, original_group); var added = _.difference(draft_group, original_group);
var removed = _.difference(original_group, draft_group); var removed = _.difference(original_group, draft_group);
var btn = $(this); var btn = $(this);

View File

@ -16,6 +16,9 @@ exports.init = function () {
exports.init(); exports.init();
exports.add = function (user_group) { exports.add = function (user_group) {
// Reformat the user group members structure to be a dict.
user_group.members = Dict.from_array(user_group.members);
user_group_name_dict.set(user_group.name, user_group); user_group_name_dict.set(user_group.name, user_group);
user_group_by_id_dict.set(user_group.id, user_group); user_group_by_id_dict.set(user_group.id, user_group);
}; };
@ -43,7 +46,7 @@ exports.get_realm_user_groups = function () {
exports.is_member_of = function (user_group_id, user_id) { exports.is_member_of = function (user_group_id, user_id) {
var user_group = user_group_by_id_dict.get(user_group_id); var user_group = user_group_by_id_dict.get(user_group_id);
return user_group.members.indexOf(user_id) !== -1; return user_group.members.has(user_id);
}; };
exports.initialize = function () { exports.initialize = function () {