pages menu logic

master
Boris Voropaev 2023-11-12 15:19:04 +03:00
parent c35bc06eaf
commit a55179c199
7 changed files with 72 additions and 39 deletions

View File

@ -1,6 +1,6 @@
<div class="item" [ngClass]="itemClass">
<drop-down *ngIf="children?.length"
ico="chevron_right_24" [visible]="toggle" (toggle)="toggle=$event" [target]="menu" [angle]="[0,90]">
<drop-down *ngIf="item.hasChildren"
ico="chevron_right_24" [visible]="toggle" (toggle)="switching($event)" [target]="menu" [angle]="[0,90]">
</drop-down>
<a (click)="rout(item.link)">
{{item.name}}

View File

@ -1,6 +1,7 @@
import {Component, EventEmitter, Input, Output,OnInit} from '@angular/core';
import { Router} from '@angular/router';
import {Subscription} from 'rxjs';
import { MenuService } from '@app/_services/menu.service';
import { PagesService } from '@app/_services/pages.service';
@Component({
selector: 'pages-menu-item',
@ -13,7 +14,11 @@ export class PagesMenuItemComponent {
public toggle=false;
currentURL:string;
constructor(private router: Router) {
constructor(
private router: Router,
private menuService: MenuService,
private pagesService: PagesService
) {
}
@ -23,44 +28,60 @@ export class PagesMenuItemComponent {
}
ngOnInit(){
this.currentURL = this.router.url;
this.toggle = this.current||this.parent;
this.router.events.subscribe((event:any)=>{
if (event.url){
this.currentURL = event.url;
this.toggle = this.current||this.parent;
}
})
if (this.toggle) this.menuService.findChildren(this.item)
}
rout(link:string){
console.log(link)
this.router.navigate([{outlets: {slider: null}}]).then(
()=>this.router.navigate([link])
)
this.menuService.navURL = link;
if (this.item.type.name=='nav-page'){
this.toggle=!this.toggle;
this.menuService.findChildren(link)
}else{
this.router.navigate([{outlets: {slider: null}}]).then(
()=>this.router.navigate([link])
)
}
}
switching(event:boolean){
this.menuService.navURL = this.item.link;
this.toggle=event;
this.menuService.findChildren(this.item)
}
get parent(){
return this.currentURL.startsWith(this.item.link)
let parents:any;
let resp = false;
parents = this.pagesService.currentPage.value.parents?.data;
if (parents) {
resp = parents.map((item:any)=>item.link).includes(this.item.link)
}
return resp
}
get current(){
return this.currentURL==this.item.link
return this.pagesService.currentPage.value.link == this.item.link
}
get active(){
return this.menuService.navURL == this.item.link;
}
get menuClass(){
let menuClass = {
selected: this.toggle
}
let menuClass = {}
menuClass['level-'+(this.level+1)] = true;
return menuClass
}
get itemClass(){
let itemClass = {
selected: this.toggle,
unlock: this.toggle,
parent: this.parent&&!this.current,
current: this.current
current: this.current,
nav: this.item.type.name == "nav-page",
active: this.active,
}
itemClass['level-'+(this.level+1)] = true;
return itemClass

View File

@ -74,7 +74,6 @@ export class PageComponent {
];
this.pagesService.find(this.url, {include: include.join(',')}).subscribe(res => {
this.page = res?.data;
console.log('NextPage', this.page)
this.pagesService.currentPage.next(this.page);
this.page = res?.data;
this.pagesService.setMetaFromPage(this.page);

View File

@ -1,33 +1,45 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable, BehaviorSubject} from "rxjs";
import {BehaviorSubject} from "rxjs";
import { PagesService } from './pages.service';
import {environment} from '@environments/environment';
@Injectable({providedIn: 'root'})
export class MenuService {
constructor(
private http: HttpClient,
constructor(
private pagesService: PagesService
){}
public pagesTree = new BehaviorSubject({data:[]});
private currentPage:any;
public navURL:string;
setPagesTree(){
let include = ['children.children.children.children.children.children.children'];
this.root({include: include.join(',')}).subscribe(res => {
this.pagesTree.next(res)
});
setPagesTree(pageURL?:any){
let include = {include: 'hasChildren, children.hasChildren'};
if (pageURL){
this.pagesService.find(pageURL,include).subscribe(
res => {
this.pagesTree.next({data:[res.data]})
}
)
}else{
this.pagesService.root(include).subscribe(
res => {
this.pagesTree.next(res)
}
);
}
}
root(params?: {}): Observable<any> {
return this.http.get(`${environment.apiUrl}/api/pages/root`, {params: params});
findChildren(item){
let include = {include: 'hasChildren, children.hasChildren'};
if (!item.children && item.hasChildren) this.pagesService.find(item.link,include).subscribe(
res=>{
item.children = res.data.children
}
)
}
}

View File

@ -7,6 +7,7 @@ export const environment = {
apiUrl: 'http://api.vniigazv2.lc',
clientId: 4,
clientSecret: 'QC09jOPEU7mpfFerpLyAJRshFUW1T28GfhsYzJHc',
project: null
};
/*

View File

@ -52,12 +52,12 @@ a.logo{
gap:24px;
pages-menu-item{
font-size: 20px;
.item{
.item:not(.nav){
drop-down{
display: none;
}
}
.sub-menu:not(.current){
.sub-menu:not(.active.unlock){
display:none;
}
.sub-menu>pages-menu{

View File

@ -6,7 +6,7 @@ export const environment = {
production: false,
apiUrl: 'http://api.nircms.lc',
clientId: 2,
clientSecret: 'm2xpjoyMM2sSAO20BpcFyPaAs4h50J4tz6so3qM2',
clientSecret: 'z1QAYw4VxcRLXyspskb4LiA2dS9Lx1WAvEzxQPR1',
project: 'vniigaz-v2'
};