Skip to content

Commit db768e1

Browse files
committed
fix(frontend:files): update file metadata timestamps on save and align OnlyOffice state change handlers
1 parent aaf7eb4 commit db768e1

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

backend/src/applications/files/interfaces/only-office-config.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export interface OnlyOfficeConfig {
165165
onAppReady?: (event: object) => void
166166
onCollaborativeChanges?: (event: object) => void
167167
onDocumentReady?: (event: object) => void
168-
onDocumentStateChange?: (event: object) => void
168+
onDocumentStateChange?: (event: { data: boolean }) => void
169169
onDownloadAs?: (event: object) => void
170170
onError?: (event: object) => void
171171
onInfo?: (event: object) => void
@@ -191,7 +191,7 @@ export interface OnlyOfficeConfig {
191191
onRequestSelectSpreadsheet?: (event: object) => void
192192
onRequestSendNotify?: (event: object) => void
193193
onRequestSharingSettings?: (event: object) => void
194-
onRequestStartFilling: (event: object) => void
194+
onRequestStartFilling?: (event: object) => void
195195
onRequestUsers?: (event: object) => void
196196
onSubmit?: (event: object) => void
197197
onWarning?: (event: object) => void

frontend/src/app/applications/files/components/utils/only-office.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class OnlyOfficeComponent implements OnInit, OnChanges, OnDestroy {
1717
@Input() documentServerUrl: string
1818
@Input() config: OnlyOfficeConfig
1919
@Output() loadError = new EventEmitter<string>()
20+
@Output() wasSaved = new EventEmitter<string>()
2021
private isFirstOnChanges = true
2122

2223
ngOnInit(): void {
@@ -51,6 +52,7 @@ export class OnlyOfficeComponent implements OnInit, OnChanges, OnDestroy {
5152
if (window?.DocEditor?.instances[this.id]) {
5253
window.DocEditor.instances[this.id].destroyEditor()
5354
window.DocEditor.instances[this.id] = undefined
55+
delete window.DocEditor.instances[this.id]
5456
}
5557
}
5658

@@ -70,6 +72,7 @@ export class OnlyOfficeComponent implements OnInit, OnChanges, OnDestroy {
7072
}
7173

7274
const config: OnlyOfficeConfig = JSON.parse(JSON.stringify(this.config))
75+
config.events = { onDocumentStateChange: (e: { data: boolean }) => (e.data ? this.wasSaved.emit() : null) }
7376
window.DocEditor.instances[this.id] = window.DocsAPI.DocEditor(this.id, config)
7477
} catch (err) {
7578
console.error(err)

frontend/src/app/applications/files/components/viewers/files-viewer-document.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { OnlyOfficeComponent } from '../utils/only-office.component'
3535
[documentServerUrl]="documentConfig.documentServerUrl"
3636
[config]="documentConfig.config"
3737
(loadError)="loadError($event)"
38+
(wasSaved)="onSave()"
3839
></app-files-onlyoffice-document>
3940
</div>
4041
}
@@ -95,4 +96,8 @@ export class FilesViewerDocumentComponent implements OnInit, OnDestroy {
9596
this.layout.closeDialog()
9697
this.layout.sendNotification('error', 'Unable to open document', errorMessage)
9798
}
99+
100+
onSave() {
101+
this.file.updateHTimeAgo()
102+
}
98103
}

frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export class FilesViewerTextComponent implements OnInit, OnDestroy {
203203
if (exit) {
204204
this.onClose().catch(console.error)
205205
}
206+
this.file().updateHTimeAgo()
206207
},
207208
error: (e: HttpErrorResponse) => {
208209
this.isSaving.set(false)

frontend/src/app/applications/files/models/file.model.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import type { FileLockProps, FileProps } from '@sync-in-server/backend/src/applications/files/interfaces/file-props.interface'
1414
import type { File } from '@sync-in-server/backend/src/applications/files/schemas/file.interface'
1515
import { SPACE_OPERATION } from '@sync-in-server/backend/src/applications/spaces/constants/spaces'
16-
import { popFromObject } from '@sync-in-server/backend/src/common/shared'
16+
import { currentTimeStamp, popFromObject } from '@sync-in-server/backend/src/common/shared'
1717
import type { Observable } from 'rxjs'
1818
import { convertBytesToText, getNewly } from '../../../common/utils/functions'
1919
import { dJs } from '../../../common/utils/time'
@@ -92,8 +92,7 @@ export class FileModel implements File {
9292
Object.assign(this, props)
9393
this.path = `${basePath}/${this.path !== '.' ? `${this.path}/` : ''}${this.root?.alias || this.name}`
9494
this.mime = this.getMime(this.mime, inShare)
95-
this.hTimeAgo = dJs(this.mtime).fromNow(true)
96-
this.newly = getNewly(this.mtime)
95+
this.updateHTimeAgo(this.mtime)
9796
this.setMimeUrl()
9897
this.setHSize()
9998
this.setRoot(inShare)
@@ -125,6 +124,12 @@ export class FileModel implements File {
125124
this.setMimeUrl()
126125
}
127126

127+
updateHTimeAgo(mtime?: number) {
128+
mtime ??= currentTimeStamp(null, true)
129+
this.hTimeAgo = dJs(mtime).fromNow(true)
130+
this.newly = getNewly(mtime)
131+
}
132+
128133
private getType(inShare: boolean) {
129134
return this.isDir ? (inShare ? mimeDirectoryShare : mimeDirectory) : mimeFile
130135
}

0 commit comments

Comments
 (0)