Skip to content

Commit

Permalink
Merge pull request #181 from hvarg/dev
Browse files Browse the repository at this point in the history
Added custom regions
  • Loading branch information
hvarg committed Dec 9, 2019
2 parents b56cae8 + a2f7f9f commit f769bc3
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 59 deletions.
16 changes: 13 additions & 3 deletions src/screens/datasets/dataset-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,19 @@ export class DatasetDetail extends connect(store)(PageViewElement) {
<wl-title level="4">${_ds.name}</wl-title>
<div style="display:flex; justify-content:space-between">
<wl-title level="5" style="color:#aaa">id:${_ds.id}</wl-title>
<span style="color: ${_ds.is_cached ? 'green' : 'lightsalmon'}">
${_ds.is_cached ? 'Available on MINT servers' : 'Not available on MINT servers'}
</span>
<div style="text-align: right;">
<span style="color: ${_ds.is_cached ? 'green' : 'lightsalmon'}">
${_ds.is_cached ? 'Available on MINT servers' : 'Available for download'}
</span>
${_ds.is_cached ? '' : html`
<br />
<span style="cursor: not-allowed;">
<wl-button flat inverted outlined disabled style="margin-top: 5px; --button-padding: 4px 8px;">
Download to MINT servers
</wl-button>
</span>
`}
</div>
</div>
<br />
<table class="pure-table pure-table-striped">
Expand Down
2 changes: 1 addition & 1 deletion src/screens/datasets/datasets-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class DatasetsSearch extends connect(store)(PageViewElement) {
<div style="display:flex; justify-content:space-between">
<wl-title level="5" style="color:#aaa">id:${ds.id}</wl-title>
<span style="color: ${ds.is_cached ? 'green' : 'lightsalmon'}">
${ds.is_cached ? 'Available on MINT servers' : 'Not available on MINT servers'}
${ds.is_cached ? 'Available on MINT servers' : 'Available for download'}
</span>
</div>
<br />
Expand Down
26 changes: 2 additions & 24 deletions src/screens/modeling/pathway/mint-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Model } from "screens/models/reducers";
import { IdMap } from "app/reducers";
import { DataResource } from "screens/datasets/reducers";
import { isObject } from "util";
import { downloadFile } from "util/ui_functions";

@customElement('mint-results')
export class MintResults extends connect(store)(MintPathwayPage) {
Expand Down Expand Up @@ -405,30 +406,7 @@ export class MintResults extends connect(store)(MintPathwayPage) {
});
});

//TODO: move this to other file
//https://stackoverflow.com/questions/14964035/how-to-export-javascript-array-info-to-csv-on-client-side
var download = function(content, fileName, mimeType) {
var a = document.createElement('a');
mimeType = mimeType || 'application/octet-stream';

if (navigator.msSaveBlob) { // IE10
navigator.msSaveBlob(new Blob([content], {
type: mimeType
}), fileName);
} else if (URL && 'download' in a) { //html5 A[download]
a.href = URL.createObjectURL(new Blob([content], {
type: mimeType
}));
a.setAttribute('download', fileName);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
} else {
location.href = 'data:application/octet-stream,' + encodeURIComponent(content); // only this mime type is supported
}
}

download(csv, 'results.csv', 'text/csv;encoding:utf-8');
downloadFile(csv, 'results.csv', 'text/csv;encoding:utf-8');
}

_nextPage(modelid: string, offset: number) {
Expand Down
47 changes: 46 additions & 1 deletion src/screens/regions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,49 @@ export const addRegions = (parent_regionid: string, regions: Region[]) : Promise
return batch.commit();
})
);
};
};

export const addSubcategory = (parent_regionid: string, category: string, subcategory: string) : Promise<void[]> => {
let regionRef = db.collection('regions').doc(parent_regionid);
let subcategory_name = category.toLowerCase() + '_subcategories';
let edit = {};
return new Promise ((resolve, reject) => {
regionRef.get().then((doc) => {
let subcategories = doc.get(subcategory_name) || [];
subcategories.push(subcategory);
edit[subcategory_name] = subcategories;

let setWithMerge = regionRef.set(edit, {merge: true});
setWithMerge.then(resolve);
})
});
};

export const removeSubcategory = (parent_regionid: string, category: string, subcategory: string) : Promise<void[]> => {
let regionRef = db.collection('regions').doc(parent_regionid);
let subcategory_name = category.toLowerCase() + '_subcategories';
let edit = {};

return new Promise ((resolve, reject) => {
regionRef.get().then((doc) => {
let subcategories = doc.get(subcategory_name) || [];
let index = subcategories.indexOf(subcategory);
if (index < 0) {
reject();
} else {
//Remove subcategory from array
subcategories.splice(index, 1);
edit[subcategory_name] = subcategories;
let setWithMerge = regionRef.set(edit, {merge: true});
setWithMerge.then(resolve);
//Remove all regions for that subcategory
let deleteQuery = db.collection('regions/' + parent_regionid + '/subregions').where('region_type', '==', subcategory);
deleteQuery.get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
doc.ref.delete();
});
});
}
})
});
};
2 changes: 1 addition & 1 deletion src/screens/regions/region-datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class RegionDatasets extends connect(store)(RegionQueryPage) {
<div>
${ds.is_cached ?
html`<span style="color: green">Available on MINT servers</span>` :
html`<span style="color: lightsalmon">Not available on MINT servers</span>`}
html`<span style="color: lightsalmon">Available for download</span>`}
<span style="color: gray">-</span> ${ds.resources.length} files
</div>
</wl-list-item>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/regions/region-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class RegionModels extends connect(store)(RegionQueryPage) {
<div>
${this._datasets[dsId].is_cached ?
html`<span style="color: green">Available on MINT servers</span>` :
html`<span style="color: lightsalmon">Not available on MINT servers</span>`}
html`<span style="color: lightsalmon">Available for download</span>`}
<span style="color: gray">-</span> ${this._datasets[dsId].resources.length} files
</div>
</wl-list-item>
Expand Down
16 changes: 0 additions & 16 deletions src/screens/regions/regions-agriculture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,10 @@ export class RegionsAgriculture extends connect(store)(PageViewElement) {

return html`
<div class="content">
${this._regionid === 'south_sudan' ? html`
<wl-tab-group align="center" style="margin-bottom: 1em;">
<wl-tab @click="${() => this._tab = 'base'}" checked="${this._tab === 'base'}">Base regions</wl-tab>
<wl-tab @click="${() => this._tab = 'woredas'}" checked="${this._tab === 'woredas'}">Woredas</wl-tab>
</wl-tab-group>
` : ''}
${this._tab == 'base' || this._regionid !== 'south_sudan' ? html`
<regions-editor active
style="--map-height: 450px;"
regionType="Agriculture"
></regions-editor>
` : ''}
${this._tab == 'woredas' && this._regionid === 'south_sudan' ? html`
<regions-editor active
style="--map-height: 450px;"
regionType="Woredas"
></regions-editor>
` : '' }
${items.length > 0 ? html`
<p>
Expand Down
Loading

0 comments on commit f769bc3

Please sign in to comment.