-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15167 from code-dot-org/editCourse
Levelbuilders can edit courses
- Loading branch information
Showing
12 changed files
with
463 additions
and
16 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
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,22 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import CourseEditor from '@cdo/apps/templates/courseOverview/CourseEditor'; | ||
|
||
$(document).ready(showCourseEditor); | ||
|
||
function showCourseEditor() { | ||
const scriptData = document.querySelector('script[data-course-editor]'); | ||
const courseEditorData = JSON.parse(scriptData.dataset.courseEditor); | ||
|
||
// Eventually we want to do this all via redux | ||
ReactDOM.render( | ||
<CourseEditor | ||
name={courseEditorData.course_summary.name} | ||
title={courseEditorData.course_summary.title} | ||
descriptionStudent={courseEditorData.course_summary.description_student} | ||
descriptionTeacher={courseEditorData.course_summary.description_teacher} | ||
scriptsInCourse={courseEditorData.course_summary.scripts.map(script => script.name)} | ||
scriptNames={courseEditorData.script_names.sort()} | ||
/>, | ||
document.getElementById('course_editor')); | ||
} |
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,79 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import CourseScriptsEditor from './CourseScriptsEditor'; | ||
|
||
const styles = { | ||
input: { | ||
width: '100%', | ||
boxSizing: 'border-box', | ||
padding: '4px 6px', | ||
color: '#555', | ||
border: '1px solid #ccc', | ||
borderRadius: 4 | ||
}, | ||
}; | ||
|
||
export default class CourseEditor extends Component { | ||
static propTypes = { | ||
name: PropTypes.string.isRequired, | ||
title: PropTypes.string.isRequired, | ||
descriptionStudent: PropTypes.string, | ||
descriptionTeacher: PropTypes.string, | ||
scriptsInCourse: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
scriptNames: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
}; | ||
|
||
render() { | ||
const { | ||
name, | ||
title, | ||
descriptionStudent, | ||
descriptionTeacher, | ||
scriptsInCourse, | ||
scriptNames, | ||
} = this.props; | ||
return ( | ||
<div> | ||
<h1>{name}</h1> | ||
<label> | ||
Title | ||
<input | ||
type="text" | ||
name="title" | ||
defaultValue={title} | ||
style={styles.input} | ||
/> | ||
</label> | ||
<label> | ||
Student Description | ||
<textarea | ||
name="description_student" | ||
defaultValue={descriptionStudent} | ||
rows={5} | ||
style={styles.input} | ||
/> | ||
</label> | ||
<label> | ||
Teacher Description | ||
<textarea | ||
name="description_teacher" | ||
defaultValue={descriptionTeacher} | ||
rows={5} | ||
style={styles.input} | ||
/> | ||
</label> | ||
<label> | ||
Scripts | ||
<div> | ||
The dropdown(s) below represent the orded set of scripts in this course. | ||
To remove a script, just set the dropdown to the default (first) value. | ||
</div> | ||
<CourseScriptsEditor | ||
inputStyle={styles.input} | ||
scriptsInCourse={scriptsInCourse} | ||
scriptNames={scriptNames} | ||
/> | ||
</label> | ||
</div> | ||
); | ||
} | ||
} |
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,66 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
export default class scriptsInCourseEditor extends Component { | ||
static propTypes = { | ||
inputStyle: PropTypes.object.isRequired, | ||
scriptsInCourse: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
scriptNames: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.handleChange = this.handleChange.bind(this); | ||
|
||
this.state = { | ||
// want provided script names, plus one empty one | ||
scriptsInCourse: props.scriptsInCourse.concat('') | ||
}; | ||
} | ||
|
||
handleChange(event) { | ||
const root = ReactDOM.findDOMNode(this); | ||
|
||
let selected = Array.prototype.map.call(root.children, child => child.value); | ||
// If the last script has a value, add a new script without one | ||
if (selected[selected.length - 1] !== '') { | ||
selected.push(''); | ||
} | ||
this.setState({ | ||
scriptsInCourse: selected | ||
}); | ||
} | ||
|
||
render() { | ||
const { scriptNames } = this.props; | ||
return ( | ||
<div> | ||
{this.state.scriptsInCourse.map((selectedScript, index) => ( | ||
<select | ||
name="scripts[]" | ||
style={{ | ||
...this.props.inputStyle, | ||
opacity: selectedScript === "" ? 0.4 : 1 | ||
}} | ||
key={index} | ||
value={selectedScript} | ||
onChange={this.handleChange} | ||
> | ||
<option key="-1" value=""> | ||
Select a script to add to course | ||
</option> | ||
{scriptNames.map((name, index) => ( | ||
<option | ||
key={index} | ||
value={name} | ||
> | ||
{name} | ||
</option> | ||
))} | ||
</select> | ||
))} | ||
</div> | ||
); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
apps/src/templates/courseOverview/CourseScriptsEditor.story.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,48 @@ | ||
import React from 'react'; | ||
import CourseScriptsEditor from './CourseScriptsEditor'; | ||
|
||
const styles = { | ||
input: { | ||
width: '100%', | ||
boxSizing: 'border-box', | ||
padding: '4px 6px', | ||
color: '#555', | ||
border: '1px solid #ccc', | ||
borderRadius: 4 | ||
}, | ||
}; | ||
|
||
const scriptNames = [ | ||
'Hour of Code', | ||
'course1', | ||
'course2', | ||
'csp1', | ||
'csp2' | ||
]; | ||
|
||
export default storybook => { | ||
storybook | ||
.storiesOf('CourseScriptsEditor', module) | ||
.addStoryTable([ | ||
{ | ||
name: 'no selected scripts', | ||
story: () => ( | ||
<CourseScriptsEditor | ||
inputStyle={styles.input} | ||
scriptsInCourse={[]} | ||
scriptNames={scriptNames} | ||
/> | ||
) | ||
}, | ||
{ | ||
name: 'one selected script', | ||
story: () => ( | ||
<CourseScriptsEditor | ||
inputStyle={styles.input} | ||
scriptsInCourse={[scriptNames[1]]} | ||
scriptNames={scriptNames} | ||
/> | ||
) | ||
} | ||
]); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- course = local_assigns[:course] | ||
- course_editor_data = {course_summary: course.summarize, | ||
script_names: Script.all.map(&:name)} | ||
- content_for(:head) do | ||
%script{ src: minifiable_asset_path('js/courses/edit.js'), data: {course_editor: course_editor_data.to_json}} | ||
= form_for(course) do |f| | ||
#course_editor | ||
%button.btn.btn-primary{type: 'submit', style: 'margin: 0'} Save Changes |
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,6 @@ | ||
{ | ||
"name": "csp", | ||
"script_names": [ | ||
"csp1" | ||
] | ||
} |
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 @@ | ||
# Autogenerated scripts locale file. | ||
--- | ||
en: | ||
data: | ||
course: | ||
name: | ||
csp: | ||
title: Computer Science Principles | ||
description_student: Student description will eventually go here | ||
description_teacher: Teacher description will eventually go here |
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.