Browse Source

Download document gantt

pull/1/head
Wahyu Ramadhan 2 years ago
parent
commit
7109d944fd
  1. 40
      edit-mode/function/ganttActivityUploadDoc.js
  2. 40
      view-mode/function/ganttActivityUploadDoc.js

40
edit-mode/function/ganttActivityUploadDoc.js

@ -186,7 +186,7 @@ function searchDocuments(activity_id) {
columns: [ columns: [
{ data: null, title: "Action", { data: null, title: "Action",
"mRender": function(data, type, row){ "mRender": function(data, type, row){
var optContent = '<button title="Download File" type="button" class="btn btn-xs btn-default" onclick="downloadDocument('+row.id+');"><span class="fa fa-download"></span></button>'; var optContent = '<button title="Download File" type="button" class="btn btn-xs btn-default" onclick="downloadDocument(' + row.id + ',`' + row.file + '`);"><span class="fa fa-download"></span></button>';
optContent += '<button title="Delete File" type="button" class="btn btn-xs btn-default" onclick="deleteDocument('+row.id+', '+activity_id+');"><span class="fa fa-trash"></span></button>'; optContent += '<button title="Delete File" type="button" class="btn btn-xs btn-default" onclick="deleteDocument('+row.id+', '+activity_id+');"><span class="fa fa-trash"></span></button>';
return optContent; return optContent;
} }
@ -207,17 +207,35 @@ function searchDocuments(activity_id) {
}); });
} }
async function downloadDocument(id) { async function downloadDocument(id, name) {
console.log('download document', id); let result;
var urlDownload = DOCUMENT_DOWNLOAD_URL(id); await fetch(DOCUMENT_DOWNLOAD_URL(id), {
const result = await axiosInstance headers: new Headers({
.get(DOCUMENT_DOWNLOAD_URL(id)) 'Content-Type': 'application/json',
.then(res => res) 'Authorization': `Bearer ${token}`
.catch((error) => error.response); })
console.log('downloadDocument', result); })
if (result && result.data.code === 200) { .then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
result = response;
return response.blob();
})
.then(blob => {
let url = window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = name;
a.click();
})
.catch(error => {
console.error(`Error: ${error.message}`);
alert('File not found');
});
if (result && result.status == 200) {
$("body").removeClass("loading"); $("body").removeClass("loading");
window.open(urlDownload);
} }
else { else {
$("body").removeClass("loading"); $("body").removeClass("loading");

40
view-mode/function/ganttActivityUploadDoc.js

@ -186,7 +186,7 @@ function searchDocuments(activity_id) {
columns: [ columns: [
{ data: null, title: "Action", { data: null, title: "Action",
"mRender": function(data, type, row){ "mRender": function(data, type, row){
var optContent = '<button title="Download File" type="button" class="btn btn-xs btn-default" onclick="downloadDocument('+row.id+');"><span class="fa fa-download"></span></button>'; var optContent = '<button title="Download File" type="button" class="btn btn-xs btn-default" onclick="downloadDocument(' + row.id + ',`' + row.file + '`);"><span class="fa fa-download"></span></button>';
optContent += '<button title="Delete File" type="button" class="btn btn-xs btn-default" onclick="deleteDocument('+row.id+', '+activity_id+');"><span class="fa fa-trash"></span></button>'; optContent += '<button title="Delete File" type="button" class="btn btn-xs btn-default" onclick="deleteDocument('+row.id+', '+activity_id+');"><span class="fa fa-trash"></span></button>';
return optContent; return optContent;
} }
@ -207,17 +207,35 @@ function searchDocuments(activity_id) {
}); });
} }
async function downloadDocument(id) { async function downloadDocument(id, name) {
console.log('download document', id); let result;
var urlDownload = DOCUMENT_DOWNLOAD_URL(id); await fetch(DOCUMENT_DOWNLOAD_URL(id), {
const result = await axiosInstance headers: new Headers({
.get(DOCUMENT_DOWNLOAD_URL(id)) 'Content-Type': 'application/json',
.then(res => res) 'Authorization': `Bearer ${token}`
.catch((error) => error.response); })
console.log('downloadDocument', result); })
if (result && result.data.code === 200) { .then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
result = response;
return response.blob();
})
.then(blob => {
let url = window.URL.createObjectURL(blob);
let a = document.createElement('a');
a.href = url;
a.download = name;
a.click();
})
.catch(error => {
console.error(`Error: ${error.message}`);
alert('File not found');
});
if (result && result.status == 200) {
$("body").removeClass("loading"); $("body").removeClass("loading");
window.open(urlDownload);
} }
else { else {
$("body").removeClass("loading"); $("body").removeClass("loading");

Loading…
Cancel
Save