Example #1
0
        public virtual void SetSearchViewableAndCreable(FindOptions findOptions, QueryDescription description)
        {
            var             entityColumn    = description.Columns.SingleEx(a => a.IsEntity);
            Type            entitiesType    = Lite.Extract(entityColumn.Type);
            Implementations?implementations = entityColumn.Implementations;

            if (findOptions.Navigate)
            {
                findOptions.Navigate = implementations.Value.IsByAll ? true : implementations.Value.Types.Any(t => Navigator.IsNavigable(t, null, true));
            }
            if (findOptions.Create)
            {
                findOptions.Create = (implementations.Value.IsByAll ? true : implementations.Value.Types.Any(t => Navigator.IsCreable(t, true)));
            }
        }
Example #2
0
        protected internal virtual PartialViewResult PopupControl(ControllerBase controller, TypeContext typeContext, PopupOptionsBase popupOptions)
        {
            Type cleanType = typeContext.UntypedValue.GetType();

            ModifiableEntity entity = (ModifiableEntity)typeContext.UntypedValue;

            AssertViewableEntitySettings(entity);

            controller.ViewData.Model = typeContext;
            controller.ViewData[ViewDataKeys.PartialViewName] = popupOptions.PartialViewName ?? Navigator.OnPartialViewName(entity);
            typeContext.ViewOverrides = Navigator.EntitySettings(entity.GetType()).GetViewOverrides();

            bool isReadOnly = popupOptions.ReadOnly ?? Navigator.IsReadOnly(entity);

            if (isReadOnly)
            {
                typeContext.ReadOnly = true;
            }

            ViewMode mode = popupOptions.ViewMode;

            controller.ViewData[ViewDataKeys.ViewMode]       = mode;
            controller.ViewData[ViewDataKeys.ShowOperations] = popupOptions.ShowOperations;
            if (mode == ViewMode.View)
            {
                controller.ViewData[ViewDataKeys.RequiresSaveOperation] = ((PopupViewOptions)popupOptions).RequiresSaveOperation ?? EntityKindCache.RequiresSaveOperation(entity.GetType());
            }

            return(new PartialViewResult
            {
                ViewName = PopupControlView,
                ViewData = controller.ViewData,
                TempData = controller.TempData
            });
        }
Example #3
0
        public void FillViewDataForViewing(ControllerBase controller, IRootEntity rootEntity, NavigateOptions options)
        {
            TypeContext tc = TypeContextUtilities.UntypedNew(rootEntity, "");

            controller.ViewData.Model = tc;

            var entity = (ModifiableEntity)rootEntity;

            controller.ViewData[ViewDataKeys.PartialViewName] = options.PartialViewName ?? Navigator.OnPartialViewName(entity);
            tc.ViewOverrides = Navigator.EntitySettings(entity.GetType()).GetViewOverrides();

            if (controller.ViewData[ViewDataKeys.TabId] == null)
            {
                controller.ViewData[ViewDataKeys.TabId] = GetOrCreateTabID(controller);
            }

            controller.ViewData[ViewDataKeys.ShowOperations] = options.ShowOperations;

            controller.ViewData[ViewDataKeys.WriteEntityState] = options.WriteEntityState || (bool?)controller.ViewData[ViewDataKeys.WriteEntityState] == true;

            AssertViewableEntitySettings(entity);

            tc.ReadOnly = options.ReadOnly ?? Navigator.IsReadOnly(entity);
        }
Example #4
0
        public static MappingContext <T> ApplyChanges <T>(this T entity, ControllerBase controller, string prefix = null, PropertyRoute route = null, SortedList <string, string> inputs = null) where T : ModifiableEntity
        {
            Mapping <T> mapping = (Mapping <T>)Navigator.EntitySettings(typeof(T)).UntypedMappingMain;

            return(ApplyChanges <T>(entity, controller, mapping, prefix, route, inputs));
        }
