Relative days

[skip ci]
This commit is contained in:
shamoon 2024-04-23 01:33:00 -07:00
parent e58c2d4bbf
commit e4092d2ad1
6 changed files with 24 additions and 6 deletions

View File

@ -1366,13 +1366,13 @@ processing. This only has an effect if
#### [`EMPTY_TRASH_DELAY=<num>`](#EMPTY_TRASH_DELAY) {#EMPTY_TRASH_DELAY}
: Sets how long in days objects remain in the 'trash' before they are permanently deleted.
: Sets how long in days documents remain in the 'trash' before they are permanently deleted.
Defaults to 30 days, minimum of 1 day.
#### [`PAPERLESS_EMPTY_TRASH_TASK_CRON=<cron expression>`](#PAPERLESS_EMPTY_TRASH_TASK_CRON) {#PAPERLESS_EMPTY_TRASH_TASK_CRON}
: Configures the schedule to empty the trash of expired deleted objects.
: Configures the schedule to empty the trash of expired deleted documents.
Defaults to `0 1 * * *`, once per day.

View File

@ -32,7 +32,7 @@ info="Manage trashed items."
</div>
</th>
<th scope="col" class="fw-normal" i18n>Name</th>
<th scope="col" class="fw-normal d-none d-sm-table-cell" i18n>Deleted</th>
<th scope="col" class="fw-normal d-none d-sm-table-cell" i18n>Remaining</th>
<th scope="col" class="fw-normal" i18n>Actions</th>
</tr>
</thead>
@ -54,7 +54,7 @@ info="Manage trashed items."
</div>
</td>
<td scope="row">{{ document.title }}</td>
<td scope="row">{{ document.deleted_at | customDate }}</td>
<td scope="row" i18n>{{ getDaysRemaining(document) }} days</td>
<td scope="row">
<div class="btn-group d-block d-sm-none">
<div ngbDropdown container="body" class="d-inline-block">

View File

@ -5,6 +5,8 @@ import { ToastService } from 'src/app/services/toast.service'
import { TrashService } from 'src/app/services/trash.service'
import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component'
import { Subject, takeUntil } from 'rxjs'
import { SettingsService } from 'src/app/services/settings.service'
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
@Component({
selector: 'pngx-trash',
@ -22,7 +24,8 @@ export class TrashComponent implements OnDestroy {
constructor(
private trashService: TrashService,
private toastService: ToastService,
private modalService: NgbModal
private modalService: NgbModal,
private settingsService: SettingsService
) {
this.reload()
}
@ -120,4 +123,11 @@ export class TrashComponent implements OnDestroy {
this.allToggled = false
this.selectedDocuments.clear()
}
getDaysRemaining(document: Document): number {
const delay = this.settingsService.get(SETTINGS_KEYS.EMPTY_TRASH_DELAY)
const diff = new Date().getTime() - new Date(document.deleted_at).getTime()
const days = Math.ceil(diff / (1000 * 3600 * 24))
return delay - days
}
}

View File

@ -63,6 +63,7 @@ export const SETTINGS_KEYS = {
'general-settings:document-editing:remove-inbox-tags',
SEARCH_DB_ONLY: 'general-settings:search:db-only',
SEARCH_FULL_TYPE: 'general-settings:search:more-link',
EMPTY_TRASH_DELAY: 'general-settings:trash:empty-trash-delay',
}
export const SETTINGS: UiSetting[] = [
@ -236,4 +237,9 @@ export const SETTINGS: UiSetting[] = [
type: 'string',
default: GlobalSearchType.TITLE_CONTENT,
},
{
key: SETTINGS_KEYS.EMPTY_TRASH_DELAY,
type: 'number',
default: 30,
},
]

View File

@ -1559,6 +1559,8 @@ class UiSettingsView(GenericAPIView):
"backend_setting": settings.ENABLE_UPDATE_CHECK,
}
ui_settings["trash_delay"] = settings.EMPTY_TRASH_DELAY
general_config = GeneralConfig()
ui_settings["app_title"] = settings.APP_TITLE

View File

@ -1166,4 +1166,4 @@ if DEBUG: # pragma: no cover
###############################################################################
# Soft Delete
###############################################################################
EMPTY_TRASH_DELAY = max(__get_int("PAPERLESS_SOFT_DELETE_DELAY", 30), 1)
EMPTY_TRASH_DELAY = max(__get_int("PAPERLESS_EMPTY_TRASH_DELAY", 30), 1)