2 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
3 import {Activity} from "app/models";
4 import {ActivityLogService} from "app/services";
6 export interface IActivityLogViewModelScope extends IWorkspaceViewModelScope {
7 activityDateArray:Array<any>; //this is in order to sort the dates
8 activityLog:Array<Activity>;
11 tableHeadersList:Array<any>;
16 getActivityLog(uniqueId:string):void;
17 onVersionChanged(version:any):void;
18 parseAction(action:string):string;
19 sort(sortBy:string):void;
22 export class ActivityLogViewModel {
27 'Sdc.Services.ActivityLogService'
30 constructor(private $scope:IActivityLogViewModelScope,
31 private $state:ng.ui.IStateService,
32 private activityLogService:ActivityLogService) {
35 this.$scope.setValidState(true);
36 this.initSortedTableScope();
37 this.$scope.updateSelectedMenuItem();
39 // Set default sorting
40 this.$scope.sortBy = 'logDate';
43 private initScope():void {
45 this.$scope.preVersion = this.$scope.component.version;
47 this.$scope.onVersionChanged = (version:any):void => {
48 if (version.versionNumber != this.$scope.component.version) {
49 this.$scope.isLoading = true;
50 this.$scope.getActivityLog(version.versionId);
54 this.$scope.getActivityLog = (uniqueId:any):void => {
56 let onError = (response) => {
57 this.$scope.isLoading = false;
58 console.info('onFaild', response);
62 let onSuccess = (response:Array<Activity>) => {
63 this.$scope.activityLog = _.sortBy(response, function (o) {
66 this.$scope.isLoading = false;
69 this.$scope.isLoading = true;
70 if (this.$scope.component.isResource()) {
71 this.activityLogService.getActivityLogService('resources', uniqueId).then(onSuccess, onError);
73 if (this.$scope.component.isService()) {
74 this.activityLogService.getActivityLogService('services', uniqueId).then(onSuccess, onError);
79 if (!this.$scope.activityLog || this.$scope.preVersion != this.$scope.component.version) {
80 this.$scope.getActivityLog(this.$scope.component.uniqueId);
83 this.$scope.parseAction = (action:string) => {
84 return action ? action.split(/(?=[A-Z])/).join(' ') : '';
89 private initSortedTableScope = ():void => {
90 this.$scope.tableHeadersList = [
91 {title: 'Date', property: 'dateFormat'},
92 {title: 'Action', property: 'ACTION'},
93 {title: 'Comment', property: 'COMMENT'},
94 {title: 'Username', property: 'MODIFIER'},
95 {title: 'Status', property: 'STATUS'}
98 this.$scope.sort = (sortBy:string):void => {
99 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
100 this.$scope.sortBy = sortBy;