Menu: Fix parent options update after create, edit or delete of a parent MenuItem.

This commit is contained in:
Konstantinos Triantafyllou 2022-07-19 14:23:01 +03:00
parent f664c4a232
commit 9f64477585
2 changed files with 14 additions and 20 deletions

View File

@ -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<string,boolean> = 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(<MenuItemExtended>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 {
})
);
}
}
}

View File

@ -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<MenuItem>(properties.adminToolsAPIURL + properties.adminToolsPortalType + "/" + portalPid + "/menu/save", JSON.stringify(menuItem), CustomOptions.getAuthOptionsWithBody())
return this.http.post<MenuItemExtended>(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<MenuItem>(properties.adminToolsAPIURL + properties.adminToolsPortalType + "/" + portalPid + "/menu/update", JSON.stringify(menuItem), CustomOptions.getAuthOptionsWithBody())
return this.http.post<MenuItemExtended>(properties.adminToolsAPIURL + properties.adminToolsPortalType + "/" + portalPid + "/menu/update", JSON.stringify(menuItem), CustomOptions.getAuthOptionsWithBody())
.pipe(catchError(this.handleError));
}