Skip to content

Commit

Permalink
Merge pull request #535 from correctexam/235-on-mobile-add-swipe-righ…
Browse files Browse the repository at this point in the history
…t-and-left-to-go-from-one-student-to-the-next-one

refactor align component
  • Loading branch information
barais authored Apr 10, 2024
2 parents 447daa3 + 9ea1847 commit cc415a5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
<!--<i class="pi pi-lock" style="font-size: 3rem"> </i>-->
<p-progressSpinner></p-progressSpinner>

<BR /> {{ avancement }}{{ avancementunit }} <BR /> {{ message }} <BR />
<BR />
{{ percentavancement | number: '1.0-2' }} % <BR /> {{ message }} <BR />

{{ submessage }}
<span *ngIf="submessage !== undefined && submessage.length > 0">{{ progress }} / 100</span>
<BR />
Expand Down Expand Up @@ -106,7 +108,7 @@ <h2 id="jhi-course-heading" data-cy="CourseCreateUpdateHeading" jhiTranslate="sc
</button>

<button
(click)="process(false)"
(click)="processFull(false)"
class="p-button p-button-primary"
[disabled]="!loaded"
[pTooltip]="'scanexam.alignscantooltip' | translate"
Expand Down
119 changes: 35 additions & 84 deletions src/main/webapp/app/scanexam/alignscan/alignscan.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,18 @@ export class AlignScanComponent implements OnInit, CacheUploadNotification {
faObjectUngroup = faObjectUngroup as IconProp;
examId = '';
exam!: IExam;
// cvState!: string;
currentStudent = 0;
nbreFeuilleParCopie = 2;
numberPagesInScan = 0;
// Change if partial update
currentPageAlign = 1;
// Change if partial update
currentPageAlignOver = 1;

percentavancement = 0;

partialAlign = false;
startPage = 1;
endPage = 1;
endPage = -1;

avancement = 0;
avancementunit = '';
// private editedImage: HTMLCanvasElement | undefined;
templatePages: Map<number, IPage> = new Map();
loaded = false;
alignement = 'marker';
Expand Down Expand Up @@ -219,25 +215,16 @@ export class AlignScanComponent implements OnInit, CacheUploadNotification {
title: 'Exam',
});
}
/* this.resolves.get(e.pageNumber!)()
this.resolves.delete(e.pageNumber!)
this.avancement = this.currentPageAlignOver;
this.currentPageAlignOver = this.currentPageAlignOver + 1;
im.data.set([]);*/

this.saveEligneImage(e.pageNumber!, im).then(() => {
im.data.set([]);
this.resolves.get(e.pageNumber!)();
this.resolves.delete(e.pageNumber!);
this.avancement = this.currentPageAlignOver;
this.currentPageAlignOver = this.currentPageAlignOver + 1;

// this.progress = ;
});
},
// eslint-disable-next-line object-shorthand
error: err => {
console.log(err);
console.error(err);
},
});
}
Expand All @@ -263,9 +250,13 @@ export class AlignScanComponent implements OnInit, CacheUploadNotification {
} else {
this.numberPagesInScan = numberPagesInScan;
}
this.avancementunit = ' / ' + this.numberPagesInScan;
}
}
async processFull(debug: boolean): Promise<void> {
this.startPage = 1;
this.endPage = this.numberPagesInScan;
await this.process(debug);
}

