-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49171 from nextcloud/feat/empty-trash
feat(trashbin): Allow emptying trash
- Loading branch information
Showing
139 changed files
with
530 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
apps/files_trashbin/src/fileListActions/emptyTrashAction.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import type { Node, View, Folder } from '@nextcloud/files' | ||
|
||
import axios from '@nextcloud/axios' | ||
import { FileListAction } from '@nextcloud/files' | ||
import { t } from '@nextcloud/l10n' | ||
import { | ||
DialogSeverity, | ||
getDialogBuilder, | ||
showError, | ||
showInfo, | ||
showSuccess, | ||
} from '@nextcloud/dialogs' | ||
|
||
import { logger } from '../logger.ts' | ||
import { generateRemoteUrl } from '@nextcloud/router' | ||
import { getCurrentUser } from '@nextcloud/auth' | ||
import { emit } from '@nextcloud/event-bus' | ||
|
||
const emptyTrash = async (): Promise<boolean> => { | ||
try { | ||
await axios.delete(generateRemoteUrl('dav') + `/trashbin/${getCurrentUser()?.uid}/trash`) | ||
showSuccess(t('files_trashbin', 'All files have been permanently deleted')) | ||
return true | ||
} catch (error) { | ||
showError(t('files_trashbin', 'Failed to empty deleted files')) | ||
logger.error('Failed to empty deleted files', { error }) | ||
return false | ||
} | ||
} | ||
|
||
export const emptyTrashAction = new FileListAction({ | ||
id: 'empty-trash', | ||
|
||
displayName: () => t('files_trashbin', 'Empty deleted files'), | ||
order: 0, | ||
|
||
enabled(view: View, nodes: Node[], folder: Folder) { | ||
if (view.id !== 'trashbin') { | ||
return false | ||
} | ||
return nodes.length > 0 && folder.path === '/' | ||
}, | ||
|
||
async exec(view: View, nodes: Node[]): Promise<void> { | ||
const askConfirmation = new Promise<boolean>((resolve) => { | ||
const dialog = getDialogBuilder(t('files_trashbin', 'Confirm permanent deletion')) | ||
.setSeverity(DialogSeverity.Warning) | ||
// TODO Add note for groupfolders | ||
.setText(t('files_trashbin', 'Are you sure you want to permanently delete all files and folders in the trash? This cannot be undone.')) | ||
.setButtons([ | ||
{ | ||
label: t('files_trashbin', 'Cancel'), | ||
type: 'secondary', | ||
callback: () => resolve(false), | ||
}, | ||
{ | ||
label: t('files_trashbin', 'Empty deleted files'), | ||
type: 'error', | ||
callback: () => resolve(true), | ||
}, | ||
]) | ||
.build() | ||
dialog.show().then(() => { | ||
resolve(false) | ||
}) | ||
}) | ||
|
||
const result = await askConfirmation | ||
if (result === true) { | ||
await emptyTrash() | ||
nodes.forEach((node) => emit('files:node:deleted', node)) | ||
return | ||
} | ||
|
||
showInfo(t('files_trashbin', 'Deletion cancelled')) | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { getLoggerBuilder } from '@nextcloud/logger' | ||
|
||
export const logger = getLoggerBuilder() | ||
.setApp('files_trashbin') | ||
.detectUser() | ||
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.