change userpages to views

This commit is contained in:
_Bastler 2021-12-04 00:16:46 +01:00
parent e7083fff11
commit 161f68aa37
16 changed files with 135 additions and 135 deletions

View File

@ -17,8 +17,8 @@ import { PageUser } from './pages/user/user.page';
import { PageUserComments } from './pages/user/usercomments/usercomments.page';
import { PageUserEntries } from './pages/user/userentries/userentries.page';
import { PageUserPageEdit } from './pages/userpage/edit/edit.page';
import { PageUserPage } from './pages/userpage/userpage.page';
import { PageViewEdit } from './pages/view/edit/edit.page';
import { PageView } from './pages/view/view.page';
import { UiMain } from './ui/main/main.ui';
@ -40,10 +40,10 @@ const routes: Routes = [
{ path: 'u/c/:username', component: PageUserComments, canActivate: [ AuthenticatedGuard ] },
{ path: 'u/e/:username', component: PageUserEntries, canActivate: [ AuthenticatedGuard ] },
{ path: 'unavailable', component: PageUnavailable },
{ path: 'p', component: PageUserPageEdit, canActivate: [ AuthenticatedGuard ] },
{ path: 'p/:name', component: PageUserPage, canActivate: [ AuthenticatedGuard ] },
{ path: 'p/:name/edit', component: PageUserPageEdit, canActivate: [ AuthenticatedGuard ] },
{ path: 'p/:name/:username', component: PageUserPage, canActivate: [ AuthenticatedGuard ] },
{ path: 'p', component: PageViewEdit, canActivate: [ AuthenticatedGuard ] },
{ path: 'p/:name', component: PageView, canActivate: [ AuthenticatedGuard ] },
{ path: 'p/:name/edit', component: PageViewEdit, canActivate: [ AuthenticatedGuard ] },
{ path: 'p/:name/:username', component: PageView, canActivate: [ AuthenticatedGuard ] },
{ path: '**', component: PageNotFound, pathMatch: 'full', canActivate: [ AuthUpdateGuard ] },
]
},

View File

@ -45,9 +45,9 @@ import { I18nService, I18nPaginatorIntl } from './services/i18n.service';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
import { UiTagsPicker } from './ui/tags/tagspicker.ui';
import { UiUserPageMenu } from './ui/userpagemenu/userpagemenu.ui';
import { PageUserPage } from './pages/userpage/userpage.page';
import { PageUserPageEdit } from './pages/userpage/edit/edit.page';
import { UiViewMenu } from './ui/viewmenu/viewmenu.ui';
import { PageView } from './pages/view/view.page';
import { PageViewEdit } from './pages/view/edit/edit.page';
import { PageSearch } from './pages/search/search.page';
@ -99,8 +99,8 @@ export class XhrInterceptor implements HttpInterceptor {
PageSettings,
PageUnavailable,
PageUser, PageUserComments, PageUserEntries,
PageUserPage,
PageUserPageEdit,
PageView,
PageViewEdit,
UiComment,
UiCommentCount,
UiCommentForm,
@ -110,7 +110,7 @@ export class XhrInterceptor implements HttpInterceptor {
UiMain,
UiPoints,
UiTagsPicker,
UiUserPageMenu,
UiViewMenu,
ConfirmDialog
],
imports: [

View File

@ -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>

View File

@ -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();
})
}
});

View File

@ -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>

View File

@ -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);
}
}

View File

