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=========================================================
20 /// <reference path="../../../../references"/>
21 module Sdc.ViewModels {
24 export interface IActivityLogViewModelScope extends IWorkspaceViewModelScope {
25 activityDateArray: Array<any>; //this is in order to sort the dates
26 activityLog: Array<Models.Activity>;
29 tableHeadersList: Array<any>;
34 getActivityLog(uniqueId:string):void;
35 onVersionChanged(version:any) : void;
36 parseAction(action:string):string;
37 sort(sortBy:string): void;
40 export class ActivityLogViewModel {
45 'Sdc.Services.ActivityLogService'
48 constructor(private $scope:IActivityLogViewModelScope,
49 private $state:ng.ui.IStateService,
50 private activityLogService:Services.ActivityLogService
54 this.$scope.setValidState(true);
55 this.initSortedTableScope();
56 this.$scope.updateSelectedMenuItem();
58 // Set default sorting
59 this.$scope.sortBy = 'logDate';
62 private initScope():void {
64 this.$scope.preVersion = this.$scope.component.version;
66 this.$scope.onVersionChanged = (version:any):void => {
67 if (version.versionNumber != this.$scope.component.version) {
68 this.$scope.isLoading = true;
69 this.$scope.getActivityLog(version.versionId);
73 this.$scope.getActivityLog = (uniqueId:any):void => {
75 let onError = (response) => {
76 this.$scope.isLoading = false;
77 console.info('onFaild', response);
81 let onSuccess = (response:Array<Models.Activity>) => {
82 this.$scope.activityLog = _.sortBy(response, function(o) { return o.TIMESTAMP; }); //response; //
83 this.$scope.isLoading = false;
86 this.$scope.isLoading = true;
87 if (this.$scope.component.isResource()) {
88 this.activityLogService.getActivityLogService('resources', uniqueId).then(onSuccess, onError);
90 if (this.$scope.component.isService()) {
91 this.activityLogService.getActivityLogService('services', uniqueId).then(onSuccess, onError);
96 if (!this.$scope.activityLog || this.$scope.preVersion != this.$scope.component.version) {
97 this.$scope.getActivityLog(this.$scope.component.uniqueId);
100 this.$scope.parseAction = (action:string) => {
101 return action ? action.split(/(?=[A-Z])/).join(' ') : '';
106 private initSortedTableScope = ():void => {
107 this.$scope.tableHeadersList = [
108 {title: 'Date', property: 'logDate'},
109 {title: 'Action', property: 'logAction'},
110 {title: 'Comment', property: 'logComment'},
111 {title: 'Username', property: 'logUsername'},
112 {title: 'Status', property: 'logStatus'}
115 this.$scope.sort = (sortBy:string):void => {
116 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
117 this.$scope.sortBy = sortBy;