Skip to content

Commit

Permalink
WIP - still need file property on layer
Browse files Browse the repository at this point in the history
  • Loading branch information
kimura-developer committed Oct 13, 2023
1 parent a8a175e commit 39dabee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
33 changes: 22 additions & 11 deletions web-app/src/ng1/admin/layers/layer.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class AdminLayerController {
$onInit() {
this.Layer.get({ id: this.$stateParams.layerId }, (layer) => {
this.layer = layer;
this.layer.isFileBased = !['WMS', 'XYZ'].includes(this.layer.type);

if (this.layer.state !== 'available') {
this.$timeout(this.checkLayerProcessingStatus.bind(this), 1000);
Expand Down Expand Up @@ -97,6 +96,10 @@ class AdminLayerController {
});
}

isLayerFileBased() {
return this.layer && !!this.layer.file;
}

$postLink() {
this.uploadSnackbar = new snackbar.MDCSnackbar(
document.querySelector('#upload-snackbar')
Expand Down Expand Up @@ -178,26 +181,34 @@ class AdminLayerController {
}

handleLayerDownloadResponse(response) {
if (response.type === 'application/json') {
if (response && response.filePath) {
const desiredFileName = this.layer.fileName;
this.triggerFileDownload(response.filePath, desiredFileName);
} else {
this.handleJSONDownloadError(response);
return;
}
}

this.triggerFileDownload(response);
triggerFileDownload(filePath, fileName) {
const a = document.createElement('a');
a.href = filePath;
a.download = fileName;
a.style.display = 'none';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}

handleLayerDownloadError(err) {
console.error('Error downloading the layer', err);
}

handleJSONDownloadError(response) {
response.text().then((text) => {
const errorObj = JSON.parse(text);
console.error(
'Error downloading the layer',
errorObj.message || errorObj
);
});
if (response && response.message) {
console.error('Error downloading the layer', response.message);
} else {
console.error('Error downloading the layer', response);
}
}

triggerFileDownload(response) {
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/ng1/admin/layers/layer.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h2>
<button class="btn btn-default pull-right" ng-click="$ctrl.editLayer($ctrl.layer)"><i class="fa fa-edit"></i> Edit</button>
</h2>
<h2>
<button ng-if="layer.isFileBased" (click)="downloadLayer()">Download</button>
<button ng-if="$ctrl.isLayerFileBased()" (click)="downloadLayer()">Download</button>
</h2>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/ng1/factories/layer.resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Layer($resource) {
download: {
method: 'GET',
url: '/api/layers/:layerId',
responseType: 'blob'
responseType: 'json'
},
}
);
Expand Down

0 comments on commit 39dabee

Please sign in to comment.