Skip to content

Commit

Permalink
CreationType copy
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Sep 11, 2024
1 parent 413a0c5 commit e36fbab
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 38 deletions.
14 changes: 13 additions & 1 deletion src/plugin/cursus/Controller/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Claroline\CoreBundle\Component\Context\DesktopContext;
use Claroline\CoreBundle\Entity\Organization\Organization;
use Claroline\CoreBundle\Entity\User;
use Claroline\CoreBundle\Entity\Workspace\Workspace;
use Claroline\CoreBundle\Library\Normalizer\TextNormalizer;
use Claroline\CoreBundle\Library\RoutingHelper;
use Claroline\CoreBundle\Manager\Tool\ToolManager;
Expand Down Expand Up @@ -214,14 +215,25 @@ public function copyAction(Request $request): JsonResponse

$data = $this->decodeRequest($request);

$workspaceData = $data['workspace'] ?? null;
$workspace = null;

if ($workspaceData) {
$workspace = $this->om->getRepository(Workspace::class)->findOneBy(['uuid' => $data['workspace']['id']]);
}

/** @var Course[] $courses */
$courses = $this->om->getRepository(Course::class)->findBy([
'uuid' => $data['ids'],
]);

foreach ($courses as $course) {
if ($this->authorization->isGranted('ADMINISTRATE', $course)) {
$processed[] = $this->crud->copy($course);
$copy = $this->crud->copy($course);
if (1 === count($courses) && $workspace) {
$copy->setWorkspace($workspace);
}
$processed[] = $copy;
}
}

Expand Down
19 changes: 8 additions & 11 deletions src/plugin/cursus/Resources/modules/course/components/empty.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {trans} from '#/main/app/intl/translation'

import {ContentSizing} from '#/main/app/content/components/sizing'
import {CreationType} from '#/plugin/cursus/course/components/type'
import {ContentPlaceholder} from '#/main/app/content/components/placeholder'
import {MODAL_COURSE_TYPE_CREATION} from '#/plugin/cursus/course/modals/creation'

const EmptyCourse = (props) =>
Expand All @@ -20,23 +19,21 @@ const EmptyCourse = (props) =>
icon: 'fa fa-fw fa-plus',
label: trans('add_course', {}, 'cursus'),
modal: [MODAL_COURSE_TYPE_CREATION, {
path: props.path
path: props.path,
contextId: props.contextId
}],
group: trans('management'),
displayed: props.canEdit,
primary: true
}
]}
>
<ContentSizing size="lg" className="mt-4">
<ContentPlaceholder
size="lg"
title={trans('no_course', {}, 'cursus')}
help={trans('no_course_help', {}, 'cursus')}
/>
</ContentSizing>

<ContentSizing size="md" className="mt-4">
<ContentSizing size="md">
<p className="text-center my-5">
<span className="h1 fa fa-bullseye mb-3 text-body-tertiary"/>
<b className="h5 d-block">{trans('no_course', {}, 'cursus')}</b>
<span className="text-body-secondary">{trans('no_course_help', {}, 'cursus')}</span>
</p>
<CreationType {...props} />
</ContentSizing>

Expand Down
63 changes: 38 additions & 25 deletions src/plugin/cursus/Resources/modules/course/components/type.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import React from 'react'
import {PropTypes as T} from 'prop-types'
import {useHistory} from 'react-router-dom'

import {url} from '#/main/app/api'
import {trans} from '#/main/app/intl'
import {ContentMenu} from '#/main/app/content/components/menu'
import {ASYNC_BUTTON, CALLBACK_BUTTON, MODAL_BUTTON} from '#/main/app/buttons'

import {MODAL_WORKSPACES} from '#/main/core/modals/workspaces'
import {ContentMenu} from '#/main/app/content/components/menu'
import {CALLBACK_BUTTON, MODAL_BUTTON} from '#/main/app/buttons'
import {Course as CourseTypes} from '#/plugin/cursus/prop-types'
import {MODAL_TRAINING_COURSES} from '#/plugin/cursus/modals/courses'

