user settings
This commit is contained in:
@@ -26,15 +26,20 @@ export class PageSettings implements OnInit {
|
||||
username: [ { disabled: true }, Validators.nullValidator ],
|
||||
email: [ '', Validators.nullValidator ],
|
||||
about: [ '', Validators.nullValidator ],
|
||||
gravity: [ '', Validators.nullValidator ],
|
||||
});
|
||||
|
||||
this.form.get('username').disable();
|
||||
|
||||
this.userService.get().subscribe(user => {
|
||||
this.user = user;
|
||||
if (!this.user.settings) {
|
||||
this.user.settings = {};
|
||||
}
|
||||
this.form.get('username').setValue(this.user.username);
|
||||
this.form.get('email').setValue(this.user.email);
|
||||
this.form.get('about').setValue(this.user.about);
|
||||
this.form.get('gravity').setValue(this.user.settings.gravity || this.user.metadata.defaultGravity);
|
||||
})
|
||||
}
|
||||
|
||||
@@ -42,6 +47,11 @@ export class PageSettings implements OnInit {
|
||||
return this.form.controls[ controlName ].errors != null;
|
||||
}
|
||||
|
||||
resetGravity(): void {
|
||||
this.user.settings.gravity = null;
|
||||
this.form.get('gravity').setValue(this.user.metadata.defaultGravity);
|
||||
}
|
||||
|
||||
save(): void {
|
||||
if (this.working) {
|
||||
return;
|
||||
@@ -53,8 +63,21 @@ export class PageSettings implements OnInit {
|
||||
this.user.about = this.form.get('about').value;
|
||||
this.user.email = this.form.get('email').value;
|
||||
|
||||
if (!this.user.settings) {
|
||||
this.user.settings = {};
|
||||
}
|
||||
|
||||
if (this.form.get('gravity').value != this.user.metadata.defaultGravity && !this.user.settings.gravity) {
|
||||
this.user.settings.gravity = this.form.get('gravity').value;
|
||||
} else if (this.user.settings.gravity) {
|
||||
this.user.settings.gravity = this.form.get('gravity').value;
|
||||
}
|
||||
|
||||
this.userService.update(this.user).subscribe((data) => {
|
||||
this.user = data;
|
||||
if (!this.user.settings) {
|
||||
this.user.settings = {};
|
||||
}
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
}, (error) => {
|
||||
|
||||
Reference in New Issue
Block a user