1 declare var angular: angular.IAngularStatic;
3 import { InventoryService } from "./mwtnInventory.service";
4 import "./mwtnInventory.service";
5 import "./components/equipment";
6 import "./components/equipmentGroup";
8 const mwtnInventory = angular.module('app.mwtnInventory');
10 interface IMwtnInventoryScope extends ng.IScope {
14 activeMountPoints: string[];
15 selectedMountPoint: string;
18 class MwtnInventoryCtrl {
19 constructor(private $rootScope, private $scope: IMwtnInventoryScope, private $state, private $timeout, private mwtnInventoryService: InventoryService) {
21 $rootScope.section_logo = 'src/app/mwtnInventory/images/mwtnInventory.png';
23 $scope.loading = false;
24 $scope.message = "Empty";
25 $scope.equipments = [];
26 $scope.selectedMountPoint = null;
28 $scope.activeMountPoints = [];
30 const getAllChildEquipments = async (equipmentsRootId: string, equimentIds: string[]) => {
31 if (!equimentIds || !equimentIds.length) {
34 const equipmentObjects = (await Promise.all(equimentIds.map(id => {
35 return mwtnInventoryService.getEquipmentDetails(equipmentsRootId, id);
36 }))).map(eq => (eq["equipment"][0]));
38 const equipmentConditionals = (await Promise.all(equimentIds.map(id => {
39 return mwtnInventoryService.getEquipmentConditionals(equipmentsRootId, id);
40 }))).map(eq => (eq["equipment-pac"][0]));
42 let results = await Promise.all(equipmentObjects.map(eq => {
43 let fruNames: string[] = (eq["contained-holder"] || []).map(ch => ch["occupying-fru"]).filter(fru => !!fru);
44 return getAllChildEquipments(equipmentsRootId, fruNames);
47 return equipmentObjects.reduce((acc, cur, ind, arr) => {
48 let conditional = equipmentConditionals[ind] || null;
49 // ensure ENVERY property can be null or undefined
50 let manufacturedThing = cur['manufactured-thing'];
51 let equipmentType = manufacturedThing && manufacturedThing['equipment-type'];
52 let manufacturerProperties = manufacturedThing && manufacturedThing['manufacturer-properties'];
53 let equipmentInstance = manufacturedThing && manufacturedThing['equipment-instance'];
60 version: equipmentType && equipmentType["version"],
61 description: equipmentType && equipmentType["description"],
62 partTypeIdentifier: equipmentType && equipmentType["part-type-identifier"],
63 modelIdentifier: equipmentType && equipmentType["model-identifier"],
64 partTypeIdetypeNamentifier: equipmentType && equipmentType["type-name"],
65 id: manufacturerProperties && manufacturerProperties['manufacturer-identifier'],
66 date: equipmentInstance && equipmentInstance['manufacture-date'] && Date.parse(equipmentInstance && equipmentInstance['manufacture-date']),
67 serial: equipmentInstance && equipmentInstance['serial-number']
69 conditional: conditional
71 (results[ind].length ? card['children'] = results[ind] : null);
77 const pleaseSelect = "Please select a mount point";
79 const refresh = async (equipmentsRootId: string) => {
80 let rootIdentifiers = await mwtnInventoryService.getRootIdentifiers(equipmentsRootId);
81 let equipments = rootIdentifiers && await getAllChildEquipments(equipmentsRootId, rootIdentifiers);
83 $scope.equipments = equipments;
87 mwtnInventoryService.getConnectedMountpoints().then(res => {
88 $scope.activeMountPoints = [pleaseSelect, ...res] ;
89 $scope.selectedMountPoint = $scope.selectedMountPoint || pleaseSelect;
92 $scope.$watch(() => ($state.params.nodeId), (newVal: string, oldVal: string) => {
93 $scope.selectedMountPoint = newVal;
96 $scope.$watch("selectedMountPoint", async (newVal: string, oldVal: string) => {
97 if (!newVal || newVal === pleaseSelect) {
98 $scope.equipments = [];
101 if ($scope.activeMountPoints[0] === pleaseSelect) {
102 [, ...$scope.activeMountPoints] = $scope.activeMountPoints;
104 $scope.loading = true;
105 if ($state.params.nodeId !== newVal) {
106 $state.go('main.mwtnInventory', { nodeId: newVal }, { notify: false });
108 await refresh(newVal).catch(err => {
109 $timeout(() => { $scope.equipments = null; });
111 $timeout(() => { $scope.loading = false; });
116 mwtnInventory.controller('mwtnInventoryCtrl', ['$rootScope', '$scope', '$state', '$timeout', 'mwtnInventoryService', MwtnInventoryCtrl]);