async process(debug: boolean): Promise<void> {
this.showMapping = debug;
Expand All @@ -275,13 +266,9 @@ export class AlignScanComponent implements OnInit, CacheUploadNotification {
this.blocked = true;
// Change if partial update
if (this.partialAlign) {
this.currentPageAlignOver = this.startPage;
this.avancement = this.startPage;
await this.removeElementForPages(+this.examId, this.startPage, this.endPage);
} else {
await this.removeElement(+this.examId);
this.currentPageAlignOver = 1;
this.avancement = 0;
}
await this.load();
await this.loadTemplatePage();
Expand Down Expand Up @@ -333,6 +320,7 @@ export class AlignScanComponent implements OnInit, CacheUploadNotification {
this.startPage = 1;
this.processpage = [];
this.currentPageAlign = 1;
this.percentavancement = 0;
this.endPage = value;
this.numberPagesInScan = value;
this.db.countAlignImage(+this.examId).then(e => (this.nbPageAlignInCache = e));
Expand All @@ -359,74 +347,40 @@ export class AlignScanComponent implements OnInit, CacheUploadNotification {
}

public async exportAsImage(): Promise<void> {
const stepPage = this.stepPage;
let nbrePageToProcess = this.numberPagesInScan;
const pagesnumber: number[] = [];

if (this.partialAlign) {
nbrePageToProcess = this.numberPagesInScan - this.startPage + 1;
for (let i = +this.startPage; i <= +this.endPage; i++) {
pagesnumber.push(i);
}
} else {
for (let i = +this.startPage; i <= +this.numberPagesInScan; i++) {
pagesnumber.push(i);
}
}

let count = Math.floor(nbrePageToProcess / stepPage);
for (let k = 0; k < count; k++) {
const pagesnumber: number[] = [];
const step =
pagesnumber.length % this.stepPage === 0
? Math.floor(pagesnumber.length / this.stepPage)
: Math.floor(pagesnumber.length / this.stepPage) + 1;
for (let i = 0; i < step; i++) {
if (this.alignement !== 'off') {
this.initPool();
}
if (this.partialAlign) {
this.currentPageAlignOver = +this.startPage;
this.avancement = +this.startPage;
for (let i = 1 + k * stepPage; i <= (k + 1) * stepPage; i++) {
if (i >= this.startPage) {
pagesnumber.push(i);
}
}
// Process jamais plus de 50 images pour éviter la fuite mémoire
let numbers: number[] = [];
if (i === step - 1) {
numbers = pagesnumber.slice(i * this.stepPage);
} else {
this.currentPageAlignOver = 1 + k * stepPage;
this.avancement = 1 + k * stepPage;
for (let i = 1 + k * stepPage; i <= (k + 1) * stepPage; i++) {
pagesnumber.push(i);
}
numbers = pagesnumber.slice(i * this.stepPage, (i + 1) * this.stepPage);
}
await PromisePool.for(pagesnumber)
.withConcurrency(this.nbreCore)
/* .onTaskFinished((page) => {
console.error('end send page to process ', page);
})*/
.process(
async page =>
new Promise<void>(resolve => {
this.alignPage(page);
this.resolves.set(page, resolve);
}),
);
if (this.alignement !== 'off') {
this.observer?.complete();
}
}
if (this.alignement !== 'off') {
this.initPool();
}
const count2 = nbrePageToProcess % stepPage;
let count1 = Math.floor(nbrePageToProcess / stepPage);
if (count2 > 0) {
const pagesnumber: number[] = [];

if (this.partialAlign) {
this.currentPageAlignOver = +this.startPage;
this.avancement = +this.startPage;
for (let i = 1 + count1 * stepPage; i <= count1 * stepPage + count2; i++) {
// if (i >= this.startPage) {
pagesnumber.push(+this.startPage + (i - 1));
// }
}
} else {
this.currentPageAlignOver = 1 + count1 * stepPage;
this.avancement = 1 + count1 * stepPage;
for (let i = 1 + count1 * stepPage; i <= count1 * stepPage + count2; i++) {
pagesnumber.push(i);
}
}
await PromisePool.for(pagesnumber)
const j = i;
await PromisePool.for(numbers)
.withConcurrency(this.nbreCore)
.onTaskFinished((user, pool) => {
this.percentavancement =
(j * this.stepPage * 100) / pagesnumber.length + (pool.processedPercentage() * numbers.length) / pagesnumber.length;
})
.process(
async page =>
new Promise<void>(resolve => {
Expand All @@ -438,7 +392,6 @@ export class AlignScanComponent implements OnInit, CacheUploadNotification {
this.observer?.complete();
}
}

this.saveData();
}

Expand All @@ -451,8 +404,6 @@ export class AlignScanComponent implements OnInit, CacheUploadNotification {
pageNumber: page,
value: dataURL!.value,
});
this.avancement = this.currentPageAlignOver;
this.currentPageAlignOver = this.currentPageAlignOver + 1;
this.resolves.get(page)();
this.resolves.delete(page);

Expand Down

0 comments on commit cc415a5

Please sign in to comment.