diff --git a/dashboard/menu/menu.component.ts b/dashboard/menu/menu.component.ts index ca470d77..a17cf96f 100644 --- a/dashboard/menu/menu.component.ts +++ b/dashboard/menu/menu.component.ts @@ -45,10 +45,10 @@ export class MenuComponent implements OnInit { {label: 'Custom Menu', value: 'customMenu'} ]; public selectedMenuType = this.menuTypes[0].value; - public normalMenuItems = []; - public featuredMenuItems = []; + public normalMenuItems: MenuItemExtended[] = []; + public featuredMenuItems: MenuItemExtended[] = []; public allPages = []; - public parentOptions = []; + public parentOptions: Option[] = []; public pageStatus: Map = null; public selectedMenuItem: string; @@ -190,11 +190,7 @@ export class MenuComponent implements OnInit { } getParentOptions() { - this.normalMenuItems.forEach(item => { - if(item.items?.length || item.parentItemId != null || item.parentItemId != '') { - this.parentOptions.push({label: item.title, value: item._id}); - } - }); + this.parentOptions = this.normalMenuItems.map(item => ({label: item.title, value: item._id})); this.parentOptions.unshift({label: 'No parent', value: ''}); } @@ -223,7 +219,7 @@ export class MenuComponent implements OnInit { route: this._fb.control(""), url: this._fb.control(""), isEnabled: this._fb.control(""), - isFeatured: this._fb.control(this.selectedMenuType == 'customMenu' ? true : false), + isFeatured: this._fb.control(this.selectedMenuType == 'customMenu'), parentItemId: this._fb.control("") }); this.addValidatorForUrlOrRoute(); @@ -287,8 +283,7 @@ export class MenuComponent implements OnInit { } else { let i = this.normalMenuItems.findIndex(_ => _._id == id); this.normalMenuItems.splice(i, 1); - let j = this.parentOptions.findIndex(_ => _._id == id); - this.parentOptions.splice(j, 1); + this.getParentOptions(); } } } @@ -304,7 +299,6 @@ export class MenuComponent implements OnInit { this.destroyTypeSubscription(); this.showLoading = true; this.menuItemForm.value.target = this.menuItemForm.value['type'] == "internal" ? "_self" : "_blank"; - console.log(this.menuItemForm.value); if(!this.menuItemForm.value._id) { this.subscriptions.push( this._helpContentService.saveMenuItem(this.menuItemForm.getRawValue(), this.portal).subscribe( @@ -330,7 +324,7 @@ export class MenuComponent implements OnInit { } } - public menuItemSavedSuccessfully(menuItem: MenuItem, isNew: boolean) { + public menuItemSavedSuccessfully(menuItem: MenuItemExtended, isNew: boolean) { if(isNew) { if(menuItem['parentItemId']) { let i = this.normalMenuItems.findIndex(_ => _._id == menuItem['parentItemId']); @@ -340,7 +334,7 @@ export class MenuComponent implements OnInit { this.featuredMenuItems.push(menuItem); } else { this.normalMenuItems.push(menuItem); - this.parentOptions.push({label: menuItem.title, value: menuItem._id}); + this.getParentOptions(); } } } else { @@ -350,6 +344,7 @@ export class MenuComponent implements OnInit { this.featuredMenuItems[this.index] = menuItem; } else { this.normalMenuItems[this.index] = menuItem; + this.getParentOptions(); } } } @@ -418,4 +413,4 @@ export class MenuComponent implements OnInit { }) ); } -} \ No newline at end of file +} diff --git a/services/help-content.service.ts b/services/help-content.service.ts index e64e48c3..b952a9ec 100644 --- a/services/help-content.service.ts +++ b/services/help-content.service.ts @@ -322,17 +322,16 @@ export class HelpContentService { .pipe(catchError(this.handleError)); } - saveMenuItem(menuItem: MenuItem, portalPid: string) { + saveMenuItem(menuItem: MenuItemExtended, portalPid: string) { HelpContentService.removeNulls(menuItem); - return this.http.post(properties.adminToolsAPIURL + properties.adminToolsPortalType + "/" + portalPid + "/menu/save", JSON.stringify(menuItem), CustomOptions.getAuthOptionsWithBody()) + return this.http.post(properties.adminToolsAPIURL + properties.adminToolsPortalType + "/" + portalPid + "/menu/save", JSON.stringify(menuItem), CustomOptions.getAuthOptionsWithBody()) .pipe(catchError(this.handleError)); } - updateMenuItem(menuItem: MenuItem, portalPid: string) { + updateMenuItem(menuItem: MenuItemExtended, portalPid: string) { HelpContentService.removeNulls(menuItem); - - return this.http.post(properties.adminToolsAPIURL + properties.adminToolsPortalType + "/" + portalPid + "/menu/update", JSON.stringify(menuItem), CustomOptions.getAuthOptionsWithBody()) + return this.http.post(properties.adminToolsAPIURL + properties.adminToolsPortalType + "/" + portalPid + "/menu/update", JSON.stringify(menuItem), CustomOptions.getAuthOptionsWithBody()) .pipe(catchError(this.handleError)); }