2022-07-15 14:24:23 +02:00
|
|
|
import {ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core';
|
2022-07-15 12:28:55 +02:00
|
|
|
import {ActivatedRoute} from '@angular/router';
|
2021-12-09 14:52:39 +01:00
|
|
|
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-12-09 15:43:36 +01:00
|
|
|
import {MenuAlignment, MenuItemExtended} 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 {Option} from '../../sharedComponents/input/input.component';
|
2022-07-11 09:25:00 +02:00
|
|
|
import {CommunityInfo} from '../../connect/community/communityInfo';
|
|
|
|
import {Stakeholder} from '../../monitor/entities/stakeholder';
|
|
|
|
import {StakeholderService} from '../../monitor/services/stakeholder.service';
|
|
|
|
import {CommunityService} from '../../connect/community/community.service';
|
2022-07-15 09:16:42 +02:00
|
|
|
import {ClearCacheService} from '../../services/clear-cache.service';
|
|
|
|
import {TransitionGroupComponent} from '../../utils/transition-group/transition-group.component';
|
|
|
|
import {HelperFunctions} from '../../utils/HelperFunctions.class';
|
2022-07-15 12:28:55 +02:00
|
|
|
import {NotificationHandler} from '../../utils/notification-handler';
|
2022-12-07 11:09:01 +01:00
|
|
|
// import {Page} from "../../utils/entities/adminTool/page";
|
|
|
|
|
2022-12-09 15:43:36 +01:00
|
|
|
declare var UIkit;
|
2022-07-15 09:16:42 +02:00
|
|
|
|
2021-12-09 14:52:39 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'menuSelector',
|
2022-07-15 09:16:42 +02:00
|
|
|
templateUrl: './menu.component.html',
|
|
|
|
styleUrls: ['./menu.component.less']
|
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;
|
2022-07-15 09:16:42 +02:00
|
|
|
@ViewChild("elements") elements: TransitionGroupComponent;
|
2022-07-15 14:24:23 +02:00
|
|
|
@ViewChild("subElements") subElements: TransitionGroupComponent;
|
2021-12-23 15:12:51 +01:00
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
private index: number;
|
2022-07-15 12:28:55 +02:00
|
|
|
|
2022-12-07 11:09:01 +01:00
|
|
|
// public newPageWindowOpen: boolean = false;
|
|
|
|
|
|
|
|
public menuItemForm: FormGroup;
|
2022-01-11 11:05:40 +01:00
|
|
|
public pageForm: FormGroup;
|
2022-07-15 09:16:42 +02:00
|
|
|
public menuTypes = [
|
|
|
|
{label: 'Normal Menu', value: 'normalMenu'},
|
|
|
|
{label: 'Custom Menu', value: 'customMenu'}
|
|
|
|
];
|
|
|
|
public selectedMenuType = this.menuTypes[0].value;
|
2022-07-19 13:23:01 +02:00
|
|
|
public normalMenuItems: MenuItemExtended[] = [];
|
|
|
|
public featuredMenuItems: MenuItemExtended[] = [];
|
2021-12-17 14:36:30 +01:00
|
|
|
public allPages = [];
|
2022-07-19 13:23:01 +02:00
|
|
|
public parentOptions: Option[] = [];
|
2022-07-15 12:28:55 +02:00
|
|
|
public pageStatus: Map<string,boolean> = null;
|
2021-12-09 14:52:39 +01:00
|
|
|
|
2022-01-05 15:41:49 +01:00
|
|
|
public selectedMenuItem: string;
|
2022-07-18 12:07:03 +02:00
|
|
|
public selectedMenuItemParent: string;
|
2022-01-05 15:41:49 +01:00
|
|
|
public isChild: boolean = false;
|
2022-07-18 13:51:08 +02:00
|
|
|
|
|
|
|
public showNormalMenu: boolean = false;
|
|
|
|
public showFeaturedMenu: boolean = false;
|
2022-12-09 15:43:36 +01:00
|
|
|
public featuredAlignment: string = MenuAlignment.CENTER.valueOf();
|
|
|
|
|
2021-12-09 14:52:39 +01:00
|
|
|
public communities: Portal[] = [];
|
|
|
|
public portal: string;
|
2022-07-11 09:25:00 +02:00
|
|
|
public name: string;
|
|
|
|
public entity: CommunityInfo | Stakeholder;
|
|
|
|
public showLogo: boolean = true;
|
2022-07-15 15:56:50 +02:00
|
|
|
public type: any;
|
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[] = [
|
2022-07-15 09:16:42 +02:00
|
|
|
{label: 'Internal page', value: 'internal'},
|
|
|
|
{label: 'External URL', value: 'external'},
|
2022-01-11 11:05:40 +01:00
|
|
|
]
|
|
|
|
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 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
|
|
|
|
2022-07-15 12:28:55 +02:00
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private title: Title,
|
2021-12-09 14:52:39 +01:00
|
|
|
private _helpContentService: HelpContentService,
|
2022-07-11 09:25:00 +02:00
|
|
|
private userManagementService: UserManagementService, private _fb: FormBuilder,
|
|
|
|
private stakeholderService: StakeholderService,
|
2022-07-15 09:16:42 +02:00
|
|
|
private communityService: CommunityService,
|
2022-07-15 14:24:23 +02:00
|
|
|
private _clearCacheService: ClearCacheService,
|
|
|
|
private cdr: ChangeDetectorRef) {
|
2021-12-09 14:52:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
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) {
|
2022-07-11 09:25:00 +02:00
|
|
|
this.name = StringUtils.capitalize(this.portal);
|
2021-12-09 14:52:39 +01:00
|
|
|
this.title.setTitle(StringUtils.capitalize(this.portal) + ' | Menu');
|
|
|
|
} else if (this.route.snapshot.params[this.route.snapshot.data.param]) {
|
2022-07-15 09:16:42 +02:00
|
|
|
this.type = this.route.snapshot.data.param;
|
2022-07-11 09:25:00 +02:00
|
|
|
if(this.route.snapshot.data.param === 'stakeholder') {
|
|
|
|
this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
|
|
if(stakeholder) {
|
|
|
|
this.name = stakeholder.name;
|
|
|
|
this.entity = stakeholder;
|
|
|
|
this.title.setTitle(this.name + ' | Menu');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
this.subscriptions.push(this.communityService.getCommunityAsObservable().subscribe(community => {
|
|
|
|
if(community) {
|
|
|
|
this.showLogo = false;
|
|
|
|
this.name = community.shortTitle;
|
|
|
|
this.entity = community;
|
|
|
|
this.title.setTitle(this.name + ' | Menu');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2021-12-09 14:52:39 +01:00
|
|
|
} else {
|
|
|
|
this.title.setTitle('Administrator Dashboard | Menu');
|
|
|
|
}
|
2022-07-15 14:24:23 +02:00
|
|
|
this.isPortalAdministrator = Session.isPortalAdministrator(user);
|
2022-07-15 09:16:42 +02:00
|
|
|
this.selectedMenuType = this.isPortalAdministrator ? this.menuTypes[0].value : this.menuTypes[1].value;
|
2021-12-09 14:52:39 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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 => {
|
2022-07-15 12:36:55 +02:00
|
|
|
this.featuredMenuItems = data.featuredMenuItems;
|
|
|
|
this.normalMenuItems = data.menuItems;
|
2022-07-18 13:51:08 +02:00
|
|
|
this.showFeaturedMenu = data.isFeaturedMenuEnabled;
|
|
|
|
this.showNormalMenu = data.isMenuEnabled;
|
2022-12-09 15:43:36 +01:00
|
|
|
this.featuredAlignment = data.featuredAlignment.valueOf();
|
2022-01-14 14:55:24 +01:00
|
|
|
this.getPages();
|
2022-07-18 12:07:03 +02:00
|
|
|
this.getParentOptions();
|
2022-01-14 14:55:24 +01:00
|
|
|
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-07-18 12:07:03 +02:00
|
|
|
getTypeOptions(isFeatured: boolean = false, parentItem) {
|
|
|
|
if(this.isChild || parentItem != '') {
|
2022-01-11 11:05:40 +01:00
|
|
|
return this.typeOptions;
|
|
|
|
} else {
|
2022-07-15 09:16:42 +02:00
|
|
|
if(isFeatured || !this.isPortalAdministrator) {
|
2022-03-02 11:26:28 +01:00
|
|
|
return this.typeOptions;
|
|
|
|
} else {
|
|
|
|
return this.typeOptions.concat(this.rootOnlyTypeOptions);
|
|
|
|
}
|
2022-01-11 11:05:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2022-07-15 12:28:55 +02:00
|
|
|
this.pageStatus = 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});
|
2022-07-15 12:28:55 +02:00
|
|
|
this.pageStatus.set(pages[i].route, 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-07-18 12:07:03 +02:00
|
|
|
getParentOptions() {
|
2022-07-19 13:23:01 +02:00
|
|
|
this.parentOptions = this.normalMenuItems.map(item => ({label: item.title, value: item._id}));
|
2022-07-18 12:07:03 +02:00
|
|
|
this.parentOptions.unshift({label: 'No parent', value: ''});
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-07-18 12:07:03 +02:00
|
|
|
public newMenuItem() {
|
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-07-19 13:23:01 +02:00
|
|
|
isFeatured: this._fb.control(this.selectedMenuType == 'customMenu'),
|
2022-07-18 12:07:03 +02:00
|
|
|
parentItemId: this._fb.control("")
|
2021-12-17 14:36:30 +01:00
|
|
|
});
|
2022-01-11 11:05:40 +01:00
|
|
|
this.addValidatorForUrlOrRoute();
|
2022-07-11 09:25:00 +02:00
|
|
|
this.menuItemsModalOpen('Add Menu Item', 'Create');
|
2021-12-17 14:36:30 +01:00
|
|
|
}
|
|
|
|
|
2022-07-19 13:25:11 +02:00
|
|
|
public editMenuItem(index: number, menuItem: MenuItemExtended, 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-07-19 13:25:11 +02: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;
|
2022-07-15 09:16:42 +02:00
|
|
|
this.index = index;
|
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-07-18 12:07:03 +02:00
|
|
|
public confirmDeleteMenuItem(id: string, isChild: boolean = false, parentId: string) {
|
|
|
|
this.selectedMenuItemParent = parentId;
|
2022-01-05 15:41:49 +01:00
|
|
|
this.selectedMenuItem = id;
|
|
|
|
this.isChild = isChild;
|
|
|
|
this.confirmModalOpen();
|
2021-12-17 08:22:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private confirmModalOpen() {
|
|
|
|
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-07-15 09:16:42 +02:00
|
|
|
public confirmedDeleteMenuItem(data: any) {
|
2022-01-05 15:41:49 +01:00
|
|
|
this.showLoading = true;
|
|
|
|
this.subscriptions.push(
|
|
|
|
this._helpContentService.deleteMenuItem(this.selectedMenuItem, this.portal).subscribe(
|
|
|
|
_ => {
|
|
|
|
this.deleteMenuItemFromArray(this.selectedMenuItem, this.isChild);
|
2022-07-15 12:28:55 +02:00
|
|
|
NotificationHandler.rise("Menu item have been <b>successfully deleted</b>");
|
2022-01-05 15:41:49 +01:00
|
|
|
this.showLoading = false;
|
2022-07-15 09:16:42 +02:00
|
|
|
this._clearCacheService.clearCache("Menu item deleted");
|
2022-08-11 11:58:20 +02:00
|
|
|
this._clearCacheService.purgeBrowserCache("Menu item deleted", this.portal);
|
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-07-18 12:07:03 +02:00
|
|
|
let i = this.normalMenuItems.findIndex(_ => _._id == this.selectedMenuItemParent);
|
|
|
|
let j = this.normalMenuItems[i].items.findIndex(_ => _._id == id);
|
|
|
|
this.normalMenuItems[i].items.splice(j, 1);
|
2022-01-05 15:41:49 +01:00
|
|
|
} else {
|
2022-07-15 09:16:42 +02:00
|
|
|
if(this.selectedMenuType == 'customMenu') {
|
|
|
|
let i = this.featuredMenuItems.findIndex(_ => _._id == id);
|
|
|
|
this.featuredMenuItems.splice(i, 1);
|
|
|
|
} else {
|
|
|
|
let i = this.normalMenuItems.findIndex(_ => _._id == id);
|
|
|
|
this.normalMenuItems.splice(i, 1);
|
2022-07-19 13:23:01 +02:00
|
|
|
this.getParentOptions();
|
2022-07-15 09:16:42 +02:00
|
|
|
}
|
2022-01-14 14:55:24 +01:00
|
|
|
}
|
2021-12-23 08:22:07 +01:00
|
|
|
}
|
|
|
|
|
2021-12-09 14:52:39 +01:00
|
|
|
private menuItemsModalOpen(title: string, yesBtn: string) {
|
|
|
|
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;
|
2022-06-29 12:56:19 +02:00
|
|
|
this.menuItemForm.value.target = this.menuItemForm.value['type'] == "internal" ? "_self" : "_blank";
|
|
|
|
if(!this.menuItemForm.value._id) {
|
2022-01-05 15:41:49 +01:00
|
|
|
this.subscriptions.push(
|
2022-07-18 13:51:08 +02:00
|
|
|
this._helpContentService.saveMenuItem(<MenuItemExtended>this.menuItemForm.getRawValue(), this.portal).subscribe(
|
2022-01-05 15:41:49 +01:00
|
|
|
menuItem => {
|
|
|
|
this.menuItemSavedSuccessfully(menuItem, true);
|
2022-07-15 12:28:55 +02:00
|
|
|
NotificationHandler.rise('Menu item <b>' + menuItem.title + '</b> has been <b>successfully created</b>');
|
2022-07-15 09:16:42 +02:00
|
|
|
this._clearCacheService.clearCache("Menu item saved");
|
2022-08-11 11:58:20 +02:00
|
|
|
this._clearCacheService.purgeBrowserCache("Menu item saved", this.portal);
|
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(
|
2022-07-18 13:51:08 +02:00
|
|
|
this._helpContentService.updateMenuItem(<MenuItemExtended>this.menuItemForm.getRawValue(), this.portal).subscribe(
|
2022-01-05 15:41:49 +01:00
|
|
|
menuItem => {
|
|
|
|
this.menuItemSavedSuccessfully(menuItem, false);
|
2022-07-15 12:28:55 +02:00
|
|
|
NotificationHandler.rise('Menu item <b>' + menuItem.title + '</b> has been <b>successfully updated</b>');
|
2022-07-15 09:16:42 +02:00
|
|
|
this._clearCacheService.clearCache("Menu item updated");
|
2022-08-11 11:58:20 +02:00
|
|
|
this._clearCacheService.purgeBrowserCache("Menu item updated", this.portal);
|
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
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 13:23:01 +02:00
|
|
|
public menuItemSavedSuccessfully(menuItem: MenuItemExtended, isNew: boolean) {
|
2022-01-05 15:41:49 +01:00
|
|
|
if(isNew) {
|
2022-07-19 13:25:11 +02:00
|
|
|
if(menuItem.parentItemId) {
|
|
|
|
let i = this.normalMenuItems.findIndex(_ => _._id == menuItem.parentItemId);
|
2022-07-18 12:07:03 +02:00
|
|
|
this.normalMenuItems[i].items.push(menuItem);
|
2022-01-05 15:41:49 +01:00
|
|
|
} else {
|
2022-07-15 09:16:42 +02:00
|
|
|
if(menuItem.isFeatured) {
|
|
|
|
this.featuredMenuItems.push(menuItem);
|
|
|
|
} else {
|
|
|
|
this.normalMenuItems.push(menuItem);
|
2022-07-19 13:23:01 +02:00
|
|
|
this.getParentOptions();
|
2022-07-15 09:16:42 +02:00
|
|
|
}
|
2022-01-05 15:41:49 +01:00
|
|
|
}
|
|
|
|
} else {
|
2022-07-19 13:25:11 +02:00
|
|
|
if(menuItem.parentItemId) {
|
2022-01-05 15:41:49 +01:00
|
|
|
} else {
|
2022-07-15 09:16:42 +02:00
|
|
|
if(menuItem.isFeatured) {
|
|
|
|
this.featuredMenuItems[this.index] = menuItem;
|
|
|
|
} else {
|
|
|
|
this.normalMenuItems[this.index] = menuItem;
|
2022-07-19 13:23:01 +02:00
|
|
|
this.getParentOptions();
|
2022-07-15 09:16:42 +02:00
|
|
|
}
|
2022-01-14 14:55:24 +01:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2022-07-15 12:28:55 +02:00
|
|
|
NotificationHandler.rise(message, 'danger');
|
2022-01-11 16:20:05 +01:00
|
|
|
console.log('Server responded: ' + error);
|
|
|
|
this.showLoading = false;
|
|
|
|
}
|
|
|
|
|
2022-07-15 09:16:42 +02:00
|
|
|
public toggleMenuItem(menuItem) {
|
|
|
|
menuItem.isOpen = !menuItem.isOpen;
|
|
|
|
}
|
|
|
|
|
2022-07-15 14:24:23 +02:00
|
|
|
public valueChange() {
|
2024-05-01 14:59:48 +02:00
|
|
|
this.elements.disable();
|
2022-07-15 14:24:23 +02:00
|
|
|
this.cdr.detectChanges();
|
|
|
|
this.elements.init();
|
2024-05-01 14:59:48 +02:00
|
|
|
this.elements.enable();
|
2022-07-15 14:24:23 +02:00
|
|
|
}
|
|
|
|
|
2022-07-15 09:16:42 +02:00
|
|
|
public get displayMenuItems() {
|
|
|
|
return this.selectedMenuType == 'customMenu' ? this.featuredMenuItems : this.normalMenuItems;
|
|
|
|
}
|
|
|
|
|
2022-07-15 14:24:23 +02:00
|
|
|
public moveElement(index: number, newIndex: number, children: MenuItemExtended[] = []) {
|
2022-07-15 09:16:42 +02:00
|
|
|
this.elements.init();
|
2022-07-20 11:14:38 +02:00
|
|
|
if(children && children.length) {
|
|
|
|
this.subElements.init();
|
|
|
|
}
|
2022-07-15 09:16:42 +02:00
|
|
|
if(this.selectedMenuType == 'customMenu') {
|
2022-07-15 12:28:55 +02:00
|
|
|
let temp = HelperFunctions.copy(this.featuredMenuItems);
|
|
|
|
HelperFunctions.swap(temp, index, newIndex);
|
|
|
|
this._helpContentService.reorderMenuItems(temp, this.portal).subscribe(() => {
|
2022-07-15 09:16:42 +02:00
|
|
|
HelperFunctions.swap(this.featuredMenuItems, index, newIndex);
|
2022-07-15 12:28:55 +02:00
|
|
|
this._clearCacheService.clearCache("Menu items reordered");
|
2022-08-11 11:58:20 +02:00
|
|
|
this._clearCacheService.purgeBrowserCache("Menu items reordered", this.portal);
|
2022-07-15 12:28:55 +02:00
|
|
|
}, error => {
|
|
|
|
this.handleError("System error reordering menu items", error);
|
|
|
|
});
|
2022-07-15 09:16:42 +02:00
|
|
|
} else {
|
2022-07-15 12:28:55 +02:00
|
|
|
let temp = HelperFunctions.copy(this.normalMenuItems);
|
2022-07-15 14:24:23 +02:00
|
|
|
if(children && children.length) {
|
|
|
|
temp = HelperFunctions.copy(children);
|
|
|
|
}
|
2022-07-15 12:28:55 +02:00
|
|
|
HelperFunctions.swap(temp, index, newIndex);
|
|
|
|
this._helpContentService.reorderMenuItems(temp, this.portal).subscribe(() => {
|
2022-07-15 14:24:23 +02:00
|
|
|
HelperFunctions.swap(children && children.length ? children : this.normalMenuItems, index, newIndex);
|
2022-07-15 12:28:55 +02:00
|
|
|
this._clearCacheService.clearCache("Menu items reordered");
|
2022-08-11 11:58:20 +02:00
|
|
|
this._clearCacheService.purgeBrowserCache("Menu items reordered", this.portal);
|
2022-07-15 12:28:55 +02:00
|
|
|
}, error => {
|
|
|
|
this.handleError("System error reordering menu items", error);
|
|
|
|
});
|
2022-07-15 09:16:42 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-18 13:51:08 +02:00
|
|
|
|
|
|
|
public toggleMenu(status: boolean, isFeatured: boolean) {
|
|
|
|
this.subscriptions.push(
|
|
|
|
this._helpContentService.toggleMenu(status, isFeatured, this.portal).subscribe(() => {
|
|
|
|
if(isFeatured) {
|
|
|
|
this.showFeaturedMenu = status;
|
|
|
|
} else {
|
|
|
|
this.showNormalMenu = status;
|
|
|
|
}
|
|
|
|
this._clearCacheService.clearCache("Menu toggled");
|
2022-08-11 11:58:20 +02:00
|
|
|
this._clearCacheService.purgeBrowserCache("Menu toggled", this.portal);
|
2022-12-09 15:43:36 +01:00
|
|
|
NotificationHandler.rise("Menu has been <b>successfully toggled to be "+(status?"visible":"hidden")+"</b>");
|
|
|
|
}, error => {
|
2022-07-18 13:51:08 +02:00
|
|
|
this.handleError("System error toggling menu", error);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2022-12-07 11:09:01 +01:00
|
|
|
|
2022-12-09 15:43:36 +01:00
|
|
|
public alignMenu(alignment: string) {
|
|
|
|
this.subscriptions.push(
|
|
|
|
this._helpContentService.alignMenu(MenuAlignment[alignment], this.portal).subscribe(() => {
|
|
|
|
this.featuredAlignment = alignment;
|
|
|
|
this._clearCacheService.clearCache("Menu aligned");
|
|
|
|
this._clearCacheService.purgeBrowserCache("Menu aligned", this.portal);
|
|
|
|
NotificationHandler.rise("Menu has been <b>successfully "+alignment.toLowerCase()+" aligned</b>");
|
|
|
|
}, error => {
|
|
|
|
this.handleError("System error aligning menu to the "+alignment.toLowerCase(), error);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-07 11:09:01 +01:00
|
|
|
// public newPageWindow() {
|
|
|
|
// this.newPageWindowOpen = !this.newPageWindowOpen;
|
|
|
|
// this.pageForm = this._fb.group({
|
|
|
|
// _id: this._fb.control(null),
|
|
|
|
// route: this._fb.control('/featured/', [Validators.required, StringUtils.validRoute(this.allPages, 'value'), this.validCustomRoute()]),
|
|
|
|
// 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 validCustomRoute(): ValidatorFn {
|
|
|
|
// return (control: AbstractControl): ValidationErrors | null => {
|
|
|
|
// if (control.value) {
|
|
|
|
// if (!control.value.startsWith("/featured")) {
|
|
|
|
// return {error: 'Custom route should start with /featured'}
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// public createPage() {
|
|
|
|
// if(!this.pageForm.value.route.startsWith('/featured')) {
|
|
|
|
// this.pageForm.value.route = '/featured/'.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});
|
2022-12-09 15:43:36 +01:00
|
|
|
// NotificationHandler.rise('Page <b>' + page.name + '</b> has been <b>successfully created</b>');
|
2022-12-07 11:09:01 +01:00
|
|
|
// this.newPageWindowOpen = !this.newPageWindowOpen;
|
|
|
|
// this.menuItemForm.get('route').setValue(page.route);
|
|
|
|
// this.menuItemForm.get('route').markAsDirty();
|
|
|
|
// this.showLoading = false;
|
|
|
|
// },
|
|
|
|
// error => this.handleError('System error creating page', error)
|
|
|
|
// )
|
|
|
|
// );
|
|
|
|
// }
|
2022-07-19 13:23:01 +02:00
|
|
|
}
|