diff --git a/src/components/incubator/EditingWorkspace.tsx b/src/components/incubator/EditingWorkspace.tsx index 73a67d1649..e42a7f0e47 100644 --- a/src/components/incubator/EditingWorkspace.tsx +++ b/src/components/incubator/EditingWorkspace.tsx @@ -4,7 +4,6 @@ import * as React from 'react'; import { InterpreterOutput, IWorkspaceState } from '../../reducers/states'; import { history } from '../../utils/history'; -import { assessmentCategoryLink } from '../../utils/paramParseHelpers'; import { retrieveLocalAssessment, storeLocalAssessment, @@ -55,7 +54,6 @@ export type OwnProps = { questionId: number; assessmentOverview: IAssessmentOverview; updateAssessmentOverview: (overview: IAssessmentOverview) => void; - listingPath?: string; notAttempted: boolean; closeDate: string; }; @@ -110,12 +108,7 @@ class AssessmentWorkspace extends React.Component { + const question: IQuestion = this.state.assessment!.questions[this.formatedQuestionId()]; + const editorValue = + question.type === QuestionTypes.programming + ? ((question as IProgrammingQuestion).solutionTemplate as string) + : '//If you see this, this is a bug. Please report bug.'; + this.props.handleEditorValueChange(editorValue); + }; + private handleSave = () => { this.setState({ hasUnsavedChanges: false @@ -345,7 +347,9 @@ class AssessmentWorkspace extends React.Component { @@ -522,9 +526,7 @@ class AssessmentWorkspace extends React.Component { - const listingPath = - this.props.listingPath || - `/academy/${assessmentCategoryLink(this.state.assessment!.category)}`; + const listingPath = '/incubator'; const assessmentWorkspacePath = listingPath + `/${this.state.assessment!.id.toString()}`; return { handleEditorEval: this.props.handleEditorEval, diff --git a/src/components/incubator/assessmentTemplates.ts b/src/components/incubator/assessmentTemplates.ts index e395859e87..359c5fea2e 100644 --- a/src/components/incubator/assessmentTemplates.ts +++ b/src/components/incubator/assessmentTemplates.ts @@ -97,6 +97,7 @@ export const mcqTemplate = (): IMCQQuestion => { ], id: 2, library: emptyLibrary(), + graderLibrary: emptyLibrary(), type: 'mcq', solution: 0, grader: { diff --git a/src/components/incubator/editingWorkspaceSideContent/DeploymentTab.tsx b/src/components/incubator/editingWorkspaceSideContent/DeploymentTab.tsx index 30c5533753..73a9c90ff2 100644 --- a/src/components/incubator/editingWorkspaceSideContent/DeploymentTab.tsx +++ b/src/components/incubator/editingWorkspaceSideContent/DeploymentTab.tsx @@ -48,7 +48,6 @@ export class DeploymentTab extends React.Component {this.deploymentTab()} - } ); } else { @@ -71,26 +70,20 @@ export class DeploymentTab extends React.Component ( - - {this.textareaContent(deploymentPath.concat(['external', 'symbols', i]))} + {this.textareaContent(deploymentPath.concat(['external', 'symbols', i]))} + + {controlButton('Delete', IconNames.MINUS, this.handleSymbolDelete(i))} - {controlButton('Delete', IconNames.MINUS, this.handleSymbolDelete(i))} )); const globals = deployment.globals.map((symbol, i) => ( - -
- {this.textareaContent(deploymentPath.concat(['globals', i, 0]))} -
+ + {this.textareaContent(deploymentPath.concat(['globals', i, 0]))} - -
- {this.globalValueTextareaContent(i)} -
- - + {this.globalValueTextareaContent(i)} + {controlButton('Delete', IconNames.MINUS, this.handleGlobalDelete(i))} @@ -109,7 +102,9 @@ export class DeploymentTab extends React.Component
Symbols:

- {symbols}
+ + {symbols} +
{controlButton('New Symbol', IconNames.PLUS, this.handleNewSymbol)} ); @@ -118,7 +113,9 @@ export class DeploymentTab extends React.Component
Globals:

- {globals}
+ + {globals} +
{controlButton('New Global', IconNames.PLUS, this.handleNewGlobal)} ); @@ -191,7 +188,7 @@ export class DeploymentTab extends React.Component { } private manageQuestionTab = () => { + const index = this.props.questionId; return (
+ {controlButton( + 'Clone Current Question', + IconNames.DOCUMENT, + this.confirmSave( + this.makeQuestion(() => + deepCopy(this.props.assessment.questions[this.props.questionId]) + ) + ) + )} +
{controlButton( 'Insert Programming Question', IconNames.FONT, @@ -50,28 +62,57 @@ export class ManageQuestionTab extends React.Component { IconNames.CONFIRM, this.confirmSave(this.makeQuestion(mcqTemplate)) )} +
{controlButton( 'Delete Current Question', IconNames.REMOVE, - this.confirmSave(this.deleteQn) + this.confirmSave(this.deleteQuestion) )} +
+ {index > 0 + ? controlButton( + 'Shift Question Left', + IconNames.CARET_LEFT, + this.confirmSave(this.shiftQuestion(-1)) + ) + : undefined} + {index < this.props.assessment.questions.length - 1 + ? controlButton( + 'Shift Question Right', + IconNames.CARET_RIGHT, + this.confirmSave(this.shiftQuestion(1)) + ) + : undefined}
); }; - private makeQuestion = (template: () => any) => () => { + private shiftQuestion = (dir: number) => () => { const assessment = this.props.assessment; const index = this.props.questionId; - let questions = assessment.questions; - questions = questions - .slice(0, index) - .concat([template()]) - .concat(questions.slice(index)); + const newIndex = index + dir; + if (newIndex >= 0 && newIndex < assessment.questions.length) { + const question = assessment.questions[index]; + const questions = assessment.questions; + questions[index] = questions[newIndex]; + questions[newIndex] = question; + assessment.questions = questions; + this.props.updateAssessment(assessment); + history.push('/incubator/-1/' + newIndex.toString()); + } + }; + + private makeQuestion = (template: () => any) => () => { + const assessment = this.props.assessment; + const index = this.props.questionId + 1; + const questions = assessment.questions; + questions.splice(index, 0, template()); assessment.questions = questions; this.props.updateAssessment(assessment); + history.push('/incubator/-1/' + index.toString()); }; - private deleteQn = () => { + private deleteQuestion = () => { const assessment = this.props.assessment; let questions = assessment.questions; const index = this.props.questionId; @@ -129,4 +170,8 @@ export class ManageQuestionTab extends React.Component { ); } +const deepCopy = (arr: any) => { + return JSON.parse(JSON.stringify(arr)); +}; + export default ManageQuestionTab; diff --git a/src/components/incubator/index.tsx b/src/components/incubator/index.tsx index 3d2a82ac41..6e90f12c8c 100644 --- a/src/components/incubator/index.tsx +++ b/src/components/incubator/index.tsx @@ -67,7 +67,7 @@ class Assessment extends React.Component { }; return (
- +
); }