diff --git a/src/app/admin/models/option-changed.ts b/src/app/admin/models/option-changed.ts new file mode 100644 index 0000000..396de90 --- /dev/null +++ b/src/app/admin/models/option-changed.ts @@ -0,0 +1,6 @@ +export interface OptionChanged +{ + slug: string; + oldValue: string; + newValue: string; +} diff --git a/src/app/admin/option/option.component.html b/src/app/admin/option/option.component.html index f0ce924..feb3adf 100644 --- a/src/app/admin/option/option.component.html +++ b/src/app/admin/option/option.component.html @@ -1,7 +1,7 @@
{{option.name}} - + {{option.description}}
diff --git a/src/app/admin/option/option.component.ts b/src/app/admin/option/option.component.ts index acf48dd..c543d09 100644 --- a/src/app/admin/option/option.component.ts +++ b/src/app/admin/option/option.component.ts @@ -1,22 +1,20 @@ -import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from "@angular/core"; +import { Component, ElementRef, Input, OnInit, Output, ViewChild, EventEmitter } from "@angular/core"; import { Option } from "../models/option"; -import { HttpClient } from "@angular/common/http"; +import { OptionChanged } from "../models/option-changed"; @Component({ selector: "app-option", templateUrl: "./option.component.html", styleUrls: ["./option.component.scss"] }) -export class OptionComponent implements OnInit, OnDestroy +export class OptionComponent implements OnInit { value: string; @Input() option: Option; @Input() config; + @Output() changed = new EventEmitter(); @ViewChild("input") input: ElementRef; - constructor(private http: HttpClient) - {} - ngOnInit(): void { this.value = this.getConfig(this.option.slug); @@ -24,8 +22,8 @@ export class OptionComponent implements OnInit, OnDestroy getConfig(slug: string): string { - const sections = slug.split(':'); - let conf = this.config; + const sections: string[] = slug.split(":"); + let conf: any = this.config; for (const child of sections) { @@ -35,10 +33,13 @@ export class OptionComponent implements OnInit, OnDestroy } return conf; } - async ngOnDestroy() + + onValueChanged(): void { - if (this.value == this.input.nativeElement.value) - return; - await this.http.put(`/api/config/${this.option.slug}`, this.input.nativeElement.value); + this.changed.emit({ + slug: this.option.slug, + oldValue: this.value, + newValue: this.input.nativeElement.value + }); } } diff --git a/src/app/admin/panel/panel.component.html b/src/app/admin/panel/panel.component.html index e27cd03..a821f47 100644 --- a/src/app/admin/panel/panel.component.html +++ b/src/app/admin/panel/panel.component.html @@ -8,10 +8,11 @@ - {{getChanges()}} changes + {{changed.size}} changes
- + +
diff --git a/src/app/admin/panel/panel.component.ts b/src/app/admin/panel/panel.component.ts index 8f232c9..01ef0e9 100644 --- a/src/app/admin/panel/panel.component.ts +++ b/src/app/admin/panel/panel.component.ts @@ -1,6 +1,8 @@ import { Component } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; import { ConfigurationSection } from "../models/configuration-section"; +import { OptionChanged } from "../models/option-changed"; +import { HttpClient } from "@angular/common/http"; @Component({ selector: "app-panel", @@ -11,8 +13,10 @@ export class PanelComponent { items: ConfigurationSection[]; config: any; + changed = new Map(); - constructor(private route: ActivatedRoute) + constructor(private route: ActivatedRoute, + private http: HttpClient) { this.route.data.subscribe(x => { @@ -21,8 +25,17 @@ export class PanelComponent }); } - getChanges(): number + onOptionChanged(event: OptionChanged): void { - return 0; + if (event.newValue === event.oldValue) + this.changed.delete(event.slug); + else + this.changed.set(event.slug, event.newValue); + } + + onSave(): void + { + this.http.put("/api/config", this.changed) + .subscribe(); } } diff --git a/src/app/admin/section/section.component.html b/src/app/admin/section/section.component.html index 007a125..35c6418 100644 --- a/src/app/admin/section/section.component.html +++ b/src/app/admin/section/section.component.html @@ -1,4 +1,6 @@

{{section.name}}

- + +
diff --git a/src/app/admin/section/section.component.ts b/src/app/admin/section/section.component.ts index adab3a5..ce31ac7 100644 --- a/src/app/admin/section/section.component.ts +++ b/src/app/admin/section/section.component.ts @@ -1,5 +1,6 @@ -import { Component, Input } from "@angular/core"; +import { Component, Input, Output, EventEmitter } from "@angular/core"; import { ConfigurationSection } from "../models/configuration-section"; +import { OptionChanged } from "../models/option-changed"; @Component({ selector: "app-section", @@ -10,4 +11,5 @@ export class SectionComponent { @Input() section: ConfigurationSection; @Input() config: any; + @Output() changed = new EventEmitter(); }