update dependencies, migrate subscribe, add submit type to buttons
This commit is contained in:
@@ -7,14 +7,14 @@ import { CommentService } from '../../services/comment.service';
|
||||
@Component({
|
||||
selector: 'page-comment',
|
||||
templateUrl: './comment.page.html',
|
||||
styleUrls: [ './comment.page.scss' ]
|
||||
styleUrls: ['./comment.page.scss']
|
||||
})
|
||||
export class PageComment implements OnInit {
|
||||
|
||||
id: number;
|
||||
comment: any;
|
||||
notfound: boolean = false;
|
||||
ignoreSubcomments: string[] = [ 'entry' ];
|
||||
ignoreSubcomments: string[] = ['entry'];
|
||||
|
||||
constructor(private commentService: CommentService,
|
||||
private route: ActivatedRoute) { }
|
||||
@@ -22,11 +22,14 @@ export class PageComment implements OnInit {
|
||||
ngOnInit(): void {
|
||||
this.id = +this.route.snapshot.paramMap.get('id');
|
||||
|
||||
this.commentService.getComment(this.id).subscribe((data) => {
|
||||
this.comment = data;
|
||||
}, (error) => {
|
||||
if (error.status == 404) {
|
||||
this.notfound = true;
|
||||
this.commentService.getComment(this.id).subscribe({
|
||||
next: (data) => {
|
||||
this.comment = data;
|
||||
},
|
||||
error: (error) => {
|
||||
if (error.status == 404) {
|
||||
this.notfound = true;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -31,35 +31,39 @@ export class PageEntries implements OnInit, OnDestroy {
|
||||
ngOnInit(): void {
|
||||
this.boundRefresh = this.refresh.bind(this);
|
||||
this.boundUpdate = this.update.bind(this);
|
||||
this.route.queryParams.subscribe(params => {
|
||||
if (this.init) {
|
||||
this.entries = { filter: {} };
|
||||
if (params[ 'p' ]) {
|
||||
this.entries.number = +params[ 'p' ] - 1;
|
||||
if (this.entries.number < 0) {
|
||||
this.entries.number = 0;
|
||||
this.route.queryParams.subscribe({
|
||||
next: (params) => {
|
||||
if (this.init) {
|
||||
this.entries = { filter: {} };
|
||||
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' ];
|
||||
}
|
||||
|
||||
if (params[ 'asc' ]) {
|
||||
this.asc = true;
|
||||
}
|
||||
|
||||
for (const param in params) {
|
||||
if (param != 's' && param != 'p' && param != 'asc') {
|
||||
this.entries.filter[ param ] = params[ param ];
|
||||
if (params['s']) {
|
||||
this.entries.size = +params['s'];
|
||||
}
|
||||
}
|
||||
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe((settings) => {
|
||||
this.settings = settings;
|
||||
this.refresh();
|
||||
this.init = false;
|
||||
})
|
||||
if (params['asc']) {
|
||||
this.asc = true;
|
||||
}
|
||||
|
||||
for (const param in params) {
|
||||
if (param != 's' && param != 'p' && param != 'asc') {
|
||||
this.entries.filter[param] = params[param];
|
||||
}
|
||||
}
|
||||
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe({
|
||||
next: (settings) => {
|
||||
this.settings = settings;
|
||||
this.refresh();
|
||||
this.init = false;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -75,11 +79,14 @@ export class PageEntries implements OnInit, OnDestroy {
|
||||
|
||||
const filter = JSON.parse(JSON.stringify(this.entries.filter || {}))
|
||||
this.entries.content = null;
|
||||
this.fetch(this.entries.number || 0, this.entries.size || this.settings.pageSize, this.asc, this.entries.filter).subscribe((data: any) => {
|
||||
this.entries = data;
|
||||
this.entries.filter = filter;
|
||||
}, (error) => {
|
||||
this.entries = { error: error };
|
||||
this.fetch(this.entries.number || 0, this.entries.size || this.settings.pageSize, this.asc, this.entries.filter).subscribe({
|
||||
next: (data: any) => {
|
||||
this.entries = data;
|
||||
this.entries.filter = filter;
|
||||
},
|
||||
error: (error) => {
|
||||
this.entries = { error: error };
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
@@ -98,7 +105,7 @@ export class PageEntries implements OnInit, OnDestroy {
|
||||
|
||||
if (this.entries.filter) {
|
||||
for (const param in this.entries.filter) {
|
||||
params[ param ] = this.entries.filter[ param ];
|
||||
params[param] = this.entries.filter[param];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,11 +118,13 @@ export class PageEntries implements OnInit, OnDestroy {
|
||||
});
|
||||
|
||||
const filter = JSON.parse(JSON.stringify(this.entries.filter || {}))
|
||||
this.fetch(event.pageIndex, event.pageSize, this.asc, this.entries.filter).subscribe((data: any) => {
|
||||
this.entries = data;
|
||||
this.entries.filter = filter;
|
||||
}, (error) => {
|
||||
this.entries = { error: error };
|
||||
this.fetch(event.pageIndex, event.pageSize, this.asc, this.entries.filter).subscribe({
|
||||
next: (data: any) => {
|
||||
this.entries = data;
|
||||
this.entries.filter = filter;
|
||||
}, error: (error) => {
|
||||
this.entries = { error: error };
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -46,10 +46,10 @@
|
||||
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button *ngIf="!working && !entry.id" mat-raised-button color="primary" [disabled]="form.invalid">
|
||||
<button type="submit" *ngIf="!working && !entry.id" mat-raised-button color="primary" [disabled]="form.invalid">
|
||||
{{'submission.create' | i18n}}
|
||||
</button>
|
||||
<button *ngIf="!working && entry.id" mat-raised-button color="primary" [disabled]="form.invalid">
|
||||
<button type="submit" *ngIf="!working && entry.id" mat-raised-button color="primary" [disabled]="form.invalid">
|
||||
{{'submission.update' | i18n}}
|
||||
</button>
|
||||
<a *ngIf="success" mat-button color="primary" routerLink="/e/{{entry.id}}">{{'submission.success' | i18n}}</a>
|
||||
|
||||
@@ -11,14 +11,14 @@ import { Subscription } from 'rxjs';
|
||||
@Component({
|
||||
selector: 'page-entry-edit',
|
||||
templateUrl: './edit.page.html',
|
||||
styleUrls: [ './edit.page.scss' ]
|
||||
styleUrls: ['./edit.page.scss']
|
||||
})
|
||||
export class PageEntryEdit implements OnInit, OnDestroy {
|
||||
|
||||
id: number;
|
||||
entry: any;
|
||||
entryTypes: string[] = [ 'LINK', 'DISCUSSION', 'QUESTION', 'INTERN' ];
|
||||
entryType: string = this.entryTypes[ 0 ];
|
||||
entryTypes: string[] = ['LINK', 'DISCUSSION', 'QUESTION', 'INTERN'];
|
||||
entryType: string = this.entryTypes[0];
|
||||
notfound: boolean = false;
|
||||
working: boolean = false;
|
||||
success: boolean = false;
|
||||
@@ -37,40 +37,48 @@ export class PageEntryEdit implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = this.formBuilder.group({
|
||||
entryType: [ '', Validators.required ],
|
||||
url: [ '', Validators.required ],
|
||||
title: [ '', Validators.required ],
|
||||
text: [ '', Validators.nullValidator ],
|
||||
entryType: ['', Validators.required],
|
||||
url: ['', Validators.required],
|
||||
title: ['', Validators.required],
|
||||
text: ['', Validators.nullValidator],
|
||||
});
|
||||
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe((settings) => {
|
||||
this.settings = settings;
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe({
|
||||
next: (settings) => {
|
||||
this.settings = settings;
|
||||
}
|
||||
});
|
||||
|
||||
this.form.get('entryType').setValue(this.entryType);
|
||||
|
||||
this.form.get('entryType').valueChanges.subscribe((value) => {
|
||||
this.entryType = value;
|
||||
switch (value) {
|
||||
case 'LINK':
|
||||
this.form.get('url').setValidators([ Validators.required ]);
|
||||
this.form.get('text').setValidators([ Validators.nullValidator ]);
|
||||
break;
|
||||
default:
|
||||
this.form.get('url').setValidators([ Validators.nullValidator ]);
|
||||
this.form.get('text').setValidators([ Validators.required ]);
|
||||
break;
|
||||
this.form.get('entryType').valueChanges.subscribe({
|
||||
next: (value) => {
|
||||
this.entryType = value;
|
||||
switch (value) {
|
||||
case 'LINK':
|
||||
this.form.get('url').setValidators([Validators.required]);
|
||||
this.form.get('text').setValidators([Validators.nullValidator]);
|
||||
break;
|
||||
default:
|
||||
this.form.get('url').setValidators([Validators.nullValidator]);
|
||||
this.form.get('text').setValidators([Validators.required]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.form.get('url').valueChanges.pipe(
|
||||
debounceTime(800),
|
||||
distinctUntilChanged()).subscribe((value) => {
|
||||
if (value && !this.form.get('title').value) {
|
||||
this.entriesService.titleHelper(value).subscribe((title: string) => {
|
||||
this.form.get('title').setValue(title);
|
||||
})
|
||||
distinctUntilChanged()).subscribe({
|
||||
next: (value) => {
|
||||
if (value && !this.form.get('title').value) {
|
||||
this.entriesService.titleHelper(value).subscribe({
|
||||
next: (title: string) => {
|
||||
this.form.get('title').setValue(title);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -85,21 +93,24 @@ export class PageEntryEdit implements OnInit, OnDestroy {
|
||||
refresh() {
|
||||
if (this.id) {
|
||||
this.form.get('entryType').disable();
|
||||
this.entriesService.getEntry(this.id).subscribe((data) => {
|
||||
this.entry = data;
|
||||
this.entryType = this.entry.entryType;
|
||||
this.form.get("entryType").setValue(this.entry.entryType);
|
||||
this.form.get("url").setValue(this.entry.url);
|
||||
this.form.get("title").setValue(this.entry.title);
|
||||
this.form.get("text").setValue(this.entry.text);
|
||||
if (!this.entry.metadata.edit) {
|
||||
this.form.get("url").disable();
|
||||
this.form.get("title").disable();
|
||||
this.form.get("text").disable();
|
||||
}
|
||||
}, (error) => {
|
||||
if (error.status == 404) {
|
||||
this.notfound = true;
|
||||
this.entriesService.getEntry(this.id).subscribe({
|
||||
next: (data) => {
|
||||
this.entry = data;
|
||||
this.entryType = this.entry.entryType;
|
||||
this.form.get("entryType").setValue(this.entry.entryType);
|
||||
this.form.get("url").setValue(this.entry.url);
|
||||
this.form.get("title").setValue(this.entry.title);
|
||||
this.form.get("text").setValue(this.entry.text);
|
||||
if (!this.entry.metadata.edit) {
|
||||
this.form.get("url").disable();
|
||||
this.form.get("title").disable();
|
||||
this.form.get("text").disable();
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
if (error.status == 404) {
|
||||
this.notfound = true;
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -110,7 +121,7 @@ export class PageEntryEdit implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
hasError(controlName: string): boolean {
|
||||
return this.form.controls[ controlName ].errors != null;
|
||||
return this.form.controls[controlName].errors != null;
|
||||
}
|
||||
|
||||
onTitleFocus(event): void {
|
||||
@@ -129,19 +140,22 @@ export class PageEntryEdit implements OnInit, OnDestroy {
|
||||
this.entry.title = this.form.get("title").value;
|
||||
this.entry.text = this.form.get("text").value;
|
||||
|
||||
this.entriesService.create(this.entry).subscribe((data) => {
|
||||
this.router.navigateByUrl('/');
|
||||
}, (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[ code.field ] = errors[ code.field ] || {};
|
||||
errors[ code.field ][ code.code ] = true;
|
||||
}
|
||||
this.entriesService.create(this.entry).subscribe({
|
||||
next: (data) => {
|
||||
this.router.navigateByUrl('/');
|
||||
},
|
||||
error: (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[code.field] = errors[code.field] || {};
|
||||
errors[code.field][code.code] = true;
|
||||
}
|
||||
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[ code ]);
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[code]);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -159,46 +173,51 @@ export class PageEntryEdit implements OnInit, OnDestroy {
|
||||
this.entry.title = this.form.get("title").value;
|
||||
this.entry.text = this.form.get("text").value;
|
||||
|
||||
this.entriesService.update(this.entry).subscribe((data) => {
|
||||
this.entry = data;
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
}, (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 403) {
|
||||
this.snackBar.open("Error");
|
||||
}
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[ code.field ] = errors[ code.field ] || {};
|
||||
errors[ code.field ][ code.code ] = true;
|
||||
this.entriesService.update(this.entry).subscribe({
|
||||
next: (data) => {
|
||||
this.entry = data;
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
},
|
||||
error: (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 403) {
|
||||
this.snackBar.open("Error");
|
||||
}
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[code.field] = errors[code.field] || {};
|
||||
errors[code.field][code.code] = true;
|
||||
}
|
||||
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[ code ]);
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[code]);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.tagsService.setTags(this.entry.id, this.entry.tags).subscribe((data) => {
|
||||
this.entry = data;
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
}, (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 403) {
|
||||
this.snackBar.open("Error");
|
||||
}
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[ code.field ] = errors[ code.field ] || {};
|
||||
errors[ code.field ][ code.code ] = true;
|
||||
this.tagsService.setTags(this.entry.id, this.entry.tags).subscribe({
|
||||
next: (data) => {
|
||||
this.entry = data;
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
}, error: (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 403) {
|
||||
this.snackBar.open("Error");
|
||||
}
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[code.field] = errors[code.field] || {};
|
||||
errors[code.field][code.code] = true;
|
||||
}
|
||||
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[ code ]);
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[code]);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -9,7 +9,7 @@ import { UiComments } from '../../ui/comments/comments.ui';
|
||||
@Component({
|
||||
selector: 'page-entry',
|
||||
templateUrl: './entry.page.html',
|
||||
styleUrls: [ './entry.page.scss' ]
|
||||
styleUrls: ['./entry.page.scss']
|
||||
})
|
||||
export class PageEntry implements OnInit {
|
||||
|
||||
@@ -29,12 +29,15 @@ export class PageEntry implements OnInit {
|
||||
}
|
||||
|
||||
refresh() {
|
||||
this.entriesService.getEntry(this.id).subscribe((data) => {
|
||||
this.entry = data;
|
||||
}, (error) => {
|
||||
if (error.status == 404) {
|
||||
this.entry = false;
|
||||
this.notfound = true;
|
||||
this.entriesService.getEntry(this.id).subscribe({
|
||||
next: (data) => {
|
||||
this.entry = data;
|
||||
},
|
||||
error: (error) => {
|
||||
if (error.status == 404) {
|
||||
this.entry = false;
|
||||
this.notfound = true;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { AuthService } from '../../services/auth.service';
|
||||
@Component({
|
||||
selector: 'page-login',
|
||||
templateUrl: './login.page.html',
|
||||
styleUrls: [ './login.page.scss' ]
|
||||
styleUrls: ['./login.page.scss']
|
||||
})
|
||||
export class PageLogin implements OnInit {
|
||||
|
||||
@@ -27,30 +27,34 @@ export class PageLogin implements OnInit {
|
||||
private route: ActivatedRoute) { }
|
||||
|
||||
async ngOnInit() {
|
||||
this.route.queryParams.subscribe(params => {
|
||||
if (params[ 'all' ] || params[ 'all' ] == '') {
|
||||
this.internalLogin = true;
|
||||
}
|
||||
if (params[ 'target' ]) {
|
||||
this.targetRoute = params[ 'target' ];
|
||||
this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
||||
}
|
||||
if (params[ 'error' ] || params[ 'error' ] == '') {
|
||||
this.loginInvalid = true;
|
||||
this.router.navigate([], { queryParams: { error: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
||||
}
|
||||
if (params[ 'externalError' ] || params[ 'externalError' ] == '') {
|
||||
this.externalLoginInvalid = true;
|
||||
this.router.navigate([], { queryParams: { externalError: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
||||
this.route.queryParams.subscribe({
|
||||
next: (params) => {
|
||||
if (params['all'] || params['all'] == '') {
|
||||
this.internalLogin = true;
|
||||
}
|
||||
if (params['target']) {
|
||||
this.targetRoute = params['target'];
|
||||
this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
||||
}
|
||||
if (params['error'] || params['error'] == '') {
|
||||
this.loginInvalid = true;
|
||||
this.router.navigate([], { queryParams: { error: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
||||
}
|
||||
if (params['externalError'] || params['externalError'] == '') {
|
||||
this.externalLoginInvalid = true;
|
||||
this.router.navigate([], { queryParams: { externalError: null }, queryParamsHandling: 'merge', replaceUrl: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.authService.getExternal().subscribe((data: any[]) => {
|
||||
this.externals = data;
|
||||
const autologinClient = localStorage.getItem("bstlboard.autologin");
|
||||
for (let client of this.externals) {
|
||||
if (client.id == autologinClient) {
|
||||
window.location.href = this.apiUrl + "/" + client.loginUrl;
|
||||
this.authService.getExternal().subscribe({
|
||||
next: (data: any[]) => {
|
||||
this.externals = data;
|
||||
const autologinClient = localStorage.getItem("bstlboard.autologin");
|
||||
for (let client of this.externals) {
|
||||
if (client.id == autologinClient) {
|
||||
window.location.href = this.apiUrl + "/" + client.loginUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -19,19 +19,23 @@ export class PageModerationComments implements OnInit {
|
||||
}
|
||||
|
||||
refresh(): void {
|
||||
this.moderationService.getFlaggedComments(this.comments.number || 0, this.comments.size || 30).subscribe((data: any) => {
|
||||
this.comments = data;
|
||||
}, (error) => { })
|
||||
this.moderationService.getFlaggedComments(this.comments.number || 0, this.comments.size || 30).subscribe({
|
||||
next: (data: any) => {
|
||||
this.comments = data;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
showMore() {
|
||||
const oldContent: any[] = this.comments.content;
|
||||
this.moderationService.getFlaggedComments(this.comments.number + 1, this.comments.size).subscribe((data) => {
|
||||
this.comments = data;
|
||||
for (let comment of this.comments.content) {
|
||||
oldContent.push(comment);
|
||||
this.moderationService.getFlaggedComments(this.comments.number + 1, this.comments.size).subscribe({
|
||||
next: (data) => {
|
||||
this.comments = data;
|
||||
for (let comment of this.comments.content) {
|
||||
oldContent.push(comment);
|
||||
}
|
||||
this.comments.content = oldContent;
|
||||
}
|
||||
this.comments.content = oldContent;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,13 +44,17 @@ export class PageSearch implements OnInit {
|
||||
})
|
||||
|
||||
this.searchFormControl.valueChanges.pipe(
|
||||
debounceTime(300)).subscribe((value: string) => {
|
||||
this.refresh();
|
||||
debounceTime(300)).subscribe({
|
||||
next: (value: string) => {
|
||||
this.refresh();
|
||||
}
|
||||
})
|
||||
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe((settings) => {
|
||||
this.settings = settings;
|
||||
this.refresh();
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe({
|
||||
next: (settings) => {
|
||||
this.settings = settings;
|
||||
this.refresh();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -79,10 +83,13 @@ export class PageSearch implements OnInit {
|
||||
});
|
||||
|
||||
this.results.content = null;
|
||||
this.searchService.search(this.searchFormControl.value || " ", this.searchType, 0, this.results.size || this.settings.pageSize, this.asc, this.byDate).subscribe((data: any) => {
|
||||
this.results = data;
|
||||
}, (error) => {
|
||||
this.results = { error: error };
|
||||
this.searchService.search(this.searchFormControl.value || " ", this.searchType, 0, this.results.size || this.settings.pageSize, this.asc, this.byDate).subscribe({
|
||||
next: (data: any) => {
|
||||
this.results = data;
|
||||
},
|
||||
error: (error) => {
|
||||
this.results = { error: error };
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -106,10 +113,13 @@ export class PageSearch implements OnInit {
|
||||
queryParamsHandling: 'merge'
|
||||
});
|
||||
|
||||
this.searchService.search(this.searchFormControl.value, this.searchType, event.pageIndex, event.pageSize, this.asc, this.byDate).subscribe((data: any) => {
|
||||
this.results = data;
|
||||
}, (error) => {
|
||||
this.results = { error: error };
|
||||
this.searchService.search(this.searchFormControl.value, this.searchType, event.pageIndex, event.pageSize, this.asc, this.byDate).subscribe({
|
||||
next: (data: any) => {
|
||||
this.results = data;
|
||||
},
|
||||
error: (error) => {
|
||||
this.results = { error: error };
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
</mat-form-field>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button *ngIf="!working" mat-raised-button color="primary" [disabled]="form.invalid">
|
||||
<button type="submit" *ngIf="!working" mat-raised-button color="primary" [disabled]="form.invalid">
|
||||
{{'settings.update' | i18n}}
|
||||
</button>
|
||||
<a *ngIf="success" mat-button color="primary">{{'settings.success' | i18n}}</a>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Subscription } from 'rxjs';
|
||||
@Component({
|
||||
selector: 'page-settings',
|
||||
templateUrl: './settings.page.html',
|
||||
styleUrls: [ './settings.page.scss' ]
|
||||
styleUrls: ['./settings.page.scss']
|
||||
})
|
||||
export class PageSettings implements OnInit, OnDestroy {
|
||||
|
||||
@@ -27,33 +27,37 @@ export class PageSettings implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = this.formBuilder.group({
|
||||
username: [ { disabled: true }, Validators.nullValidator ],
|
||||
email: [ '', Validators.nullValidator ],
|
||||
about: [ '', Validators.nullValidator ],
|
||||
gravity: [ '', Validators.nullValidator ],
|
||||
entryDelay: [ '', Validators.nullValidator ],
|
||||
commentDelay: [ '', Validators.nullValidator ],
|
||||
pageSize: [ '', Validators.nullValidator ],
|
||||
username: [{ disabled: true }, Validators.nullValidator],
|
||||
email: ['', Validators.nullValidator],
|
||||
about: ['', Validators.nullValidator],
|
||||
gravity: ['', Validators.nullValidator],
|
||||
entryDelay: ['', Validators.nullValidator],
|
||||
commentDelay: ['', Validators.nullValidator],
|
||||
pageSize: ['', 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.userService.get().subscribe({
|
||||
next: (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.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);
|
||||
});
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe({
|
||||
next: (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);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -62,7 +66,7 @@ export class PageSettings implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
hasError(controlName: string): boolean {
|
||||
return this.form.controls[ controlName ].errors != null;
|
||||
return this.form.controls[controlName].errors != null;
|
||||
}
|
||||
|
||||
resetGravity(): void {
|
||||
@@ -124,25 +128,28 @@ export class PageSettings implements OnInit, OnDestroy {
|
||||
this.user.settings.pageSize = this.form.get('pageSize').value;
|
||||
}
|
||||
|
||||
this.userService.update(this.user).subscribe((data) => {
|
||||
this.user = data;
|
||||
if (!this.user.settings) {
|
||||
this.user.settings = {};
|
||||
}
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
this.settingsService.getSettings();
|
||||
}, (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[ code.field ] = errors[ code.field ] || {};
|
||||
errors[ code.field ][ code.code ] = true;
|
||||
this.userService.update(this.user).subscribe({
|
||||
next: (data) => {
|
||||
this.user = data;
|
||||
if (!this.user.settings) {
|
||||
this.user.settings = {};
|
||||
}
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
this.settingsService.getSettings();
|
||||
},
|
||||
error: (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[code.field] = errors[code.field] || {};
|
||||
errors[code.field][code.code] = true;
|
||||
}
|
||||
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[ code ]);
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[code]);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Router, ActivatedRoute } from '@angular/router';
|
||||
@Component({
|
||||
selector: 'page-unavailable',
|
||||
templateUrl: './unavailable.page.html',
|
||||
styleUrls: [ './unavailable.page.scss' ]
|
||||
styleUrls: ['./unavailable.page.scss']
|
||||
})
|
||||
export class PageUnavailable implements OnInit {
|
||||
|
||||
@@ -17,10 +17,12 @@ export class PageUnavailable implements OnInit {
|
||||
private route: ActivatedRoute) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.queryParams.subscribe(params => {
|
||||
if (params[ 'target' ]) {
|
||||
this.targetRoute = params[ 'target' ];
|
||||
this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge', skipLocationChange: true });
|
||||
this.route.queryParams.subscribe({
|
||||
next: (params) => {
|
||||
if (params['target']) {
|
||||
this.targetRoute = params['target'];
|
||||
this.router.navigate([], { queryParams: { target: null }, queryParamsHandling: 'merge', skipLocationChange: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -30,7 +32,7 @@ export class PageUnavailable implements OnInit {
|
||||
if (!this.targetRoute || this.targetRoute === "unavailable" || this.targetRoute === "/unavailable") {
|
||||
this.location.back;
|
||||
} else {
|
||||
this.router.navigate([ this.targetRoute ]);
|
||||
this.router.navigate([this.targetRoute]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { UserService } from '../../services/user.service';
|
||||
@Component({
|
||||
selector: 'page-user',
|
||||
templateUrl: './user.page.html',
|
||||
styleUrls: [ './user.page.scss' ]
|
||||
styleUrls: ['./user.page.scss']
|
||||
})
|
||||
export class PageUser implements OnInit {
|
||||
|
||||
@@ -21,11 +21,14 @@ export class PageUser implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.username = this.route.snapshot.paramMap.get('username');
|
||||
this.userService.getUser(this.username).subscribe((data) => {
|
||||
this.user = data;
|
||||
}, (error) => {
|
||||
if (error.status == 422) {
|
||||
this.notfound = true;
|
||||
this.userService.getUser(this.username).subscribe({
|
||||
next: (data) => {
|
||||
this.user = data;
|
||||
},
|
||||
error: (error) => {
|
||||
if (error.status == 422) {
|
||||
this.notfound = true;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { SettingsService } from '../../../services/settings.service';
|
||||
@Component({
|
||||
selector: 'page-usercomments',
|
||||
templateUrl: './usercomments.page.html',
|
||||
styleUrls: [ './usercomments.page.scss' ]
|
||||
styleUrls: ['./usercomments.page.scss']
|
||||
})
|
||||
export class PageUserComments implements OnInit, OnDestroy {
|
||||
|
||||
@@ -17,18 +17,22 @@ export class PageUserComments implements OnInit, OnDestroy {
|
||||
username: string;
|
||||
comments: any = {};
|
||||
init: boolean = true;
|
||||
ignore: string[] = [ "author" ];
|
||||
ignore: string[] = ["author"];
|
||||
settingsSubscription: Subscription;
|
||||
|
||||
constructor(private settingsService: SettingsService, private commentService: CommentService, private router: Router, private route: ActivatedRoute) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.username = this.route.snapshot.paramMap.get('username');
|
||||
this.settingsSubscription = 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) => { })
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe({
|
||||
next: (settings) => {
|
||||
this.settings = settings;
|
||||
this.commentService.getByUser(this.username, this.comments.number || 0, this.comments.size || this.settings.pageSize, this.ignore).subscribe({
|
||||
next: (data: any) => {
|
||||
this.comments = data;
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -38,12 +42,14 @@ export class PageUserComments implements OnInit, OnDestroy {
|
||||
|
||||
showMore() {
|
||||
const oldContent: any[] = this.comments.content;
|
||||
this.commentService.getByUser(this.username, this.comments.number + 1, this.comments.size, this.ignore).subscribe((data) => {
|
||||
this.comments = data;
|
||||
for (let comment of this.comments.content) {
|
||||
oldContent.push(comment);
|
||||
this.commentService.getByUser(this.username, this.comments.number + 1, this.comments.size, this.ignore).subscribe({
|
||||
next: (data) => {
|
||||
this.comments = data;
|
||||
for (let comment of this.comments.content) {
|
||||
oldContent.push(comment);
|
||||
}
|
||||
this.comments.content = oldContent;
|
||||
}
|
||||
this.comments.content = oldContent;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
</mat-card-content>
|
||||
<mat-card-actions class="flex wrap fill">
|
||||
<button *ngIf="!working" mat-raised-button color="primary" [disabled]="form.invalid">
|
||||
<button type="submit" *ngIf="!working" mat-raised-button color="primary" [disabled]="form.invalid">
|
||||
<mat-icon>save</mat-icon> {{ (view.id ? 'views.update' : 'views.create') | i18n}}
|
||||
</button>
|
||||
<a mat-button color="primary" routerLink="/v/{{view.name}}" *ngIf="view.id">{{ 'views.goTo' |
|
||||
|
||||
@@ -13,16 +13,16 @@ import { MatDialog } from '@angular/material/dialog';
|
||||
@Component({
|
||||
selector: 'page-view-edit',
|
||||
templateUrl: './edit.page.html',
|
||||
styleUrls: [ './edit.page.scss' ]
|
||||
styleUrls: ['./edit.page.scss']
|
||||
})
|
||||
export class PageViewEdit implements OnInit, OnDestroy {
|
||||
|
||||
name: string;
|
||||
view: any;
|
||||
entryTypes: string[] = [ undefined, 'LINK', 'DISCUSSION', 'QUESTION', 'INTERN' ];
|
||||
entryType: string = this.entryTypes[ 0 ];
|
||||
sortings: string[] = [ 'NEW', 'TOP', 'HOT', 'LAST' ];
|
||||
sorting: string = this.sortings[ 0 ];
|
||||
entryTypes: string[] = [undefined, 'LINK', 'DISCUSSION', 'QUESTION', 'INTERN'];
|
||||
entryType: string = this.entryTypes[0];
|
||||
sortings: string[] = ['NEW', 'TOP', 'HOT', 'LAST'];
|
||||
sorting: string = this.sortings[0];
|
||||
notfound: boolean = false;
|
||||
working: boolean = false;
|
||||
form: FormGroup;
|
||||
@@ -44,34 +44,44 @@ export class PageViewEdit implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = this.formBuilder.group({
|
||||
name: [ '', Validators.required ],
|
||||
entryType: [ '', Validators.nullValidator ],
|
||||
sorting: [ '', Validators.required ],
|
||||
index: [ '', Validators.required ],
|
||||
name: ['', Validators.required],
|
||||
entryType: ['', Validators.nullValidator],
|
||||
sorting: ['', Validators.required],
|
||||
index: ['', Validators.required],
|
||||
});
|
||||
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe((settings) => {
|
||||
this.settings = settings;
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe({
|
||||
next: (settings) => {
|
||||
this.settings = settings;
|
||||
}
|
||||
});
|
||||
|
||||
this.route.params.subscribe((params) => {
|
||||
if (params.name) {
|
||||
this.form.get('name').setValue(params.name);
|
||||
this.route.params.subscribe({
|
||||
next: (params) => {
|
||||
if (params.name) {
|
||||
this.form.get('name').setValue(params.name);
|
||||
|
||||
this.form.get('entryType').setValue(this.entryType);
|
||||
this.form.get('entryType').valueChanges.subscribe((value) => {
|
||||
this.entryType = value;
|
||||
});
|
||||
this.form.get('sorting').setValue(this.sorting);
|
||||
this.form.get('sorting').valueChanges.subscribe((value) => {
|
||||
this.sorting = value;
|
||||
});
|
||||
this.form.get('index').valueChanges.subscribe((value) => {
|
||||
this.view.index = value;
|
||||
});
|
||||
this.form.get('entryType').setValue(this.entryType);
|
||||
this.form.get('entryType').valueChanges.subscribe({
|
||||
next: (value) => {
|
||||
this.entryType = value;
|
||||
}
|
||||
});
|
||||
this.form.get('sorting').setValue(this.sorting);
|
||||
this.form.get('sorting').valueChanges.subscribe({
|
||||
next: (value) => {
|
||||
this.sorting = value;
|
||||
}
|
||||
});
|
||||
this.form.get('index').valueChanges.subscribe({
|
||||
next: (value) => {
|
||||
this.view.index = value;
|
||||
}
|
||||
});
|
||||
|
||||
this.name = params.name;
|
||||
this.refresh();
|
||||
this.name = params.name;
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -84,17 +94,20 @@ export class PageViewEdit implements OnInit, OnDestroy {
|
||||
|
||||
refresh() {
|
||||
if (this.name) {
|
||||
this.viewService.getView(this.name, undefined).subscribe((data) => {
|
||||
this.view = data;
|
||||
this.entryType = this.view.entryType;
|
||||
this.sorting = this.view.sorting;
|
||||
this.form.get("name").setValue(this.view.name);
|
||||
this.form.get("entryType").setValue(this.view.entryType);
|
||||
this.form.get("sorting").setValue(this.view.sorting);
|
||||
this.form.get("index").setValue(this.view.index);
|
||||
}, (error) => {
|
||||
if (error.status == 404) {
|
||||
this.notfound = true;
|
||||
this.viewService.getView(this.name, undefined).subscribe({
|
||||
next: (data) => {
|
||||
this.view = data;
|
||||
this.entryType = this.view.entryType;
|
||||
this.sorting = this.view.sorting;
|
||||
this.form.get("name").setValue(this.view.name);
|
||||
this.form.get("entryType").setValue(this.view.entryType);
|
||||
this.form.get("sorting").setValue(this.view.sorting);
|
||||
this.form.get("index").setValue(this.view.index);
|
||||
},
|
||||
error: (error) => {
|
||||
if (error.status == 404) {
|
||||
this.notfound = true;
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
@@ -111,7 +124,7 @@ export class PageViewEdit implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
hasError(controlName: string): boolean {
|
||||
return this.form.controls[ controlName ].errors != null;
|
||||
return this.form.controls[controlName].errors != null;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,28 +140,31 @@ export class PageViewEdit implements OnInit, OnDestroy {
|
||||
this.view.sorting = this.sorting;
|
||||
this.view.index = this.form.get("index").value;
|
||||
|
||||
this.viewService.createOrUpdate(this.view).subscribe((data) => {
|
||||
this.view = data;
|
||||
this.working = false;
|
||||
this.snackBar.open(this.i18n.get('views.success', []), this.i18n.get("close", []), {
|
||||
duration: 3000
|
||||
});
|
||||
this.router.navigateByUrl('/v/' + this.view.name);
|
||||
this.viewService.getViews();
|
||||
}, (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 403) {
|
||||
this.snackBar.open("Error");
|
||||
}
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[ code.field ] = errors[ code.field ] || {};
|
||||
errors[ code.field ][ code.code ] = true;
|
||||
this.viewService.createOrUpdate(this.view).subscribe({
|
||||
next: (data) => {
|
||||
this.view = data;
|
||||
this.working = false;
|
||||
this.snackBar.open(this.i18n.get('views.success', []), this.i18n.get("close", []), {
|
||||
duration: 3000
|
||||
});
|
||||
this.router.navigateByUrl('/v/' + this.view.name);
|
||||
this.viewService.getViews();
|
||||
},
|
||||
error: (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 403) {
|
||||
this.snackBar.open("Error");
|
||||
}
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[code.field] = errors[code.field] || {};
|
||||
errors[code.field][code.code] = true;
|
||||
}
|
||||
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[ code ]);
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[code]);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -158,18 +174,22 @@ export class PageViewEdit implements OnInit, OnDestroy {
|
||||
const dialogRef = this.dialog.open(ConfirmDialog, {
|
||||
data: {
|
||||
'label': 'views.confirmDelete',
|
||||
'args': [ this.view.name ]
|
||||
'args': [this.view.name]
|
||||
}
|
||||
})
|
||||
|
||||
dialogRef.afterClosed().subscribe(result => {
|
||||
if (result) {
|
||||
this.working = true;
|
||||
this.viewService.deleteView(this.view.name).subscribe(() => {
|
||||
this.working = false;
|
||||
this.router.navigateByUrl('/');
|
||||
this.viewService.getViews();
|
||||
})
|
||||
dialogRef.afterClosed().subscribe({
|
||||
next: (result) => {
|
||||
if (result) {
|
||||
this.working = true;
|
||||
this.viewService.deleteView(this.view.name).subscribe({
|
||||
next: () => {
|
||||
this.working = false;
|
||||
this.router.navigateByUrl('/');
|
||||
this.viewService.getViews();
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { PageEntries } from '../entries/entries.page';
|
||||
@Component({
|
||||
selector: 'page-view',
|
||||
templateUrl: './view.page.html',
|
||||
styleUrls: [ './view.page.scss' ]
|
||||
styleUrls: ['./view.page.scss']
|
||||
})
|
||||
export class PageView implements OnInit, OnDestroy {
|
||||
|
||||
@@ -27,27 +27,32 @@ export class PageView implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.paramsSub = this.route.params.subscribe((params: Params) => {
|
||||
this.name = params[ 'name' ];
|
||||
this.username = params[ 'username' ];
|
||||
this.paramsSub = this.route.params.subscribe({
|
||||
next: (params: Params) => {
|
||||
this.name = params['name'];
|
||||
this.username = params['username'];
|
||||
|
||||
if (!this.name) {
|
||||
this.viewService.getViews().then((data: any) => {
|
||||
const views = data.content;
|
||||
if (!views || views.length == 0) {
|
||||
this.router.navigate([ '/v' ], { queryParams: { name: this.name }, queryParamsHandling: 'merge' });
|
||||
} else {
|
||||
this.router.navigateByUrl('/v/' + views[ 0 ].name);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.viewService.getView(this.name, this.username).subscribe((data) => {
|
||||
if (this.entries) {
|
||||
this.entries.refresh();
|
||||
}
|
||||
}, (error) => {
|
||||
this.router.navigate([ '/v' ], { queryParams: { name: this.name }, queryParamsHandling: 'merge' });
|
||||
})
|
||||
if (!this.name) {
|
||||
this.viewService.getViews().then((data: any) => {
|
||||
const views = data.content;
|
||||
if (!views || views.length == 0) {
|
||||
this.router.navigate(['/v'], { queryParams: { name: this.name }, queryParamsHandling: 'merge' });
|
||||
} else {
|
||||
this.router.navigateByUrl('/v/' + views[0].name);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.viewService.getView(this.name, this.username).subscribe({
|
||||
next: (data) => {
|
||||
if (this.entries) {
|
||||
this.entries.refresh();
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
this.router.navigate(['/v'], { queryParams: { name: this.name }, queryParamsHandling: 'merge' });
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
this.boundFetch = this.fetch.bind(this);
|
||||
|
||||
Reference in New Issue
Block a user