Skip to content

Mission editing slang #503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c4fe884
Removed previous button on first question, added divider
ZiHawkEye Mar 24, 2019
15d8749
Yarn format
ZiHawkEye Mar 24, 2019
079b843
Changeded help description
ZiHawkEye Mar 24, 2019
4b074f9
Merge pull request #12 from source-academy/mission-editing
gerhean Mar 24, 2019
f09f97c
fix import for firefox
gerhean Mar 24, 2019
0547d1f
max width for globals
ZiHawkEye Mar 24, 2019
eeeac40
merge
ZiHawkEye Mar 24, 2019
19044bb
symbols aligned
ZiHawkEye Mar 24, 2019
0cf76f4
increase abstraction
gerhean Mar 24, 2019
a254845
Merge pull request #13 from source-academy/mission-editing
gerhean Mar 24, 2019
01ffb72
manage questions give warning
gerhean Mar 24, 2019
22b7d80
Merge branch 'missionEditing-slang' of https://github.com/gerhean/cad…
gerhean Mar 24, 2019
1138294
UI change for deployment tab
ZiHawkEye Mar 24, 2019
03bdaa9
merge changes
gerhean Mar 24, 2019
de9f70a
Merge pull request #15 from source-academy/mission-editing
gerhean Mar 24, 2019
fb1353d
fixed maxGrade and maxXP calculation
gerhean Mar 24, 2019
6a173f2
added local/global switch
gerhean Mar 25, 2019
a7ee16c
adjust mcq options
gerhean Mar 25, 2019
60a7f64
split question template tab
gerhean Mar 25, 2019
c1cb2a7
swap answer and solutionTemplate
gerhean Mar 25, 2019
7460f3c
add reading
gerhean Mar 25, 2019
6ffe9cb
add grading deployment
gerhean Mar 25, 2019
a0f1237
Merge pull request #16 from source-academy/mission-editing
gerhean Mar 25, 2019
05dd14a
clone question shift question added
ZiHawkEye Mar 25, 2019
ab2976d
Merge pull request #17 from ZiHawkEye/mission-editing
gerhean Mar 25, 2019
9dce47b
fixed symbol formating
gerhean Mar 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/components/incubator/EditingWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -55,7 +54,6 @@ export type OwnProps = {
questionId: number;
assessmentOverview: IAssessmentOverview;
updateAssessmentOverview: (overview: IAssessmentOverview) => void;
listingPath?: string;
notAttempted: boolean;
closeDate: string;
};
Expand Down Expand Up @@ -110,12 +108,7 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
*/
public componentDidMount() {
if (this.props.assessment) {
const question: IQuestion = this.props.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);
this.resetEditorValue();
this.setState({
originalMaxGrade: this.getMaxMarks('maxGrade'),
originalMaxXp: this.getMaxMarks('maxXp')
Expand Down Expand Up @@ -295,6 +288,15 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
this.props.handleClearContext(library);
};

private resetEditorValue = () => {
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
Expand Down Expand Up @@ -345,7 +347,9 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
this.setState({
assessment: assessmentVal
});
this.handleRefreshLibrary();
this.handleSave();
this.resetEditorValue();
};

private handleChangeActiveTab = (tab: number) => {
Expand Down Expand Up @@ -522,9 +526,7 @@ class AssessmentWorkspace extends React.Component<AssessmentWorkspaceProps, ISta
props: AssessmentWorkspaceProps,
questionId: number
) => {
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,
Expand Down
1 change: 1 addition & 0 deletions src/components/incubator/assessmentTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const mcqTemplate = (): IMCQQuestion => {
],
id: 2,
library: emptyLibrary(),
graderLibrary: emptyLibrary(),
type: 'mcq',
solution: 0,
grader: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export class DeploymentTab extends React.Component<IProps, { activeTab: number }
{this.props.label + ' Deployment'}
<br />
{this.deploymentTab()}
}
</div>
);
} else {
Expand All @@ -71,26 +70,20 @@ export class DeploymentTab extends React.Component<IProps, { activeTab: number }
// const deploymentDisp = this.props.isGlobalDeployment ? 'Global Deployment' : 'Local Deployment';
const symbols = deployment.external.symbols.map((symbol, i) => (
<tr key={i}>
<td style={{ width: '520px' }}>
{this.textareaContent(deploymentPath.concat(['external', 'symbols', i]))}
<td>{this.textareaContent(deploymentPath.concat(['external', 'symbols', i]))}</td>
<td style={{ width: '100px' }}>
{controlButton('Delete', IconNames.MINUS, this.handleSymbolDelete(i))}
</td>
<td>{controlButton('Delete', IconNames.MINUS, this.handleSymbolDelete(i))}</td>
</tr>
));

const globals = deployment.globals.map((symbol, i) => (
<tr key={i}>
<td className="col-xs-3" style={{ height: '2rem', width: '10rem', overflow: 'auto' }}>
<div style={{ height: '2rem', width: '10rem', overflow: 'auto' }}>
{this.textareaContent(deploymentPath.concat(['globals', i, 0]))}
</div>
<td style={{ width: '170px' }}>
{this.textareaContent(deploymentPath.concat(['globals', i, 0]))}
</td>
<td className="col-xs-7" style={{ height: '2rem', width: '20rem', overflow: 'auto' }}>
<div style={{ height: '2rem', width: '20rem', overflow: 'auto' }}>
{this.globalValueTextareaContent(i)}
</div>
</td>
<td className="col-xs-2">
<td>{this.globalValueTextareaContent(i)}</td>
<td style={{ width: '90px' }}>
{controlButton('Delete', IconNames.MINUS, this.handleGlobalDelete(i))}
</td>
</tr>
Expand All @@ -109,7 +102,9 @@ export class DeploymentTab extends React.Component<IProps, { activeTab: number }
<br />
<div>Symbols:</div>
<br />
<table style={{ width: '100%' }}>{symbols}</table>
<table style={{ width: '100%' }}>
<tbody>{symbols}</tbody>
</table>
{controlButton('New Symbol', IconNames.PLUS, this.handleNewSymbol)}
</React.Fragment>
);
Expand All @@ -118,7 +113,9 @@ export class DeploymentTab extends React.Component<IProps, { activeTab: number }
<React.Fragment>
<div>Globals:</div>
<br />
<table style={{ width: '100%' }}>{globals}</table>
<table style={{ width: '100%', borderSpacing: '5px' }}>
<tbody>{globals}</tbody>
</table>
{controlButton('New Global', IconNames.PLUS, this.handleNewGlobal)}
</React.Fragment>
);
Expand Down Expand Up @@ -191,7 +188,7 @@ export class DeploymentTab extends React.Component<IProps, { activeTab: number }
global[1] = altEval(global[2]!);
this.props.updateAssessment(assessment);
} catch (e) {
global[2] = 'Invalid Expression';
global[2] = '"Invalid Expression"';
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ButtonGroup, Classes, Dialog, Intent } from '@blueprintjs/core';
import { IconNames } from '@blueprintjs/icons';
import * as React from 'react';

