Skip to content

Commit

Permalink
pr review 2
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Sep 4, 2024
1 parent 99668a7 commit feeb62a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 51 deletions.
32 changes: 9 additions & 23 deletions src/plugin/cursus/Controller/CourseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,37 +106,23 @@ protected function getDefaultHiddenFilters(): array
}
}

return $filters;
}

/**
* @Route("/", name="apiv2_cursus_course_list", methods={"GET"})
*/
public function listAction(Request $request): JsonResponse
{
$params = $request->query->all();
$params['hiddenFilters'] = [
'archived' => false,
];
$filters['archived'] = false;

return new JsonResponse(
$this->crud->list(Course::class, $params)
);
return $filters;
}

/**
* @Route("/public", name="apiv2_cursus_course_list_public", methods={"GET"})
*/
public function listPublicAction(Request $request): JsonResponse
{
$params = $request->query->all();
$params['hiddenFilters'] = [
'public' => true,
];

return new JsonResponse(
$this->crud->list(Course::class, $params)
);
return new JsonResponse($this->crud->list(
Course::class,
array_merge($request->query->all(), ['hiddenFilters' => array_merge($this->getDefaultHiddenFilters(), [
'public' => true,
])]),
$this->getOptions()['list']
));
}

/**
Expand Down
17 changes: 8 additions & 9 deletions src/plugin/cursus/Resources/modules/course/components/type.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const CreationType = (props) => {
if (props.modal) {
props.fadeModal()
}
history.push(props.path + '/course/new')
props.startCreation(null, CourseTypes.defaultProps, selected[0])
history.push(props.path + '/new')
props.openForm(null, CourseTypes.defaultProps, selected[0])
}
}
)
Expand All @@ -58,8 +58,8 @@ const CreationType = (props) => {
if (props.modal) {
props.fadeModal()
}
history.push(props.path + '/course/new')
props.startCreation(null, CourseTypes.defaultProps, selected[0])
history.push(props.path + '/new')
props.openForm(null, CourseTypes.defaultProps, selected[0])
}
}
)
Expand All @@ -76,8 +76,8 @@ const CreationType = (props) => {
if (props.modal) {
props.fadeModal()
}
history.push(props.path + '/course/new')
props.startCreation(null, CourseTypes.defaultProps)
history.push(props.path + '/new')
props.openForm(null, CourseTypes.defaultProps)
}
}
}, {
Expand Down Expand Up @@ -118,11 +118,10 @@ const CreationType = (props) => {
}

CreationType.propTypes = {
startCreation: T.func,
create: T.func,
path: T.string.isRequired,
openForm: T.func.isRequired,
reset: T.func,
contextType: T.string,
path: T.string.isRequired,
modal: T.bool,
fadeModal: T.func
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,27 @@ import {CreationType} from '#/plugin/cursus/course/components/type'

const CreationModal = (props) =>
<Modal
{...omit(props, 'create', 'startCreation')}
{...omit(props, 'openForm')}
title={trans('new_course', {}, 'cursus')}
subtitle={trans('')}
centered={true}
onExited={props.reset}
>
<div className="modal-body">
<CreationType {...props} modal={true}/>
<CreationType
path={props.path}
contextType={props.contextType}
openForm={props.openForm}
fadeModal={props.fadeModal}
modal={true}
/>
</div>
</Modal>

CreationModal.propTypes = {
startCreation: T.func.isRequired,
create: T.func.isRequired,
path: T.string.isRequired,
contextType: T.string.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 @@ -14,7 +14,7 @@ const CreationModal = withReducer(selectors.STORE_NAME, reducer)(
contextType: toolSelectors.contextType(state)
}),
(dispatch) => ({
startCreation(slug, defaultProps, workspace) {
openForm(slug, defaultProps, workspace = null) {
dispatch(courseActions.openForm(slug, defaultProps, workspace))
},
reset() {
Expand Down
20 changes: 12 additions & 8 deletions src/plugin/cursus/Resources/modules/course/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ actions.openForm = (courseSlug = null, defaultProps = {}, workspace = null) => (
return dispatch(formActions.resetForm(selectors.FORM_NAME, defaultProps, true))
}

return dispatch({
[API_REQUEST]: {
url: ['apiv2_cursus_course_get', {field: 'slug', id: courseSlug}],
silent: true,
before: () => dispatch(formActions.resetForm(selectors.FORM_NAME, null, true)),
success: (data) => dispatch(formActions.resetForm(selectors.FORM_NAME, data))
}
})
if (courseSlug) {
return dispatch({
[API_REQUEST]: {
url: ['apiv2_cursus_course_get', {field: 'slug', id: courseSlug}],
silent: true,
before: () => dispatch(formActions.resetForm(selectors.FORM_NAME, null, true)),
success: (data) => dispatch(formActions.resetForm(selectors.FORM_NAME, data))
}
})
} else {
return dispatch(formActions.resetForm(selectors.FORM_NAME, defaultProps, true))
}
}

actions.openSession = (sessionId = null, force = false) => (dispatch, getState) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ const EventsTool = (props) =>
history={params.history}
/>)
} else {
return (<EmptyCourse path={props.path} canEdit={props.canEdit} contextType={props.contextType} />)
return (
<EmptyCourse
path={props.path}
canEdit={props.canEdit}
contextType={props.contextType}
/>
)
}
}
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const CatalogList = (props) =>
icon: 'fa fa-fw fa-plus',
label: trans('add_course', {}, 'cursus'),
modal: [MODAL_COURSE_TYPE_CREATION, {
path: props.path
path: props.path + '/course'
}],
group: trans('management'),
displayed: props.canEdit,
Expand All @@ -40,8 +40,9 @@ const CatalogList = (props) =>
url={['apiv2_cursus_course_list']}
>
<CreationType
path={props.path}
path={props.path + '/course'}
contextType={props.contextType}
openForm={props.openForm}
/>
</CourseList>

Expand All @@ -50,7 +51,8 @@ const CatalogList = (props) =>
CatalogList.propTypes = {
path: T.string.isRequired,
canEdit: T.bool.isRequired,
contextType: T.string
contextType: T.string,
openForm: T.func.isRequired
}

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const CatalogMain = (props) =>
path={props.path}
canEdit={props.canEdit}
contextType={props.contextType}
openForm={props.openForm}
/>
)
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const CatalogMain = withReducer(courseSelectors.STORE_NAME, courseReducer)(
open(slug) {
dispatch(courseActions.open(slug))
},
openForm(slug, defaultProps) {
dispatch(courseActions.openForm(slug, defaultProps))
openForm(slug, defaultProps, workspace = null) {
dispatch(courseActions.openForm(slug, defaultProps, workspace))
}
})
)(CatalogMainComponent)
Expand Down

0 comments on commit feeb62a

Please sign in to comment.