Skip to content

Commit 614d000

Browse files
authored
Merge pull request #83 from PatternAtlas/fix/pattern-navigation
Fix/pattern navigation
2 parents e67bf8e + d293713 commit 614d000

File tree

37 files changed

+1023
-318
lines changed

37 files changed

+1023
-318
lines changed

src/app/core/component/action-button-bar/action-button-bar.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<mat-toolbar>
22
<pp-navigate-back *ngIf="goBackButton"></pp-navigate-back>
33

4+
<span></span>
5+
<img class="image-with-margin" mat-card-image (click)=iconEditButtonClicked() *ngIf="iconUrl" [src]="iconUrl">
6+
47
<span class="action-button-with-margin"><b>{{this.displayText}}</b></span>
58

69
<ng-content></ng-content>

src/app/core/component/action-button-bar/action-button-bar.component.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,15 @@
22
margin-right: 10px;
33
margin-left: 10px;
44
}
5+
6+
.mat-card-image {
7+
width: auto;
8+
height: 50px;
9+
cursor: pointer;
10+
}
11+
12+
.image-with-margin {
13+
margin-right: 5px;
14+
margin-left: 15px;
15+
}
16+

src/app/core/component/action-button-bar/action-button-bar.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ export class ActionButtonBarComponent implements OnInit {
1111
@Output() add2Clicked = new EventEmitter<void>();
1212
@Output() reloadClicked = new EventEmitter<void>();
1313
@Output() changedText = new EventEmitter<void>();
14+
@Output() iconEditClicked = new EventEmitter<void>();
1415
@Input() addButtonText: string;
1516
@Input() reloadButton = false;
1617
@Input() goBackButton = true;
1718
@Input() secondAddButton: boolean;
1819
@Input() firstAddButton = true;
1920
@Input() secondAddButtonText: string;
21+
@Input() iconEdit = false;
22+
@Input() iconUrl: string;
2023

2124
@Input() displayText: string;
2225

@@ -38,4 +41,8 @@ export class ActionButtonBarComponent implements OnInit {
3841
secondAddButtonClicked() {
3942
this.add2Clicked.emit();
4043
}
44+
45+
iconEditButtonClicked() {
46+
this.iconEditClicked.emit();
47+
}
4148
}

src/app/core/component/create-pattern-relation/create-pattern-relation.component.html

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
<h1 mat-dialog-title>Add a relation to another pattern</h1>
1+
<h1 *ngIf="isDelete" mat-dialog-title>Edit or Delete the selected Relation</h1>
2+
<h1 *ngIf="!isDelete" mat-dialog-title>Add a Relation to another Pattern</h1>
23
<div mat-dialog-content [formGroup]="relationForm">
34
<mat-form-field *ngIf="data.firstPattern; else chooseFirstPattern">
45
<input type="text" matInput [value]="data.firstPattern.name" readonly/>
56
</mat-form-field>
67
<ng-template #chooseFirstPattern>
8+
<mat-form-field *ngIf="relationForm.get('secondPattern').value != null; else chooseFirstPatternWithEmptyForm">
9+
<mat-select formControlName="firstPattern">
10+
<div *ngFor="let pattern of data.patterns">
11+
<mat-option *ngIf="pattern.name != relationForm.get('secondPattern').value.name "
12+
[value]="pattern">
13+
{{pattern.name}}
14+
</mat-option>
15+
</div>
16+
</mat-select>
17+
</mat-form-field>
18+
</ng-template>
19+
<ng-template #chooseFirstPatternWithEmptyForm>
720
<mat-form-field>
821
<mat-select formControlName="firstPattern">
922
<mat-option *ngFor="let pattern of data.patterns"
@@ -42,6 +55,18 @@ <h1 mat-dialog-title>Add a relation to another pattern</h1>
4255
<input type="text" matInput [value]="data.secondPattern.name" readonly/>
4356
</mat-form-field>
4457
<ng-template #chooseSecondPattern>
58+
<mat-form-field *ngIf="relationForm.get('firstPattern').value != null; else chooseSecondPatternWithEmptyForm">
59+
<mat-select formControlName="secondPattern">
60+
<div *ngFor="let pattern of data.patterns">
61+
<mat-option *ngIf=" pattern.name != relationForm.get('firstPattern').value.name"
62+
[value]="pattern">
63+
{{pattern.name}}
64+
</mat-option>
65+
</div>
66+
</mat-select>
67+
</mat-form-field>
68+
</ng-template>
69+
<ng-template #chooseSecondPatternWithEmptyForm>
4570
<mat-form-field>
4671
<mat-select formControlName="secondPattern">
4772
<mat-option *ngFor="let pattern of data.patterns"
@@ -56,8 +81,13 @@ <h1 mat-dialog-title>Add a relation to another pattern</h1>
5681
</mat-form-field>
5782
</div>
5883
<div mat-dialog-actions>
59-
<button mat-button [mat-dialog-close]="null">Close</button>
60-
<button mat-button [mat-dialog-close]="mapDialogDataToEdge(relationForm.value)" [disabled]="!relationForm?.valid">
61-
Save
84+
<button mat-raised-button [mat-dialog-close]="null">Close</button>
85+
<button *ngIf="isDelete" (click)="deleteLink()" [mat-dialog-close]="data" class="pattern-button" mat-raised-button color="warn">
86+
<i class="material-icons">delete</i> Delete
87+
</button>
88+
89+
<button mat-raised-button style="margin-left: auto; margin-right: 0;" color="primary"
90+
[mat-dialog-close]="mapDialogDataToEdge(relationForm.value)" [disabled]="!relationForm?.valid"><i
91+
class="material-icons">save</i> Save
6292
</button>
6393
</div>

src/app/core/component/create-pattern-relation/create-pattern-relation.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@
55
.mat-form-field {
66
margin-left: 2.5rem !important;
77
}
8+
9+
.mat-input-element {
10+
height: 1.125em;
11+
}

src/app/core/component/create-pattern-relation/create-pattern-relation.component.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ import { Observable } from 'rxjs';
1515
styleUrls: ['./create-pattern-relation.component.scss']
1616
})
1717

