/*==========================================================================================================================
    | MENU
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Provides the global menu for the site layout, which exposes the top two tiers of navigation.
    /// </summary>
    public async virtual Task<PartialViewResult> Menu() {

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish variables
      \-----------------------------------------------------------------------------------------------------------------------*/
      var currentTopic          = CurrentTopic;
      var navigationRootTopic   = (Topic)null;

      /*------------------------------------------------------------------------------------------------------------------------
      | Identify navigation root
      >-------------------------------------------------------------------------------------------------------------------------
      | The navigation root in the case of the main menu is the namespace; i.e., the first topic underneath the root.
      \-----------------------------------------------------------------------------------------------------------------------*/
      navigationRootTopic = HierarchicalTopicMappingService.GetHierarchicalRoot(currentTopic, 2, "Web");
      var navigationRoot = await HierarchicalTopicMappingService.GetRootViewModelAsync(
        navigationRootTopic,
        3,
        t => t.ContentType != "PageGroup"
      ).ConfigureAwait(false);

      /*------------------------------------------------------------------------------------------------------------------------
      | Construct view model
      \-----------------------------------------------------------------------------------------------------------------------*/
      var navigationViewModel   = new NavigationViewModel<T>() {
        NavigationRoot          = navigationRoot,
        CurrentKey              = CurrentTopic?.GetUniqueKey()
      };

      /*------------------------------------------------------------------------------------------------------------------------
      | Return the corresponding view
      \-----------------------------------------------------------------------------------------------------------------------*/
      return PartialView(navigationViewModel);

    }
Ejemplo n.º 2
0
    /*==========================================================================================================================
    | PAGE LEVEL NAVIGATION
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Provides page-level navigation for the current page.
    /// </summary>
    public async Task<PartialViewResult> PageLevelNavigation() {

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish variables
      \-----------------------------------------------------------------------------------------------------------------------*/
      var currentTopic = CurrentTopic;
      var navigationRootTopic = currentTopic;

      /*------------------------------------------------------------------------------------------------------------------------
      | Identify navigation root
      >-------------------------------------------------------------------------------------------------------------------------
      | The navigation root in the case of the page-level navigation any parent of content type "PageGroup".
      \-----------------------------------------------------------------------------------------------------------------------*/
      if (navigationRootTopic != null) {
        while (navigationRootTopic.Parent != null && !navigationRootTopic.ContentType.Equals("PageGroup")) {
          navigationRootTopic = navigationRootTopic.Parent;
        }
      }

      if (navigationRootTopic?.Parent == null) navigationRootTopic = null;

      /*------------------------------------------------------------------------------------------------------------------------
      | Construct view model
      \-----------------------------------------------------------------------------------------------------------------------*/
      var navigationViewModel = new NavigationViewModel<NavigationTopicViewModel>() {
        NavigationRoot = await HierarchicalTopicMappingService.GetRootViewModelAsync(navigationRootTopic),
        CurrentKey = CurrentTopic?.GetUniqueKey()
      };

      /*------------------------------------------------------------------------------------------------------------------------
      | Return the corresponding view
      \-----------------------------------------------------------------------------------------------------------------------*/
      return PartialView(navigationViewModel);

    }
    /*==========================================================================================================================
    | METHOD: INVOKE (ASYNC)
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Provides the calls-to-action for the current page, which may change based on the current context.
    /// </summary>
    public async Task<IViewComponentResult> InvokeAsync() {

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish variables
      \-----------------------------------------------------------------------------------------------------------------------*/
      var currentTopic          = CurrentTopic;

      /*------------------------------------------------------------------------------------------------------------------------
      | Identify navigation root
      >-------------------------------------------------------------------------------------------------------------------------
      | The navigation root in the case of the main menu is the namespace; i.e., the first topic underneath the root.
      \-----------------------------------------------------------------------------------------------------------------------*/
      var navigationRootTopic = HierarchicalTopicMappingService.GetHierarchicalRoot(currentTopic, 3, "Web");

      /*------------------------------------------------------------------------------------------------------------------------
      | Validate conditions
      \-----------------------------------------------------------------------------------------------------------------------*/
      Contract.Assume(navigationRootTopic, $"The root topic could not be identified for the page-level navigation.");
      Contract.Assume(CurrentTopic, $"The current topic could not be identified for the page-level navigation.");

      /*------------------------------------------------------------------------------------------------------------------------
      | Construct view model
      \-----------------------------------------------------------------------------------------------------------------------*/
      var navigationViewModel = new NavigationViewModel<NavigationTopicViewModel>() {
        NavigationRoot = await HierarchicalTopicMappingService.GetRootViewModelAsync(navigationRootTopic).ConfigureAwait(true),
        CurrentWebPath = CurrentTopic?.GetWebPath()
      };

      /*------------------------------------------------------------------------------------------------------------------------
      | Return the corresponding view
      \-----------------------------------------------------------------------------------------------------------------------*/
      return View(navigationViewModel);

    }
Ejemplo n.º 4
0
    /*==========================================================================================================================
    | METHOD: INVOKE (ASYNC)
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Provides the pagel-level navigation menu for the current page, which exposes one tier of navigation from the nearest
    ///   page group.
    /// </summary>
    public async Task<IViewComponentResult> InvokeAsync() {

      /*------------------------------------------------------------------------------------------------------------------------
      | Retrieve root topic
      \-----------------------------------------------------------------------------------------------------------------------*/
      var navigationRootTopic = GetNavigationRoot();

      /*------------------------------------------------------------------------------------------------------------------------
      | Construct view model
      \-----------------------------------------------------------------------------------------------------------------------*/
      var navigationViewModel = new UnitListViewModel() {
        NavigationRoot = await MapNavigationTopicViewModels(navigationRootTopic).ConfigureAwait(true),
        CurrentWebPath = CurrentTopic?.GetWebPath()?? HttpContext.Request.Path
      };

      /*------------------------------------------------------------------------------------------------------------------------
      | Set current status
      \-----------------------------------------------------------------------------------------------------------------------*/
      foreach (var trackedNavigationViewModel in navigationViewModel.NavigationRoot.Children) {
        trackedNavigationViewModel.IsVisited = IsComplete(trackedNavigationViewModel.Key);
      }

      /*------------------------------------------------------------------------------------------------------------------------
      | Write course cookie
      \-----------------------------------------------------------------------------------------------------------------------*/
      var isCourseNowComplete   = navigationViewModel.NavigationRoot.Children.All(t => t.IsVisited is true);
      var wasCourseComplete     = IsComplete(CurrentTopic.Key);

      if (isCourseNowComplete != wasCourseComplete) {
        HttpContext.Response.Cookies.Append(
          $"Status{CurrentTopic.Key}",
          isCourseNowComplete.ToString(),
          new Microsoft.AspNetCore.Http.CookieOptions() {
            Path                = CurrentTopic.Parent.GetWebPath(),
            Expires             = DateTime.Now.AddYears(20)
          }
        );
        navigationViewModel.TrackingEvents.Add(
          new TrackingEventViewModel("Courses", isCourseNowComplete? "EndCourse" : "StartCourse", CurrentTopic.Key)
        );
      }

      /*------------------------------------------------------------------------------------------------------------------------
      | Return the corresponding view
      \-----------------------------------------------------------------------------------------------------------------------*/
      return View(navigationViewModel);

    }
Ejemplo n.º 5
0
    /*==========================================================================================================================
    | METHOD: INVOKE (ASYNC)
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Provides the pagel-level navigation menu for the current page, which exposes one tier of navigation from the nearest
    ///   page group.
    /// </summary>
    public async Task<IViewComponentResult> InvokeAsync() {

      /*------------------------------------------------------------------------------------------------------------------------
      | Retrieve root topic
      \-----------------------------------------------------------------------------------------------------------------------*/
      var navigationRootTopic = GetNavigationRoot();

      /*------------------------------------------------------------------------------------------------------------------------
      | Construct view model
      \-----------------------------------------------------------------------------------------------------------------------*/
      var navigationViewModel = new LessonListViewModel() {
        NavigationRoot = await MapNavigationTopicViewModels(navigationRootTopic).ConfigureAwait(true),
        CurrentWebPath = CurrentTopic?.GetWebPath()?? HttpContext.Request.Path
      };

      /*------------------------------------------------------------------------------------------------------------------------
      | Write lesson cookie
      \-----------------------------------------------------------------------------------------------------------------------*/
      if (!IsVisited(CurrentTopic.Key)) {
        HttpContext.Response.Cookies.Append(
          $"Visited{CurrentTopic.Key}",
          "1",
          new Microsoft.AspNetCore.Http.CookieOptions() {
            Path                = CurrentTopic.Parent.GetWebPath(),
            Expires             = DateTime.Now.AddYears(20)
          }
        );
      }

      /*------------------------------------------------------------------------------------------------------------------------
      | Set visit status
      \-----------------------------------------------------------------------------------------------------------------------*/
      foreach (var trackedNavigationViewModel in navigationViewModel.NavigationRoot.Children) {
        var isCurrent = CurrentTopic.Key.Equals(trackedNavigationViewModel.Key, StringComparison.OrdinalIgnoreCase);
        var isVisited = IsVisited(trackedNavigationViewModel.Key);
        trackedNavigationViewModel.IsVisited = isCurrent? true : isVisited? (bool?)true : null;
      }

      /*------------------------------------------------------------------------------------------------------------------------
      | Write unit cookie
      \-----------------------------------------------------------------------------------------------------------------------*/
      var isUnitNowComplete     = navigationViewModel.NavigationRoot.Children.All(t => t.IsVisited is true);
      var wasUnitComplete       = IsUnitComplete();

      if (isUnitNowComplete != wasUnitComplete) {
        HttpContext.Response.Cookies.Append(
          $"Status{CurrentTopic.Parent.Key}",
          isUnitNowComplete.ToString(),
          new Microsoft.AspNetCore.Http.CookieOptions() {
            Path                = CurrentTopic.Parent.Parent.GetWebPath(),
            Expires             = DateTime.Now.AddYears(20)
          }
        );
        navigationViewModel.TrackingEvents.Add(
          new TrackingEventViewModel(
            "Courses",
            isUnitNowComplete? "EndUnit" : "StartUnit",
            $"{CurrentTopic.Parent.Parent.Key}:{CurrentTopic.Parent.Key}"
          )
        );
      }

      /*------------------------------------------------------------------------------------------------------------------------
      | Return the corresponding view
      \-----------------------------------------------------------------------------------------------------------------------*/
      return View(navigationViewModel);

    }