50ef061eef7e9d8ddabcc735b0cca4b693ff97ca
[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
36   getDescriptorTypeFromRecordType = (recordType) => {
37       if (recordType == 'nsr') {
38         return 'nsd';
39       } else if (recordType == 'vnfr') {
40         return 'vnfd';
41       }
42       return null;
43   }
44
45   render(){
46     let navClass = 'catalogItems';
47
48     let self = this;
49     let html;
50     let className = this.props.isLoading ? 'loading' : '';
51     let nav = [];
52
53     this.props.nav.map(function(n, k) {
54       let itemClassName = navClass + '_item';
55       let catalog_name = (n.type == 'nsr' ? <span>({n.nsd_name})</span> : '');
56       let scalingGroupClass = '';
57       let scalingGroupTitleClass = '';
58       let scalingGroupTitle = '';
59       let navObj = [];
60       if (n.scalingGroupName) {
61         scalingGroupClass = navClass + ' -is-scaled';
62         scalingGroupTitleClass = scalingGroupClass + '_title';
63         scalingGroupTitle = n.scalingGroupName + '_' + n.scalingGroupInstanceId;
64         n.vnfr && n.vnfr.map((vnfr, vnfrIndex) => {
65           let iClassName = itemClassName;
66           if(vnfr.id == self.props.activeNavID) {
67             iClassName += ' -is-selected';
68           }
69           navObj.push(
70             <div key={'id' + k + '-' + vnfr.id}  onClick={self.props.loadRecord.bind(self,vnfr)} className={iClassName}>
71               <img
72                   onError={self.handleImageError}
73                   src={Utils.cleanImageDataURI(vnfr.logo, self.getDescriptorTypeFromRecordType(vnfr.type), vnfr.id)}
74               />
75               <section id={vnfr.id}>
76               <h1 title={vnfr.name}>{vnfr.name}</h1>
77                 <h2>{vnfr.type}</h2>
78               </section>
79             </div>
80           )
81         });
82       } else {
83         if(n.id == self.props.activeNavID) {
84           itemClassName += ' -is-selected';
85         }
86         navObj.push(
87           <div key={'id' + k + '-' + n.id}  onClick={self.props.loadRecord.bind(self,n)} className={itemClassName}>
88             <img
89                 onError={self.handleImageError}
90                 src={Utils.cleanImageDataURI(n.logo, self.getDescriptorTypeFromRecordType(n.type), n.id)}
91             />
92             <section id={n.id}>
93             <h1 title={n.name}>{n.name}</h1>
94               <h2>{n.type}</h2>
95             </section>
96           </div>
97         );
98       }
99       nav.push(
100         <li className={scalingGroupClass} key={"scalingGroupTile-" + k}>
101           <div className={scalingGroupTitleClass}>
102             {scalingGroupTitle}
103           </div>
104           {navObj}
105         </li>
106       )
107     })
108     if(this.props.isLoading) {
109         html = <DashboardCard className="loading" showHeader={true} title="Loading..."><LoadingIndicator size={10} show={true} /></DashboardCard>
110     } else {
111         html = (
112           <DashboardCard showHeader={true} title="Select Record" className={"recordNavigator" + className}>
113             <ul className="catalogItems">
114               {
115                 nav
116               }
117             </ul>
118           </DashboardCard>
119         );
120     }
121     return html;
122   }
123 }
124 RecordNavigator.defaultProps = {
125   nav: []
126 }
127
128