Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 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 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 21 | 'use strict'; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 22 | |
| 23 | export enum UserRole { |
| 24 | ADMIN, |
| 25 | DESIGNER, |
| 26 | TESTER, |
| 27 | GOVERNOR, |
Michael Lando | 75aacbb | 2017-07-17 21:12:03 +0300 | [diff] [blame] | 28 | OPS |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | export interface IUserManager { |
| 32 | isInEditMode:boolean; |
| 33 | filterTerm:string; |
| 34 | } |
| 35 | |
| 36 | export 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 | |
| 47 | export interface IUser { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 48 | userInfo:IUserProperties; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 49 | getRole():UserRole; |
| 50 | getRoleToView():string; |
| 51 | getName():string; |
| 52 | getFirstName():string; |
| 53 | getLastName():string; |
| 54 | } |
| 55 | |
| 56 | export class User implements IUser { |
| 57 | |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 58 | constructor(public userInfo:IUserProperties) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | public getLastName = () => { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 62 | return this.userInfo.lastName; |
| 63 | }; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 64 | |
| 65 | public getFirstName = () => { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 66 | return this.userInfo.firstName; |
| 67 | }; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 68 | |
| 69 | public getName = () => { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 70 | return this.userInfo.firstName + ' ' + this.userInfo.lastName; |
| 71 | }; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 72 | |
| 73 | public getLastLogin = () => { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 74 | if (!this.userInfo.lastLoginTime || this.userInfo.lastLoginTime === "0") { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 75 | return ""; |
| 76 | } else { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 77 | return this.userInfo.lastLoginTime; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 78 | } |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 79 | }; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 80 | |
| 81 | public getRole = ():UserRole => { |
| 82 | let role:UserRole; |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 83 | switch (UserRole[this.userInfo.role.toUpperCase()]) { |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 84 | 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 Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 99 | } |
| 100 | return role; |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 101 | }; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 102 | |
| 103 | public getRoleToView = ():string => { |
Tal Gitelman | 51d50f0 | 2017-12-10 18:55:03 +0200 | [diff] [blame] | 104 | let role:string = this.userInfo.role.toLowerCase().replace('governor', 'governance_Rep'); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 105 | return role.charAt(0).toUpperCase() + role.slice(1).replace('_', ' '); |
| 106 | } |
| 107 | } |