change userpages to views

This commit is contained in:
2021-12-04 00:16:46 +01:00
parent e7083fff11
commit 161f68aa37
16 changed files with 135 additions and 135 deletions
@@ -1,21 +1,21 @@
<div class="container">
<mat-progress-bar *ngIf="!userpage" mode="indeterminate"></mat-progress-bar>
<form [formGroup]="form" (ngSubmit)="save()" #formDirective="ngForm" *ngIf="userpage && settings">
<mat-progress-bar *ngIf="!view" mode="indeterminate"></mat-progress-bar>
<form [formGroup]="form" (ngSubmit)="save()" #formDirective="ngForm" *ngIf="view && settings">
<mat-card>
<mat-card-content>
<p>{{ (userpage.id ? 'userpages.edit' : 'userpages.create') | i18n}}</p>
<p>{{ (view.id ? 'views.edit' : 'views.create') | i18n}}</p>
<mat-form-field>
<input matInput placeholder="{{'userpages.name' | i18n}}" formControlName="name" matAutofocus>
<input matInput placeholder="{{'views.name' | i18n}}" formControlName="name" matAutofocus>
<mat-error *ngIf="hasError('name')">
<div *ngFor="let error of form.get('name').errors | keyvalue">
{{'userpages.name.error.' + error.key | i18n}}<br>
{{'views.name.error.' + error.key | i18n}}<br>
</div>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-select placeholder="{{'userpages.sorting' | i18n}}" formControlName="sorting">
<mat-select placeholder="{{'views.sorting' | i18n}}" formControlName="sorting">
<mat-select-trigger>
<mat-icon>{{'sorting.' + sorting + '.icon' | i18n}}</mat-icon> {{'sorting.' + sorting | i18n}}
</mat-select-trigger>
@@ -25,14 +25,14 @@
</mat-select>
</mat-form-field>
<ui-tagspicker [(model)]="userpage.tags" placeholder="{{'userpages.tags' | i18n}}">
<ui-tagspicker [(model)]="view.tags" placeholder="{{'views.tags' | i18n}}">
</ui-tagspicker>
<ui-tagspicker [(model)]="userpage.excludedTags" placeholder="{{'userpages.excludedTags' | i18n}}">
<ui-tagspicker [(model)]="view.excludedTags" placeholder="{{'views.excludedTags' | i18n}}">
</ui-tagspicker>
<mat-form-field>
<mat-select placeholder="{{'userpages.entryType' | i18n}}" formControlName="entryType">
<mat-select placeholder="{{'views.entryType' | i18n}}" formControlName="entryType">
<mat-select-trigger>
<span *ngIf="entryType">
<mat-icon>{{'entryType.' + entryType + '.icon' | i18n}}</mat-icon> {{'entryType.' +
@@ -51,30 +51,30 @@
</mat-form-field>
<mat-form-field>
<input matInput placeholder="{{'userpages.index' | i18n}}" formControlName="index" type="number" min="0">
<input matInput placeholder="{{'views.index' | i18n}}" formControlName="index" type="number" min="0">
<mat-error *ngIf="hasError('index')">
<div *ngFor="let error of form.get('index').errors | keyvalue">
{{'userpages.index.error.' + error.key | i18n}}<br>
{{'views.index.error.' + error.key | i18n}}<br>
</div>
</mat-error>
</mat-form-field>
<section>
<mat-checkbox [checked]="userpage.divider" (change)="userpage.divider = $event.checked">{{'userpages.divider'
<mat-checkbox [checked]="view.divider" (change)="view.divider = $event.checked">{{'views.divider'
| i18n}}</mat-checkbox>
</section>
</mat-card-content>
<mat-card-actions fxLayout="row wrap" fxFlexFill>
<button *ngIf="!working" mat-raised-button color="primary" [disabled]="form.invalid">
<mat-icon>save</mat-icon> {{ (userpage.id ? 'userpages.update' : 'userpages.create') | i18n}}
<mat-icon>save</mat-icon> {{ (view.id ? 'views.update' : 'views.create') | i18n}}
</button>
<a mat-button color="primary" routerLink="/p/{{userpage.name}}" *ngIf="userpage.id">{{ 'userpages.goTo' |
<a mat-button color="primary" routerLink="/p/{{view.name}}" *ngIf="view.id">{{ 'views.goTo' |
i18n}}</a>
<span fxFlexOffset="auto" fxFlexOffset.xs="none"></span>
<a mat-raised-button color="warn" *ngIf="!working && userpage.id" (click)="deleteUserPage()">
<a mat-raised-button color="warn" *ngIf="!working && view.id" (click)="deleteView()">
<mat-icon>delete</mat-icon> {{
'userpages.delete' |
'views.delete' |
i18n}}
</a>
</mat-card-actions>
@@ -5,20 +5,20 @@ import { MatSnackBar } from '@angular/material/snack-bar';
import { TagsService } from 'src/app/services/tags.service';
import { SettingsService } from 'src/app/services/settings.service';
import { Subscription } from 'rxjs';
import { UserPageService } from 'src/app/services/userpage.service';
import { ViewService } from 'src/app/services/view.service';
import { I18nService } from 'src/app/services/i18n.service';
import { ConfirmDialog } from 'src/app/ui/confirm/confirm.component';
import { MatDialog } from '@angular/material/dialog';
@Component({
selector: 'page-userpage-edit',
selector: 'page-view-edit',
templateUrl: './edit.page.html',
styleUrls: [ './edit.page.scss' ]
})
export class PageUserPageEdit implements OnInit, OnDestroy {
export class PageViewEdit implements OnInit, OnDestroy {
name: string;
userpage: any;
view: any;
entryTypes: string[] = [ undefined, 'LINK', 'DISCUSSION', 'QUESTION', 'INTERN' ];
entryType: string = this.entryTypes[ 0 ];
sortings: string[] = [ 'NEW', 'TOP', 'HOT', 'LAST' ];
@@ -30,7 +30,7 @@ export class PageUserPageEdit implements OnInit, OnDestroy {
settingsSubscription: Subscription;
constructor(private userPageService: UserPageService,
constructor(private viewService: ViewService,
private tagsService: TagsService,
private settingsService: SettingsService,
private formBuilder: FormBuilder,
@@ -65,7 +65,7 @@ export class PageUserPageEdit implements OnInit, OnDestroy {
this.sorting = value;
});
this.form.get('index').valueChanges.subscribe((value) => {
this.userpage.index = value;
this.view.index = value;
});
this.name = this.route.snapshot.paramMap.get('name');
@@ -78,30 +78,30 @@ export class PageUserPageEdit implements OnInit, OnDestroy {
refresh() {
if (this.name) {
this.userPageService.getUserPage(this.name, undefined).subscribe((data) => {
this.userpage = data;
this.entryType = this.userpage.entryType;
this.sorting = this.userpage.sorting;
this.form.get("name").setValue(this.userpage.name);
this.form.get("entryType").setValue(this.userpage.entryType);
this.form.get("sorting").setValue(this.userpage.sorting);
this.form.get("index").setValue(this.userpage.index);
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;
}
})
} else {
this.userpage = {};
this.userpage.entryType = this.entryType;
this.userpage.sorting = this.sorting;
this.userpage.tags = [];
this.userpage.excludedTags = [];
this.userpage.index = 99;
this.form.get("name").setValue(this.userpage.name);
this.form.get("entryType").setValue(this.userpage.entryType);
this.form.get("sorting").setValue(this.userpage.sorting);
this.form.get("index").setValue(this.userpage.index);
this.view = {};
this.view.entryType = this.entryType;
this.view.sorting = this.sorting;
this.view.tags = [];
this.view.excludedTags = [];
this.view.index = 99;
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);
}
}
@@ -117,19 +117,19 @@ export class PageUserPageEdit implements OnInit, OnDestroy {
this.working = true;
this.userpage.name = this.form.get("name").value;
this.userpage.entryType = this.entryType;
this.userpage.sorting = this.sorting;
this.userpage.index = this.form.get("index").value;
this.view.name = this.form.get("name").value;
this.view.entryType = this.entryType;
this.view.sorting = this.sorting;
this.view.index = this.form.get("index").value;
this.userPageService.createOrUpdate(this.userpage).subscribe((data) => {
this.userpage = data;
this.viewService.createOrUpdate(this.view).subscribe((data) => {
this.view = data;
this.working = false;
this.snackBar.open(this.i18n.get('userpages.success', []), this.i18n.get("close", []), {
this.snackBar.open(this.i18n.get('views.success', []), this.i18n.get("close", []), {
duration: 3000
});
this.router.navigateByUrl('/p/' + this.userpage.name);
this.userPageService.getUserPages();
this.router.navigateByUrl('/p/' + this.view.name);
this.viewService.getViews();
}, (error) => {
this.working = false;
if (error.status == 403) {
@@ -149,21 +149,21 @@ export class PageUserPageEdit implements OnInit, OnDestroy {
})
}
deleteUserPage() {
deleteView() {
const dialogRef = this.dialog.open(ConfirmDialog, {
data: {
'label': 'userpages.confirmDelete',
'args': [ this.userpage.name ]
'label': 'views.confirmDelete',
'args': [ this.view.name ]
}
})
dialogRef.afterClosed().subscribe(result => {
if (result) {
this.working = true;
this.userPageService.deleteUserPage(this.userpage.name).subscribe(() => {
this.viewService.deleteView(this.view.name).subscribe(() => {
this.working = false;
this.router.navigateByUrl('/');
this.userPageService.getUserPages();
this.viewService.getViews();
})
}
});
@@ -1,5 +1,5 @@
<div fxLayout="column" fxFlexFill>
<a mat-mini-fab routerLink="/p/{{name}}/edit" matTooltip="{{'userpages.edit' | i18n}}" color="primary">
<a mat-mini-fab routerLink="/p/{{name}}/edit" matTooltip="{{'views.edit' | i18n}}" color="primary">
<mat-icon inline="true">edit</mat-icon>
</a>
<page-entries #entries [fetch]="boundFetch" fxFlex="grow"></page-entries>
@@ -1,17 +1,17 @@
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Subscription } from 'rxjs';
import { UserPageService } from 'src/app/services/userpage.service';
import { ViewService } from 'src/app/services/view.service';
import { EntriesService } from '../../services/entries.service';
import { PageEntries } from '../entries/entries.page';
@Component({
selector: 'page-userpage',
templateUrl: './userpage.page.html',
styleUrls: [ './userpage.page.scss' ]
selector: 'page-view',
templateUrl: './view.page.html',
styleUrls: [ './view.page.scss' ]
})
export class PageUserPage implements OnInit, OnDestroy {
export class PageView implements OnInit, OnDestroy {
boundFetch: Function;
name: string;
@@ -21,7 +21,7 @@ export class PageUserPage implements OnInit, OnDestroy {
constructor(
private entriesService: EntriesService,
private userPageService: UserPageService,
private viewService: ViewService,
private router: Router,
private route: ActivatedRoute) {
}
@@ -31,7 +31,7 @@ export class PageUserPage implements OnInit, OnDestroy {
this.name = params[ 'name' ];
this.username = params[ 'username' ];
this.userPageService.getUserPage(this.name, this.username).subscribe((data) => {
this.viewService.getView(this.name, this.username).subscribe((data) => {
if (this.entries) {
this.entries.refresh();
}
@@ -53,7 +53,7 @@ export class PageUserPage implements OnInit, OnDestroy {
filter.username = this.username;
}
return this.entriesService.getByUserPage(this.name, page, size, asc, filter);
return this.entriesService.getByView(this.name, page, size, asc, filter);
}
}