Skip to content

Commit

Permalink
pr review
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Sep 17, 2024
1 parent 836ee87 commit ba44622
Show file tree
Hide file tree
Showing 18 changed files with 271 additions and 174 deletions.
4 changes: 2 additions & 2 deletions src/main/theme/Entity/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class Theme
/**
* @ORM\Column(nullable=true)
*/
private ?string $primaryColor;
private ?string $primaryColor = null;

/**
* @ORM\Column(nullable=true)
*/
private ?string $secondaryColor;
private ?string $secondaryColor= null;

public function __construct()
{
Expand Down
57 changes: 27 additions & 30 deletions src/plugin/cursus/Controller/SessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Claroline\CoreBundle\Component\Context\DesktopContext;
use Claroline\CoreBundle\Entity\Group;
use Claroline\CoreBundle\Entity\Organization\Organization;
use Claroline\CoreBundle\Entity\Template\Template;
use Claroline\CoreBundle\Entity\User;
use Claroline\CoreBundle\Library\Normalizer\TextNormalizer;
use Claroline\CoreBundle\Library\RoutingHelper;
Expand Down Expand Up @@ -164,45 +163,43 @@ public function copyAction(Request $request): JsonResponse
}

/**
* @Route("/cancel", name="cancel", methods={"POST"})
* @Route("/{id}/list/canceled", name="list_canceled", methods={"GET"})
*
* @EXT\ParamConverter("course", class="Claroline\CursusBundle\Entity\Course", options={"mapping": {"id": "uuid"}})
*/
public function cancelAction(Request $request): JsonResponse
public function listCanceledAction(Course $course, Request $request): JsonResponse
{
$processed = [];
$this->checkPermission('EDIT', $course, [], true);

$this->om->startFlushSuite();

$data = $this->decodeRequest($request);
$filters = $request->query->all();
$filters['hiddenFilters'] = $filters['hiddenFilters'] ?? [];

/** @var Session[] $sessions */
$sessions = $this->om->getRepository(Session::class)->findBy([
'uuid' => $data['ids'],
$filters['hiddenFilters'] = array_merge($filters['hiddenFilters'], [
'course' => $course->getUuid(),
'canceled' => true
]);

foreach ($sessions as $session) {
if ($this->authorization->isGranted('EDIT', $session) && !$session->isCanceled()) {
$session->setCanceled(true);
$session->setCancelReason($data['cancelReason'] ?? null);

$cancelTemplate = null;
$templateRepo = $this->om->getRepository(Template::class);
if (!empty($data['canceledTemplate']) && $data['canceledTemplate']['id']) {
$cancelTemplate = $templateRepo->findOneBy(['uuid' => $data['canceledTemplate']['id']]);
// if ($cancelTemplate) {
// $this->manager->sendSessionCancel($session);
// }
}
$session->setCanceledTemplate($cancelTemplate);

$processed[] = $session;
}
}
return new JsonResponse(
$this->crud->list(Session::class, $filters)
);
}

$this->om->endFlushSuite();
/**
* @Route("/cancel", name="cancel", methods={"POST"})
*/
public function cancelAction(Request $request): JsonResponse
{
$data = $this->decodeRequest($request);

$processedSessions = $this->manager->cancelSessions(
$data['ids'],
$data['cancelReason'] ?? null,
$data['canceledTemplate'] ?? null
);

return new JsonResponse(array_map(function (Session $session) {
return $this->serializer->serialize($session);
}, $processed));
}, $processedSessions));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/cursus/Entity/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Session extends AbstractTraining implements IdentifiableInterface
private bool $canceled = false;

/**
* @ORM\Column(name="cancel_reason", type="string", nullable=true)
* @ORM\Column(name="cancel_reason", type="text", nullable=true)
*/
private ?string $cancelReason = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function up(Schema $schema): void
ALTER TABLE claro_cursusbundle_course_session
ADD canceled_template_id INT DEFAULT NULL,
ADD canceled TINYINT(1) NOT NULL,
ADD cancel_reason VARCHAR(255) DEFAULT NULL
ADD cancel_reason LONGTEXT DEFAULT NULL
');
$this->addSql('
ALTER TABLE claro_cursusbundle_course_session
Expand Down
35 changes: 35 additions & 0 deletions src/plugin/cursus/Manager/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Claroline\AppBundle\Manager\PlatformManager;
use Claroline\AppBundle\Persistence\ObjectManager;
use Claroline\CoreBundle\Entity\Role;
use Claroline\CoreBundle\Entity\Template\Template;
use Claroline\CoreBundle\Entity\Workspace\Workspace;
use Claroline\CoreBundle\Event\CatalogEvents\MessageEvents;
use Claroline\CoreBundle\Event\SendMessageEvent;
Expand Down Expand Up @@ -510,6 +511,40 @@ public function sendSessionCancel(Session $session): void
}
}

