Skip to content

Commit

Permalink
Creation types for trainings
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Aug 26, 2024
1 parent 4fece7a commit 18bfc89
Show file tree
Hide file tree
Showing 16 changed files with 307 additions and 31 deletions.
26 changes: 14 additions & 12 deletions src/plugin/cursus/Resources/modules/course/components/empty.jsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
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'
import {Button} from '#/main/app/action/components/button'
import {MODAL_BUTTON} from '#/main/app/buttons'
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) =>
<ToolPage
primaryAction="add"
actions={[
{
name: 'add',
type: LINK_BUTTON,
type: MODAL_BUTTON,
icon: 'fa fa-fw fa-plus',
label: trans('add_course', {}, 'cursus'),
target: `${props.path}/new`,
modal: [MODAL_COURSE_TYPE_CREATION, {
path: props.path
}],
group: trans('management'),
displayed: props.canEdit,
primary: true
Expand All @@ -30,14 +34,12 @@ const EmptyCourse = (props) =>
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>

<ContentSizing size="md" className="mt-4">
<CreationType {...props} />
</ContentSizing>

</ToolPage>

EmptyCourse.propTypes = {
Expand Down
130 changes: 130 additions & 0 deletions src/plugin/cursus/Resources/modules/course/components/type.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import React from 'react'
import {PropTypes as T} from 'prop-types'
import {useHistory} from 'react-router-dom'
import {trans} from '#/main/app/intl'

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'

const CreationType = (props) => {
const history = useHistory()

return (
<ContentMenu
className="mb-3"
items={[
{
id: 'create-with-workspace',
icon: 'book',
label: trans('create_mode_workspace', {}, 'cursus'),
description: trans('create_mode_workspace_desc', {}, 'cursus'),
displayed: props.contextType === 'desktop',
action: {
type: MODAL_BUTTON,
modal: [MODAL_WORKSPACES, {
url: ['apiv2_workspace_list_managed'],
multiple: false,
selectAction: (selected) => (
{
type: CALLBACK_BUTTON,
callback: () => {
if (props.modal) {
props.fadeModal()
}
history.push(props.path + '/new')
props.startCreation(null, CourseTypes.defaultProps, selected[0])
}
}
)
}]
}
}, {
id: 'create-from-model',
icon: 'stamp',
label: trans('create_mode_model', {}, 'cursus'),
description: trans('create_mode_model_desc', {}, 'cursus'),
displayed: props.contextType === 'desktop',
action: {
type: MODAL_BUTTON,
modal: [MODAL_WORKSPACES, {
url: ['apiv2_workspace_list_model'],
multiple: false,
selectAction: (selected) => (
{
type: CALLBACK_BUTTON,
callback: () => {
if (props.modal) {
props.fadeModal()
}
history.push(props.path + '/new')
props.startCreation(null, CourseTypes.defaultProps, selected[0])
}
}
)
}]
}
}, {
id: 'create-empty',
icon: 'plus-circle',
label: trans('create_mode_empty', {}, 'cursus'),
description: trans('create_mode_empty_desc', {}, 'cursus'),
action: {
type: CALLBACK_BUTTON,
callback: () => {
if (props.modal) {
props.fadeModal()
}
history.push(props.path + '/new')
props.startCreation(null, CourseTypes.defaultProps)
}
}
}, {
id: 'create-from-copy',
icon: 'clone',
label: trans('create_mode_copy', {}, 'cursus'),
description: trans('create_mode_copy_desc', {}, 'cursus'),
action: {
type: MODAL_BUTTON
},
group: trans('create_mode_group_existing', {}, 'cursus')
}, {
id: 'create-from-organization',
icon: 'building',
label: trans('create_mode_organization', {}, 'cursus'),
description: trans('create_mode_organization_desc', {}, 'cursus'),
action: {
type: CALLBACK_BUTTON,
callback: () => true
},
group: trans('create_mode_group_existing', {}, 'cursus')
}, {
id: 'create-from-existing',
icon: 'graduation-cap',
label: trans('create_mode_existing', {}, 'cursus'),
description: trans('create_mode_existing_desc', {}, 'cursus'),
displayed: props.contextType === 'workspace',
action: {
type: CALLBACK_BUTTON
},
group: trans('create_mode_group_existing', {}, 'cursus')
}
]}
/>
)
}

CreationType.propTypes = {
startCreation: T.func.isRequired,
create: T.func.isRequired,
reset: T.func.isRequired,
contextType: T.string,
path: T.string,
modal: T.bool,
fadeModal: T.func
}

export {
CreationType
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react'
import {PropTypes as T} from 'prop-types'
import omit from 'lodash/omit'

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

import {Modal} from '#/main/app/overlays/modal/components/modal'
import {CreationType} from '#/plugin/cursus/course/components/type'

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

CreationModal.propTypes = {
startCreation: T.func.isRequired,
create: T.func.isRequired,
reset: T.func.isRequired,
fadeModal: T.func.isRequired
}

export {
CreationModal
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {connect} from 'react-redux'

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

import {actions as formActions} from '#/main/app/content/form'
import {selectors as toolSelectors} from '#/main/core/tool/store'
import {actions as courseActions} from '#/plugin/cursus/course/store'
import {reducer, selectors} from '#/plugin/cursus/course/modals/creation/store'
import {CreationModal as BaseCreationModal} from '#/plugin/cursus/course/modals/creation/components/modal'

const CreationModal = withReducer(selectors.STORE_NAME, reducer)(
connect(
(state) => ({
contextType: toolSelectors.contextType(state)
}),
(dispatch) => ({
startCreation(slug, defaultProps, workspace) {
dispatch(courseActions.openForm(slug, defaultProps, workspace))
},
reset() {
dispatch(formActions.reset(selectors.STORE_NAME, {}, true))
}
})
)(BaseCreationModal)
)

export {
CreationModal
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {registry} from '#/main/app/modals/registry'

// gets the modal component
import {CreationModal} from '#/plugin/cursus/course/modals/creation/containers/modal'

const MODAL_COURSE_TYPE_CREATION = 'MODAL_COURSE_TYPE_CREATION'

// make the modal available for use
registry.add(MODAL_COURSE_TYPE_CREATION, CreationModal)

export {
MODAL_COURSE_TYPE_CREATION
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {reducer} from '#/plugin/cursus/course/modals/creation/store/reducer'
import {selectors} from '#/plugin/cursus/course/modals/creation/store/selectors'

export {
reducer,
selectors
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {makeFormReducer} from '#/main/app/content/form/store'
import {selectors} from '#/plugin/cursus/course/modals/creation/store/selectors'

const reducer = makeFormReducer(selectors.STORE_NAME, {
new: true
})

export {
reducer
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const STORE_NAME = 'courseTypeCreation'

export const selectors = {
STORE_NAME
}
12 changes: 5 additions & 7 deletions src/plugin/cursus/Resources/modules/course/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ actions.open = (courseSlug, force = false) => (dispatch, getState) => {
}

actions.openForm = (courseSlug = null, defaultProps = {}, workspace = null) => (dispatch) => {
if (!courseSlug) {
if(workspace) {
defaultProps = {
...defaultProps,
_workspaceType: 'workspace',
workspace: workspace
}
if(workspace) {
defaultProps = {
...defaultProps,
_workspaceType: workspace.meta.model ? 'model' : '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 @@ -2,21 +2,20 @@ import React from 'react'
import get from 'lodash/get'
import {PropTypes as T} from 'prop-types'

import {trans} from '#/main/app/intl'
import {Tool} from '#/main/core/tool'
import {LINK_BUTTON} from '#/main/app/buttons'
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 {CourseEditor} from '#/plugin/cursus/course/editor/containers/main'

import {Tool} from '#/main/core/tool'

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'
import {EventsPresences} from '#/plugin/cursus/tools/events/containers/presences'
import {EventsRegistered} from '#/plugin/cursus/tools/events/components/registered'
import {LINK_BUTTON} from '#/main/app/buttons'
import {trans} from '#/main/app/intl'

const EventsTool = (props) =>
<Tool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ 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 {LINK_BUTTON, MODAL_BUTTON} from '#/main/app/buttons'
import {ToolPage} from '#/main/core/tool'

import {CourseList} from '#/plugin/cursus/course/components/list'
import {ContentSizing} from '#/main/app/content/components/sizing'
import {CreationType} from '#/plugin/cursus/course/components/type'
import {selectors} from '#/plugin/cursus/tools/trainings/catalog/store'
import {MODAL_COURSE_TYPE_CREATION} from '#/plugin/cursus/course/modals/creation'

const CatalogList = (props) =>
<ToolPage
Expand All @@ -20,10 +23,12 @@ const CatalogList = (props) =>
actions={[
{
name: 'add',
type: LINK_BUTTON,
type: MODAL_BUTTON,
icon: 'fa fa-fw fa-plus',
label: trans('add_course', {}, 'cursus'),
target: `${props.path}/new`,
modal: [MODAL_COURSE_TYPE_CREATION, {
path: props.path
}],
group: trans('management'),
displayed: props.canEdit,
primary: true
Expand All @@ -35,11 +40,18 @@ const CatalogList = (props) =>
name={selectors.LIST_NAME}
url={['apiv2_cursus_course_list']}
/>

{props.courses.totalResults === 0 &&
<ContentSizing size="md" className="mt-4">
<CreationType {...props} />
</ContentSizing>
}
</ToolPage>

CatalogList.propTypes = {
path: T.string.isRequired,
canEdit: T.bool.isRequired
canEdit: T.bool.isRequired,
courses: T.object
}

export {
Expand Down
Loading

0 comments on commit 18bfc89

Please sign in to comment.