added new metadata to form
This commit is contained in:
parent
dbb4c1ed38
commit
a8548ce2f4
5 changed files with 33 additions and 17 deletions
|
|
@ -5,6 +5,10 @@
|
||||||
</mat-card-header>
|
</mat-card-header>
|
||||||
|
|
||||||
<mat-card-content>
|
<mat-card-content>
|
||||||
|
<div class="new-category">
|
||||||
|
<app-metadata-form (newMetaData)="createCategory($event.name)" [editing]="true" [label]="'New Category'"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="category-list">
|
<div class="category-list">
|
||||||
@for (category of categories(); track category.id) {
|
@for (category of categories(); track category.id) {
|
||||||
<app-metadata-form [metadata]="category" (newMetaData)="updateCategory($event)" />
|
<app-metadata-form [metadata]="category" (newMetaData)="updateCategory($event)" />
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.new-category {
|
||||||
|
padding-top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
.category-list {
|
.category-list {
|
||||||
padding-top: 1rem;
|
|
||||||
display: grid;
|
display: grid;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ export class CategoriesComponent {
|
||||||
|
|
||||||
public constructor(private readonly categoryService: CategoryService) { }
|
public constructor(private readonly categoryService: CategoryService) { }
|
||||||
|
|
||||||
|
public async createCategory(name: string): Promise<void> {
|
||||||
|
console.log('Creating new category', name);
|
||||||
|
}
|
||||||
|
|
||||||
public async updateCategory(category: Category): Promise<void> {
|
public async updateCategory(category: Category): Promise<void> {
|
||||||
await this.categoryService.updateCategory(category);
|
await this.categoryService.updateCategory(category);
|
||||||
await this.categoryService.fetchCategories();
|
await this.categoryService.fetchCategories();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="metadata-form-container">
|
<div class="metadata-form-container">
|
||||||
@if (!editing()) {
|
@if (!editing()) {
|
||||||
<div>{{ metadata().name }}</div>
|
<div>{{ metadata()?.name }}</div>
|
||||||
|
|
||||||
<button matIconButton (click)="editing.set(true)">
|
<button matIconButton (click)="editing.set(true)">
|
||||||
<mat-icon>edit</mat-icon>
|
<mat-icon>edit</mat-icon>
|
||||||
|
|
@ -8,13 +8,18 @@
|
||||||
} @else {
|
} @else {
|
||||||
<div class="metadata-edit">
|
<div class="metadata-edit">
|
||||||
<mat-form-field appearance="outline">
|
<mat-form-field appearance="outline">
|
||||||
|
@if (label()) {
|
||||||
|
<mat-label>{{ label() }}</mat-label>
|
||||||
|
}
|
||||||
<input type="text" matInput [(ngModel)]="name">
|
<input type="text" matInput [(ngModel)]="name">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<div class="metadata-edit-buttons">
|
<div class="metadata-edit-buttons">
|
||||||
<button matIconButton (click)="reset()">
|
@if (metadata()) {
|
||||||
<mat-icon>undo</mat-icon>
|
<button matIconButton (click)="reset()">
|
||||||
</button>
|
<mat-icon>undo</mat-icon>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
|
||||||
<button matIconButton (click)="saveMetaData()" [disabled]="!nameValid()">
|
<button matIconButton (click)="saveMetaData()" [disabled]="!nameValid()">
|
||||||
<mat-icon>save</mat-icon>
|
<mat-icon>save</mat-icon>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { Component, computed, input, model, OnInit, output, signal } from '@angular/core';
|
import { Component, computed, input, model, OnInit, output } from '@angular/core';
|
||||||
import { MatIconModule } from '@angular/material/icon';
|
import { MatIconModule } from '@angular/material/icon';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatFormField, MatInput } from '@angular/material/input';
|
import { MatInputModule } from '@angular/material/input';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
interface MetaData {
|
interface MetaData {
|
||||||
|
|
@ -14,40 +14,40 @@ interface MetaData {
|
||||||
imports: [
|
imports: [
|
||||||
MatIconModule,
|
MatIconModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
MatFormField,
|
MatInputModule,
|
||||||
MatInput,
|
FormsModule,
|
||||||
FormsModule
|
|
||||||
],
|
],
|
||||||
templateUrl: './metadata-form.component.html',
|
templateUrl: './metadata-form.component.html',
|
||||||
styleUrl: './metadata-form.component.scss'
|
styleUrl: './metadata-form.component.scss'
|
||||||
})
|
})
|
||||||
export class MetadataFormComponent implements OnInit {
|
export class MetadataFormComponent implements OnInit {
|
||||||
public metadata = input.required<MetaData>();
|
public editing = model(false);
|
||||||
|
public label = input<string>();
|
||||||
|
public metadata = input<MetaData>();
|
||||||
public newMetaData = output<MetaData>();
|
public newMetaData = output<MetaData>();
|
||||||
|
|
||||||
public name = model('');
|
public name = model('');
|
||||||
public nameValid = computed(() => {
|
public nameValid = computed(() => {
|
||||||
const existingName = this.metadata().name;
|
const existingName = this.metadata()?.name;
|
||||||
const newName = this.name();
|
const newName = this.name();
|
||||||
|
|
||||||
return !!newName && newName !== existingName;
|
return !!newName && newName !== existingName;
|
||||||
});
|
});
|
||||||
public editing = signal(false);
|
|
||||||
|
|
||||||
public ngOnInit(): void {
|
public ngOnInit(): void {
|
||||||
this.reset();
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public saveMetaData(): void {
|
public saveMetaData(): void {
|
||||||
this.editing.set(false);
|
|
||||||
this.newMetaData.emit({
|
this.newMetaData.emit({
|
||||||
...this.metadata(),
|
...this.metadata()!,
|
||||||
name: this.name()
|
name: this.name()
|
||||||
});
|
});
|
||||||
|
this.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public reset(): void {
|
public reset(): void {
|
||||||
this.editing.set(false);
|
this.name.set(this.metadata()?.name ?? '');
|
||||||
this.name.set(this.metadata().name);
|
this.editing.set(!this.metadata());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue