Пример #1
0
        public static void RenderSpanText(RenderContext context, String cssClass, Bind binding, String value = null)
        {
            if (binding == null && value == null)
            {
                return;
            }
            var tag = new TagBuilder("span", cssClass);

            if (binding != null)
            {
                tag.MergeAttribute("v-text", binding.GetPathFormat(context));
            }
            tag.RenderStart(context);
            if (value != null)
            {
                context.Writer.Write(value);
            }
            tag.RenderEnd(context);
        }
Пример #2
0
        internal void RenderColumn(RenderContext context, Int32 colIndex)
        {
            CheckValid();
            var column = new TagBuilder("data-grid-column");

            SetColumnRole(column);

            MergeBindingAttribute(context, column, "header", nameof(Header), Header);

            MergeBindingAttributeBool(column, context, "v-if", nameof(If), If);

            MergeBoolAttribute(column, context, nameof(Editable), Editable);
            if (_noPadding)
            {
                column.MergeAttribute(":no-padding", "true");
            }
            if (Sort != null)
            {
                column.MergeAttribute(":sort", Sort.Value.ToString().ToLowerInvariant());
            }
            if (SortProperty != null)
            {
                column.MergeAttribute("sort-prop", SortProperty);
            }
            if (Small != null)
            {
                column.MergeAttribute(":small", Small.Value.ToString().ToLowerInvariant());
            }

            var boldBind = GetBinding(nameof(Bold));

            if (boldBind != null)
            {
                column.MergeAttribute("bold", $"{{{boldBind.GetPath(context)}}}");
            }
            else if (Bold != null)
            {
                column.MergeAttribute("bold", Bold.Value.ToString().ToLowerInvariant());
            }

            MergeBoolAttribute(column, context, nameof(Fit), Fit);
            if (Width != null)
            {
                column.MergeAttribute("width", Width.Value);
            }
            var iconBind = GetBinding(nameof(Icon));

            if (iconBind != null)
            {
                column.MergeAttribute("bind-icon", iconBind.Path /*without context*/);
            }
            else if (Icon != Icon.NoIcon)
            {
                column.MergeAttribute("icon", Icon.ToString().ToKebabCase());
            }
            if (Wrap != WrapMode.Default)
            {
                column.MergeAttribute("wrap", Wrap.ToString().ToKebabCase(), true);
            }

            var markBind = GetBinding(nameof(Mark));

            if (markBind != null)
            {
                column.MergeAttribute("mark", markBind.Path /*!without context!*/);
            }
            else if (Mark != null)
            {
                throw new XamlException("The Mark property must be a binding");
            }

            CreateEditable();

            Boolean isTemplate = Content is UIElementBase;
            String  tmlId      = null;

            if (!isTemplate)
            {
                // always content without a SEMICOLON!
                var bindProp = GetBinding(nameof(Content));
                if (bindProp != null)
                {
                    column.MergeAttribute("content", bindProp.Path /*!without context!*/);
                    if (bindProp.DataType != DataType.String)
                    {
                        column.MergeAttribute("data-type", bindProp.DataType.ToString());
                    }
                    if (bindProp.HideZeros)
                    {
                        column.MergeAttribute(":hide-zeros", "true");
                    }
                    if (!String.IsNullOrEmpty(bindProp.Format))
                    {
                        column.MergeAttribute("format", bindProp.Format);
                    }
                }
                else if (Content != null)
                {
                    throw new XamlException($"The Content property must be a binding ({Content})");
                }
            }

            Bind ctBind = GetBinding(nameof(ControlType));

            if (ctBind != null)
            {
                column.MergeAttribute(":control-type", ctBind.Path /*!without context!*/);
            }
            else if (ControlType != ColumnControlType.Default)
            {
                column.MergeAttribute("control-type", ControlType.ToString().ToLowerInvariant());
            }

            var alignProp = GetBinding(nameof(Align));

            if (alignProp != null)
            {
                column.MergeAttribute(":align", alignProp.Path /*!without context!*/, true);
            }
            else if (Align != TextAlign.Default)
            {
                column.MergeAttribute("align", Align.ToString().ToLowerInvariant(), true);
            }

            if (isTemplate)
            {
                tmlId = $"col{colIndex}";
                column.MergeAttribute("id", tmlId);
            }

            var cmdBind = GetBindingCommand(nameof(Command));

            if (cmdBind != null)
            {
                column.MergeAttribute(":command", cmdBind.GetCommand(context, indirect: true));
            }
            column.RenderStart(context);
            column.RenderEnd(context);
            if (isTemplate)
            {
                var templ = new TagBuilder("template");
                templ.MergeAttribute("slot", tmlId);
                templ.MergeAttribute("slot-scope", "cell");
                templ.RenderStart(context);
                using (var ctx = new ScopeContext(context, "cell.row", null))
                {
                    (Content as UIElementBase).RenderElement(context);
                }
                templ.RenderEnd(context);
            }
        }
