diff --git a/src/app/account.service.ts b/src/app/account.service.ts index 7f602df..aa39dec 100644 --- a/src/app/account.service.ts +++ b/src/app/account.service.ts @@ -81,7 +81,7 @@ updateUserInfo(then: Function = () => {}) { var token = localStorage.getItem('userToken') if (token == null) { - this.setUser('') + this.logout() return } var data = JSON.parse(atob(token?.split('.')[1] as string)) @@ -92,13 +92,11 @@ var checkTokenAnswer = Object.assign(new CheckTokenAnswer(), answer) if (checkTokenAnswer.valid) { } else { - this.router.navigate(['/']) - this.setUser('') + this.logout() } then() }, () => { - this.router.navigate(['/']) - this.setUser('') + this.logout() }) } @@ -116,6 +114,7 @@ if (status.success) { Swal.fire('Password changed!', 'Watch out, \nyour old password won\'t work anymore', 'success') } else { + this.logout() Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') } then() @@ -133,4 +132,17 @@ f(this.username) }); } + + postStatus(status: string, time: number) { + this.http.post(`${environment.apiURL}/users/postStatus`, + {username: this.username, status, lifetime: time, + token: localStorage.getItem('userToken')}).subscribe((answer) => { + var status = Object.assign(new Answer(), answer) + if (status.success) { + Swal.fire('You posted a status', 'Everyone can see it', 'success') + } else { + Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') + } + }) + } } diff --git a/src/app/account.service.ts b/src/app/account.service.ts index 7f602df..aa39dec 100644 --- a/src/app/account.service.ts +++ b/src/app/account.service.ts @@ -81,7 +81,7 @@ updateUserInfo(then: Function = () => {}) { var token = localStorage.getItem('userToken') if (token == null) { - this.setUser('') + this.logout() return } var data = JSON.parse(atob(token?.split('.')[1] as string)) @@ -92,13 +92,11 @@ var checkTokenAnswer = Object.assign(new CheckTokenAnswer(), answer) if (checkTokenAnswer.valid) { } else { - this.router.navigate(['/']) - this.setUser('') + this.logout() } then() }, () => { - this.router.navigate(['/']) - this.setUser('') + this.logout() }) } @@ -116,6 +114,7 @@ if (status.success) { Swal.fire('Password changed!', 'Watch out, \nyour old password won\'t work anymore', 'success') } else { + this.logout() Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') } then() @@ -133,4 +132,17 @@ f(this.username) }); } + + postStatus(status: string, time: number) { + this.http.post(`${environment.apiURL}/users/postStatus`, + {username: this.username, status, lifetime: time, + token: localStorage.getItem('userToken')}).subscribe((answer) => { + var status = Object.assign(new Answer(), answer) + if (status.success) { + Swal.fire('You posted a status', 'Everyone can see it', 'success') + } else { + Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') + } + }) + } } diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 726150d..9052a81 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -22,4 +22,23 @@ + +

Post status

+
+ + status + this field must not be empty + + + + Time + + + {{time.viewValue}} + + + + +
+
\ No newline at end of file diff --git a/src/app/account.service.ts b/src/app/account.service.ts index 7f602df..aa39dec 100644 --- a/src/app/account.service.ts +++ b/src/app/account.service.ts @@ -81,7 +81,7 @@ updateUserInfo(then: Function = () => {}) { var token = localStorage.getItem('userToken') if (token == null) { - this.setUser('') + this.logout() return } var data = JSON.parse(atob(token?.split('.')[1] as string)) @@ -92,13 +92,11 @@ var checkTokenAnswer = Object.assign(new CheckTokenAnswer(), answer) if (checkTokenAnswer.valid) { } else { - this.router.navigate(['/']) - this.setUser('') + this.logout() } then() }, () => { - this.router.navigate(['/']) - this.setUser('') + this.logout() }) } @@ -116,6 +114,7 @@ if (status.success) { Swal.fire('Password changed!', 'Watch out, \nyour old password won\'t work anymore', 'success') } else { + this.logout() Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') } then() @@ -133,4 +132,17 @@ f(this.username) }); } + + postStatus(status: string, time: number) { + this.http.post(`${environment.apiURL}/users/postStatus`, + {username: this.username, status, lifetime: time, + token: localStorage.getItem('userToken')}).subscribe((answer) => { + var status = Object.assign(new Answer(), answer) + if (status.success) { + Swal.fire('You posted a status', 'Everyone can see it', 'success') + } else { + Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') + } + }) + } } diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 726150d..9052a81 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -22,4 +22,23 @@ + +

Post status

+
+ + status + this field must not be empty + + + + Time + + + {{time.viewValue}} + + + + +
+
\ No newline at end of file diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index 189d680..c96f14b 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -3,22 +3,38 @@ import { Router } from '@angular/router'; import { AccountService } from '../account.service'; +interface TimeEntry { + value: number + viewValue: string +} + @Component({ selector: 'app-admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.scss'] }) export class AdminComponent implements OnInit { - public passwordForm: FormGroup + passwordForm: FormGroup + statusForm: FormGroup public passwordError = false public username = '' - + timeOptions: TimeEntry[] = [ + {value: 60, viewValue: '1 Minute'}, + {value: 600, viewValue: '10 Minutes'}, + {value: 3600, viewValue: '1 Hour'}, + {value: 36000, viewValue: '10 Hours'}, + {value: 24 * 3600, viewValue: '1 Day'}, + ] + defaultTime = '10 Minutes' constructor(public account: AccountService, router: Router, private formBuilder: FormBuilder) { - this.passwordForm = this.formBuilder.group({ password: ['', Validators.required], password_repeat: ['', Validators.required] }) + this.statusForm = this.formBuilder.group({ + status: ['', Validators.required], + time: [null], + }) account.subscribe((username: string) => { if (account.username.length == 0) { router.navigate(['login']) @@ -28,6 +44,7 @@ } ngOnInit(): void { + var form = this.statusForm.get('time')?.setValue(60) } onPasswordSubmit() { @@ -43,4 +60,11 @@ this.passwordForm.reset() }, () => {}) } + + onStatusSubmit() { + if (this.statusForm.invalid) { + return + } + this.account.postStatus(this.statusForm.controls['status'].value, this.statusForm.controls['time'].value) + } } diff --git a/src/app/account.service.ts b/src/app/account.service.ts index 7f602df..aa39dec 100644 --- a/src/app/account.service.ts +++ b/src/app/account.service.ts @@ -81,7 +81,7 @@ updateUserInfo(then: Function = () => {}) { var token = localStorage.getItem('userToken') if (token == null) { - this.setUser('') + this.logout() return } var data = JSON.parse(atob(token?.split('.')[1] as string)) @@ -92,13 +92,11 @@ var checkTokenAnswer = Object.assign(new CheckTokenAnswer(), answer) if (checkTokenAnswer.valid) { } else { - this.router.navigate(['/']) - this.setUser('') + this.logout() } then() }, () => { - this.router.navigate(['/']) - this.setUser('') + this.logout() }) } @@ -116,6 +114,7 @@ if (status.success) { Swal.fire('Password changed!', 'Watch out, \nyour old password won\'t work anymore', 'success') } else { + this.logout() Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') } then() @@ -133,4 +132,17 @@ f(this.username) }); } + + postStatus(status: string, time: number) { + this.http.post(`${environment.apiURL}/users/postStatus`, + {username: this.username, status, lifetime: time, + token: localStorage.getItem('userToken')}).subscribe((answer) => { + var status = Object.assign(new Answer(), answer) + if (status.success) { + Swal.fire('You posted a status', 'Everyone can see it', 'success') + } else { + Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') + } + }) + } } diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 726150d..9052a81 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -22,4 +22,23 @@ + +

Post status

+
+ + status + this field must not be empty + + + + Time + + + {{time.viewValue}} + + + + +
+
\ No newline at end of file diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index 189d680..c96f14b 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -3,22 +3,38 @@ import { Router } from '@angular/router'; import { AccountService } from '../account.service'; +interface TimeEntry { + value: number + viewValue: string +} + @Component({ selector: 'app-admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.scss'] }) export class AdminComponent implements OnInit { - public passwordForm: FormGroup + passwordForm: FormGroup + statusForm: FormGroup public passwordError = false public username = '' - + timeOptions: TimeEntry[] = [ + {value: 60, viewValue: '1 Minute'}, + {value: 600, viewValue: '10 Minutes'}, + {value: 3600, viewValue: '1 Hour'}, + {value: 36000, viewValue: '10 Hours'}, + {value: 24 * 3600, viewValue: '1 Day'}, + ] + defaultTime = '10 Minutes' constructor(public account: AccountService, router: Router, private formBuilder: FormBuilder) { - this.passwordForm = this.formBuilder.group({ password: ['', Validators.required], password_repeat: ['', Validators.required] }) + this.statusForm = this.formBuilder.group({ + status: ['', Validators.required], + time: [null], + }) account.subscribe((username: string) => { if (account.username.length == 0) { router.navigate(['login']) @@ -28,6 +44,7 @@ } ngOnInit(): void { + var form = this.statusForm.get('time')?.setValue(60) } onPasswordSubmit() { @@ -43,4 +60,11 @@ this.passwordForm.reset() }, () => {}) } + + onStatusSubmit() { + if (this.statusForm.invalid) { + return + } + this.account.postStatus(this.statusForm.controls['status'].value, this.statusForm.controls['time'].value) + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1fb908c..2aab2ac 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -13,6 +13,7 @@ import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { MatSelectModule } from '@angular/material/select'; import { MatOptionModule } from '@angular/material/core'; +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -58,6 +59,7 @@ MatSlideToggleModule, MatSelectModule, MatOptionModule, + MatProgressSpinnerModule, ], providers: [AccountService], bootstrap: [AppComponent] diff --git a/src/app/account.service.ts b/src/app/account.service.ts index 7f602df..aa39dec 100644 --- a/src/app/account.service.ts +++ b/src/app/account.service.ts @@ -81,7 +81,7 @@ updateUserInfo(then: Function = () => {}) { var token = localStorage.getItem('userToken') if (token == null) { - this.setUser('') + this.logout() return } var data = JSON.parse(atob(token?.split('.')[1] as string)) @@ -92,13 +92,11 @@ var checkTokenAnswer = Object.assign(new CheckTokenAnswer(), answer) if (checkTokenAnswer.valid) { } else { - this.router.navigate(['/']) - this.setUser('') + this.logout() } then() }, () => { - this.router.navigate(['/']) - this.setUser('') + this.logout() }) } @@ -116,6 +114,7 @@ if (status.success) { Swal.fire('Password changed!', 'Watch out, \nyour old password won\'t work anymore', 'success') } else { + this.logout() Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') } then() @@ -133,4 +132,17 @@ f(this.username) }); } + + postStatus(status: string, time: number) { + this.http.post(`${environment.apiURL}/users/postStatus`, + {username: this.username, status, lifetime: time, + token: localStorage.getItem('userToken')}).subscribe((answer) => { + var status = Object.assign(new Answer(), answer) + if (status.success) { + Swal.fire('You posted a status', 'Everyone can see it', 'success') + } else { + Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') + } + }) + } } diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 726150d..9052a81 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -22,4 +22,23 @@ + +

Post status

+
+ + status + this field must not be empty + + + + Time + + + {{time.viewValue}} + + + + +
+
\ No newline at end of file diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index 189d680..c96f14b 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -3,22 +3,38 @@ import { Router } from '@angular/router'; import { AccountService } from '../account.service'; +interface TimeEntry { + value: number + viewValue: string +} + @Component({ selector: 'app-admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.scss'] }) export class AdminComponent implements OnInit { - public passwordForm: FormGroup + passwordForm: FormGroup + statusForm: FormGroup public passwordError = false public username = '' - + timeOptions: TimeEntry[] = [ + {value: 60, viewValue: '1 Minute'}, + {value: 600, viewValue: '10 Minutes'}, + {value: 3600, viewValue: '1 Hour'}, + {value: 36000, viewValue: '10 Hours'}, + {value: 24 * 3600, viewValue: '1 Day'}, + ] + defaultTime = '10 Minutes' constructor(public account: AccountService, router: Router, private formBuilder: FormBuilder) { - this.passwordForm = this.formBuilder.group({ password: ['', Validators.required], password_repeat: ['', Validators.required] }) + this.statusForm = this.formBuilder.group({ + status: ['', Validators.required], + time: [null], + }) account.subscribe((username: string) => { if (account.username.length == 0) { router.navigate(['login']) @@ -28,6 +44,7 @@ } ngOnInit(): void { + var form = this.statusForm.get('time')?.setValue(60) } onPasswordSubmit() { @@ -43,4 +60,11 @@ this.passwordForm.reset() }, () => {}) } + + onStatusSubmit() { + if (this.statusForm.invalid) { + return + } + this.account.postStatus(this.statusForm.controls['status'].value, this.statusForm.controls['time'].value) + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1fb908c..2aab2ac 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -13,6 +13,7 @@ import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { MatSelectModule } from '@angular/material/select'; import { MatOptionModule } from '@angular/material/core'; +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -58,6 +59,7 @@ MatSlideToggleModule, MatSelectModule, MatOptionModule, + MatProgressSpinnerModule, ], providers: [AccountService], bootstrap: [AppComponent] diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 6bbb28e..b7052eb 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -44,4 +44,16 @@ The backend is made using Ruby on rails.

+ +

User statuses:

+
+ +
+ +
+

{{userStatus.user}}

+

{{userStatus.message}}

+
+
+
\ No newline at end of file diff --git a/src/app/account.service.ts b/src/app/account.service.ts index 7f602df..aa39dec 100644 --- a/src/app/account.service.ts +++ b/src/app/account.service.ts @@ -81,7 +81,7 @@ updateUserInfo(then: Function = () => {}) { var token = localStorage.getItem('userToken') if (token == null) { - this.setUser('') + this.logout() return } var data = JSON.parse(atob(token?.split('.')[1] as string)) @@ -92,13 +92,11 @@ var checkTokenAnswer = Object.assign(new CheckTokenAnswer(), answer) if (checkTokenAnswer.valid) { } else { - this.router.navigate(['/']) - this.setUser('') + this.logout() } then() }, () => { - this.router.navigate(['/']) - this.setUser('') + this.logout() }) } @@ -116,6 +114,7 @@ if (status.success) { Swal.fire('Password changed!', 'Watch out, \nyour old password won\'t work anymore', 'success') } else { + this.logout() Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') } then() @@ -133,4 +132,17 @@ f(this.username) }); } + + postStatus(status: string, time: number) { + this.http.post(`${environment.apiURL}/users/postStatus`, + {username: this.username, status, lifetime: time, + token: localStorage.getItem('userToken')}).subscribe((answer) => { + var status = Object.assign(new Answer(), answer) + if (status.success) { + Swal.fire('You posted a status', 'Everyone can see it', 'success') + } else { + Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') + } + }) + } } diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 726150d..9052a81 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -22,4 +22,23 @@ + +

Post status

+
+ + status + this field must not be empty + + + + Time + + + {{time.viewValue}} + + + + +
+
\ No newline at end of file diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index 189d680..c96f14b 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -3,22 +3,38 @@ import { Router } from '@angular/router'; import { AccountService } from '../account.service'; +interface TimeEntry { + value: number + viewValue: string +} + @Component({ selector: 'app-admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.scss'] }) export class AdminComponent implements OnInit { - public passwordForm: FormGroup + passwordForm: FormGroup + statusForm: FormGroup public passwordError = false public username = '' - + timeOptions: TimeEntry[] = [ + {value: 60, viewValue: '1 Minute'}, + {value: 600, viewValue: '10 Minutes'}, + {value: 3600, viewValue: '1 Hour'}, + {value: 36000, viewValue: '10 Hours'}, + {value: 24 * 3600, viewValue: '1 Day'}, + ] + defaultTime = '10 Minutes' constructor(public account: AccountService, router: Router, private formBuilder: FormBuilder) { - this.passwordForm = this.formBuilder.group({ password: ['', Validators.required], password_repeat: ['', Validators.required] }) + this.statusForm = this.formBuilder.group({ + status: ['', Validators.required], + time: [null], + }) account.subscribe((username: string) => { if (account.username.length == 0) { router.navigate(['login']) @@ -28,6 +44,7 @@ } ngOnInit(): void { + var form = this.statusForm.get('time')?.setValue(60) } onPasswordSubmit() { @@ -43,4 +60,11 @@ this.passwordForm.reset() }, () => {}) } + + onStatusSubmit() { + if (this.statusForm.invalid) { + return + } + this.account.postStatus(this.statusForm.controls['status'].value, this.statusForm.controls['time'].value) + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1fb908c..2aab2ac 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -13,6 +13,7 @@ import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { MatSelectModule } from '@angular/material/select'; import { MatOptionModule } from '@angular/material/core'; +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -58,6 +59,7 @@ MatSlideToggleModule, MatSelectModule, MatOptionModule, + MatProgressSpinnerModule, ], providers: [AccountService], bootstrap: [AppComponent] diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 6bbb28e..b7052eb 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -44,4 +44,16 @@ The backend is made using Ruby on rails.

+ +

User statuses:

+
+ +
+ +
+

{{userStatus.user}}

+

{{userStatus.message}}

+
+
+
\ No newline at end of file diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 73acf06..47e5069 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,4 +1,14 @@ +import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; +import { environment } from 'src/environments/environment'; + +class UserStatus { + constructor(public user: string, public message: string) {} +} + +class UserStatusAnswer { + constructor(public success: boolean = false, public userStatuses: UserStatus[] = []) {} +} @Component({ selector: 'app-home', @@ -6,10 +16,19 @@ styleUrls: ['./home.component.scss'] }) export class HomeComponent implements OnInit { + userStatuses: UserStatus[] = [] + loading = true - constructor() { } + constructor(private http: HttpClient) { } ngOnInit(): void { + this.http.get(`${environment.apiURL}/users/status`).subscribe((answer) => { + var userStatusAnswer = Object.assign(new UserStatusAnswer(), answer) + this.loading = !userStatusAnswer.success + if (!this.loading) { + this.userStatuses = userStatusAnswer.userStatuses + } + } + ) } - } diff --git a/src/app/account.service.ts b/src/app/account.service.ts index 7f602df..aa39dec 100644 --- a/src/app/account.service.ts +++ b/src/app/account.service.ts @@ -81,7 +81,7 @@ updateUserInfo(then: Function = () => {}) { var token = localStorage.getItem('userToken') if (token == null) { - this.setUser('') + this.logout() return } var data = JSON.parse(atob(token?.split('.')[1] as string)) @@ -92,13 +92,11 @@ var checkTokenAnswer = Object.assign(new CheckTokenAnswer(), answer) if (checkTokenAnswer.valid) { } else { - this.router.navigate(['/']) - this.setUser('') + this.logout() } then() }, () => { - this.router.navigate(['/']) - this.setUser('') + this.logout() }) } @@ -116,6 +114,7 @@ if (status.success) { Swal.fire('Password changed!', 'Watch out, \nyour old password won\'t work anymore', 'success') } else { + this.logout() Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') } then() @@ -133,4 +132,17 @@ f(this.username) }); } + + postStatus(status: string, time: number) { + this.http.post(`${environment.apiURL}/users/postStatus`, + {username: this.username, status, lifetime: time, + token: localStorage.getItem('userToken')}).subscribe((answer) => { + var status = Object.assign(new Answer(), answer) + if (status.success) { + Swal.fire('You posted a status', 'Everyone can see it', 'success') + } else { + Swal.fire('Error!', 'Something went wrong, bad user token?', 'error') + } + }) + } } diff --git a/src/app/admin/admin.component.html b/src/app/admin/admin.component.html index 726150d..9052a81 100644 --- a/src/app/admin/admin.component.html +++ b/src/app/admin/admin.component.html @@ -22,4 +22,23 @@ + +

Post status

+
+ + status + this field must not be empty + + + + Time + + + {{time.viewValue}} + + + + +
+
\ No newline at end of file diff --git a/src/app/admin/admin.component.ts b/src/app/admin/admin.component.ts index 189d680..c96f14b 100644 --- a/src/app/admin/admin.component.ts +++ b/src/app/admin/admin.component.ts @@ -3,22 +3,38 @@ import { Router } from '@angular/router'; import { AccountService } from '../account.service'; +interface TimeEntry { + value: number + viewValue: string +} + @Component({ selector: 'app-admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.scss'] }) export class AdminComponent implements OnInit { - public passwordForm: FormGroup + passwordForm: FormGroup + statusForm: FormGroup public passwordError = false public username = '' - + timeOptions: TimeEntry[] = [ + {value: 60, viewValue: '1 Minute'}, + {value: 600, viewValue: '10 Minutes'}, + {value: 3600, viewValue: '1 Hour'}, + {value: 36000, viewValue: '10 Hours'}, + {value: 24 * 3600, viewValue: '1 Day'}, + ] + defaultTime = '10 Minutes' constructor(public account: AccountService, router: Router, private formBuilder: FormBuilder) { - this.passwordForm = this.formBuilder.group({ password: ['', Validators.required], password_repeat: ['', Validators.required] }) + this.statusForm = this.formBuilder.group({ + status: ['', Validators.required], + time: [null], + }) account.subscribe((username: string) => { if (account.username.length == 0) { router.navigate(['login']) @@ -28,6 +44,7 @@ } ngOnInit(): void { + var form = this.statusForm.get('time')?.setValue(60) } onPasswordSubmit() { @@ -43,4 +60,11 @@ this.passwordForm.reset() }, () => {}) } + + onStatusSubmit() { + if (this.statusForm.invalid) { + return + } + this.account.postStatus(this.statusForm.controls['status'].value, this.statusForm.controls['time'].value) + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1fb908c..2aab2ac 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -13,6 +13,7 @@ import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { MatSelectModule } from '@angular/material/select'; import { MatOptionModule } from '@angular/material/core'; +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -58,6 +59,7 @@ MatSlideToggleModule, MatSelectModule, MatOptionModule, + MatProgressSpinnerModule, ], providers: [AccountService], bootstrap: [AppComponent] diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 6bbb28e..b7052eb 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -44,4 +44,16 @@ The backend is made using Ruby on rails.

+ +

User statuses:

+
+ +
+ +
+

{{userStatus.user}}

+

{{userStatus.message}}

+
+
+
\ No newline at end of file diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 73acf06..47e5069 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,4 +1,14 @@ +import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; +import { environment } from 'src/environments/environment'; + +class UserStatus { + constructor(public user: string, public message: string) {} +} + +class UserStatusAnswer { + constructor(public success: boolean = false, public userStatuses: UserStatus[] = []) {} +} @Component({ selector: 'app-home', @@ -6,10 +16,19 @@ styleUrls: ['./home.component.scss'] }) export class HomeComponent implements OnInit { + userStatuses: UserStatus[] = [] + loading = true - constructor() { } + constructor(private http: HttpClient) { } ngOnInit(): void { + this.http.get(`${environment.apiURL}/users/status`).subscribe((answer) => { + var userStatusAnswer = Object.assign(new UserStatusAnswer(), answer) + this.loading = !userStatusAnswer.success + if (!this.loading) { + this.userStatuses = userStatusAnswer.userStatuses + } + } + ) } - } diff --git a/src/styles.scss b/src/styles.scss index 10cb87c..a5032a0 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -47,4 +47,9 @@ .error { color: mat-color($error); +} + +.flex-center { + display: flex; + justify-content: space-around; } \ No newline at end of file