Skip to content

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

feat(frontend:files): improve text viewer with line wrapping, saving state, and enhanced search panel handling

johavene5f0863bbd92
diff --git a/backend/src/applications/files/constants/only-office.ts b/backend/src/applications/files/constants/only-office.ts
index a5c3df1a..fe654b4b 100644
--- a/backend/src/applications/files/constants/only-office.ts
+++ b/backend/src/applications/files/constants/only-office.ts
@@ -34,10 +34,8 @@ export const ONLY_OFFICE_EXTENSIONS = {
['rtf', 'word'],
['stw', 'word'],
['sxw', 'word'],
- ['txt', 'word'],
['wps', 'word'],
['wpt', 'word'],
- ['xml', 'word'],
['md', 'word'],
// CELL
@@ -107,7 +105,6 @@ export const ONLY_OFFICE_EXTENSIONS = {
['odt', 'word'],
['ott', 'word'],
['rtf', 'word'],
- ['txt', 'word'],
['md', 'word'],
// CELL
@@ -155,7 +152,6 @@ export const ONLY_OFFICE_CONVERT_EXTENSIONS = {
'rtf',
'stw',
'sxw',
- 'txt',
'wps',
'wpt',
'xps'
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 9b8d9741..968dfc65 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
@@ -17,6 +17,14 @@ import { OnlyOfficeComponent } from '../utils/only-office.component'
@Component({
selector: 'app-files-viewer-document',
imports: [OnlyOfficeComponent],
+ styles: [
+ `
+ // fix onlyoffice iframe blinking when we hide and show via the windows manager
+ .doc-placeholder {
+ display: none !important;
+ }
+ `
+ ],
template: `
@if (documentConfig) {
<div [style.height.px]="currentHeight()">
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 5b5fee08..7dc7fca3 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
@@ -23,15 +23,30 @@
class="d-none d-sm-block btn btn-sm btn-secondary me-1"
type="button"
[disabled]="isReadonly() || !isModified()">
- <fa-icon [icon]="icons.faFloppyDisk"></fa-icon>
+ @if (isSaving()) {
+ <fa-icon [icon]="icons.faSpinner" animation="spin"></fa-icon>
+ } @else {
+ <fa-icon [icon]="icons.faFloppyDisk"></fa-icon>
+ }
</button>
+
<button
btnCheckbox
- [ngModel]="this.isSearchPanelOpen"
+ [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">
+ <fa-icon [icon]="icons.faArrowsLeftRightToLine"></fa-icon>
+ </button>
+ <button
+ btnCheckbox
+ [ngModel]="this.isSearchPanelOpen()"
(ngModelChange)="toggleSearch()"
[tooltip]="'Search' | translate:locale.language"
container="body"
- class="d-none d-sm-block btn btn-sm btn-custom me-1"
+ class="d-none d-sm-block btn btn-sm btn-custom"
type="button"
[disabled]="!isReadable()">
<fa-icon [icon]="icons.faMagnifyingGlass"></fa-icon>
@@ -39,11 +54,12 @@
</div>
<code-editor
#editor
+ [autoFocus]="true"
[languages]="languages"
[language]="currentLanguage"
[(ngModel)]="content"
(change)="contentChange()"
[theme]="currentTheme"
[readonly]="isReadonly()"
- [lineWrapping]="true" />
+ [lineWrapping]="lineWrapping()" />
</div>
\ No newline at end of file
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 be6ee5df..d0ca8f81 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
@@ -12,7 +12,7 @@ import { LanguageDescription } from '@codemirror/language'
import { languages } from '@codemirror/language-data'
import { closeSearchPanel, openSearchPanel } from '@codemirror/search'
import { FaIconComponent } from '@fortawesome/angular-fontawesome'
-import { faFloppyDisk, faLock, faLockOpen, faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons'
+import { faArrowsLeftRightToLine, faFloppyDisk, faLock, faLockOpen, faMagnifyingGlass, faSpinner } from '@fortawesome/free-solid-svg-icons'
import { L10N_LOCALE, L10nLocale, L10nTranslatePipe } from 'angular-l10n'
import { ButtonCheckboxDirective } from 'ngx-bootstrap/buttons'
import { TooltipModule } from 'ngx-bootstrap/tooltip'
@@ -31,6 +31,26 @@ import { FilesUploadService } from '../../services/files-upload.service'
height: calc(100% - 40px);
font-size: 0.8rem;
}
+
+ .cm-focused {
+ outline: none !important;
+ }
+
+ .cm-panel.cm-search {
+ display: flex;
+ align-items: center;
+ text-wrap: nowrap;
+
+ label {
+ display: flex;
+ align-items: center;
+ }
+
+ button[aria-label='close'] {
+ right: 10px !important;
+ font-size: 18px !important;
+ }
+ }
`
],
templateUrl: 'files-viewer-text.component.html'
@@ -40,16 +60,18 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
currentHeight = input<number>()
file = input<FileModel>()
mode = input<'view' | 'edit'>('view')
- isReadonly = linkedSignal(() => this.mode() === 'view')
- isReadable = signal(false)
- isModified = signal(false)
+ protected isReadonly = linkedSignal(() => this.mode() === 'view')
+ protected isReadable = signal(false)
+ protected isModified = signal(false)
+ protected isSaving = signal(false)
+ protected lineWrapping = signal(false)
protected content: string
protected currentLanguage = undefined
protected readonly languages: LanguageDescription[] = languages
protected currentTheme: any = 'light'
- protected readonly icons = { faFloppyDisk, faLock, faLockOpen, faMagnifyingGlass }
+ protected readonly icons = { faFloppyDisk, faLock, faLockOpen, faMagnifyingGlass, faSpinner, faArrowsLeftRightToLine }
protected readonly locale = inject<L10nLocale>(L10N_LOCALE)
- protected isSearchPanelOpen = false
+ protected isSearchPanelOpen = signal(false)
private isContentReady = false
private readonly layout = inject(LayoutService)
private readonly http = inject(HttpClient)
@@ -103,19 +125,33 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
}
toggleReadonly() {
- this.isReadonly.update((value) => !value)
+ this.isReadonly.set(!this.isReadonly())
+ if (this.isSearchPanelOpen()) {
+ // reset search state when open to enable/disable the replace function
+ setTimeout(() => {
+ this.toggleSearch()
+ this.toggleSearch()
+ }, 100)
+ }
}
save() {
+ this.isSaving.set(true)
this.filesUpload.uploadOneFile(this.file(), this.content, true).subscribe({
- next: () => this.isModified.set(false),
- error: (e: HttpErrorResponse) => this.layout.sendNotification('error', 'Unable to save document', e.error.message)
+ next: () => {
+ this.isModified.set(false)
+ this.isSaving.set(false)
+ },
+ error: (e: HttpErrorResponse) => {
+ this.isSaving.set(false)
+ this.layout.sendNotification('error', 'Unable to save document', e.error.message)
+ }
})
}
toggleSearch() {
- this.isSearchPanelOpen = !this.isSearchPanelOpen
- if (this.isSearchPanelOpen) {
+ this.isSearchPanelOpen.set(!this.isSearchPanelOpen())
+ if (this.isSearchPanelOpen()) {
openSearchPanel(this.editor.view)
} else {
closeSearchPanel(this.editor.view)
diff --git a/frontend/src/app/applications/files/models/file.model.ts b/frontend/src/app/applications/files/models/file.model.ts
index 599a6768..650609df 100644
--- a/frontend/src/app/applications/files/models/file.model.ts
+++ b/frontend/src/app/applications/files/models/file.model.ts
@@ -135,6 +135,7 @@ export class FileModel implements File {
const longMime = mimeArray[mimeArray.length - 1]
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
@@ -144,9 +145,6 @@ export class FileModel implements File {
this.shortMime = 'document'
this.isEditable = ONLY_OFFICE_EXTENSIONS.EDITABLE.has(extension)
this.isViewable = this.isEditable || ONLY_OFFICE_EXTENSIONS.VIEWABLE.has(extension)
- } else if (longMime === 'html') {
- this.isViewable = true
- this.isEditable = true
} else if (extension === 'mp4') {
this.isViewable = true
this.shortMime = 'media'
@@ -164,6 +162,7 @@ export class FileModel implements File {
this.isViewable = false
} else if (!notViewableExtensions.has(extension)) {
this.isViewable = true
+ this.isEditable = true
this.shortMime = 'text'
}
return mime
diff --git a/frontend/src/styles/components/_fixes.scss b/frontend/src/styles/components/_fixes.scss
index 88e3236e..4930c11b 100755
--- a/frontend/src/styles/components/_fixes.scss
+++ b/frontend/src/styles/components/_fixes.scss
@@ -18,32 +18,6 @@ hr {
color: $gray;
}
-// fix onlyoffice iframe blinking when we hide and show via the windows manager
-.doc-placeholder {
- display: none !important;
-}
-
.progress-bar {
overflow: visible !important;
-}
-
-// codemirror
-.cm-focused {
- outline: none !important;
-}
-
-.cm-panel.cm-search {
- display: flex;
- align-items: center;
- text-wrap: nowrap;
-
- label {
- display: flex;
- align-items: center;
- }
-
- button[aria-label="close"] {
- right: 10px !important;
- font-size: 18px !important;
- }
}
\ No newline at end of file