2016-12-13 11:08:13 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import FontAwesome from 'react-fontawesome'
|
|
|
|
|
|
2017-04-03 20:58:47 +12:00
|
|
|
export default class Notifications extends React.Component{
|
2016-12-13 11:08:13 +13:00
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props)
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 20:58:47 +12:00
|
|
|
renderNotifications(){
|
|
|
|
|
if (!this.props.notifications || this.props.notifications.length <= 0) return null
|
2016-12-13 11:08:13 +13:00
|
|
|
|
2017-04-05 09:01:20 +12:00
|
|
|
return (
|
|
|
|
|
<span>
|
|
|
|
|
{
|
|
|
|
|
this.props.notifications.map(notification => {
|
|
|
|
|
switch (notification.type){
|
|
|
|
|
case 'shortcut':
|
|
|
|
|
return (
|
2017-04-05 20:28:41 +12:00
|
|
|
<div className="shortcut-notification" key={notification.key}>
|
2017-04-05 09:01:20 +12:00
|
|
|
<FontAwesome name={notification.content} />
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return (
|
2017-05-30 09:06:59 +12:00
|
|
|
<div className={notification.type+" notification"} key={notification.key} data-key={notification.key}>
|
2017-04-05 20:28:41 +12:00
|
|
|
<FontAwesome name="close" className="close-button" onClick={ e => this.props.uiActions.removeNotification(notification.key) } />
|
2017-05-29 16:29:49 +12:00
|
|
|
{notification.title ? <h4>{notification.title}</h4> : null}
|
|
|
|
|
<p dangerouslySetInnerHTML={{__html: notification.content}}></p>
|
2017-04-05 09:01:20 +12:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</span>
|
|
|
|
|
)
|
2016-12-13 11:08:13 +13:00
|
|
|
}
|
|
|
|
|
|
2017-04-06 09:01:53 +12:00
|
|
|
renderProcesses(){
|
|
|
|
|
if (!this.props.processes || this.props.processes.length <= 0) return null
|
|
|
|
|
var processes = this.props.processes
|
|
|
|
|
var items = []
|
|
|
|
|
|
|
|
|
|
for (var key in processes){
|
|
|
|
|
if (processes.hasOwnProperty(key)){
|
|
|
|
|
if (processes[key].cancelling){
|
|
|
|
|
items.push(
|
|
|
|
|
<div className="process notification cancelling" key={key}>
|
|
|
|
|
Cancelling
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
items.push(
|
|
|
|
|
<div className="process notification" key={key}>
|
|
|
|
|
<FontAwesome name="close" className="close-button" onClick={ e => this.props.uiActions.cancelProcess(key) } />
|
|
|
|
|
{ processes[key].content }
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<span>
|
|
|
|
|
{items}
|
|
|
|
|
</span>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 09:01:20 +12:00
|
|
|
// do we want the loading of everything to be displayed?
|
|
|
|
|
// not likely...
|
2017-04-03 20:58:47 +12:00
|
|
|
renderLoader(){
|
|
|
|
|
if (!this.props.load_queue){
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var load_queue = this.props.load_queue
|
2017-04-10 08:09:38 +12:00
|
|
|
var load_count = 0
|
2017-04-03 20:58:47 +12:00
|
|
|
for (var key in load_queue){
|
|
|
|
|
if (load_queue.hasOwnProperty(key)){
|
2017-04-10 08:09:38 +12:00
|
|
|
load_count++
|
2017-04-03 20:58:47 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-10 08:09:38 +12:00
|
|
|
if (load_count > 0){
|
|
|
|
|
var className = "loading "
|
|
|
|
|
if (load_count > 20){
|
|
|
|
|
className += 'high'
|
|
|
|
|
} else if (load_count > 5){
|
|
|
|
|
className += 'medium'
|
|
|
|
|
} else {
|
|
|
|
|
className += 'low'
|
|
|
|
|
}
|
2017-04-03 20:58:47 +12:00
|
|
|
return (
|
2017-04-10 08:09:38 +12:00
|
|
|
<div className={className}></div>
|
2017-04-03 20:58:47 +12:00
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2016-12-13 11:08:13 +13:00
|
|
|
}
|
|
|
|
|
|
2017-04-03 20:58:47 +12:00
|
|
|
render(){
|
|
|
|
|
return (
|
|
|
|
|
<div className="notifications">
|
2017-04-10 08:09:38 +12:00
|
|
|
{this.renderLoader()}
|
2017-04-03 20:58:47 +12:00
|
|
|
{this.renderNotifications()}
|
2017-04-06 09:01:53 +12:00
|
|
|
{this.renderProcesses()}
|
2017-04-03 20:58:47 +12:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|