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