template-file-editor-modal.component.ts 2.63 KB
Newer Older
1
import { Component, OnInit, Inject, ViewChild } from '@angular/core';
2
import { TranslateService } from '@ngx-translate/core';
3
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
4
5
import { EcplOnlyofficeViewerComponent } from '@plugins/onlyoffice-api-js/onlyoffice-viewer.component';
import { CollaboraOnlineViewerComponent } from '@plugins/collabora-online/collabora-online-viewer.component';
6
import { take, tap } from 'rxjs/operators';
7
import { Office365SharepointViewerComponent } from '@plugins/office365-sharepoint/office365-sharepoint-viewer.component';
8
9
10
11
12
13
14

@Component({
    templateUrl: 'template-file-editor-modal.component.html',
    styleUrls: ['template-file-editor-modal.component.scss'],
})
export class TemplateFileEditorModalComponent implements OnInit {

15
16
    @ViewChild('onlyofficeViewer', { static: false }) onlyofficeViewer: EcplOnlyofficeViewerComponent;
    @ViewChild('collaboraOnlineViewer', { static: false }) collaboraOnlineViewer: CollaboraOnlineViewerComponent;
17
    @ViewChild('officeSharepointViewer', { static: false }) officeSharepointViewer: Office365SharepointViewerComponent;
18

19
20
21
    loading: boolean = false;
    editorOptions: any = null;
    file: any = null;
22
    editorType: any = null;
23
    documentIsModified: boolean = false;
24

25
    constructor(public translate: TranslateService, public dialogRef: MatDialogRef<TemplateFileEditorModalComponent>, @Inject(MAT_DIALOG_DATA) public data: any) { }
26
27
28
29

    ngOnInit(): void {
        this.editorOptions = this.data.editorOptions;
        this.file = this.data.file;
30
        this.editorType = this.data.editorType;
31
32
33
    }

    close() {
34
        this.loading = true;
35
36
37
38
        if (this.editorType === 'onlyoffice') {
            this.onlyofficeViewer.getFile().pipe(
                take(1),
                tap((data: any) => {
39
                    this.loading = false;
40
41
42
43
44
45
46
                    this.dialogRef.close(data);
                })
            ).subscribe();
        } else if (this.editorType === 'collaboraonline') {
            this.collaboraOnlineViewer.getFile().pipe(
                take(1),
                tap((data: any) => {
47
                    this.loading = false;
48
49
50
                    this.dialogRef.close(data);
                })
            ).subscribe();
51
52
53
54
55
56
57
58
        } else if (this.editorType === 'office365sharepoint') {
            this.officeSharepointViewer.getFile().pipe(
                take(1),
                tap((data: any) => {
                    this.loading = false;
                    this.dialogRef.close(data);
                })
            ).subscribe();
59
        } else {
60
            this.loading = false;
61
62
            this.dialogRef.close();
        }
63
64
    }
}