@@ -56,6 +56,7 @@ import { BlockUIModule } from 'primeng/blockui';
5656import { PredictionStudentResponseService } from '../mlt/prediction-studentresponse-service' ;
5757import { IExam } from 'app/entities/exam/exam.model' ;
5858import { imagenoanswer } from '../corrigequestion/noresponse' ;
59+ import { IExamSheet } from 'app/entities/exam-sheet/exam-sheet.model' ;
5960
6061export interface Zone4SameCommentOrSameGrade {
6162 answers : Answer [ ] ;
@@ -671,29 +672,64 @@ export class ComparestudentanswerComponent implements OnInit, AfterViewInit {
671672 } ) ;
672673 }
673674
674- downloadAllHighQuality ( ) : void {
675+ async downloadAllHighQuality ( ) : Promise < void > {
675676 const zip = new jszip ( ) ;
676677 const img = zip . folder ( 'images' ) ;
677678 const metadata = zip . folder ( 'metadata' ) ;
679+ const all = await firstValueFrom ( this . questionService . getallcommentsandprediction4qId ( + this . qId ! ) ) ;
680+ metadata ?. file ( 'metadata.json' , JSON . stringify ( all ) ) ;
681+
682+ if ( this . exam ?. nbgrader === true ) {
683+ const _srs = await firstValueFrom ( this . sheetService . query ( { examId : + this . examId ! } ) ) ;
684+ const srs : IExamSheet [ ] = _srs . body || [ ] ;
685+ const _q = await firstValueFrom ( this . questionService . find ( + this . qId ! ) ) ;
686+ // Query predictions for this question
687+ const q = _q . body || undefined ;
688+ if ( q !== undefined ) {
689+ let j = 1 ;
690+ for ( const sr of srs ) {
691+ const i = await this . db . getAlignImagesForPageNumbers ( + this . examId ! , [ sr . pagemin ! + q . zoneDTO ! . pageNumber ! ] ) ;
692+
693+ // const pageNumber = 1;
694+ let imageb64 = '' ;
695+ if ( i . length === 0 ) {
696+ imageb64 = imagenoanswer ;
697+ } else {
698+ const image = JSON . parse ( i [ 0 ] . value , this . reviver ) ;
699+ imageb64 = image . pages ;
700+ }
701+ const idx = imageb64 . indexOf ( 'base64,' ) + 'base64,' . length ; // or = 28 if you're sure about the prefix
702+ const ext = imageb64 . substring ( 0 , idx ) ;
703+ let extension = '.webp' ;
704+ if ( ext === 'data:image/png;base64,' ) {
705+ extension = '.png' ;
706+ } else if ( ext === 'data:image/jpg;base64,' ) {
707+ extension = '.jpg' ;
708+ }
709+ const content = imageb64 . substring ( idx ) ;
678710
679- let exportImageType = 'image/webp' ;
680- if (
681- this . preferenceService . getPreference ( ) . imageTypeExport !== undefined &&
682- [ 'image/webp' , 'image/png' , 'image/jpg' ] . includes ( this . preferenceService . getPreference ( ) . imageTypeExport )
683- ) {
684- exportImageType = this . preferenceService . getPreference ( ) . imageTypeExport ;
685- }
686- let _extension = '.webp' ;
687- if ( exportImageType === 'image/png' ) {
688- _extension = '.png' ;
689- } else if ( exportImageType === 'image/jpg' ) {
690- _extension = '.jpg' ;
691- }
692- const extension = _extension ;
693-
694- firstValueFrom ( this . questionService . getallcommentsandprediction4qId ( + this . qId ! ) ) . then ( res => {
695- const all = res ;
696- metadata ?. file ( 'metadata.json' , JSON . stringify ( all ) ) ;
711+ img ! . file ( 'reponse_' + q . numero + '_' + j + '_' + 1 + '_' + this . qId ! + '_' + sr . id ! + extension , content , { base64 : true } ) ;
712+ j ++ ;
713+ }
714+ zip . generateAsync ( { type : 'blob' } ) . then ( content => {
715+ FileSaver . saveAs ( content , 'Exam' + this . examId + '.zip' ) ;
716+ } ) ;
717+ }
718+ } else {
719+ let exportImageType = 'image/webp' ;
720+ if (
721+ this . preferenceService . getPreference ( ) . imageTypeExport !== undefined &&
722+ [ 'image/webp' , 'image/png' , 'image/jpg' ] . includes ( this . preferenceService . getPreference ( ) . imageTypeExport )
723+ ) {
724+ exportImageType = this . preferenceService . getPreference ( ) . imageTypeExport ;
725+ }
726+ let _extension = '.webp' ;
727+ if ( exportImageType === 'image/png' ) {
728+ _extension = '.png' ;
729+ } else if ( exportImageType === 'image/jpg' ) {
730+ _extension = '.jpg' ;
731+ }
732+ const extension = _extension ;
697733
698734 const obs = this . predictionStudentResponseService . downloadStudentResponsesFromQuestionIds ( + this . examId ! , + this . qId ! ) ;
699735 const ps : Promise < any > [ ] = [ ] ;
@@ -732,7 +768,7 @@ export class ComparestudentanswerComponent implements OnInit, AfterViewInit {
732768 ) ;
733769 } ) ;
734770 } ) ;
735- } ) ;
771+ }
736772 }
737773
738774 dragStart ( value : any ) : void {
0 commit comments