From 065922b279e7968228e322c7c62e7cab5b67ff06 Mon Sep 17 00:00:00 2001 From: Marco Zeisler Date: Tue, 4 May 2021 19:36:25 +0200 Subject: [PATCH] delete environment.prod.ts; use environment.ts for location + port; --- .../editieren/editieren.component.ts | 14 +++--- .../einstellungen/einstellungen.component.ts | 5 ++- .../app/component/tweets/tweets.component.ts | 45 ++++++++++--------- frontend/src/app/services/feed.service.ts | 3 +- frontend/src/environments/environment.prod.ts | 10 ----- frontend/src/environments/environment.ts | 21 ++------- 6 files changed, 38 insertions(+), 60 deletions(-) delete mode 100644 frontend/src/environments/environment.prod.ts diff --git a/frontend/src/app/component/einstellungen/editieren/editieren.component.ts b/frontend/src/app/component/einstellungen/editieren/editieren.component.ts index a62950e..c9ae507 100644 --- a/frontend/src/app/component/einstellungen/editieren/editieren.component.ts +++ b/frontend/src/app/component/einstellungen/editieren/editieren.component.ts @@ -1,7 +1,7 @@ import {Component, OnInit} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; -import {FormGroup, FormBuilder, AbstractControl} from '@angular/forms'; -import {FileInput, FileValidator} from 'ngx-material-file-input'; +import {FormGroup, FormBuilder} from '@angular/forms'; +import {FileValidator} from 'ngx-material-file-input'; import {HttpClient} from '@angular/common/http'; import {environment} from '../../../../environments/environment'; import {throwError} from 'rxjs'; @@ -28,8 +28,6 @@ export class EditierenComponent implements OnInit { keywords: String; readonly maxSize = 10240; - private currentLocation = environment.location; - constructor(private route: ActivatedRoute, private formBuilder: FormBuilder, private http: HttpClient, @@ -55,7 +53,7 @@ export class EditierenComponent implements OnInit { } public loadFeed(id) { - this.http.get('http://127.0.0.1:8000/feeds/' + id + '/').subscribe( + this.http.get('http://' + environment.location + ':' + environment.port + '/feeds/' + id + '/').subscribe( (data: any) => { this.url = data.url; this.active = data.active; @@ -88,7 +86,7 @@ export class EditierenComponent implements OnInit { form.append('icon', feedData.icon._files['0']); } if (this.id == null) { - this.http.post('http://127.0.0.1:8000/feeds/', form).subscribe( + this.http.post('http://' + environment.location + ':' + environment.port + '/feeds/', form).subscribe( () => { this._snackbar.open('Feed erfolgreich gespeichert!', 'Schließen', {duration: 3000}); }, @@ -99,7 +97,7 @@ export class EditierenComponent implements OnInit { } ); } else { - this.http.put('http://127.0.0.1:8000/feeds/' + this.id + '/', form).subscribe( + this.http.put('http://' + environment.location + ':' + environment.port + '/feeds/' + this.id + '/', form).subscribe( () => { this._snackbar.open('Feed erfolgreich gespeichert!', 'Schließen', {duration: 3000}); }, @@ -114,7 +112,7 @@ export class EditierenComponent implements OnInit { public errorDialog() { - const dialogRef = this._dialog.open(DialogComponent, { + this._dialog.open(DialogComponent, { data: { title: 'Serverfehler', body: 'Fehler beim Aufruf des Servers', diff --git a/frontend/src/app/component/einstellungen/einstellungen.component.ts b/frontend/src/app/component/einstellungen/einstellungen.component.ts index d71ac6f..cb6243f 100644 --- a/frontend/src/app/component/einstellungen/einstellungen.component.ts +++ b/frontend/src/app/component/einstellungen/einstellungen.component.ts @@ -8,6 +8,7 @@ import {FeedService} from '../../services/feed.service'; import {ActivatedRoute} from '@angular/router'; import {DialogComponent} from '../dialog/dialog.component'; import {MatDialog} from '@angular/material/dialog'; +import {environment} from '../../../environments/environment'; @Component({ selector: 'app-einstellungen', @@ -34,7 +35,7 @@ export class EinstellungenComponent implements OnInit { } deleteFeed(id: number) { - this.http.delete('http://127.0.0.1:8000/feeds/' + id + '/').subscribe( + this.http.delete('http://' + environment.location + ':' + environment.port + '/feeds/' + id + '/').subscribe( () => { this._snackbar.open('Feed erfolgreich gelöscht!', 'Schließen', {duration: 3000}); this.feeds = this.feeds.filter(feed => feed.id !== id); @@ -69,7 +70,7 @@ export class EinstellungenComponent implements OnInit { public errorDialog() { - const dialogRef = this._dialog.open(DialogComponent, { + this._dialog.open(DialogComponent, { data: { title: 'Serverfehler', body: 'Fehler beim Aufruf des Servers', diff --git a/frontend/src/app/component/tweets/tweets.component.ts b/frontend/src/app/component/tweets/tweets.component.ts index 712712a..8bdb03e 100644 --- a/frontend/src/app/component/tweets/tweets.component.ts +++ b/frontend/src/app/component/tweets/tweets.component.ts @@ -1,11 +1,12 @@ import {Component, OnInit} from '@angular/core'; import {AuthService} from '../../services/auth.service'; -import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {HttpClient} from '@angular/common/http'; import {FeedService} from '../../services/feed.service'; import {IFeed} from '../../interfaces/feed.interface'; import {Observable} from 'rxjs'; -import {Tweet} from "../../interfaces/interface"; -import {SnackbarService} from "../../services/snackbar.service"; +import {Tweet} from '../../interfaces/interface'; +import {SnackbarService} from '../../services/snackbar.service'; +import {environment} from '../../../environments/environment'; @Component({ @@ -34,8 +35,8 @@ export class TweetsComponent implements OnInit { ngOnInit(): void { - this.fillTweets() - console.log(this.tweets) + this.fillTweets(); + console.log(this.tweets); } @@ -43,17 +44,19 @@ export class TweetsComponent implements OnInit { console.log(this.tweets); - this.http.get('http://127.0.0.1:8000/getMoreTweets/'+this.tweets[this.tweets.length-1].tweet_id+'/').subscribe(data => { - console.log(data) + this.http.get( + 'http://' + environment.location + ':' + environment.port + '/getMoreTweets/' + this.tweets[this.tweets.length - 1].tweet_id + '/' + ).subscribe(data => { + console.log(data); - if(data.length == 0){ - this._snackbarService.show("Keine weiteren Tweets vorhanden","Schließen"); + if (data.length === 0) { + this._snackbarService.show('Keine weiteren Tweets vorhanden', 'Schließen'); } - for(let tweet of data){ - let position = tweet.text.search(": http"); - tweet.text = tweet.text.substring(0,position); + for (const tweet of data) { + const position = tweet.text.search(': http'); + tweet.text = tweet.text.substring(0, position); this.tweets.push(tweet); } } @@ -61,18 +64,18 @@ export class TweetsComponent implements OnInit { } - fillTweets(){ + fillTweets() { - this.http.get('http://127.0.0.1:8000/getSixTweets/').subscribe(data => { - console.log(data) - for(let tweet of data){ - let position = tweet.text.search(": http"); - tweet.text = tweet.text.substring(0,position); - this.tweets.push(tweet); - } + this.http.get('http://' + environment.location + ':' + environment.port + '/getSixTweets/').subscribe(data => { + console.log(data); + for (const tweet of data) { + const position = tweet.text.search(': http'); + tweet.text = tweet.text.substring(0, position); + this.tweets.push(tweet); + } } ); - } + } } diff --git a/frontend/src/app/services/feed.service.ts b/frontend/src/app/services/feed.service.ts index 68a4124..c15a198 100644 --- a/frontend/src/app/services/feed.service.ts +++ b/frontend/src/app/services/feed.service.ts @@ -3,12 +3,13 @@ import {HttpClient} from '@angular/common/http'; import {Observable} from 'rxjs'; import {IFeed} from '../interfaces/feed.interface'; import {delay} from 'rxjs/operators'; +import {environment} from '../../environments/environment'; @Injectable({ providedIn: 'root' }) export class FeedService { - private url = 'http://localhost:8000/feeds/'; + private url = 'http://' + environment.location + ':' + environment.port + '/feeds/'; constructor(private http: HttpClient) {} diff --git a/frontend/src/environments/environment.prod.ts b/frontend/src/environments/environment.prod.ts deleted file mode 100644 index 74fe16e..0000000 --- a/frontend/src/environments/environment.prod.ts +++ /dev/null @@ -1,10 +0,0 @@ -import {NgxLoggerLevel} from 'ngx-logger'; - -export const environment = { - title: 'Bsp 4 Gruppe 4', - production: true, - location: window.location.hostname, - port: 8000, - ws_url_root: 'ws://' + window.location.hostname + ':' + window.location.port + '/', - log_level: NgxLoggerLevel.WARN, -}; diff --git a/frontend/src/environments/environment.ts b/frontend/src/environments/environment.ts index af1a0f9..084d7c1 100644 --- a/frontend/src/environments/environment.ts +++ b/frontend/src/environments/environment.ts @@ -1,25 +1,10 @@ -// This file can be replaced during build by using the `fileReplacements` array. -// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. -// The list of file replacements can be found in `angular.json`. - import {NgxLoggerLevel} from 'ngx-logger'; export const environment = { title: 'Bsp 4 Gruppe 4', - openid_endpoint: 'https://waecm-sso.inso.tuwien.ac.at/auth/realms/waecm/protocol/openid-connect', - production: false, - location: 'http://localhost:4200', + production: true, + location: window.location.hostname, port: 8000, - ws_location: 'ws://127.0.0.1', - ws_port: 8000, - log_level: NgxLoggerLevel.DEBUG, + log_level: NgxLoggerLevel.WARN, }; -/* - * For easier debugging in development mode, you can import the following file - * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. - * - * This import should be commented out in production mode because it will have a negative impact - * on performance if an error is thrown. - */ -// import 'zone.js/dist/zone-error'; // Included with Angular CLI.