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'; |
| 22 | import {IUserResource} from "../services/user-resource-service"; |
| 23 | |
| 24 | export enum UserRole { |
| 25 | ADMIN, |
| 26 | DESIGNER, |
| 27 | TESTER, |
| 28 | GOVERNOR, |
Michael Lando | 75aacbb | 2017-07-17 21:12:03 +0300 | [diff] [blame^] | 29 | OPS |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | export interface IUserManager { |
| 33 | isInEditMode:boolean; |
| 34 | filterTerm:string; |
| 35 | } |
| 36 | |
| 37 | export interface IUserProperties extends IUserManager { |
| 38 | firstName:string; |
| 39 | lastName:string; |
| 40 | userId:string; |
| 41 | email:string; |
| 42 | role:string; |
| 43 | tempRole:string; |
| 44 | lastLoginTime:string; |
| 45 | status:string; |
| 46 | } |
| 47 | |
| 48 | export interface IUser { |
| 49 | resource:IUserResource; |
| 50 | getRole():UserRole; |
| 51 | getRoleToView():string; |
| 52 | getName():string; |
| 53 | getFirstName():string; |
| 54 | getLastName():string; |
| 55 | } |
| 56 | |
| 57 | export class User implements IUser { |
| 58 | |
| 59 | constructor(public resource:IUserResource) { |
| 60 | } |
| 61 | |
| 62 | public getLastName = () => { |
| 63 | return this.resource.lastName; |
| 64 | } |
| 65 | |
| 66 | public getFirstName = () => { |
| 67 | return this.resource.firstName; |
| 68 | } |
| 69 | |
| 70 | public getName = () => { |
| 71 | return this.resource.firstName + ' ' + this.resource.lastName; |
| 72 | } |
| 73 | |
| 74 | public getLastLogin = () => { |
| 75 | if (!this.resource.lastLoginTime || this.resource.lastLoginTime === "0") { |
| 76 | return ""; |
| 77 | } else { |
| 78 | return this.resource.lastLoginTime; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | public getRole = ():UserRole => { |
| 83 | let role:UserRole; |
| 84 | switch (UserRole[this.resource.role.toUpperCase()]) { |
| 85 | case UserRole.ADMIN: |
| 86 | role = UserRole.ADMIN; |
| 87 | break; |
| 88 | case UserRole.DESIGNER: |
| 89 | role = UserRole.DESIGNER; |
| 90 | break; |
| 91 | case UserRole.TESTER: |
| 92 | role = UserRole.TESTER; |
| 93 | break; |
| 94 | case UserRole.GOVERNOR: |
| 95 | role = UserRole.GOVERNOR; |
| 96 | break; |
| 97 | case UserRole.OPS: |
| 98 | role = UserRole.OPS; |
| 99 | break; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 100 | } |
| 101 | return role; |
| 102 | } |
| 103 | |
| 104 | public getRoleToView = ():string => { |
| 105 | let role:string = this.resource.role.toLowerCase().replace('governor', 'governance_Rep'); |
| 106 | return role.charAt(0).toUpperCase() + role.slice(1).replace('_', ' '); |
| 107 | } |
| 108 | } |