From d25e3ea7b9509db023868d72b146ea492f884043 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Mon, 3 May 2021 12:07:32 +0200 Subject: [PATCH] Load feeds from backend --- .../einstellungen.component.html | 10 ++--- .../einstellungen/einstellungen.component.ts | 37 ++++++++++++++++++- frontend/src/app/interfaces/feed.interface.ts | 8 ++++ frontend/src/app/services/feed.service.ts | 19 ++++++++++ 4 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 frontend/src/app/interfaces/feed.interface.ts create mode 100644 frontend/src/app/services/feed.service.ts diff --git a/frontend/src/app/component/einstellungen/einstellungen.component.html b/frontend/src/app/component/einstellungen/einstellungen.component.html index 7eabee9..c1038ba 100644 --- a/frontend/src/app/component/einstellungen/einstellungen.component.html +++ b/frontend/src/app/component/einstellungen/einstellungen.component.html @@ -1,21 +1,21 @@
-
+
- Feed-Icon + Feed-Icon
- https://rss.orf.at/news.xml + {{feed.url}}
-
-
diff --git a/frontend/src/app/component/einstellungen/einstellungen.component.ts b/frontend/src/app/component/einstellungen/einstellungen.component.ts index 7fd5297..272c725 100644 --- a/frontend/src/app/component/einstellungen/einstellungen.component.ts +++ b/frontend/src/app/component/einstellungen/einstellungen.component.ts @@ -1,4 +1,11 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, OnInit} from '@angular/core'; +import {HttpClient} from '@angular/common/http'; +import {Observable, throwError} from 'rxjs'; +import {MatSnackBar} from '@angular/material/snack-bar'; +import {NGXLogger} from 'ngx-logger'; +import {IFeed} from '../../interfaces/feed.interface'; +import {FeedService} from '../../services/feed.service'; +import {ActivatedRoute, Router} from '@angular/router'; @Component({ selector: 'app-einstellungen', @@ -9,10 +16,36 @@ export class EinstellungenComponent implements OnInit { icon; - constructor() { + feeds: Observable; + + constructor(private http: HttpClient, + private _snackbar: MatSnackBar, + private _logger: NGXLogger, + private _feedService: FeedService, + private _route: ActivatedRoute, + private _router: Router) { this.icon = 'assets/logo.svg'; + this._feedService.getFeeds().subscribe( + (data: any) => { + this.feeds = data; + } + ); } ngOnInit(): void { } + + deleteFeed(id: number) { + console.log('Got number for deletion: ' + id); + this.http.delete('http://127.0.0.1:8000/feeds/' + id + '/').subscribe( + () => { + this._snackbar.open('Feed erfolgreich gelöscht!', 'Schließen', {duration: 3000}); + }, + err => { + this._logger.error(err); + return throwError(err); + } + ); + this._router.navigate([this._router.url]); + } } diff --git a/frontend/src/app/interfaces/feed.interface.ts b/frontend/src/app/interfaces/feed.interface.ts new file mode 100644 index 0000000..ece8a92 --- /dev/null +++ b/frontend/src/app/interfaces/feed.interface.ts @@ -0,0 +1,8 @@ +export interface IFeed { + id: number; + url: string; + active: boolean; + icon: File; + keywords: string; + match_all_keywords: string; +} diff --git a/frontend/src/app/services/feed.service.ts b/frontend/src/app/services/feed.service.ts new file mode 100644 index 0000000..ab087e0 --- /dev/null +++ b/frontend/src/app/services/feed.service.ts @@ -0,0 +1,19 @@ +import {Injectable} from '@angular/core'; +import {HttpClient} from '@angular/common/http'; +import {Observable} from 'rxjs'; +import {IFeed} from '../interfaces/feed.interface'; +import {delay} from 'rxjs/operators'; + +@Injectable({ + providedIn: 'root' +}) +export class FeedService { + private url = 'http://localhost:8000/feeds/'; + + constructor(private http: HttpClient) {} + + getFeeds(): Observable { + console.log('FeedService called'); + return this.http.get(this.url).pipe(delay(200)); + } +}