4 * Copyright 2016 RIFT.IO Inc
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import React from 'react';
20 import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
21 import DashboardCard from 'widgets/dashboard_card/dashboard_card.jsx';
22 import MonitoringParamsCarousel from '../monitoring_params/monitoringParamsCarousel.jsx';
23 import VnfrCard from '../vnfr/vnfrCard.jsx';
24 import {LaunchpadCard, LpCardNfviMetrics, EpaParams, NsrPrimitiveJobList} from '../launchpad_card/launchpadCard.jsx';
25 import VnfrConfigPrimitives from '../launchpad_card/vnfrConfigPrimitives.jsx';
26 import NsrConfigPrimitives from '../launchpad_card/nsrConfigPrimitives.jsx';
27 import NsrScalingGroups from '../launchpad_card/nsrScalingGroups.jsx';
28 import LoadingIndicator from 'widgets/loading-indicator/loadingIndicator.jsx';
29 import NfviMetricBars from 'widgets/nfvi-metric-bars/nfviMetricBars.jsx';
30 import ParseMP from '../monitoring_params/monitoringParamComponents.js';
31 import PlacementGroupsInfo from './placementGroupsInfo.jsx';
32 import JobListCard from '../launchpad_card/jobListCard.jsx';
33 import NSVirtualLinks from '../virtual_links/nsVirtualLinks.jsx';
34 import LaunchpadFleetStore from '../launchpadFleetStore.js';
36 export default class RecordCard extends React.Component {
41 handleSelect = (index, last) => {
42 // console.log('Selected tab is', index, 'last index is', last);
45 openConsole = (url, event) => {
46 event.preventDefault();
47 LaunchpadFleetStore.getVDUConsoleLink(url);
57 let configPrimitivesProps = {};
58 let displayConfigPrimitives = false;
59 let configPrimitiveComponent = null;
60 let scalingGroupsProps = {};
61 let displayScalingGroups = false;
62 let scalingGroupComponent = null;
63 let consoleUrlsComponent = null;
64 let consoleUrlsList = [];
66 let displayNSVirtualLinks = false;
67 let nsVirtualLinksProps = {};
68 let nsVirtualLinksComponent = null;
75 switch(this.props.type) {
77 cardData = this.props.data[0];
78 // Disabling config primitives for VNF
79 configPrimitivesProps = [cardData];
80 displayConfigPrimitives = cardData['service-primitives-present'];
81 if (displayConfigPrimitives) {
82 configPrimitiveComponent = (
83 <div className="flex vnfrConfigPrimitiveContainer">
84 <VnfrConfigPrimitives data={configPrimitivesProps} />
85 {/* <NsrPrimitiveJobList jobs={cardData['config-agent-job']}/> */}
86 <div style={{display:'flex', flexDirection: 'column', flex: '1 1 40%'}}>
87 <div className="launchpadCard_title">
90 <div className="scrollContainer">
92 //Sort for recent on top
95 return parseInt(b['job-id']) - parseInt(a['job-id']);
98 //Return only vnfr configs
99 if(job["triggered-by"] == 'vnf-primitive') {
100 return job.vnfr.map(function(v){
101 //That match the currently selected job id
102 if(v.id == cardData.id) {
103 return v.primitive.map(function(p, i) {
104 return <JobListCard type="vnfr" job-id={job['job-id']} cardData={cardData} key={ob['job-id'] + '-' + i} {...p} />
116 if (cardData['vdur']) {
117 cardData['vdur'].map((vdur, index) => {
118 let consoleLink = vdur['console-url'] ? 'Obtain Token And Open VM Console' : 'None';
119 consoleUrlsList.push(
122 {vdur['name'] + '-' + vdur.id.substr(0,4)}
124 <span className='consoleLink' onClick={self.openConsole.bind(self, vdur["console-url"])}>
129 notice = <li className='notice'>* If a separate browser window does not open, please check if the popup was blocked and allow it.</li>
131 consoleUrlsComponent = (
132 <div className="consoleUrlsComponent">
133 <ul className="consoleUrlsList">
140 components = ParseMP.call(this, cardData["monitoring-param"], "vnfr-id");
143 cardData = this.props.data.nsrs[0];
144 configPrimitivesProps = cardData;
145 scalingGroupsProps = cardData;
146 displayConfigPrimitives = cardData['service-primitive'];
147 displayScalingGroups = cardData['scaling-group-descriptor'] ? true : false;
148 let sortedJobs = this.props.jobData.sort(function(a,b){
149 return parseInt(b['job-id']) - parseInt(a['job-id']);
151 if (displayConfigPrimitives) {
152 configPrimitiveComponent = (
153 <div className="flex nsConfigPrimitiveContainer">
154 <NsrConfigPrimitives data={configPrimitivesProps} />
155 <div style={{display:'flex', flexDirection: 'column', flex: '1 1 40%'}}>
156 <div className="launchpadCard_title">
159 <div className="scrollContainer">
160 {sortedJobs.map(function(job, i){
161 if(job["triggered-by"] == 'ns-primitive') {
162 return <JobListCard type="nsr" job-id={job['job-id']} cardData={cardData} key={job['job-id'] + '-' + 'nsr'} {...job} />
165 .concat(sortedJobs.map(function(job) {
166 if(!job.hasOwnProperty('job-name') && (job["triggered-by"] == 'ns-primitive')) {
167 return job.vnfr.map(function(v, h){
168 //That match the currently selected job id
169 if(v.id == cardData.id) {
170 return v.primitive.map(function(p, i) {
171 return <JobListCard type="vnfr" job-id={job['job-id']} cardData={cardData} key={ob['job-id'] + '-' + 'vnfr' + '-' + h} {...p} />
183 if (displayScalingGroups) {
184 scalingGroupComponent = (
185 <div className="flex nsrScalingGroupContainer">
186 <NsrScalingGroups data={scalingGroupsProps} />
191 // Virtual Links tab content
192 displayNSVirtualLinks = true;
193 nsVirtualLinksProps = cardData;
194 if (displayNSVirtualLinks) {
195 nsVirtualLinksComponent = (
196 <div className='flex nsVirtualLinksContainer'>
197 <NSVirtualLinks data={nsVirtualLinksProps} />
202 components = ParseMP.call(this, cardData["monitoring-param"], "vnfr-id");
205 let mgmt_interface = cardData["dashboard-url"];
207 let metricsAndParams = [];
210 let nfviMetrics = <LpCardNfviMetrics data={cardData["nfvi-metrics"]} />;
211 metricsAndParams.push(<div className="monitoringParams" key="mp">
212 {components.map(function(c, k) {
213 return <div key={k} className="mpSlide">{c.title}{c.component}</div>
216 metricsAndParams.push((<div key="nvfi" className="nfvi-metrics">
218 <EpaParams data={cardData["epa-params"]} />
224 mgmtHTML = <a href={mgmt_interface} target="_blank">Open Application Dashboard</a>;
226 if(this.props.isLoading) {
227 html = <DashboardCard className="loading" showHeader={true} title={cardData["short-name"]}><LoadingIndicator size={10} show={true} /></DashboardCard>
229 let glyphValue = (this.props.mmmrecordDetailsToggleValue) ? "chevron-left" : "chevron-right";
231 if (this.props.type == 'nsr') {
233 <Tab key={cardData.id}>NS Data</Tab>
235 } else if (this.props.type == 'vnfr') {
237 <Tab key={cardData.id}>VNF Data</Tab>
242 <TabPanel key={cardData.id + '-panel'}>
244 <div className="launchpadCard_title" style={{textAlign:'right'}}><span style={{float:'left'}}>MONITORING PARAMETERS</span>
248 <div className="cardSectionFooter">
254 if (this.props.type == 'nsr') {
255 if (scalingGroupComponent) {
257 <Tab key={cardData.id + '-sg'}>Scaling Groups</Tab>
261 <TabPanel key={cardData.id + '-sg-panel'}>
263 {scalingGroupComponent}
265 <div className="cardSectionFooter">
270 if(cardData.hasOwnProperty('vnfd-placement-group-maps')
271 || cardData.hasOwnProperty('nsd-placement-group-maps')) {
273 <Tab key='placement_groups'>
278 <TabPanel key='placement_groups_panel'>
280 <PlacementGroupsInfo nsr={cardData} navRef={this.props.navRef} />
287 if (configPrimitiveComponent) {
288 let primitivesTabTitle = '';
289 if (this.props.type == 'nsr') {
290 primitivesTabTitle = 'Service Primitive';
291 } else if (this.props.type == 'vnfr') {
292 primitivesTabTitle = 'Service Primitive'
296 <Tab key={cardData.id + '-cp'}>{primitivesTabTitle}</Tab>
300 <TabPanel key={cardData.id + '-cp-panel'}>
301 <div className="configPrimitives">
302 {configPrimitiveComponent}
304 <div className="cardSectionFooter">
310 if (nsVirtualLinksComponent) {
311 let nsVirtualLinksTabTitle = 'Virtual Links';
313 <Tab key={cardData.id + '-nsvl'}>{nsVirtualLinksTabTitle}</Tab>
317 <TabPanel key={cardData.id + '-nsvl-panel'}>
318 <div className='nsVirtualLinks'>
319 {nsVirtualLinksComponent}
321 <div className="cardSectionFooter">
327 if (consoleUrlsComponent) {
328 let consoleUrlsTabTitle = '';
329 consoleUrlsTabTitle = 'VDU Console Links';
332 <Tab key={cardData.id + '-cp'}>{consoleUrlsTabTitle}</Tab>
336 <TabPanel key={cardData.id + '-cp-panel'}>
337 <div className="consoleUrls">
338 {consoleUrlsComponent}
340 <div className="cardSectionFooter">
347 <DashboardCard className="recordCard" showHeader={true} title={cardData["short-name"]}>
348 <a onClick={this.props.recordDetailsToggleFn} className={"recordViewToggle " + (this.props.recordDetailsToggleValue ? "on": null)}><span className="oi" data-glyph={glyphValue} title="Toggle Details Panel" aria-hidden="true"></span></a>
349 <Tabs onSelect={this.handleSelect}>
361 RecordCard.defaultProps = {