[feat] sort names by display name mode
This commit is contained in:
parent
d34898e1e9
commit
d35cc8e8d1
|
@ -1,6 +1,7 @@
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { api } from '../internal';
|
import { api } from '../internal';
|
||||||
import { isAxiosError, useMainStore } from '.';
|
import { isAxiosError, useMainStore } from '.';
|
||||||
|
import { DisplayNameMode } from '@flaschengeist/users';
|
||||||
|
|
||||||
export function fixUser(u?: FG.User) {
|
export function fixUser(u?: FG.User) {
|
||||||
return !u ? u : Object.assign(u, { birthday: u.birthday ? new Date(u.birthday) : undefined });
|
return !u ? u : Object.assign(u, { birthday: u.birthday ? new Date(u.birthday) : undefined });
|
||||||
|
@ -33,16 +34,40 @@ export const useUserStore = defineStore({
|
||||||
getters: {
|
getters: {
|
||||||
users(state) {
|
users(state) {
|
||||||
const u = state._users.filter((u) => !u.deleted);
|
const u = state._users.filter((u) => !u.deleted);
|
||||||
u.sort((a, b) => {
|
|
||||||
const a_lastname = a.lastname.toLowerCase();
|
switch (this.userSettings['display_name']) {
|
||||||
const b_lastname = b.lastname.toLowerCase();
|
case DisplayNameMode.FIRSTNAME_LASTNAME || DisplayNameMode.FIRSTNAME:
|
||||||
const a_firstname = a.firstname.toLowerCase();
|
u.sort((a, b) => {
|
||||||
const b_firstname = b.firstname.toLowerCase();
|
const a_lastname = a.lastname.toLowerCase();
|
||||||
if (a_lastname === b_lastname) {
|
const b_lastname = b.lastname.toLowerCase();
|
||||||
return a_firstname < b_firstname ? -1 : 1;
|
const a_firstname = a.firstname.toLowerCase();
|
||||||
}
|
const b_firstname = b.firstname.toLowerCase();
|
||||||
return a_lastname < b_lastname ? -1 : 1;
|
if (a_firstname === b_firstname) {
|
||||||
});
|
return a_lastname < b_lastname ? -1 : 1;
|
||||||
|
}
|
||||||
|
return a_firstname < b_firstname ? -1 : 1;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case <string>DisplayNameMode.DISPLAYNAME:
|
||||||
|
u.sort((a, b) => {
|
||||||
|
const a_displayname = a.display_name.toLowerCase();
|
||||||
|
const b_displayname = b.display_name.toLowerCase();
|
||||||
|
return a_displayname < b_displayname ? -1 : 1;
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
u.sort((a, b) => {
|
||||||
|
const a_lastname = a.lastname.toLowerCase();
|
||||||
|
const b_lastname = b.lastname.toLowerCase();
|
||||||
|
const a_firstname = a.firstname.toLowerCase();
|
||||||
|
const b_firstname = b.firstname.toLowerCase();
|
||||||
|
if (a_lastname === b_lastname) {
|
||||||
|
return a_firstname < b_firstname ? -1 : 1;
|
||||||
|
}
|
||||||
|
return a_lastname < b_lastname ? -1 : 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return u;
|
return u;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue