diff --git a/src/components/NavigationBar.tsx b/src/components/NavigationBar.tsx index ee5f1055d0..128cdcc719 100644 --- a/src/components/NavigationBar.tsx +++ b/src/components/NavigationBar.tsx @@ -61,7 +61,7 @@ const NavigationBar: React.SFC = props => ( to="/incubator" > -
Incubator
+
Mission-Control
- Incubator + Mission-Control
@@ -72,7 +72,7 @@ exports[`NavigationBar renders correctly with username 1`] = `
- Incubator + Mission-Control
diff --git a/src/components/assessment/AssessmentWorkspace.tsx b/src/components/assessment/AssessmentWorkspace.tsx old mode 100755 new mode 100644 index ddc16ce912..0cd778bd64 --- a/src/components/assessment/AssessmentWorkspace.tsx +++ b/src/components/assessment/AssessmentWorkspace.tsx @@ -1,4 +1,13 @@ -import { Button, Card, Dialog, NonIdealState, Spinner } from '@blueprintjs/core'; +import { + Button, + ButtonGroup, + Card, + Classes, + Dialog, + Intent, + NonIdealState, + Spinner +} from '@blueprintjs/core'; import { IconNames } from '@blueprintjs/icons'; import * as React from 'react'; @@ -6,6 +15,7 @@ import { InterpreterOutput, IWorkspaceState } from '../../reducers/states'; import { beforeNow } from '../../utils/dateHelpers'; import { history } from '../../utils/history'; import { assessmentCategoryLink } from '../../utils/paramParseHelpers'; +import { controlButton } from '../commons'; import Markdown from '../commons/Markdown'; import Workspace, { WorkspaceProps } from '../workspace'; import { ControlBarProps } from '../workspace/ControlBar'; @@ -67,13 +77,15 @@ export type DispatchProps = { class AssessmentWorkspace extends React.Component< AssessmentWorkspaceProps, - { showOverlay: boolean } + { showOverlay: boolean; showResetOverlay: boolean } > { public constructor(props: AssessmentWorkspaceProps) { super(props); this.state = { - showOverlay: false + showOverlay: false, + showResetOverlay: false }; + this.props.handleEditorValueChange(''); } /** @@ -86,6 +98,20 @@ class AssessmentWorkspace extends React.Component< if (this.props.questionId === 0 && this.props.notAttempted) { this.setState({ showOverlay: true }); } + if (this.props.assessment) { + const question: IQuestion = this.props.assessment.questions[ + this.props.questionId >= this.props.assessment.questions.length + ? this.props.assessment.questions.length - 1 + : this.props.questionId + ]; + this.props.handleEditorValueChange( + question.type === QuestionTypes.programming + ? question.answer !== null + ? ((question as IProgrammingQuestion).answer as string) + : (question as IProgrammingQuestion).solutionTemplate + : '' + ); + } } /** @@ -119,24 +145,53 @@ class AssessmentWorkspace extends React.Component< ); + + const resetOverlay = ( + +
+ + +
+
+ + {controlButton('Cancel', null, () => this.setState({ showResetOverlay: false }), { + minimal: false + })} + {controlButton( + 'Confirm', + null, + () => { + this.setState({ showResetOverlay: false }); + this.props.handleEditorValueChange( + (this.props.assessment!.questions[questionId] as IProgrammingQuestion) + .solutionTemplate + ); + this.props.handleUpdateHasUnsavedChanges(true); + }, + { minimal: false, intent: Intent.DANGER } + )} + +
+
+ ); /* If questionId is out of bounds, set it to the max. */ const questionId = this.props.questionId >= this.props.assessment.questions.length ? this.props.assessment.questions.length - 1 : this.props.questionId; const question: IQuestion = this.props.assessment.questions[questionId]; - const editorValue = - question.type === QuestionTypes.programming - ? question.answer !== null - ? ((question as IProgrammingQuestion).answer as string) - : (question as IProgrammingQuestion).solutionTemplate - : null; const workspaceProps: WorkspaceProps = { controlBarProps: this.controlBarProps(this.props, questionId), editorProps: question.type === QuestionTypes.programming ? { - editorValue: editorValue!, + editorValue: this.props.editorValue!, handleEditorEval: this.props.handleEditorEval, handleEditorValueChange: this.props.handleEditorValueChange, handleUpdateHasUnsavedChanges: this.props.handleUpdateHasUnsavedChanges @@ -165,6 +220,7 @@ class AssessmentWorkspace extends React.Component< return (
{overlay} + {resetOverlay}
); @@ -194,7 +250,7 @@ class AssessmentWorkspace extends React.Component< ? question.answer !== null ? ((question as IProgrammingQuestion).answer as string) : (question as IProgrammingQuestion).solutionTemplate - : null; + : ''; this.props.handleUpdateCurrentAssessmentId(assessmentId, questionId); this.props.handleResetWorkspace({ editorValue }); this.props.handleClearContext(question.library); @@ -286,6 +342,9 @@ class AssessmentWorkspace extends React.Component< this.props.assessment!.questions[questionId].id, this.props.editorValue! ), + onClickReset: () => { + this.setState({ showResetOverlay: true }); + }, questionProgress: [questionId + 1, this.props.assessment!.questions.length], sourceChapter: this.props.assessment!.questions[questionId].library.chapter }; diff --git a/src/components/assessment/__tests__/__snapshots__/AssessmentWorkspace.tsx.snap b/src/components/assessment/__tests__/__snapshots__/AssessmentWorkspace.tsx.snap index dc954779c5..a3a3c8643e 100644 --- a/src/components/assessment/__tests__/__snapshots__/AssessmentWorkspace.tsx.snap +++ b/src/components/assessment/__tests__/__snapshots__/AssessmentWorkspace.tsx.snap @@ -10,6 +10,22 @@ exports[`AssessmentWorkspace page with MCQ question renders correctly 1`] = ` + +
+ + +
+
+ + + Cancel + + + Confirm + + +
+
" `; @@ -22,6 +38,22 @@ exports[`AssessmentWorkspace page with overdue assessment renders correctly 1`] + +
+ + +
+
+ + + Cancel + + + Confirm + + +
+
" `; @@ -34,6 +66,22 @@ exports[`AssessmentWorkspace page with programming question renders correctly 1` + +
+ + +
+
+ + + Cancel + + + Confirm + + +
+
" `; diff --git a/src/components/assessment/assessmentShape.ts b/src/components/assessment/assessmentShape.ts index a0c93f0560..6bd85067f7 100644 --- a/src/components/assessment/assessmentShape.ts +++ b/src/components/assessment/assessmentShape.ts @@ -46,7 +46,7 @@ export type GradingStatus = keyof typeof GradingStatuses; export interface IAssessment { category: AssessmentCategory; globalDeployment?: Library; - graderDeployment?: any; + graderDeployment?: Library; id: number; longSummary: string; missionPDF: string; @@ -84,6 +84,7 @@ export interface IQuestion { content: string; id: number; library: Library; + graderLibrary?: Library; type: QuestionType; grader: { name: string; diff --git a/src/components/incubator/EditingOverviewCard.tsx b/src/components/incubator/EditingOverviewCard.tsx index fdeecdf25c..1336cd65f1 100644 --- a/src/components/incubator/EditingOverviewCard.tsx +++ b/src/components/incubator/EditingOverviewCard.tsx @@ -105,7 +105,7 @@ export class EditingOverviewCard extends React.Component { {this.state.editingOverviewField === 'shortSummary' ? ( this.makeEditingOverviewTextarea('shortSummary') ) : ( - + )}
@@ -138,7 +138,7 @@ export class EditingOverviewCard extends React.Component {

{this.state.editingOverviewField === 'title' ? this.makeEditingOverviewTextarea('title') - : title}{' '} + : createPlaceholder(title)}

{this.makeExportButton(overview)}
@@ -160,6 +160,14 @@ export class EditingOverviewCard extends React.Component { ); } +const createPlaceholder = (str: string): string => { + if (str.match('^\n*$')) { + return 'Enter Value Here.'; + } else { + return str; + } +}; + const makeOverviewCardButton = (overview: IAssessmentOverview, listingPath: string | undefined) => { const icon: IconName = IconNames.EDIT; const label: string = 'Edit mission'; diff --git a/src/components/incubator/EditingWorkspace.tsx b/src/components/incubator/EditingWorkspace.tsx index 1d654dace5..1e790de1d9 100644 --- a/src/components/incubator/EditingWorkspace.tsx +++ b/src/components/incubator/EditingWorkspace.tsx @@ -1,19 +1,26 @@ -import { NonIdealState, Spinner } from '@blueprintjs/core'; +import { ButtonGroup, Classes, Dialog, Intent, NonIdealState, Spinner } from '@blueprintjs/core'; import { IconNames } from '@blueprintjs/icons'; import * as React from 'react'; import { InterpreterOutput, IWorkspaceState } from '../../reducers/states'; import { history } from '../../utils/history'; import { assessmentCategoryLink } from '../../utils/paramParseHelpers'; -import { retrieveLocalAssessment } from '../../utils/xmlParser'; +import { + retrieveLocalAssessment, + storeLocalAssessment, + storeLocalAssessmentOverview +} from '../../utils/xmlParser'; import { IAssessment, + IAssessmentOverview, IMCQQuestion, IProgrammingQuestion, IQuestion, Library, QuestionTypes } from '../assessment/assessmentShape'; +import { controlButton } from '../commons'; +import Markdown from '../commons/Markdown'; import Workspace, { WorkspaceProps } from '../workspace'; import { ControlBarProps } from '../workspace/ControlBar'; import { SideContentProps } from '../workspace/side-content'; @@ -44,8 +51,10 @@ export type StateProps = { export type OwnProps = { assessmentId: number; - listingPath?: string; questionId: number; + assessmentOverview: IAssessmentOverview; + updateAssessmentOverview: (overview: IAssessmentOverview) => void; + listingPath?: string; notAttempted: boolean; closeDate: string; }; @@ -70,20 +79,24 @@ export type DispatchProps = { }; interface IState { - showOverlay: boolean; assessment: IAssessment | null; activeTab: number; hasUnsavedChanges: boolean; + showResetOverlay: boolean; + originalMaxGrade: number; + originalMaxXp: number; } class AssessmentWorkspace extends React.Component { public constructor(props: AssessmentWorkspaceProps) { super(props); this.state = { - showOverlay: false, assessment: retrieveLocalAssessment(), activeTab: 0, - hasUnsavedChanges: false + hasUnsavedChanges: false, + showResetOverlay: false, + originalMaxGrade: 0, + originalMaxXp: 0 }; } @@ -92,12 +105,20 @@ class AssessmentWorkspace extends React.Component ); } - /* If questionId is out of bounds, set it to the max. */ - const questionId = - this.props.questionId >= this.state.assessment.questions.length - ? this.state.assessment.questions.length - 1 - : this.props.questionId; + + const questionId = this.formatedQuestionId(); const question: IQuestion = this.state.assessment.questions[questionId]; - const editorValue = - question.type === QuestionTypes.programming - ? question.answer !== null - ? ((question as IProgrammingQuestion).answer as string) - : (question as IProgrammingQuestion).solutionTemplate - : null; const workspaceProps: WorkspaceProps = { controlBarProps: this.controlBarProps(this.props, questionId), editorProps: question.type === QuestionTypes.programming ? { - editorValue: editorValue!, + editorValue: this.props.editorValue || (question.answer as string), handleEditorEval: this.props.handleEditorEval, handleEditorValueChange: this.props.handleEditorValueChange, handleUpdateHasUnsavedChanges: this.props.handleUpdateHasUnsavedChanges @@ -162,11 +174,64 @@ class AssessmentWorkspace extends React.Component + {this.resetOverlay(questionId)}
); } + /* If questionId is out of bounds, set it within range. */ + private formatedQuestionId = () => { + let questionId = this.props.questionId; + if (questionId < 0) { + questionId = 0; + } else if (questionId >= this.state.assessment!.questions.length) { + questionId = this.state.assessment!.questions.length - 1; + } + return questionId; + }; + + /** + * Resets to last save. + */ + private resetOverlay = (questionId: number) => ( + +
+ +
+
+ + {controlButton('Cancel', null, () => this.setState({ showResetOverlay: false }), { + minimal: false + })} + {controlButton( + 'Confirm', + null, + () => { + const assessment = retrieveLocalAssessment()!; + const question = assessment.questions[questionId] as IQuestion; + this.handleRefreshLibrary(); + this.setState({ + assessment, + hasUnsavedChanges: false, + showResetOverlay: false, + originalMaxGrade: question.maxGrade, + originalMaxXp: question.maxXp + }); + }, + { minimal: false, intent: Intent.DANGER } + )} + +
+
+ ); + /** * Checks if there is a need to reset the workspace, then executes * a dispatch (in the props) if needed. @@ -179,26 +244,20 @@ class AssessmentWorkspace extends React.Component { + const question = this.state.assessment!.questions[this.formatedQuestionId()]; + let library = + question.library.chapter === -1 ? this.state.assessment!.globalDeployment! : question.library; + if (library && library.globals.length > 0) { + const globalsVal = library.globals.map((x: any) => x[0]); + const symbolsVal = library.external.symbols.concat(globalsVal); + library = { + ...library, + external: { + name: library.external.name, + symbols: uniq(symbolsVal) + } + }; + } + this.props.handleClearContext(library); + }; + private handleSave = () => { this.setState({ hasUnsavedChanges: false }); - localStorage.setItem('MissionEditingAssessmentSA', JSON.stringify(this.state.assessment)); + storeLocalAssessment(this.state.assessment!); + this.handleRefreshLibrary(); + this.handleSaveGradeAndXp(); + }; + + private handleSaveGradeAndXp = () => { + const questionId = this.formatedQuestionId(); + const assessment = this.state.assessment!; + const curGrade = assessment.questions[questionId].maxGrade; + const changeGrade = curGrade - this.state.originalMaxGrade; + const curXp = assessment.questions[questionId].maxXp; + const changeXp = curXp - this.state.originalMaxXp; + if (changeGrade !== 0 || changeXp !== 0) { + const overview = this.props.assessmentOverview; + if (changeGrade !== 0) { + overview.maxGrade += changeGrade; + } + if (changeXp !== 0) { + overview.maxXp += changeXp; + } + this.setState({ + originalMaxGrade: curGrade, + originalMaxXp: curXp + }); + this.props.updateAssessmentOverview(overview); + storeLocalAssessmentOverview(overview); + } }; private updateEditAssessmentState = (assessmentVal: IAssessment) => { @@ -228,10 +336,9 @@ class AssessmentWorkspace extends React.Component { this.setState({ - assessment: assessmentVal, - hasUnsavedChanges: false + assessment: assessmentVal }); - localStorage.setItem('MissionEditingAssessmentSA', JSON.stringify(assessmentVal)); + this.handleSave(); }; private handleChangeActiveTab = (tab: number) => { @@ -297,6 +404,7 @@ class AssessmentWorkspace extends React.Component history.push(listingPath), onClickSave: this.handleSave, + onClickReset: () => { + this.setState({ showResetOverlay: this.state.hasUnsavedChanges }); + }, questionProgress: [questionId + 1, this.state.assessment!.questions.length], sourceChapter: this.state.assessment!.questions[questionId].library.chapter }; }; } +function uniq(a: string[]) { + const seen = {}; + return a.filter(item => (seen.hasOwnProperty(item) ? false : (seen[item] = true))); +} + export default AssessmentWorkspace; diff --git a/src/components/incubator/ImportFromFileComponent.tsx b/src/components/incubator/ImportFromFileComponent.tsx index cc0ae71a66..5d2971e9fc 100644 --- a/src/components/incubator/ImportFromFileComponent.tsx +++ b/src/components/incubator/ImportFromFileComponent.tsx @@ -88,11 +88,11 @@ export class ImportFromFileComponent extends React.Component { }; private makeMission = () => { - localStorage.setItem('MissionEditingOverviewSA', JSON.stringify(overviewTemplate)); - this.props.updateEditingOverview(overviewTemplate); + localStorage.setItem('MissionEditingOverviewSA', JSON.stringify(overviewTemplate())); + this.props.updateEditingOverview(overviewTemplate()); - localStorage.setItem('MissionEditingAssessmentSA', JSON.stringify(assessmentTemplate)); - this.props.newAssessment(assessmentTemplate); + localStorage.setItem('MissionEditingAssessmentSA', JSON.stringify(assessmentTemplate())); + this.props.newAssessment(assessmentTemplate()); }; } diff --git a/src/components/incubator/assessmentTemplates.ts b/src/components/incubator/assessmentTemplates.ts index c8a3f56b5c..e8684115a3 100644 --- a/src/components/incubator/assessmentTemplates.ts +++ b/src/components/incubator/assessmentTemplates.ts @@ -7,96 +7,118 @@ import { IProgrammingQuestion, Library } from '../../components/assessment/assessmentShape'; -import { mock2DRuneLibrary } from '../../mocks/assessmentAPI'; -export const emptyLibrary: Library = { - chapter: -1, - external: { - name: 'NONE', - symbols: [] - }, - globals: [] +export const emptyLibrary = (): Library => { + return { + chapter: -1, + external: { + name: 'NONE', + symbols: [] + }, + globals: [] + }; }; -export const overviewTemplate: IAssessmentOverview = { - category: AssessmentCategories.Mission, - closeAt: '2100-12-01T00:00+08', - coverImage: 'https://fakeimg.pl/300/', - grade: 1, - id: -1, - maxGrade: 0, - maxXp: 0, - openAt: '2000-01-01T00:00+08', - title: 'Insert title here', - shortSummary: 'Insert short summary here', - status: AssessmentStatuses.not_attempted, - story: 'mission', - xp: 0, - gradingStatus: 'none' +export const normalLibrary = (): Library => { + return { + chapter: 1, + external: { + name: 'NONE', + symbols: [] + }, + globals: [] + }; }; -export const programmingTemplate: IProgrammingQuestion = { - answer: '//1st question mock solution template', - comment: '`Great Job` **young padawan**', - content: 'Enter content here', - id: 0, - library: emptyLibrary, - solutionTemplate: '//This is a mock solution template', - type: 'programming', - grader: { - name: 'avenger', - id: 1 - }, - gradedAt: '2038-06-18T05:24:26.026Z', - xp: 0, - grade: 0, - maxGrade: 2, - maxXp: 2 +export const overviewTemplate = (): IAssessmentOverview => { + return { + category: AssessmentCategories.Mission, + closeAt: '2100-12-01T00:00+08', + coverImage: 'https://fakeimg.pl/300/', + grade: 1, + id: -1, + maxGrade: 0, + maxXp: 0, + openAt: '2000-01-01T00:00+08', + title: 'Insert title here', + shortSummary: 'Insert short summary here', + status: AssessmentStatuses.not_attempted, + story: 'mission', + xp: 0, + gradingStatus: 'none' + }; }; -export const mcqTemplate: IMCQQuestion = { - answer: 3, - comment: null, - content: 'This is a mock MCQ question', - choices: [ - { - content: 'A', - hint: null - }, - { - content: 'B', - hint: null +export const programmingTemplate = (): IProgrammingQuestion => { + return { + answer: '//1st question mock solution template', + comment: '`Great Job` **young padawan**', + content: 'Enter content here', + id: 0, + library: emptyLibrary(), + graderLibrary: emptyLibrary(), + solutionTemplate: '//This is a mock solution template', + type: 'programming', + grader: { + name: 'avenger', + id: 1 }, - { - content: 'C', - hint: null + gradedAt: '2038-06-18T05:24:26.026Z', + xp: 0, + grade: 0, + maxGrade: 0, + maxXp: 0 + }; +}; + +export const mcqTemplate = (): IMCQQuestion => { + return { + answer: 3, + comment: null, + content: 'This is a mock MCQ question', + choices: [ + { + content: 'A', + hint: null + }, + { + content: 'B', + hint: null + }, + { + content: 'C', + hint: null + }, + { + content: 'D', + hint: null + } + ], + id: 2, + library: emptyLibrary(), + type: 'mcq', + solution: 1, + grader: { + name: 'avenger', + id: 1 }, - { - content: 'D', - hint: null - } - ], - id: 2, - library: emptyLibrary, - type: 'mcq', - solution: 1, - grader: { - name: 'avenger', - id: 1 - }, - gradedAt: '2038-06-18T05:24:26.026Z', - xp: 0, - grade: 0, - maxGrade: 2, - maxXp: 2 + gradedAt: '2038-06-18T05:24:26.026Z', + xp: 0, + grade: 0, + maxGrade: 0, + maxXp: 0 + }; }; -export const assessmentTemplate: IAssessment = { - category: 'Mission', - globalDeployment: mock2DRuneLibrary, - id: -1, - longSummary: 'Insert mission briefing here', - missionPDF: 'www.google.com', - questions: [programmingTemplate], - title: 'Insert title here' +export const assessmentTemplate = (): IAssessment => { + return { + category: 'Mission', + globalDeployment: normalLibrary(), + graderDeployment: emptyLibrary(), + id: -1, + longSummary: 'Insert mission briefing here', + missionPDF: 'www.google.com', + questions: [programmingTemplate()], + title: 'Insert title here' + }; }; diff --git a/src/components/incubator/editingWorkspaceSideContent/DeploymentTab.tsx b/src/components/incubator/editingWorkspaceSideContent/DeploymentTab.tsx index 0a34a229cb..e762dc80da 100644 --- a/src/components/incubator/editingWorkspaceSideContent/DeploymentTab.tsx +++ b/src/components/incubator/editingWorkspaceSideContent/DeploymentTab.tsx @@ -15,6 +15,7 @@ interface IProps { assessment: IAssessment; pathToLibrary: Array; updateAssessment: (assessment: IAssessment) => void; + handleRefreshLibrary: (library: Library) => void; isGlobalDeployment: boolean; } @@ -76,9 +77,13 @@ export class DeploymentTab extends React.Component )); + const resetLibrary = controlButton('Reload Library', IconNames.REFRESH, () => + this.props.handleRefreshLibrary(deployment) + ); + return (
- {deploymentDisp} + {deploymentDisp} {resetLibrary}

Interpreter: @@ -152,7 +157,7 @@ export class DeploymentTab extends React.Component { const assessment = this.props.assessment; if (this.state.deploymentEnabled) { - assignToPath(this.props.pathToLibrary, JSON.parse(JSON.stringify(emptyLibrary)), assessment); + assignToPath(this.props.pathToLibrary, emptyLibrary(), assessment); } else { assignToPath(this.props.pathToLibrary.concat(['chapter']), 1, assessment); } diff --git a/src/components/incubator/editingWorkspaceSideContent/ManageQuestionTab.tsx b/src/components/incubator/editingWorkspaceSideContent/ManageQuestionTab.tsx index d350a7c48b..15cf713006 100644 --- a/src/components/incubator/editingWorkspaceSideContent/ManageQuestionTab.tsx +++ b/src/components/incubator/editingWorkspaceSideContent/ManageQuestionTab.tsx @@ -1,6 +1,8 @@ +import { IconNames } from '@blueprintjs/icons'; import * as React from 'react'; import { IAssessment } from '../../assessment/assessmentShape'; +import { controlButton } from '../../commons'; import { mcqTemplate, programmingTemplate } from '../../incubator/assessmentTemplates'; interface IProps { @@ -21,20 +23,24 @@ export class ManageQuestionTab extends React.Component { private manageQuestionTab = () => { return (
- - - + {controlButton( + 'Make Programming Question', + IconNames.FONT, + this.makeQuestion(programmingTemplate) + )} + {controlButton('Make MCQ Question', IconNames.CONFIRM, this.makeQuestion(mcqTemplate))} + {controlButton('Delete Question', IconNames.REMOVE, this.deleteQn)}
); }; - private makeQuestion = (template: any) => () => { + private makeQuestion = (template: () => any) => () => { const assessment = this.props.assessment; const index = this.props.questionId; let questions = assessment.questions; questions = questions .slice(0, index) - .concat([template]) + .concat([template()]) .concat(questions.slice(index)); assessment.questions = questions; this.props.updateAssessment(assessment); diff --git a/src/components/incubator/editingWorkspaceSideContent/TextareaContent.tsx b/src/components/incubator/editingWorkspaceSideContent/TextareaContent.tsx index 7d98de8b81..615952c6aa 100644 --- a/src/components/incubator/editingWorkspaceSideContent/TextareaContent.tsx +++ b/src/components/incubator/editingWorkspaceSideContent/TextareaContent.tsx @@ -10,8 +10,8 @@ interface IProps { isNumber?: boolean; numberRange?: number[]; path: Array; - processResults?: (str: string | number) => string | number; useRawValue?: boolean; + processResults?: (newVal: string | number) => string | number; updateAssessment: (assessment: IAssessment) => void; } diff --git a/src/components/incubator/index.tsx b/src/components/incubator/index.tsx index 7162beda56..3d2a82ac41 100644 --- a/src/components/incubator/index.tsx +++ b/src/components/incubator/index.tsx @@ -6,9 +6,9 @@ import ImportFromFileComponent from '../../containers/incubator/ImportFromFileCo import { stringParamToInt } from '../../utils/paramParseHelpers'; import { retrieveLocalAssessmentOverview } from '../../utils/xmlParser'; import { AssessmentStatuses, IAssessmentOverview } from '../assessment/assessmentShape'; -import { OwnProps as AssessmentProps } from '../assessment/AssessmentWorkspace'; import ContentDisplay from '../commons/ContentDisplay'; import { EditingOverviewCard } from '../incubator/EditingOverviewCard'; +import { OwnProps as AssessmentProps } from '../incubator/EditingWorkspace'; const DEFAULT_QUESTION_ID: number = 0; @@ -60,6 +60,8 @@ class Assessment extends React.Component { const assessmentProps: AssessmentProps = { assessmentId, questionId, + assessmentOverview: overview, + updateAssessmentOverview: this.updateEditingOverview, notAttempted: overview.status === AssessmentStatuses.not_attempted, closeDate: overview.closeAt }; diff --git a/src/components/workspace/ControlBar.tsx b/src/components/workspace/ControlBar.tsx old mode 100755 new mode 100644 index 5bf80be90e..0d2de4ee04 --- a/src/components/workspace/ControlBar.tsx +++ b/src/components/workspace/ControlBar.tsx @@ -37,6 +37,7 @@ export type ControlBarProps = { onClickPrevious?(): any; onClickReturn?(): any; onClickSave?(): any; + onClickReset?(): any; }; interface IChapter { @@ -62,7 +63,8 @@ class ControlBar extends React.PureComponent { hasShareButton: true, onClickNext: () => {}, onClickPrevious: () => {}, - onClickSave: () => {} + onClickSave: () => {}, + onClickReset: () => {} }; private shareInputElem: HTMLInputElement; @@ -136,12 +138,16 @@ class ControlBar extends React.PureComponent { const stopAutorunButton = this.props.hasEditorAutorunButton ? controlButton('Autorun', IconNames.STOP, this.props.handleToggleEditorAutorun) : undefined; + const resetButton = this.props.hasSaveButton + ? controlButton('Reset', IconNames.REPEAT, this.props.onClickReset) + : undefined; return (
{this.props.isEditorAutorun ? undefined : this.props.isRunning ? stopButton : runButton} {saveButton} {shareButton} {chapterSelectButton} {externalSelectButton} {this.props.isEditorAutorun ? stopAutorunButton : startAutorunButton} + {resetButton}
); } @@ -201,7 +207,7 @@ class ControlBar extends React.PureComponent { } private hasPreviousButton() { - return this.props.questionProgress && this.props.questionProgress[0] > 0; + return this.props.questionProgress && this.props.questionProgress[0] > 1; } private hasReturnButton() { diff --git a/src/styles/_academy.scss b/src/styles/_academy.scss index 85b7e5101f..4f3eeaf37a 100644 --- a/src/styles/_academy.scss +++ b/src/styles/_academy.scss @@ -129,7 +129,8 @@ } } -.betcha-dialog { +.betcha-dialog, +.assessment-reset { span.warning { font-weight: bold; color: firebrick; diff --git a/src/utils/xmlParser.ts b/src/utils/xmlParser.ts index 7d1b20630e..6f86b0c464 100644 --- a/src/utils/xmlParser.ts +++ b/src/utils/xmlParser.ts @@ -45,6 +45,14 @@ export const retrieveLocalAssessmentOverview = (): IAssessmentOverview | null => } }; +export const storeLocalAssessment = (assessment: IAssessment): void => { + localStorage.setItem('MissionEditingAssessmentSA', JSON.stringify(assessment)); +}; + +export const storeLocalAssessmentOverview = (overview: IAssessmentOverview): void => { + localStorage.setItem('MissionEditingOverviewSA', JSON.stringify(overview)); +}; + export const makeEntireAssessment = (result: any): [IAssessmentOverview, IAssessment] => { const assessmentArr = makeAssessment(result); const overview = makeAssessmentOverview(result, assessmentArr[1], assessmentArr[2]); @@ -80,13 +88,12 @@ const makeAssessment = (result: any): [IAssessment, number, number] => { const task: IXmlParseStrTask = result.CONTENT.TASK[0]; const rawOverview: IXmlParseStrOverview = task.$; const questionArr = makeQuestions(task); - const libraryVal = makeLibrary(task.DEPLOYMENT); return [ { category: capitalizeFirstLetter(rawOverview.kind) as AssessmentCategories, id: editingId, - globalDeployment: libraryVal, - graderDeployment: task.GRADERDEPLOYMENT[0], + globalDeployment: makeLibrary(task.DEPLOYMENT), + graderDeployment: makeLibrary(task.GRADERDEPLOYMENT), longSummary: task.TEXT[0], missionPDF: 'google.com', questions: questionArr[0], @@ -137,14 +144,14 @@ const makeQuestions = (task: IXmlParseStrTask): [IQuestion[], number, number] => let maxXp = 0; const questions: Array = []; task.PROBLEMS[0].PROBLEM.forEach((problem: IXmlParseStrProblem, curId: number) => { - const libraryVal = makeLibrary(problem.DEPLOYMENT); const localMaxXp = problem.$.maxxp ? parseInt(problem.$.maxxp, 10) : 0; const question: IQuestion = { answer: null, comment: null, content: problem.TEXT[0], id: curId, - library: libraryVal, + library: makeLibrary(problem.DEPLOYMENT), + graderLibrary: makeLibrary(problem.GRADERDEPLOYMENT), type: problem.$.type, grader: { name: 'fake person', @@ -278,8 +285,9 @@ export const assessmentToXml = ( task.PROBLEMS = { PROBLEM: [] }; task.DEPLOYMENT = exportLibrary(assessment.globalDeployment!); - if (assessment.graderDeployment) { - task.GRADERDEPLOYMENT = assessment.graderDeployment; + + if (assessment.graderDeployment!.chapter !== -1) { + task.GRADERDEPLOYMENT = exportLibrary(assessment.graderDeployment!); } assessment.questions.forEach((question: IProgrammingQuestion | IMCQQuestion) => { @@ -300,6 +308,11 @@ export const assessmentToXml = ( problem.$['DEPLOYMENT'] = exportLibrary(question.library); } + if (question.graderLibrary!.chapter !== -1) { + /* tslint:disable:no-string-literal */ + problem.$['GRADERDEPLOYMENT'] = exportLibrary(question.graderLibrary!); + } + if (question.maxXp) { /* tslint:disable:no-string-literal */ problem.$['maxxp'] = question.maxXp;