2022-01-13 10:23:27 +01:00
|
|
|
import {Component, ElementRef, OnInit, ViewChild, Input} from '@angular/core';
|
2021-12-09 14:52:39 +01:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {HelpContentService} from '../../services/help-content.service';
|
|
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
|
|
|
import {Portal} from '../../utils/entities/adminTool/portal';
|
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
|
|
import {Session} from '../../login/utils/helper.class';
|
|
|
|
import {UserManagementService} from '../../services/user-management.service';
|
2022-01-11 11:05:40 +01:00
|
|
|
import {Subscriber, Subscription} from "rxjs";
|
2021-12-09 14:52:39 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
|
|
|
import {StringUtils} from "../../utils/string-utils.class";
|
|
|
|
import {Title} from "@angular/platform-browser";
|
|
|
|
import {AlertModal} from '../../utils/modal/alert';
|
2022-01-11 11:05:40 +01:00
|
|
|
import {MenuItem} from '../../sharedComponents/menu';
|
2021-12-17 08:22:07 +01:00
|
|
|
import {SearchInputComponent} from '../../sharedComponents/search-input/search-input.component';
|
2022-01-11 11:05:40 +01:00
|
|
|
import {Page} from '../../utils/entities/adminTool/page';
|
|
|
|
import {Option} from '../../sharedComponents/input/input.component';
|
2021-12-09 14:52:39 +01:00
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
declare var UIkit;
|
|
|
|
|
2021-12-09 14:52:39 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'menuSelector',
|
|
|
|
templateUrl: './menu.component.html',
|
2022-01-11 11:05:40 +01:00
|
|
|
styles: [`
|
|
|
|
.z-index-2 {
|
|
|
|
z-index: 2;
|
|
|
|
}
|
|
|
|
`]
|
2021-12-09 14:52:39 +01:00
|
|
|
})
|
|
|
|
export class MenuComponent implements OnInit {
|
|
|
|
|
2021-12-17 08:22:07 +01:00
|
|
|
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
|
2021-12-09 14:52:39 +01:00
|
|
|
@ViewChild('editModal') editModal: AlertModal;
|
|
|
|
@ViewChild('deleteModal') deleteModal: AlertModal;
|
2021-12-23 15:12:51 +01:00
|
|
|
|
2022-01-11 11:05:40 +01:00
|
|
|
public activeRootMenuId: string;
|
|
|
|
public activeRootMenu: MenuItem;
|
|
|
|
public childrenMenuItems: MenuItem[] = [];
|
2022-01-13 10:23:27 +01:00
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
private index: number;
|
2022-01-13 10:23:27 +01:00
|
|
|
|
2021-12-17 08:22:07 +01:00
|
|
|
public menuItemForm: FormGroup;
|
2022-01-11 11:05:40 +01:00
|
|
|
public pageForm: FormGroup;
|
2021-12-23 15:12:51 +01:00
|
|
|
public rootMenuItems = [];
|
2021-12-17 14:36:30 +01:00
|
|
|
public allPages = [];
|
2022-01-14 14:55:24 +01:00
|
|
|
public menuRouteStatus: Map<string,boolean> = null;
|
2021-12-09 14:52:39 +01:00
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
public selectedMenuItem: string;
|
|
|
|
public isChild: boolean = false;
|
2021-12-09 14:52:39 +01:00
|
|
|
|
|
|
|
public communities: Portal[] = [];
|
|
|
|
public portal: string;
|
|
|
|
|
2021-12-23 08:22:07 +01:00
|
|
|
public newPageWindowOpen: boolean = false;
|
2021-12-09 14:52:39 +01:00
|
|
|
public showLoading = true;
|
|
|
|
public isPortalAdministrator = null;
|
|
|
|
public filterForm: FormGroup;
|
2022-01-11 11:05:40 +01:00
|
|
|
public typeOptions: Option[] = [
|
2021-12-17 08:22:07 +01:00
|
|
|
{label: 'Internal Link', value: 'internal'},
|
2022-01-11 11:05:40 +01:00
|
|
|
{label: 'External Link', value: 'external'},
|
|
|
|
]
|
|
|
|
public rootOnlyTypeOptions: Option[] = [
|
|
|
|
{label: 'No Action', value: 'noAction'}
|
2021-12-17 08:22:07 +01:00
|
|
|
]
|
2022-01-05 15:41:49 +01:00
|
|
|
|
|
|
|
public keyword: string = '';
|
|
|
|
public selectedKeyword: string = '';
|
|
|
|
private searchText: string = '';
|
|
|
|
|
|
|
|
public properties: EnvProperties = properties;
|
2021-12-09 14:52:39 +01:00
|
|
|
private subscriptions: any[] = [];
|
2022-01-11 11:05:40 +01:00
|
|
|
private typeSub: Subscription = null;
|
2021-12-09 14:52:39 +01:00
|
|
|
|
|
|
|
constructor(private element: ElementRef, private route: ActivatedRoute,
|
|
|
|
private _router: Router, private title: Title,
|
|
|
|
private _helpContentService: HelpContentService,
|
|
|
|
private userManagementService: UserManagementService, private _fb: FormBuilder) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.filterForm = this._fb.group({
|
|
|
|
keyword: [''],
|
|
|
|
});
|
2022-01-05 15:41:49 +01:00
|
|
|
this.subscriptions.push(this.filterForm.get('keyword').valueChanges.subscribe(value => {
|
|
|
|
this.searchText = value.toLowerCase();
|
|
|
|
this.applyFilters();
|
|
|
|
}));
|
2021-12-09 14:52:39 +01:00
|
|
|
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];
|
2022-01-14 14:55:24 +01:00
|
|
|
this.getMenuItems();
|
2021-12-09 14:52:39 +01:00
|
|
|
if (this.route.snapshot.data.portal) {
|
|
|
|
this.title.setTitle(StringUtils.capitalize(this.portal) + ' | Menu');
|
|
|
|
} else if (this.route.snapshot.params[this.route.snapshot.data.param]) {
|
|
|
|
this.title.setTitle(this.portal.toUpperCase() + ' | Menu');
|
|
|
|
} else {
|
|
|
|
this.title.setTitle('Administrator Dashboard | Menu');
|
|
|
|
}
|
|
|
|
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.portal;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.subscriptions.forEach(value => {
|
|
|
|
if (value instanceof Subscriber) {
|
|
|
|
value.unsubscribe();
|
|
|
|
} else if (value instanceof Function) {
|
|
|
|
value();
|
|
|
|
}
|
|
|
|
});
|
2022-01-11 11:05:40 +01:00
|
|
|
this.destroyTypeSubscription();
|
2021-12-09 14:52:39 +01:00
|
|
|
}
|
2021-12-17 08:22:07 +01:00
|
|
|
|
2022-01-11 11:05:40 +01:00
|
|
|
destroyTypeSubscription() {
|
|
|
|
if(this.typeSub instanceof Subscriber) {
|
|
|
|
this.typeSub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-23 08:22:07 +01:00
|
|
|
getMenuItems() {
|
|
|
|
this.subscriptions.push(
|
|
|
|
this._helpContentService.getMenuItems(this.portal).subscribe(
|
|
|
|
data => {
|
2021-12-23 15:12:51 +01:00
|
|
|
this.rootMenuItems = data;
|
|
|
|
if(data && data.length > 0) {
|
2022-01-11 11:05:40 +01:00
|
|
|
this.changeActiveRootMenuItem(data[0]);
|
2021-12-23 15:12:51 +01:00
|
|
|
}
|
2022-01-14 14:55:24 +01:00
|
|
|
this.getPages();
|
|
|
|
this.showLoading = false;
|
2021-12-23 08:22:07 +01:00
|
|
|
},
|
2022-01-11 16:20:05 +01:00
|
|
|
error => this.handleError("Server error fetching menu items", error)
|
2021-12-23 08:22:07 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-02 11:26:28 +01:00
|
|
|
getTypeOptions(isFeatured: boolean = false) {
|
2022-01-11 11:05:40 +01:00
|
|
|
if(this.isChild) {
|
|
|
|
return this.typeOptions;
|
|
|
|
} else {
|
2022-03-02 11:26:28 +01:00
|
|
|
if(isFeatured) {
|
|
|
|
return this.typeOptions;
|
|
|
|
} else {
|
|
|
|
return this.typeOptions.concat(this.rootOnlyTypeOptions);
|
|
|
|
}
|
2022-01-11 11:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-23 15:12:51 +01:00
|
|
|
getActiveRootItem(id: string): MenuItem {
|
|
|
|
return this.rootMenuItems.find(element => element['_id'] == id);
|
|
|
|
}
|
|
|
|
|
2022-01-11 11:05:40 +01:00
|
|
|
changeActiveRootMenuItem(item: MenuItem) {
|
2022-01-14 14:55:24 +01:00
|
|
|
this.activeRootMenuId = item['_id'];
|
2022-01-11 11:05:40 +01:00
|
|
|
this.activeRootMenu = item;
|
|
|
|
this.childrenMenuItems = item.items;
|
|
|
|
this.applyFilters();
|
|
|
|
}
|
|
|
|
|
2021-12-23 08:22:07 +01:00
|
|
|
getPages() {
|
|
|
|
this.subscriptions.push(
|
2022-01-14 14:55:24 +01:00
|
|
|
this._helpContentService.getCommunityPagesByType(this.portal, '', this.properties.adminToolsAPIURL).subscribe(
|
2021-12-23 08:22:07 +01:00
|
|
|
data => {
|
|
|
|
let pages = data;
|
|
|
|
this.allPages = [];
|
2022-01-14 14:55:24 +01:00
|
|
|
this.menuRouteStatus = new Map();
|
2021-12-23 08:22:07 +01:00
|
|
|
for(let i = 0; i < pages.length; i++) {
|
|
|
|
if(pages[i] && pages[i].name && pages[i].route) {
|
2022-01-14 14:55:24 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-12-23 08:22:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-01-11 16:20:05 +01:00
|
|
|
error => this.handleError("Server error fetching pages", error)
|
2021-12-23 08:22:07 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
public newPageWindow() {
|
|
|
|
this.newPageWindowOpen = !this.newPageWindowOpen;
|
2022-01-11 11:05:40 +01:00
|
|
|
this.pageForm = this._fb.group({
|
|
|
|
_id: this._fb.control(null),
|
2022-01-13 14:46:22 +01:00
|
|
|
route: this._fb.control('', [Validators.required, StringUtils.validRoute(this.allPages, 'value')]),
|
2022-01-11 11:05:40 +01:00
|
|
|
name: this._fb.control('', Validators.required),
|
|
|
|
isEnabled: this._fb.control(true),
|
|
|
|
portalType: this._fb.control(this.properties.adminToolsPortalType, Validators.required),
|
|
|
|
portalPid: this._fb.control(this.portal),
|
|
|
|
top: this._fb.control(true),
|
|
|
|
bottom: this._fb.control(false),
|
|
|
|
left: this._fb.control(false),
|
|
|
|
right: this._fb.control(false),
|
|
|
|
type: this._fb.control('html', Validators.required),
|
|
|
|
entities: this._fb.control([''])
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public createPage() {
|
|
|
|
if(!this.pageForm.value.route.startsWith('/')) {
|
|
|
|
this.pageForm.value.route = '/'.concat(this.pageForm.value.route);
|
|
|
|
}
|
|
|
|
this.showLoading = true;
|
|
|
|
this.subscriptions.push(
|
|
|
|
this._helpContentService.savePage(<Page>this.pageForm.value, this.properties.adminToolsAPIURL).subscribe(
|
|
|
|
page => {
|
|
|
|
this.allPages.push({value: page.route, label: page.name});
|
|
|
|
UIkit.notification('Page <b>' + page.name + '</b> has been <b>successfully created</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
this.newPageWindowOpen = !this.newPageWindowOpen;
|
|
|
|
this.menuItemForm.get('route').setValue(page.route);
|
2022-01-13 14:46:22 +01:00
|
|
|
this.menuItemForm.get('route').markAsDirty();
|
2022-01-13 10:23:27 +01:00
|
|
|
this.showLoading = false;
|
2022-01-11 16:20:05 +01:00
|
|
|
},
|
|
|
|
error => this.handleError('System error creating page', error)
|
2022-01-11 11:05:40 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
addValidatorForUrlOrRoute() {
|
|
|
|
this.destroyTypeSubscription();
|
|
|
|
this.typeSub = this.menuItemForm.get('type').valueChanges.subscribe(value => {
|
|
|
|
setTimeout(() => {
|
2022-01-11 12:15:37 +01:00
|
|
|
this.menuItemForm.controls['route'].clearValidators();
|
|
|
|
this.menuItemForm.controls['url'].clearValidators();
|
2022-01-11 11:05:40 +01:00
|
|
|
if(value === "internal") {
|
|
|
|
this.menuItemForm.controls['route'].setValidators([Validators.required]);
|
|
|
|
} else if(value === "external") {
|
2022-01-11 12:15:37 +01:00
|
|
|
this.menuItemForm.controls['url'].setValidators([Validators.required, StringUtils.urlValidator()]);
|
2022-01-11 11:05:40 +01:00
|
|
|
}
|
2022-01-11 12:15:37 +01:00
|
|
|
this.menuItemForm.controls['route'].updateValueAndValidity();
|
|
|
|
this.menuItemForm.controls['url'].updateValueAndValidity();
|
2022-01-11 11:05:40 +01:00
|
|
|
}, 0);
|
|
|
|
});
|
2022-01-05 15:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public newMenuItem(isChild: boolean = false) {
|
2021-12-17 14:36:30 +01:00
|
|
|
this.menuItemForm = this._fb.group({
|
2022-01-05 15:41:49 +01:00
|
|
|
_id: this._fb.control(""),
|
2021-12-17 14:36:30 +01:00
|
|
|
title: this._fb.control("",Validators.required),
|
2022-01-11 11:05:40 +01:00
|
|
|
type: this._fb.control("",Validators.required),
|
2021-12-17 14:36:30 +01:00
|
|
|
route: this._fb.control(""),
|
|
|
|
url: this._fb.control(""),
|
2021-12-23 15:12:51 +01:00
|
|
|
isEnabled: this._fb.control(""),
|
2022-03-02 11:26:28 +01:00
|
|
|
isFeatured: this._fb.control(false),
|
2022-01-11 11:05:40 +01:00
|
|
|
parentItemId: this._fb.control(isChild ? this.activeRootMenuId : null)
|
2021-12-17 14:36:30 +01:00
|
|
|
});
|
2022-01-05 15:41:49 +01:00
|
|
|
this.isChild = isChild;
|
2022-01-11 11:05:40 +01:00
|
|
|
this.addValidatorForUrlOrRoute();
|
2022-01-05 15:41:49 +01:00
|
|
|
this.menuItemsModalOpen('Create Menu Item', 'Create');
|
2021-12-17 14:36:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
public editMenuItem(menuItem: MenuItem, isChild: boolean = false) {
|
2021-12-17 14:36:30 +01:00
|
|
|
this.menuItemForm = this._fb.group({
|
2022-01-05 15:41:49 +01:00
|
|
|
_id: this._fb.control(menuItem['_id']),
|
|
|
|
title: this._fb.control(menuItem.title,Validators.required),
|
2022-01-11 11:05:40 +01:00
|
|
|
type: this._fb.control(menuItem['type'],Validators.required),
|
2022-01-11 12:15:37 +01:00
|
|
|
route: this._fb.control(menuItem.route, (menuItem['type'] == "internal") ? [Validators.required] : []),
|
|
|
|
url: this._fb.control(menuItem.url, (menuItem['type'] == "external") ? [Validators.required, StringUtils.urlValidator()] : []),
|
2022-03-02 11:26:28 +01:00
|
|
|
isFeatured: this._fb.control(menuItem.isFeatured),
|
2022-01-05 15:41:49 +01:00
|
|
|
parentItemId: this._fb.control(menuItem['parentItemId'])
|
2021-12-17 14:36:30 +01:00
|
|
|
});
|
2022-01-05 15:41:49 +01:00
|
|
|
this.isChild = isChild;
|
|
|
|
if(this.isChild) {
|
2022-01-11 11:05:40 +01:00
|
|
|
this.index = this.getActiveRootItem(this.activeRootMenuId).items.findIndex(value => value._id === menuItem['_id']);
|
2022-01-05 15:41:49 +01:00
|
|
|
} else {
|
|
|
|
this.index = this.rootMenuItems.findIndex(value => value._id === menuItem['_id']);
|
|
|
|
}
|
2022-01-11 11:05:40 +01:00
|
|
|
this.addValidatorForUrlOrRoute();
|
2022-01-05 15:41:49 +01:00
|
|
|
this.menuItemsModalOpen('Edit Menu Item', 'Save Changes');
|
2021-12-17 14:36:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
public confirmDeleteMenuItem(id: string, isChild: boolean = false) {
|
|
|
|
this.selectedMenuItem = id;
|
|
|
|
this.isChild = isChild;
|
|
|
|
this.confirmModalOpen();
|
2021-12-17 08:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private confirmModalOpen() {
|
|
|
|
this.deleteModal.cancelButton = true;
|
|
|
|
this.deleteModal.okButton = true;
|
|
|
|
this.deleteModal.alertTitle = 'Delete Confirmation';
|
2022-01-05 15:41:49 +01:00
|
|
|
this.deleteModal.message = 'Are you sure you want to delete this menu item?';
|
2021-12-17 08:22:07 +01:00
|
|
|
this.deleteModal.okButtonText = 'Yes';
|
|
|
|
this.deleteModal.open();
|
|
|
|
}
|
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
public confirmedDeleteMenuItem(data: any, isChild: boolean = false) {
|
|
|
|
this.showLoading = true;
|
|
|
|
this.subscriptions.push(
|
|
|
|
this._helpContentService.deleteMenuItem(this.selectedMenuItem, this.portal).subscribe(
|
|
|
|
_ => {
|
|
|
|
this.deleteMenuItemFromArray(this.selectedMenuItem, this.isChild);
|
|
|
|
UIkit.notification('Menu item have been <b>successfully deleted</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
this.showLoading = false;
|
2022-01-11 16:20:05 +01:00
|
|
|
},
|
|
|
|
error => this.handleError("Server error deleting menu item", error)
|
2022-01-05 15:41:49 +01:00
|
|
|
)
|
|
|
|
)
|
2021-12-09 14:52:39 +01:00
|
|
|
}
|
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
private deleteMenuItemFromArray(id: string, isChild: boolean = false) {
|
|
|
|
if(isChild) {
|
2022-01-11 11:05:40 +01:00
|
|
|
let i = this.getActiveRootItem(this.activeRootMenuId).items.findIndex(_ => _._id == id);
|
|
|
|
this.getActiveRootItem(this.activeRootMenuId).items.splice(i, 1);
|
2022-01-05 15:41:49 +01:00
|
|
|
} else {
|
|
|
|
let i = this.rootMenuItems.findIndex(_ => _._id == id);
|
|
|
|
this.rootMenuItems.splice(i, 1);
|
2022-01-11 11:05:40 +01:00
|
|
|
this.changeActiveRootMenuItem(this.rootMenuItems[0]);
|
2022-01-05 15:41:49 +01:00
|
|
|
}
|
2022-01-14 14:55:24 +01:00
|
|
|
if(this.menuRouteStatus != null) {
|
|
|
|
this.menuRouteStatus.delete(id);
|
|
|
|
}
|
2022-01-11 11:05:40 +01:00
|
|
|
this.applyFilters();
|
2021-12-23 08:22:07 +01:00
|
|
|
}
|
|
|
|
|
2021-12-09 14:52:39 +01:00
|
|
|
private menuItemsModalOpen(title: string, yesBtn: string) {
|
|
|
|
this.editModal.cancelButton = true;
|
|
|
|
this.editModal.okButton = true;
|
|
|
|
this.editModal.okButtonLeft = false;
|
|
|
|
this.editModal.alertTitle = title;
|
|
|
|
this.editModal.okButtonText = yesBtn;
|
|
|
|
this.editModal.open();
|
|
|
|
}
|
2021-12-17 08:22:07 +01:00
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
public menuItemSaveConfirmed(data: any) {
|
2022-01-11 11:05:40 +01:00
|
|
|
this.destroyTypeSubscription();
|
2022-01-05 15:41:49 +01:00
|
|
|
this.showLoading = true;
|
|
|
|
if(!this.menuItemForm.value._id) {
|
|
|
|
this.subscriptions.push(
|
|
|
|
this._helpContentService.saveMenuItem(<MenuItem>this.menuItemForm.value, this.portal).subscribe(
|
|
|
|
menuItem => {
|
|
|
|
this.menuItemSavedSuccessfully(menuItem, true);
|
|
|
|
UIkit.notification('Menu item <b>' + menuItem.title + '</b> has been <b>successfully created</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2022-01-11 16:20:05 +01:00
|
|
|
},
|
|
|
|
error => this.handleError("System error creating menu item", error)
|
2022-01-05 15:41:49 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
this.subscriptions.push(
|
|
|
|
this._helpContentService.updateMenuItem(<MenuItem>this.menuItemForm.value, this.portal).subscribe(
|
|
|
|
menuItem => {
|
|
|
|
this.menuItemSavedSuccessfully(menuItem, false);
|
|
|
|
UIkit.notification('Menu item <b>' + menuItem.title + '</b> has been <b>successfully updated</b>', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2022-01-11 16:20:05 +01:00
|
|
|
},
|
|
|
|
error => this.handleError("System error updating menu item", error)
|
2022-01-05 15:41:49 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public menuItemSavedSuccessfully(menuItem: MenuItem, isNew: boolean) {
|
|
|
|
if(isNew) {
|
|
|
|
if(this.isChild) {
|
2022-01-11 11:05:40 +01:00
|
|
|
this.getActiveRootItem(this.activeRootMenuId).items.push(menuItem);
|
2022-01-05 15:41:49 +01:00
|
|
|
} else {
|
|
|
|
this.rootMenuItems.push(menuItem);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(this.isChild) {
|
2022-01-11 11:05:40 +01:00
|
|
|
this.getActiveRootItem(this.activeRootMenuId).items[this.index] = menuItem;
|
2022-01-05 15:41:49 +01:00
|
|
|
} else {
|
|
|
|
this.rootMenuItems[this.index] = menuItem;
|
|
|
|
}
|
|
|
|
}
|
2022-01-14 14:55:24 +01:00
|
|
|
if(this.menuRouteStatus != null) {
|
|
|
|
const found = this.allPages.find(page => page.route == menuItem.route);
|
|
|
|
if(found) {
|
|
|
|
this.menuRouteStatus.set(menuItem._id, found.isEnabled);
|
|
|
|
}
|
|
|
|
}
|
2022-01-11 11:05:40 +01:00
|
|
|
this.applyFilters();
|
2022-01-05 15:41:49 +01:00
|
|
|
this.showLoading = false;
|
|
|
|
}
|
2021-12-17 08:22:07 +01:00
|
|
|
|
2022-01-11 16:20:05 +01:00
|
|
|
handleError(message: string, error) {
|
|
|
|
UIkit.notification(message, {
|
|
|
|
status: 'danger',
|
|
|
|
timeout: 6000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
public applyFilters() {
|
2022-01-11 16:20:05 +01:00
|
|
|
this.childrenMenuItems = this.activeRootMenu.items.filter(item => item.title.toLowerCase().includes(this.searchText) || (item.url||'').toLowerCase().includes(this.searchText) || (item.route||'').toLowerCase().includes(this.searchText));
|
2021-12-17 08:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public onSearchClose() {
|
2021-12-17 14:36:30 +01:00
|
|
|
this.selectedKeyword = this.filterForm.get('keyword').value;
|
2021-12-17 08:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public reset() {
|
|
|
|
this.selectedKeyword = null;
|
|
|
|
this.searchInputComponent.reset();
|
|
|
|
}
|
2021-12-09 14:52:39 +01:00
|
|
|
}
|