Max Chu | 6a4bb65 | 2017-09-29 17:15:56 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the 'License'); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an 'AS IS' BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
| 19 | import { |
| 20 | IMicrosemiMaFormat, IMicrosemiMdFormat, IMicrosemiMepFormat, IMicrosemiStats, |
| 21 | IMicrosemiStatsData |
| 22 | } from './stats-service'; |
| 23 | import './cfmlist.component.scss'; |
| 24 | import * as _ from 'lodash'; |
| 25 | |
| 26 | class CfmlistComponent { |
| 27 | |
| 28 | static $inject = [ |
| 29 | 'MicrosemiStats', |
| 30 | '$state' |
| 31 | ]; |
| 32 | |
| 33 | public mds: IMicrosemiMdFormat[]; |
| 34 | public mas: IMicrosemiMaFormat[]; |
| 35 | public meps: IMicrosemiMepFormat[]; |
| 36 | public dms: IMicrosemiStatsData[]; |
| 37 | |
| 38 | public md: any; |
| 39 | public ma: any; |
| 40 | public mdValue: number; |
| 41 | public maValue: number; |
| 42 | public mepValue: number; |
| 43 | public dmValue: number; |
| 44 | |
| 45 | public displayButton = false; |
| 46 | public displaydms = false; |
| 47 | |
| 48 | constructor ( |
| 49 | private MicrosemiStats : IMicrosemiStats, |
| 50 | private $state: any |
| 51 | ) {} |
| 52 | |
| 53 | $onInit() { |
| 54 | this.MicrosemiStats.getMds().then((res) => { |
| 55 | this.mds = res; |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | public triggerRefresh(changed: string) { |
| 60 | switch (changed) { |
| 61 | case 'md': |
| 62 | this.meps = []; |
| 63 | this.maValue = null; |
| 64 | this.mepValue = null; |
| 65 | this.getMas(this.mdValue); |
| 66 | this.displayButton = false; |
| 67 | this.displaydms = false; |
| 68 | break; |
| 69 | case 'ma': |
| 70 | this.mepValue = null; |
| 71 | this.dmValue = null; |
| 72 | this.getMeps(this.maValue); |
| 73 | this.displayButton = false; |
| 74 | this.displaydms = false; |
| 75 | break; |
| 76 | case 'mep': |
| 77 | this.dmValue = null; |
| 78 | this.getDms(this.mepValue); |
| 79 | this.displayButton = false; |
| 80 | this.displaydms = true; |
| 81 | break; |
| 82 | case 'dm': |
| 83 | this.displayButton = true; |
| 84 | break; |
| 85 | default: |
| 86 | break; |
| 87 | } |
| 88 | |
| 89 | } |
| 90 | |
| 91 | public getMas(mdNumericId: number) { |
| 92 | this.md = _.find(this.mds, (md) => { |
| 93 | return md.mdNumericId === Number(mdNumericId); |
| 94 | }); |
| 95 | this.mas = this.md.maList; |
| 96 | } |
| 97 | |
| 98 | public getMeps(maNumericId: number) { |
| 99 | this.ma = _.find(this.mas, (ma) => { |
| 100 | return ma.maNumericId === Number(maNumericId); |
| 101 | }); |
| 102 | this.MicrosemiStats.getMeps(this.md.mdName, this.ma.maName) |
| 103 | .then((res: IMicrosemiMepFormat[]) => { |
| 104 | this.meps = res; |
| 105 | }); |
| 106 | } |
| 107 | |
| 108 | public getDms(mepNumericId: number) { |
| 109 | this.MicrosemiStats.getDms(this.md.mdName, this.ma.maName, String(mepNumericId)) |
| 110 | .then((res: IMicrosemiStatsData[]) => { |
| 111 | this.dms = res; |
| 112 | }); |
| 113 | } |
| 114 | |
| 115 | public stateChange() { |
| 116 | this.$state.go('xos.cfmstat', { |
| 117 | mdName: this.md.mdName, |
| 118 | maName: this.ma.maName, |
| 119 | mepId: this.mepValue, |
| 120 | dmId: this.dmValue |
| 121 | }); |
| 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | export const cfmlistComponent: angular.IComponentOptions = { |
| 127 | template: require('./cfmlist.component.html'), |
| 128 | controllerAs: 'vm', |
| 129 | controller: CfmlistComponent |
| 130 | }; |