Fix bugs in attribute outputs page
[sdc.git] / catalog-ui / src / app / models / user.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 'use strict';
21
22 export enum UserRole {
23     ADMIN,
24     DESIGNER
25 }
26
27 // tslint:disable-next-line:interface-name
28 export interface IUserManager {
29     isInEditMode: boolean;
30     filterTerm: string;
31 }
32
33 // tslint:disable-next-line:interface-name
34 export interface IUserProperties extends IUserManager {
35     firstName: string;
36     lastName: string;
37     userId: string;
38     email: string;
39     role: string;
40     tempRole: string;
41     lastLoginTime: string;
42     status: string;
43 }
44
45 // tslint:disable-next-line:interface-name
46 export interface IUser {
47     userInfo: IUserProperties;
48     getRole(): UserRole;
49     getRoleToView(): string;
50     getName(): string;
51     getFirstName(): string;
52     getLastName(): string;
53 }
54
55 export class User implements IUser {
56
57     constructor(public userInfo: IUserProperties) {
58     }
59
60     public getLastName = () => {
61         return this.userInfo.lastName;
62     }
63
64     public getFirstName = () => {
65         return this.userInfo.firstName;
66     }
67
68     public getName = () => {
69         return this.userInfo.firstName + ' ' + this.userInfo.lastName;
70     }
71
72     public getLastLogin = () => {
73         if (!this.userInfo.lastLoginTime || this.userInfo.lastLoginTime === '0') {
74             return '';
75         } else {
76             return this.userInfo.lastLoginTime;
77         }
78     }
79
80     public getRole = (): UserRole => {
81         let role: UserRole;
82         switch (UserRole[this.userInfo.role.toUpperCase()]) {
83             case UserRole.ADMIN:
84                 role = UserRole.ADMIN;
85                 break;
86             case UserRole.DESIGNER:
87                 role = UserRole.DESIGNER;
88                 break;
89         }
90         return role;
91     }
92
93     public getRoleToView = (): string => {
94         const role: string = this.userInfo.role.toLowerCase().replace('governor', 'governance_Rep');
95         return role.charAt(0).toUpperCase() + role.slice(1).replace('_', ' ');
96     }
97 }