2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 import * as _ from "lodash";
23 import { User, IUserProperties, IUser, IAppConfigurtaion } from "app/models";
24 import { UserService } from "../../../ng2/services/user.service";
25 import { SdcUiCommon, SdcUiServices, SdcUiComponents } from "onap-ui-angular";
26 import { AuthenticationService } from "app/ng2/services/authentication.service";
28 interface IUserManagementViewModelScope extends ng.IScope {
29 usersList:Array<IUserProperties>;
35 sort(sortBy:string):void;
36 getTitle(role:string):string;
40 export class UserManagementViewModel {
44 'AuthenticationServiceNg2',
49 constructor(private $scope:IUserManagementViewModelScope,
50 private userService:UserService,
51 private authService:AuthenticationService,
52 private $filter:ng.IFilterService,
53 private modalService:SdcUiServices.ModalService) {
56 setTimeout(this.initScope, 1000);
60 private getAllUsers = ():void => {
61 this.$scope.isLoading = true;
63 let onError = (response) => {
64 this.$scope.isLoading = false;
65 console.info('onFaild', response);
67 let onSuccess = (response:Array<IUserProperties>) => {
68 this.$scope.usersList = response;
69 _.forEach(this.$scope.usersList, (user:any, i:number)=> {
72 this.$scope.isLoading = false;
74 this.userService.getAllUsers().subscribe(onSuccess, onError);
77 private initScope = ():void => {
79 this.$scope.tableHeadersList = [{title: "First Name", property: 'firstName'}, {
84 title: this.$filter('translate')("USER_MANAGEMENT_TABLE_HEADER_USER_ID"),
86 }, {title: "Email", property: 'email'}, {title: "Role", property: 'role'}, {
88 property: 'lastLoginTime'
90 this.$scope.sortBy = 'lastLoginTime';
91 this.$scope.reverse = false;
94 this.$scope.sort = (sortBy:string):void => {//default sort by descending last update. default for alphabetical = ascending
95 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? ( !this.$scope.reverse) : this.$scope.reverse = false;
96 this.$scope.sortBy = sortBy;
99 this.$scope.getTitle = (role:string):string => {
100 return role.toLowerCase().replace('governor', 'governance_Rep').replace('_', ' ');