summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-header/drawing-board-header.service.ts
blob: 4e8e3116323f0243b3397fc570d60242bf88cf76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import {Injectable} from "@angular/core";
import {ActivatedRoute} from "@angular/router";
import {addServiceAction} from "../../../shared/storeUtil/utils/service/service.actions";
import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
import {AppState} from "../../../shared/store/reducers";
import {DrawingBoardTreeComponent} from "../drawing-board-tree/drawing-board-tree.component";
import {AuditInfoModalComponent} from "../../../shared/components/auditInfoModal/auditInfoModal.component";
import {ServiceModel} from "../../../shared/models/serviceModel";
import {NgRedux} from "@angular-redux/store";
import * as _ from 'lodash';
import {ErrorMsgService} from "../../../shared/components/error-msg/error-msg.service";
import {DrawingBoardModes} from "../drawing-board.modes";
import {ServiceInstance} from "../../../shared/models/serviceInstance";
import {FeatureFlagsService, Features} from "../../../shared/services/featureFlag/feature-flags.service";

@Injectable()
export class DrawingBoardHeaderService{

  constructor(private route: ActivatedRoute, private store: NgRedux<AppState>, private errorMsgService: ErrorMsgService){}
  generateOldViewEditPath(): string{
    let query: string =
      `subscriberId=${this.route.snapshot.queryParams['subscriberId']}&` +
      `subscriberName=${this.route.snapshot.queryParams['subscriberName']}&` +
      `serviceType=${this.route.snapshot.queryParams['serviceType']}&` +
      `serviceInstanceId=${this.route.snapshot.queryParams['serviceInstanceId']}`;
    return '../../serviceModels.htm#/instantiate?' + query;
  }

  deleteService(serviceModelId: string, isDeleted: boolean ) {
    if(isDeleted){
      this.store.dispatch(addServiceAction(serviceModelId, ServiceInstanceActions.Delete));
      DrawingBoardTreeComponent.triggerDeleteActionService.next(serviceModelId);
    } else{
      this.store.dispatch(addServiceAction(serviceModelId, ServiceInstanceActions.None));
      DrawingBoardTreeComponent.triggerUndoDeleteActionService.next(serviceModelId);
    }
  }

  upgradeService(serviceModelId: string, isUpgraded: boolean ) {
    if(isUpgraded){
      this.store.dispatch(addServiceAction(serviceModelId, ServiceInstanceActions.Upgrade));
    }
    else{
      this.store.dispatch(addServiceAction(serviceModelId, ServiceInstanceActions.None));
    }
  }

  showAuditInfo(serviceModelId) : void {
    let instance: ServiceInstance = this.store.getState().service.serviceInstance[serviceModelId];
    let model =  new ServiceModel(this.store.getState().service.serviceHierarchy[serviceModelId]);
    AuditInfoModalComponent.openInstanceAuditInfoModal.next({instanceId : serviceModelId , type : 'SERVICE', model : model , instance : instance});
  }

  toggleResumeService(serviceModelId, isResume: boolean) : void {
    const action: ServiceInstanceActions = isResume ? ServiceInstanceActions.Resume : ServiceInstanceActions.None;
    this.store.dispatch(addServiceAction(serviceModelId, action));

  }


  /*************************************************
    should return true if deploy should be disabled
   *************************************************/
  deployShouldBeDisabled(serviceInstanceId: string, mode : string) : boolean {
    const serviceInstance = this.store.getState().service.serviceInstance[serviceInstanceId];
    if(!_.isNil(serviceInstance)){
      const validationCounter = serviceInstance.validationCounter;
      if (!_.isNil(this.errorMsgService.errorMsgObject) && mode !== DrawingBoardModes.RETRY_EDIT) return true;
      if(validationCounter > 0) return true;
      if(serviceInstance.action !== ServiceInstanceActions.None) return false;
      if(mode === DrawingBoardModes.RETRY_EDIT) return false;
      return !serviceInstance.isDirty;
    }
    return true;
  }

  getModeButton(mode : string) : string {
    switch (mode) {
      case DrawingBoardModes.EDIT:
        return 'UPDATE';
      case DrawingBoardModes.RETRY_EDIT:
        return 'REDEPLOY';
      default: return 'DEPLOY';
    }
  }
  getButtonText(mode : DrawingBoardModes) : string {
    switch (mode) {
      case DrawingBoardModes.EDIT:
      case DrawingBoardModes.VIEW:
        return 'EDIT';
      case DrawingBoardModes.RETRY_EDIT:
      case DrawingBoardModes.RETRY:
        return 'REDEPLOY';
    }
  }

  showEditService(mode: DrawingBoardModes, serviceModelId: string): boolean{
    const serviceInstance = this.store.getState().service.serviceInstance;
    return mode === DrawingBoardModes.CREATE || mode === DrawingBoardModes.RECREATE || ((mode === DrawingBoardModes.RETRY_EDIT || mode === DrawingBoardModes.EDIT)&&
      !_.isNil(serviceInstance) && !_.isNil(serviceInstance[serviceModelId])&& serviceInstance[serviceModelId].action === ServiceInstanceActions.Create);
  }

  showResumeService(serviceModelId: string): boolean {
    const serviceInstance: ServiceInstance = !_.isNil(this.store.getState().service.serviceInstance)? this.store.getState().service.serviceInstance[serviceModelId] : null;
    if (serviceInstance)
    {
      return FeatureFlagsService.getFlagState(Features.FLAG_1908_RESUME_MACRO_SERVICE, this.store) &&
        serviceInstance.vidNotions.instantiationType.toLowerCase() === "macro" &&
        serviceInstance.subscriptionServiceType.toLowerCase() !== "transport" &&
        serviceInstance.orchStatus &&
        (serviceInstance.orchStatus.toLowerCase() === "assigned" ||
          serviceInstance.orchStatus.toLowerCase() === "inventoried");
    }
    return false;
  }
}