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

[editor] Change element selection to also select the underlying section

Need to bubble the event further up to where there is a section 
reference.
parent 6b784d4a
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<app-section-static *ngIf="!section.dynamicPositioning" <app-section-static *ngIf="!section.dynamicPositioning"
class="section drop-list" id="section-{{i}}" class="section drop-list" id="section-{{i}}"
[section]="section" [section]="section"
[sectionIndex]="i"
[isSelected]="selectionService.selectedPageSectionIndex === i" [isSelected]="selectionService.selectedPageSectionIndex === i"
cdkDropList cdkDropListSortingDisabled cdkDropList cdkDropListSortingDisabled
[cdkDropListData]="{ sectionIndex: i }" [cdkDropListData]="{ sectionIndex: i }"
......
import { import {
Directive, Input, Directive, Input,
ComponentFactoryResolver, ComponentRef, ComponentFactoryResolver, ComponentRef,
ViewChild, ViewContainerRef, OnInit, OnDestroy, ChangeDetectorRef ViewChild, ViewContainerRef, OnInit, OnDestroy, ChangeDetectorRef, Output, EventEmitter
} from '@angular/core'; } from '@angular/core';
import { Subject } from 'rxjs'; import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
...@@ -19,6 +19,7 @@ import { ClozeElement } from '../../../../../../../../common/models/compound-ele ...@@ -19,6 +19,7 @@ import { ClozeElement } from '../../../../../../../../common/models/compound-ele
export abstract class CanvasElementOverlay implements OnInit, OnDestroy { export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
@Input() element!: UIElement; @Input() element!: UIElement;
@Input() viewMode: boolean = false; @Input() viewMode: boolean = false;
@Output() elementSelected = new EventEmitter<any>();
@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 | CompoundElementComponent>; protected childComponent!: ComponentRef<ElementComponent | CompoundElementComponent>;
...@@ -59,9 +60,9 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy { ...@@ -59,9 +60,9 @@ export abstract class CanvasElementOverlay implements OnInit, OnDestroy {
selectElement(multiSelect: boolean = false): void { selectElement(multiSelect: boolean = false): void {
if (multiSelect) { if (multiSelect) {
this.selectionService.selectElement({ componentElement: this, multiSelect: true }); this.elementSelected.emit({ componentElement: this, multiSelect: true });
} else { } else {
this.selectionService.selectElement({ componentElement: this, multiSelect: false }); this.elementSelected.emit({ componentElement: this, multiSelect: false });
} }
} }
......
...@@ -6,6 +6,7 @@ import { DragItemData, DropListData } from './canvas.component'; ...@@ -6,6 +6,7 @@ import { DragItemData, DropListData } from './canvas.component';
import { UnitService } from '../../../../services/unit.service'; import { UnitService } from '../../../../services/unit.service';
import { Section } from '../../../../../../../common/models/section'; import { Section } from '../../../../../../../common/models/section';
import { UIElementType } from '../../../../../../../common/models/uI-element'; import { UIElementType } from '../../../../../../../common/models/uI-element';
import { SelectionService } from '../../../../services/selection.service';
@Component({ @Component({
selector: 'app-section-dynamic', selector: 'app-section-dynamic',
...@@ -52,6 +53,8 @@ import { UIElementType } from '../../../../../../../common/models/uI-element'; ...@@ -52,6 +53,8 @@ import { UIElementType } from '../../../../../../../common/models/uI-element';
cdkDropList cdkDropListSortingDisabled cdkDropList cdkDropListSortingDisabled
[cdkDropListData]="{ sectionIndex: sectionIndex }" [cdkDropListData]="{ sectionIndex: sectionIndex }"
[cdkDropListConnectedTo]="dropListList" [cdkDropListConnectedTo]="dropListList"
(elementSelected)="selectionService.selectElement($event);
selectionService.selectedPageSectionIndex = sectionIndex"
(resize)="resizeOverlay($event)" (resize)="resizeOverlay($event)"
[style.position]="'relative'" [style.position]="'relative'"
[style.pointer-events]="dragging ? 'none' : 'auto'"> [style.pointer-events]="dragging ? 'none' : 'auto'">
...@@ -71,7 +74,7 @@ export class SectionDynamicComponent { ...@@ -71,7 +74,7 @@ export class SectionDynamicComponent {
dragging = false; dragging = false;
constructor(public unitService: UnitService) { } constructor(public unitService: UnitService, public selectionService: SelectionService) { }
drop(event: CdkDragDrop<DropListData>): void { drop(event: CdkDragDrop<DropListData>): void {
const dragItemData: DragItemData = event.item.data; const dragItemData: DragItemData = event.item.data;
......
...@@ -4,6 +4,7 @@ import { ...@@ -4,6 +4,7 @@ import {
import { UnitService } from '../../../../services/unit.service'; import { UnitService } from '../../../../services/unit.service';
import { Section } from '../../../../../../../common/models/section'; import { Section } from '../../../../../../../common/models/section';
import { UIElementType } from '../../../../../../../common/models/uI-element'; import { UIElementType } from '../../../../../../../common/models/uI-element';
import { SelectionService } from '../../../../services/selection.service';
@Component({ @Component({
selector: 'app-section-static', selector: 'app-section-static',
...@@ -16,7 +17,9 @@ import { UIElementType } from '../../../../../../../common/models/uI-element'; ...@@ -16,7 +17,9 @@ import { UIElementType } from '../../../../../../../common/models/uI-element';
(dragover)="$event.preventDefault()" (drop)="newElementDropped($event)"> (dragover)="$event.preventDefault()" (drop)="newElementDropped($event)">
<app-static-canvas-overlay <app-static-canvas-overlay
*ngFor="let element of section.elements" *ngFor="let element of section.elements"
[element]="$any(element)"> [element]="$any(element)"
(elementSelected)="selectionService.selectElement($event);
selectionService.selectedPageSectionIndex = sectionIndex">
</app-static-canvas-overlay> </app-static-canvas-overlay>
</div> </div>
`, `,
...@@ -26,10 +29,11 @@ import { UIElementType } from '../../../../../../../common/models/uI-element'; ...@@ -26,10 +29,11 @@ import { UIElementType } from '../../../../../../../common/models/uI-element';
}) })
export class SectionStaticComponent { export class SectionStaticComponent {
@Input() section!: Section; @Input() section!: Section;
@Input() sectionIndex!: number;
@Input() isSelected!: boolean; @Input() isSelected!: boolean;
@ViewChild('sectionElement') sectionElement!: ElementRef; @ViewChild('sectionElement') sectionElement!: ElementRef;
constructor(public unitService: UnitService) { } constructor(public unitService: UnitService, public selectionService: SelectionService) { }
newElementDropped(event: DragEvent): void { newElementDropped(event: DragEvent): void {
event.preventDefault(); event.preventDefault();
......
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