-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "refactor(Authoring): Create select component component"
This reverts commit 1b9b54b.
- Loading branch information
1 parent
1b9b54b
commit c794666
Showing
9 changed files
with
103 additions
and
173 deletions.
There are no files selected for viewing
13 changes: 0 additions & 13 deletions
13
src/app/authoring-tool/select-component/select-component.component.html
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
src/app/authoring-tool/select-component/select-component.component.spec.ts
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
src/app/authoring-tool/select-component/select-component.component.ts
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/app/authoring-tool/select-component/select-component.harness.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 52 additions & 9 deletions
61
src/app/authoring-tool/select-step-and-component/select-step-and-component.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,76 @@ | ||
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | ||
import { ProjectService } from '../../../assets/wise5/services/projectService'; | ||
import { ReferenceComponent } from '../../domain/referenceComponent'; | ||
import { MatFormFieldModule } from '@angular/material/form-field'; | ||
import { MatSelectModule } from '@angular/material/select'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { CommonModule } from '@angular/common'; | ||
import { SelectStepComponent } from '../select-step/select-step.component'; | ||
import { SelectComponentComponent } from '../select-component/select-component.component'; | ||
|
||
@Component({ | ||
selector: 'select-step-and-component', | ||
templateUrl: './select-step-and-component.component.html', | ||
styleUrls: ['./select-step-and-component.component.scss'], | ||
standalone: true, | ||
imports: [SelectComponentComponent, SelectStepComponent] | ||
imports: [CommonModule, FormsModule, MatFormFieldModule, MatSelectModule, SelectStepComponent] | ||
}) | ||
export class SelectStepAndComponentComponent { | ||
export class SelectStepAndComponentComponent implements OnInit { | ||
@Input() allowedComponentTypes: string[] = []; | ||
@Output() componentChange: EventEmitter<ReferenceComponent> = new EventEmitter(); | ||
protected components: any[] = []; | ||
protected componentToIsAllowed: Map<string, boolean> = new Map<string, boolean>(); | ||
@Input() referenceComponent: ReferenceComponent; | ||
@Output() stepChange: EventEmitter<ReferenceComponent> = new EventEmitter(); | ||
@Input() thisComponentId: string; | ||
|
||
constructor(private changeDetector: ChangeDetectorRef) {} | ||
constructor(private projectService: ProjectService) {} | ||
|
||
ngOnInit(): void { | ||
if (this.referenceComponent.nodeId != null) { | ||
this.calculateComponents(this.referenceComponent.nodeId); | ||
if (this.referenceComponent.componentId == null) { | ||
this.automaticallySetComponentIfPossible(this.referenceComponent.nodeId); | ||
} | ||
} | ||
} | ||
|
||
private calculateComponents(nodeId: string): void { | ||
this.components = this.projectService.getComponents(nodeId); | ||
for (const component of this.components) { | ||
this.componentToIsAllowed.set( | ||
component.id, | ||
this.allowedComponentTypes.includes(component.type) | ||
); | ||
} | ||
} | ||
|
||
protected stepChanged(nodeId: string): void { | ||
this.referenceComponent.nodeId = nodeId; | ||
this.changeDetector.detectChanges(); | ||
this.referenceComponent.componentId = null; | ||
this.automaticallySetComponentIfPossible(nodeId); | ||
this.calculateComponents(nodeId); | ||
this.stepChange.emit(this.referenceComponent); | ||
} | ||
|
||
protected componentChanged(componentId: string): void { | ||
this.referenceComponent.componentId = componentId; | ||
this.changeDetector.detectChanges(); | ||
protected componentChanged(): void { | ||
this.componentChange.emit(this.referenceComponent); | ||
} | ||
|
||
private automaticallySetComponentIfPossible(nodeId: string): void { | ||
let numAllowedComponents = 0; | ||
let allowedComponent = null; | ||
for (const component of this.projectService.getComponents(nodeId)) { | ||
if ( | ||
this.allowedComponentTypes.includes(component.type) && | ||
component.id !== this.thisComponentId | ||
) { | ||
numAllowedComponents += 1; | ||
allowedComponent = component; | ||
} | ||
} | ||
if (numAllowedComponents === 1) { | ||
this.referenceComponent.componentId = allowedComponent.id; | ||
this.componentChanged(); | ||
} | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
src/app/authoring-tool/select-step-and-component/select-step-and-component.harness.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { ComponentHarness } from '@angular/cdk/testing'; | ||
import { SelectStepHarness } from '../select-step/select-step.harness'; | ||
import { SelectComponentHarness } from '../select-component/select-component.harness'; | ||
|
||
export class SelectStepAndComponentHarness extends ComponentHarness { | ||
static hostSelector = 'select-step-and-component'; | ||
getSelectComponent = this.locatorFor(SelectComponentHarness); | ||
getSelectStep = this.locatorFor(SelectStepHarness); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters