Skip to content

Commit

Permalink
clean up file manager
Browse files Browse the repository at this point in the history
  • Loading branch information
jardakotesovec committed Jul 18, 2024
1 parent 99b275f commit 81aa1c8
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 262 deletions.
10 changes: 4 additions & 6 deletions src/managers/FileManager/FileManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<div class="flex items-center border border-light p-4">
<div class="flex-grow">
<h3 class="text-lg-bold text-heading">
{{ fileManagerStore.managerConfiguration.title }}
{{ fileManagerStore.managerConfig.title }}
</h3>
<p class="pt-2 text-sm-normal">
{{ fileManagerStore.managerConfiguration.description }}
{{ fileManagerStore.managerConfig.description }}
</p>
</div>
<div class="ms-2 flex flex-none space-x-2">
Expand Down Expand Up @@ -56,10 +56,8 @@
</template>
<script setup>
import {inject} from 'vue';
import {
FileManagerConfigurations,
useFileManagerStore,
} from './fileManagerStore.js';
import {useFileManagerStore} from './fileManagerStore.js';
import {FileManagerConfigurations} from './useFileManagerConfig.js';
import PkpButton from '@/components/Button/Button.vue';
import PkpTable from '@/components/TableNext/Table.vue';
import TableHeader from '@/components/TableNext/TableHeader.vue';
Expand Down
279 changes: 29 additions & 250 deletions src/managers/FileManager/fileManagerStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,254 +3,31 @@ import {defineComponentStore} from '@/utils/defineComponentStore';
import {ref, computed} from 'vue';
import {useFetch} from '@/composables/useFetch';
import {useUrl} from '@/composables/useUrl';
import {useLocalize} from '@/composables/useLocalize';
import {Actions, useFileManagerActions} from './useFileManagerActions';
import {useCurrentUser} from '@/composables/useCurrentUser';

const {tk} = useLocalize();

