2020-08-31 17:31:05 +00:00
|
|
|
|
2021-03-09 12:27:26 +00:00
|
|
|
import {makeObservable, observable, action} from 'mobx';
|
2020-08-31 17:31:05 +00:00
|
|
|
|
2020-09-29 18:59:57 +00:00
|
|
|
export class storeUsers {
|
2021-03-09 12:27:26 +00:00
|
|
|
constructor() {
|
|
|
|
makeObservable(this, {
|
|
|
|
users: observable,
|
|
|
|
reset: action,
|
|
|
|
currentUser: observable,
|
|
|
|
setCurrentUser: action,
|
|
|
|
connection: action
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
users = [];
|
|
|
|
currentUser;
|
2020-08-31 17:31:05 +00:00
|
|
|
|
2021-03-09 12:27:26 +00:00
|
|
|
reset (users) {
|
2020-09-29 18:59:57 +00:00
|
|
|
this.users = Object.values(users)
|
|
|
|
}
|
2021-02-18 15:40:54 +00:00
|
|
|
|
2021-03-09 12:27:26 +00:00
|
|
|
setCurrentUser (id) {
|
2021-02-18 15:40:54 +00:00
|
|
|
this.users.forEach((item) => {
|
|
|
|
if (item.asc_getIdOriginal() === id) {
|
|
|
|
this.currentUser = item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-09 12:27:26 +00:00
|
|
|
connection (change) {
|
2021-02-25 16:26:42 +00:00
|
|
|
let changed = false;
|
|
|
|
for (let uid in this.users) {
|
|
|
|
if (undefined !== uid) {
|
|
|
|
const user = this.users[uid];
|
|
|
|
if (user && user.asc_getId() === change.asc_getId()) {
|
|
|
|
this.users[uid] = change;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
!changed && change && (this.users[change.asc_getId()] = change);
|
|
|
|
}
|
|
|
|
|
2021-02-18 15:40:54 +00:00
|
|
|
getInitials (name) {
|
|
|
|
const fio = Common.Utils.UserInfoParser.getParsedName(name).split(' ');
|
|
|
|
let initials = fio[0].substring(0, 1).toUpperCase();
|
|
|
|
for (let i = fio.length-1; i>0; i--) {
|
|
|
|
if (fio[i][0]!=='(' && fio[i][0]!==')') {
|
|
|
|
initials += fio[i].substring(0, 1).toUpperCase();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return initials;
|
|
|
|
}
|
2021-02-25 16:26:42 +00:00
|
|
|
|
|
|
|
searchUserById (id) {
|
2021-03-04 17:24:35 +00:00
|
|
|
let user = null;
|
2021-02-25 16:26:42 +00:00
|
|
|
this.users.forEach((item) => {
|
|
|
|
if (item.asc_getIdOriginal() === id) {
|
2021-03-04 17:24:35 +00:00
|
|
|
user = item;
|
2021-02-25 16:26:42 +00:00
|
|
|
}
|
|
|
|
});
|
2021-03-04 17:24:35 +00:00
|
|
|
return user;
|
2021-02-25 16:26:42 +00:00
|
|
|
}
|
2020-09-29 18:59:57 +00:00
|
|
|
}
|