Implement updating of feeds
This commit is contained in:
parent
28749401e3
commit
5b69354737
@ -6,13 +6,13 @@
|
||||
<div class=" input-row">
|
||||
<mat-form-field appearance="standard" class="input">
|
||||
<mat-label>Vollständige URL des RSS-Feeds</mat-label>
|
||||
<input matInput formControlName="url" placeholder="https://rss.orf.at/news.xml">
|
||||
<input matInput formControlName="url" placeholder="https://rss.orf.at/news.xml" required>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="input-row text-left">
|
||||
<mat-form-field appearance="standard" class="input">
|
||||
<mat-label>Gesuchte Stichwörter</mat-label>
|
||||
<input matInput formControlName="keywords" placeholder="Spiel,Spaß,Schokolade">
|
||||
<input matInput formControlName="keywords" placeholder="Spiel,Spaß,Schokolade" required>
|
||||
</mat-form-field>
|
||||
<mat-checkbox formControlName="match_all_keywords">Alle Stichworte müssen enthalten sein</mat-checkbox>
|
||||
</div>
|
||||
@ -29,11 +29,11 @@
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div class="input-row text-left">
|
||||
<mat-slide-toggle color="primary" formControlName="active">Slide me!</mat-slide-toggle>
|
||||
<mat-slide-toggle color="primary" formControlName="active">Feed als aktiv markieren</mat-slide-toggle>
|
||||
</div>
|
||||
<div class="input-row margin-auto einstellungen_buttons_wrapper">
|
||||
<button routerLink="/einstellungen" mat-raised-button>Abbrechen</button>
|
||||
<button mat-raised-button (click)="saveFeed(feedForm.value)">
|
||||
<button mat-raised-button (click)="saveFeed(feedForm.value)" [disabled]="feedForm.invalid">
|
||||
<mat-icon>save</mat-icon>
|
||||
Speichern
|
||||
</button>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user