Esempio n. 1
0
        private static MvcHtmlString DropDownList(HtmlHelper helper, EntityCombo entityCombo)
        {
            List <SelectListItem> items = new List <SelectListItem>();

            items.Add(new SelectListItem()
            {
                Text = "-", Value = ""
            });

            List <Lite <IEntity> > data = entityCombo.Data != null?entityCombo.Data.ToList() :
                                              AutocompleteUtils.FindAllLite(entityCombo.Implementations.Value).Cast <Lite <IEntity> >().ToList();

            if (entityCombo.SortElements)
            {
                data = data.OrderBy(a => a.ToString()).ToList();
            }

            var current = entityCombo.UntypedValue is IEntity ? ((IEntity)entityCombo.UntypedValue)?.ToLite() :
                          entityCombo.UntypedValue as Lite <IEntity>;

            if (current != null && !data.Contains(current))
            {
                data.Add(current);
            }

            items.AddRange(
                data.Select(lite => new SelectListItem()
            {
                Text     = lite.ToString(),
                Value    = lite.Key(),
                Selected = lite.Is(current)
            }));


            entityCombo.ComboHtmlProperties.AddCssClass("form-control");

            if (entityCombo.ComboHtmlProperties.ContainsKey("onchange"))
            {
                throw new InvalidOperationException("EntityCombo cannot have onchange html property, use onEntityChanged instead");
            }

            entityCombo.ComboHtmlProperties.Add("onchange", entityCombo.SFControlThen("combo_selected()"));

            if (entityCombo.Size > 0)
            {
                entityCombo.ComboHtmlProperties.AddCssClass("sf-entity-list");
                entityCombo.ComboHtmlProperties.Add("size", Math.Min(entityCombo.Size, items.Count - 1));
            }

            if (entityCombo.PlaceholderLabels && !entityCombo.ComboHtmlProperties.ContainsKey("placeholder"))
            {
                entityCombo.ComboHtmlProperties.Add("placeholder", entityCombo.LabelText);
            }

            return(helper.SafeDropDownList(
                       entityCombo.Compose(EntityComboKeys.Combo),
                       items,
                       entityCombo.ComboHtmlProperties));
        }
Esempio n. 2
0
        public List <Lite <TypeEntity> > FindMainEntityType(string subString, int count)
        {
            var list = TypeLogic.TypeToEntity
                       .Where(kvp => typeof(ICaseMainEntity).IsAssignableFrom(kvp.Key))
                       .Select(kvp => kvp.Value.ToLite());

            return(AutocompleteUtils.Autocomplete(list, subString, count));
        }
Esempio n. 3
0
        public override List <Lite <Entity> > Autocomplete(Implementations implementations, string subString, int count)
        {
            if (string.IsNullOrEmpty(subString))
            {
                return(new List <Lite <Entity> >());
            }

            return(AutocompleteUtils.FindLiteLike(implementations, subString, 5));
        }
        public JsonNetResult Autocomplete(string types, string q, int l)
        {
            Type[] typeArray = EntityBase.ParseTypes(types);
            if (typeArray == null)
            {
                throw new ArgumentException("ImplementedByAll not allowed in Autocomplete");
            }

            List <Lite <Entity> > lites = AutocompleteUtils.FindLiteLike(Implementations.By(typeArray), q, l);

            var result = lites.Select(o => new AutocompleteResult(o)).ToList();

            return(this.JsonNet(result));
        }
Esempio n. 5
0
    internal List <Lite <IWorkflowNodeEntity> > Autocomplete(string subString, int count, List <Lite <IWorkflowNodeEntity> > excludes)
    {
        var events     = AutocompleteUtils.Autocomplete(Events.Where(a => a.Value.Type == WorkflowEventType.Finish).Select(a => a.Key), subString, count);
        var activities = AutocompleteUtils.Autocomplete(Activities.Keys, subString, count);
        var gateways   = AutocompleteUtils.Autocomplete(Gateways.Keys, subString, count);

        return(new Sequence <Lite <IWorkflowNodeEntity> >()
        {
            events,
            activities,
            gateways
        }
               .Except(excludes.EmptyIfNull())
               .OrderByDescending(a => a.ToString() !.Length)
               .Take(count)
               .ToList());
    }
Esempio n. 6
0
        public async Task <List <Lite <Entity> > > FetchAllLites(string types, CancellationToken token)
        {
            Implementations implementations = ParseImplementations(types);

            return(await AutocompleteUtils.FindAllLiteAsync(implementations, token));
        }
Esempio n. 7
0
        public async Task <List <Lite <Entity> > > FindLiteLike(string types, string subString, int count, CancellationToken token)
        {
            Implementations implementations = ParseImplementations(types);

            return(await AutocompleteUtils.FindLiteLikeAsync(implementations, subString, count, token));
        }
