userpages + filter improvments
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormGroup, Validators, NgForm } from '@angular/forms';
|
||||
|
||||
import { UserService } from '../../services/user.service';
|
||||
import { SettingsService } from 'src/app/services/settings.service';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'page-settings',
|
||||
templateUrl: './settings.page.html',
|
||||
styleUrls: [ './settings.page.scss' ]
|
||||
})
|
||||
export class PageSettings implements OnInit {
|
||||
export class PageSettings implements OnInit, OnDestroy {
|
||||
|
||||
auth: any;
|
||||
user: any;
|
||||
@@ -18,6 +19,7 @@ export class PageSettings implements OnInit {
|
||||
form: FormGroup;
|
||||
settings: any;
|
||||
@ViewChild('formDirective') private formDirective: NgForm;
|
||||
settingsSubscription: Subscription;
|
||||
|
||||
constructor(
|
||||
private userService: UserService,
|
||||
@@ -32,6 +34,7 @@ export class PageSettings implements OnInit {
|
||||
gravity: [ '', Validators.nullValidator ],
|
||||
entryDelay: [ '', Validators.nullValidator ],
|
||||
commentDelay: [ '', Validators.nullValidator ],
|
||||
pageSize: [ '', Validators.nullValidator ],
|
||||
});
|
||||
|
||||
this.form.get('username').disable();
|
||||
@@ -45,15 +48,18 @@ export class PageSettings implements OnInit {
|
||||
this.form.get('email').setValue(this.user.email);
|
||||
this.form.get('about').setValue(this.user.about);
|
||||
|
||||
this.settingsService.settings.subscribe((settings) => {
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe((settings) => {
|
||||
this.settings = settings;
|
||||
this.form.get('gravity').setValue(this.user.settings.gravity || this.settings.defaultGravity);
|
||||
this.form.get('entryDelay').setValue(this.user.settings.entryDelay || this.settings.defaultEntryDelay);
|
||||
this.form.get('commentDelay').setValue(this.user.settings.commentDelay || this.settings.defaultCommentDelay);
|
||||
this.form.get('pageSize').setValue(this.user.settings.pageSize || this.settings.defaultPageSize);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.settingsSubscription.unsubscribe();
|
||||
}
|
||||
|
||||
hasError(controlName: string): boolean {
|
||||
@@ -75,6 +81,11 @@ export class PageSettings implements OnInit {
|
||||
this.form.get('commentDelay').setValue(this.settings.defaultCommentDelay);
|
||||
}
|
||||
|
||||
resetPageSize(): void {
|
||||
this.user.settings.pageSize = null;
|
||||
this.form.get('pageSize').setValue(this.settings.defaultPageSize);
|
||||
}
|
||||
|
||||
save(): void {
|
||||
if (this.working) {
|
||||
return;
|
||||
@@ -108,6 +119,12 @@ export class PageSettings implements OnInit {
|
||||
this.user.settings.commentDelay = this.form.get('commentDelay').value;
|
||||
}
|
||||
|
||||
if (this.form.get('pageSize').value != this.settings.defaultPageSize && !this.user.settings.pageSize) {
|
||||
this.user.settings.pageSize = this.form.get('pageSize').value;
|
||||
} else if (this.user.settings.pageSize) {
|
||||
this.user.settings.pageSize = this.form.get('pageSize').value;
|
||||
}
|
||||
|
||||
this.userService.update(this.user).subscribe((data) => {
|
||||
this.user = data;
|
||||
if (!this.user.settings) {
|
||||
@@ -115,6 +132,7 @@ export class PageSettings implements OnInit {
|
||||
}
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
this.settingsService.getSettings();
|
||||
}, (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 422) {
|
||||
|
||||
Reference in New Issue
Block a user