2018-09-11 16:38:23 +02:00
|
|
|
import { BaseViewModel } from '../../base/base-view-model';
|
|
|
|
import { User } from '../../../shared/models/users/user';
|
|
|
|
import { Group } from '../../../shared/models/users/group';
|
|
|
|
import { BaseModel } from '../../../shared/models/base/base-model';
|
|
|
|
|
|
|
|
export class ViewUser extends BaseViewModel {
|
|
|
|
private _user: User;
|
|
|
|
private _groups: Group[];
|
|
|
|
|
|
|
|
public get user(): User {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this._user ? this._user : null;
|
2018-09-11 16:38:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public get groups(): Group[] {
|
|
|
|
return this._groups;
|
|
|
|
}
|
|
|
|
|
2018-09-18 18:27:14 +02:00
|
|
|
public get id(): number {
|
|
|
|
return this.user ? this.user.id : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get username(): string {
|
|
|
|
return this.user ? this.user.username : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get title(): string {
|
|
|
|
return this.user ? this.user.title : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get first_name(): string {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this.user ? this.user.first_name : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get last_name(): string {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this.user ? this.user.last_name : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get full_name(): string {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.user ? this.user.full_name : null;
|
|
|
|
}
|
|
|
|
|
2018-09-18 18:27:14 +02:00
|
|
|
public get email(): string {
|
|
|
|
return this.user ? this.user.email : null;
|
2018-09-11 16:38:23 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get structure_level(): string {
|
2018-09-11 16:38:23 +02:00
|
|
|
return this.user ? this.user.structure_level : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get participant_number(): string {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this.user ? this.user.number : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get groups_id(): number[] {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this.user ? this.user.groups_id : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Required by the input selector
|
|
|
|
*/
|
|
|
|
public set groupIds(ids: number[]) {
|
|
|
|
if (this.user) {
|
|
|
|
this.user.groups_id = ids;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get default_password(): string {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this.user ? this.user.default_password : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get comment(): string {
|
|
|
|
return this.user ? this.user.comment : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get is_present(): boolean {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this.user ? this.user.is_present : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get is_active(): boolean {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this.user ? this.user.is_active : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get is_committee(): boolean {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this.user ? this.user.is_committee : null;
|
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
public get about_me(): string {
|
2018-09-18 18:27:14 +02:00
|
|
|
return this.user ? this.user.about_me : null;
|
|
|
|
}
|
|
|
|
|
2018-09-11 16:38:23 +02:00
|
|
|
public constructor(user?: User, groups?: Group[]) {
|
|
|
|
super();
|
|
|
|
this._user = user;
|
|
|
|
this._groups = groups;
|
|
|
|
}
|
|
|
|
|
2018-09-18 18:27:14 +02:00
|
|
|
/**
|
|
|
|
* required by BaseViewModel. Don't confuse with the users title.
|
|
|
|
*/
|
2018-09-11 16:38:23 +02:00
|
|
|
public getTitle(): string {
|
|
|
|
return this.user ? this.user.toString() : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TODO: Implement
|
|
|
|
*/
|
2018-09-18 18:27:14 +02:00
|
|
|
public replaceGroup(newGroup: Group): void {}
|
2018-09-11 16:38:23 +02:00
|
|
|
|
2018-09-20 12:25:37 +02:00
|
|
|
public updateValues(update: BaseModel): void {
|
|
|
|
if (update instanceof Group) {
|
|
|
|
this.updateGroup(update as Group);
|
|
|
|
}
|
|
|
|
if (update instanceof User) {
|
|
|
|
this.updateUser(update as User);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public updateGroup(update: Group): void {
|
|
|
|
if (this.user && this.user.groups_id) {
|
|
|
|
if (this.user.containsGroupId(update.id)) {
|
|
|
|
this.replaceGroup(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-11 16:38:23 +02:00
|
|
|
/**
|
|
|
|
* Updates values. Triggered through observables.
|
|
|
|
*
|
|
|
|
* @param update a new User or Group
|
|
|
|
*/
|
2018-09-20 12:25:37 +02:00
|
|
|
public updateUser(update: User): void {
|
|
|
|
if (this.user.id === update.id) {
|
|
|
|
this._user = update;
|
2018-09-11 16:38:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|