Skip to content

Commit

Permalink
Merge pull request #2226 from WikiWatershed/tt/compare-view-revamp-lo…
Browse files Browse the repository at this point in the history
…ading-states

Compare View Revamp: Loading States

Connects #2134
  • Loading branch information
rajadain committed Sep 13, 2017
2 parents 9054f47 + d1fc31f commit a4de7a3
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/mmw/js/src/compare/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,25 @@ var WindowModel = Backbone.Model.extend({
scenarios: null, // ScenariosCollection
tabs: null, // TabsCollection
visibleScenarioIndex: 0, // Index of the first visible scenario
polling: false, // If any results are polling
},

initialize: function() {
var setPolling = _.bind(this.setPolling, this);

this.get('scenarios').forEach(function(scenario) {
scenario.get('results').on('change', setPolling);
});
},

setPolling: function() {
var getPolling = function(scenario) {
return scenario.get('results').pluck('polling');
},
scenarios = this.get('scenarios'),
polling = _(scenarios.map(getPolling)).flatten().some();

this.set({ polling: polling });
},

addOrReplaceInput: function(input) {
Expand Down
3 changes: 2 additions & 1 deletion src/mmw/js/src/compare/templates/compareWindow2.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<div class="compare-title">
<h1>Compare</h1>
</div>
<div class="spinner hidden"></div>
<div class="compare-close">
<button>
<i class="fa fa-times"></i>
Expand Down Expand Up @@ -30,5 +31,5 @@ <h2>Scenarios</h2>
</button>
</div>
</div>
<div class="compare-sections">
<div class="compare-sections polling">
</div>
14 changes: 13 additions & 1 deletion src/mmw/js/src/compare/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var CompareWindow2 = modalViews.ModalBaseView.extend({
closeButton: '.compare-close > button',
nextButton: '.compare-scenario-buttons > .btn-next-scenario',
prevButton: '.compare-scenario-buttons > .btn-prev-scenario',
spinner: '.spinner',
},

events: _.defaults({
Expand All @@ -48,6 +49,7 @@ var CompareWindow2 = modalViews.ModalBaseView.extend({
modelEvents: {
'change:mode': 'showSectionsView',
'change:visibleScenarioIndex': 'highlightButtons',
'change:polling': 'setPolling',
},

regions: {
Expand Down Expand Up @@ -137,6 +139,16 @@ var CompareWindow2 = modalViews.ModalBaseView.extend({
visibleScenarioIndex: Math.max(--visibleScenarioIndex, 0)
});
},

setPolling: function() {
if (this.model.get('polling')) {
this.ui.spinner.removeClass('hidden');
this.sectionsRegion.$el.addClass('polling');
} else {
this.ui.spinner.addClass('hidden');
this.sectionsRegion.$el.removeClass('polling');
}
},
});

var TabPanelView = Marionette.ItemView.extend({
Expand Down Expand Up @@ -406,7 +418,7 @@ var ChartView = Marionette.CollectionView.extend({

// Show charts from visibleScenarioIndex
this.$('.nv-group > rect:nth-child(n + ' + (i+1) + ')').css({
'opacity': 1,
'opacity': '',
});

// Hide charts up to visibleScenarioIndex
Expand Down
21 changes: 21 additions & 0 deletions src/mmw/sass/components/_spinner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.spinner:after {
content: '';
box-sizing: border-box;
position: absolute;
top: 22px;
right: 14px;
width: 20px;
height: 20px;
margin-top: -10px;
margin-left: -10px;
border-radius: 50%;
border: 2px solid #ccc;
border-top-color: #333;
animation: spinner-animation 0.6s linear infinite;
}

@keyframes spinner-animation {
to {
transform: rotate(360deg);
}
}
1 change: 1 addition & 0 deletions src/mmw/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"components/sidebar",
"components/global-navigation",
"components/layerpicker",
"components/spinner",
"components/slider";

/**
Expand Down
13 changes: 13 additions & 0 deletions src/mmw/sass/pages/_compare.scss
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ $compare-chart-table-height: calc(100vh - #{$height-lg} - #{$compare-footer-heig
.compare-sections {
flex: 0 1 auto;
overflow: auto;

&.polling {
.compare-column, rect {
opacity: 0.25;
}
}
}

.spinner {
position: absolute;
top: 53px;
right: 50%;
}

.compare-close {
Expand Down Expand Up @@ -514,6 +526,7 @@ $compare-chart-table-height: calc(100vh - #{$height-lg} - #{$compare-footer-heig
.compare-column {
min-width: 120px;
width: 120px;
transition: opacity 0.3s ease-in-out;

.compare-scenario-title {
font-size: $font-size-h5;
Expand Down

0 comments on commit a4de7a3

Please sign in to comment.