add warnings for disabled pages/routes on the menu items - dev only

This commit is contained in:
Alex Martzios 2022-01-14 15:55:24 +02:00
parent 00db2024b8
commit 3228c67a14
4 changed files with 39 additions and 13 deletions

View File

@ -80,6 +80,9 @@
<span class="title uk-padding-remove">Route: </span><span <span class="title uk-padding-remove">Route: </span><span
class="uk-padding-remove uk-margin-left">{{child.route}}</span> class="uk-padding-remove uk-margin-left">{{child.route}}</span>
</div> </div>
<div *ngIf="(menuRouteStatus != null && !menuRouteStatus.get(child._id) && child.type == 'internal')" class="uk-grid uk-width-1-1 uk-margin-left">
<span class="uk-padding-remove uk-text-warning">The item is not used either because the required page does not exist or it is disabled</span>
</div>
</div> </div>
</div> </div>
<div class="uk-width-1-5"> <div class="uk-width-1-5">
@ -125,7 +128,10 @@
<div class="uk-text-center">Select one of the pages</div> <div class="uk-text-center">Select one of the pages</div>
<div dashboard-input [formInput]="menuItemForm.get('route')" [validators]="menuItemForm.get('route').validator" <div dashboard-input [formInput]="menuItemForm.get('route')" [validators]="menuItemForm.get('route').validator"
type="autocomplete" label="Page" placeholder="Search all pages" [options]="allPages" type="autocomplete" label="Page" placeholder="Search all pages" [options]="allPages"
[showOptionsOnEmpty]="false"> [showOptionsOnEmpty]="false" class="uk-margin-bottom">
</div>
<div *ngIf="(menuRouteStatus != null && !menuRouteStatus.get(menuItemForm.get('_id').value) && !menuItemForm.get('route').dirty)" class="uk-text-center">
<span class="uk-text-warning">The item is not used either because the required page does not exist or it is disabled</span>
</div> </div>
<div class="uk-text-center uk-margin-top">Or <a (click)="newPageWindow()">create a new one</a></div> <div class="uk-text-center uk-margin-top">Or <a (click)="newPageWindow()">create a new one</a></div>
<div *ngIf="newPageWindowOpen" class="uk-card uk-card-default uk-card-body uk-margin-top"> <div *ngIf="newPageWindowOpen" class="uk-card uk-card-default uk-card-body uk-margin-top">

View File

@ -43,6 +43,7 @@ export class MenuComponent implements OnInit {
public pageForm: FormGroup; public pageForm: FormGroup;
public rootMenuItems = []; public rootMenuItems = [];
public allPages = []; public allPages = [];
public menuRouteStatus: Map<string,boolean> = null;
public selectedMenuItem: string; public selectedMenuItem: string;
public isChild: boolean = false; public isChild: boolean = false;
@ -86,6 +87,7 @@ export class MenuComponent implements OnInit {
})); }));
this.userManagementService.getUserInfo().subscribe(user => { this.userManagementService.getUserInfo().subscribe(user => {
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param]; this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
this.getMenuItems();
if (this.route.snapshot.data.portal) { if (this.route.snapshot.data.portal) {
this.title.setTitle(StringUtils.capitalize(this.portal) + ' | Menu'); this.title.setTitle(StringUtils.capitalize(this.portal) + ' | Menu');
} else if (this.route.snapshot.params[this.route.snapshot.data.param]) { } else if (this.route.snapshot.params[this.route.snapshot.data.param]) {
@ -95,9 +97,6 @@ export class MenuComponent implements OnInit {
} }
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.portal; this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.portal;
}); });
this.showLoading = false;
this.getMenuItems();
this.getPages();
} }
ngOnDestroy(): void { ngOnDestroy(): void {
@ -125,8 +124,9 @@ export class MenuComponent implements OnInit {
if(data && data.length > 0) { if(data && data.length > 0) {
this.changeActiveRootMenuItem(data[0]); this.changeActiveRootMenuItem(data[0]);
} }
this.getPages();
this.showLoading = false;
}, },
// err => console.error("Server error fetching menu items: ", err)
error => this.handleError("Server error fetching menu items", error) error => this.handleError("Server error fetching menu items", error)
) )
); );
@ -145,7 +145,7 @@ export class MenuComponent implements OnInit {
} }
changeActiveRootMenuItem(item: MenuItem) { changeActiveRootMenuItem(item: MenuItem) {
this.activeRootMenuId = item['_id'] this.activeRootMenuId = item['_id'];
this.activeRootMenu = item; this.activeRootMenu = item;
this.childrenMenuItems = item.items; this.childrenMenuItems = item.items;
this.applyFilters(); this.applyFilters();
@ -153,13 +153,25 @@ export class MenuComponent implements OnInit {
getPages() { getPages() {
this.subscriptions.push( this.subscriptions.push(
this._helpContentService.getAllPages(this.properties.adminToolsAPIURL,this.portal).subscribe( this._helpContentService.getCommunityPagesByType(this.portal, '', this.properties.adminToolsAPIURL).subscribe(
data => { data => {
let pages = data; let pages = data;
this.allPages = []; this.allPages = [];
this.menuRouteStatus = new Map();
for(let i = 0; i < pages.length; i++) { for(let i = 0; i < pages.length; i++) {
if(pages[i] && pages[i].name && pages[i].route) { if(pages[i] && pages[i].name && pages[i].route) {
this.allPages.push({value: pages[i].route, label: pages[i].name}); this.allPages.push({value: pages[i].route, label: pages[i].name + (pages[i].isEnabled ? '' : ' [disabled]'), isEnabled: pages[i].isEnabled});
this.rootMenuItems.forEach(parent => {
if(parent.route == pages[i].route) {
this.menuRouteStatus.set(parent._id, pages[i].isEnabled);
}
if(parent.items) {
const found = parent.items.find(child => child.route == pages[i].route);
if(found) {
this.menuRouteStatus.set(found._id, pages[i].isEnabled);
}
}
})
} }
} }
}, },
@ -303,6 +315,9 @@ export class MenuComponent implements OnInit {
this.rootMenuItems.splice(i, 1); this.rootMenuItems.splice(i, 1);
this.changeActiveRootMenuItem(this.rootMenuItems[0]); this.changeActiveRootMenuItem(this.rootMenuItems[0]);
} }
if(this.menuRouteStatus != null) {
this.menuRouteStatus.delete(id);
}
this.applyFilters(); this.applyFilters();
} }
@ -363,6 +378,12 @@ export class MenuComponent implements OnInit {
this.rootMenuItems[this.index] = menuItem; this.rootMenuItems[this.index] = menuItem;
} }
} }
if(this.menuRouteStatus != null) {
const found = this.allPages.find(page => page.route == menuItem.route);
if(found) {
this.menuRouteStatus.set(menuItem._id, found.isEnabled);
}
}
this.applyFilters(); this.applyFilters();
this.showLoading = false; this.showLoading = false;
} }

View File

@ -118,7 +118,6 @@ export class PagesComponent implements OnInit {
if (this.portal) { if (this.portal) {
this.getPageHelpContentsCounts(this.portal); this.getPageHelpContentsCounts(this.portal);
} }
} }
ngOnDestroy(): void { ngOnDestroy(): void {
@ -242,7 +241,7 @@ export class PagesComponent implements OnInit {
this.index = this.pages.findIndex(value => value._id === page._id); this.index = this.pages.findIndex(value => value._id === page._id);
this.pageForm = this._fb.group({ this.pageForm = this._fb.group({
_id: this._fb.control(page._id), _id: this._fb.control(page._id),
route: this._fb.control(page.route, [Validators.required, StringUtils.validRoute(this.pages, 'route', page.route)]), route: this._fb.control(page.route, Validators.required),
name: this._fb.control(page.name, Validators.required), name: this._fb.control(page.name, Validators.required),
isEnabled: this._fb.control(page.isEnabled), isEnabled: this._fb.control(page.isEnabled),
portalType: this._fb.control(page.portalType, Validators.required), portalType: this._fb.control(page.portalType, Validators.required),
@ -268,7 +267,7 @@ export class PagesComponent implements OnInit {
this.entitiesCtrl = this._fb.array([]); this.entitiesCtrl = this._fb.array([]);
this.pageForm = this._fb.group({ this.pageForm = this._fb.group({
_id: this._fb.control(null), _id: this._fb.control(null),
route: this._fb.control('', [Validators.required, StringUtils.validRoute(this.pages, 'route')]), route: this._fb.control('', Validators.required),
name: this._fb.control('', Validators.required), name: this._fb.control('', Validators.required),
isEnabled: this._fb.control(true), isEnabled: this._fb.control(true),
portalType: this._fb.control('', Validators.required), portalType: this._fb.control('', Validators.required),
@ -364,7 +363,7 @@ export class PagesComponent implements OnInit {
if (error == null) { if (error == null) {
// this.formComponent.reset(); // this.formComponent.reset();
this.pageForm = this._fb.group({ this.pageForm = this._fb.group({
route: this._fb.control('', [Validators.required, StringUtils.validRoute(this.pages, 'route')]), route: this._fb.control('', Validators.required),
name: this._fb.control('', Validators.required), name: this._fb.control('', Validators.required),
isEnabled: this._fb.control(true), isEnabled: this._fb.control(true),
portalType: this._fb.control('', Validators.required), portalType: this._fb.control('', Validators.required),

View File

@ -103,7 +103,7 @@ export class NavigationBarComponent implements OnInit, OnDestroy {
this.handleError('Error getting community information (e.g. pages,entities) for community with id: ' + this.communityId, error); this.handleError('Error getting community information (e.g. pages,entities) for community with id: ' + this.communityId, error);
})); }));
} }
if(this.portal != 'connect') { if(this.portal != 'connect' && this.portal != 'connect-admin' && this.properties.adminToolsPortalType == 'community') {
this.subs.push( this.subs.push(
this._helpContentService.getMenuItems(this.portal).subscribe( this._helpContentService.getMenuItems(this.portal).subscribe(
data => { data => {