RIFT-15032: launchpad UI - Viewport - icons for nsr
[osm/UI.git] / skyquake / plugins / launchpad / src / recordViewer / recordNavigator.jsx
1
2 /*
3  * 
4  *   Copyright 2016 RIFT.IO Inc
5  *
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
9  *
10  *       http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19 import React from 'react';
20 import RecordViewActions from './recordViewActions.js';
21 import LoadingIndicator from 'widgets/loading-indicator/loadingIndicator.jsx';
22 import DashboardCard from 'widgets/dashboard_card/dashboard_card.jsx';
23 import Utils from 'utils/utils.js';
24
25 import './recordNavigator.scss';
26
27 export default class RecordNavigator extends React.Component{
28   constructor(props) {
29     super(props)
30   }
31   handleImageError = (e) => {
32       console.log('Bad logo path, using default');
33       e.target.src = require('style/img/catalog-default.svg');
34   }
35   render(){
36     let navClass = 'catalogItems';
37
38     let self = this;
39     let html;
40     let className = this.props.isLoading ? 'loading' : '';
41     let nav = [];
42
43     this.props.nav.map(function(n, k) {
44       let itemClassName = navClass + '_item';
45       let catalog_name = (n.type == 'nsr' ? <span>({n.nsd_name})</span> : '');
46       let scalingGroupClass = '';
47       let scalingGroupTitleClass = '';
48       let scalingGroupTitle = '';
49       let navObj = [];
50       if (n.scalingGroupName) {
51         scalingGroupClass = navClass + ' -is-scaled';
52         scalingGroupTitleClass = scalingGroupClass + '_title';
53         scalingGroupTitle = n.scalingGroupName + '_' + n.scalingGroupInstanceId;
54         n.vnfr && n.vnfr.map((vnfr, vnfrIndex) => {
55           let iClassName = itemClassName;
56           if(vnfr.id == self.props.activeNavID) {
57             iClassName += ' -is-selected';
58           }
59           navObj.push(
60             <div key={'id' + k + '-' + vnfr.id}  onClick={self.props.loadRecord.bind(self,vnfr)} className={iClassName}>
61               <img
62                   onError={self.handleImageError}
63                   src={Utils.cleanImageDataURI(vnfr.logo, vnfr.type, vnfr.id)}
64               />
65               <section id={vnfr.id}>
66               <h1 title={vnfr.name}>{vnfr.name}</h1>
67                 <h2>{vnfr.type}</h2>
68               </section>
69             </div>
70           )
71         });
72       } else {
73         if(n.id == self.props.activeNavID) {
74           itemClassName += ' -is-selected';
75         }
76         navObj.push(
77           <div key={'id' + k + '-' + n.id}  onClick={self.props.loadRecord.bind(self,n)} className={itemClassName}>
78             <img
79                 onError={self.handleImageError}
80                 src={Utils.cleanImageDataURI(n.logo, n.type, n.id)}
81             />
82             <section id={n.id}>
83             <h1 title={n.name}>{n.name}</h1>
84               <h2>{n.type}</h2>
85             </section>
86           </div>
87         );
88       }
89       nav.push(
90         <li className={scalingGroupClass} key={"scalingGroupTile-" + k}>
91           <div className={scalingGroupTitleClass}>
92             {scalingGroupTitle}
93           </div>
94           {navObj}
95         </li>
96       )
97     })
98     if(this.props.isLoading) {
99         html = <DashboardCard className="loading" showHeader={true} title="Loading..."><LoadingIndicator size={10} show={true} /></DashboardCard>
100     } else {
101         html = (
102           <DashboardCard showHeader={true} title="Select Record" className={"recordNavigator" + className}>
103             <ul className="catalogItems">
104               {
105                 nav
106               }
107             </ul>
108           </DashboardCard>
109         );
110     }
111     return html;
112   }
113 }
114 RecordNavigator.defaultProps = {
115   nav: []
116 }
117
118