Skip to content

Commit 7d04d35

Browse files
authored
Merge pull request #2662 from Vizzuality/disposable/disable-subnational-analysis
Release: Disable subnational analysis
2 parents 989e02a + 4a3c703 commit 7d04d35

File tree

5 files changed

+75
-9
lines changed

5 files changed

+75
-9
lines changed

app/assets/javascripts/map/presenters/analysis/AnalysisCountryPresenter.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ define([
3636
country: null,
3737
regions: null,
3838
region: null,
39+
layers: [],
3940

4041
overlay_stroke_weight: 2
4142
}
@@ -53,6 +54,8 @@ define([
5354

5455
this.status.on('change:regions', this.changeRegions.bind(this));
5556

57+
this.status.on('change:layers', this.changeLayers.bind(this));
58+
5659
this.status.on('change:enabled', this.changeEnabled.bind(this));
5760
this.status.on('change:enabledSubscription', this.changeEnabledSubscription.bind(this));
5861
},
@@ -74,8 +77,18 @@ define([
7477
region: params.iso.region
7578
},
7679
isoDisabled: (!!params.dont_analyze) || !(!!params.iso.country && params.iso.country != 'ALL'),
80+
fit_to_geom: !!params.fit_to_geom,
81+
layers: params.baselayers
7782

78-
fit_to_geom: !!params.fit_to_geom
83+
});
84+
}
85+
},
86+
// Temp: to disable the regions selector
87+
// for GLAD and terra-i
88+
{
89+
'LayerNav/change': function(layerSpec) {
90+
this.status.set({
91+
layers: _.clone(layerSpec.attributes)
7992
});
8093
}
8194
},
@@ -158,6 +171,10 @@ define([
158171
this.view.setSelects();
159172
},
160173

174+
changeLayers: function() {
175+
this.view.render();
176+
},
177+
161178

162179
/**
163180
* ACTIONS

app/assets/javascripts/map/templates/analysis/analysis-country.handlebars

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
<option value="{{this.iso}}">{{this.name}}</option>
66
{{/each}}
77
</select>
8-
<select data-placeholder="Select jurisdiction (optional)" disabled="true" class="chosen-select default notranslate" id="analysis-region-select">
9-
<option></option>
10-
</select>
8+
{{#if showRegions}}
9+
<select data-placeholder="Select jurisdiction (optional)" disabled="true" class="chosen-select default notranslate" id="analysis-region-select">
10+
<option></option>
11+
</select>
12+
{{/if}}
1113
</div>
1214
<ul id="country-button-container" class="button-container one">
1315
<li><button id="analysis-country-button" class="btn green uppercase disabled">Analyze</button></li>

app/assets/javascripts/map/templates/analysis/analysis-results.handlebars

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
<option value="{{iso}}">{{name}}</option>
77
{{/each}}
88
</select>
9-
<select data-placeholder="Select jurisdiction (optional)" disabled="true" class="chosen-select default notranslate" id="analysis-region-select">
10-
<option></option>
11-
</select>
9+
{{#if showRegions}}
10+
<select data-placeholder="Select jurisdiction (optional)" disabled="true" class="chosen-select default notranslate" id="analysis-region-select">
11+
<option></option>
12+
</select>
13+
{{/if}}
1214
</div>
1315
{{/if}}
1416

app/assets/javascripts/map/views/analysis/AnalysisCountryView.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ define([
4242

4343
render: function(){
4444
this.$el.removeClass('-results').html(this.template({
45-
countries: this.countries
45+
countries: this.countries,
46+
showRegions: this._showRegions()
4647
}));
4748

4849
this.cache();
@@ -72,7 +73,33 @@ define([
7273
});
7374
},
7475

76+
// TEMP: To disable regions for GLAD & Terra-i
77+
_showRegions: function() {
78+
var layers = this.presenter.status.attributes.layers;
79+
var layersSlugs = [];
80+
var showRegions = true;
81+
82+
_.each(layers, function(layer) {
83+
if (layer.slug) {
84+
layersSlugs.push(layer.slug);
85+
} else {
86+
_.each(layer, function(sublayer) {
87+
layersSlugs.push(sublayer.slug);
88+
});
89+
}
90+
});
7591

92+
if (layersSlugs.indexOf('umd_as_it_happens') !== -1 ||
93+
layersSlugs.indexOf('terrailoss') !== -1) {
94+
showRegions = false;
95+
this.presenter.status.set({
96+
iso: _.extend({}, this.presenter.status.attributes.iso, {
97+
region: null
98+
})
99+
});
100+
}
101+
return showRegions;
102+
},
76103

77104

78105

app/assets/javascripts/map/views/analysis/AnalysisResultsNewView.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ define([
7171

7272
this.$el.addClass('-results').html(this.templates.success({
7373
resource: this.presenter.status.get('resource'),
74-
countries: (!!country && country != 'ALL') ? this.countries : null
74+
countries: (!!country && country != 'ALL') ? this.countries : null,
75+
showRegions: this._showRegions()
7576
}));
7677

7778
this.cache();
@@ -149,6 +150,23 @@ define([
149150
});
150151
},
151152

153+
// Temp to disable GLAD and terra-i
154+
_showRegions: function() {
155+
var layers = this.presenter.status.attributes.baselayers_full;
156+
var layersSlugs = [];
157+
var showRegions = true;
158+
159+
_.each(layers, function(val, key) {
160+
layersSlugs.push(key);
161+
});
162+
163+
if (layersSlugs.indexOf('umd_as_it_happens') !== -1 ||
164+
layersSlugs.indexOf('terrailoss') !== -1) {
165+
showRegions = false;
166+
}
167+
return showRegions;
168+
}
169+
152170

153171
});
154172

0 commit comments

Comments
 (0)