Skip to content

Commit

Permalink
Delete evidence
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Oct 18, 2024
1 parent cdc72ef commit deedd2f
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 54 deletions.
19 changes: 18 additions & 1 deletion src/plugin/cursus/Controller/EventPresenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function downloadUserPdfAction(EventPresence $eventPresence, Request $req
}

/**
* @Route("/{id}/evidences", name="apiv2_cursus_presence_evidences_upload", methods={"POST"})
* @Route("/{id}/evidences", name="apiv2_cursus_presence_evidence_upload", methods={"POST"})
*
* @EXT\ParamConverter("eventPresence", class="Claroline\CursusBundle\Entity\EventPresence", options={"mapping": {"id": "uuid"}})
*/
Expand Down Expand Up @@ -298,6 +298,23 @@ public function uploadEvidences(EventPresence $eventPresence, Request $request):
return new JsonResponse($this->serializer->serialize($eventPresence));
}

/**
* @Route("/{id}/evidences", name="apiv2_cursus_presence_evidence_delete", methods={"DELETE"})
*
* @EXT\ParamConverter("eventPresence", class="Claroline\CursusBundle\Entity\EventPresence", options={"mapping": {"id": "uuid"}})
*/
public function deleteEvidenceAction(EventPresence $eventPresence): JsonResponse
{
$this->checkPermission('EDIT', $eventPresence, [], true);

$eventPresence->setEvidences(null);

$this->om->persist($eventPresence);
$this->om->flush();

return new JsonResponse(['success' => true]);
}

/**
* @Route("/{id}/evidences", name="apiv2_cursus_presence_evidence_download", methods={"GET"})
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export default (presences, refresher) => {
name: 'add-evidence',
type: MODAL_BUTTON,
icon: 'fa fa-fw fa-file-upload',
label: trans('add_evidences', {}, 'presence'),
label: trans('add_evidence', {}, 'presence'),
modal: [MODAL_EVIDENCE, {
parent: processable[0],
onSuccess: refresher.update,
editable: true
}],
displayed: 0 !== processable.length && [constants.PRESENCE_STATUS_ABSENT_UNJUSTIFIED, constants.PRESENCE_STATUS_ABSENT_JUSTIFIED].includes(processable[0].status),
displayed: 0 !== processable.length
&& [constants.PRESENCE_STATUS_ABSENT_UNJUSTIFIED, constants.PRESENCE_STATUS_ABSENT_JUSTIFIED].includes(processable[0].status)
&& (!processable[0].evidences || processable[0].evidences.length === 0),
group: trans('validation', {}, 'presence'),
scope: ['object']
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {hasPermission} from '#/main/app/security'
import {url} from '#/main/app/api'
import {ASYNC_BUTTON} from '#/main/app/buttons'
import {trans} from '#/main/app/intl/translation'

/**
* Delete evidence action.
*/
export default (presences, refresher) => {
const processable = presences.filter(presence => hasPermission('edit', presence))

return {
name: 'delete-evidence',
type: ASYNC_BUTTON,
icon: 'fa fa-fw fa-trash',
label: trans('delete_evidence', {}, 'presence'),
displayed: 0 !== processable.length && (processable[0].evidences && processable[0].evidences.length > 0),
dangerous: true,
confirm: {
title: trans('delete_evidence', {}, 'presence'),
message: trans('delete_evidence_message', {}, 'presence')
},
request: {
url: url(['apiv2_cursus_presence_evidence_delete', {id: processable[0].id}]),
request: {
method: 'DELETE'
},
success: () => refresher.delete(processable)
},
group: trans('management'),
scope: ['object']
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {PropTypes as T} from 'prop-types'

import omit from 'lodash/omit'
import classes from 'classnames'
import isEmpty from 'lodash/isEmpty'
import isNull from 'lodash/isNull'
import {trans} from '#/main/app/intl/translation'

import {CALLBACK_BUTTON} from '#/main/app/buttons'
Expand All @@ -15,28 +15,28 @@ import {actions} from '#/plugin/cursus/modals/presence/evidences/store'
import {FileThumbnail} from '#/main/app/data/types/file/components/thumbnail'

const EvidenceModalComponent = (props) => {
const [files, setFiles] = useState([])
const [file, setFile] = useState(null)

return (
<Modal
{...omit(props, 'parent', 'add', 'editable', 'createFiles')}
{...omit(props, 'parent', 'add', 'editable', 'createFile', 'onSuccess')}
icon={classes('fa fa-fw', {
'fa-file-upload': props.editable,
'fa-file-lines': !props.editable
})}
title={trans(props.editable ? 'add_evidences' : 'evidences', {}, 'presence')}
title={trans(props.editable ? 'add_evidence' : 'evidence', {}, 'presence')}
>
<div className="modal-body">
{props.editable &&
<DataInput
id="add-evidences-files"
id="add-evidence-file"
type="file"
label={trans('files')}
value={files}
onChange={setFiles}
value={file}
onChange={setFile}
required={true}
options={{
multiple: true,
multiple: false,
autoUpload: false
}}
/>
Expand All @@ -59,8 +59,8 @@ const EvidenceModalComponent = (props) => {
type={CALLBACK_BUTTON}
primary={true}
label={trans('add', {}, 'actions')}
disabled={isEmpty(files)}
callback={() => props.createFiles(props.parent, files, () => {
disabled={isNull(file)}
callback={() => props.createFile(props.parent, file, () => {
props.onSuccess()
props.fadeModal()
})}
Expand All @@ -74,15 +74,15 @@ EvidenceModalComponent.propTypes = {
parent: T.object.isRequired,
editable: T.bool.isRequired,
onSuccess: T.func.isRequired,
createFiles: T.func.isRequired,
createFile: T.func.isRequired,
fadeModal: T.func.isRequired
}

const EvidenceModal = connect(
null,
(dispatch) => ({
createFiles(parent, files, callback) {
dispatch(actions.createFiles(parent, files, callback))
createFile(parent, file, callback) {
dispatch(actions.createFile(parent, file, callback))
}
})
)(EvidenceModalComponent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {API_REQUEST} from '#/main/app/api'
export const actions = {}

actions.createFiles = (presence, files, onSuccess) => {
actions.createFile = (presence, file, onSuccess) => {
const formData = new FormData()
files.forEach((file, index) => formData.append(index, file))
formData.append(0, file)

return ({
[API_REQUEST]: {
url: ['apiv2_cursus_presence_evidences_upload', {id: presence.id}],
url: ['apiv2_cursus_presence_evidence_upload', {id: presence.id}],
type: 'upload',
request: {
method: 'POST',
Expand Down
3 changes: 2 additions & 1 deletion src/plugin/cursus/Resources/modules/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ registry.add('ClarolineCursusBundle', {
'mark-absent-unjustified': () => { return import(/* webpackChunkName: "training-action-presence-absent-unjustified" */ '#/plugin/cursus/actions/presence/mark-absent-unjustified') },
'mark-absent-present' : () => { return import(/* webpackChunkName: "training-action-presence-present" */ '#/plugin/cursus/actions/presence/mark-present') },
'mark-unknown' : () => { return import(/* webpackChunkName: "training-action-presence-unknown" */ '#/plugin/cursus/actions/presence/mark-unknown') },
'add-evidence' : () => { return import(/* webpackChunkName: "training-action-presence-add-evidence" */ '#/plugin/cursus/actions/presence/add-evidence') }
'add-evidence' : () => { return import(/* webpackChunkName: "training-action-presence-add-evidence" */ '#/plugin/cursus/actions/presence/add-evidence') },
'delete-evidence' : () => { return import(/* webpackChunkName: "training-action-presence-delete-evidence" */ '#/plugin/cursus/actions/presence/delete-evidence') }
}
},

Expand Down
41 changes: 13 additions & 28 deletions src/plugin/cursus/Resources/modules/presence/components/list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import omit from 'lodash/omit'
import merge from 'lodash/merge'
import classes from 'classnames'

import {trans, transChoice} from '#/main/app/intl/translation'
import {trans} from '#/main/app/intl/translation'
import {Button} from '#/main/app/action'
import {constants} from '#/plugin/cursus/constants'
import {MODAL_BUTTON, DOWNLOAD_BUTTON} from '#/main/app/buttons'
import {DOWNLOAD_BUTTON} from '#/main/app/buttons'
import {ListData} from '#/main/app/content/list/containers/data'
import {actions as listActions} from '#/main/app/content/list/store'
import {MODAL_EVIDENCE} from '#/plugin/cursus/modals/presence/evidences'
import {selectors as securitySelectors} from '#/main/app/security/store'
import {getActions, getDefaultAction} from '#/plugin/cursus/presence/utils'

Expand Down Expand Up @@ -69,34 +68,20 @@ const Presences = props => {
}, {
name: 'evidences',
type: 'number',
label: trans('evidences', {}, 'presence'),
label: trans('evidence', {}, 'presence'),
displayed: true,
render: (row) => {
if (row.evidences && row.evidences.length > 0) {
if( row.evidences.length === 1) {
return (
<Button
className="btn btn-link"
type={DOWNLOAD_BUTTON}
label={(transChoice('evidence_count', 1, {count: 1}, 'presence') )}
file={{url: ['apiv2_cursus_presence_evidence_download', {id: row.id, file: row.evidences[0]}]}}
/>
)
} else {
return (
<Button
className="btn btn-link"
type={MODAL_BUTTON}
label={(transChoice('evidence_count', row.evidences.length, { count: row.evidences.length }, 'presence') )}
modal={[MODAL_EVIDENCE, {
parent: row,
editable: false
}]}
/>
)
}
if (row.evidences && row.evidences.length === 1) {
return (
<Button
className="btn btn-link"
type={DOWNLOAD_BUTTON}
label={trans('download_evidence', {}, 'presence')}
file={{url: ['apiv2_cursus_presence_evidence_download', {id: row.id, file: row.evidences[0]}]}}
/>
)
} else {
return transChoice('evidence_count', 0, { count: 0 }, 'presence')
return trans('no_evidence', {}, 'presence')
}
}
}, {
Expand Down
13 changes: 10 additions & 3 deletions src/plugin/cursus/Resources/translations/presence.en.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"add_evidences": "Add evidence",
"add_evidence": "Add evidence",
"evidence": "Evidence",
"evidences": "Evidences",
"evidence_count": "{0} No evidence | {1} 1 evidence | ]1,Inf[ %count% evidences",

"show_evidence": "Show evidence",

"download_evidence": "Download evidence",
"no_evidence": "No evidence",

"delete_evidence": "Delete evidence",
"delete_evidence_message": "Are you sure you want to delete this evidence?",

"event_not_found": "Event not found",
"event_not_found_desc": "This code does not correspond to any event.",
"event_not_found_retry": "Enter again event code",
Expand Down
13 changes: 10 additions & 3 deletions src/plugin/cursus/Resources/translations/presence.fr.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"add_evidences": "Ajouter un justificatif",
"add_evidence": "Ajouter un justificatif",
"evidence": "Justificatif",
"evidences": "Justificatifs",
"evidence_count": "{0} Aucun justificatif | {1} 1 justificatif | ]1,Inf[ %count% justificatifs",

"show_evidence": "Afficher le justificatif",

"download_evidence": "Télécharger le justificatif",
"no_evidence": "Aucun justificatif",

"delete_evidence": "Supprimer le justificatif",
"delete_evidence_message": "Êtes-vous sûr de vouloir supprimer ce justificatif ?",

"event_not_found": "Séance introuvable",
"event_not_found_desc": "Ce code ne correspond à aucune séance.",
"event_not_found_retry": "Saisir à nouveau le code de la séance",
Expand Down

0 comments on commit deedd2f

Please sign in to comment.