const CreationType = (props) => {
const history = useHistory()
const handleNavigation = (props, history, workspace = null, course = null) => {
if (props.modal) {
props.fadeModal()
}
if (course) {
history.push(`${props.path}/${course.slug}`)
} else {
history.push(props.path + '/new')
props.openForm(null, CourseTypes.defaultProps, workspace)
}
}

return (
<ContentMenu
Expand All @@ -29,13 +43,7 @@ const CreationType = (props) => {
selectAction: (selected) => (
{
type: CALLBACK_BUTTON,
callback: () => {
if (props.modal) {
props.fadeModal()
}
history.push(props.path + '/new')
props.openForm(null, CourseTypes.defaultProps, selected[0])
}
callback: () => handleNavigation(props, history, selected[0])
}
)
}]
Expand All @@ -54,13 +62,7 @@ const CreationType = (props) => {
selectAction: (selected) => (
{
type: CALLBACK_BUTTON,
callback: () => {
if (props.modal) {
props.fadeModal()
}
history.push(props.path + '/new')
props.openForm(null, CourseTypes.defaultProps, selected[0])
}
callback: () => handleNavigation(props, history, selected[0])
}
)
}]
Expand All @@ -72,13 +74,7 @@ const CreationType = (props) => {
description: trans('create_mode_empty_desc', {}, 'cursus'),
action: {
type: CALLBACK_BUTTON,
callback: () => {
if (props.modal) {
props.fadeModal()
}
history.push(props.path + '/new')
props.openForm(null, CourseTypes.defaultProps)
}
callback: () => handleNavigation(props, history)
}
}, {
id: 'create-from-copy',
Expand All @@ -87,7 +83,23 @@ const CreationType = (props) => {
description: trans('create_mode_copy_desc', {}, 'cursus'),
action: {
type: MODAL_BUTTON,
modal: []
modal: [MODAL_TRAINING_COURSES, {
selectAction: (selected) => ({
type: ASYNC_BUTTON,
label: trans('copy', {}, 'actions'),
request: {
url: url(['apiv2_cursus_course_copy']),
request: {
method: 'POST',
body: JSON.stringify({
ids: selected.length ? [selected[selected.length - 1].id] : [],
workspace: props.contextId
})
},
success: (course) => handleNavigation(props, history, null, course[0])
}
})
}]
},
group: trans('create_mode_group_existing', {}, 'cursus')
}, {
Expand Down Expand Up @@ -119,9 +131,10 @@ const CreationType = (props) => {

CreationType.propTypes = {
path: T.string.isRequired,
openForm: T.func.isRequired,
openForm: T.func,
reset: T.func,
contextType: T.string,
contextId: T.object,
modal: T.bool,
fadeModal: T.func
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const CreationModal = (props) =>
<CreationType
path={props.path}
contextType={props.contextType}
contextId={props.contextId}
openForm={props.openForm}
fadeModal={props.fadeModal}
modal={true}
Expand All @@ -29,6 +30,7 @@ const CreationModal = (props) =>
CreationModal.propTypes = {
path: T.string.isRequired,
contextType: T.string.isRequired,
contextId: T.object.isRequired,
openForm: T.func.isRequired,
reset: T.func.isRequired,
fadeModal: T.func.isRequired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const EventsTool = (props) =>
path={props.path}
canEdit={props.canEdit}
contextType={props.contextType}
contextId={props.currentContext.data}
openForm={props.openForm}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ const CatalogList = (props) =>
name={selectors.LIST_NAME}
url={['apiv2_cursus_course_list']}
>
<p className="text-center my-5 mt-1">
<span className="h1 fa fa-bullseye mb-3 text-body-tertiary" />
<b className="h5 d-block">{trans('no_courses', {}, 'cursus')}</b>
<span className="text-body-secondary">{trans('no_courses_help', {}, 'cursus')}</span>
</p>
<CreationType
path={props.path + '/course'}
contextType={props.contextType}
Expand Down
4 changes: 3 additions & 1 deletion src/plugin/cursus/Resources/translations/cursus.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@
"export-presences-empty": "Download the attendance list (empty)",
"export-presences-filled": "Download the attendance list (filled)",
"no_course": "No training",
"no_course_help": "No training is linked to this workspace",
"no_course_help": "No trainings is linked to this workspace",
"no_courses": "No training",
"no_courses_help": "The training catalog is empty.",
"no_session": "No session",
"session_info": "Session information",
"download_presence": "Download the certificate of presence (.pdf)",
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/cursus/Resources/translations/cursus.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
"export-presences-filled": "Télécharger la liste de présences (remplie)",
"no_course": "Aucune formation",
"no_course_help": "Aucune formation n'est liée à cet espace d'activités",
"no_courses": "Aucune formations",
"no_courses_help": "Le catalogue de formations est vide.",
"no_session": "Aucune session",
"session_info": "Informations sur la session",
"download_presence": "Télécharger l'attestation de présence (.pdf)",
Expand Down

0 comments on commit e36fbab

Please sign in to comment.