35f9caa3b4ca01a635d1612acf69c46bd42bb745
[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 import LaunchpadFleetStore from '../launchpadFleetStore.js';
23
24
25 export default class managementInterfaces extends React.Component {
26   constructor(props) {
27     super(props);
28   }
29   componentWillReceiveProps(nextProps) {
30
31   }
32
33   openConsole = (url, event) => {
34     event.preventDefault();
35     LaunchpadFleetStore.getVDUConsoleLink(url);
36   }
37   render() {
38     let self = this;
39     let dashboard_html;
40     let console_html;
41     let isDisplayed = this.props.display;
42     let status;
43     let notice;
44     let applicationDashboards = this.props.interfaces.sort(function(a,b) {
45       try {
46             if ((a["short-name"] + '-' + a.id.substr(0,4)) > (b["short-name"] + '-' + b.id.substr(0,4))) {
47               return 1;
48             }
49       } catch(e) {
50         return 1;
51       }
52       return -1;
53     });
54
55     if(applicationDashboards.length > 0){
56       status = applicationDashboards.map(function(i, index) {
57         let mgmtLink = i["dashboard-url"] ? i["dashboard-url"] : 'None';
58           return (
59             <li key={index}><h3>{i["short-name"] + '-' + i.id.substr(0,4)}</h3><a href={i["dashboard-url"]} target="_blank">{mgmtLink}</a></li>
60           )
61         });
62     } else {
63       status = <li>No Application Dashboard Links have been specified.</li>
64     }
65     dashboard_html = (
66           <ul>
67             {status}
68           </ul>
69       );
70
71     let consoleLinks = this.props.consoleUrls && this.props.consoleUrls.sort(function(a,b) {
72       try {
73             if ((a["name"] + '-' + a.id.substr(0,4)) > (b["name"] + '-' + b.id.substr(0,4))) {
74               return 1;
75             }
76       } catch(e) {
77         return 1;
78       }
79       return -1;
80     });
81
82     if(consoleLinks && consoleLinks.length > 0){
83       status = consoleLinks.map(function(i, index) {
84         let consoleLink = i["console-url"] ? 'Obtain Token And Open VM Console' : 'None';
85           return (
86             <li key={index}><h3>{i["name"] + '-' + i.id.substr(0,4)}</h3><span className='consoleLink' onClick={self.openConsole.bind(self, i["console-url"])}>{consoleLink} *</span></li>
87           )
88         });
89       notice = <li className='notice'>* If a separate browser window does not open, please check if the popup was blocked and allow it.</li>
90     } else {
91       status = <li>No VDU Console Links have been specified.</li>
92     }
93     console_html = (
94         <ul>
95           {status}
96           {notice}
97         </ul>
98     );
99
100     return (
101       <div className={this.props.className + (isDisplayed ? '_open':'_close')}>
102         <h2>
103           Application Dashboard Links
104         </h2>
105         {dashboard_html}
106         <h2>
107           VM Console Links
108         </h2>
109         {console_html}
110       </div>);
111   }
112 }
113
114 managementInterfaces.defaultProps = {
115   display: false,
116   interfaces: []
117 }
118
119