export const FileManagerConfigurations = {
SUBMISSION_FILES: ({stageId}) => ({
permissions: [
{
roles: [pkp.const.ROLE_ID_AUTHOR],
actions: [Actions.LIST, Actions.EDIT, Actions.DOWNLOAD_ALL],
},
{
roles: [
pkp.const.ROLE_ID_SUB_EDITOR,
pkp.const.ROLE_ID_MANAGER,
pkp.const.ROLE_ID_SITE_ADMIN,
pkp.const.ROLE_ID_ASSISTANT,
],
actions: [
Actions.LIST,
Actions.UPLOAD,
Actions.DOWNLOAD_ALL,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
},
],
actions: [
Actions.UPLOAD,
Actions.DOWNLOAD_ALL,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
fileStage: pkp.const.SUBMISSION_FILE_SUBMISSION,
titleKey: tk('dashboard.summary.deskReviewFiles'),
descriptionKey: tk('dashboard.summary.deskReviewFilesDescription'),
wizardTitleKey: tk('submission.submit.uploadSubmissionFile'),
}),
EDITOR_REVIEW_FILES: ({stageId}) => ({
permissions: [
{
roles: [
pkp.const.ROLE_ID_SUB_EDITOR,
pkp.const.ROLE_ID_MANAGER,
pkp.const.ROLE_ID_SITE_ADMIN,
pkp.const.ROLE_ID_ASSISTANT,
],
actions: [
Actions.LIST,
Actions.SELECT_UPLOAD,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
},
],

actions: [
Actions.SELECT_UPLOAD,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
fileStage:
stageId === pkp.const.WORKFLOW_STAGE_ID_INTERNAL_REVIEW
? pkp.const.SUBMISSION_FILE_INTERNAL_REVIEW_FILE
: pkp.const.SUBMISSION_FILE_REVIEW_FILE,
gridComponent: 'grid.files.review.EditorReviewFilesGridHandler',
titleKey: tk('dashboard.summary.filesForReview'),
descriptionKey: tk('dashboard.summary.deskReviewFilesDescription'),
uploadSelectTitleKey: tk('editor.submission.review.currentFiles'),
}),
WORKFLOW_REVIEW_REVISIONS: ({stageId}) => ({
permissions: [
{
roles: [pkp.const.ROLE_ID_AUTHOR],
actions: [Actions.LIST, Actions.UPLOAD, Actions.EDIT, Actions.DELETE],
},
{
roles: [
pkp.const.ROLE_ID_AUTHOR,
pkp.const.ROLE_ID_SUB_EDITOR,
pkp.const.ROLE_ID_MANAGER,
pkp.const.ROLE_ID_SITE_ADMIN,
pkp.const.ROLE_ID_ASSISTANT,
],
actions: [
Actions.LIST,
Actions.UPLOAD,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
},
],
actions: [Actions.UPLOAD, Actions.EDIT, Actions.DELETE, Actions.SEE_NOTES],
fileStage:
stageId === pkp.const.WORKFLOW_STAGE_ID_INTERNAL_REVIEW
? pkp.const.SUBMISSION_FILE_INTERNAL_REVIEW_REVISION
: pkp.const.SUBMISSION_FILE_REVIEW_REVISION,
titleKey: tk('dashboard.summary.revisionsSubmitted'),
descriptionKey: tk('dashboard.summary.revisionsSubmittedDescription'),
wizardTitleKey: tk('editor.submissionReview.uploadFile'),
}),
COPYEDITED_FILES: ({stageId}) => ({
permissions: [
{
roles: [pkp.const.ROLE_ID_AUTHOR],
actions: [Actions.LIST],
},
{
roles: [
pkp.const.ROLE_ID_SUB_EDITOR,
pkp.const.ROLE_ID_MANAGER,
pkp.const.ROLE_ID_SITE_ADMIN,
pkp.const.ROLE_ID_ASSISTANT,
],
actions: [
Actions.LIST,
Actions.UPLOAD,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
},
],
actions: [
Actions.LIST,
Actions.UPLOAD,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
fileStage: pkp.const.SUBMISSION_FILE_COPYEDIT,
titleKey: tk('dashboard.summary.copyeditedFiles'),
descriptionKey: tk('dashboard.summary.copyeditedFilesDescription'),
gridComponent: 'grid.files.copyedit.CopyeditFilesGridHandler',
uploadSelectTitleKey: tk('editor.submissionReview.uploadFile'),
}),
FINAL_DRAFT_FILES: ({stageId}) => ({
permissions: [
{
roles: [
pkp.const.ROLE_ID_SUB_EDITOR,
pkp.const.ROLE_ID_MANAGER,
pkp.const.ROLE_ID_SITE_ADMIN,
pkp.const.ROLE_ID_ASSISTANT,
],
actions: [
Actions.LIST,
Actions.SELECT_UPLOAD,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
},
],
actions: [
Actions.LIST,
Actions.SELECT_UPLOAD,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
fileStage: pkp.const.SUBMISSION_FILE_FINAL,
titleKey: tk('dashboard.summary.draftFiles'),
descriptionKey: tk('dashboard.summary.draftFilesDescription'),
gridComponent: 'grid.files.final.FinalDraftFilesGridHandler',
uploadSelectTitleKey: tk('editor.submission.uploadSelectFiles'),
}),
PRODUCTION_READY_FILES: ({stageId}) => ({
permissions: [
{
roles: [
pkp.const.ROLE_ID_SUB_EDITOR,
pkp.const.ROLE_ID_MANAGER,
pkp.const.ROLE_ID_SITE_ADMIN,
pkp.const.ROLE_ID_ASSISTANT,
],
actions: [
Actions.LIST,
Actions.UPLOAD,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
},
],
actions: [
Actions.LIST,
Actions.UPLOAD,
Actions.EDIT,
Actions.DELETE,
Actions.SEE_NOTES,
],
fileStage: pkp.const.SUBMISSION_FILE_PRODUCTION_READY,
titleKey: tk('dashboard.summary.productionReadyFiles'),
descriptionKey: tk('dashboard.summary.productionReadyFilesDescription'),
wizardTitleKey: tk('submission.upload.productionReady'),
}),
};

import {useFileManagerConfig} from './useFileManagerConfig';
export const useFileManagerStore = defineComponentStore(
'fileManager',
(props) => {
const {t} = useLocalize();

const submissionId = ref(props.submission.id);

/**
* Manager configuration
*/
const {managerConfig} = useFileManagerConfig({
configName: props.configName,
submissionStageId: props.submissionStageId,
});

/**
* Files fetching
*/
const {apiUrl: filesApiUrl} = useUrl(
`submissions/${submissionId.value}/files`,
);

/** Expose file manager configuration */
const {hasCurrentUserAtLeastOneRole} = useCurrentUser();

const managerConfiguration = computed(() => {
const config = FileManagerConfigurations[props.configName]({
stageId: props.submissionStageId,
});

const permittedActions = config.actions.filter((action) => {
return config.permissions.some((perm) => {
return (
perm.actions.includes(action) &&
hasCurrentUserAtLeastOneRole(perm.roles)
);
});
});

return {
fileStage: config.fileStage,
permittedActions,
title: t(config.titleKey),
description: t(config.descriptionKey),
wizardTitleKey: config.wizardTitleKey,
uploadSelectTitleKey: config.uploadSelectTitleKey,
gridComponent: config.gridComponent,
};
});

const {data, fetch: fetchFiles} = useFetch(filesApiUrl, {
query: {
fileStages: managerConfiguration.value.fileStage,
fileStages: managerConfig.value.fileStage,
reviewRoundId: props.reviewRoundId ? props.reviewRoundId : undefined,
},
});
Expand All @@ -259,31 +36,33 @@ export const useFileManagerStore = defineComponentStore(

fetchFiles();

/** Handling Actions */
/**
* Handling Actions
*/

const _actionFns = useFileManagerActions();

const topActions = computed(() =>
_actionFns.getTopActions.value({
managerConfiguration: managerConfiguration.value,
_actionFns.getTopActions({
managerConfig: managerConfig.value,
}),
);

const bottomActions = computed(() =>
_actionFns.getBottomActions.value({
managerConfiguration: managerConfiguration.value,
_actionFns.getBottomActions({
managerConfig: managerConfig.value,
filesCount: files.value.length,
}),
);

const itemActions = computed(() =>
_actionFns.getItemActions.value({
managerConfiguration: managerConfiguration.value,
_actionFns.getItemActions({
managerConfig: managerConfig.value,
}),
);

function handleItemAction(actionName, {file}) {
_actionFns.handleItemAction.value(
_actionFns.handleItemAction(
actionName,
{
file,
Expand All @@ -304,16 +83,16 @@ export const useFileManagerStore = defineComponentStore(
}

function handleAction(actionName) {
_actionFns.handleAction.value(
_actionFns.handleAction(
actionName,
{
submissionStageId: props.submissionStageId,
reviewRoundId: props.reviewRoundId,
submission: props.submission,
fileStage: managerConfiguration.value.fileStage,
wizardTitleKey: managerConfiguration.value.wizardTitleKey,
uploadSelectTitleKey: managerConfiguration.value.uploadSelectTitleKey,
gridComponent: managerConfiguration.value.gridComponent,
fileStage: managerConfig.value.fileStage,
wizardTitleKey: managerConfig.value.wizardTitleKey,
uploadSelectTitleKey: managerConfig.value.uploadSelectTitleKey,
gridComponent: managerConfig.value.gridComponent,
},
() => fetchFiles(),
);
Expand All @@ -323,7 +102,7 @@ export const useFileManagerStore = defineComponentStore(
title: props.title,
files,
fetchFiles,
managerConfiguration,
managerConfig,
topActions,
bottomActions,
itemActions,
Expand Down
Loading

0 comments on commit 81aa1c8

Please sign in to comment.