Пример #3
0
        void GenerateFromDataModel(RenderContext context, String propertyName)
        {
            var dm = context.DataModel;

            if (dm == null)
            {
                return;
            }
            var coll   = dm.Eval <List <ExpandoObject> >(propertyName);
            var rootMd = dm.Metadata["TRoot"];

            if (!rootMd.Fields.ContainsKey(propertyName))
            {
                throw new XamlException($"Pproperty {propertyName} not found in the root of the data model");
            }
            var fieldData = rootMd.Fields[propertyName];
            var fieldsMD  = dm.Metadata[fieldData.RefObject];

            var header = new SheetRow()
            {
                Style = RowStyle.Header
            };
            var dataRow = new SheetRow();

            Header.Add(header);

            var dataSect = new SheetSection();

            dataSect.SetBinding(nameof(dataSect.ItemsSource), new Bind(propertyName));
            dataSect.Children.Add(dataRow);
            Sections.Add(dataSect);

            foreach (var field in fieldsMD.Fields)
            {
                header.Cells.Add(new SheetCell()
                {
                    Content = field.Key
                });
                var cellBind = new Bind(field.Key);
                cellBind.SetWrapped();
                var cell = new SheetCell();
                cell.SetBinding(nameof(cell.Content), cellBind);
                switch (field.Value.SqlDataType)
                {
                case SqlDataType.DateTime:
                    cellBind.DataType = DataType.DateTime;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Center;
                    break;

                case SqlDataType.Date:
                    cellBind.DataType = DataType.Date;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Center;
                    break;

                case SqlDataType.Time:
                    cellBind.DataType = DataType.Time;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Center;
                    break;

                case SqlDataType.Currency:
                    cellBind.DataType = DataType.Currency;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Right;
                    break;

                case SqlDataType.Float:
                case SqlDataType.Decimal:
                    cellBind.DataType = DataType.Number;
                    cell.Wrap         = WrapMode.NoWrap;
                    cell.Align        = TextAlign.Right;
                    break;

                case SqlDataType.Int:
                case SqlDataType.Bigint:
                    cell.Align = TextAlign.Right;
                    cell.Wrap  = WrapMode.NoWrap;
                    break;
                }
                dataRow.Cells.Add(cell);
            }
        }
Пример #4
0
        internal override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null)
        {
            if (SkipRender(context))
            {
                return;
            }
            var td = new TagBuilder("td");

            onRender?.Invoke(td);

            MergeAttributes(td, context);

            var boldBind   = GetBinding(nameof(Bold));
            var italicBind = GetBinding(nameof(Italic));

            if (boldBind != null || italicBind != null)
            {
                var sb = new StringBuilder("{");
                if (boldBind != null)
                {
                    sb.Append($"bold: {boldBind.GetPath(context)}, ");
                }
                if (italicBind != null)
                {
                    sb.Append($"italic: {italicBind.GetPath(context)}, ");
                }
                sb.RemoveTailComma();
                sb.Append("}");
                td.MergeAttribute(":class", sb.ToString());
            }
            td.AddCssClassBoolNo(Bold, "bold");
            td.AddCssClassBoolNo(Italic, "italic");
            td.AddCssClassBool(Gray, "gray");

            MergeContent(td, context);

            if (Align != TextAlign.Left)
            {
                td.AddCssClass("text-" + Align.ToString().ToLowerInvariant());
            }

            if (VAlign != VerticalAlign.Default)
            {
                td.AddCssClass($"valign-{VAlign.ToString().ToLowerInvariant()}");
            }

            if (Content is ITableControl)
            {
                td.AddCssClass("ctrl");
            }

            Bind isBind = GetBinding(nameof(ItemsSource));

            if (isBind != null)
            {
                td.MergeAttribute("v-for", $"(cell, cellIndex) in {isBind.GetPath(context)}");
                td.MergeAttribute(":key", "cellIndex");
            }
            MergeAttributeInt32(td, context, nameof(ColSpan), "colspan", ColSpan);
            MergeAttributeInt32(td, context, nameof(RowSpan), "rowspan", RowSpan);
            td.RenderStart(context);
            RenderContent(context);

            /*
             * Никакого толку, содержимое в атрибуте
             * if (Validate)
             * {
             * var val = new TagBuilder("validator-control");
             * val.MergeAttribute(":item", "row");
             * val.MergeAttribute("prop", "Sum");
             * val.Render(context);
             * }*/
            td.RenderEnd(context);
        }
Пример #5
0
        internal void RenderStart(RenderContext context, Action <TagBuilder> onRender = null)
        {
            if (context.IsDialog && RunAt == RunMode.ServerUrl)
            {
                throw new XamlException("RunAt='ServerUrl' is not allowed in dialogs");
            }
            String cwTag = "collection-view";

            if (RunAt == RunMode.Server)
            {
                cwTag = "collection-view-server";
            }
            else if (RunAt == RunMode.ServerUrl)
            {
                cwTag = "collection-view-server-url";
            }
            _outer = new TagBuilder(cwTag, "cw", IsInGrid);
            onRender?.Invoke(_outer);
            if (Parent is Page)
            {
                _outer.AddCssClass("cw-absolute");
            }
            MergeAttributes(_outer, context);
            Bind itemsSource = GetBinding(nameof(ItemsSource));

            if (itemsSource != null)
            {
                _outer.MergeAttribute(":items-source", itemsSource.GetPath(context));
            }

            if (Sort != null)
            {
                _outer.MergeAttribute(":initial-sort", Sort.GetJsValue(context));
            }
            if (Filter != null)
            {
                _outer.MergeAttribute(":initial-filter", Filter.GetJsValue(context));
                _outer.MergeAttribute(":persistent-filter", Filter.GetPersistentValue(context));
                if (RunAt == RunMode.Client)
                {
                    if (String.IsNullOrEmpty(FilterDelegate))
                    {
                        throw new XamlException("To filter on the client, a FilterDelegate is required");
                    }
                    _outer.MergeAttribute(":filter-delegate", $"$delegate('{FilterDelegate}')");
                }
            }

            if (GroupBy != null)
            {
                _outer.MergeAttribute(":initial-group", GroupBy.GetJsValue(context));
            }

            if (PageSize != null)
            {
                _outer.MergeAttribute(":initial-page-size", PageSize.Value.ToString());
            }

            _outer.RenderStart(context);
            _inner = new TagBuilder("template");
            _inner.MergeAttribute("slot-scope", "Parent");
            _inner.RenderStart(context);
        }