Skip to content

Commit

Permalink
downloadLayer in AdminLayerController and layer.resource
Browse files Browse the repository at this point in the history
  • Loading branch information
kimura-developer committed Oct 3, 2023
1 parent 0ec46fe commit 2f4326b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 16 additions & 2 deletions web-app/src/ng1/admin/layers/layer.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,22 @@ class AdminLayerController {
}

downloadLayer() {
// WIP - placeholder
this.$state.go('admin.layerEdit', { layerId: layer.id });
this.Layer.downloadLayer(this.$stateParams.eventId, this.layer.id)
.then((response) => {
const blob = new Blob([response.data], { type: response.data.type });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
// Use a structured naming convention for the filename
a.download = `Layer-${this.layer.id}-${new Date().toISOString()}.ext`;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch((err) => {
console.error('Error downloading the layer', err);
});
}

addUploadFile() {
Expand Down
6 changes: 6 additions & 0 deletions web-app/src/ng1/factories/layer.resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@ function Layer($resource) {
}
};

Layer.downloadLayer = function (eventId, layerId) {
const url = `/api/events/${eventId}/layers/${layerId}`;
return $resource(url).get({ responseType: 'blob' }).$promise;
};


return Layer;
}

0 comments on commit 2f4326b

Please sign in to comment.