import { history } from '../../../utils/history';
import { IAssessment } from '../../assessment/assessmentShape';
import { controlButton } from '../../commons';
import Markdown from '../../commons/Markdown';
Expand Down Expand Up @@ -38,8 +39,19 @@ export class ManageQuestionTab extends React.Component<IProps, IState> {
}

private manageQuestionTab = () => {
const index = this.props.questionId;
return (
<div>
{controlButton(
'Clone Current Question',
IconNames.DOCUMENT,
this.confirmSave(
this.makeQuestion(() =>
deepCopy(this.props.assessment.questions[this.props.questionId])
)
)
)}
<br />
{controlButton(
'Insert Programming Question',
IconNames.FONT,
Expand All @@ -50,28 +62,57 @@ export class ManageQuestionTab extends React.Component<IProps, IState> {
IconNames.CONFIRM,
this.confirmSave(this.makeQuestion(mcqTemplate))
)}
<br />
{controlButton(
'Delete Current Question',
IconNames.REMOVE,
this.confirmSave(this.deleteQn)
this.confirmSave(this.deleteQuestion)
)}
<br />
{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}
</div>
);
};

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;
Expand Down Expand Up @@ -129,4 +170,8 @@ export class ManageQuestionTab extends React.Component<IProps, IState> {
);
}

const deepCopy = (arr: any) => {
return JSON.parse(JSON.stringify(arr));
};

export default ManageQuestionTab;
2 changes: 1 addition & 1 deletion src/components/incubator/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Assessment extends React.Component<IAssessmentProps, State> {
};
return (
<div className="Academy">
<EditingWorkspaceContainer {...assessmentProps} listingPath="/incubator" />
<EditingWorkspaceContainer {...assessmentProps} />
</div>
);
}
Expand Down