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,9 +55,33 @@ export default class AuditTahunan extends Component { ...@@ -55,9 +55,33 @@ export default class AuditTahunan extends Component {
] ]
}) })
this.setState({ dataTable }) 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() { render() {
let columns = [{ let columns = [{
name: "Action", name: "Action",
...@@ -78,7 +102,7 @@ export default class AuditTahunan extends Component { ...@@ -78,7 +102,7 @@ export default class AuditTahunan extends Component {
marginRight: 15 marginRight: 15
}} }}
// onClick={() => console.log(tableMeta)} // onClick={() => console.log(tableMeta)}
// onClick={() => this.openPopUp(tableMeta.rowData, 'edit')} onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
> >
<img src={Images.download} /> <img src={Images.download} />
</button> </button>
......
...@@ -55,18 +55,42 @@ export default class BOD extends Component { ...@@ -55,18 +55,42 @@ export default class BOD extends Component {
item.company_name, item.company_name,
item.document_periode, item.document_periode,
item.document_type, item.document_type,
String(Number(item.document_size) / 1000 + ' MB'), String(Number(item.document_size) / 1000 + ' KB'),
item.created_by, item.created_by,
item.created_at, item.created_at,
] ]
}) })
this.setState({ dataTable }) 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() { render() {
let columns = [ let columns = [
{ {
...@@ -88,7 +112,7 @@ export default class BOD extends Component { ...@@ -88,7 +112,7 @@ export default class BOD extends Component {
marginRight: 15 marginRight: 15
}} }}
// onClick={() => console.log(tableMeta)} // onClick={() => console.log(tableMeta)}
// onClick={() => this.openPopUp(tableMeta.rowData, 'edit')} onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
> >
<img src={Images.download} /> <img src={Images.download} />
</button> </button>
......
...@@ -143,35 +143,6 @@ export default class DocumentManagement extends Component { ...@@ -143,35 +143,6 @@ export default class DocumentManagement extends Component {
this.setState({ alert: false }) 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() { render() {
return ( return (
<div style={{ height: this.props.height, backgroundColor: '#f8f8f8' }}> <div style={{ height: this.props.height, backgroundColor: '#f8f8f8' }}>
...@@ -231,7 +202,6 @@ export default class DocumentManagement extends Component { ...@@ -231,7 +202,6 @@ export default class DocumentManagement extends Component {
<QReview <QReview
data={this.state.listData[this.state.tab]} data={this.state.listData[this.state.tab]}
refresh={this.state.refresh} refresh={this.state.refresh}
getDownloadDocument={this.getDownloadDocument.bind(this)}
/> />
: :
this.state.id === 68543 ? this.state.id === 68543 ?
...@@ -246,7 +216,7 @@ export default class DocumentManagement extends Component { ...@@ -246,7 +216,7 @@ export default class DocumentManagement extends Component {
refresh={this.state.refresh} refresh={this.state.refresh}
/> />
: :
<span>Test2</span> <span>Coming Soon</span>
)} )}
</div> </div>
......
...@@ -47,15 +47,39 @@ export default class ManualBookETMS extends Component { ...@@ -47,15 +47,39 @@ export default class ManualBookETMS extends Component {
item.description, item.description,
item.company_name, item.company_name,
item.document_type, item.document_type,
String(Number(item.document_size) / 1000 + ' MB'), String(Number(item.document_size) / 1000 + ' KB'),
item.created_by, item.created_by,
item.created_at, item.created_at,
] ]
}) })
this.setState({ dataTable }) 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() { render() {
let columns = [{ let columns = [{
name: "Action", name: "Action",
...@@ -76,7 +100,7 @@ export default class ManualBookETMS extends Component { ...@@ -76,7 +100,7 @@ export default class ManualBookETMS extends Component {
marginRight: 15 marginRight: 15
}} }}
// onClick={() => console.log(tableMeta)} // onClick={() => console.log(tableMeta)}
// onClick={() => this.openPopUp(tableMeta.rowData, 'edit')} onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
> >
<img src={Images.download} /> <img src={Images.download} />
</button> </button>
......
...@@ -47,15 +47,39 @@ export default class ManualBookTia extends Component { ...@@ -47,15 +47,39 @@ export default class ManualBookTia extends Component {
item.company_name, item.company_name,
item.document_periode, item.document_periode,
item.document_type, item.document_type,
String(Number(item.document_size) / 1000 + ' MB'), String(Number(item.document_size) / 1000 + ' KB'),
item.created_by, item.created_by,
item.created_at, item.created_at,
] ]
}) })
this.setState({ dataTable }) 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() { render() {
let columns = [{ let columns = [{
name: "Action", name: "Action",
...@@ -76,7 +100,7 @@ export default class ManualBookTia extends Component { ...@@ -76,7 +100,7 @@ export default class ManualBookTia extends Component {
marginRight: 15 marginRight: 15
}} }}
// onClick={() => console.log(tableMeta)} // onClick={() => console.log(tableMeta)}
// onClick={() => this.openPopUp(tableMeta.rowData, 'edit')} onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
> >
<img src={Images.download} /> <img src={Images.download} />
</button> </button>
......
...@@ -61,12 +61,18 @@ export default class QReview extends Component { ...@@ -61,12 +61,18 @@ export default class QReview extends Component {
item.company_name, item.company_name,
item.document_periode, item.document_periode,
item.document_type, item.document_type,
String(Number(item.document_size) / 1000 + ' MB'), String(Number(item.document_size) / 1000 + ' KB'),
item.created_by, item.created_by,
item.created_at, item.created_at
] ]
}) })
this.setState({ dataTable }) this.setState({ dataTable })
let docPath = response.data.data.map((item) => {
return [
item.document_filepath
]
})
this.setState({ docPath })
} else { } else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => { this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In")) { if (response.data.message.includes("Someone Logged In")) {
...@@ -86,29 +92,24 @@ export default class QReview extends Component { ...@@ -86,29 +92,24 @@ export default class QReview extends Component {
}) })
} }
openPopUp(index, type){ openPopUp = async (index, val, type) =>{
if (type === 'download') { if (type === 'download') {
const formData = new FormData(); console.log(this.state.docPath[val])
formData.append("documentName", index[1]); let res = await fetch(
formData.append("fileType", index[5]); "https://tia.eksad.com/tia-reporting-dev/public/document/download_document?documentName="+this.state.docPath[val]+"&&fileType="+index[5]
this.setState({ formData }, ()=> { )
this.props.getDownloadDocument(this.state.formData) 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() { render() {
let columns = [{ let columns = [{
name: "Action", name: "Action",
...@@ -129,7 +130,7 @@ export default class QReview extends Component { ...@@ -129,7 +130,7 @@ export default class QReview extends Component {
marginRight: 15 marginRight: 15
}} }}
// onClick={() => console.log(tableMeta)} // onClick={() => console.log(tableMeta)}
onClick={() => this.openPopUp(tableMeta.rowData, 'download')} onClick={() => this.openPopUp(tableMeta.rowData, val, 'download')}
> >
<img src={Images.download} /> <img src={Images.download} />
</button> </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