blob: 0fb536429094618cbdbbcf56f22db0da83b09ea3 [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
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
Michael Landoed64b5e2017-06-09 03:19:04 +030021'use strict';
Michael Landoed64b5e2017-06-09 03:19:04 +030022
23export enum UserRole {
24 ADMIN,
25 DESIGNER,
26 TESTER,
27 GOVERNOR,
Michael Lando75aacbb2017-07-17 21:12:03 +030028 OPS
Michael Landoed64b5e2017-06-09 03:19:04 +030029}
30
31export interface IUserManager {
32 isInEditMode:boolean;
33 filterTerm:string;
34}
35
36export interface IUserProperties extends IUserManager {
37 firstName:string;
38 lastName:string;
39 userId:string;
40 email:string;
41 role:string;
42 tempRole:string;
43 lastLoginTime:string;
44 status:string;
45}
46
47export interface IUser {
Tal Gitelman51d50f02017-12-10 18:55:03 +020048 userInfo:IUserProperties;
Michael Landoed64b5e2017-06-09 03:19:04 +030049 getRole():UserRole;
50 getRoleToView():string;
51 getName():string;
52 getFirstName():string;
53 getLastName():string;
54}
55
56export class User implements IUser {
57
Tal Gitelman51d50f02017-12-10 18:55:03 +020058 constructor(public userInfo:IUserProperties) {
Michael Landoed64b5e2017-06-09 03:19:04 +030059 }
60
61 public getLastName = () => {
Tal Gitelman51d50f02017-12-10 18:55:03 +020062 return this.userInfo.lastName;
63 };
Michael Landoed64b5e2017-06-09 03:19:04 +030064
65 public getFirstName = () => {
Tal Gitelman51d50f02017-12-10 18:55:03 +020066 return this.userInfo.firstName;
67 };
Michael Landoed64b5e2017-06-09 03:19:04 +030068
69 public getName = () => {
Tal Gitelman51d50f02017-12-10 18:55:03 +020070 return this.userInfo.firstName + ' ' + this.userInfo.lastName;
71 };
Michael Landoed64b5e2017-06-09 03:19:04 +030072
73 public getLastLogin = () => {
Tal Gitelman51d50f02017-12-10 18:55:03 +020074 if (!this.userInfo.lastLoginTime || this.userInfo.lastLoginTime === "0") {
Michael Landoed64b5e2017-06-09 03:19:04 +030075 return "";
76 } else {
Tal Gitelman51d50f02017-12-10 18:55:03 +020077 return this.userInfo.lastLoginTime;
Michael Landoed64b5e2017-06-09 03:19:04 +030078 }
Tal Gitelman51d50f02017-12-10 18:55:03 +020079 };
Michael Landoed64b5e2017-06-09 03:19:04 +030080
81 public getRole = ():UserRole => {
82 let role:UserRole;
Tal Gitelman51d50f02017-12-10 18:55:03 +020083 switch (UserRole[this.userInfo.role.toUpperCase()]) {
Michael Landoed64b5e2017-06-09 03:19:04 +030084 case UserRole.ADMIN:
85 role = UserRole.ADMIN;
86 break;
87 case UserRole.DESIGNER:
88 role = UserRole.DESIGNER;
89 break;
90 case UserRole.TESTER:
91 role = UserRole.TESTER;
92 break;
93 case UserRole.GOVERNOR:
94 role = UserRole.GOVERNOR;
95 break;
96 case UserRole.OPS:
97 role = UserRole.OPS;
98 break;
Michael Landoed64b5e2017-06-09 03:19:04 +030099 }
100 return role;
Tal Gitelman51d50f02017-12-10 18:55:03 +0200101 };
Michael Landoed64b5e2017-06-09 03:19:04 +0300102
103 public getRoleToView = ():string => {
Tal Gitelman51d50f02017-12-10 18:55:03 +0200104 let role:string = this.userInfo.role.toLowerCase().replace('governor', 'governance_Rep');
Michael Landoed64b5e2017-06-09 03:19:04 +0300105 return role.charAt(0).toUpperCase() + role.slice(1).replace('_', ' ');
106 }
107}