Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Andi Braimllari committed Dec 7, 2024
1 parent 1ac4590 commit ea4c15f
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/app/home/modals/document-upload/document-upload.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import {
takeUntil
} from 'rxjs';
import * as XLSX from 'xlsx';
import { WorkBook, WorkSheet } from 'xlsx';

import { DarkModeService } from '../../../services/dark-mode.service';
import { environment } from '../../../../environments/environment';
import { MarkedPage } from '../../../models/marked-page';
import { DocumentMarking } from '../../../models/document-marking';
import { WorkBook, WorkSheet } from 'xlsx';

@Component({
selector: 'app-document-upload',
Expand Down Expand Up @@ -113,36 +113,6 @@ export class DocumentUploadComponent implements OnDestroy {
document.getElementById('uploaded-document-name')!.title = '';
}

private startProcessingTimer(totalMinutes: number = 3 * 60 * 1000): void {
this.countdown$ = interval(60 * 1000).pipe(
startWith(0),
map((_, index) => totalMinutes - index * 60 * 1000),
takeUntil(this.countdownSubject)
);

this.countdown$.subscribe((count: number) => {
const countInMinutes = count / 60000;
this.processingTimeLeft =
countInMinutes === 1 ? '1 minutë' : `${countInMinutes} minuta`;
if (count === 0) {
this.stopProcessingTimer();
}
});
}

private stopProcessingTimer(): void {
this.countdownSubject.next();
}

private initializeURLs(): void {
this.baseURL = environment.baseURL;
this.uploadDocumentURL = this.baseURL + '/api/uploadDocument';
}

getMaxLength(arr: any[], property: string): number {
return Math.max(...arr.map((item) => item[property].toString().length));
}

downloadReport(): void {
const data: any[][] = [
['Numri i Faqes', 'Shenjimi', 'Lloji', 'Përshkrimi', 'Sugjerimet']
Expand All @@ -163,7 +133,7 @@ export class DocumentUploadComponent implements OnDestroy {

const columns = Object.keys(data[0]);
const columnWidths = columns.map((col) => ({
wch: Math.max(col.length, this.getMaxLength(data, col))
wch: Math.max(col.length, this.getMaxCellLength(data, col))
}));

const markedPagesReport: WorkBook = XLSX.utils.book_new();
Expand All @@ -184,4 +154,34 @@ export class DocumentUploadComponent implements OnDestroy {
`penda-${fileName?.substring(0, fileName?.length - 4)}.xlsx`
);
}

private startProcessingTimer(totalMinutes: number = 3 * 60 * 1000): void {
this.countdown$ = interval(60 * 1000).pipe(
startWith(0),
map((_, index) => totalMinutes - index * 60 * 1000),
takeUntil(this.countdownSubject)
);

this.countdown$.subscribe((count: number) => {
const countInMinutes = count / 60000;
this.processingTimeLeft =
countInMinutes === 1 ? '1 minutë' : `${countInMinutes} minuta`;
if (count === 0) {
this.stopProcessingTimer();
}
});
}

private stopProcessingTimer(): void {
this.countdownSubject.next();
}

private getMaxCellLength(arr: any[], property: string): number {
return Math.max(...arr.map((item) => item[property].toString().length));
}

private initializeURLs(): void {
this.baseURL = environment.baseURL;
this.uploadDocumentURL = this.baseURL + '/api/uploadDocument';
}
}

0 comments on commit ea4c15f

Please sign in to comment.