Beispiel #1
0
        public override async Task <IViewProviderResult> BuildIndexAsync(Question question, IViewProviderContext updater)
        {
            // Get top labels
            var labels = await _labelStore.QueryAsync()
                         .Take(1, 5, false)
                         .Select <LabelQueryParams>(async q =>
            {
                q.FeatureId.Equals(await GetFeatureIdAsync());
            })
                         .OrderBy("TotalEntities", OrderBy.Desc)
                         .ToList();

            return(Views(View <LabelsViewModel <Label> >("Question.Labels.Index.Sidebar", model =>
            {
                model.Labels = labels?.Data;
                return model;
            }).Zone("content-right").Order(2)
                         ));
        }
        public async Task <IViewComponentResult> InvokeAsync(Topic entity)
        {
            // Get entity labels
            var labels = await _labelStore.QueryAsync()
                         .Take(1, 10)
                         .Select <LabelQueryParams>(q =>
            {
                q.EntityId.Equals(entity.Id);
            })
                         .OrderBy("Name", OrderBy.Desc)
                         .ToList();

            return(View(new LabelsViewModel <Label>
            {
                Labels = labels?.Data
            }));
        }
Beispiel #3
0
        public async Task <IPagedResults <TModel> > GetResultsAsync(LabelIndexOptions options, PagerOptions pager)
        {
            return(await _labelStore.QueryAsync()
                   .Take(pager.Page, pager.Size, pager.CountTotal)
                   .Select <LabelQueryParams>(q =>
            {
                if (options.FeatureId > 0)
                {
                    q.FeatureId.Equals(options.FeatureId);
                }

                if (!String.IsNullOrEmpty(options.Search))
                {
                    q.Keywords.Like(options.Search);
                }
            })
                   .OrderBy(options.Sort.ToString(), options.Order)
                   .ToList());
        }
Beispiel #4
0
        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 <Topic>)] as EntityIndexViewModel <Topic>;

            if (viewModel == null)
            {
                throw new Exception($"A view model of type {typeof(EntityIndexViewModel<Topic>).ToString()} has not been registered on the HttpContext!");
            }

            var indexViewModel = new EntityIndexViewModel <Topic>
            {
                Options = viewModel?.Options,
                Pager   = viewModel?.Pager
            };

            // Get labels for feature
            var labels = await _labelStore.QueryAsync()
                         .Take(1, 10)
                         .Select <LabelQueryParams>(q =>
            {
                if (viewModel.Options.FeatureId != null)
                {
                    q.FeatureId.Equals(viewModel.Options.FeatureId.Value);
                }
            })
                         .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("tools").Order(1),
                       View <EntityIndexViewModel <Topic> >("Home.Display.Content", model => indexViewModel).Zone("content").Order(1),
                       View <LabelsViewModel <Label> >("Topic.Labels.Index.Sidebar", model =>
            {
                model.SelectedLabelId = label?.Id ?? 0;
                model.Labels = labels?.Data;
                return model;
            }).Zone("sidebar").Order(1)
                       ));
        }
Beispiel #5
0
        private async Task <IEnumerable <LabelApiResult> > BuildSelectionsAsync(LabelDropDownViewModel model)
        {
            if (model.SelectedLabels == null)
            {
                return(new List <LabelApiResult>());
            }

            if (((int[])model.SelectedLabels).Length == 0)
            {
                return(new List <LabelApiResult>());
            }

            // Get all labels for selected ids
            var labels = await _labelStore.QueryAsync()
                         .Select <LabelQueryParams>(q =>
            {
                q.Id.IsIn(model.SelectedLabels.ToArray());
            })
                         .OrderBy("TotalEntities", OrderBy.Desc)
                         .ToList();

            // Build results
            var results = new List <LabelApiResult>();

            if (labels?.Data != null)
            {
                foreach (var label in labels.Data)
                {
                    results.Add(new LabelApiResult()
                    {
                        Id          = label.Id,
                        Name        = label.Name,
                        Description = label.Description,
                        ForeColor   = label.ForeColor,
                        BackColor   = label.BackColor
                    });
                }
            }
            return(results);
        }
Beispiel #6
0
        public override async Task <IViewProviderResult> BuildDisplayAsync(Label label, IViewProviderContext context)
        {
            // Get topic index view model from context
            var viewModel = context.Controller.HttpContext.Items[typeof(EntityIndexViewModel <Article>)] as EntityIndexViewModel <Article>;

            if (viewModel == null)
            {
                throw new Exception($"A view model of type {typeof(EntityIndexViewModel<Article>).ToString()} has not been registered on the HttpContext!");
            }

            var indexViewModel = new EntityIndexViewModel <Article>
            {
                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 <Article> >("Home.Display.Content", model => indexViewModel).Zone("content").Order(1),
                       View <LabelsViewModel <Label> >("Article.Labels.Index.Sidebar", model =>
            {
                model.SelectedLabelId = label?.Id ?? 0;
                model.Labels = labels?.Data;
                return model;
            }).Zone("content-right").Order(1)
                       ));
        }
Beispiel #7
0
        // ----------

        async Task <ICommandResultBase> InstallInternalAsync(IShellFeature feature)
        {
            // Validate

            if (feature == null)
            {
                throw new ArgumentNullException(nameof(feature));
            }

            if (string.IsNullOrEmpty(feature.ModuleId))
            {
                throw new ArgumentNullException(nameof(feature.ModuleId));
            }

            var user = await _contextFacade.GetAuthenticatedUserAsync();

            // Get all feature tags
            var labels = await _labelStore.QueryAsync()
                         .Select <LabelQueryParams>(Q =>
            {
                Q.FeatureId.Equals(feature.Id);
            })
                         .ToList();

            // Associate every tag with at least 1 entity

            var output = new CommandResultBase();

            if (labels != null)
            {
                var entities = await _entityStore.QueryAsync()
                               .Select <EntityQueryParams>(q =>
                {
                    q.FeatureId.Equals(feature.Id);
                })
                               .ToList();

                var alreadyAdded = new Dictionary <int, Entity>();
                foreach (var label in labels?.Data)
                {
                    var randomEntities = GetRandomEntities(entities?.Data, alreadyAdded);
                    if (randomEntities == null)
                    {
                        return(output.Success());
                    }
                    foreach (var entity in randomEntities)
                    {
                        var result = await _entityLabelManager.CreateAsync(new EntityLabel()
                        {
                            EntityId      = entity.Id,
                            LabelId       = label.Id,
                            CreatedUserId = user?.Id ?? 0,
                            CreatedDate   = DateTime.UtcNow
                        });

                        if (!result.Succeeded)
                        {
                            return(output.Failed(result.Errors.ToArray()));
                        }
                    }
                }
            }

            return(output.Success());
        }