public override async Task <IViewProviderResult> BuildDisplayAsync(Label label, IViewProviderContext context) { // Get topic index view model from context var viewModel = _actionContextAccessor.ActionContext.HttpContext.Items[typeof(EntityIndexViewModel <Issue>)] as EntityIndexViewModel <Issue>; if (viewModel == null) { throw new Exception($"A view model of type {typeof(EntityIndexViewModel<Issue>).ToString()} has not been registered on the HttpContext!"); } var indexViewModel = new EntityIndexViewModel <Issue> { Options = viewModel?.Options, Pager = viewModel?.Pager }; // Get top 10 labels for feature var labels = await _labelStore.QueryAsync() .Take(10, false) .Select <LabelQueryParams>(async q => { q.FeatureId.Equals(await GetFeatureIdAsync()); }) .OrderBy("Entities", OrderBy.Desc) .ToList(); return(Views( View <Label>("Home.Display.Header", model => label).Zone("header").Order(1), View <Label>("Home.Display.Tools", model => label).Zone("header-right").Order(1), View <EntityIndexViewModel <Issue> >("Home.Display.Content", model => indexViewModel).Zone("content").Order(1), View <LabelsViewModel <Label> >("Issue.Labels.Index.Sidebar", model => { model.SelectedLabelId = label?.Id ?? 0; model.Labels = labels?.Data; return model; }).Zone("content-right").Order(1) )); }
async Task <EntityIndexViewModel <Entity> > GetIndexViewModel(EntityIndexViewModel <Entity> model) { // If full text is enabled add rank to sort options if (model.Options.Sort == SortBy.Rank) { var sortColumns = new List <SortColumn>() { new SortColumn() { Text = "Relevancy", Value = SortBy.Rank } }; sortColumns.AddRange(model.SortColumns); model.SortColumns = sortColumns; } // Build results var results = await _entityService .ConfigureQuery(async q => { // Hide private? if (!await _authorizationService.AuthorizeAsync(HttpContext.User, Permissions.ViewPrivateEntities)) { q.HidePrivate.True(); } // Hide hidden? if (!await _authorizationService.AuthorizeAsync(HttpContext.User, Permissions.ViewHiddenEntities)) { q.HideHidden.True(); } // Hide spam? if (!await _authorizationService.AuthorizeAsync(HttpContext.User, Permissions.ViewSpamEntities)) { q.HideSpam.True(); } // Hide deleted? if (!await _authorizationService.AuthorizeAsync(HttpContext.User, Permissions.ViewDeletedEntities)) { q.HideDeleted.True(); } }) .GetResultsAsync(model.Options, model.Pager); // Set pager total model.Pager.SetTotal(results?.Total ?? 0); model.Results = results; model.SortColumns = _defaultSortColumns; model.SortOrder = _defaultSortOrder; model.Filters = _defaultFilters; return(model); }