Example #5
0
        public R GetRuntimeValue <R>(MappingContext <T> ctx, PropertyRoute route)
            where R : class, T
        {
            if (AllowedMappings != null && !AllowedMappings.ContainsKey(typeof(R)))
            {
                return((R)(object)ctx.None(ValidationMessage.Type0NotAllowed.NiceToString().FormatWith(typeof(R))));
            }

            Mapping <R>    mapping = (Mapping <R>)(AllowedMappings?.TryGetC(typeof(R)) ?? Navigator.EntitySettings(typeof(R)).UntypedMappingLine);
            SubContext <R> sc      = new SubContext <R>(ctx.Prefix, null, route, ctx)
            {
                Value = ctx.Value as R
            };                                                                                             // If the type is different, the AutoEntityMapping has the current value but EntityMapping just null

            sc.Value          = mapping(sc);
            ctx.SupressChange = sc.SupressChange;
            ctx.AddChild(sc);
            return(sc.Value);
        }
        static QuerySettings()
        {
            FormatRules = new List <FormatterRule>
            {
                new FormatterRule("object", c => true, c => new CellFormatter((h, o) =>
                {
                    return(o != null ? o.ToString().EncodeHtml() : MvcHtmlString.Empty);
                })
                {
                    WriteData = false
                }),

                new FormatterRule("Enum", c => c.Type.UnNullify().IsEnum, c => new CellFormatter((h, o) =>
                {
                    return(o != null ? ((Enum)o).NiceToString().EncodeHtml() : MvcHtmlString.Empty);
                })),

                new FormatterRule("Lite", c => c.Type.UnNullify().IsLite(), c => new CellFormatter((h, o) =>
                {
                    return(h.LightEntityLine((Lite <IEntity>)o, isSearch: false));
                })),

                new FormatterRule("Guid", c => c.Type.UnNullify() == typeof(Guid), c => new CellFormatter((h, o) =>
                {
                    return(o != null ? (new HtmlTag("span").Class("guid").SetInnerText(o.ToString().Start(5) + "…" + o.ToString().End(5))) : MvcHtmlString.Empty);
                })
                {
                    WriteData = true, TextAlign = "middle"
                }),

                new FormatterRule("DateTime", c => c.Type.UnNullify() == typeof(DateTime), c => new CellFormatter((h, o) =>
                {
                    return(o != null ? ((DateTime)o).ToUserInterface().ToString(c.Format).EncodeHtml() : MvcHtmlString.Empty);
                })
                {
                    WriteData = false, TextAlign = "right"
                }),

                new FormatterRule("TimeSpan", c => c.Type.UnNullify() == typeof(TimeSpan), c => new CellFormatter((h, o) =>
                {
                    return(o != null ? ((TimeSpan)o).ToString(c.Format).EncodeHtml() : MvcHtmlString.Empty);
                })
                {
                    WriteData = false, TextAlign = "right"
                }),

                new FormatterRule("Number", c => Reflector.IsNumber(c.Type) && c.Unit == null, c => new CellFormatter((h, o) =>
                {
                    return(o != null? ((IFormattable)o).ToString(c.Format, CultureInfo.CurrentCulture).EncodeHtml(): MvcHtmlString.Empty);
                })
                {
                    WriteData = false, TextAlign = "right"
                }),

                new FormatterRule("Number with Unit", c => Reflector.IsNumber(c.Type) && c.Unit.HasText(), c => new CellFormatter((h, o) =>
                {
                    if (o != null)
                    {
                        string s = ((IFormattable)o).ToString(c.Format, CultureInfo.CurrentCulture);
                        if (c.Unit.HasText())
                        {
                            s += " " + c.Unit;
                        }
                        return(s.EncodeHtml());
                    }
                    return(MvcHtmlString.Empty);
                })
                {
                    TextAlign = "right"
                }),

                new FormatterRule("bool", c => c.Type.UnNullify() == typeof(bool), c => new CellFormatter((h, o) =>
                {
                    return(o != null ? new HtmlTag("input")
                           .Attr("type", "checkbox")
                           .Attr("disabled", "disabled")
                           .Let(a => (bool)o ? a.Attr("checked", "checked") : a)
                           .ToHtml() : MvcHtmlString.Empty);
                })
                {
                    TextAlign = "center"
                }),
            };

            EntityFormatRules = new List <EntityFormatterRule>
            {
                new EntityFormatterRule(row => true, (h, row) =>
                {
                    if (Navigator.IsNavigable(row.Entity.EntityType, null, isSearch: true))
                    {
                        return(h.LightEntityLine(row.Entity, isSearch: true, innerText: EntityControlMessage.View.NiceToString()));
                    }
                    else
                    {
                        return(MvcHtmlString.Empty);
                    }
                }),
            };

            PropertyFormatters = new Dictionary <PropertyRoute, CellFormatter>();
        }