Broker System for Supercredit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 satır
3.2KB

  1. import {AfterViewInit, Component, ElementRef, EventEmitter, OnInit, Output, ViewChild, ViewEncapsulation} from '@angular/core';
  2. import {FileInfo, FileRestrictions, SuccessEvent, UploadComponent, UploadEvent, UploadProgressEvent} from '@progress/kendo-angular-upload';
  3. import {AuthService} from '../service/auth.service';
  4. import {range} from '@progress/kendo-angular-dateinputs/dist/es2015/util';
  5. import {Router} from '@angular/router';
  6. import {PageChangeEvent} from '@progress/kendo-angular-pager';
  7. @Component({
  8. selector: 'app-lender-uploads',
  9. templateUrl: './lender-uploads.component.html',
  10. styleUrls: ['./lender-uploads.component.scss'],
  11. })
  12. export class LenderUploadsComponent implements OnInit {
  13. @Output() success: EventEmitter<SuccessEvent> = new EventEmitter<SuccessEvent>();
  14. @Output() click: EventEmitter<FileInfo> = new EventEmitter<FileInfo>();
  15. @Output() complete: EventEmitter<FileInfo> = new EventEmitter<FileInfo>();
  16. @Output() upload: EventEmitter<boolean> = new EventEmitter<boolean>();
  17. private uploads: SuccessEvent[] = [];
  18. public value = 0 ;
  19. public map: Map<string, SuccessEvent> = new Map<string, SuccessEvent>();
  20. uploadSaveUrl = 'https://svr2021.lawipac.com:8080/api/v1/lender-upload/'; // should represent an actual API endpoint
  21. uploadRemoveUrl = 'https://svr2021.lawipac.com:8080/api/v1/lender-upload-remove/'; // should represent an actual API endpoint
  22. public allUploads = [...range(30, 44 )];
  23. public displayedUploads: any[] = [];
  24. public filteredUploads: any[] = [];
  25. public skip = 0;
  26. public pageSize = 12;
  27. public total = 0;
  28. myRestrictions: FileRestrictions = {
  29. allowedExtensions: ['.pdf', '.xls', '.xlsx']
  30. };
  31. constructor(private auth: AuthService, private router: Router) {
  32. }
  33. ngOnInit(): void {
  34. this.uploadSaveUrl = this.auth.getUrl('lender-upload/');
  35. this.uploadRemoveUrl = this.auth.getUrl('lender-upload-remove/');
  36. this.loadDisplayedUploads();
  37. }
  38. public onClick( files: any): void{
  39. this.click.emit(files[0]);
  40. }
  41. public onSuccess(ss: SuccessEvent ): void {
  42. this.uploads.push(ss);
  43. this.map.set(ss.files[0].uid, ss);
  44. this.success.emit(ss);
  45. this.allUploads.unshift(this.allUploads.length + 100);
  46. }
  47. public onUpload(ss: UploadEvent ): void {
  48. this.upload.emit(true);
  49. }
  50. public onComplete(): void {
  51. this.upload.emit(false);
  52. }
  53. public hasResp(uid): boolean {
  54. let found = false;
  55. this.uploads.every(v => {
  56. if ( v.files[0].uid === uid ) {
  57. found = true;
  58. return false; // stop search
  59. }
  60. });
  61. return found;
  62. }
  63. public uploadProgress(prog: UploadProgressEvent): void {
  64. this.value = prog.percentComplete.valueOf();
  65. }
  66. public show( i: number): void{
  67. this.router.navigate(['/upload-details/' + i]);
  68. }
  69. public onPageChange(e: PageChangeEvent): void {
  70. this.skip = e.skip;
  71. this.pageSize = e.take;
  72. this.loadDisplayedUploads();
  73. }
  74. private loadDisplayedUploads(): void {
  75. this.filteredUploads = this.allUploads ;
  76. this.displayedUploads = this.filteredUploads.slice(this.skip, this.skip + this.pageSize);
  77. this.total = this.displayedUploads.length;
  78. }
  79. public onFilterUploads(hint: string): void {
  80. this.loadDisplayedUploads();
  81. }
  82. }