782e99f4bb8e93860f2ea1ad37a1f93f99a3815b
[osm/UI.git] / skyquake / plugins / launchpad / src / launchpad_card / launchpadCardMgmtInterfaces.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
20 import React from 'react';
21 import Loader from 'widgets/loading-indicator/loadingIndicator.jsx';
22
23 export default class managementInterfaces extends React.Component {
24   constructor(props) {
25     super(props);
26   }
27   componentWillReceiveProps(nextProps) {
28
29   }
30   render() {
31     let dashboard_html;
32     let console_html;
33     let isDisplayed = this.props.display;
34     let status;
35     let applicationDashboards = this.props.interfaces.sort(function(a,b) {
36       try {
37             if ((a["short-name"] + '-' + a.id.substr(0,4)) > (b["short-name"] + '-' + b.id.substr(0,4))) {
38               return 1;
39             }
40       } catch(e) {
41         return 1;
42       }
43       return -1;
44     });
45
46     if(applicationDashboards.length > 0){
47       status = applicationDashboards.map(function(i, index) {
48         let mgmtLink = i["dashboard-url"] ? i["dashboard-url"] : 'None';
49           return (
50             <li key={index}><h3>{i["short-name"] + '-' + i.id.substr(0,4)}</h3><a href={i["dashboard-url"]} target="_blank">{mgmtLink}</a></li>
51           )
52         });
53     } else {
54       status = <li>No Application Dashboard Links have been specified.</li>
55     }
56     dashboard_html = (
57           <ul>
58             {status}
59           </ul>
60       );
61
62     let consoleLinks = this.props.consoleUrls && this.props.consoleUrls.sort(function(a,b) {
63       try {
64             if ((a["name"] + '-' + a.id.substr(0,4)) > (b["name"] + '-' + b.id.substr(0,4))) {
65               return 1;
66             }
67       } catch(e) {
68         return 1;
69       }
70       return -1;
71     });
72
73     if(consoleLinks && consoleLinks.length > 0){
74       status = consoleLinks.map(function(i, index) {
75         let consoleLink = i["console-url"] ? 'Open VM Console' : 'None';
76           return (
77             <li key={index}><h3>{i["name"] + '-' + i.id.substr(0,4)}</h3><a href={i["console-url"]} target="_blank">{consoleLink}</a></li>
78           )
79         });
80     } else {
81       status = <li>No VDU Console Links have been specified.</li>
82     }
83     console_html = (
84         <ul>
85           {status}
86         </ul>
87     );
88
89     return (
90       <div className={this.props.className + (isDisplayed ? '_open':'_close')}>
91         <h2>
92           Application Dashboard Links
93         </h2>
94         {dashboard_html}
95         <h2>
96           VM Console Links
97         </h2>
98         {console_html}
99       </div>);
100   }
101 }
102
103 managementInterfaces.defaultProps = {
104   display: false,
105   interfaces: []
106 }
107
108