Skip to content

Commit c370da6

Browse files
committed
missionOverviews
missionOverviews can now be added
1 parent 88d4824 commit c370da6

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed

src/actions/actionTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export const SUBMIT_ANSWER = 'SUBMIT_ANSWER'
5959
export const SUBMIT_ASSESSMENT = 'SUBMIT_ASSESSMENT'
6060
export const SUBMIT_GRADING = 'SUBMIT_GRADING'
6161
export const UPDATE_HISTORY_HELPERS = 'UPDATE_HISTORY_HELPERS'
62+
export const UPDATE_ASSESSMENT_OVERVIEW = 'UPDATE_ASSESSMENT_OVERVIEW'
6263
export const UPDATE_ASSESSMENT_OVERVIEWS = 'UPDATE_ASSESSMENT_OVERVIEWS'
6364
export const UPDATE_ASSESSMENT = 'UPDATE_ASSESSMENT'
6465
export const UPDATE_GRADING_OVERVIEWS = 'UPDATE_GRADING_OVERVIEWS'

src/actions/session.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ export const updateHistoryHelpers: ActionCreator<actionTypes.IAction> = (loc: st
9999
payload: loc
100100
})
101101

102+
export const updateAssessmentOverview = (overview: IAssessmentOverview) => ({
103+
type: actionTypes.UPDATE_ASSESSMENT_OVERVIEW,
104+
payload: overview
105+
})
106+
102107
export const updateAssessmentOverviews = (overviews: IAssessmentOverview[]) => ({
103108
type: actionTypes.UPDATE_ASSESSMENT_OVERVIEWS,
104109
payload: overviews

src/components/assessment/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import { OwnProps as AssessmentProps } from '../assessment/AssessmentWorkspace'
3434
import { controlButton } from '../commons'
3535
import ContentDisplay from '../commons/ContentDisplay'
36+
import ImportFromFileComponent from '../commons/ImportFromFileComponent'
3637
import Markdown from '../commons/Markdown'
3738

3839
const DEFAULT_QUESTION_ID: number = 0
@@ -170,6 +171,7 @@ class Assessment extends React.Component<IAssessmentProps, State> {
170171
{upcomingCardsCollapsible}
171172
{openedCardsCollapsible}
172173
{closedCardsCollapsible}
174+
<ImportFromFileComponent />
173175
</>
174176
)
175177
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import * as React from 'react'
2+
import { connect, MapDispatchToProps } from "react-redux"
3+
import { bindActionCreators, Dispatch } from 'redux'
4+
import { parseString } from 'xml2js'
5+
import { updateAssessment, updateAssessmentOverview} from '../../actions/session'
6+
import {
7+
AssessmentCategories,
8+
AssessmentStatuses,
9+
GradingStatuses,
10+
// IAssessment,
11+
IAssessmentOverview
12+
} from '../../components/assessment/assessmentShape'
13+
// import { IDispatchProps } from '../../components/assessment'
14+
15+
16+
const mapDispatchToProps: MapDispatchToProps<any, IAssessmentOverview> = (dispatch: Dispatch<any>) =>
17+
bindActionCreators(
18+
{
19+
newAssessment: updateAssessment,
20+
newAssessmentOverview: updateAssessmentOverview
21+
},
22+
dispatch
23+
)
24+
25+
const capitalizeFirstLetter = (str: string) => {
26+
return str.charAt(0).toUpperCase() + str.slice(1);
27+
}
28+
29+
const makeAssessmentOverview = (task: any) => {
30+
const rawOverview = task.$;
31+
return {
32+
category: capitalizeFirstLetter(rawOverview.kind) as AssessmentCategories,
33+
closeAt: rawOverview.duedate,
34+
coverImage: rawOverview.coverimage,
35+
grade: 1,
36+
id: 7,
37+
maxGrade: 3000,
38+
maxXp: 1000,
39+
openAt: rawOverview.startdate,
40+
title: rawOverview.title,
41+
shortSummary: task.WEBSUMMARY[0],
42+
status: AssessmentStatuses.not_attempted,
43+
story: rawOverview.story,
44+
xp: 0,
45+
gradingStatus: "none" as GradingStatuses
46+
}
47+
}
48+
49+
class ImportFromFileComponent extends React.Component<any, any>{
50+
public fileReader : FileReader;
51+
public constructor(props: any) {
52+
super(props);
53+
this.handleFileRead = this.handleFileRead.bind(this);
54+
this.handleChangeFile = this.handleChangeFile.bind(this);
55+
}
56+
57+
public render(){
58+
return(
59+
<div>
60+
<input
61+
type="file"
62+
id="file"
63+
accept=".xml"
64+
onChange={this.handleChangeFile}
65+
/>
66+
</div>
67+
)
68+
}
69+
70+
private handleFileRead = (e: any) => {
71+
const content = this.fileReader.result;
72+
if (content) {
73+
parseString(content, (err: any, result: any) => {
74+
// tslint:disable-next-line:no-console
75+
console.dir(result);
76+
const task = result.CONTENT.TASK[0];
77+
const overview: IAssessmentOverview = makeAssessmentOverview(task);
78+
this.props.newAssessmentOverview(overview);
79+
});
80+
}
81+
// You can set content in state and show it in render.
82+
}
83+
84+
private handleChangeFile = (e: any) => {
85+
const files = e.target.files
86+
if (e.target.files){
87+
this.fileReader = new FileReader();
88+
this.fileReader.onloadend = this.handleFileRead;
89+
this.fileReader.readAsText(files[0]);
90+
}
91+
}
92+
}
93+
94+
export default connect(null, mapDispatchToProps)(ImportFromFileComponent)

src/reducers/session.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
SET_TOKENS,
77
SET_USER,
88
UPDATE_ASSESSMENT,
9+
UPDATE_ASSESSMENT_OVERVIEW,
910
UPDATE_ASSESSMENT_OVERVIEWS,
1011
UPDATE_GRADING,
1112
UPDATE_GRADING_OVERVIEWS,
@@ -49,10 +50,28 @@ export const reducer: Reducer<ISessionState> = (state = defaultSession, action:
4950
...state,
5051
assessments: newAssessments
5152
}
52-
case UPDATE_ASSESSMENT_OVERVIEWS:
53+
case UPDATE_ASSESSMENT_OVERVIEW:
54+
const newOverviews = Object.assign([], state.assessmentOverviews);
55+
newOverviews.push(action.payload);
5356
return {
5457
...state,
55-
assessmentOverviews: action.payload
58+
assessmentOverviews: newOverviews
59+
}
60+
case UPDATE_ASSESSMENT_OVERVIEWS:
61+
if (state.assessmentOverviews){
62+
const updatedOverviews = Object.assign([], state.assessmentOverviews);
63+
const usedIDs = new Set();
64+
state.assessmentOverviews.forEach((x: any) => {usedIDs.add(x.id)});
65+
action.payload.forEach((x: any) => {if (!usedIDs.has(x.id)) {updatedOverviews.push(x)}})
66+
return {
67+
...state,
68+
assessmentOverviews: updatedOverviews
69+
}
70+
} else{
71+
return {
72+
...state,
73+
assessmentOverviews: action.payload
74+
}
5675
}
5776
case UPDATE_GRADING:
5877
const newGradings = new Map(state.gradings)

0 commit comments

Comments
 (0)