coffeecode12

Untitled

May 31st, 2022
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. async convertFile() {
  2. if(this.f.bank.value.bankName === '' || this.f.tglAwalUjiTuntas.value ===''){
  3. console.log('bank tidak valid')
  4. return
  5. }else{
  6. const file = this.f.file.value[0];
  7. const dialogConfig = new MatDialogConfig();
  8. dialogConfig.disableClose = true;
  9. dialogConfig.data = {
  10. dialogTitle: 'Converting file',
  11. dialogText: 'Silahkan menunggu...',
  12. isLoading: true,
  13. };
  14. const dialogRef = this.dialog.open(DialogComponent, dialogConfig);
  15. const folderBank = this.f.bank.value.bankName.replaceAll(' ' , '-') + '-' + moment( this.f.tglAwalUjiTuntas.value).format('MM') + '-' + moment(this.f.tglAwalUjiTuntas.value).format('yy')
  16. let pathArray = []
  17. let fullPath : any = '';
  18.  
  19. pathArray.push(folderBank);
  20. pathArray.push("Penugasan-uji-tuntas");
  21. pathArray.push("Upload-Files");
  22.  
  23. let tempFile = [];
  24. tempFile.push(file);
  25.  
  26. let resp = await this.fileService.generateFolder(pathArray,0,pathArray.length)
  27. resp.subscribe(
  28. async (res : any) => {
  29. await this.generateFile.state.subscribe(
  30. (fileRes : any) => {
  31. fullPath = fileRes
  32. if(fileRes.index == pathArray.length){
  33. this.fileService.convertFileBase64Try(tempFile , fullPath?.pathTo ).subscribe((res) => {
  34.  
  35. if (res) {
  36. this.formModel = {
  37. fileContent: res.formModel.fileContent,
  38. filename: res.formModel.filename,
  39. fiturId: res.formModel.fiturId,
  40. folderPath: res.formModel.folderPath,
  41. fileSize: res.formModel.fileSize
  42. }
  43. dialogRef.close();
  44. }
  45. }, (error) => {
  46. dialogRef.close();
  47. const dialogConfigError = new MatDialogConfig();
  48. dialogConfigError.disableClose = true;
  49. dialogConfigError.data = {
  50. dialogTitle: 'Gagal Convert File',
  51. dialogText: error.error.detail,
  52. isLoading: false
  53. };
  54. const dialogErr = this.dialog.open(DialogInfoComponent, dialogConfigError);
  55. });
  56.  
  57. }
  58.  
  59. }
  60. )
  61. }
  62. )
  63. }
  64. }
Add Comment
Please, Sign In to add comment