Esempio n. 8
0
        private static MvcHtmlString InternalEntityListCheckbox <T>(this HtmlHelper helper, EntityListCheckbox entityListCheckBox)
        {
            if (!entityListCheckBox.Visible || entityListCheckBox.HideIfNull && entityListCheckBox.UntypedValue == null)
            {
                return(MvcHtmlString.Empty);
            }

            var elementType = entityListCheckBox.Type.ElementType();

            if (!elementType.IsIEntity() && !elementType.IsLite())
            {
                throw new InvalidOperationException("EntityCombo can only be done for an identifiable or a lite, not for {0}".FormatWith(elementType.CleanType()));
            }

            HtmlStringBuilder sb = new HtmlStringBuilder();

            using (sb.SurroundLine(new HtmlTag("fieldset", entityListCheckBox.Prefix).Class("SF-repeater-field SF-control-container SF-avoid-child-errors")))
            {
                sb.AddLine(helper.Hidden(entityListCheckBox.Compose(EntityListBaseKeys.ListPresent), ""));

                using (sb.SurroundLine(new HtmlTag("div", entityListCheckBox.Compose("hidden")).Class("hide")))
                {
                }

                using (sb.SurroundLine(new HtmlTag("legend")))
                    using (sb.SurroundLine(new HtmlTag("div", entityListCheckBox.Compose("header"))))
                    {
                        sb.AddLine(new HtmlTag("span").InnerHtml(entityListCheckBox.LabelHtml ?? entityListCheckBox.LabelText.FormatHtml()).ToHtml());

                        using (sb.SurroundLine(new HtmlTag("span", entityListCheckBox.Compose("shownButton")).Class("pull-right")))
                        {
                            sb.AddLine(EntityButtonHelper.Create(helper, entityListCheckBox, btn: false));
                            sb.AddLine(EntityButtonHelper.Find(helper, entityListCheckBox, btn: false));
                        }
                    }

                using (sb.SurroundLine(new HtmlTag("div").Id(entityListCheckBox.Compose(EntityRepeaterKeys.ItemsContainer)).Attr("style", GetStyle(entityListCheckBox))))
                {
                    IEnumerable <Lite <IEntity> > data = entityListCheckBox.Data ?? AutocompleteUtils.FindAllLite(entityListCheckBox.Implementations.Value).OrderBy(a => a.ToString());

                    if (entityListCheckBox.UntypedValue != null)
                    {
                        var already = TypeContextUtilities.TypeElementContext((TypeContext <MList <T> >)entityListCheckBox.Parent).ToDictionary(a => AsLite(a.Value), "repeated elements");

                        List <Lite <IEntity> > liteList = data.Except(already.Keys).ToList();

                        List <T> typedList = typeof(Lite <IEntity>).IsAssignableFrom(typeof(T)) ? liteList.Cast <T>().ToList(): Database.RetrieveFromListOfLite(liteList).Cast <T>().ToList();

                        var extra = typedList.Select((e, i) => new TypeElementContext <T>(e, (TypeContext)entityListCheckBox.Parent, i + already.Count, null)).ToDictionary(a => AsLite(a.Value), "repeated elements");

                        foreach (var lite in data)
                        {
                            sb.Add(InternalRepeaterElement(helper, already.TryGetC(lite) ?? extra.GetOrThrow(lite), entityListCheckBox, already.ContainsKey(lite), lite));
                        }
                    }
                }

                if (entityListCheckBox.ElementType.IsEmbeddedEntity() && entityListCheckBox.Create)
                {
                    T embedded = (T)(object)new ConstructorContext(helper.ViewContext.Controller).ConstructUntyped(typeof(T));
                    TypeElementContext <T> templateTC = new TypeElementContext <T>(embedded, (TypeContext)entityListCheckBox.Parent, 0, null);
                    sb.AddLine(EntityBaseHelper.EmbeddedTemplate(entityListCheckBox, EntityBaseHelper.RenderContent(helper, templateTC, RenderContentMode.Content, entityListCheckBox), null));
                }

                sb.AddLine(entityListCheckBox.ConstructorScript(JsModule.Lines, "EntityListCheckbox"));
            }

            return(sb.ToHtml());
        }
Esempio n. 9
0
 public virtual List <Lite <Entity> > FindLiteLike(Implementations implementations, string subString, int count)
 {
     return(Return(MethodInfo.GetCurrentMethod(), implementations.ToString(),
                   () => AutocompleteUtils.FindLiteLike(implementations, subString, count)));
 }
Esempio n. 10
0
 public virtual List <Lite <Entity> > FindAllLite(Implementations implementations)
 {
     return(Return(MethodInfo.GetCurrentMethod(), implementations.ToString(),
                   () => AutocompleteUtils.FindAllLite(implementations)));
 }
Esempio n. 11
0
        public List <Lite <Entity> > FetchAllLites([FromUri] string types)
        {
            Implementations implementations = ParseImplementations(types);

            return(AutocompleteUtils.FindAllLite(implementations));
        }
Esempio n. 12
0
        public List <Lite <Entity> > FindLiteLike(string types, string subString, int count)
        {
            Implementations implementations = ParseImplementations(types);

            return(AutocompleteUtils.FindLiteLike(implementations, subString, count));
        }