Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

feat(files): improve file handling with edit mode toggle, unsaved changes warning, enhanced modal logic, and updated constants

johavenbcc3ad28bd26
diff --git a/backend/src/applications/files/constants/only-office.ts b/backend/src/applications/files/constants/only-office.ts
index fe654b4b..134fa003 100644
--- a/backend/src/applications/files/constants/only-office.ts
+++ b/backend/src/applications/files/constants/only-office.ts
@@ -25,7 +25,6 @@ export const ONLY_OFFICE_EXTENSIONS = {
['html', 'word'],
['hwp', 'word'],
['hwpx', 'word'],
- ['md', 'word'],
['mht', 'word'],
['mhtml', 'word'],
['odt', 'word'],
@@ -36,7 +35,6 @@ export const ONLY_OFFICE_EXTENSIONS = {
['sxw', 'word'],
['wps', 'word'],
['wpt', 'word'],
- ['md', 'word'],
// CELL
['csv', 'cell'],
@@ -105,7 +103,6 @@ export const ONLY_OFFICE_EXTENSIONS = {
['odt', 'word'],
['ott', 'word'],
['rtf', 'word'],
- ['md', 'word'],
// CELL
['xlsb', 'cell'],
diff --git a/backend/src/applications/files/constants/operations.ts b/backend/src/applications/files/constants/operations.ts
index 7cc52724..4dffbaaf 100644
--- a/backend/src/applications/files/constants/operations.ts
+++ b/backend/src/applications/files/constants/operations.ts
@@ -16,3 +16,8 @@ export enum FILE_OPERATION {
TOUCH = 'touch',
THUMBNAIL = 'thumbnail'
}
+
+export enum FILE_MODE {
+ VIEW = 'view',
+ EDIT = 'edit'
+}
diff --git a/backend/src/applications/files/files-only-office.controller.spec.ts b/backend/src/applications/files/files-only-office.controller.spec.ts
index b792d807..630b60fb 100644
--- a/backend/src/applications/files/files-only-office.controller.spec.ts
+++ b/backend/src/applications/files/files-only-office.controller.spec.ts
@@ -8,6 +8,7 @@ import { Test, TestingModule } from '@nestjs/testing'
import { ContextInterceptor } from '../../infrastructure/context/interceptors/context.interceptor'
import { ContextManager } from '../../infrastructure/context/services/context-manager.service'
import { SpacesManager } from '../spaces/services/spaces-manager.service'
+import { FILE_MODE } from './constants/operations'
import { FilesOnlyOfficeController } from './files-only-office.controller'
import { FilesMethods } from './services/files-methods.service'
import { FilesOnlyOfficeManager } from './services/files-only-office-manager.service'
@@ -49,13 +50,13 @@ describe(FilesOnlyOfficeController.name, () => {
const user: any = { id: 1 }
const space: any = { id: 'space-1' }
const req: any = { headers: {}, params: {}, query: {} }
- const expected = { config: 'ok', mode: 'view' }
+ const expected = { config: 'ok', mode: FILE_MODE.VIEW }
filesOnlyOfficeManagerMock.getSettings.mockResolvedValue(expected)
const result = await controller.onlyOfficeSettings(user, space, undefined as any, req)
expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledTimes(1)
- expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, 'view', req)
+ expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, FILE_MODE.VIEW, req)
expect(result).toBe(expected)
})
@@ -63,12 +64,12 @@ describe(FilesOnlyOfficeController.name, () => {
const user: any = { id: 2 }
const space: any = { id: 'space-2' }
const req: any = { headers: { 'x-test': '1' } }
- const expected = { config: 'ok', mode: 'edit' }
+ const expected = { config: 'ok', mode: FILE_MODE.EDIT }
filesOnlyOfficeManagerMock.getSettings.mockResolvedValue(expected)
- const result = await controller.onlyOfficeSettings(user, space, 'edit', req)
+ const result = await controller.onlyOfficeSettings(user, space, FILE_MODE.EDIT, req)
- expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, 'edit', req)
+ expect(filesOnlyOfficeManagerMock.getSettings).toHaveBeenCalledWith(user, space, FILE_MODE.EDIT, req)
expect(result).toBe(expected)
})
})
diff --git a/backend/src/applications/files/files-only-office.controller.ts b/backend/src/applications/files/files-only-office.controller.ts
index 954777b4..77f79b37 100644
--- a/backend/src/applications/files/files-only-office.controller.ts
+++ b/backend/src/applications/files/files-only-office.controller.ts
@@ -13,6 +13,7 @@ import { FastifySpaceRequest } from '../spaces/interfaces/space-request.interfac
import { SpaceEnv } from '../spaces/models/space-env.model'
import { GetUser } from '../users/decorators/user.decorator'
import { UserModel } from '../users/models/user.model'
+import { FILE_MODE } from './constants/operations'
import { API_FILES_ONLY_OFFICE, FILES_ROUTE } from './constants/routes'
import { OnlyOfficeEnvironment } from './decorators/only-office-environment.decorator'
import { OnlyOfficeReqConfig } from './interfaces/only-office-config.interface'
@@ -32,7 +33,7 @@ export class FilesOnlyOfficeController {
onlyOfficeSettings(
@GetUser() user: UserModel,
@GetSpace() space: SpaceEnv,
- @Query('mode') mode: 'view' | 'edit' = 'view',
+ @Query('mode') mode: FILE_MODE = FILE_MODE.VIEW,
@Request() req: FastifySpaceRequest
): Promise<OnlyOfficeReqConfig> {
return this.filesOnlyOfficeManager.getSettings(user, space, mode, req)
diff --git a/backend/src/applications/files/guards/files-only-office.guard.ts b/backend/src/applications/files/guards/files-only-office.guard.ts
index f6b1b04f..5fec41ba 100644
--- a/backend/src/applications/files/guards/files-only-office.guard.ts
+++ b/backend/src/applications/files/guards/files-only-office.guard.ts
@@ -6,14 +6,21 @@
import { ExecutionContext, HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'
import { AuthGuard, IAuthGuard } from '@nestjs/passport'
+import { FastifyRequest } from 'fastify'
import { Observable } from 'rxjs'
import { configuration } from '../../../configuration/config.environment'
+import { API_FILES_ONLY_OFFICE_STATUS } from '../constants/routes'
@Injectable()
export class FilesOnlyOfficeGuard extends AuthGuard('filesOnlyOfficeToken') implements IAuthGuard {
private readonly logger = new Logger(FilesOnlyOfficeGuard.name)
canActivate(ctx: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
+ const req: FastifyRequest = ctx.switchToHttp().getRequest()
+ if (req.originalUrl === API_FILES_ONLY_OFFICE_STATUS) {
+ // Skip token validation for the status endpoint
+ return true
+ }
if (!configuration.applications.files.onlyoffice.enabled) {
this.logger.warn(`${this.canActivate.name} - feature not enabled`)
throw new HttpException('Feature not enabled', HttpStatus.BAD_REQUEST)
diff --git a/backend/src/applications/files/interfaces/only-office-config.interface.ts b/backend/src/applications/files/interfaces/only-office-config.interface.ts
index 69190b2f..fa7ad4af 100644
--- a/backend/src/applications/files/interfaces/only-office-config.interface.ts
+++ b/backend/src/applications/files/interfaces/only-office-config.interface.ts
@@ -4,6 +4,8 @@
* See the LICENSE file for licensing details
*/
+import { FILE_MODE } from '../constants/operations'
+
export interface OnlyOfficeReqConfig {
documentServerUrl: string
config: OnlyOfficeConfig
@@ -72,7 +74,7 @@ export interface OnlyOfficeConfig {
}
createUrl?: string
lang?: string
- mode?: 'view' | 'edit'
+ mode?: FILE_MODE
recent?: any[]
region?: string
templates?: any[]
diff --git a/backend/src/applications/files/services/files-only-office-manager.service.ts b/backend/src/applications/files/services/files-only-office-manager.service.ts
index 74c4a65f..869dcc5a 100644
--- a/backend/src/applications/files/services/files-only-office-manager.service.ts
+++ b/backend/src/applications/files/services/files-only-office-manager.service.ts
@@ -34,6 +34,7 @@ import {
ONLY_OFFICE_INTERNAL_URI,
ONLY_OFFICE_TOKEN_QUERY_PARAM_NAME
} from '../constants/only-office'
+import { FILE_MODE } from '../constants/operations'
import { API_FILES_ONLY_OFFICE_CALLBACK, API_FILES_ONLY_OFFICE_DOCUMENT } from '../constants/routes'
import type { FileProps } from '../interfaces/file-props.interface'
import { OnlyOfficeCallBack, OnlyOfficeConfig, OnlyOfficeConvertForm, OnlyOfficeReqConfig } from '../interfaces/only-office-config.interface'
@@ -63,7 +64,7 @@ export class FilesOnlyOfficeManager {
return { enabled: configuration.applications.files.onlyoffice.enabled }
}
- async getSettings(user: UserModel, space: SpaceEnv, mode: 'edit' | 'view', req: FastifySpaceRequest): Promise<OnlyOfficeReqConfig> {
+ async getSettings(user: UserModel, space: SpaceEnv, mode: FILE_MODE, req: FastifySpaceRequest): Promise<OnlyOfficeReqConfig> {
if (!(await isPathExists(space.realPath))) {
throw new HttpException('Document not found', HttpStatus.NOT_FOUND)
}
@@ -74,10 +75,10 @@ export class FilesOnlyOfficeManager {
if (!ONLY_OFFICE_EXTENSIONS.VIEWABLE.has(fileExtension) && !ONLY_OFFICE_EXTENSIONS.EDITABLE.has(fileExtension)) {
throw new HttpException('Document not supported', HttpStatus.BAD_REQUEST)
}
- if (mode === 'edit' && (!ONLY_OFFICE_EXTENSIONS.EDITABLE.has(fileExtension) || !haveSpaceEnvPermissions(space, SPACE_OPERATION.MODIFY))) {
- mode = 'view'
+ if (mode === FILE_MODE.EDIT && (!ONLY_OFFICE_EXTENSIONS.EDITABLE.has(fileExtension) || !haveSpaceEnvPermissions(space, SPACE_OPERATION.MODIFY))) {
+ mode = FILE_MODE.VIEW
}
- if (mode === 'edit') {
+ if (mode === FILE_MODE.EDIT) {
// check lock conflicts
try {
await this.filesLockManager.checkConflicts(space.dbFile, DEPTH.RESOURCE, { userId: user.id, lockScope: LOCK_SCOPE.SHARED })
@@ -144,7 +145,7 @@ export class FilesOnlyOfficeManager {
private async genConfiguration(
user: UserModel,
space: SpaceEnv,
- mode: 'edit' | 'view',
+ mode: FILE_MODE,
fileId: string,
fileUrl: string,
fileExtension: string,
@@ -165,12 +166,12 @@ export class FilesOnlyOfficeManager {
key: await this.getDocumentKey(fileId),
permissions: {
download: true,
- edit: mode === 'edit',
+ edit: mode === FILE_MODE.EDIT,
changeHistory: false,
comment: true,
fillForms: true,
print: true,
- review: mode === 'edit'
+ review: mode === FILE_MODE.EDIT
},
url: fileUrl
},
diff --git a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html
index 161470e1..93e6e23b 100644
--- a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html
+++ b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html
@@ -6,29 +6,36 @@
<div class="modal-header">
<h4 class="modal-title">
- <i class="fas fa-eye"></i>
- <span>{{ currentFile.name }}</span>
+ <fa-icon [icon]="isEditing ? icons.faPen : icons.faEye"></fa-icon>
+ <span class="ms-2">{{ currentFile.name }}</span>
</h4>
<button (click)="onMinimize()" aria-label="Minimize" class="btn-minimize btn-minimize-white" type="button"></button>
<button (click)="onClose()" aria-label="Close" class="btn-close btn-close-white ms-3" type="button"></button>
</div>
@if (currentFile) {
<div class="modal-body">
- @switch (shortMime) {
- @case ('image') {
+ @switch (hookedShortMime) {
+ @case (SHORT_MIME.IMAGE) {
<app-files-viewer-image [currentHeight]="currentHeight" [(file)]="currentFile" [directoryImages]="directoryImages()"></app-files-viewer-image>
}
- @case ('pdf') {
+ @case (SHORT_MIME.PDF) {
<app-files-viewer-pdf [currentHeight]="currentHeight" [fileUrl]="currentFile.dataUrl"></app-files-viewer-pdf>
}
- @case ('media') {
+ @case (SHORT_MIME.MEDIA) {
<app-files-viewer-media [currentHeight]="currentHeight" [fileUrl]="currentFile.dataUrl"></app-files-viewer-media>
}
- @case ('document') {
+ @case (SHORT_MIME.DOCUMENT) {
<app-files-viewer-document [currentHeight]="currentHeight" [file]="currentFile" [mode]="mode"></app-files-viewer-document>
}
@default {
- <app-files-viewer-text [currentHeight]="currentHeight" [file]="currentFile" [mode]="mode"></app-files-viewer-text>
+ <app-files-viewer-text
+ [currentHeight]="currentHeight"
+ [file]="currentFile"
+ [mode]="mode"
+ [isWriteable]="isWriteable"
+ [modalClosing]="modalClosing()"
+ (readonlyChange)="onReadonlyChange($event)">
+ </app-files-viewer-text>
}
}
</div>
diff --git a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts
index 52785751..db8ba868 100644
--- a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts
+++ b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts
@@ -4,9 +4,13 @@
* See the LICENSE file for licensing details
*/
-import { Component, computed, inject, Input, OnDestroy, OnInit } from '@angular/core'
+import { Component, computed, inject, Input, OnDestroy, OnInit, signal } from '@angular/core'
+import { FaIconComponent } from '@fortawesome/angular-fontawesome'
+import { faEye, faPen } from '@fortawesome/free-solid-svg-icons'
+import { FILE_MODE } from '@sync-in-server/backend/src/applications/files/constants/operations'
import { Subscription } from 'rxjs'
import { LayoutService } from '../../../../layout/layout.service'
+import { SHORT_MIME } from '../../files.constants'
import { FileModel } from '../../models/file.model'
import { FilesViewerDocumentComponent } from '../viewers/files-viewer-document.component'
import { FilesViewerImageComponent } from '../viewers/files-viewer-image.component'
@@ -16,15 +20,27 @@ import { FilesViewerTextComponent } from '../viewers/files-viewer-text.component
@Component({
selector: 'app-files-viewer-dialog',
- imports: [FilesViewerPdfComponent, FilesViewerMediaComponent, FilesViewerTextComponent, FilesViewerDocumentComponent, FilesViewerImageComponent],
+ imports: [
+ FilesViewerPdfComponent,
+ FilesViewerMediaComponent,
+ FilesViewerTextComponent,
+ FilesViewerDocumentComponent,
+ FilesViewerImageComponent,
+ FaIconComponent
+ ],
templateUrl: 'files-viewer-dialog.component.html'
})
export class FilesViewerDialogComponent implements OnInit, OnDestroy {
@Input({ required: true }) currentFile: FileModel
@Input({ required: true }) directoryFiles: FileModel[]
- @Input({ required: true }) mode: 'view' | 'edit'
- @Input({ required: true }) shortMime: string
+ @Input({ required: true }) mode: FILE_MODE
+ @Input({ required: true }) isWriteable: boolean
+ @Input({ required: true }) hookedShortMime: string
+ modalClosing = signal<boolean>(false)
+ protected isEditing = false
protected currentHeight: number
+ protected readonly SHORT_MIME = SHORT_MIME
+ protected readonly icons = { faEye, faPen }
protected directoryImages = computed(() => this.directoryFiles.filter((file) => file.isImage))
private openedFile: { id: string | number; name: string; mimeUrl: string }
private readonly layout = inject(LayoutService)
@@ -32,6 +48,7 @@ export class FilesViewerDialogComponent implements OnInit, OnDestroy {
private readonly offsetTop = 42
ngOnInit() {
+ this.isEditing = this.mode === FILE_MODE.EDIT
this.openedFile = { id: this.currentFile.id, name: this.currentFile.name, mimeUrl: this.currentFile.mimeUrl }
this.onResize()
}
@@ -41,13 +58,24 @@ export class FilesViewerDialogComponent implements OnInit, OnDestroy {
}
onClose() {
- this.layout.closeDialog(null, this.openedFile.id)
+ if (this.currentFile.isEditable && this.hookedShortMime === SHORT_MIME.TEXT) {
+ // Prevent closing the modal without saving when using the text editor
+ this.modalClosing.set(true)
+ // Force the next state change
+ setTimeout(() => this.modalClosing.set(false), 1000)
+ } else {
+ this.layout.closeDialog(null, this.openedFile.id)
+ }
}
onMinimize() {
this.layout.minimizeDialog(this.openedFile.id, { name: this.openedFile.name, mimeUrl: this.openedFile.mimeUrl })
}
+ onReadonlyChange(state: boolean) {
+ this.isEditing = !state
+ }
+
private onResize() {
this.currentHeight = window.innerHeight - this.offsetTop
}
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-document.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-document.component.ts
index 968dfc65..cd8887ec 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-document.component.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-document.component.ts
@@ -6,6 +6,7 @@
import { HttpClient, HttpParams } from '@angular/common/http'
import { Component, inject, input, Input, OnDestroy, OnInit } from '@angular/core'
+import { FILE_MODE } from '@sync-in-server/backend/src/applications/files/constants/operations'
import { API_FILES_ONLY_OFFICE_SETTINGS } from '@sync-in-server/backend/src/applications/files/constants/routes'
import { OnlyOfficeReqConfig } from '@sync-in-server/backend/src/applications/files/interfaces/only-office-config.interface'
import { SERVER_NAME } from '@sync-in-server/backend/src/common/shared'
@@ -40,7 +41,7 @@ import { OnlyOfficeComponent } from '../utils/only-office.component'
})
export class FilesViewerDocumentComponent implements OnInit, OnDestroy {
@Input({ required: true }) file: FileModel
- @Input({ required: true }) mode: 'view' | 'edit'
+ @Input({ required: true }) mode: FILE_MODE
currentHeight = input<number>()
protected docId: string
protected documentConfig: OnlyOfficeReqConfig = null
@@ -60,12 +61,12 @@ export class FilesViewerDocumentComponent implements OnInit, OnDestroy {
return
}
// do not allow edit if backend only allow 'view' mode
- if (this.mode === 'edit' && data.config.editorConfig.mode !== 'edit') {
- data.config.editorConfig.mode = 'view'
+ if (this.mode === FILE_MODE.EDIT && data.config.editorConfig.mode !== FILE_MODE.EDIT) {
+ data.config.editorConfig.mode = FILE_MODE.VIEW
} else {
data.config.editorConfig.mode = this.mode
}
- if (this.mode === 'edit') {
+ if (this.mode === FILE_MODE.EDIT) {
// set lock on file
this.file.lock = {
owner: `${SERVER_NAME} - ${this.store.user.getValue().fullName} (${this.store.user.getValue().email})`,
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html
index 91c65e81..88ff01f2 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html
@@ -8,21 +8,20 @@
<div class="app-top-menu">
<button
(click)="toggleReadonly()"
- [tooltip]="(isReadonly() ? 'Read-only' : 'Read-write') | translate:locale.language"
+ [tooltip]="(isReadonly() || !isWriteable() ? 'Read-only' : 'Read-write') | translate:locale.language"
[adaptivePosition]="true"
- container="body"
class="d-none d-sm-block btn btn-sm btn-secondary me-1"
type="button"
- [disabled]="!isReadable()">
+ [disabled]="!isReadable() || !isWriteable()">
<fa-icon [icon]="isReadonly() ? icons.faLock : icons.faLockOpen"></fa-icon>
</button>
<button
(click)="save()"
- [tooltip]="'Save' | translate:locale.language"
- container="body"
+ [tooltip]="(isReadonly() || !isWriteable() || !isModified() ? null : 'Save') | translate:locale.language"
+ [isDisabled]="isReadonly() || !isWriteable() || !isModified()"
class="d-none d-sm-block btn btn-sm btn-secondary me-1"
type="button"
- [disabled]="isReadonly() || !isModified()">
+ [disabled]="isReadonly() || !isWriteable() || !isModified()">
@if (isSaving()) {
<fa-icon [icon]="icons.faSpinner" animation="spin"></fa-icon>
} @else {
@@ -34,22 +33,38 @@
[ngModel]="lineWrapping()"
(ngModelChange)="lineWrapping.set($event)"
[tooltip]="'Line Wrap' | translate:locale.language"
- container="body"
class="d-none d-sm-block btn btn-sm btn-custom me-1"
- type="button">
+ type="button"
+ [disabled]="!isReadable()">
<fa-icon [icon]="icons.faArrowsLeftRightToLine"></fa-icon>
</button>
<button
btnCheckbox
- [ngModel]="isSearchPanelOpen"
+ [ngModel]="isSearchPanelOpen()"
(ngModelChange)="toggleSearch()"
[tooltip]="'Search' | translate:locale.language"
- container="body"
class="d-none d-sm-block btn btn-sm btn-custom"
type="button"
[disabled]="!isReadable()">
<fa-icon [icon]="icons.faMagnifyingGlass"></fa-icon>
</button>
+ @if (warnOnUnsavedChanges()) {
+ <button (click)="save(true)"
+ class="btn btn-sm btn-primary me-2 ms-auto"
+ type="button"
+ l10nTranslate>Save And Exit
+ </button>
+ <button (click)="layout.closeDialog()"
+ class="btn btn-sm btn-danger me-2"
+ data-dismiss="modal" type="button"
+ l10nTranslate>Close Without Saving
+ </button>
+ <button (click)="warnOnUnsavedChanges.set(false)"
+ class="btn btn-sm btn-secondary"
+ data-dismiss="modal" type="button"
+ l10nTranslate>Cancel
+ </button>
+ }
</div>
<code-editor
#editor
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts
index 09e3c7ce..11a8a8bd 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts
@@ -6,17 +6,32 @@
import { CodeEditor } from '@acrodata/code-editor'
import { HttpClient, HttpErrorResponse } from '@angular/common/http'
-import { Component, HostListener, inject, input, linkedSignal, OnDestroy, OnInit, signal, viewChild, ViewEncapsulation } from '@angular/core'
+import {
+ Component,
+ effect,
+ HostListener,
+ inject,
+ input,
+ linkedSignal,
+ OnDestroy,
+ OnInit,
+ output,
+ signal,
+ untracked,
+ viewChild,
+ ViewEncapsulation
+} from '@angular/core'
import { FormsModule } from '@angular/forms'
import { LanguageDescription } from '@codemirror/language'
import { languages } from '@codemirror/language-data'
import { closeSearchPanel, openSearchPanel } from '@codemirror/search'
import { FaIconComponent } from '@fortawesome/angular-fontawesome'
import { faArrowsLeftRightToLine, faFloppyDisk, faLock, faLockOpen, faMagnifyingGlass, faSpinner } from '@fortawesome/free-solid-svg-icons'
-import { L10N_LOCALE, L10nLocale, L10nTranslatePipe } from 'angular-l10n'
+import { FILE_MODE } from '@sync-in-server/backend/src/applications/files/constants/operations'
+import { L10N_LOCALE, L10nLocale, L10nTranslateDirective, L10nTranslatePipe } from 'angular-l10n'
import { ButtonCheckboxDirective } from 'ngx-bootstrap/buttons'
import { TooltipModule } from 'ngx-bootstrap/tooltip'
-import { themeDark } from '../../../../layout/layout.interfaces'
+import { AppWindow, themeDark } from '../../../../layout/layout.interfaces'
import { LayoutService } from '../../../../layout/layout.service'
import { FileModel } from '../../models/file.model'
import { FilesUploadService } from '../../services/files-upload.service'
@@ -24,7 +39,7 @@ import { FilesUploadService } from '../../services/files-upload.service'
@Component({
selector: 'app-files-viewer-text',
encapsulation: ViewEncapsulation.None,
- imports: [CodeEditor, TooltipModule, FormsModule, FaIconComponent, L10nTranslatePipe, ButtonCheckboxDirective],
+ imports: [CodeEditor, TooltipModule, FormsModule, FaIconComponent, L10nTranslatePipe, ButtonCheckboxDirective, L10nTranslateDirective],
styles: [
`
.code-editor {
@@ -46,8 +61,7 @@ import { FilesUploadService } from '../../services/files-upload.service'
}
button[aria-label='close'] {
- right: 10px !important;
- font-size: 18px !important;
+ display: none;
}
}
`
@@ -56,14 +70,18 @@ import { FilesUploadService } from '../../services/files-upload.service'
})
export class FilesViewerTextComponent implements OnInit, OnDestroy {
editor = viewChild<CodeEditor>('editor')
- currentHeight = input<number>()
- file = input<FileModel>()
- mode = input<'view' | 'edit'>('view')
- protected isReadonly = linkedSignal(() => this.mode() === 'view')
+ currentHeight = input.required<number>()
+ file = input.required<FileModel>()
+ mode = input.required<FILE_MODE>()
+ isWriteable = input.required<boolean>()
+ modalClosing = input.required<boolean>()
+ readonlyChange = output<boolean>()
+ protected isReadonly = linkedSignal(() => this.mode() === FILE_MODE.VIEW)
protected isReadable = signal(false)
protected isModified = signal(false)
protected isSaving = signal(false)
protected lineWrapping = signal(false)
+ protected warnOnUnsavedChanges = signal(false)
protected content: string
protected currentLanguage = undefined
protected readonly languages: LanguageDescription[] = languages
@@ -71,13 +89,34 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
protected readonly icons = { faFloppyDisk, faLock, faLockOpen, faMagnifyingGlass, faSpinner, faArrowsLeftRightToLine }
protected readonly locale = inject<L10nLocale>(L10N_LOCALE)
protected isSearchPanelOpen = signal(false)
+ protected readonly layout = inject(LayoutService)
private isContentReady = false
- private readonly layout = inject(LayoutService)
private readonly http = inject(HttpClient)
private readonly filesUpload = inject(FilesUploadService)
private subscription = this.layout.switchTheme.subscribe((layout: string) => (this.currentTheme = layout === themeDark ? 'dark' : 'light'))
private readonly maxSize = 5242880 // 5MB
+ constructor() {
+ effect(() => {
+ // Only track modalClosing
+ if (!this.modalClosing()) return
+ const fileId = untracked(() => this.file().id)
+ const modified = untracked(() => this.isModified()) // ignore dependency on isModified
+ if (modified) {
+ this.warnOnUnsavedChanges.set(true)
+ // restore dialog if minimized
+ if (this.layout.windows.getValue().find((w: AppWindow) => w.id === fileId)) {
+ this.layout.restoreDialog(fileId)
+ }
+ } else {
+ this.layout.closeDialog(null, fileId)
+ }
+ })
+ effect(() => {
+ this.readonlyChange.emit(this.isReadonly())
+ })
+ }
+
@HostListener('document:keydown', ['$event'])
onKeyDown(event: KeyboardEvent) {
// ESC
@@ -86,9 +125,12 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
if (this.isSearchPanelOpen()) {
event.stopPropagation()
this.toggleSearch()
+ } else if (this.warnOnUnsavedChanges()) {
+ event.stopPropagation()
+ this.warnOnUnsavedChanges.set(false)
} else if (this.isModified()) {
event.stopPropagation()
- // Show dialog alert
+ this.warnOnUnsavedChanges.set(true)
}
return
}
@@ -121,7 +163,7 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
}
toggleReadonly() {
- this.isReadonly.set(!this.isReadonly())
+ this.isReadonly.update((state) => !state)
// Reset search state when open to enable/disable the replace function
if (this.isSearchPanelOpen()) {
setTimeout(() => {
@@ -131,12 +173,16 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
}
}
- save() {
+ save(exit = false) {
this.isSaving.set(true)
this.filesUpload.uploadOneFile(this.file(), this.content, true).subscribe({
next: () => {
this.isModified.set(false)
this.isSaving.set(false)
+ this.warnOnUnsavedChanges.set(false)
+ if (exit) {
+ this.layout.closeDialog(null, this.file().id)
+ }
},
error: (e: HttpErrorResponse) => {
this.isSaving.set(false)
diff --git a/frontend/src/app/applications/files/files.constants.ts b/frontend/src/app/applications/files/files.constants.ts
index cc759c5f..a4af4458 100644
--- a/frontend/src/app/applications/files/files.constants.ts
+++ b/frontend/src/app/applications/files/files.constants.ts
@@ -23,8 +23,15 @@ export const logoDarkUrl = `${assetsUrl}/logo-dark${mimeExtension}`
export const logoUrl = `${assetsUrl}/logo${mimeExtension}`
export const linkProtected = `${assetsUrl}/protected.png`
export const defaultMimeUrl = getAssetsMimeUrl(mimeFile)
-export const compressibleMimes = new Set(['application-gzip', 'application-zip', 'application-x-tar'])
-export const notViewableExtensions = new Set([
+export const COMPRESSIBLE_MIMES = new Set(['application-gzip', 'application-zip', 'application-x-tar'])
+export const SHORT_MIME = {
+ DOCUMENT: 'document',
+ TEXT: 'text',
+ IMAGE: 'image',
+ MEDIA: 'media',
+ PDF: 'pdf'
+} as const
+export const UNSUPPORTED_VIEW_EXTENSIONS = new Set([
'rar',
'7z',
'iso',
diff --git a/frontend/src/app/applications/files/models/file.model.ts b/frontend/src/app/applications/files/models/file.model.ts
index 650609df..f2a859e9 100644
--- a/frontend/src/app/applications/files/models/file.model.ts
+++ b/frontend/src/app/applications/files/models/file.model.ts
@@ -22,13 +22,14 @@ import { setTextIconPermissions } from '../../spaces/spaces.functions'
import type { OwnerType } from '../../users/interfaces/owner.interface'
import { userAvatarUrl } from '../../users/user.functions'
import {
- compressibleMimes,
+ COMPRESSIBLE_MIMES,
defaultMimeUrl,
getAssetsMimeUrl,
mimeDirectory,
mimeDirectoryShare,
mimeFile,
- notViewableExtensions
+ SHORT_MIME,
+ UNSUPPORTED_VIEW_EXTENSIONS
} from '../files.constants'
export class FileModel implements File {
@@ -66,7 +67,7 @@ export class FileModel implements File {
comments: CommentModel[]
// Computed
- shortMime: string
+ shortMime: (typeof SHORT_MIME)[keyof typeof SHORT_MIME]
mimeUrl: string
hSize: string
hTimeAgo: string
@@ -131,44 +132,41 @@ export class FileModel implements File {
this.isViewable = false
return this.getType(inShare)
} else if (mime) {
- const mimeArray = mime.split('-')
- const longMime = mimeArray[mimeArray.length - 1]
+ const temporaryMime = mime.split('-')[0]
const extension = this.name.split('.').pop().toLowerCase()
- this.shortMime = mimeArray[0]
-
- if (extension === 'pdf') {
- // uses pdfjs for reading and onlyoffice for writing, this test should be placed first
- this.shortMime = longMime
+ if (extension === SHORT_MIME.PDF) {
+ this.shortMime = SHORT_MIME.PDF
this.isViewable = true
this.isEditable = ONLY_OFFICE_EXTENSIONS.EDITABLE.has(extension)
} else if (ONLY_OFFICE_EXTENSIONS.EDITABLE.has(extension) || ONLY_OFFICE_EXTENSIONS.VIEWABLE.has(extension)) {
- this.shortMime = 'document'
+ this.shortMime = SHORT_MIME.DOCUMENT
this.isEditable = ONLY_OFFICE_EXTENSIONS.EDITABLE.has(extension)
this.isViewable = this.isEditable || ONLY_OFFICE_EXTENSIONS.VIEWABLE.has(extension)
} else if (extension === 'mp4') {
this.isViewable = true
- this.shortMime = 'media'
+ this.shortMime = SHORT_MIME.MEDIA
this.haveThumbnail = true
- } else if (this.shortMime === 'image') {
+ } else if (temporaryMime === SHORT_MIME.IMAGE) {
+ this.shortMime = SHORT_MIME.IMAGE
this.isImage = true
this.isViewable = true
this.haveThumbnail = true
- } else if (['video', 'audio'].indexOf(this.shortMime) > -1) {
- this.shortMime = 'media'
+ } else if (['video', 'audio'].indexOf(temporaryMime) > -1) {
+ this.shortMime = SHORT_MIME.MEDIA
this.isViewable = true
this.haveThumbnail = true
- } else if (compressibleMimes.has(mime)) {
+ } else if (COMPRESSIBLE_MIMES.has(mime)) {
this.isCompressible = false
this.isViewable = false
- } else if (!notViewableExtensions.has(extension)) {
+ } else if (!UNSUPPORTED_VIEW_EXTENSIONS.has(extension)) {
this.isViewable = true
this.isEditable = true
- this.shortMime = 'text'
+ this.shortMime = SHORT_MIME.TEXT
}
return mime
} else {
this.isViewable = true
- this.shortMime = 'text'
+ this.shortMime = SHORT_MIME.TEXT
return this.getType(inShare)
}
}
diff --git a/frontend/src/app/applications/files/services/files.service.ts b/frontend/src/app/applications/files/services/files.service.ts
index 0a0d0feb..b81779e8 100644
--- a/frontend/src/app/applications/files/services/files.service.ts
+++ b/frontend/src/app/applications/files/services/files.service.ts
@@ -8,7 +8,7 @@ import type { TreeNode } from '@ali-hm/angular-tree-component'
import { HttpClient, HttpErrorResponse, HttpParams } from '@angular/common/http'
import { inject, Injectable } from '@angular/core'
import { DomSanitizer } from '@angular/platform-browser'
-import { FILE_OPERATION } from '@sync-in-server/backend/src/applications/files/constants/operations'
+import { FILE_MODE, FILE_OPERATION } from '@sync-in-server/backend/src/applications/files/constants/operations'
import {
API_FILES_ONLY_OFFICE_STATUS,
API_FILES_OPERATION_MAKE,
@@ -31,6 +31,7 @@ import type { FileTask } from '@sync-in-server/backend/src/applications/files/mo
import type { FileContent } from '@sync-in-server/backend/src/applications/files/schemas/file-content.interface'
import type { FileRecent } from '@sync-in-server/backend/src/applications/files/schemas/file-recent.interface'
import { API_SPACES_TREE } from '@sync-in-server/backend/src/applications/spaces/constants/routes'
+import { SPACE_OPERATION } from '@sync-in-server/backend/src/applications/spaces/constants/spaces'
import { forbiddenChars, isValidFileName } from '@sync-in-server/backend/src/common/shared'
import { BsModalRef } from 'ngx-bootstrap/modal'
import { EMPTY, firstValueFrom, map, Observable, Subject } from 'rxjs'
@@ -40,6 +41,7 @@ import { LayoutService } from '../../../layout/layout.service'
import { StoreService } from '../../../store/store.service'
import { FilesOverwriteDialogComponent } from '../components/dialogs/files-overwrite-dialog.component'
import { FilesViewerDialogComponent } from '../components/dialogs/files-viewer-dialog.component'
+import { SHORT_MIME } from '../files.constants'
import { FileContentModel } from '../models/file-content.model'
import { FileRecentModel } from '../models/file-recent.model'
import { FileModel } from '../models/file.model'
@@ -225,24 +227,29 @@ export class FilesService {
})
}
- async openViewerDialog(mode: 'view' | 'edit', currentFile: FileModel, directoryFiles: FileModel[]) {
+ async openViewerDialog(mode: FILE_MODE, currentFile: FileModel, directoryFiles: FileModel[], permissions: string) {
this.http.head(currentFile.dataUrl).subscribe({
next: async () => {
- let shortMime: string
+ let hookedShortMime: string
try {
- shortMime = await this.viewerHook(mode, currentFile)
+ hookedShortMime = await this.viewerHook(mode, currentFile)
} catch {
// OnlyOffice isn't enabled, falling back to download
this.download(currentFile)
return
}
+ const isWriteable = permissions.indexOf(SPACE_OPERATION.MODIFY) > -1
+ if (mode === FILE_MODE.EDIT && !isWriteable) {
+ mode = FILE_MODE.VIEW
+ }
this.layout.openDialog(FilesViewerDialogComponent, 'full', {
id: currentFile.id, // only used to manage the modal
initialState: {
currentFile: currentFile,
directoryFiles: directoryFiles,
mode: mode,
- shortMime: shortMime
+ isWriteable: isWriteable,
+ hookedShortMime: hookedShortMime
} satisfies Partial<FilesViewerDialogComponent>
})
},
@@ -253,17 +260,17 @@ export class FilesService {
})
}
- private async viewerHook(mode: 'view' | 'edit', currentFile: FileModel): Promise<string> {
+ private async viewerHook(mode: FILE_MODE, currentFile: FileModel): Promise<string> {
const onlyOfficeEnabled = await this.getOnlyOfficeStatus()
- if (currentFile.shortMime === 'document' && !onlyOfficeEnabled) {
+ if (currentFile.shortMime === SHORT_MIME.DOCUMENT && !onlyOfficeEnabled) {
if (currentFile.mime.startsWith('text-')) {
- return 'text'
+ return SHORT_MIME.TEXT
}
throw new Error('Feature not enabled')
}
- if (currentFile.shortMime === 'pdf') {
- if (mode === 'edit' && onlyOfficeEnabled) {
- return 'document'
+ if (currentFile.shortMime === SHORT_MIME.PDF) {
+ if (mode === FILE_MODE.EDIT && onlyOfficeEnabled) {
+ return SHORT_MIME.DOCUMENT
}
}
return currentFile.shortMime
@@ -275,7 +282,6 @@ export class FilesService {
}
try {
const status = await firstValueFrom(this.http.get<{ enabled: boolean }>(API_FILES_ONLY_OFFICE_STATUS))
- // if the request succeeds, "enabled" will always be true
this.store.filesOnlyOffice.set(status)
return status.enabled
} catch {
diff --git a/frontend/src/app/applications/spaces/components/spaces-browser.component.ts b/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
index 15155375..f14bc03f 100644
--- a/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
+++ b/frontend/src/app/applications/spaces/components/spaces-browser.component.ts
@@ -36,7 +36,7 @@ import {
} from '@fortawesome/free-solid-svg-icons'
import { ContextMenuComponent, ContextMenuModule } from '@perfectmemory/ngx-contextmenu'
import { tarExtension } from '@sync-in-server/backend/src/applications/files/constants/compress'
-import { FILE_OPERATION } from '@sync-in-server/backend/src/applications/files/constants/operations'
+import { FILE_MODE, FILE_OPERATION } from '@sync-in-server/backend/src/applications/files/constants/operations'
import type { CompressFileDto } from '@sync-in-server/backend/src/applications/files/dto/file-operations.dto'
import type { FileProps } from '@sync-in-server/backend/src/applications/files/interfaces/file-props.interface'
import type { FileSpace } from '@sync-in-server/backend/src/applications/files/interfaces/file-space.interface'
@@ -439,9 +439,9 @@ export class SpacesBrowserComponent implements OnInit, AfterViewInit, OnDestroy
if (this.selection[0].isDir) {
this.browse(this.selection[0])
} else if (editMode && this.selection[0].isEditable) {
- this.openViewerDialog('edit')
+ this.openViewerDialog(FILE_MODE.EDIT)
} else if (this.selection[0].isViewable) {
- this.openViewerDialog('view')
+ this.openViewerDialog(FILE_MODE.VIEW)
} else {
this.downloadFiles()
}
@@ -452,7 +452,7 @@ export class SpacesBrowserComponent implements OnInit, AfterViewInit, OnDestroy
this.layout.sendNotification('info', 'The file is locked', this.selection[0].lock.owner)
return
}
- this.openViewerDialog('edit')
+ this.openViewerDialog(FILE_MODE.EDIT)
}
shortcutUploadFiles() {
@@ -723,8 +723,9 @@ export class SpacesBrowserComponent implements OnInit, AfterViewInit, OnDestroy
return f
}
- private openViewerDialog(mode: 'view' | 'edit') {
- this.filesService.openViewerDialog(mode, this.selection[0], this.files).catch(console.error)
+ private openViewerDialog(mode: FILE_MODE) {
+ const permissions = this.selection[0]?.root ? this.selection[0].root.permissions : this.spacePermissions
+ this.filesService.openViewerDialog(mode, this.selection[0], this.files, permissions).catch(console.error)
}
private focusOn(selectName: string) {
diff --git a/frontend/src/app/layout/layout.interfaces.ts b/frontend/src/app/layout/layout.interfaces.ts
index 04126f2e..d0dd217c 100644
--- a/frontend/src/app/layout/layout.interfaces.ts
+++ b/frontend/src/app/layout/layout.interfaces.ts
@@ -60,6 +60,6 @@ export interface TabMenu {
}
export interface AppWindow {
- id: any
+ id: number | string
element: { name: string; mimeUrl: string }
}
diff --git a/frontend/src/app/layout/layout.service.ts b/frontend/src/app/layout/layout.service.ts
index 72f56831..3797adbd 100644
--- a/frontend/src/app/layout/layout.service.ts
+++ b/frontend/src/app/layout/layout.service.ts
@@ -11,7 +11,7 @@ import { FaConfig } from '@fortawesome/angular-fontawesome'
import { IconDefinition } from '@fortawesome/fontawesome-svg-core'
import { ContextMenuComponent, ContextMenuService } from '@perfectmemory/ngx-contextmenu'
import { L10nTranslationService } from 'angular-l10n'
-import { BsModalRef, BsModalService, ModalOptions } from 'ngx-bootstrap/modal'
+import { BsModalRef, BsModalService, ModalContainerComponent, ModalOptions } from 'ngx-bootstrap/modal'
import { setTheme } from 'ngx-bootstrap/utils'
import { ActiveToast, ToastrService } from 'ngx-toastr'
import { BehaviorSubject, fromEvent, mergeWith, Observable, Subject } from 'rxjs'
@@ -27,6 +27,10 @@ import { AppWindow, TAB_GROUP, TAB_MENU, TabMenu, themeDark, themeLight } from '
declare const window: any
+interface ModalComponent extends ModalContainerComponent {
+ id: string | number
+}
+
@Injectable({ providedIn: 'root' })
export class LayoutService {
public currentRightSideBarTab: string | null = null
@@ -52,7 +56,10 @@ export class LayoutService {
public breadcrumbNav = new BehaviorSubject<BreadCrumbUrl>({ url: '' })
// Navigation breadcrumb icon
public breadcrumbIcon = new BehaviorSubject<IconDefinition>(null)
- public minimizedWindows = new BehaviorSubject<AppWindow[]>([])
+ // Modal section
+ public windows = new BehaviorSubject<AppWindow[]>([]) // minimized modals
+ public modalRefs = new Map<number | string, BsModalRef>()
+ // Services
private readonly title = inject(Title)
private readonly ngZone = inject(NgZone)
private readonly translation = inject(L10nTranslationService)
@@ -72,9 +79,7 @@ export class LayoutService {
private preferTheme = fromEvent(window.matchMedia('(prefers-color-scheme: dark)'), 'change').pipe(
map((e: any) => (e.matches ? themeDark : themeLight))
)
- // Modal section
- private modalIds = new Set<number | string>()
- private readonly dialogConfig: ModalOptions = {
+ private readonly modalOptions: ModalOptions = {
animated: true,
keyboard: true,
backdrop: true,
@@ -134,34 +139,35 @@ export class LayoutService {
openDialog(dialog: any, size: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full', componentState: any = {}, override: ModalOptions = {}): BsModalRef {
const dialogClass = `modal-${size || 'sm'} modal-primary`
- if (componentState.id && this.minimizedWindows.getValue().find((w: AppWindow) => w.id === componentState.id)) {
- return this.restoreDialog(componentState.id)
+ if (componentState.id && this.windows.getValue().find((w: AppWindow) => w.id === componentState.id)) {
+ this.restoreDialog(componentState.id)
+ return this.modalRefs.get(componentState.id)
}
- const state: ModalOptions = Object.assign(componentState, { ...this.dialogConfig, ...override }, { class: dialogClass })
+ const state: ModalOptions = Object.assign(componentState, { ...this.modalOptions, ...override }, { class: dialogClass })
const modalRef = this.bsModal.show(dialog, state)
- this.modalIds.add(modalRef.id)
+ this.modalRefs.set(modalRef.id, modalRef)
return modalRef
}
- minimizeDialog(modalId: any, element: { name: string; mimeUrl: string }): BsModalRef<unknown> {
- const modal = this.getModal(modalId)
+ minimizeDialog(modalId: any, element: { name: string; mimeUrl: string }): ModalComponent {
+ const modal = this.getModalComponent(modalId)
if (modal) {
this.closeModalWithEffect(modal)
- if (!this.minimizedWindows.getValue().find((m: AppWindow) => m.id === modalId)) {
- this.minimizedWindows.next([...this.minimizedWindows.getValue(), { id: modalId, element }])
+ if (!this.windows.getValue().find((m: AppWindow) => m.id === modalId)) {
+ this.windows.next([...this.windows.getValue(), { id: modalId, element }])
}
- if (this.minimizedWindows.getValue().length === 1) {
+ if (this.windows.getValue().length === 1) {
this.showRSideBarTab(TAB_MENU.WINDOWS, false, 3000)
}
}
return modal
}
- restoreDialog(modalId: any): BsModalRef<unknown> {
- const modal: BsModalRef<unknown> = this.getModal(modalId)
+ restoreDialog(modalId: any): ModalComponent {
+ const modal = this.getModalComponent(modalId)
if (modal) {
this.openModalWithEffect(modal)
- this.minimizedWindows.next(this.minimizedWindows.getValue().filter((m: AppWindow) => m.id !== modalId))
+ this.windows.next(this.windows.getValue().filter((m: AppWindow) => m.id !== modalId))
}
return modal
}
@@ -169,14 +175,14 @@ export class LayoutService {
closeDialog(delay: number | null = null, id: number | string = null, all = false) {
if (all) {
this.bsModal.hide()
- this.modalIds.clear()
- this.minimizedWindows.next([])
+ this.modalRefs.clear()
+ this.windows.next([])
return
}
if (!id) {
let last: string | number
- const minimizedIds: (string | number)[] = this.minimizedWindows.getValue().map((w) => w.id)
- for (const value of this.modalIds) {
+ const minimizedIds: (string | number)[] = this.windows.getValue().map((w) => w.id)
+ for (const value of this.modalRefs.keys()) {
if (minimizedIds.indexOf(value) > -1) continue
last = value
}
@@ -187,15 +193,15 @@ export class LayoutService {
return
}
}
- this.modalIds.delete(id)
- const modal: BsModalRef<unknown> = this.getModal(id)
+ const modal = this.getModalComponent(id)
+ this.modalRefs.delete(id)
if (!modal) return
if (delay) {
setTimeout(() => this.closeModalWithEffect(modal, true), delay)
} else {
this.closeModalWithEffect(modal, true)
}
- this.minimizedWindows.next(this.minimizedWindows.getValue().filter((m) => m.id !== id))
+ this.windows.next(this.windows.getValue().filter((m) => m.id !== id))
}
openContextMenu(event: any, component: ContextMenuComponent<any>) {
@@ -283,7 +289,7 @@ export class LayoutService {
this.closeDialog(null, null, true)
}
- private openModalWithEffect(modal: BsModalRef<unknown>) {
+ private openModalWithEffect(modal: ModalComponent) {
this.bsModal['_renderer'].setAttribute(modal['instance']._element.nativeElement, 'aria-hidden', 'false')
this.bsModal['_renderer'].setStyle(modal['instance']._element.nativeElement, 'display', 'block')
setTimeout(() => {
@@ -291,7 +297,7 @@ export class LayoutService {
}, 100)
}
- private closeModalWithEffect(modal: BsModalRef<unknown>, hide = false) {
+ private closeModalWithEffect(modal: ModalComponent, hide = false) {
this.bsModal['_renderer'].setAttribute(modal['instance']._element.nativeElement, 'aria-hidden', 'true')
this.bsModal['_renderer'].removeClass(modal['instance']._element.nativeElement, 'show')
setTimeout(() => this.bsModal['_renderer'].setStyle(modal['instance']._element.nativeElement, 'display', 'none'), 500)
@@ -319,8 +325,8 @@ export class LayoutService {
}
}
- private getModal(modalId: any): BsModalRef {
- const modal: BsModalRef = this.bsModal['loaders'].find((loader: any) => loader.instance?.config.id === modalId)
+ private getModalComponent(modalId: number | string): ModalComponent {
+ const modal: ModalComponent = this.bsModal['loaders'].find((loader: any) => loader.instance?.config.id === modalId)
if (modal) {
modal.id = modalId
return modal
@@ -330,7 +336,7 @@ export class LayoutService {
}
private atLeastOneModalOpen(): boolean {
- return this.modalIds.size - this.minimizedWindows.getValue().length > 0
+ return this.modalRefs.size - this.windows.getValue().length > 0
}
private setTheme(theme: string) {
diff --git a/frontend/src/app/layout/sidebar/components/windows.component.ts b/frontend/src/app/layout/sidebar/components/windows.component.ts
index 94ee80d0..e82777a0 100755
--- a/frontend/src/app/layout/sidebar/components/windows.component.ts
+++ b/frontend/src/app/layout/sidebar/components/windows.component.ts
@@ -26,7 +26,7 @@ export class WindowsComponent implements OnDestroy {
private readonly subscription: Subscription = null
constructor() {
- this.subscription = this.layout.minimizedWindows.subscribe((windows: AppWindow[]) => this.setWindows(windows))
+ this.subscription = this.layout.windows.subscribe((windows: AppWindow[]) => this.setWindows(windows))
}
ngOnDestroy() {
@@ -40,16 +40,25 @@ export class WindowsComponent implements OnDestroy {
onClose(ev: MouseEvent, window: AppWindow) {
ev.preventDefault()
ev.stopPropagation()
- this.layout.closeDialog(null, window.id)
- if (!this.layout.minimizedWindows.getValue().length) {
+ const modal = this.layout.modalRefs.get(window.id)
+ if (modal) {
+ modal.content.onClose()
+ }
+ if (!this.layout.windows.getValue().length) {
this.layout.toggleRSideBar(false)
}
}
onCloseAll() {
- this.layout.closeDialog(null, null, true)
- this.layout.minimizedWindows.next([])
- this.layout.toggleRSideBar(false)
+ for (const w of this.layout.windows.getValue()) {
+ const modal = this.layout.modalRefs.get(w.id)
+ if (modal) {
+ modal.content.onClose()
+ }
+ }
+ if (!this.layout.windows.getValue().length) {
+ this.layout.toggleRSideBar(false)
+ }
}
private setWindows(windows: AppWindow[]) {
diff --git a/frontend/src/app/layout/sidebar/sidebar.right.component.ts b/frontend/src/app/layout/sidebar/sidebar.right.component.ts
index eb24b826..7786924e 100644
--- a/frontend/src/app/layout/sidebar/sidebar.right.component.ts
+++ b/frontend/src/app/layout/sidebar/sidebar.right.component.ts
@@ -87,7 +87,7 @@ export class SideBarRightComponent implements OnDestroy {
components: [WindowsComponent],
icon: faWindowRestore,
title: null,
- count: { value: this.layout.minimizedWindows.pipe(map((modals: AppWindow[]) => modals.length)), level: 'maroon' },
+ count: { value: this.layout.windows.pipe(map((modals: AppWindow[]) => modals.length)), level: 'maroon' },
showOnCount: true,
firstOfLasts: true,
active: false
diff --git a/frontend/src/i18n/de.json b/frontend/src/i18n/de.json
index 500261e8..7403531e 100644
--- a/frontend/src/i18n/de.json
+++ b/frontend/src/i18n/de.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "Benachrichtigungseinstellung kann nicht aktualisiert werden",
"Unable to update full-text search preference": "Volltextsuche-Einstellung kann nicht aktualisiert werden",
"Unable to open document": "Dokument kann nicht geöffnet werden",
+ "Unable to save document": "Dokument kann nicht gespeichert werden",
"Home": "Startseite",
"Recents": "Zuletzt verwendet",
"recents": "zuletzt",
@@ -603,5 +604,7 @@
"Save": "Speichern",
"Line Wrap": "Zeilenumbruch",
"Read-only": "Schreibgeschützt",
- "Read-write": "Lesen/Schreiben"
+ "Read-write": "Lesen/Schreiben",
+ "Save And Exit": "Speichern und beenden",
+ "Close Without Saving": "Schließen ohne zu speichern"
}
\ No newline at end of file
diff --git a/frontend/src/i18n/es.json b/frontend/src/i18n/es.json
index 67887b5d..728393af 100644
--- a/frontend/src/i18n/es.json
+++ b/frontend/src/i18n/es.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "No se puede actualizar la preferencia de notificaciones",
"Unable to update full-text search preference": "No se puede actualizar la preferencia de búsqueda de texto completo",
"Unable to open document": "No se puede abrir el documento",
+ "Unable to save document": "No se puede guardar el documento",
"Home": "Inicio",
"Recents": "Recientes",
"recents": "recientes",
@@ -603,5 +604,7 @@
"Save": "Guardar",
"Line Wrap": "Ajuste de línea",
"Read-only": "Solo lectura",
- "Read-write": "Lectura y escritura"
+ "Read-write": "Lectura y escritura",
+ "Save And Exit": "Guardar y salir",
+ "Close Without Saving": "Cerrar sin guardar"
}
\ No newline at end of file
diff --git a/frontend/src/i18n/fr.json b/frontend/src/i18n/fr.json
index a657ffc8..ff540a86 100644
--- a/frontend/src/i18n/fr.json
+++ b/frontend/src/i18n/fr.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "Impossible de mettre à jour la préférence de notification",
"Unable to update full-text search preference": "Impossible de mettre à jour la préférence de recherche full-text",
"Unable to open document": "Impossible d'ouvrir le document",
+ "Unable to save document": "Impossible d’enregistrer le document",
"Home": "Accueil",
"Recents": "Récents",
"recents": "recents",
@@ -603,5 +604,7 @@
"Save": "Enregistrer",
"Line Wrap": "Retour à la ligne automatique",
"Read-only": "Lecture seule",
- "Read-write": "Lecture-écriture"
+ "Read-write": "Lecture-écriture",
+ "Save And Exit": "Enregistrer et quitter",
+ "Close Without Saving": "Fermer sans enregistrer"
}
diff --git a/frontend/src/i18n/hi.json b/frontend/src/i18n/hi.json
index 6fe977bd..7674daad 100644
--- a/frontend/src/i18n/hi.json
+++ b/frontend/src/i18n/hi.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "सूचना प्राथमिकता अपडेट नहीं की जा सकी",
"Unable to update full-text search preference": "पूर्ण-पाठ खोज प्राथमिकता अपडेट नहीं की जा सकी",
"Unable to open document": "दस्तावेज़ नहीं खोला जा सका",
+ "Unable to save document": "दस्तावेज़ सहेजा नहीं जा सका",
"Home": "होम",
"Recents": "हाल के",
"recents": "हाल के",
@@ -603,5 +604,7 @@
"Save": "सहेजें",
"Line Wrap": "लाइन रैप",
"Read-only": "केवल-पढ़ने योग्य",
- "Read-write": "पढ़ने-लिखने योग्य"
+ "Read-write": "पढ़ने-लिखने योग्य",
+ "Save And Exit": "सहेजें और बाहर निकलें",
+ "Close Without Saving": "बिना सहेजे बंद करें"
}
\ No newline at end of file
diff --git a/frontend/src/i18n/it.json b/frontend/src/i18n/it.json
index e33728bc..01f0f897 100644
--- a/frontend/src/i18n/it.json
+++ b/frontend/src/i18n/it.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "Impossibile aggiornare la preferenza di notifica",
"Unable to update full-text search preference": "Impossibile aggiornare la preferenza di ricerca full-text",
"Unable to open document": "Impossibile aprire il documento",
+ "Unable to save document": "Impossibile salvare il documento",
"Home": "Home",
"Recents": "Recenti",
"recents": "recenti",
@@ -603,5 +604,7 @@
"Save": "Salva",
"Line Wrap": "A capo automatico",
"Read-only": "Sola lettura",
- "Read-write": "Lettura e scrittura"
+ "Read-write": "Lettura e scrittura",
+ "Save And Exit": "Salva e esci",
+ "Close Without Saving": "Chiudi senza salvare"
}
\ No newline at end of file
diff --git a/frontend/src/i18n/ja.json b/frontend/src/i18n/ja.json
index f5dfe4fa..00404d03 100644
--- a/frontend/src/i18n/ja.json
+++ b/frontend/src/i18n/ja.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "通知設定を更新できません",
"Unable to update full-text search preference": "フルテキスト検索設定を更新できません",
"Unable to open document": "ドキュメントを開けません",
+ "Unable to save document": "ドキュメントを保存できません",
"Home": "ホーム",
"Recents": "最近",
"recents": "最近",
@@ -603,5 +604,7 @@
"Save": "保存",
"Line Wrap": "折り返し",
"Read-only": "読み取り専用",
- "Read-write": "読み書き可能"
+ "Read-write": "読み書き可能",
+ "Save And Exit": "保存して終了",
+ "Close Without Saving": "保存せずに閉じる"
}
diff --git a/frontend/src/i18n/ko.json b/frontend/src/i18n/ko.json
index 25b24a28..807f4ae0 100644
--- a/frontend/src/i18n/ko.json
+++ b/frontend/src/i18n/ko.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "알림 설정을 업데이트할 수 없습니다",
"Unable to update full-text search preference": "전문 검색 설정을 업데이트할 수 없습니다",
"Unable to open document": "문서를 열 수 없습니다",
+ "Unable to save document": "문서를 저장할 수 없습니다",
"Home": "홈",
"Recents": "최근 항목",
"recents": "최근",
@@ -603,5 +604,7 @@
"Save": "저장",
"Line Wrap": "자동 줄 바꿈",
"Read-only": "읽기 전용",
- "Read-write": "읽기/쓰기"
+ "Read-write": "읽기/쓰기",
+ "Save And Exit": "저장하고 종료",
+ "Close Without Saving": "저장하지 않고 닫기"
}
diff --git a/frontend/src/i18n/pl.json b/frontend/src/i18n/pl.json
index 31e48f61..948d7824 100644
--- a/frontend/src/i18n/pl.json
+++ b/frontend/src/i18n/pl.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "Nie można zaktualizować preferencji powiadomień",
"Unable to update full-text search preference": "Nie można zaktualizować preferencji wyszukiwania pełnotekstowego",
"Unable to open document": "Nie można otworzyć dokumentu",
+ "Unable to save document": "Nie można zapisać dokumentu",
"Home": "Strona główna",
"Recents": "Ostatnie",
"recents": "ostatnie",
@@ -603,5 +604,7 @@
"Save": "Zapisz",
"Line Wrap": "Zawijanie wierszy",
"Read-only": "Tylko do odczytu",
- "Read-write": "Odczyt i zapis"
+ "Read-write": "Odczyt i zapis",
+ "Save And Exit": "Zapisz i wyjdź",
+ "Close Without Saving": "Zamknij bez zapisywania"
}
diff --git a/frontend/src/i18n/pt-BR.json b/frontend/src/i18n/pt-BR.json
index 9ac970ad..a4a43507 100644
--- a/frontend/src/i18n/pt-BR.json
+++ b/frontend/src/i18n/pt-BR.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "Não foi possível atualizar a preferência de notificação",
"Unable to update full-text search preference": "Não foi possível atualizar a preferência de pesquisa de texto completo",
"Unable to open document": "Não foi possível abrir o documento",
+ "Unable to save document": "Não é possível salvar o documento",
"Home": "Início",
"Recents": "Recentes",
"recents": "recentes",
@@ -603,5 +604,7 @@
"Save": "Salvar",
"Line Wrap": "Quebra de linha automática",
"Read-only": "Somente leitura",
- "Read-write": "Leitura e escrita"
+ "Read-write": "Leitura e escrita",
+ "Save And Exit": "Salvar e sair",
+ "Close Without Saving": "Fechar sem salvar"
}
diff --git a/frontend/src/i18n/pt.json b/frontend/src/i18n/pt.json
index 71fe62db..14329837 100644
--- a/frontend/src/i18n/pt.json
+++ b/frontend/src/i18n/pt.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "Não é possível atualizar a preferência de notificação",
"Unable to update full-text search preference": "Não é possível atualizar a preferência de pesquisa de texto completo",
"Unable to open document": "Não é possível abrir o documento",
+ "Unable to save document": "Não é possível salvar o documento",
"Home": "Início",
"Recents": "Recentes",
"recents": "recentes",
@@ -603,5 +604,7 @@
"Save": "Salvar",
"Line Wrap": "Quebra de linha automática",
"Read-only": "Somente leitura",
- "Read-write": "Leitura e escrita"
+ "Read-write": "Leitura e escrita",
+ "Save And Exit": "Salvar e sair",
+ "Close Without Saving": "Fechar sem salvar"
}
\ No newline at end of file
diff --git a/frontend/src/i18n/ru.json b/frontend/src/i18n/ru.json
index 0227777f..22505447 100644
--- a/frontend/src/i18n/ru.json
+++ b/frontend/src/i18n/ru.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "Не удалось обновить настройки уведомлений",
"Unable to update full-text search preference": "Не удалось обновить настройки полнотекстового поиска",
"Unable to open document": "Не удалось открыть документ",
+ "Unable to save document": "Не удалось сохранить документ",
"Home": "Главная",
"Recents": "Недавние",
"recents": "недавние",
@@ -603,5 +604,7 @@
"Save": "Сохранить",
"Line Wrap": "Перенос строк",
"Read-only": "Только чтение",
- "Read-write": "Чтение и запись"
+ "Read-write": "Чтение и запись",
+ "Save And Exit": "Сохранить и выйти",
+ "Close Without Saving": "Закрыть без сохранения"
}
\ No newline at end of file
diff --git a/frontend/src/i18n/tr.json b/frontend/src/i18n/tr.json
index 5af65049..983cd2f5 100644
--- a/frontend/src/i18n/tr.json
+++ b/frontend/src/i18n/tr.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "Bildirim tercihi güncellenemedi",
"Unable to update full-text search preference": "Tam metin arama tercihi güncellenemedi",
"Unable to open document": "Belge açılamadı",
+ "Unable to save document": "Belge kaydedilemedi",
"Home": "Ana sayfa",
"Recents": "Son kullanılanlar",
"recents": "son",
@@ -603,5 +604,7 @@
"Save": "Kaydet",
"Line Wrap": "Satır kaydırma",
"Read-only": "Salt okunur",
- "Read-write": "Okuma/Yazma"
+ "Read-write": "Okuma/Yazma",
+ "Save And Exit": "Kaydet ve çık",
+ "Close Without Saving": "Kaydetmeden kapat"
}
diff --git a/frontend/src/i18n/zh.json b/frontend/src/i18n/zh.json
index 31a00f0e..8e50d54c 100644
--- a/frontend/src/i18n/zh.json
+++ b/frontend/src/i18n/zh.json
@@ -170,6 +170,7 @@
"Unable to update notification preference": "无法更新通知偏好",
"Unable to update full-text search preference": "无法更新全文搜索偏好",
"Unable to open document": "无法打开文档",
+ "Unable to save document": "无法保存文档",
"Home": "首页",
"Recents": "最近",
"recents": "最近",
@@ -603,5 +604,7 @@
"Save": "保存",
"Line Wrap": "自动换行",
"Read-only": "只读",
- "Read-write": "读写"
+ "Read-write": "读写",
+ "Save And Exit": "保存并退出",
+ "Close Without Saving": "不保存并关闭"
}
\ No newline at end of file