18-
18+
/**
19+
* This dialog is getting used to
20+
* 1. Create new relations
21+
* 2. Edit existing relations (isDelete = true)
22+
* 3. Delete existing relations (isDelete = true)
23+
*/
1924
export class CreatePatternRelationComponent implements OnInit {
2025

2126
constructor(public dialogRef: MatDialogRef<CreatePatternRelationComponent>, @Inject(MAT_DIALOG_DATA) public data: DialogData, private fb: FormBuilder) {
2227
}
2328

29+
isDelete: boolean;
2430
directionEnum = PatternRelationDescriptorDirection;
2531
patterns: Pattern[];
2632
directionTypes = [
@@ -54,14 +60,17 @@ export class CreatePatternRelationComponent implements OnInit {
5460
} catch (e) {
5561
}
5662

63+
if(this.data.description === undefined){
64+
this.data.description = '';
65+
}
66+
this.isDelete =this.data.isDelete; // set view to delete/edit instead of create
5767
this.relationForm = this.fb.group({
5868
firstPattern: [this.data.firstPattern, [Validators.required]],
5969
secondPattern: [this.data.secondPattern, [Validators.required]],
6070
direction: [preselectedEdgeDirection, [Validators.required]],
61-
relationType: ['', [Validators.required]],
62-
description: ['', []],
71+
relationType: [this.data.relationType, [Validators.required]],
72+
description: [this.data.description, []],
6373
});
64-
6574
if (this.data.relationTypes) {
6675
this.subscriptionRefs.push(this.data.relationTypes.subscribe(relationTypes => this.relationTypes = relationTypes));
6776
}
@@ -94,16 +103,26 @@ export class CreatePatternRelationComponent implements OnInit {
94103

95104
}
96105

106+
/**
107+
* called when delete button is pressed --> delete Link
108+
*/
109+
deleteLink() {
110+
this.data.deleteLink = true;
111+
}
97112
}
98113

99114
export interface DialogData {
115+
relationType: string;
116+
description: string;
100117
firstPattern?: Pattern;
101118
secondPattern?: Pattern;
102119
preselectedEdgeDirection?: PatternRelationDescriptorDirection;
103120
patterns: Pattern[];
104121
patternLanguage: PatternLanguage;
105122
patternContainer: PatternContainer;
106123
relationTypes?: Observable<string[]>;
124+
isDelete: boolean; // delete button toggle
125+
deleteLink: boolean; // set true if delete button pressed
107126
}
108127

109128
export interface PatternRelationDirection {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h1 mat-dialog-title>Edit or Delete Relation</h1>
2+
<div mat-dialog-actions>
3+
<button mat-button (click)="onNoClick()">Cancle</button>
4+
<button [mat-dialog-close]="data" class="pattern-button" mat-raised-button color="warn">
5+
<i class="material-icons">delete</i>
6+
</button>
7+
</div>

src/app/core/component/delete-confirmation-dialog/delete-confirmation-dialog.component.scss

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { DeleteConfirmationDialogComponent } from './delete-confirmation-dialog.component';
4+
5+
describe('DeleteConfirmationDialogComponent', () => {
6+
let component: DeleteConfirmationDialogComponent;
7+
let fixture: ComponentFixture<DeleteConfirmationDialogComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [ DeleteConfirmationDialogComponent ]
12+
})
13+
.compileComponents();
14+
}));
15+
16+
beforeEach(() => {
17+
fixture = TestBed.createComponent(DeleteConfirmationDialogComponent);
18+
component = fixture.componentInstance;
19+
fixture.detectChanges();
20+
});
21+
22+
it('should create', () => {
23+
expect(component).toBeTruthy();
24+
});
25+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component, Inject } from '@angular/core';
2+
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
3+
4+
@Component({
5+
selector: 'pp-delete-confirmation-dialog',
6+
templateUrl: './delete-confirmation-dialog.component.html',
7+
styleUrls: ['./delete-confirmation-dialog.component.scss']
8+
})
9+
export class DeleteConfirmationDialogComponent {
10+
11+
constructor(
12+
public dialogRef: MatDialogRef<DeleteConfirmationDialogComponent>,
13+
@Inject(MAT_DIALOG_DATA) public data) {
14+
}
15+
16+
onNoClick(): void {
17+
this.dialogRef.close();
18+
}
19+
}

0 commit comments

Comments
 (0)