From df067fd3cbbd889c2dc065e59b7caca731ed744e Mon Sep 17 00:00:00 2001 From: _Bastler Date: Sat, 4 Dec 2021 10:56:57 +0100 Subject: [PATCH] fix views --- src/app/app-routing.module.ts | 4 +-- src/app/material/autofocus.ts | 1 - src/app/pages/bookmarks/bookmarks.page.ts | 4 +-- src/app/pages/comment/comment.page.ts | 5 ++-- .../comments/moderation.comments.page.ts | 1 - src/app/pages/search/search.page.ts | 2 +- src/app/pages/user/user.page.ts | 2 +- .../user/usercomments/usercomments.page.ts | 2 +- src/app/pages/view/edit/edit.page.ts | 4 +-- src/app/pages/view/view.page.html | 2 +- src/app/pages/view/view.page.ts | 25 +++++++++++++------ src/app/services/requesterror.ts | 1 - src/app/services/settings.service.ts | 2 +- src/app/services/tags.service.ts | 2 +- src/app/services/user.service.ts | 3 +-- src/app/ui/comment/comment.ui.ts | 2 +- src/app/ui/comments/comments.ui.ts | 1 - src/app/ui/entries/entries.ui.ts | 2 +- src/app/ui/entry/entry.ui.ts | 2 +- src/app/ui/main/main.ui.ts | 3 +-- src/app/ui/tags/tagspicker.ui.ts | 1 - 21 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a6c362d..2f294f5 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,7 +1,7 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; -import { AuthGuard, AuthUpdateGuard, AuthenticatedGuard, AnonymousGuard } from './auth/auth.guard'; +import { AuthUpdateGuard, AuthenticatedGuard, AnonymousGuard } from './auth/auth.guard'; import { PageBookmarks } from './pages/bookmarks/bookmarks.page'; import { PageComment } from './pages/comment/comment.page'; import { PageEntryEdit } from './pages/entry/edit/edit.page'; @@ -25,7 +25,7 @@ import { UiMain } from './ui/main/main.ui'; const routes: Routes = [ { path: '', component: UiMain, children: [ - { path: '', redirectTo: "/v/TOP", pathMatch: 'full' }, + { path: '', component: PageView, canActivate: [ AuthenticatedGuard ] }, { path: 'login', component: PageLogin, canActivate: [ AnonymousGuard ] }, { path: 'search', component: PageSearch, canActivate: [ AuthenticatedGuard ] }, { path: 'moderation/comments', component: PageModerationComments, canActivate: [ AuthenticatedGuard ] }, diff --git a/src/app/material/autofocus.ts b/src/app/material/autofocus.ts index 592312e..8290d33 100644 --- a/src/app/material/autofocus.ts +++ b/src/app/material/autofocus.ts @@ -1,5 +1,4 @@ import { Directive, ElementRef, OnInit } from '@angular/core'; -import { MatInput } from '@angular/material/input'; @Directive({ selector: '[matAutofocus]', diff --git a/src/app/pages/bookmarks/bookmarks.page.ts b/src/app/pages/bookmarks/bookmarks.page.ts index 5ed3681..0453181 100644 --- a/src/app/pages/bookmarks/bookmarks.page.ts +++ b/src/app/pages/bookmarks/bookmarks.page.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { BookmarksService } from '../../services/bookmarks.service'; @@ -16,7 +16,7 @@ export class PageBookmarks implements OnInit { } fetch(page: number, size: number) { - return this.bookmarksService.getEntries(page,size); + return this.bookmarksService.getEntries(page, size); } } diff --git a/src/app/pages/comment/comment.page.ts b/src/app/pages/comment/comment.page.ts index 16f275a..c7e1fe9 100644 --- a/src/app/pages/comment/comment.page.ts +++ b/src/app/pages/comment/comment.page.ts @@ -1,9 +1,8 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { CommentService } from '../../services/comment.service'; -import { UiComments } from '../../ui/comments/comments.ui'; @Component({ selector: 'page-comment', @@ -15,7 +14,7 @@ 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) { } diff --git a/src/app/pages/moderation/comments/moderation.comments.page.ts b/src/app/pages/moderation/comments/moderation.comments.page.ts index ec72f89..b9297e3 100644 --- a/src/app/pages/moderation/comments/moderation.comments.page.ts +++ b/src/app/pages/moderation/comments/moderation.comments.page.ts @@ -1,6 +1,5 @@ import { Component, OnInit, Input } from '@angular/core'; -import { Router, ActivatedRoute } from '@angular/router'; import { ModerationService } from '../../../services/moderarion.service'; @Component({ diff --git a/src/app/pages/search/search.page.ts b/src/app/pages/search/search.page.ts index 5524a71..4cebe27 100644 --- a/src/app/pages/search/search.page.ts +++ b/src/app/pages/search/search.page.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { FormControl } from '@angular/forms'; import { PageEvent } from '@angular/material/paginator'; import { ActivatedRoute, Router } from '@angular/router'; diff --git a/src/app/pages/user/user.page.ts b/src/app/pages/user/user.page.ts index 9c1c4ac..c0e277b 100644 --- a/src/app/pages/user/user.page.ts +++ b/src/app/pages/user/user.page.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewChild } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; diff --git a/src/app/pages/user/usercomments/usercomments.page.ts b/src/app/pages/user/usercomments/usercomments.page.ts index 6bc68f2..920bb2c 100644 --- a/src/app/pages/user/usercomments/usercomments.page.ts +++ b/src/app/pages/user/usercomments/usercomments.page.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input, OnDestroy } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { Subscription } from 'rxjs'; diff --git a/src/app/pages/view/edit/edit.page.ts b/src/app/pages/view/edit/edit.page.ts index 68c4da3..a5949cd 100644 --- a/src/app/pages/view/edit/edit.page.ts +++ b/src/app/pages/view/edit/edit.page.ts @@ -1,6 +1,6 @@ -import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router'; -import { FormBuilder, FormGroup, Validators, NgForm } from '@angular/forms'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MatSnackBar } from '@angular/material/snack-bar'; import { TagsService } from 'src/app/services/tags.service'; import { SettingsService } from 'src/app/services/settings.service'; diff --git a/src/app/pages/view/view.page.html b/src/app/pages/view/view.page.html index 3adc92e..a0a5709 100644 --- a/src/app/pages/view/view.page.html +++ b/src/app/pages/view/view.page.html @@ -1,4 +1,4 @@ edit - \ No newline at end of file + \ No newline at end of file diff --git a/src/app/pages/view/view.page.ts b/src/app/pages/view/view.page.ts index 463f1b5..45a30f8 100644 --- a/src/app/pages/view/view.page.ts +++ b/src/app/pages/view/view.page.ts @@ -31,13 +31,24 @@ export class PageView implements OnInit, OnDestroy { this.name = params[ 'name' ]; this.username = params[ 'username' ]; - 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((data) => { + if (this.entries) { + this.entries.refresh(); + } + }, (error) => { + this.router.navigate([ '/v' ], { queryParams: { name: this.name }, queryParamsHandling: 'merge' }); + }) + } }); this.boundFetch = this.fetch.bind(this); } diff --git a/src/app/services/requesterror.ts b/src/app/services/requesterror.ts index 621bb93..2fa43de 100644 --- a/src/app/services/requesterror.ts +++ b/src/app/services/requesterror.ts @@ -1,4 +1,3 @@ - export class RequestError extends Error { response: any; diff --git a/src/app/services/settings.service.ts b/src/app/services/settings.service.ts index 16a6d06..2d5fe46 100644 --- a/src/app/services/settings.service.ts +++ b/src/app/services/settings.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { ReplaySubject, of } from 'rxjs'; +import { ReplaySubject } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { RequestError } from './requesterror'; diff --git a/src/app/services/tags.service.ts b/src/app/services/tags.service.ts index a0b8755..65aedc5 100644 --- a/src/app/services/tags.service.ts +++ b/src/app/services/tags.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { HttpClient, HttpParams } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { environment } from '../../environments/environment'; @Injectable({ diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index 9a520d1..f1b9318 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@angular/core'; -import { ReplaySubject, of } from 'rxjs'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { environment } from '../../environments/environment'; diff --git a/src/app/ui/comment/comment.ui.ts b/src/app/ui/comment/comment.ui.ts index 128f032..da1c256 100644 --- a/src/app/ui/comment/comment.ui.ts +++ b/src/app/ui/comment/comment.ui.ts @@ -1,6 +1,6 @@ import { Component, OnInit, Input, ViewChild } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { FormBuilder, FormGroup, Validators, NgForm } from '@angular/forms'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { AuthService } from '../../services/auth.service'; import { VoteService } from '../../services/vote.service'; diff --git a/src/app/ui/comments/comments.ui.ts b/src/app/ui/comments/comments.ui.ts index 4ac5dcc..0d39cfb 100644 --- a/src/app/ui/comments/comments.ui.ts +++ b/src/app/ui/comments/comments.ui.ts @@ -1,5 +1,4 @@ import { Component, OnInit, Input, OnDestroy } from '@angular/core'; -import { PageEvent } from '@angular/material/paginator'; import { Subscription } from 'rxjs'; import { CommentService } from '../../services/comment.service'; diff --git a/src/app/ui/entries/entries.ui.ts b/src/app/ui/entries/entries.ui.ts index bf7d3a6..5379c70 100644 --- a/src/app/ui/entries/entries.ui.ts +++ b/src/app/ui/entries/entries.ui.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input, ViewChild } from '@angular/core'; +import { Component, OnInit, Input } from '@angular/core'; import { Observable } from 'rxjs'; @Component({ diff --git a/src/app/ui/entry/entry.ui.ts b/src/app/ui/entry/entry.ui.ts index 45cd670..11744e1 100644 --- a/src/app/ui/entry/entry.ui.ts +++ b/src/app/ui/entry/entry.ui.ts @@ -8,7 +8,7 @@ import { BookmarksService } from '../../services/bookmarks.service'; import { ModerationService } from '../../services/moderarion.service'; import { ConfirmDialog } from '../../ui/confirm/confirm.component'; import { EntriesService } from 'src/app/services/entries.service'; -import { ActivatedRoute, Params, Router } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; @Component({ selector: 'ui-entry', diff --git a/src/app/ui/main/main.ui.ts b/src/app/ui/main/main.ui.ts index 626503f..ae4b622 100644 --- a/src/app/ui/main/main.ui.ts +++ b/src/app/ui/main/main.ui.ts @@ -1,4 +1,4 @@ -import { Component, HostListener, ViewChild } from '@angular/core'; +import { Component, HostListener } from '@angular/core'; import { Router } from '@angular/router'; import { DomSanitizer } from '@angular/platform-browser'; import { MatIconRegistry } from '@angular/material/icon'; @@ -9,7 +9,6 @@ import { AuthService } from '../../services/auth.service'; import { UserService } from '../../services/user.service'; import { I18nService } from '../../services/i18n.service'; import { SettingsService } from '../../services/settings.service'; -import { MatSidenav } from '@angular/material/sidenav'; @Component({ selector: 'ui-main', diff --git a/src/app/ui/tags/tagspicker.ui.ts b/src/app/ui/tags/tagspicker.ui.ts index e5f27a9..97c1cd0 100644 --- a/src/app/ui/tags/tagspicker.ui.ts +++ b/src/app/ui/tags/tagspicker.ui.ts @@ -3,7 +3,6 @@ import { Component, OnInit, Input, ViewChild, ElementRef } from '@angular/core'; import { FormControl } from '@angular/forms'; import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; import { MatChipInputEvent } from '@angular/material/chips'; -import { MatPaginator } from '@angular/material/paginator'; import { Observable } from 'rxjs'; import { debounceTime, switchMap } from 'rxjs/operators'; import { TagsService } from 'src/app/services/tags.service';