From 5b6935473761e9583e25771b61de58ba2a296083 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Mon, 3 May 2021 12:07:06 +0200 Subject: [PATCH] Implement updating of feeds --- .../editieren/editieren.component.html | 8 +-- .../editieren/editieren.component.ts | 53 ++++++++++++++----- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/component/einstellungen/editieren/editieren.component.html b/frontend/src/app/component/einstellungen/editieren/editieren.component.html index 5568431..031abca 100644 --- a/frontend/src/app/component/einstellungen/editieren/editieren.component.html +++ b/frontend/src/app/component/einstellungen/editieren/editieren.component.html @@ -6,13 +6,13 @@
Vollständige URL des RSS-Feeds - +
Gesuchte Stichwörter - + Alle Stichworte müssen enthalten sein
@@ -29,11 +29,11 @@
- Slide me! + Feed als aktiv markieren
- diff --git a/frontend/src/app/component/einstellungen/editieren/editieren.component.ts b/frontend/src/app/component/einstellungen/editieren/editieren.component.ts index 07bcf38..919748a 100644 --- a/frontend/src/app/component/einstellungen/editieren/editieren.component.ts +++ b/frontend/src/app/component/einstellungen/editieren/editieren.component.ts @@ -51,13 +51,26 @@ export class EditierenComponent implements OnInit { } loadFeed(id) { - // TODO: direkt vor laden alle inputs deaktivieren (od hiden) und erst nach fertigem laden wieder entsperren - // TODO: load feed from backend and fill - console.log('TODO: Load feed settings with id ' + id); + this.http.get('http://127.0.0.1:8000/feeds/' + id + '/').subscribe( + (data: any) => { + this._logger.debug('Data: ' + JSON.stringify(data)); + this.url = data.url; + this.active = data.active; + this.keywords = data.keywords; + this.match_all_keywords = data.match_all_keywords; + this.feedForm.patchValue({ + url: data.url, + active: data.active, + keywords: data.keywords, + match_all_keywords: data.match_all_keywords + }); + this._logger.debug('Icon in loadFeed' + this.icon); + }, + err => this._logger.error(err), + () => this._logger.debug('Loaded feed with ID ' + id) + ); } - // TODO: bei Input-Words die Leerzeichen vor- und nach dem letzten Zeichen entfernen: " Formel 1 " wird zu "Formel 1" - saveFeed(feedData) { const form: FormData = new FormData(); form.append('url', feedData.url); @@ -70,14 +83,26 @@ export class EditierenComponent implements OnInit { if (feedData.icon != null) { form.append('icon', feedData.icon._files['0']); } - this.http.post('http://127.0.0.1:8000/feeds/', form).subscribe( - () => { - this._snackbar.open('Feed erfolgreich gespeichert!', 'Schließen', {duration: 3000}); - }, - err => { - this._logger.error(err); - return throwError(err); - } - ); + if (this.id == null) { + this.http.post('http://127.0.0.1:8000/feeds/', form).subscribe( + () => { + this._snackbar.open('Feed erfolgreich gespeichert!', 'Schließen', {duration: 3000}); + }, + err => { + this._logger.error(err); + return throwError(err); + } + ); + } else { + this.http.put('http://127.0.0.1:8000/feeds/' + this.id + '/', form).subscribe( + () => { + this._snackbar.open('Feed erfolgreich gespeichert!', 'Schließen', {duration: 3000}); + }, + err => { + this._logger.error(err); + return throwError(err); + } + ); + } } }