feat: will now properly re-order channels whenever a new club/soc is added
This commit is contained in:
parent
143483d3b3
commit
934842cbc9
1 changed files with 12 additions and 9 deletions
|
@ -363,28 +363,31 @@ pub mod committee {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut channel_names = vec![];
|
let mut channel_names = vec![];
|
||||||
|
let mut positions = vec![];
|
||||||
for role in roles_db.values() {
|
for role in roles_db.values() {
|
||||||
// save these to db
|
// save these to db
|
||||||
db_role_set(db, role).await;
|
db_role_set(db, role).await;
|
||||||
|
|
||||||
// pull out teh channel names
|
|
||||||
if re_order {
|
if re_order {
|
||||||
channel_names.push((role.name_channel.to_owned(), role.id_channel));
|
let channel_id = role.id_channel.to_owned();
|
||||||
|
if let Some(channel) = channels.get_mut(&channel_id) {
|
||||||
|
// record the position of each of teh C&S channels
|
||||||
|
positions.push(channel.position);
|
||||||
|
|
||||||
|
// pull out teh channel names
|
||||||
|
channel_names.push((role.name_channel.to_owned(), channel_id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if re_order {
|
if re_order {
|
||||||
|
// sort by the position and name
|
||||||
|
positions.sort();
|
||||||
channel_names.sort_by_key(|(name, _)| name.to_owned());
|
channel_names.sort_by_key(|(name, _)| name.to_owned());
|
||||||
|
|
||||||
// get a list of all teh new positions
|
|
||||||
let mut new_positions = vec![];
|
let mut new_positions = vec![];
|
||||||
for (i, (_, id)) in channel_names.iter().enumerate() {
|
for (i, (_, id)) in channel_names.iter().enumerate() {
|
||||||
if let Some(channel) = channels.get_mut(id) {
|
new_positions.push((id.to_owned(), positions[i] as u64));
|
||||||
let position_new = i as u64;
|
|
||||||
if position_new != channel.position as u64 {
|
|
||||||
new_positions.push((channel.id.to_owned(), position_new));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !new_positions.is_empty() {
|
if !new_positions.is_empty() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue