Exemplo n.º 1
0
 public async Task <IViewComponentResult> InvokeAsync(NavigationDetailViewModel currentNavViewModel)
 {
     return(View(await GetNavigationAsync(currentNavViewModel)));
 }
Exemplo n.º 2
0
        private Task <NavigationDetailViewModel> GetNavigationAsync(NavigationDetailViewModel currentNavViewModel)
        {
            var ndvm = new NavigationDetailViewModel
            {
                MainMenus = new List <MainMenu>(),
                SubMenus  = new List <SubMenu>()
            };

            if (_ud.IsActiveSession())
            {
                var journey = _ud.FarmDetails().UserJourney;
                ndvm.MainMenus = _sd.GetJourney((int)journey)
                                 .MainMenus
                                 .OrderBy(m => m.SortNumber)
                                 .ToList();

                var currentAction = CoreSiteActions.NotUsed;
                var currentPage   = FeaturePages.NotUsed;

                if (currentNavViewModel.UsesFeaturePages)
                {
                    if (currentNavViewModel.CurrentPage.ToLower().EndsWith("index"))
                    {
                        currentPage = EnumHelper <FeaturePages> .GetValueFromDescription(currentNavViewModel.CurrentPage);
                    }
                    else
                    {
                        var indexPage = currentNavViewModel
                                        .CurrentPage.Substring(0, currentNavViewModel.CurrentPage.LastIndexOf('/') + 1);
                        currentPage = EnumHelper <FeaturePages> .GetValueFromDescription($"{indexPage}Index");
                    }
                }
                else
                {
                    currentAction = EnumHelper <CoreSiteActions> .Parse(currentNavViewModel.CurrentAction);
                }

                if (currentNavViewModel.UsesFeaturePages || currentAction > CoreSiteActions.Home)
                {
                    ndvm.UseInterceptJS = currentAction == CoreSiteActions.Farm;
                    var currentMainMenu = ndvm.MainMenus
                                          .SingleOrDefault(m => m.IsCurrentMainMenu(currentAction) || m.IsCurrentMainMenu(currentPage));

                    if (currentMainMenu != null)
                    {
                        currentMainMenu.ElementId = "current";
                        ndvm.SubMenus             = currentMainMenu.SubMenus.OrderBy(s => s.SortNumber).ToList();

                        ndvm.SubMenus = FilterRanchSubMenus(journey, ndvm.SubMenus);

                        var currentSubMenu = ndvm.SubMenus.SingleOrDefault(sm =>
                                                                           sm.IsSubMenuCurrent(currentAction) || sm.IsSubMenuCurrent(currentPage));

                        if (currentSubMenu != null)
                        {
                            currentSubMenu.ElementId = "current2";
                        }
                    }
                }
            }

            return(Task.FromResult(ndvm));
        }
Exemplo n.º 3
0
        private Task <NavigationDetailViewModel> GetNavigationAsync(CoreSiteActions currentAction)
        {
            var ndvm = new NavigationDetailViewModel();

            ndvm.mainMenuOptions = new List <MainMenu>();
            ndvm.subMenuOptions  = new List <SubMenu>();

            if (_ud.IsActiveSession())
            {
                ndvm.mainMenuOptions = _sd.GetMainMenus();

                var hasAnimals           = _ud.FarmDetails()?.HasAnimals ?? true;
                var importsManureCompost = _ud.FarmDetails()?.ImportsManureCompost ?? true;

                var greyOutClass = "top-level-nav-greyedout";

                var noManureCompost = !_ud.GetAllManagedManures().Any(); //Want true to grey out Storage and Nutrient Analysis

                ndvm.mainMenuOptions
                .Single(s => s.Action.Equals(CoreSiteActions.ManureGeneratedObtained.ToString()))
                .GreyOutClass = !hasAnimals && !importsManureCompost ? greyOutClass : string.Empty;

                if (currentAction > CoreSiteActions.Home)
                {
                    ndvm.UseInterceptJS = currentAction == CoreSiteActions.Farm;
                    var currentMainMenu =
                        ndvm.mainMenuOptions.SingleOrDefault(m => m.IsCurrentMainMenu(currentAction.ToString()));
                    if (currentMainMenu != null)
                    {
                        currentMainMenu.ElementId = "current";
                        ndvm.subMenuOptions       = currentMainMenu.SubMenus;

                        var currentSubMenu = ndvm.subMenuOptions.SingleOrDefault(sm =>
                                                                                 sm.Action.Equals(currentAction.ToString(), StringComparison.CurrentCultureIgnoreCase));

                        if (currentSubMenu != null)
                        {
                            currentSubMenu.ElementId = "current2";
                        }

                        if (currentMainMenu.Controller.Equals(AppControllers.ManureManagement.ToString()))
                        {
                            if (currentMainMenu.Controller == AppControllers.ManureManagement.ToString())
                            {
                                greyOutClass = "second-level-nav-greyedout";
                                ndvm.subMenuOptions
                                .Single(s => s.Action.Equals(CoreSiteActions.ManureGeneratedObtained.ToString()))
                                .GreyOutClass = !hasAnimals ? greyOutClass : string.Empty;

                                ndvm.subMenuOptions
                                .Single(s => s.Action.Equals(CoreSiteActions.ManureImported.ToString()))
                                .GreyOutClass = !importsManureCompost ? greyOutClass : string.Empty;

                                ndvm.subMenuOptions
                                .Single(s => s.Action.Equals(CoreSiteActions.ManureStorage.ToString()))
                                .GreyOutClass = !hasAnimals && !importsManureCompost
                                        ? greyOutClass
                                        : string.Empty;

                                ndvm.subMenuOptions
                                .Single(s => s.Action.Equals(CoreSiteActions.ManureNutrientAnalysis.ToString()))
                                .GreyOutClass = !hasAnimals && !importsManureCompost
                                        ? greyOutClass
                                        : string.Empty;
                            }
                        }
                    }
                }
            }

            return(Task.FromResult(ndvm));
        }