Skip to content
Snippets Groups Projects
document-viewer.component.ts 45.2 KiB
Newer Older
  • Learn to ignore specific revisions
  •                             arrValues.push({
                                    id: arrType.id,
                                    label: arrType.label,
                                    title: arrType.label,
                                    disabled: true,
                                    isTitle: true,
                                    color: '#135f7f'
                                });
                                data.templates.filter((template: any) => template.attachmentType === arrType.id).forEach((template: any) => {
                                    arrValues.push({
                                        id: template.id,
                                        label: '    ' + template.label,
    
                                        title: template.exists ? template.label : this.translate.instant('lang.fileDoesNotExists'),
    
                                        extension: template.extension,
                                        disabled: !template.exists,
                                    });
                                });
                            });
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
    
                            this.listTemplates = arrValues;
                        })
    
    Alex ORLUC's avatar
    Alex ORLUC committed
    
    
    
        closeEditor() {
            this.templateListForm.reset();
            this.editInProgress = false;
    
            this.isDocModified = false;
    
    
        setEditor() {
            if (this.headerService.user.preferences.documentEdition === 'java') {
                this.editor.mode = 'java';
    
                this.editor.async = true;
    
            } else if (this.headerService.user.preferences.documentEdition === 'onlyoffice') {
                this.editor.mode = 'onlyoffice';
    
                this.editor.async = false;
    
            } else if (this.headerService.user.preferences.documentEdition === 'collaboraonline') {
                this.editor.mode = 'collaboraOnline';
                this.editor.async = false;
    
                this.getFile().pipe(
                    map((data: any) => {
                        const formatdatas = {
                            encodedFile: data.content,
    
                            format: data.format,
                            resId: this.resId
    
                        };
                        return formatdatas;
                    }),
                    exhaustMap((data) => this.http.put(`../rest/resources/${this.resId}?onlyDocument=true`, data)),
                    tap(() => {
                        this.closeEditor();
                        this.loadRessource(this.resId);
                        resolve(true);
                    }),
    
                    finalize(() => this.loading = false),
    
                    catchError((err: any) => {
                        this.notify.handleSoftErrors(err);
                        resolve(false);
                        return of(false);
                    })
                ).subscribe();
    
            });
        }
    
        loadTmpDocument(base64Content: string, format: string) {
            return new Promise((resolve, reject) => {
    
                this.http.post(`../rest/convertedFile/encodedFile`, { format: format, encodedFile: base64Content }).pipe(
    
                    tap((data: any) => {
                        console.log(data);
                        this.file = {
                            name: 'maarch',
                            format: format,
                            type: 'application/pdf',
                            contentMode: 'base64',
                            content: base64Content,
                            src: this.base64ToArrayBuffer(data.encodedResource)
                        };
                    }),
    
                    // exhaustMap((data) => this.http.post(`../rest/convertedFile/encodedFile`, data.content)),
    
                    catchError((err: any) => {
                        this.notify.handleSoftErrors(err);
                        resolve(false);
                        return of(false);
                    })
                ).subscribe();
            });
        }
    
        saveTmpDocument() {
            return new Promise((resolve, reject) => {
                this.getFile().pipe(
                    tap((data: any) => {
                        this.file = {
                            name: 'maarch',
                            format: data.format,
                            type: 'application/pdf',
                            contentMode: 'base64',
                            content: data.content,
                            src: null
                        };
                    }),
    
                    exhaustMap((data) => this.http.post(`../rest/convertedFile/encodedFile`, { format: data.format, encodedFile: data.content })),
    
                    tap((data: any) => {
                        this.file.src = this.base64ToArrayBuffer(data.encodedResource);
                        this.closeEditor();
                        resolve(true);
                    }),
                    catchError((err: any) => {
                        this.notify.handleSoftErrors(err);
    
                        resolve(false);
                        return of(false);
                    })
                ).subscribe();
    
    
        openResourceVersion(version: number, type: string) {
    
            const title = type !== 'PDF' ? this.translate.instant('lang.' + type + '_version') : `${this.translate.instant('lang.version')} ${version}`;
    
    
            // TO SHOW ORIGINAL DOC (because autoload signed doc)
            type = type === 'SIGN' ? 'PDF' : type;
    
    
            this.http.get(`../rest/resources/${this.resId}/content/${version}?type=${type}`).pipe(
    
                    this.dialog.open(DocumentViewerModalComponent, { autoFocus: false, panelClass: 'maarch-full-height-modal', data: { title: `${title}`, base64: data.encodedDocument } });
    
                }),
                catchError((err: any) => {
                    this.notify.handleSoftErrors(err);
                    return of(false);
                })
            ).subscribe();
        }
    
    
        unsignMainDocument() {
    
            this.dialogRef = this.dialog.open(ConfirmComponent, { panelClass: 'maarch-modal', autoFocus: false, disableClose: true, data: { title: this.translate.instant('lang.UNSIGN'), msg: this.translate.instant('lang.confirmAction') } });
    
    
            this.dialogRef.afterClosed().pipe(
                filter((data: string) => data === 'ok'),
    
                exhaustMap(() => this.http.put(`../rest/resources/${this.resId}/unsign`, {})),
    
                    this.notify.success(this.translate.instant('lang.documentUnsigned'));
    
                    this.loadRessource(this.resId);
                }),
                catchError((err: any) => {
                    this.notify.handleErrors(err);
                    return of(false);
                })
            ).subscribe();
        }
    
    
        isEditorLoaded() {
            if (this.isEditingTemplate()) {
                return this.isEditingTemplate() && this.isDocModified;
            } else {
                return true;
            }
        }
    
    
        openMaarchParapheurWorkflow() {
            this.dialog.open(VisaWorkflowModalComponent, { panelClass: 'maarch-modal', data: { id: this.resId, type: 'resource' } });
        }