comment period
This commit is contained in:
@@ -1,22 +1,24 @@
|
||||
import { Component, OnInit, Input } from '@angular/core';
|
||||
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { PageEvent } from '@angular/material/paginator';
|
||||
|
||||
import { SettingsService } from '../../services/settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'page-entries',
|
||||
templateUrl: './entries.page.html'
|
||||
})
|
||||
export class PageEntries implements OnInit {
|
||||
|
||||
settings: any;
|
||||
@Input() fetch: Function;
|
||||
entries: any;
|
||||
boundRefresh: Function;
|
||||
boundUpdate: Function;
|
||||
init: boolean = true;
|
||||
|
||||
constructor(private router: Router, private route: ActivatedRoute) { }
|
||||
constructor(
|
||||
private settingsService: SettingsService, private router: Router, private route: ActivatedRoute) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.boundRefresh = this.refresh.bind(this);
|
||||
@@ -35,8 +37,11 @@ export class PageEntries implements OnInit {
|
||||
this.entries.size = +params[ 's' ];
|
||||
}
|
||||
|
||||
this.refresh();
|
||||
this.init = false;
|
||||
this.settingsService.settings.subscribe((settings) => {
|
||||
this.settings = settings;
|
||||
this.refresh();
|
||||
this.init = false;
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -47,7 +52,7 @@ export class PageEntries implements OnInit {
|
||||
}
|
||||
|
||||
this.entries.content = null;
|
||||
this.fetch(this.entries.number || 0, this.entries.size || 30).subscribe((data: any) => {
|
||||
this.fetch(this.entries.number || 0, this.entries.size || this.settings.pageSize).subscribe((data: any) => {
|
||||
this.entries = data;
|
||||
}, (error) => { })
|
||||
|
||||
@@ -61,7 +66,7 @@ export class PageEntries implements OnInit {
|
||||
params.p = event.pageIndex + 1;
|
||||
}
|
||||
|
||||
if (event.pageSize != 30) {
|
||||
if (event.pageSize != this.settings.pageSize) {
|
||||
params.s = event.pageSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,18 +19,33 @@
|
||||
<mat-divider></mat-divider>
|
||||
<p>{{'settings.pagesettings' | i18n}}</p>
|
||||
<mat-form-field>
|
||||
<button *ngIf="user.settings.gravity || form.get('gravity').value != user.metadata.defaultGravity" matPrefix
|
||||
<button *ngIf="user.settings.gravity || form.get('gravity').value != settings.defaultGravity" matPrefix
|
||||
mat-icon-button (click)="resetGravity()">
|
||||
<mat-icon>cancel</mat-icon>
|
||||
</button>
|
||||
<input type="number" min="0" max="2" step="0.1" matInput placeholder="{{'settings.gravity' | i18n}}"
|
||||
formControlName="gravity">
|
||||
<mat-hint *ngIf="form.get('gravity').value != 0">
|
||||
{{'settings.gravity.hint' | i18n}}
|
||||
</mat-hint>
|
||||
<mat-hint *ngIf="form.get('gravity').value == 0">
|
||||
{{'settings.gravity.zero' | i18n}}
|
||||
</mat-hint>
|
||||
<mat-hint *ngIf="form.get('gravity').value != 0">
|
||||
{{'settings.gravity.hint' | i18n}}
|
||||
</mat-hint>
|
||||
<mat-hint *ngIf="form.get('gravity').value == 0">
|
||||
{{'settings.gravity.zero' | i18n}}
|
||||
</mat-hint>
|
||||
</mat-form-field>
|
||||
<mat-form-field>
|
||||
<button
|
||||
*ngIf="user.settings.commentDelay || form.get('commentDelay').value != settings.defaultCommentDelay"
|
||||
matPrefix mat-icon-button (click)="resetCommentDelay()">
|
||||
<mat-icon>cancel</mat-icon>
|
||||
</button>
|
||||
<input type="number" min="0" max="15" step="1" matInput placeholder="{{'settings.commentDelay' | i18n}}"
|
||||
formControlName="commentDelay">
|
||||
<mat-hint *ngIf="form.get('commentDelay').value != 0">
|
||||
{{'settings.commentDelay.hint' | i18n}}
|
||||
</mat-hint>
|
||||
<mat-hint *ngIf="form.get('commentDelay').value == 0">
|
||||
{{'settings.commentDelay.zero' | i18n}}
|
||||
</mat-hint>
|
||||
</mat-form-field>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Component, 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';
|
||||
|
||||
@Component({
|
||||
selector: 'page-settings',
|
||||
@@ -15,10 +16,12 @@ export class PageSettings implements OnInit {
|
||||
working: boolean = false;
|
||||
success: boolean = false;
|
||||
form: FormGroup;
|
||||
settings: any;
|
||||
@ViewChild('formDirective') private formDirective: NgForm;
|
||||
|
||||
constructor(
|
||||
private userService: UserService,
|
||||
private settingsService: SettingsService,
|
||||
private formBuilder: FormBuilder) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -27,6 +30,7 @@ export class PageSettings implements OnInit {
|
||||
email: [ '', Validators.nullValidator ],
|
||||
about: [ '', Validators.nullValidator ],
|
||||
gravity: [ '', Validators.nullValidator ],
|
||||
commentDelay: [ '', Validators.nullValidator ],
|
||||
});
|
||||
|
||||
this.form.get('username').disable();
|
||||
@@ -39,8 +43,15 @@ export class PageSettings implements OnInit {
|
||||
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);
|
||||
|
||||
this.settingsService.settings.subscribe((settings) => {
|
||||
this.settings = settings;
|
||||
this.form.get('gravity').setValue(this.user.settings.gravity || this.settings.defaultGravity);
|
||||
this.form.get('commentDelay').setValue(this.user.settings.commentDelay || this.settings.defaultCommentDelay);
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
hasError(controlName: string): boolean {
|
||||
@@ -49,7 +60,12 @@ export class PageSettings implements OnInit {
|
||||
|
||||
resetGravity(): void {
|
||||
this.user.settings.gravity = null;
|
||||
this.form.get('gravity').setValue(this.user.metadata.defaultGravity);
|
||||
this.form.get('gravity').setValue(this.settings.defaultGravity);
|
||||
}
|
||||
|
||||
resetCommentDelay(): void {
|
||||
this.user.settings.commentDelay = null;
|
||||
this.form.get('commentDelay').setValue(this.settings.defaultCommentDelay);
|
||||
}
|
||||
|
||||
save(): void {
|
||||
@@ -67,12 +83,18 @@ export class PageSettings implements OnInit {
|
||||
this.user.settings = {};
|
||||
}
|
||||
|
||||
if (this.form.get('gravity').value != this.user.metadata.defaultGravity && !this.user.settings.gravity) {
|
||||
if (this.form.get('gravity').value != this.settings.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;
|
||||
}
|
||||
|
||||
if (this.form.get('commentDelay').value != this.settings.defaultCommentDelay && !this.user.settings.commentDelay) {
|
||||
this.user.settings.commentDelay = this.form.get('commentDelay').value;
|
||||
} else if (this.user.settings.commentDelay) {
|
||||
this.user.settings.commentDelay = this.form.get('gravity').value;
|
||||
}
|
||||
|
||||
this.userService.update(this.user).subscribe((data) => {
|
||||
this.user = data;
|
||||
if (!this.user.settings) {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Component, OnInit, Input } from '@angular/core';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { CommentService } from '../../../services/comment.service';
|
||||
import { SettingsService } from '../../../services/settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'page-usercomments',
|
||||
@@ -11,18 +12,22 @@ import { CommentService } from '../../../services/comment.service';
|
||||
})
|
||||
export class PageUserComments implements OnInit {
|
||||
|
||||
settings: any;
|
||||
username: string;
|
||||
comments: any = {};
|
||||
init: boolean = true;
|
||||
ignore : string[] = ["author"];
|
||||
ignore: string[] = [ "author" ];
|
||||
|
||||
constructor(private commentService: CommentService, private router: Router, private route: ActivatedRoute) { }
|
||||
constructor(private settingsService: SettingsService, private commentService: CommentService, private router: Router, private route: ActivatedRoute) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.username = this.route.snapshot.paramMap.get('username');
|
||||
this.commentService.getByUser(this.username, this.comments.number || 0, this.comments.size || 30, this.ignore).subscribe((data: any) => {
|
||||
this.comments = data;
|
||||
}, (error) => { })
|
||||
this.settingsService.settings.subscribe((settings) => {
|
||||
this.settings = settings;
|
||||
this.commentService.getByUser(this.username, this.comments.number || 0, this.comments.size || this.settings.pageSize, this.ignore).subscribe((data: any) => {
|
||||
this.comments = data;
|
||||
}, (error) => { })
|
||||
})
|
||||
}
|
||||
|
||||
showMore() {
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
<div class="container">
|
||||
<p>{{'user.entriesBy' | i18n}}<a routerLink="/u/{{username}}">{{username}}</a></p>
|
||||
</div>
|
||||
<ui-entries fxFlex="1 0 1" [entries]="entries" [refresh]="boundRefresh" [update]="boundUpdate"></ui-entries>
|
||||
<page-entries [fetch]="boundFetch"></page-entries>
|
||||
</div>
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { EntriesService } from '../../../services/entries.service';
|
||||
import { PageEvent } from '@angular/material/paginator';
|
||||
|
||||
@Component({
|
||||
selector: 'page-userentries',
|
||||
@@ -11,73 +10,18 @@ import { PageEvent } from '@angular/material/paginator';
|
||||
})
|
||||
export class PageUserEntries implements OnInit {
|
||||
|
||||
username : string;
|
||||
entries: any;
|
||||
boundRefresh: Function;
|
||||
boundUpdate: Function;
|
||||
init: boolean = true;
|
||||
username: string;
|
||||
boundFetch: Function;
|
||||
|
||||
constructor(private entriesService: EntriesService, private router: Router, private route: ActivatedRoute) { }
|
||||
constructor(private entriesService: EntriesService, private route: ActivatedRoute) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.username = this.route.snapshot.paramMap.get('username');
|
||||
this.boundRefresh = this.refresh.bind(this);
|
||||
this.boundUpdate = this.update.bind(this);
|
||||
this.route.queryParams.subscribe(params => {
|
||||
if (this.init) {
|
||||
this.entries = {};
|
||||
if (params[ 'p' ]) {
|
||||
this.entries.number = +params[ 'p' ] - 1;
|
||||
if (this.entries.number < 0) {
|
||||
this.entries.number = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (params[ 's' ]) {
|
||||
this.entries.size = +params[ 's' ];
|
||||
}
|
||||
|
||||
this.refresh();
|
||||
this.init = false;
|
||||
}
|
||||
});
|
||||
this.boundFetch = this.fetch.bind(this);
|
||||
}
|
||||
|
||||
refresh(): void {
|
||||
if (!this.entries) {
|
||||
this.entries = {};
|
||||
}
|
||||
|
||||
this.entries.content = null;
|
||||
this.entriesService.getByUser(this.username, this.entries.number || 0, this.entries.size || 30).subscribe((data: any) => {
|
||||
this.entries = data;
|
||||
}, (error) => { })
|
||||
|
||||
}
|
||||
|
||||
update(event: PageEvent) {
|
||||
this.entries.content = null;
|
||||
const params: any = { p: null, s: null };
|
||||
|
||||
if (event.pageIndex != 0) {
|
||||
params.p = event.pageIndex + 1;
|
||||
}
|
||||
|
||||
if (event.pageSize != 30) {
|
||||
params.s = event.pageSize;
|
||||
}
|
||||
|
||||
this.router.navigate(
|
||||
[],
|
||||
{
|
||||
relativeTo: this.route,
|
||||
queryParams: params,
|
||||
queryParamsHandling: 'merge'
|
||||
});
|
||||
|
||||
this.entriesService.getByUser(this.username,event.pageIndex, event.pageSize).subscribe((data: any) => {
|
||||
this.entries = data;
|
||||
}, (error) => { })
|
||||
fetch(page: number, size: number) {
|
||||
return this.entriesService.getByUser(this.username, page, size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user