public function cancelSessions(array $sessionIds, ?string $cancelReason = null, ?array $cancelTemplateData = null): array
{
$processed = [];

$this->om->startFlushSuite();

/** @var Session[] $sessions */
$sessions = $this->sessionRepo->findBy([
'uuid' => $sessionIds,
]);

foreach ($sessions as $session) {
if (!$session->isCanceled()) {
$session->setCanceled(true);
$session->setCancelReason($cancelReason);

$cancelTemplate = null;
if (!empty($cancelTemplateData['id'])) {
$cancelTemplate = $this->om->getRepository(Template::class)->findOneBy(['uuid' => $cancelTemplateData['id']]);
if ($cancelTemplate) {
$this->sendSessionCancel($session);
}
}

$session->setCanceledTemplate($cancelTemplate);
$processed[] = $session;
}
}

$this->om->endFlushSuite();

return $processed;
}

/**
* Register the user to the linked workspace and events if the registration is fully validated (confirmed and validated).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const CourseAbout = (props) => {
const courseRegistration = getCourseRegistration(props.registrations)

const availableSessions = props.availableSessions
.filter(session => (!props.activeSession || props.activeSession.id !== session.id) && !get(session, 'restrictions.hidden'))
.filter(session => (!props.activeSession || props.activeSession.id !== session.id) && !get(session, 'restrictions.hidden') && !get(session, 'meta.canceled'))

return (
<div className="row mt-3">
Expand Down Expand Up @@ -187,7 +187,9 @@ const CourseAbout = (props) => {

{get(props.activeSession, 'meta.canceled') === true &&
<AlertBlock type="info" title={trans('cancel_session_info', {}, 'actions')}>
{get(props.activeSession, 'meta.cancelReason')}
<ContentHtml>
{get(props.activeSession, 'meta.cancelReason')}
</ContentHtml>
</AlertBlock>
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import {PropTypes as T} from 'prop-types'

import {trans} from '#/main/app/intl'

import {EditorPage} from '#/main/app/editor'
import {selectors} from '#/plugin/cursus/course/store'
import {Course as CourseTypes} from '#/plugin/cursus/prop-types'
import {SessionList} from '#/plugin/cursus/session/components/list'

const CourseEditorCanceledSessions = (props) =>
<EditorPage
title={trans('canceled_sessions', {}, 'cursus')}
help={trans('canceled_sessions_help', {}, 'cursus')}
>
<SessionList
path={props.path}
course={props.course}
name={selectors.STORE_NAME+'.courseSessionsCanceled'}
url={['apiv2_cursus_session_list_canceled', {id: props.course.id}]}
/>
</EditorPage>

CourseEditorCanceledSessions.propTypes = {
path: T.string.isRequired,
course: T.shape(
CourseTypes.propTypes
).isRequired
}

export {
CourseEditorCanceledSessions
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, {useEffect} from 'react'
import get from 'lodash/get'
import {PropTypes as T} from 'prop-types'

Expand All @@ -13,50 +13,69 @@ import {CourseEditorActions} from '#/plugin/cursus/course/editor/components/acti
import {CourseEditorOverview} from '#/plugin/cursus/course/editor/components/overview'
import {CourseEditorAppearance} from '#/plugin/cursus/course/editor/components/appearance'
import {CourseEditorWorkspaces} from '#/plugin/cursus/course/editor/components/workspaces'
import {CourseEditorCanceledSessions} from '#/plugin/cursus/course/editor/components/list'
import {CourseEditorPermissions} from '#/plugin/cursus/course/editor/components/permissions'
import {CourseEditorRegistration} from '#/plugin/cursus/course/editor/components/registration'

import {selectors} from '#/plugin/cursus/course/store'

const CourseEditor = (props) =>
<Editor
path={route(props.course, null, props.path)+'/edit'}
title={get(props.course, 'name')}
name={selectors.FORM_NAME}
target={['apiv2_cursus_course_update', {id: props.course.id}]}
canAdministrate={hasPermission('administrate', props.course)}
close={props.path}
defaultPage="overview"
historyPage={CourseEditorHistory}
actionsPage={CourseEditorActions}
overviewPage={CourseEditorOverview}
appearancePage={CourseEditorAppearance}
permissionsPage={CourseEditorPermissions}
pages={[
{
name:'workspaces',
title: trans('workspaces'),
render: () => (
<CourseEditorWorkspaces
name={selectors.FORM_NAME}
course={props.course}
contextType={props.contextType}
update={props.update}
/>
)
}, {
name:'registration',
title: trans('registration'),
render: () => (
<CourseEditorRegistration
name={selectors.FORM_NAME}
course={props.course}
update={props.update}
/>
)
}
].concat(props.pages || [])}
/>
const CourseEditor = (props) => {

useEffect(() => {
props.openForm(props.slug)
}, [props.slug])

return (
<Editor
path={route(props.course, null, props.path) + '/edit'}
title={get(props.course, 'name')}
name={selectors.FORM_NAME}
target={['apiv2_cursus_course_update', {id: props.course.id}]}
canAdministrate={hasPermission('administrate', props.course)}
close={props.path}
defaultPage="overview"
historyPage={CourseEditorHistory}
actionsPage={CourseEditorActions}
overviewPage={CourseEditorOverview}
appearancePage={CourseEditorAppearance}
permissionsPage={CourseEditorPermissions}
pages={[
{
name: 'workspaces',
title: trans('workspaces'),
render: () => (
<CourseEditorWorkspaces
name={selectors.FORM_NAME}
course={props.course}
contextType={props.contextType}
update={props.update}
/>
)
}, {
name: 'registration',
title: trans('registration'),
render: () => (
<CourseEditorRegistration
name={selectors.FORM_NAME}
course={props.course}
update={props.update}
/>
)
}, {
name: 'canceled',
title: trans('canceled_sessions', {}, 'cursus'),
help: trans('canceled_sessions_help', {}, 'cursus'),
render: () => (
<CourseEditorCanceledSessions
path={props.path}
course={props.course}
/>
)
}
].concat(props.pages || [])}
/>
)
}

CourseEditor.propTypes = {
path: T.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ const CourseEditorOverview = () =>
primary: true,
fields: [
{
name: 'description',
name: 'plainDescription',
type: 'string',
label: trans('description_short'),
help: trans('course_short_desc_help', {}, 'cursus'),

}, {
name: 'description',
label: trans('description_long'),
type: 'html',
help: trans('course_long_desc_help', {}, 'cursus'),
options: {
long: true,
minRows: 2
}
}, {
name: 'plainDescription',
label: trans('description_long'),
type: 'html',
help: trans('course_long_desc_help', {}, 'cursus')
}, {
name: 'meta.duration',
type: 'number',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {connect} from 'react-redux'

import {withReducer} from '#/main/app/store/components/withReducer'

import {selectors as toolSelectors} from '#/main/core/tool'
import {reducer, selectors} from '#/plugin/cursus/course/store'
import {selectors as toolSelectors} from '#/main/core/tool'
import {actions as courseActions, reducer, selectors} from '#/plugin/cursus/course/store'
import {actions as formActions, selectors as formSelectors} from '#/main/app/content/form/store'

import {CourseEditor as CourseEditorComponent} from '#/plugin/cursus/course/editor/components/main'
Expand All @@ -16,6 +16,9 @@ const CourseEditor = withReducer(selectors.STORE_NAME, reducer)(
course: formSelectors.data(formSelectors.form(state, selectors.FORM_NAME))
}),
(dispatch) => ({
openForm(slug, defaultProps, workspace = null) {
dispatch(courseActions.openForm(slug, defaultProps, workspace))
},
update(name, prop, value) {
dispatch(formActions.updateProp(name, prop, value))
}
Expand Down
3 changes: 3 additions & 0 deletions src/plugin/cursus/Resources/modules/course/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const reducer = combineReducers({
[LOAD_COURSE]: () => true
})
}),
courseSessionsCanceled: makeListReducer(selectors.STORE_NAME+'.courseSessionsCanceled', {
sortBy: {property: 'order', direction: 1}
}),
courseEvents: makeListReducer(selectors.STORE_NAME+'.courseEvents', {
filters: [{property: 'status', value: 'not_ended'}],
sortBy: {property: 'startDate', direction: 1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default {
filterable: true
}, {
name: 'meta.canceled',
alias: 'canceled',
label: trans('canceled'),
type: 'boolean',
filterable: true,
Expand Down
Loading

0 comments on commit ba44622

Please sign in to comment.