From ed56ad1193bb5bb0a81fb843a11eb90d3fed9861 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 26 Apr 2018 10:03:40 +0200 Subject: Add ability to update the user display name/description --- .../my-account-profile/index.ts | 1 + .../my-account-profile.component.html | 24 ++++++++ .../my-account-profile.component.scss | 23 ++++++++ .../my-account-profile.component.ts | 65 ++++++++++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 client/src/app/my-account/my-account-settings/my-account-profile/index.ts create mode 100644 client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.html create mode 100644 client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.scss create mode 100644 client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts (limited to 'client/src/app/my-account/my-account-settings/my-account-profile') diff --git a/client/src/app/my-account/my-account-settings/my-account-profile/index.ts b/client/src/app/my-account/my-account-settings/my-account-profile/index.ts new file mode 100644 index 000000000..3cc049f8f --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-profile/index.ts @@ -0,0 +1 @@ +export * from './my-account-profile.component' diff --git a/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.html b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.html new file mode 100644 index 000000000..306f3a12c --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.html @@ -0,0 +1,24 @@ +
{{ error }}
+ +
+ + + +
+ {{ formErrors['display-name'] }} +
+ + + +
+ {{ formErrors.description }} +
+ + +
diff --git a/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.scss b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.scss new file mode 100644 index 000000000..fc2b92c89 --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.scss @@ -0,0 +1,23 @@ +@import '_variables'; +@import '_mixins'; + +input[type=text] { + @include peertube-input-text(340px); + + display: block; + margin-bottom: 15px; +} + +textarea { + @include peertube-textarea(500px, 150px); + + display: block; +} + +input[type=submit] { + @include peertube-button; + @include orange-button; + + margin-top: 15px; +} + diff --git a/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts new file mode 100644 index 000000000..2b7ba353c --- /dev/null +++ b/client/src/app/my-account/my-account-settings/my-account-profile/my-account-profile.component.ts @@ -0,0 +1,65 @@ +import { Component, Input, OnInit } from '@angular/core' +import { FormBuilder, FormGroup } from '@angular/forms' +import { NotificationsService } from 'angular2-notifications' +import { FormReactive, USER_DESCRIPTION, USER_DISPLAY_NAME, UserService } from '../../../shared' +import { User } from '@app/shared' + +@Component({ + selector: 'my-account-profile', + templateUrl: './my-account-profile.component.html', + styleUrls: [ './my-account-profile.component.scss' ] +}) +export class MyAccountProfileComponent extends FormReactive implements OnInit { + @Input() user: User = null + + error: string = null + + form: FormGroup + formErrors = { + 'display-name': '', + 'description': '' + } + validationMessages = { + 'display-name': USER_DISPLAY_NAME.MESSAGES, + 'description': USER_DESCRIPTION.MESSAGES + } + + constructor ( + private formBuilder: FormBuilder, + private notificationsService: NotificationsService, + private userService: UserService + ) { + super() + } + + buildForm () { + this.form = this.formBuilder.group({ + 'display-name': [ this.user.account.displayName, USER_DISPLAY_NAME.VALIDATORS ], + 'description': [ this.user.account.description, USER_DESCRIPTION.VALIDATORS ] + }) + + this.form.valueChanges.subscribe(data => this.onValueChanged(data)) + } + + ngOnInit () { + this.buildForm() + } + + updateMyProfile () { + const displayName = this.form.value['display-name'] + const description = this.form.value['description'] + + this.error = null + + this.userService.updateMyProfile({ displayName, description }).subscribe( + () => { + this.user.account.displayName = displayName + this.user.account.description = description + + this.notificationsService.success('Success', 'Profile updated.') + }, + + err => this.error = err.message + ) + } +} -- cgit v1.2.3