TextComponent.editable

This commit is contained in:
Patrick Haßel 2024-10-29 12:03:57 +01:00
parent 7dc4c3ca7c
commit 65617c1538
4 changed files with 15 additions and 8 deletions

View File

@ -60,7 +60,8 @@ export class UserService {
return this.subject.subscribe(next); return this.subject.subscribe(next);
} }
owns(group: Group): boolean { iOwn(group: Group): boolean {
return this.user?.publicUuid === group.owner.publicUuid; return this.user?.publicUuid === group.owner.publicUuid;
} }
} }

View File

@ -8,15 +8,15 @@
<tr> <tr>
<th>Titel</th> <th>Titel</th>
<td> <td>
<app-text *ngIf="userService.owns(group)" [initial]="group.title" (onChange)="changeTitle(group, $event)"></app-text> <app-text [initial]="group.title" [editable]="userService.iOwn(group)" (onChange)="changeTitle(group, $event)"></app-text>
<ng-container *ngIf="!userService.owns(group)"></ng-container> <ng-container *ngIf="!userService.iOwn(group)"></ng-container>
</td> </td>
</tr> </tr>
<tr> <tr>
<th>Passwort</th> <th>Passwort</th>
<td> <td>
<app-text *ngIf="userService.owns(group)" [initial]="group.password" (onChange)="changePassword(group, $event)"></app-text> <app-text [initial]="group.password" [editable]="userService.iOwn(group)" (onChange)="changePassword(group, $event)"></app-text>
<ng-container *ngIf="!userService.owns(group)"></ng-container> <ng-container *ngIf="!userService.iOwn(group)"></ng-container>
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@ -1 +1,2 @@
<input [(ngModel)]="model" (focus)="begin()" (blur)="apply()" (keydown.enter)="apply()" (keydown.escape)="abort()"> <input *ngIf="editable" [(ngModel)]="model" (focus)="begin()" (blur)="apply()" (keydown.enter)="apply()" (keydown.escape)="abort()">
<div *ngIf="!editable">{{ _initial }}</div>

View File

@ -1,18 +1,20 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {FormsModule} from "@angular/forms"; import {FormsModule} from "@angular/forms";
import {NgIf} from "@angular/common";
@Component({ @Component({
selector: 'app-text', selector: 'app-text',
standalone: true, standalone: true,
imports: [ imports: [
FormsModule FormsModule,
NgIf
], ],
templateUrl: './text.component.html', templateUrl: './text.component.html',
styleUrl: './text.component.less' styleUrl: './text.component.less'
}) })
export class TextComponent implements OnInit { export class TextComponent implements OnInit {
private _initial: string = ""; protected _initial: string = "";
protected model: string = this._initial; protected model: string = this._initial;
@ -29,6 +31,9 @@ export class TextComponent implements OnInit {
} }
} }
@Input()
editable: boolean = false;
ngOnInit(): void { ngOnInit(): void {
this.model = this._initial; this.model = this._initial;
} }