-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from nmco/globalspinner
Full Screen Map Loading Spinner #108.
- Loading branch information
Showing
13 changed files
with
389 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* Copyright 2015, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
var React = require('react'); | ||
|
||
var GlobalSpinner = React.createClass({ | ||
propTypes: { | ||
id: React.PropTypes.string, | ||
loadingLayers: React.PropTypes.object, | ||
showSpinner: React.PropTypes.func, | ||
hideSpinner: React.PropTypes.func, | ||
spinnersInfo: React.PropTypes.object, | ||
delayMs: React.PropTypes.number | ||
}, | ||
getDefaultProps() { | ||
return { | ||
id: "mapstore-globalspinner", | ||
loadingLayers: {}, | ||
showSpinner() {}, | ||
hideSpinner() {}, | ||
delayMs: 500 | ||
}; | ||
}, | ||
componentWillReceiveProps(newProps) { | ||
var id = newProps.id; | ||
var delayMs = newProps.delayMs; | ||
var func = this.isSomeLayerLoading(newProps.loadingLayers) ? newProps.showSpinner : newProps.hideSpinner; | ||
setTimeout(() => func(id), delayMs); | ||
}, | ||
render() { | ||
if (this.isSomeLayerLoading(this.props.loadingLayers) && this.show()) { | ||
return ( | ||
<div id={this.props.id}></div> | ||
); | ||
} | ||
return null; | ||
}, | ||
isSomeLayerLoading(loadingLayers) { | ||
return Object.keys(loadingLayers).map( | ||
(key) => { return loadingLayers[key]; }).some(element => element === true); | ||
}, | ||
show() { | ||
return (this.props.spinnersInfo || {})[this.props.id] || false; | ||
} | ||
}); | ||
|
||
module.exports = GlobalSpinner; |
48 changes: 48 additions & 0 deletions
48
web/client/components/globalspinner/__tests__/GlobalSpinner-test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright 2015, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
var React = require('react/addons'); | ||
var GlobalSpinner = require('../GlobalSpinner'); | ||
var expect = require('expect'); | ||
|
||
describe('test the globalspinner component', () => { | ||
afterEach((done) => { | ||
React.unmountComponentAtNode(document.body); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
|
||
it('creates the component with defaults', () => { | ||
const globalspinner = React.render(<GlobalSpinner/>, document.body); | ||
expect(globalspinner).toExist(); | ||
const globalspinnerDiv = React.findDOMNode(globalspinner); | ||
expect(globalspinnerDiv).toNotExist(); | ||
}); | ||
|
||
it('creates the component with layers loading and spinner to show', () => { | ||
const globalspinner = React.render(<GlobalSpinner id="globalspinner" loadingLayers={{layer1: true}} | ||
spinnersInfo={{globalspinner: true}}/>, document.body); | ||
expect(globalspinner).toExist(); | ||
const globalspinnerDiv = React.findDOMNode(globalspinner); | ||
expect(globalspinnerDiv).toExist(); | ||
}); | ||
|
||
it('creates the component with layers loading but no spinner to show', () => { | ||
const globalspinner = React.render(<GlobalSpinner id="globalspinner" loadingLayers={{layer1: true}} | ||
spinnersInfo={{globalspinner: false}}/>, document.body); | ||
expect(globalspinner).toExist(); | ||
const globalspinnerDiv = React.findDOMNode(globalspinner); | ||
expect(globalspinnerDiv).toNotExist(); | ||
}); | ||
|
||
it('creates the component with layers load', () => { | ||
const globalspinner = React.render(<GlobalSpinner loadingLayers={{layer1: false}}/>, document.body); | ||
expect(globalspinner).toExist(); | ||
const globalspinnerDiv = React.findDOMNode(globalspinner); | ||
expect(globalspinnerDiv).toNotExist(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.