diff --git a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.component.ts b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.component.ts
index 1ee4bbf582..ab9e8c7310 100644
--- a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.component.ts
+++ b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.component.ts
@@ -1,6 +1,7 @@
-import { Component, Input, OnChanges } from '@angular/core';
+import { AfterViewChecked, Component, ElementRef, Input, OnChanges, ViewChild } from '@angular/core';
import { isEmpty } from 'tsfun';
-import { Relation, Resource } from 'idai-field-core';
+import { Relation, Resource, Document } from 'idai-field-core';
+import { AngularUtility } from '../../../../angular/angular-utility';
/**
@@ -10,13 +11,18 @@ import { Relation, Resource } from 'idai-field-core';
selector: 'relation-picker-group',
templateUrl: './relation-picker-group.html'
})
-export class RelationPickerGroupComponent implements OnChanges {
+export class RelationPickerGroupComponent implements OnChanges, AfterViewChecked {
@Input() resource: Resource;
@Input() relationDefinition: Relation;
+ @ViewChild('plusButton') plusButtonElement: ElementRef;
+
public relations: any;
+ private creating: boolean = false;
+ private autoScroll: boolean = false;
+
public ngOnChanges() {
@@ -24,12 +30,33 @@ export class RelationPickerGroupComponent implements OnChanges {
}
- public createRelation() {
+ public async ngAfterViewChecked() {
+
+ if (this.autoScroll && this.plusButtonElement) {
+ await AngularUtility.refresh();
+ this.plusButtonElement.nativeElement.scrollIntoViewIfNeeded(false);
+ this.autoScroll = false;
+ }
+ }
+
+
+ public onTargetSelected(target: Document) {
+
+ if (this.creating) {
+ this.creating = false;
+ if (target) this.autoScroll = true;
+ }
+ }
+
+
+ public async createRelation() {
if (!this.relations[this.relationDefinition.name])
this.relations[this.relationDefinition.name] = [];
this.relations[this.relationDefinition.name].push('');
+
+ this.creating = true;
}
@@ -42,7 +69,7 @@ export class RelationPickerGroupComponent implements OnChanges {
}
- public isPlusButtonVisible(): boolean {
+ public isPlusButtonAvailable(): boolean {
return !this.relations[this.relationDefinition.name]
|| isEmpty(this.relations[this.relationDefinition.name])
diff --git a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.html b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.html
index 16948259e8..d9efcb8b02 100644
--- a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.html
+++ b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.html
@@ -1,14 +1,15 @@
+ [relationIndex]="i"
+ (onTargetSelected)="onTargetSelected($event)">
- 0"
type="button"
(click)="createRelation()">+
- 1"
+
1"
class="relation-picker-group-space">
-
\ No newline at end of file
diff --git a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.scss b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.scss
index 1876b97791..f22a1e525c 100644
--- a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.scss
+++ b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker-group.scss
@@ -22,6 +22,7 @@ relation-picker-group {
color: #555 !important;
box-shadow: 0 1px 1px 1px rgba(0, 0, 0, 0.14), 0 0 0 0 rgba(0, 0, 0, 0.14) !important;
user-select: none;
+ scroll-margin: 10px;
&.with-margin {
margin-top: 5px;
diff --git a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker.component.ts b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker.component.ts
index 0ba40c3b29..c2fa45cccb 100644
--- a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker.component.ts
+++ b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker.component.ts
@@ -1,4 +1,4 @@
-import { Component, Input, OnChanges } from '@angular/core';
+import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { isUndefinedOrEmpty } from 'tsfun';
import { Document, Datastore, Resource, Relation, Labels, ProjectConfiguration } from 'idai-field-core';
import { getSuggestions } from './get-suggestions';
@@ -22,6 +22,8 @@ export class RelationPickerComponent implements OnChanges {
@Input() relationDefinition: Relation;
@Input() relationIndex: number;
+ @Output() onTargetSelected: EventEmitter
= new EventEmitter();
+
public availableTargets: Array;
public selectedTarget: Document|undefined;
public disabled: boolean = false;
@@ -54,9 +56,9 @@ export class RelationPickerComponent implements OnChanges {
}
- public onTargetSelected(targetId: string) {
+ public selectTarget(targetId: string) {
- const target: Document = targetId
+ const target: Document|undefined = targetId
? this.availableTargets.find(t => t.resource.id === targetId)
: undefined;
@@ -65,6 +67,8 @@ export class RelationPickerComponent implements OnChanges {
} else {
this.deleteRelation();
}
+
+ this.onTargetSelected.emit(target);
}
@@ -72,6 +76,7 @@ export class RelationPickerComponent implements OnChanges {
await this.updateSelectedTarget();
if (!this.selectedTarget) this.deleteRelation();
+ this.onTargetSelected.emit();
}
diff --git a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker.html b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker.html
index c16967673d..4b1f9c5879 100644
--- a/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker.html
+++ b/desktop/src/app/components/docedit/widgets/relationpicker/relation-picker.html
@@ -4,7 +4,7 @@
[values]="getAvailableTargetIds()"
[getLabel]="getTargetLabel"
[initiallyOpened]="true"
- (onValueSelected)="onTargetSelected($event)"
+ (onValueSelected)="selectTarget($event)"
(onBlur)="onBlur()"
(onScrollToEnd)="loadNextChunk()"
(onSearchTermChanged)="search($event)">