Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

AppMenu: show AppMenuItem in dependency of feature #6637


User avatar
1
alexanderpilhar created

6.7.0, Angular, .NET Framework

I want to display certain AppMenuItems only in dependency of certain features.

I couldn't find anything about it in documentation, but I found a 2 years old support question here: [Using featureDependency in Navigation Provider? #1880](https://support.aspnetzero.com/QA/Questions/1880)

The problem is, I don't know where to import SimpleFeatureDependency from.


5 Answer(s)
  • User Avatar
    0
    alexanderpilhar created

    If I do it like this (app-navigation.service.ts):

    new AppMenuItem("MenuItemName", "PermissionName", "fas fa-icon", "/app/main/page", null, null, null, "FeatureName")
    

    then browser console shows error messages.

    One of the errors says: ERROR TypeError: "this.featureDependency is not a function". This is because of (app-navigation.service.ts):

    showMenuItem(menuItem: AppMenuItem): boolean {        
            ...
            if (menuItem.hasFeatureDependency() && !menuItem.featureDependencySatisfied()) {
                hideMenuItem = true;
            }
            ...        
    }
    

    and (app-menu-item.ts):

    featureDependencySatisfied(): boolean {
            if (this.featureDependency) {
                return this.featureDependency();
            }
    
            return false;
    }
    

    this.featureDependency() does not exist ... at least, it's not a function but a property of type any.

    Do i have to pass on some function?

  • User Avatar
    0
    aaron created
    Support Team

    It's a C# class.

    Sample usage in test case: https://github.com/aspnetboilerplate/aspnetboilerplate/blob/cb0626b58670e123787c7884aafb3758fb6e3ba6/test/Abp.Zero.SampleApp/Authorization/AppAuthorizationProvider.cs

  • User Avatar
    0
    alexanderpilhar created

    I extended app-navigation-service.ts like follows:

    ...
    import { FeatureCheckerService } from '@abp/features/feature-checker.service';
    ...
    constructor(
        private _permissionCheckerService: PermissionCheckerService,
        private _featureCheckerService: FeatureCheckerService,
        private _appSessionService: AppSessionService
    ) { }
    ...
    checkFeature(feature: string): boolean {
        const result = this._featureCheckerService.isEnabled(feature);
        abp.log.info(`Feature.isEnabled: ${result}`);
        return result;
    }
    ...
    new AppMenuItem("MenuItemName", "PermissionName", "fas fa-icon", "/app/main/page", null, null, null, this.checkFeature("FeatureName"))
    

    But result is always false ...

    EDIT

    There was a type in my feature name ... now I'm back at ERROR TypeError: "this.featureDependency is not a function" since the function is executed (!?) when passed on ... changing it to:

    new AppMenuItem("MenuItemName", "PermissionName", "fas fa-icon", "/app/main/page", null, null, null, (): boolean => { return this.checkFeature("FeatureName"); })
    

    leads to: ERROR TypeError: "_v.parent.context.item.items is null"

  • User Avatar
    2
    ismcagdas created
    Support Team

    Yes, you can do it like https://github.com/aspnetzero/aspnet-zero-core/issues/1632#issuecomment-428900148

    This should be added to documentation and we will add it, sorry for this.

  • User Avatar
    0
    alexanderpilhar created

    Thanks a lot @ismcagdas!

    Using

    new AppMenuItem("MenuItemName", "PermissionName", "fas fa-icon", "/app/main/page", undefined, undefined, undefined, () => {
        return this._featureCheckerService.isEnabled("FeatureName");
    })
    

    works : )