-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
307 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/plugin/cursus/Resources/modules/course/components/type.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
32 changes: 32 additions & 0 deletions
32
src/plugin/cursus/Resources/modules/course/modals/creation/components/modal.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
29 changes: 29 additions & 0 deletions
29
src/plugin/cursus/Resources/modules/course/modals/creation/containers/modal.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
13 changes: 13 additions & 0 deletions
13
src/plugin/cursus/Resources/modules/course/modals/creation/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
7 changes: 7 additions & 0 deletions
7
src/plugin/cursus/Resources/modules/course/modals/creation/store/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
10 changes: 10 additions & 0 deletions
10
src/plugin/cursus/Resources/modules/course/modals/creation/store/reducer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
5 changes: 5 additions & 0 deletions
5
src/plugin/cursus/Resources/modules/course/modals/creation/store/selectors.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const STORE_NAME = 'courseTypeCreation' | ||
|
||
export const selectors = { | ||
STORE_NAME | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.