Skip to content
Snippets Groups Projects
Commit 18a6e881 authored by rhenck's avatar rhenck
Browse files

[editor] Add selection logic for Cloze Components

This uses a special event fired only by ClozeComponent, but potentially 
future compound elements as well.
The selection service gets a special method bypassing the usual 
selection logic and just firing the selection event for the props panel.
parent 49c3c7a9
No related branches found
No related tags found
No related merge requests found
...@@ -4,11 +4,16 @@ import { ...@@ -4,11 +4,16 @@ import {
ViewChild, ViewContainerRef, OnInit, OnDestroy, ChangeDetectorRef ViewChild, ViewContainerRef, OnInit, OnDestroy, ChangeDetectorRef
} from '@angular/core'; } from '@angular/core';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { UnitService } from '../../../../services/unit.service'; import { takeUntil } from 'rxjs/operators';
import * as ElementFactory from '../../../../../../../common/util/element.factory'; import { UnitService } from '../../../../../services/unit.service';
import { ElementComponent } from '../../../../../../../common/element-component.directive'; import * as ElementFactory from '../../../../../../../../common/util/element.factory';
import { SelectionService } from '../../../../services/selection.service'; import { ElementComponent } from '../../../../../../../../common/element-component.directive';
import { UIElement } from '../../../../../../../common/models/uI-element'; import { SelectionService } from '../../../../../services/selection.service';
import { UIElement } from '../../../../../../../../common/models/uI-element';
import { CompoundElementComponent } from
'../../../../../../../../common/element-components/compound-elements/compound-element.directive';
import { ClozeComponent } from '../../../../../../../../common/element-components/compound-elements/cloze.component';
import { ClozeElement } from '../../../../../../../../common/models/compound-elements/cloze-element';
@Directive() @Directive()
export abstract class CanvasElementOverlay implements OnInit, OnDestroy { export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
...@@ -16,7 +21,7 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy { ...@@ -16,7 +21,7 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
@Input() viewMode: boolean = false; @Input() viewMode: boolean = false;
@ViewChild('elementContainer', { read: ViewContainerRef, static: true }) private elementContainer!: ViewContainerRef; @ViewChild('elementContainer', { read: ViewContainerRef, static: true }) private elementContainer!: ViewContainerRef;
isSelected = false; isSelected = false;
protected childComponent!: ComponentRef<ElementComponent>; protected childComponent!: ComponentRef<ElementComponent | CompoundElementComponent>;
private ngUnsubscribe = new Subject<void>(); private ngUnsubscribe = new Subject<void>();
constructor(public selectionService: SelectionService, constructor(public selectionService: SelectionService,
...@@ -30,21 +35,18 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy { ...@@ -30,21 +35,18 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
this.childComponent.instance.elementModel = this.element; this.childComponent.instance.elementModel = this.element;
// Make children not clickable. This way the only relevant events are managed by the overlay. // Make children not clickable. This way the only relevant events are managed by the overlay.
// this.childComponent.location.nativeElement.style.pointerEvents = 'none'; this.childComponent.location.nativeElement.style.pointerEvents = 'none';
this.selectionService.selectElement({ componentElement: this, multiSelect: false }); this.selectionService.selectElement({ componentElement: this, multiSelect: false });
// This allows to listen for changed directly on the element. And update the model accordingly. if (this.childComponent.instance instanceof ClozeComponent) {
// Since the elements are no longer interactable this code is not used. It may be in the future that this.childComponent.instance.elementSelected
// this functionality is wanted again. Therefore the code is kept in commented out form. .pipe(takeUntil(this.ngUnsubscribe))
.subscribe((element: ClozeElement) => {
// if (this.childComponent.instance instanceof FormElementComponent) { this.childComponent.location.nativeElement.style.pointerEvents = 'unset';
// this.childComponent.instance.elementValueChanged this.selectionService.selectCompoundChild(element);
// .pipe(takeUntil(this.ngUnsubscribe)) });
// .subscribe((changeElement: ValueChangeElement) => { }
// this.unitService.updateElementProperty([this.element], 'value', changeElement.values[1]);
// });
// }
} }
setSelected(newValue: boolean): void { setSelected(newValue: boolean): void {
......
...@@ -39,4 +39,8 @@ export class SelectionService { ...@@ -39,4 +39,8 @@ export class SelectionService {
this.selectedElementComponents = []; this.selectedElementComponents = [];
this._selectedElements.next([]); this._selectedElements.next([]);
} }
selectCompoundChild(element: UIElement): void {
this._selectedElements.next([element]);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment