Skip to content

Commit

Permalink
feat: add content editable support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 11, 2020
1 parent a166b62 commit 6a51778
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/app/features/path/path.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="path">
<div class="header markdown">
<h2>Path to Production</h2>
<h3>Path to Production</h3>
</div>

<mat-toolbar>
Expand All @@ -24,17 +24,20 @@ <h2>{{pipe.title}}</h2>
</div>
</div>
<div class='wrapper' id="pipe">
<div class='container' *ngFor="let pipe of pipeData;let i = index"
<div class='container'
*ngFor="let pipe of pipeData;let i = index"
id="{{i}}_pipe"
[ngStyle]="getContainerStyle(pipe)">

<div
class="editable"
contenteditable="true"
#itemElement
id="pipe{{i}}_child{{j}}"
(click)="enableEdit(i, j)"
[ngStyle]="getEditableStyle()"
(keydown.enter)="updateItem(i, j, $event)"
ngDefaultControl
*ngFor="let item of pipe.items;let j = index" id="{{i}}_pipe_child{{j}}">
*ngFor="let item of pipe.items;let j = index">
{{item}}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/path/path.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

.header {
margin-top: 1em;
h2 {
h3 {
text-align: center;
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/app/features/path/path.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, OnInit} from '@angular/core';
import {Component, ElementRef, OnInit, QueryList, Renderer2, ViewChildren} from '@angular/core';
import {StorageMap} from '@ngx-pwa/local-storage';

interface Item {
Expand All @@ -15,6 +15,7 @@ interface Item {
styleUrls: ['./path.component.scss']
})
export class PathComponent implements OnInit {
@ViewChildren('itemElement') itemElements: QueryList<ElementRef>;
pipeData = [
{
id: 1,
Expand Down Expand Up @@ -74,7 +75,7 @@ export class PathComponent implements OnInit {
];
private maxLength: number;

constructor(private storage: StorageMap) {
constructor(private storage: StorageMap, private renderer: Renderer2) {
}

ngOnInit(): void {
Expand Down Expand Up @@ -169,4 +170,15 @@ export class PathComponent implements OnInit {

});
}

enableEdit(i: number, j: number) {
const elementId = `pipe${i}_child${j}`;
const filterElements = this.itemElements.filter((el) => {
return el.nativeElement.id === elementId;
});
if (filterElements.length > 0 ) {
const element = filterElements[0];
this.renderer.setProperty(element.nativeElement, 'contentEditable', true);
}
}
}
1 change: 1 addition & 0 deletions src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {DragulaModule} from 'ng2-dragula';
FormsModule,
ReactiveFormsModule,
MarkdownRenderComponent,
DragulaModule
],
entryComponents: []
})
Expand Down

0 comments on commit 6a51778

Please sign in to comment.