Skip to content

Commit f3f2aa9

Browse files
authored
Mission editing slang (#450)
* update js-slang imports, and use null for empty list * pass tests * pass tests * format all external libraries with prettier * Update README.md * minorOverviewChanges * minorOverviewChanges1 * AddedAssignmentSupport * minorOverviewChanges2 * placed xmlpharser in alt file * update js-slang to version 0.2.0 * Bump showdown from 1.8.6 to 1.8.7 (#397) Bumps [showdown](https://github.com/showdownjs/showdown) from 1.8.6 to 1.8.7. - [Release notes](https://github.com/showdownjs/showdown/releases) - [Changelog](https://github.com/showdownjs/showdown/blob/master/CHANGELOG.md) - [Commits](showdownjs/showdown@1.8.6...1.8.7) Signed-off-by: dependabot[bot] <support@dependabot.com> * update acorn, fix order of imports * Bump react-redux from 5.0.7 to 5.1.0 (#401) Bumps [react-redux](https://github.com/reduxjs/react-redux) from 5.0.7 to 5.1.0. - [Release notes](https://github.com/reduxjs/react-redux/releases) - [Changelog](https://github.com/reduxjs/react-redux/blob/master/CHANGELOG.md) - [Commits](reduxjs/react-redux@v5.0.7...v5.1.0) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump react-ace from 6.1.4 to 6.2.0 (#398) Bumps [react-ace](https://github.com/securingsincity/react-ace) from 6.1.4 to 6.2.0. - [Release notes](https://github.com/securingsincity/react-ace/releases) - [Changelog](https://github.com/securingsincity/react-ace/blob/master/CHANGELOG.md) - [Commits](securingsincity/react-ace@6.1.4...6.2.0) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump react from 16.4.2 to 16.6.0 (#399) Bumps [react](https://github.com/facebook/react) from 16.4.2 to 16.6.0. - [Release notes](https://github.com/facebook/react/releases) - [Changelog](https://github.com/facebook/react/blob/master/CHANGELOG.md) - [Commits](facebook/react@v16.4.2...v16.6.0) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump node-sass-chokidar from 1.3.3 to 1.3.4 (#400) Bumps [node-sass-chokidar](https://github.com/michaelwayman/node-sass-chokidar) from 1.3.3 to 1.3.4. - [Release notes](https://github.com/michaelwayman/node-sass-chokidar/releases) - [Changelog](https://github.com/michaelwayman/node-sass-chokidar/blob/master/CHANGELOG.md) - [Commits](https://github.com/michaelwayman/node-sass-chokidar/commits) Signed-off-by: dependabot[bot] <support@dependabot.com> * [Security] Bump stringstream from 0.0.5 to 0.0.6 (#414) Bumps [stringstream](https://github.com/mhart/StringStream) from 0.0.5 to 0.0.6. **This update includes security fixes.** - [Release notes](https://github.com/mhart/StringStream/releases) - [Commits](mhart/StringStream@v0.0.5...v0.0.6) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump typesafe-actions from 1.1.3 to 3.0.0 (#438) Bumps [typesafe-actions](https://github.com/piotrwitek/typesafe-actions) from 1.1.3 to 3.0.0. - [Release notes](https://github.com/piotrwitek/typesafe-actions/releases) - [Commits](piotrwitek/typesafe-actions@v1.1.3...v3.0.0) Signed-off-by: dependabot[bot] <support@dependabot.com> * update readme * [Security] Bump lodash from 4.17.10 to 4.17.11 (#434) Bumps [lodash](https://github.com/lodash/lodash) from 4.17.10 to 4.17.11. **This update includes security fixes.** - [Release notes](https://github.com/lodash/lodash/releases) - [Changelog](https://github.com/lodash/lodash/blob/master/CHANGELOG) - [Commits](lodash/lodash@4.17.10...4.17.11) Signed-off-by: dependabot[bot] <support@dependabot.com> * [Security] Bump macaddress from 0.2.8 to 0.2.9 (#415) Bumps [macaddress](https://github.com/scravy/node-macaddress) from 0.2.8 to 0.2.9. **This update includes security fixes.** - [Release notes](https://github.com/scravy/node-macaddress/releases) - [Commits](scravy/node-macaddress@0.2.8...0.2.9) Signed-off-by: dependabot[bot] <support@dependabot.com> * Bump @types/enzyme from 3.1.13 to 3.1.17 (#440) Bumps [@types/enzyme](https://github.com/DefinitelyTyped/DefinitelyTyped) from 3.1.13 to 3.1.17. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits) Signed-off-by: dependabot[bot] <support@dependabot.com> * created editing folder copy of assessment, may be merged later * added interface * library parsing * Local storage Missions are now loaded in local storage * packages fixed * export library * Added UI to edit assessmentsOverview * Moved edititngOverviewCard logic new file edititngOverviewCard * export added * minor debugging
1 parent a4315d5 commit f3f2aa9

File tree

3 files changed

+217
-2
lines changed

3 files changed

+217
-2
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"react-router": "^4.2.0",
6060
"react-router-dom": "^4.2.2",
6161
"react-router-redux": "^5.0.0-alpha.9",
62+
"react-textarea-autosize": "^7.1.0",
6263
"react-transition-group": "^2.3.1",
6364
"redux": "^3.7.2",
6465
"redux-mock-store": "^1.5.1",
@@ -95,6 +96,7 @@
9596
"@types/react-router-dom": "^4.2.6",
9697
"@types/react-router-redux": "^5.0.13",
9798
"@types/react-test-renderer": "^16.0.1",
99+
"@types/react-textarea-autosize": "^4.3.3",
98100
"@types/redux-mock-store": "^0.0.13",
99101
"@types/showdown": "^1.7.5",
100102
"@types/xml2js": "^0.4.3",
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
import {
2+
Button,
3+
Card,
4+
Elevation,
5+
Icon,
6+
IconName,
7+
Intent,
8+
Text,
9+
} from '@blueprintjs/core'
10+
import { IconNames } from '@blueprintjs/icons'
11+
import * as React from 'react'
12+
import { NavLink } from 'react-router-dom'
13+
import Textarea from 'react-textarea-autosize';
14+
15+
import defaultCoverImage from '../../assets/default_cover_image.jpg'
16+
import { getPrettyDate } from '../../utils/dateHelpers'
17+
import { assessmentCategoryLink } from '../../utils/paramParseHelpers'
18+
import { exportXml } from '../../utils/xmlParser'
19+
20+
import { IAssessmentOverview } from '../assessment/assessmentShape'
21+
import { controlButton } from '../commons'
22+
import Markdown from '../commons/Markdown'
23+
24+
const DEFAULT_QUESTION_ID: number = 0
25+
26+
type Props = {
27+
overview: IAssessmentOverview,
28+
updateEditingOverview: (overview: IAssessmentOverview) => void
29+
}
30+
31+
interface IState {
32+
editingOverviewField: string,
33+
fieldValue: any
34+
}
35+
36+
const textareaStyle = {
37+
"height": "100%",
38+
"width": "100%",
39+
"overflow": "hidden" as "hidden",
40+
"resize": "none" as "none"
41+
}
42+
43+
export class EditingOverviewCard extends React.Component<Props, IState> {
44+
public constructor(props: Props) {
45+
super(props)
46+
this.state = {
47+
editingOverviewField: '',
48+
fieldValue: ''
49+
}
50+
}
51+
52+
public render() {
53+
return <div>
54+
{this.makeEditingOverviewCard(this.props.overview)}
55+
</div>;
56+
}
57+
58+
private saveEditOverview = (field: keyof IAssessmentOverview) => (e: any) =>{
59+
const overview = {
60+
...this.props.overview,
61+
[field]: this.state.fieldValue
62+
}
63+
this.setState({
64+
editingOverviewField: '',
65+
fieldValue:''
66+
})
67+
localStorage.setItem('MissionEditingOverviewSA', JSON.stringify(overview));
68+
this.props.updateEditingOverview(overview);
69+
}
70+
71+
private handleEditOverview = () => (e: any) =>{
72+
this.setState({
73+
fieldValue:e.target.value
74+
})
75+
}
76+
77+
private toggleEditField = (field: keyof IAssessmentOverview) => (e: any) => {
78+
this.setState({
79+
editingOverviewField: field,
80+
fieldValue: this.props.overview[field]
81+
})
82+
}
83+
84+
private handleExportXml = () => (e: any) => {
85+
exportXml();
86+
}
87+
88+
private makeEditingOverviewTextarea = (field: keyof IAssessmentOverview) =>
89+
<Textarea
90+
style={textareaStyle}
91+
onChange={this.handleEditOverview()}
92+
onBlur={this.saveEditOverview(field)}
93+
value={this.state.fieldValue}
94+
/>
95+
96+
private makeEditingOverviewCard = (
97+
overview: IAssessmentOverview
98+
) => (
99+
<div>
100+
You can edit this card
101+
<Card className="row listing" elevation={Elevation.ONE}>
102+
103+
<div className="col-xs-3 listing-picture" onClick={this.toggleEditField("coverImage")}>
104+
{this.state.editingOverviewField === 'coverImage' ? (
105+
this.makeEditingOverviewTextarea('coverImage')
106+
) : (
107+
<img
108+
className={`cover-image-${overview.status}`}
109+
src={overview.coverImage ? overview.coverImage : defaultCoverImage}
110+
/>
111+
)}
112+
</div>
113+
114+
<div className="col-xs-9 listing-text">
115+
{this.makeEditingOverviewCardTitle(
116+
overview,
117+
overview.title
118+
)}
119+
<div className="row listing-grade">
120+
<h6>
121+
{' '}
122+
{`Max Grade: ${overview.maxGrade}`}
123+
{' '}
124+
</h6>
125+
</div>
126+
<div className="row listing-xp">
127+
<h6>
128+
{' '}
129+
{`Max XP: ${overview.maxXp}`}
130+
{' '}
131+
</h6>
132+
</div>
133+
<div className="row listing-description" onClick={this.toggleEditField('shortSummary')}>
134+
{this.state.editingOverviewField === 'shortSummary' ? (
135+
this.makeEditingOverviewTextarea('shortSummary')
136+
) : (
137+
<Markdown content={overview.shortSummary} />
138+
)}
139+
140+
</div>
141+
<div className="listing-controls">
142+
<Text className="listing-due-date">
143+
<Icon className="listing-due-icon" iconSize={12} icon={IconNames.TIME} />
144+
<div className="date-container">Opens at:&nbsp;</div>
145+
<div className="date-container" onClick={this.toggleEditField("openAt")}>
146+
{this.state.editingOverviewField === "openAt"
147+
? this.makeEditingOverviewTextarea("openAt")
148+
: `${getPrettyDate(overview.openAt)}`}
149+
</div>
150+
151+
<div className="date-container">&nbsp;&nbsp;Due:&nbsp;</div>
152+
<div className="date-container" onClick={this.toggleEditField("closeAt")}>
153+
{this.state.editingOverviewField === "closeAt"
154+
? this.makeEditingOverviewTextarea("closeAt")
155+
: `${getPrettyDate(overview.closeAt)}`}
156+
</div>
157+
</Text>
158+
{makeOverviewCardButton(overview)}
159+
</div>
160+
</div>
161+
</Card>
162+
</div>
163+
)
164+
165+
private makeEditingOverviewCardTitle = (
166+
overview: IAssessmentOverview,
167+
title: string
168+
) => (
169+
<div className="row listing-title">
170+
<Text ellipsize={true} className={'col-xs-10'}>
171+
<h4 onClick={this.toggleEditField("title")}>
172+
{ this.state.editingOverviewField === 'title'
173+
? this.makeEditingOverviewTextarea('title')
174+
: title
175+
}{' '}
176+
</h4>
177+
</Text>
178+
<div className="col-xs-2">{this.makeSubmissionButton(overview)}</div>
179+
</div>
180+
)
181+
182+
private makeSubmissionButton = (
183+
overview: IAssessmentOverview
184+
) => (
185+
<Button
186+
// disabled={overview.status !== AssessmentStatuses.attempted}
187+
icon={IconNames.CONFIRM}
188+
intent={Intent.DANGER}
189+
minimal={true}
190+
// intentional: each menu renders own version of onClick
191+
// tslint:disable-next-line:jsx-no-lambda
192+
onClick={this.handleExportXml()}
193+
>
194+
Export XML
195+
</Button>
196+
)
197+
198+
}
199+
200+
const makeOverviewCardButton = (overview: IAssessmentOverview) => {
201+
const icon: IconName = IconNames.EDIT;
202+
const label: string = "Edit mission";
203+
return (
204+
<NavLink
205+
to={`/academy/${assessmentCategoryLink(
206+
overview.category
207+
)}/${overview.id.toString()}/${DEFAULT_QUESTION_ID}`}
208+
>
209+
{controlButton(label, icon)}
210+
</NavLink>
211+
)
212+
}

src/containers/assessment/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux'
22
import { withRouter } from 'react-router'
33
import { bindActionCreators, Dispatch } from 'redux'
44

5-
import { fetchAssessmentOverviews, submitAssessment } from '../../actions/session'
5+
import { fetchAssessmentOverviews, submitAssessment, updateAssessment } from '../../actions/session'
66
import Assessment, { IDispatchProps, IOwnProps, IStateProps } from '../../components/assessment'
77
import { IAssessmentOverview } from '../../components/assessment/assessmentShape'
88
import { IState, Role } from '../../reducers/states'
@@ -23,7 +23,8 @@ const mapDispatchToProps: MapDispatchToProps<IDispatchProps, {}> = (dispatch: Di
2323
bindActionCreators(
2424
{
2525
handleAssessmentOverviewFetch: fetchAssessmentOverviews,
26-
handleSubmitAssessment: submitAssessment
26+
handleSubmitAssessment: submitAssessment,
27+
newAssessment: updateAssessment,
2728
},
2829
dispatch
2930
)

0 commit comments

Comments
 (0)