Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame^] | 1 | import {Injectable} from "@angular/core"; |
| 2 | import {NgRedux} from "@angular-redux/store"; |
| 3 | import {AppState} from "../../../shared/store/reducers"; |
| 4 | import {AaiService} from "../../../shared/services/aaiService/aai.service"; |
| 5 | import {Subject} from "rxjs"; |
| 6 | import {ComponentInfoModel, ComponentInfoType} from "./component-info-model"; |
| 7 | import {ModelInformationItem} from "../../../shared/components/model-information/model-information.component"; |
| 8 | import * as _ from 'lodash'; |
| 9 | @Injectable() |
| 10 | export class ComponentInfoService { |
| 11 | static triggerComponentInfoChange: Subject<ComponentInfoModel> = new Subject<ComponentInfoModel>(); |
| 12 | constructor( private _store: NgRedux<AppState>, private _aaiService : AaiService){ } |
| 13 | |
| 14 | getInfoForService(serviceModelId):ComponentInfoModel { |
| 15 | if(_.isNil(this._store.getState().service.serviceHierarchy[serviceModelId])) return null; |
| 16 | |
| 17 | let serviceHierarchy = this._store.getState().service.serviceHierarchy[serviceModelId].service; |
| 18 | const serviceInstance = this._store.getState().service.serviceInstance[serviceModelId]; |
| 19 | const modelInfoItems: ModelInformationItem[] = [ |
| 20 | ModelInformationItem.createInstance("Subscriber Name",this._aaiService.extractSubscriberNameBySubscriberId(serviceInstance.globalSubscriberId)), |
| 21 | ModelInformationItem.createInstance("Service Type",serviceInstance.subscriptionServiceType), |
| 22 | ModelInformationItem.createInstance("Service Role",serviceHierarchy.serviceRole), |
| 23 | ]; |
| 24 | serviceHierarchy.type = serviceHierarchy.serviceType; |
| 25 | return this.addGeneralInfoItems(modelInfoItems, ComponentInfoType.SERVICE, serviceHierarchy, serviceInstance ); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | addGeneralInfoItems(modelInfoSpecificItems: ModelInformationItem[], type: ComponentInfoType, model, instance) { |
| 30 | let modelInfoItems: ModelInformationItem[] = [ |
| 31 | ModelInformationItem.createInstance("Type", (model && model.type) ? model.type : ((instance && instance.modelInfo) ? instance.modelInfo.modelType : null)), |
| 32 | ModelInformationItem.createInstance("Model Version", model ? model.version : null), |
| 33 | ModelInformationItem.createInstance("Model Customization ID", model ? model.customizationUuid : null), |
| 34 | ModelInformationItem.createInstance("Instance ID", instance ? instance.instanceId : null), |
| 35 | ModelInformationItem.createInstance("In Maintenance", instance? instance.inMaint : null), |
| 36 | ]; |
| 37 | modelInfoItems = modelInfoItems.concat(modelInfoSpecificItems); |
| 38 | const modelInfoItemsWithoutEmpty = _.filter(modelInfoItems, function(item){ return !item.values.every(_.isNil)}); |
| 39 | return new ComponentInfoModel(type, modelInfoItemsWithoutEmpty, []); |
| 40 | } |
| 41 | } |