@ -34,7 +34,7 @@ export class EntriesService {
return this.http.get(environment.apiUrl + "/entries" + path, { params: httpParams });
}
getByUserPage(name: string, page: number, size: number, asc: boolean, filter: any) {
getByView(name: string, page: number, size: number, asc: boolean, filter: any) {
return this.fetch("/" + name, page, size, asc, filter);
}

View File

@ -7,23 +7,23 @@ import { RequestError } from './requesterror';
@Injectable({
providedIn: 'root',
})
export class UserPageService {
export class ViewService {
userPages: ReplaySubject<any> = new ReplaySubject(1);
views: ReplaySubject<any> = new ReplaySubject(1);
constructor(private http: HttpClient) {
}
getUserPages() {
return this.http.get(environment.apiUrl + "/userpages").toPromise().then((data: any) => {
this.userPages.next(data);
getViews() {
return this.http.get(environment.apiUrl + "/views").toPromise().then((data: any) => {
this.views.next(data);
return data;
}, error => {
throw new RequestError(error);
});;
}
getPublicUserPages(page: number, size: number, desc: boolean) {
getPublicViews(page: number, size: number, desc: boolean) {
let httpParams = new HttpParams();
if (page != undefined) {
httpParams = httpParams.set("page", "" + page);
@ -35,24 +35,24 @@ export class UserPageService {
httpParams = httpParams.set("desc", "" + desc);
}
return this.http.get(environment.apiUrl + "/userpages/public", { params: httpParams });
return this.http.get(environment.apiUrl + "/views/public", { params: httpParams });
}
getUserPage(name: string, username: string) {
getView(name: string, username: string) {
let httpParams = new HttpParams();
if (username != undefined) {
httpParams = httpParams.set("user", "" + username);
}
return this.http.get(environment.apiUrl + "/userpages/userpage/" + name, { params: httpParams });
return this.http.get(environment.apiUrl + "/views/view/" + name, { params: httpParams });
}
createOrUpdate(userPage: any) {
return this.http.post(environment.apiUrl + "/userpages/userpage", userPage);
createOrUpdate(view: any) {
return this.http.post(environment.apiUrl + "/views/view", view);
}
deleteUserPage(name: string) {
return this.http.delete(environment.apiUrl + "/userpages/userpage/" + name);
deleteView(name: string) {
return this.http.delete(environment.apiUrl + "/views/view/" + name);
}
}

View File

@ -42,7 +42,7 @@
<mat-sidenav #sidenav [mode]="isBiggerScreen() ? 'side' : 'over'" [(opened)]="opened"
(click)="!isBiggerScreen() && opened=false">
<mat-nav-list>
<ui-userpagemenu *ngIf="authenticated"></ui-userpagemenu>
<ui-viewmenu *ngIf="authenticated"></ui-viewmenu>
<mat-divider *ngIf="moderator"></mat-divider>
<a *ngIf="moderator" routerLink="/moderation/entries" routerLinkActive="active" mat-list-item>
<mat-icon>report</mat-icon> {{'moderation.entries' | i18n}}

View File

@ -1,13 +0,0 @@
<ng-container *ngIf="settings">
<ng-container *ngFor="let userpage of userpages">
<mat-divider *ngIf="userpage.divider"></mat-divider>
<a routerLink="/p/{{userpage.name}}" routerLinkActive="active" mat-list-item>
<mat-icon>{{'sorting.' + userpage.sorting + '.icon' | i18n}}</mat-icon> {{'sorting.' + userpage.name | i18nEmpty}}
</a>
</ng-container>
<mat-divider></mat-divider>
<a *ngIf="userpages.length < settings.maxUserPages" routerLink="/p" routerLinkActive="active" mat-list-item
title="{{'userpages.add' | i18n}}">
<mat-icon style="margin: 0 auto;">add</mat-icon>
</a>
</ng-container>

View File

@ -1,32 +0,0 @@
import { Component, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { SettingsService } from 'src/app/services/settings.service';
import { UserPageService } from 'src/app/services/userpage.service';
@Component({
selector: 'ui-userpagemenu',
templateUrl: 'userpagemenu.ui.html',
styleUrls: [ './userpagemenu.ui.scss' ]
})
export class UiUserPageMenu implements OnInit {
userpages: any[] = [];
settings: any;
settingsSubscription: Subscription;
constructor(private userPageService: UserPageService, private settingsService: SettingsService) {
}
ngOnInit(): void {
this.settingsSubscription = this.settingsService.settings.subscribe((settings) => {
this.settings = settings;
this.userPageService.userPages.subscribe((data: any) => {
this.userpages = data.content;
})
this.userPageService.getUserPages();
})
}
}

View File

@ -0,0 +1,13 @@
<ng-container *ngIf="settings">
<ng-container *ngFor="let view of views">
<mat-divider *ngIf="view.divider"></mat-divider>
<a routerLink="/p/{{view.name}}" routerLinkActive="active" mat-list-item>
<mat-icon>{{'sorting.' + view.sorting + '.icon' | i18n}}</mat-icon> {{'sorting.' + view.name | i18nEmpty}}
</a>
</ng-container>
<mat-divider></mat-divider>
<a *ngIf="views.length < settings.maxViews" routerLink="/p" routerLinkActive="active" mat-list-item
title="{{'views.add' | i18n}}">
<mat-icon style="margin: 0 auto;">add</mat-icon>
</a>
</ng-container>

View File

@ -0,0 +1,32 @@
import { Component, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { SettingsService } from 'src/app/services/settings.service';
import { ViewService } from 'src/app/services/view.service';
@Component({
selector: 'ui-viewmenu',
templateUrl: 'viewmenu.ui.html',
styleUrls: [ './viewmenu.ui.scss' ]
})
export class UiViewMenu implements OnInit {
views: any[] = [];
settings: any;
settingsSubscription: Subscription;
constructor(private viewService: ViewService, private settingsService: SettingsService) {
}
ngOnInit(): void {
this.settingsSubscription = this.settingsService.settings.subscribe((settings) => {
this.settings = settings;
this.viewService.views.subscribe((data: any) => {
this.views = data.content;
})
this.viewService.getViews();
})
}
}