Skip to content

Commit 75d31c8

Browse files
manuweidependabot[bot]mbeisel
authored
Feature/markdown pattern references (#97)
* add button + functionaliaty to reference another pattern in the markdown editor * refactor getData method pattern language needs to be loaded first, because we need the pattern language object to load the pattern afterwards * load pattern language by either ID or URI when creating a pattern * use id instead of URI for navigation * refactoring * refactoring: move markdowneditor logic to its own class * enable to add href references to pattern when editing a pattern * fix minor deep code issues + whitespace * fix more deep code issues * Bump browserslist from 4.12.0 to 4.16.6 Bumps [browserslist](https://github.com/browserslist/browserslist) from 4.12.0 to 4.16.6. - [Release notes](https://github.com/browserslist/browserslist/releases) - [Changelog](https://github.com/browserslist/browserslist/blob/main/CHANGELOG.md) - [Commits](browserslist/browserslist@4.12.0...4.16.6) Signed-off-by: dependabot[bot] <[email protected]> * add css * fix lint errors * remove unused tests * remove unused test * comply to lint rules * fix typo * Changing this.pattern.id to this.patternId to prevent pattern.id does not exist bug * remove test log Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Martin Beisel <[email protected]>
1 parent 36d9f07 commit 75d31c8

File tree

19 files changed

+344
-161
lines changed

19 files changed

+344
-161
lines changed

src/app/core/component/cardrenderer/card-renderer.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class CardRendererComponent {
3232

3333
navigate(pattern: UriEntity): void {
3434
this.zone.run(() => {
35-
this.router.navigate([UriConverter.doubleEncodeUri(pattern.uri)], { relativeTo: this.activatedRoute });
35+
this.router.navigate([pattern.id], { relativeTo: this.activatedRoute });
3636
});
3737
}
3838

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<h1 mat-dialog-title *ngIf="data?.name">Do you really want to delete {{data.name}}?</h1>
22
<h1 mat-dialog-title *ngIf="!data?.name">Do you really want to delete this item?</h1>
33
<div mat-dialog-actions>
4-
<button mat-button (click)="onNoClick()">Cancle</button>
5-
<button [mat-dialog-close]="data" class="pattern-button" style="margin-left: auto;
4+
<button mat-button (click)="onNoClick()">Cancel</button>
5+
<button [mat-dialog-close]="data" class="pattern-button" style="margin-left: auto;
66
margin-right: 0;" mat-raised-button color="warn">
77
<i class="material-icons">delete</i>
88
</button>

src/app/core/component/edit-url-dialog/edit-url-dialog.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ <h1 mat-dialog-title>Edit Title or Icon for {{data.pattern.name}}</h1>
22
<div mat-dialog-content>
33
<mat-form-field>
44
<mat-label>Adjust Pattern Name</mat-label>
5-
<input matInput placeholder={{data.pattern.name}} [(ngModel)]="data.name" >
5+
<input matInput placeholder={{data.pattern.name}} [(ngModel)]="data.name">
66
</mat-form-field>
77
<mat-form-field>
88
<mat-label>Adjust Icon URL</mat-label>
9-
<input matInput placeholder={{data.pattern.iconUrl}} [(ngModel)]="data.icon" >
9+
<input matInput placeholder={{data.pattern.iconUrl}} [(ngModel)]="data.icon">
1010
</mat-form-field>
1111
</div>
1212
<mat-dialog-actions align="end">
13-
<button mat-button (click)="onNoClick()">Cancle</button>
13+
<button mat-button (click)="onNoClick()">Cancel</button>
1414
<button mat-button [mat-dialog-close]="data" cdkFocusInitial>Ok</button>
1515
</mat-dialog-actions>

src/app/core/component/markdown-content-container/discuss-dialog/discuss-dialog.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ <h1 mat-dialog-title>{{data.title}}</h1>
1313
<mat-dialog-actions align="end">
1414
<button mat-button (click)="deleteComment()">Delete comment</button>
1515
<div fxFlex></div>
16-
<button mat-button (click)="onNoClick()">Cancle</button>
16+
<button mat-button (click)="onNoClick()">Cancel</button>
1717
<button mat-button [mat-dialog-close]="data" cdkFocusInitial>Ok</button>
1818
</mat-dialog-actions>

src/app/core/component/markdown-content-container/markdown-pattern-sectioncontent/markdown-pattern-section-content.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import * as QuantumCircuit from 'quantum-circuit';
2626
export class MarkdownPatternSectionContentComponent extends DataRenderingComponent implements AfterViewInit {
2727
data: string;
2828
renderedData: string;
29+
patternLanguageId: string;
2930
title = '';
3031
imageModels: ImageModel[] = [];
3132
svg: Selection<SVGSVGElement, any, any, any>;
@@ -107,7 +108,7 @@ export class MarkdownPatternSectionContentComponent extends DataRenderingCompone
107108

108109
openEditor(): void {
109110
const dialogRef = this.dialog.open(MdEditorComponent,
110-
{ data: { content: this.data, field: this.title } });
111+
{ data: { content: this.data, field: this.title, patternLanguageId: this.patternLanguageId } });
111112
dialogRef.afterClosed().subscribe(async (result: DialogData) => {
112113
const previousValue = this.data;
113114

src/app/core/component/md-editor/md-editor.component.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@ <h1 mat-dialog-title>Edit '{{data.label}}'</h1>
44
<i class="material-icons">close</i>
55
</button>
66
</div>
7-
<div mat-dialog-content>
8-
<td-text-editor #mdEditor [value]="data.content"></td-text-editor>
7+
<div mat-dialog-content [formGroup]="selectedPatternForm">
8+
<div style="display: flex; align-items: center;">
9+
<mat-form-field appearance="fill" style="flex: 0.625; margin-right: 0.3em">
10+
<mat-label>Pattern</mat-label>
11+
<mat-select formControlName="selectedPattern">
12+
<mat-option *ngFor="let pattern of patterns" [value]="pattern">
13+
{{pattern.name}}
14+
</mat-option>
15+
</mat-select>
16+
</mat-form-field>
17+
<button mat-raised-button color="primary" [disabled]="!selectedPatternForm.controls['selectedPattern'].value"
18+
(click)="addReference()" matTooltip=" Add Reference to another Pattern">
19+
Add Reference
20+
</button>
21+
</div>
22+
<td-text-editor #mdEditor [value]="data.content" [options]="options"></td-text-editor>
923
</div>
1024
<div mat-dialog-actions>
1125
<button mat-raised-button color="warn"
Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,89 @@
1-
import { Component, Inject, ViewChild } from '@angular/core';
1+
import { Component, Inject, OnInit, ViewChild } from '@angular/core';
22
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
33
import { TdTextEditorComponent } from '@covalent/text-editor';
4+
import { MarkdownEditorUtils } from '../../util/markdown-editor-utils';
5+
import Pattern from '../../model/hal/pattern.model';
6+
import { PatternService } from '../../service/pattern.service';
7+
import { FormBuilder, FormGroup } from '@angular/forms';
48

59
export class DialogData {
6-
field: string;
7-
label?: string;
8-
content: string;
10+
11+
field: string;
12+
label?: string;
13+
content: string;
14+
patternLanguageId: string;
915
}
1016

1117
@Component({
1218
selector: 'pp-md-editor',
1319
templateUrl: './md-editor.component.html',
1420
styleUrls: ['./md-editor.component.scss']
1521
})
16-
export class MdEditorComponent {
22+
export class MdEditorComponent implements OnInit {
1723

18-
@ViewChild('mdEditor') private _textEditor: TdTextEditorComponent;
19-
private intialContent: string;
24+
@ViewChild('mdEditor') private _textEditor: TdTextEditorComponent;
25+
private intialContent: string;
26+
patterns: Array<Pattern>;
27+
selectedPatternForm: FormGroup;
2028

21-
constructor(public dialogRef: MatDialogRef<MdEditorComponent>,
22-
@Inject(MAT_DIALOG_DATA) public data: DialogData) {
23-
if (!data.label) {
24-
data.label = data.field;
25-
}
26-
this.intialContent = data.content;
27-
// We revert changes and close modal at click on backdrop
28-
this.dialogRef.backdropClick().subscribe(() => {
29-
this.dialogRef.close({ field: this.data.field, content: this.intialContent });
30-
});
31-
// We revert changes and close modal at hitting ESC
32-
this.dialogRef.keydownEvents().subscribe(event => {
33-
if (event.code === 'Escape') {
34-
this.dialogRef.close({ field: this.data.field, content: this.intialContent });
35-
}
36-
});
29+
constructor(public dialogRef: MatDialogRef<MdEditorComponent>,
30+
@Inject(MAT_DIALOG_DATA) public data: DialogData, private patternService: PatternService,
31+
private _fb: FormBuilder) {
32+
if (!data.label) {
33+
data.label = data.field;
3734
}
38-
39-
close(): void {
35+
this.intialContent = data.content;
36+
// We revert changes and close modal at click on backdrop
37+
this.dialogRef.backdropClick().subscribe(() => {
4038
this.dialogRef.close({ field: this.data.field, content: this.intialContent });
41-
}
39+
});
40+
// We revert changes and close modal at hitting ESC
41+
this.dialogRef.keydownEvents().subscribe(event => {
42+
if (event.code === 'Escape') {
43+
this.dialogRef.close({ field: this.data.field, content: this.intialContent });
44+
}
45+
});
46+
}
4247

43-
saveChanges(): void {
44-
this.dialogRef.close({ field: this.data.field, content: this._textEditor.value });
45-
}
48+
options: any = {
49+
autoDownloadFontAwesome: true,
50+
toolbar:
51+
[...MarkdownEditorUtils.standardMarkdownEditiorButtons,
52+
{
53+
name: 'latex-environment',
54+
action: (editor) => {
55+
MarkdownEditorUtils.insertTextAtCursor(editor, '$', '$');
56+
},
57+
className: 'fa fa-subscript',
58+
title: 'Add Formula',
59+
},
60+
'|', // Separator
61+
MarkdownEditorUtils.helpButton,
62+
'preview'
63+
],
64+
};
4665

47-
revert(): void {
48-
this._textEditor.value = this.intialContent;
49-
}
66+
ngOnInit() {
67+
this.patternService.getPatternsById(this.data.patternLanguageId).subscribe(res => this.patterns = res);
68+
this.selectedPatternForm = this._fb.group({
69+
selectedPattern: ['', []]
70+
});
71+
}
72+
73+
close(): void {
74+
this.dialogRef.close({ field: this.data.field, content: this.intialContent });
75+
}
76+
77+
saveChanges(): void {
78+
this.dialogRef.close({ field: this.data.field, content: this._textEditor.value });
79+
}
80+
81+
revert(): void {
82+
this._textEditor.value = this.intialContent;
83+
}
5084

85+
addReference() {
86+
const pattern = this.selectedPatternForm.controls['selectedPattern'].value;
87+
MarkdownEditorUtils.insertTextAtCursor(this._textEditor.simpleMDE, MarkdownEditorUtils.getPatternHrefMarkdown(this.data.patternLanguageId, pattern), '');
88+
}
5189
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<h1 mat-dialog-title>Which Pattern do you want to reference? </h1>
2+
<div mat-dialog-content [formGroup]="selectedPatternForm">
3+
<mat-form-field appearance="fill">
4+
<mat-label>Pattern</mat-label>
5+
<mat-select formControlName="selectedPattern">
6+
<mat-option *ngFor="let pattern of data.patterns" [value]="pattern">
7+
{{pattern.name}}
8+
</mat-option>
9+
</mat-select>
10+
</mat-form-field>
11+
</div>
12+
<mat-dialog-actions align="end">
13+
<button mat-button (click)="onNoClick()">Cancel</button>
14+
<button mat-button [mat-dialog-close]="selectedPatternForm.controls['selectedPattern'].value" cdkFocusInitial>Ok
15+
</button>
16+
</mat-dialog-actions>

src/app/core/component/select-pattern-dialog/select-pattern-dialog.component.scss

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Component, Inject, OnInit } from '@angular/core';
2+
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
3+
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
4+
5+
@Component({
6+
selector: 'pp-select-pattern-dialog',
7+
templateUrl: './select-pattern-dialog.component.html',
8+
styleUrls: ['./select-pattern-dialog.component.scss']
9+
})
10+
export class SelectPatternDialogComponent implements OnInit {
11+
12+
13+
constructor(
14+
public dialogRef: MatDialogRef<SelectPatternDialogComponent>,
15+
@Inject(MAT_DIALOG_DATA) public data: any, private _fb: FormBuilder) {
16+
}
17+
18+
selectedPatternForm: FormGroup;
19+
20+
onNoClick(): void {
21+
this.dialogRef.close();
22+
}
23+
24+
25+
ngOnInit(): void {
26+
this.selectedPatternForm = this._fb.group({
27+
selectedPattern: ['', [Validators.required]]
28+
});
29+
}
30+
31+
}

0 commit comments

Comments
 (0)