Skip to content

Commit

Permalink
course creation
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed May 14, 2024
1 parent 7b39454 commit 36cb35c
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,9 @@ const CourseCreationComponent = (props) =>
}]}
title={trans('trainings', {}, 'tools')}
subtitle={trans('new_course', {}, 'cursus')}
primaryAction="add"
actions={[{
name: 'add',
type: LINK_BUTTON,
icon: 'fa fa-fw fa-plus',
label: trans('add_course', {}, 'cursus'),
target: props.path,
group: trans('management'),
primary: true
}]}
>
<CourseForm
contextType={props.contextType}
path={props.path}
name={selectors.FORM_NAME}
/>
Expand Down
50 changes: 50 additions & 0 deletions src/plugin/cursus/Resources/modules/course/components/empty.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react'
import {PropTypes as T} from 'prop-types'

import {trans} from '#/main/app/intl/translation'
import {LINK_BUTTON} from '#/main/app/buttons'
import {ToolPage} from '#/main/core/tool/containers/page'
import {Button} from '#/main/app/action/components/button'
import {ContentSizing} from '#/main/app/content/components/sizing'
import {ContentPlaceholder} from '#/main/app/content/components/placeholder'

const EmptyCourse = (props) =>
<ToolPage
primaryAction="add"
actions={[
{
name: 'add',
type: LINK_BUTTON,
icon: 'fa fa-fw fa-plus',
label: trans('add_course', {}, 'cursus'),
target: `${props.path}/new`,
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')}
/>
<Button
className="btn btn-primary w-100 my-3"
size="lg"
type={LINK_BUTTON}
target={`${props.path}/new`}
label={trans('add_course', {}, 'cursus')}
/>
</ContentSizing>
</ToolPage>

EmptyCourse.propTypes = {
path: T.string.isRequired,
canEdit: T.bool.isRequired
}

export {
EmptyCourse
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ const CourseParameters = (props) => {
className="mt-3"
name={props.name}
buttons={true}
locked={'workspace' === props.contextType ? ['workspace', '_workspaceType'] : []}
save={{
type: CALLBACK_BUTTON,
callback: () => props.save(props.course, props.isNew, props.name).then(course => {
if (props.isNew) {
history.push(route(course))
if ('workspace' === props.contextType) {
history.push(props.path)
} else {
history.push(route(course))
}
}
})
}}
Expand Down Expand Up @@ -281,7 +286,8 @@ CourseParameters.propTypes = {
course: T.shape(
CourseTypes.propTypes
),
update: T.func.isRequired
update: T.func.isRequired,
contextType: T.string.isRequired
}

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ const CourseRegistration = (props) => {
type: CALLBACK_BUTTON,
callback: () => props.save(props.course, props.isNew, props.name).then(course => {
if (props.isNew) {
history.push(route(course))
if ('workspace' === props.contextType) {
history.push(props.path)
} else {
history.push(route(course))
}
}
})
}}
Expand Down Expand Up @@ -166,7 +170,8 @@ CourseRegistration.propTypes = {
course: T.shape(
CourseTypes.propTypes
),
update: T.func.isRequired
update: T.func.isRequired,
contextType: T.string.isRequired
}

export {
Expand Down
9 changes: 8 additions & 1 deletion src/plugin/cursus/Resources/modules/course/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ actions.open = (courseSlug, force = false) => (dispatch, getState) => {
}
}

actions.openForm = (courseSlug = null, defaultProps = {}) => (dispatch) => {
actions.openForm = (courseSlug = null, defaultProps = {}, workspace = null) => (dispatch) => {
if (!courseSlug) {
if(workspace) {
defaultProps = {
...defaultProps,
_workspaceType: 'workspace',
workspace: workspace
}
}
return dispatch(formActions.resetForm(selectors.FORM_NAME, defaultProps, true))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import get from 'lodash/get'
import {PropTypes as T} from 'prop-types'

import {Routes} from '#/main/app/router'

import {Course} from '#/plugin/cursus/course/containers/main'
import {Course as CourseTypes} from '#/plugin/cursus/prop-types'
import {CourseCreation} from '#/plugin/cursus/course/components/creation'

import {EmptyCourse} from '#/plugin/cursus/course/components/empty'
import {EventsAll} from '#/plugin/cursus/tools/events/components/all'
import {EventsPublic} from '#/plugin/cursus/tools/events/components/public'
import {EventsDetails} from '#/plugin/cursus/tools/events/containers/details'
Expand All @@ -19,15 +22,29 @@ const EventsTool = (props) =>
]}
routes={[
{
path: '/new',
onEnter: () => props.openForm(null, CourseTypes.defaultProps, props.currentContext.data),
disabled: !props.canEdit,
component: CourseCreation
}, {
path: '/about',
onEnter: () => props.openCourse(props.course.slug),
render: (params = {}) => (
<Course
path={props.path+'/about'}
slug={props.course.slug}
history={params.history}
/>
)
onEnter: () => {
if (props.course) {
return props.openCourse(props.course.slug)
}
},
render: (params = {}) => {
if (props.course) {
return (
<Course
path={props.path + '/about'}
slug={props.course.slug}
history={params.history}
/>)
} else {
return (<EmptyCourse path={props.path} canEdit={props.canEdit}/>)
}
}
}, {
path: '/registered',
onEnter: props.invalidateList,
Expand All @@ -50,13 +67,13 @@ const EventsTool = (props) =>
}, {
path: '/all',
onEnter: props.invalidateList,
disabled: !props.canEdit && !props.canRegister,
render: () => (
<EventsAll
path={props.path}
contextId={get(props.currentContext, 'data.id')}
/>
),
disabled: !props.canEdit && !props.canRegister
)
}, {
path: '/presences',
component: EventsPresences
Expand All @@ -68,6 +85,7 @@ const EventsTool = (props) =>
]}
/>


EventsTool.propTypes = {
path: T.string.isRequired,
currentContext: T.shape({
Expand All @@ -78,6 +96,7 @@ EventsTool.propTypes = {
canRegister: T.bool.isRequired,
invalidateList: T.func.isRequired,
open: T.func.isRequired,
openForm: T.func.isRequired,
openCourse: T.func,
course: T.shape({
slug: T.string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,37 @@ import {withReducer} from '#/main/app/store/reducer'

import {selectors} from '#/plugin/cursus/tools/events/store'
import {selectors as toolSelectors} from '#/main/core/tool/store'

import {actions as listActions} from '#/main/app/content/list/store'
import {actions as courseActions} from '#/plugin/cursus/course/store'

import {EventsTool as EventsToolComponent} from '#/plugin/cursus/tools/events/components/tool'
import {actions as eventActions, reducer as eventReducer, selectors as eventSelectors} from '#/plugin/cursus/event/store'

import {actions as eventActions, reducer as eventReducer, selectors as eventSelectors} from '#/plugin/cursus/event/store'
import {actions as courseActions, reducer as courseReducer, selectors as courseSelectors} from '#/plugin/cursus/course/store'

const EventsTool = withReducer(eventSelectors.STORE_NAME, eventReducer)( // not the best place to do it
connect(
(state) => ({
path: toolSelectors.path(state),
course: selectors.course(state),
currentContext: toolSelectors.context(state),
canEdit: hasPermission('edit', toolSelectors.toolData(state)),
canRegister: hasPermission('register', toolSelectors.toolData(state))
}),
(dispatch) => ({
open(id) {
dispatch(eventActions.open(id))
},
openCourse(slug) {
dispatch(courseActions.open(slug))
},
invalidateList() {
dispatch(listActions.invalidateData(selectors.LIST_NAME))
}
})
)(EventsToolComponent)
const EventsTool = withReducer(courseSelectors.STORE_NAME, courseReducer)(
withReducer(eventSelectors.STORE_NAME, eventReducer)(
connect(
(state) => ({
path: toolSelectors.path(state),
course: selectors.course(state),
currentContext: toolSelectors.context(state),
canEdit: hasPermission('edit', toolSelectors.toolData(state)),
canRegister: hasPermission('register', toolSelectors.toolData(state))
}),
(dispatch) => ({
open(id) {
dispatch(eventActions.open(id))
},
openCourse(slug) {
dispatch(courseActions.open(slug))
},
openForm(slug, defaultProps, workspace) {
dispatch(courseActions.openForm(slug, defaultProps, workspace))
},
invalidateList() {
dispatch(listActions.invalidateData(selectors.LIST_NAME))
}
})
)(EventsToolComponent)
)
)

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {makeListReducer} from '#/main/app/content/list/store'
import {makeReducer, combineReducers} from '#/main/app/store/reducer'

import {TOOL_LOAD} from '#/main/core/tool/store'
import {FORM_SUBMIT_SUCCESS} from '#/main/app/content/form/store'
import {selectors} from '#/plugin/cursus/tools/events/store/selectors'
import {selectors as courseSelectors} from '#/plugin/cursus/course/store'

const reducer = combineReducers({
events: makeListReducer(selectors.LIST_NAME, {
Expand All @@ -15,8 +17,9 @@ const reducer = combineReducers({
}),
course: makeReducer({}, {
[makeInstanceAction(TOOL_LOAD, selectors.STORE_NAME)]: (state, action) => {
return action.toolData.course
}
return typeof action.toolData.course !== 'undefined' ? action.toolData.course : null
},
[FORM_SUBMIT_SUCCESS+'/'+courseSelectors.FORM_NAME]: (state, action) => action.updatedData
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import {hasPermission} from '#/main/app/security'
import {withReducer} from '#/main/app/store/reducer'

import {selectors as toolSelectors} from '#/main/core/tool/store'
import {actions as courseActions} from '#/plugin/cursus/course/store'
import {reducer, selectors} from '#/plugin/cursus/tools/trainings/catalog/store'
import {CatalogMain as CatalogMainComponent} from '#/plugin/cursus/tools/trainings/catalog/components/main'
import {actions as courseActions, reducer as courseReducer, selectors as courseSelectors} from '#/plugin/cursus/course/store'

const CatalogMain = withReducer(selectors.STORE_NAME, reducer)(
connect(
(state) => ({
path: toolSelectors.path(state),
course: selectors.course(state),
canEdit: hasPermission('edit', toolSelectors.toolData(state))
}),
(dispatch) => ({
open(slug) {
dispatch(courseActions.open(slug))
},
openForm(slug, defaultProps) {
dispatch(courseActions.openForm(slug, defaultProps))
}
})
)(CatalogMainComponent)
const CatalogMain = withReducer(courseSelectors.STORE_NAME, courseReducer)(
withReducer(selectors.STORE_NAME, reducer)(
connect(
(state) => ({
path: toolSelectors.path(state),
course: selectors.course(state),
canEdit: hasPermission('edit', toolSelectors.toolData(state))
}),
(dispatch) => ({
open(slug) {
dispatch(courseActions.open(slug))
},
openForm(slug, defaultProps) {
dispatch(courseActions.openForm(slug, defaultProps))
}
})
)(CatalogMainComponent)
)
)

export {
Expand Down
1 change: 1 addition & 0 deletions src/plugin/cursus/Resources/translations/cursus.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"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_session": "No session",
"session_info": "Session information",
"download_presence": "Download the certificate of presence (.pdf)",
Expand Down
1 change: 1 addition & 0 deletions src/plugin/cursus/Resources/translations/cursus.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"export-presences-empty": "Télécharger la liste de présences (vide)",
"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_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 36cb35c

Please sign in to comment.