Skip to content

Commit

Permalink
feat(Authoring): Allow adding branch from add step button (#1935)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Terashima <honchikun@gmail.com>
Co-authored-by: Jonathan Lim-Breitbart <breity10@gmail.com>
  • Loading branch information
3 people authored Sep 13, 2024
1 parent 400a4be commit 13dd769
Show file tree
Hide file tree
Showing 86 changed files with 4,993 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h6 *ngIf="item.order != 0 && item.node.type == 'group'">
mat-button
color="primary"
routerLink="../choose-unit"
[state]="{ targetId: targetId }"
[state]="target"
aria-label="Back"
i18n-aria-label
i18n
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ConfigService } from '../../../../assets/wise5/services/configService';
import { CopyNodesService } from '../../../../assets/wise5/services/copyNodesService';
import { InsertNodesService } from '../../../../assets/wise5/services/insertNodesService';
import { AbstractImportStepComponent } from '../../../../assets/wise5/authoringTool/addNode/abstract-import-step/abstract-import-step.component';
import { InsertFirstNodeInBranchPathService } from '../../../../assets/wise5/services/insertFirstNodeInBranchPathService';

@Component({
selector: 'choose-import-step',
Expand All @@ -19,12 +20,21 @@ export class ChooseImportStepComponent extends AbstractImportStepComponent {
constructor(
protected configService: ConfigService,
protected copyNodesService: CopyNodesService,
protected insertFirstNodeInBranchPathService: InsertFirstNodeInBranchPathService,
protected insertNodesService: InsertNodesService,
protected projectService: TeacherProjectService,
protected route: ActivatedRoute,
protected router: Router
) {
super(configService, copyNodesService, insertNodesService, projectService, route, router);
super(
configService,
copyNodesService,
insertFirstNodeInBranchPathService,
insertNodesService,
projectService,
route,
router
);
}

ngOnInit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ <h5 i18n>Choose a unit from which to import step(s).</h5>
<div class="nav-controls">
<mat-divider></mat-divider>
<div fxLayout="row" fxLayoutGap="16px" fxLayoutAlign="end center">
<button
mat-button
color="primary"
routerLink="../../choose-template"
[state]="{ targetId: targetId }"
i18n
>
<button mat-button color="primary" routerLink="../../choose-template" [state]="target" i18n>
Back
</button>
<span fxFlex></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ConfigService } from '../../../../assets/wise5/services/configService';
import { ProjectLibraryService } from '../../../../assets/wise5/services/projectLibraryService';
import { ActivatedRoute, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { AddStepTarget } from '../../../domain/addStepTarget';

@Component({
selector: 'choose-import-unit',
Expand All @@ -12,8 +13,8 @@ import { Subscription } from 'rxjs';
export class ChooseImportUnitComponent {
protected libraryProjects: any[];
protected myProjects: any[];
protected targetId: string;
private subscriptions: Subscription = new Subscription();
protected target: AddStepTarget;

constructor(
private configService: ConfigService,
Expand All @@ -23,7 +24,7 @@ export class ChooseImportUnitComponent {
) {}

ngOnInit(): void {
this.targetId = history.state.targetId;
this.target = history.state;
this.myProjects = this.configService.getAuthorableProjects();
this.subscriptions.add(
this.projectLibraryService.getLibraryProjects().subscribe((libraryProjects) => {
Expand All @@ -37,12 +38,10 @@ export class ChooseImportUnitComponent {
}

protected chooseProject(project: any): void {
this.target.importProjectId = project.id;
this.router.navigate(['../choose-step'], {
relativeTo: this.route,
state: {
importProjectId: project.id,
targetId: this.targetId
}
state: this.target
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export class SelectComponentComponent {
this.calculateComponents(this.nodeId);
this.setComponentId();
}
if (changes.allowedComponentTypes) {
this.allowedComponentTypes = changes.allowedComponentTypes.currentValue;
this.calculateComponents(this.nodeId);
}
if (changes.componentId) {
this.componentId = changes.componentId.currentValue;
}
}

private calculateComponents(nodeId: string): void {
Expand Down
20 changes: 20 additions & 0 deletions src/app/domain/addStepTarget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export class AddStepTarget {
branchNodeId?: string;
firstNodeIdInBranchPath?: string;
importProjectId?: number;
node?: any;
targetId?: string;
type: 'in' | 'after' | 'firstStepInBranchPath';

constructor(
type: 'in' | 'after' | 'firstStepInBranchPath',
targetId: string,
branchNodeId?: string,
firstNodeIdInBranchPath?: string
) {
this.type = type;
this.targetId = targetId;
this.branchNodeId = branchNodeId;
this.firstNodeIdInBranchPath = firstNodeIdInBranchPath;
}
}
28 changes: 28 additions & 0 deletions src/app/domain/branchCriteria.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const CHOICE_CHOSEN_VALUE = 'choiceChosen';
export const RANDOM_VALUE = 'random';
export const SCORE_VALUE = 'score';
export const WORKGROUP_ID_VALUE = 'workgroupId';

export interface BranchCriteria {
text: string;
value: string;
}

export const BRANCH_CRITERIA: BranchCriteria[] = [
{
text: $localize`Workgroup ID`,
value: WORKGROUP_ID_VALUE
},
{
text: $localize`Score`,
value: SCORE_VALUE
},
{
text: $localize`Choice Chosen`,
value: CHOICE_CHOSEN_VALUE
},
{
text: $localize`Random`,
value: RANDOM_VALUE
}
];
19 changes: 19 additions & 0 deletions src/app/services/branchServiceTestHelperFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { copy } from '../../assets/wise5/common/object/object';
import { TransitionLogic } from '../../assets/wise5/common/TransitionLogic';

export function expectTransitionLogic(node: any, transitionLogic: TransitionLogic) {
expect(copy(node.transitionLogic)).toEqual(copy(transitionLogic));
}

export function expectConstraint(
constraint: any,
expectedAction: string,
expectedTargetId: string,
expectedRemovalCriteria: any[]
) {
expect(constraint.action).toEqual(expectedAction);
expect(constraint.targetId).toEqual(expectedTargetId);
for (let i = 0; i < expectedRemovalCriteria.length; i++) {
expect(copy(constraint.removalCriteria[i])).toEqual(copy(expectedRemovalCriteria[i]));
}
}
Loading

0 comments on commit 13dd769

Please sign in to comment.