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 Loader from 'widgets/loading-indicator/loadingIndicator.jsx';
22 //Currently displays all buffer state messages. Should consider showing only the n most recent.
23 //TODO remove loader when current state is running
24 //TODO need to look at refactoring this
25 class ThrottledMessage extends React.Component {
30 this.displayBuffer = [];
34 this.state.loading = props.loading;
35 this.state.buffer = {};
36 this.state.displayMessage = 'Loading...'
39 componentWillReceiveProps(nextProps) {
40 let buffer = nextProps.buffer;
42 this.buildBufferObject(nextProps);
43 this.bufferIt(this.props);
48 if(this.props.buffer.length) {
49 let buffer = this.props.buffer;
50 this.buildBufferObject(this.props);
51 this.bufferIt(this.props);
54 componentWillUnmount() {
55 clearInterval(this.bufferInterval);
57 buildBufferObject(props) {
59 let buffer = self.state.buffer;
60 this.last_id = props.buffer[props.buffer.length -1].id;
61 props.buffer.map(function(item) {
62 if(!buffer[item.id]) {
67 self.displayBuffer.push(buffer[item.id]);
74 clearInterval(self.bufferInterval);
75 self.bufferInterval = setInterval(function() {
76 let currentStatus = self.props.currentStatus;
77 let failed = currentStatus == 'failed';
78 for (let i = 0; i < self.displayBuffer.length; i++) {
79 if(!self.displayBuffer[i].displayed) {
80 self.displayBuffer[i].displayed = true;
83 displaymsg = self.displayBuffer[self.displayBuffer.length-1].data.description;
84 clearInterval(self.bufferInterval);
85 self.props.onEnd(failed);
87 displaymsg = self.displayBuffer[i].data.description;
90 displayMessage: displaymsg
96 if((currentStatus == 'running' || currentStatus == 'started' || currentStatus == 'stopped' || failed) && self.displayBuffer[self.displayBuffer.length - 1].displayed ) {
97 clearInterval(self.bufferInterval);
98 self.props.onEnd(failed);
103 if(!this.props.hasFailed) {
104 return (<span className='throttledMessageText'>{this.state.displayMessage}</span>)
106 return (<span> </span>)
111 ThrottledMessage.defaultProps = {
115 export default class operationalStatus extends React.Component {
119 this.state.message = 'Loading...';
120 this.state.messageHistory = {};
122 componentWillReceiveProps(nextProps) {
130 statusMessage(currentStatus, currentStatusDetails) {
131 var message = currentStatus;
132 if (currentStatusDetails) {
133 message += ' - ' + currentStatusDetails;
139 let isDisplayed = this.props.display;
140 let isFailed = (this.props.currentStatus == 'failed') || false;
141 let title = (!this.props.loading || isFailed) ? <h2>History</h2> : '';
142 let status = this.props.status.map(function(status, index) {
154 if(this.props.loading) {
157 //If there is no collection of status event message, just display currentStatus
160 <div className={this.props.className + '_loading'}>
161 <Loader show={!isFailed}/>
162 <ThrottledMessage currentStatus={this.props.currentStatus} buffer={this.props.status} onEnd={this.props.doneLoading}/>
167 <div className={this.props.className + '_loading'}>
168 <Loader show={!isFailed}/>
169 {this.statusMessage(this.props.currentStatus,this.props.currentStatusDetails)}
178 <ThrottledMessage currentStatus={this.props.currentStatus} buffer={this.props.status} onEnd={this.props.doneLoading} hasFailed={isFailed}/>
190 return (<div className={this.props.className + (isDisplayed ? '_open':'_close')}>{title} {html}</div>);
194 operationalStatus.defaultProps = {