|
51 | 51 | getInitialState:function(){
|
52 | 52 | return {
|
53 | 53 | statusOpen:true,
|
| 54 | + blinkingBell: false, |
54 | 55 | additionalContents:this.parseComponentConfigs(),
|
55 | 56 | workspaces: this.props.pydio.user.getRepositoriesList()
|
56 | 57 | };
|
|
107 | 108 | this._timer = global.setTimeout(this.closeNavigation, 300);
|
108 | 109 | },
|
109 | 110 |
|
| 111 | + onAlertPanelBadgeChange: function(paneData, newValue, oldValue, memoData){ |
| 112 | + if(paneData.id !== 'navigation_alerts'){ |
| 113 | + return; |
| 114 | + } |
| 115 | + if(newValue){ |
| 116 | + this.setState({blinkingBell: newValue, blinkingBellClass:paneData.options['titleClassName']}); |
| 117 | + }else{ |
| 118 | + this.setState({blinkingBell: false}); |
| 119 | + } |
| 120 | + |
| 121 | + if(newValue && newValue !== oldValue){ |
| 122 | + if(Object.isNumber(newValue)){ |
| 123 | + if(oldValue !== '' && newValue > oldValue){ |
| 124 | + let notifText = 'Something happened!'; |
| 125 | + if(memoData instanceof PydioDataModel){ |
| 126 | + let node = memoData.getRootNode().getFirstChildIfExists(); |
| 127 | + if(node){ |
| 128 | + if(paneData.options['tipAttribute']){ |
| 129 | + notifText = node.getMetadata().get(paneData.options['tipAttribute']); |
| 130 | + }else{ |
| 131 | + notifText = node.getLabel(); |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + AlertTask.setCloser(this.openNavigation.bind(this)); |
| 136 | + let title = global.pydio.MessageHash[paneData.options.title] || paneData.options.title; |
| 137 | + let alert = new AlertTask(title, notifText); |
| 138 | + alert.show(); |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + }, |
| 144 | + |
110 | 145 | render:function(){
|
111 | 146 | const additional = this.state.additionalContents.map(function(paneData){
|
112 | 147 | if(paneData.type == 'ListProvider'){
|
|
115 | 150 | pydio={this.props.pydio}
|
116 | 151 | paneData={paneData}
|
117 | 152 | nodeClicked={this.listNodeClicked}
|
| 153 | + onBadgeChange={this.onAlertPanelBadgeChange} |
118 | 154 | />
|
119 | 155 | );
|
120 | 156 | }else{
|
121 | 157 | return null;
|
122 | 158 | }
|
123 | 159 | }.bind(this));
|
124 | 160 |
|
| 161 | + let badge; |
| 162 | + if(this.state.blinkingBell){ |
| 163 | + badge = <span className={"badge-icon icon-bell-alt"}/>; |
| 164 | + } |
| 165 | + |
125 | 166 | return (
|
126 | 167 | <span>
|
127 | 168 | <div id="repo_chooser" onClick={this.openNavigation} onMouseOver={this.openNavigation} className={this.state.statusOpen?"open":""}>
|
128 |
| - <span className="icon-reorder"/> |
| 169 | + <span className="icon-reorder"/>{badge} |
129 | 170 | </div>
|
130 | 171 | <div className={"left-panel" + (this.state.statusOpen?'':' hidden')} onMouseOver={this.closeMouseover} onMouseOut={this.closeMouseout}>
|
131 | 172 | {additional}
|
|
139 | 180 | }
|
140 | 181 | });
|
141 | 182 |
|
| 183 | + class AlertTask extends PydioTasks.Task{ |
| 184 | + |
| 185 | + constructor(label, statusMessage){ |
| 186 | + super({ |
| 187 | + id : 'local-alert-task-' + Math.random(), |
| 188 | + userId : global.pydio.user.id, |
| 189 | + wsId : global.pydio.user.activeRepository, |
| 190 | + label : label, |
| 191 | + status : PydioTasks.Task.STATUS_PENDING, |
| 192 | + statusMessage : statusMessage, |
| 193 | + className : 'alert-task' |
| 194 | + }); |
| 195 | + } |
| 196 | + |
| 197 | + show(){ |
| 198 | + this._timer = global.setTimeout(function(){ |
| 199 | + this.updateStatus(PydioTasks.Task.STATUS_COMPLETE); |
| 200 | + }.bind(this), 7000); |
| 201 | + PydioTasks.Store.getInstance().enqueueLocalTask(this); |
| 202 | + } |
| 203 | + |
| 204 | + updateStatus(status, statusMessage = ''){ |
| 205 | + this._internal['status'] = status; |
| 206 | + this._internal['statusMessage'] = statusMessage; |
| 207 | + this.notifyMainStore(); |
| 208 | + } |
| 209 | + |
| 210 | + notifyMainStore(){ |
| 211 | + PydioTasks.Store.getInstance().notify("tasks_updated"); |
| 212 | + } |
| 213 | + |
| 214 | + hasOpenablePane(){ |
| 215 | + return true; |
| 216 | + } |
| 217 | + openDetailPane(){ |
| 218 | + AlertTask.close(); |
| 219 | + } |
| 220 | + |
| 221 | + static setCloser(click){ |
| 222 | + AlertTask.__CLOSER = click; |
| 223 | + } |
| 224 | + |
| 225 | + static close(){ |
| 226 | + AlertTask.__CLOSER(); |
| 227 | + } |
| 228 | + |
| 229 | + } |
| 230 | + |
| 231 | + |
| 232 | + |
142 | 233 | var DataModelBadge = React.createClass({
|
143 | 234 |
|
144 | 235 | propTypes:{
|
145 | 236 | dataModel:React.PropTypes.instanceOf(PydioDataModel),
|
146 |
| - options:React.PropTypes.object |
| 237 | + options:React.PropTypes.object, |
| 238 | + onBadgeIncrease: React.PropTypes.func, |
| 239 | + onBadgeChange: React.PropTypes.func |
147 | 240 | },
|
148 | 241 |
|
149 | 242 | getInitialState:function(){
|
150 | 243 | return {value:''};
|
151 | 244 | },
|
152 | 245 |
|
153 | 246 | componentDidMount:function(){
|
154 |
| - var options = this.props.options; |
155 |
| - var dm = this.props.dataModel; |
| 247 | + let options = this.props.options; |
| 248 | + let dm = this.props.dataModel; |
| 249 | + let newValue = ''; |
156 | 250 | this._observer = function(){
|
157 | 251 | switch (options.property){
|
158 | 252 | case "root_children":
|
159 | 253 | var l = dm.getRootNode().getChildren().size;
|
160 |
| - this.setState({value:l?l:''}); |
| 254 | + newValue = l ? l : 0; |
161 | 255 | break;
|
162 | 256 | case "root_label":
|
163 |
| - this.setState({value:dm.getRootNode().getLabel()}); |
| 257 | + newValue = dm.getRootNode().getLabel(); |
164 | 258 | break;
|
165 | 259 | case "root_children_empty":
|
166 | 260 | var cLength = dm.getRootNode().getChildren().size;
|
167 |
| - this.setState({value:!cLength?options['emptyMessage']:''}); |
| 261 | + newValue = !cLength?options['emptyMessage']:''; |
168 | 262 | break;
|
169 | 263 | case "metadata":
|
170 | 264 | if(options['metadata_sum']){
|
171 |
| - var sum = 0; |
| 265 | + newValue = 0; |
172 | 266 | dm.getRootNode().getChildren().forEach(function(c){
|
173 |
| - if(c.getMetadata().get(options['metadata_sum'])) sum += parseInt(c.getMetadata().get(options['metadata_sum'])); |
| 267 | + if(c.getMetadata().get(options['metadata_sum'])) newValue += parseInt(c.getMetadata().get(options['metadata_sum'])); |
174 | 268 | });
|
175 |
| - this.setState({value:sum?sum:''}); |
176 | 269 | }
|
177 | 270 | break;
|
178 | 271 | default:
|
179 | 272 | break;
|
180 | 273 | }
|
| 274 | + let prevValue = this.state.value; |
| 275 | + if(newValue && newValue !== prevValue){ |
| 276 | + if(Object.isNumber(newValue) && this.props.onBadgeIncrease){ |
| 277 | + if(prevValue !== '' && newValue > prevValue) this.props.onBadgeIncrease(newValue, prevValue ? prevValue : 0, this.props.dataModel); |
| 278 | + } |
| 279 | + } |
| 280 | + if(this.props.onBadgeChange){ |
| 281 | + this.props.onBadgeChange(newValue, prevValue, this.props.dataModel); |
| 282 | + } |
| 283 | + this.setState({value: newValue}); |
181 | 284 | }.bind(this);
|
182 | 285 | dm.getRootNode().observe("loaded", this._observer);
|
183 | 286 | },
|
|
202 | 305 | paneData:React.PropTypes.object,
|
203 | 306 | pydio:React.PropTypes.instanceOf(Pydio),
|
204 | 307 | nodeClicked:React.PropTypes.func,
|
205 |
| - startOpen:React.PropTypes.bool |
| 308 | + startOpen:React.PropTypes.bool, |
| 309 | + onBadgeIncrease: React.PropTypes.func, |
| 310 | + onBadgeChange: React.PropTypes.func |
206 | 311 | },
|
207 | 312 |
|
208 | 313 | getInitialState:function(){
|
|
225 | 330 | this.setState({open:!this.state.open, componentLaunched:true});
|
226 | 331 | },
|
227 | 332 |
|
| 333 | + onBadgeIncrease: function(newValue, prevValue, memoData){ |
| 334 | + if(this.props.onBadgeIncrease){ |
| 335 | + this.props.onBadgeIncrease(this.props.paneData, newValue, prevValue, memoData); |
| 336 | + if(!this.state.open) this.toggleOpen(); |
| 337 | + } |
| 338 | + }, |
| 339 | + |
| 340 | + onBadgeChange(newValue, prevValue, memoData){ |
| 341 | + if(this.props.onBadgeChange){ |
| 342 | + this.props.onBadgeChange(this.props.paneData, newValue, prevValue, memoData); |
| 343 | + if(!this.state.open) this.toggleOpen(); |
| 344 | + } |
| 345 | + }, |
| 346 | + |
228 | 347 | render:function(){
|
229 | 348 |
|
230 | 349 | var messages = this.props.pydio.MessageHash;
|
|
236 | 355 |
|
237 | 356 | var badge;
|
238 | 357 | if(paneData.options.dataModelBadge){
|
239 |
| - badge = <DataModelBadge dataModel={this.state.dataModel} options={paneData.options.dataModelBadge} />; |
| 358 | + badge = <DataModelBadge |
| 359 | + dataModel={this.state.dataModel} |
| 360 | + options={paneData.options.dataModelBadge} |
| 361 | + onBadgeIncrease={this.onBadgeIncrease} |
| 362 | + onBadgeChange={this.onBadgeChange} |
| 363 | + />; |
240 | 364 | }
|
241 | 365 | var emptyMessage;
|
242 | 366 | if(paneData.options.emptyChildrenMessage){
|
|
0 commit comments