Commit f2d49c8a authored by Deni Rinaldi's avatar Deni Rinaldi

Merge branch 'rifka' into 'master'

fix download

See merge request !290
parents 259b9b4a bfdc8ddb
......@@ -55,7 +55,31 @@ export default class AuditTahunan extends Component {
]
})
this.setState({ dataTable })
let docPath = response.data.data.map((item) => {
return [
item.document_filepath
]
})
this.setState({ docPath })
})
}
openPopUp = async (index, val, type) =>{
if (type === 'download') {
console.log(this.state.docPath[val])
let res = await fetch(
"https://tia.eksad.com/tia-reporting-dev/public/document/download_document?documentName="+this.state.docPath[val]+"&&fileType="+index[5]
)
res = await res.blob()
// console.log(res)
if (res.size > 0) {
let url = window.URL.createObjectURL(res);
let a = document.createElement('a');
a.href = url;
a.download = index[1];
a.click();
}
}
}
render() {
......@@ -78,7 +102,7 @@ export default class AuditTahunan extends Component {
marginRight: 15
}}
// onClick={() => console.log(tableMeta)}
// onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}
onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
>
<img src={Images.download} />
</button>
......
......@@ -55,18 +55,42 @@ export default class BOD extends Component {
item.company_name,
item.document_periode,
item.document_type,
String(Number(item.document_size) / 1000 + ' MB'),
String(Number(item.document_size) / 1000 + ' KB'),
item.created_by,
item.created_at,
]
})
this.setState({ dataTable })
let docPath = response.data.data.map((item) => {
return [
item.document_filepath
]
})
this.setState({ docPath })
}
}
}
})
}
openPopUp = async (index, val, type) =>{
if (type === 'download') {
console.log(this.state.docPath[val])
let res = await fetch(
"https://tia.eksad.com/tia-reporting-dev/public/document/download_document?documentName="+this.state.docPath[val]+"&&fileType="+index[5]
)
res = await res.blob()
// console.log(res)
if (res.size > 0) {
let url = window.URL.createObjectURL(res);
let a = document.createElement('a');
a.href = url;
a.download = index[1];
a.click();
}
}
}
render() {
let columns = [
{
......@@ -88,7 +112,7 @@ export default class BOD extends Component {
marginRight: 15
}}
// onClick={() => console.log(tableMeta)}
// onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}
onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
>
<img src={Images.download} />
</button>
......
......@@ -143,35 +143,6 @@ export default class DocumentManagement extends Component {
this.setState({ alert: false })
}
getDownloadDocument(payload){
// console.log(payload)
api.create().downloadDocument(payload).then(response => {
console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.status === "success") {
// this.getDataDocument(settingID)
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'success', visibleCreate: false })
}
else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error' })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error' })
}
})
}
render() {
return (
<div style={{ height: this.props.height, backgroundColor: '#f8f8f8' }}>
......@@ -231,7 +202,6 @@ export default class DocumentManagement extends Component {
<QReview
data={this.state.listData[this.state.tab]}
refresh={this.state.refresh}
getDownloadDocument={this.getDownloadDocument.bind(this)}
/>
:
this.state.id === 68543 ?
......@@ -246,7 +216,7 @@ export default class DocumentManagement extends Component {
refresh={this.state.refresh}
/>
:
<span>Test2</span>
<span>Coming Soon</span>
)}
</div>
......
......@@ -47,13 +47,37 @@ export default class ManualBookETMS extends Component {
item.description,
item.company_name,
item.document_type,
String(Number(item.document_size) / 1000 + ' MB'),
String(Number(item.document_size) / 1000 + ' KB'),
item.created_by,
item.created_at,
]
})
this.setState({ dataTable })
let docPath = response.data.data.map((item) => {
return [
item.document_filepath
]
})
this.setState({ docPath })
})
}
openPopUp = async (index, val, type) =>{
if (type === 'download') {
console.log(this.state.docPath[val])
let res = await fetch(
"https://tia.eksad.com/tia-reporting-dev/public/document/download_document?documentName="+this.state.docPath[val]+"&&fileType="+index[5]
)
res = await res.blob()
// console.log(res)
if (res.size > 0) {
let url = window.URL.createObjectURL(res);
let a = document.createElement('a');
a.href = url;
a.download = index[1];
a.click();
}
}
}
render() {
......@@ -76,7 +100,7 @@ export default class ManualBookETMS extends Component {
marginRight: 15
}}
// onClick={() => console.log(tableMeta)}
// onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}
onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
>
<img src={Images.download} />
</button>
......
......@@ -47,13 +47,37 @@ export default class ManualBookTia extends Component {
item.company_name,
item.document_periode,
item.document_type,
String(Number(item.document_size) / 1000 + ' MB'),
String(Number(item.document_size) / 1000 + ' KB'),
item.created_by,
item.created_at,
]
})
this.setState({ dataTable })
let docPath = response.data.data.map((item) => {
return [
item.document_filepath
]
})
this.setState({ docPath })
})
}
openPopUp = async (index, val, type) =>{
if (type === 'download') {
console.log(this.state.docPath[val])
let res = await fetch(
"https://tia.eksad.com/tia-reporting-dev/public/document/download_document?documentName="+this.state.docPath[val]+"&&fileType="+index[5]
)
res = await res.blob()
// console.log(res)
if (res.size > 0) {
let url = window.URL.createObjectURL(res);
let a = document.createElement('a');
a.href = url;
a.download = index[1];
a.click();
}
}
}
render() {
......@@ -76,7 +100,7 @@ export default class ManualBookTia extends Component {
marginRight: 15
}}
// onClick={() => console.log(tableMeta)}
// onClick={() => this.openPopUp(tableMeta.rowData, 'edit')}
onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
>
<img src={Images.download} />
</button>
......
......@@ -61,12 +61,18 @@ export default class QReview extends Component {
item.company_name,
item.document_periode,
item.document_type,
String(Number(item.document_size) / 1000 + ' MB'),
String(Number(item.document_size) / 1000 + ' KB'),
item.created_by,
item.created_at,
item.created_at
]
})
this.setState({ dataTable })
let docPath = response.data.data.map((item) => {
return [
item.document_filepath
]
})
this.setState({ docPath })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In")) {
......@@ -86,29 +92,24 @@ export default class QReview extends Component {
})
}
openPopUp(index, type){
openPopUp = async (index, val, type) =>{
if (type === 'download') {
const formData = new FormData();
formData.append("documentName", index[1]);
formData.append("fileType", index[5]);
this.setState({ formData }, ()=> {
this.props.getDownloadDocument(this.state.formData)
})
console.log(this.state.docPath[val])
let res = await fetch(
"https://tia.eksad.com/tia-reporting-dev/public/document/download_document?documentName="+this.state.docPath[val]+"&&fileType="+index[5]
)
res = await res.blob()
// console.log(res)
if (res.size > 0) {
let url = window.URL.createObjectURL(res);
let a = document.createElement('a');
a.href = url;
a.download = index[1];
a.click();
}
}
downloadDoc() {
let datax = this.state.index
console.log(datax)
// let payload = {
// "documentName": this.state.typeId.approval_type_id,
// "fileType": this.state.order
// }
// this.props.getDownloadDocument(payload)
}
render() {
let columns = [{
name: "Action",
......@@ -129,7 +130,7 @@ export default class QReview extends Component {
marginRight: 15
}}
// onClick={() => console.log(tableMeta)}
onClick={() => this.openPopUp(tableMeta.rowData, 'download')}
onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
>
<img src={Images.download} />
</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment