From af5e743b01f20f24d0c25e786d57f557b21f3a24 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 6 Apr 2017 21:21:03 +0200 Subject: Client: add ability for user to change nsfw settings --- .../account-details/account-details.component.html | 16 +++++ .../account-details/account-details.component.ts | 68 ++++++++++++++++++++++ client/src/app/account/account-details/index.ts | 1 + 3 files changed, 85 insertions(+) create mode 100644 client/src/app/account/account-details/account-details.component.html create mode 100644 client/src/app/account/account-details/account-details.component.ts create mode 100644 client/src/app/account/account-details/index.ts (limited to 'client/src/app/account/account-details') diff --git a/client/src/app/account/account-details/account-details.component.html b/client/src/app/account/account-details/account-details.component.html new file mode 100644 index 000000000..24b0750d2 --- /dev/null +++ b/client/src/app/account/account-details/account-details.component.html @@ -0,0 +1,16 @@ +
{{ error }}
+ +
+
+ + +
+ {{ formErrors['displayNSFW'] }} +
+
+ + +
diff --git a/client/src/app/account/account-details/account-details.component.ts b/client/src/app/account/account-details/account-details.component.ts new file mode 100644 index 000000000..30e5b14ee --- /dev/null +++ b/client/src/app/account/account-details/account-details.component.ts @@ -0,0 +1,68 @@ +import { Component, OnInit, Input } from '@angular/core'; +import { FormBuilder, FormGroup } from '@angular/forms'; +import { Router } from '@angular/router'; + +import { NotificationsService } from 'angular2-notifications'; + +import { AuthService } from '../../core'; +import { + FormReactive, + User, + UserService, + USER_PASSWORD +} from '../../shared'; + +@Component({ + selector: 'my-account-details', + templateUrl: './account-details.component.html' +}) + +export class AccountDetailsComponent extends FormReactive implements OnInit { + @Input() user: User = null; + + error: string = null; + + form: FormGroup; + formErrors = {}; + validationMessages = {}; + + constructor( + private authService: AuthService, + private formBuilder: FormBuilder, + private router: Router, + private notificationsService: NotificationsService, + private userService: UserService + ) { + super(); + } + + buildForm() { + this.form = this.formBuilder.group({ + displayNSFW: [ this.user.displayNSFW ], + }); + + this.form.valueChanges.subscribe(data => this.onValueChanged(data)); + } + + ngOnInit() { + this.buildForm(); + } + + updateDetails() { + const displayNSFW = this.form.value['displayNSFW']; + const details = { + displayNSFW + }; + + this.error = null; + this.userService.updateDetails(details).subscribe( + () => { + this.notificationsService.success('Success', 'Informations updated.'); + + this.authService.refreshUserInformations(); + }, + + err => this.error = err + ); + } +} diff --git a/client/src/app/account/account-details/index.ts b/client/src/app/account/account-details/index.ts new file mode 100644 index 000000000..28f644738 --- /dev/null +++ b/client/src/app/account/account-details/index.ts @@ -0,0 +1 @@ +export * from './account-details.component'; -- cgit v1.2.3