public void Render(RenderInfo info) { if (String.IsNullOrEmpty(info.FileName)) { throw new XamlException("No source for render"); } IProfileRequest request = _profile.CurrentRequest; String fileName = String.Empty; IXamlElement uiElem = null; using (request.Start(ProfileAction.Render, $"load: {info.FileTitle}")) { try { // XamlServices.Load sets IUriContext if (!String.IsNullOrEmpty(info.FileName)) { using (var fileStream = _host.ApplicationReader.FileStreamFullPathRO(info.FileName)) { RootFileName = info.FileName; ApplicationReader = _host.ApplicationReader; uiElem = XamlServices.Load(fileStream) as IXamlElement; } } else if (!String.IsNullOrEmpty(info.Text)) { uiElem = XamlServices.Parse(info.Text) as IXamlElement; } else { throw new XamlException("Xaml. There must be either a 'FileName' or a 'Text' property"); } if (uiElem == null) { throw new XamlException("Xaml. Root is not 'UIElement'"); } var stylesPath = _host.ApplicationReader.MakeFullPath(String.Empty, "styles.xaml"); if (_host.ApplicationReader.FileExists(stylesPath)) { using (var stylesStream = _host.ApplicationReader.FileStreamFullPathRO(stylesPath)) { if (stylesStream != null) { if (!(XamlServices.Load(stylesStream) is Styles styles)) { throw new XamlException("Xaml. Styles is not 'Styles'"); } if (uiElem is IRootContainer root) { root.SetStyles(styles); } } } } } finally { RootFileName = null; ApplicationReader = null; } } using (request.Start(ProfileAction.Render, $"render: {info.FileTitle}")) { RenderContext ctx = new RenderContext(uiElem, info) { RootId = info.RootId, Path = info.Path }; if (info.SecondPhase) { if (!(uiElem is ISupportTwoPhaseRendering twoPhaseRender)) { throw new XamlException("The two-phase rendering is not available"); } twoPhaseRender.RenderSecondPhase(ctx); } else { uiElem.RenderElement(ctx); } Grid.ClearAttached(); Splitter.ClearAttached(); FullHeightPanel.ClearAttached(); Toolbar.ClearAttached(); } if (uiElem is IDisposable disp) { disp.Dispose(); } }
internal String GetCommand(RenderContext context, Boolean indirect = false, String argument = null, XamlElement src = null) { if (indirect) { if (!IsIndirectSupported) { throw new XamlException($"Command '{Command}' is not available in this context"); } } switch (Command) { case CommandType.Unknown: throw new NotImplementedException($"Command required for BindCmd extension"); case CommandType.Refresh: case CommandType.Reload: return($"$reload({CommandArgument(context, nullable: true)})"); case CommandType.Requery: return("$requery()"); case CommandType.Save: return($"$save({{toast: {GetToast(context)}, options:{GetOptionsValid(context)}}})"); case CommandType.Clear: return($"{CommandArgument(context)}.$empty()"); case CommandType.Close: if (src != null) { var inlineModal = src.FindParent <InlineDialog>(); if (inlineModal != null) { return($"$inlineClose('{inlineModal.Id}', false)"); } } return(context.IsDialog ? "$modalClose()" : "$close()"); case CommandType.CloseOk: return(context.IsDialog ? "$modalClose(true)" : throw new XamlException("The command 'CloseOk' is allowed for Dialogs only")); case CommandType.SaveAndClose: if (context.IsDialog) { return($"$modalSaveAndClose(true, {GetOptionsValid(context)})"); } return($"$saveAndClose({{toast: {GetToast(context)}}})"); case CommandType.OpenSelected: return($"$openSelected({CommandUrl(context, decorate: true)}, {CommandArgument(context)}, {NewWindowJS}, {UpdateAfterArgument(context)})"); case CommandType.OpenSelectedFrame: return($"$openSelectedFrame({CommandUrl(context, decorate: true)}, {CommandArgument(context)}, {UpdateAfterArgument(context)})"); case CommandType.Select: return($"$modalSelect({CommandArgument(context)}, {GetOptionsValid(context)})"); case CommandType.SelectChecked: return($"$modalSelectChecked({CommandArgument(context)})"); case CommandType.RemoveSelected: return($"$removeSelected({CommandArgument(context)}, {GetConfirm(context)})"); case CommandType.DbRemove: return($"$dbRemove({CommandArgument(context)}, {GetConfirm(context)}, {GetOptions(context)})"); case CommandType.DbRemoveSelected: return($"$dbRemoveSelected({CommandArgument(context)}, {GetConfirm(context)}, {GetOptions(context)})"); case CommandType.MailTo: return(null); case CommandType.Navigate: return($"$navigateSimple({CommandUrl(context)}, {NewWindowJS})"); case CommandType.NavigateExternal: return($"$navigateExternal({CommandUrl(context, decorate:false, skipCheck:true)}, {NewWindowJS})"); case CommandType.Download: return($"$download({CommandUrl(context)})"); case CommandType.Attachment: return($"$attachment({CommandUrl(context)}, {CommandArgument(context)}, {GetOptions(context)})"); case CommandType.Help: return($"$showHelp({CommandUrl(context)})"); case CommandType.Print: return($"$print()"); case CommandType.Open: if (indirect) { var argSting = "this"; if (!IsArgumentEmpty(context)) { argSting = CommandArgument(context); } // arg4 may contain a single quote!!! return($"{{cmd:$navigate, eval: true, arg1:{CommandUrl(context, true)}, arg2:'{argSting}', arg3:{NewWindowJS}, arg4:{UpdateAfterArgument(context)}}}"); } else { return($"$navigate({CommandUrl(context)}, {CommandArgument(context)}, {NewWindowJS}, {UpdateAfterArgument(context)})"); } case CommandType.Create: return($"$navigate({CommandUrl(context)}, {CommandArgument(context, nullable:true)}, {NewWindowJS}, {UpdateAfterArgument(context)}, {GetOptions(context)})"); case CommandType.Remove: if (indirect) { return($"{{cmd:$remove, arg1:'this'}}"); } else { return($"$remove({CommandArgumentOrThis(context)}, {GetConfirm(context)})"); } case CommandType.Append: return($"{CommandArgument(context)}.$append()"); case CommandType.Prepend: return($"{CommandArgument(context)}.$prepend()"); case CommandType.Browse: return($"$dialog('browse', {CommandUrl(context)}, {CommandArgument(context)}, {GetData(context)})"); case CommandType.Execute: if (indirect) { var arg2 = IsArgumentEmpty(context) ? "this" : CommandArgument(context); return($"{{cmd:$exec, arg1:'{GetName()}', arg2:'{arg2}', arg3: {GetConfirm(context)}, arg4: {GetOptions(context)}}}"); } if (argument != null) { return($"$exec('{GetName()}', {argument}, {GetConfirm(context)}, {GetOptions(context)})"); } return($"$exec('{GetName()}', {CommandArgument(context, nullable: true)}, {GetConfirm(context)}, {GetOptions(context)})"); case CommandType.ExecuteSelected: return($"$execSelected('{GetName()}', {CommandArgument(context)}, {GetConfirm(context)})"); case CommandType.Report: return($"$report({GetReportName(context)}, {CommandArgument(context, nullable: true)}, " + $"{GetOptions(context)}, {CommandUrlOptional(context)}, {GetData(context)})"); case CommandType.Export: return($"$export({CommandArgument(context, nullable:true)}, {CommandUrlOptional(context)}, {GetData(context)}, {GetOptions(context)})"); case CommandType.ExportTo: return($"$exportTo('{Format}', {CommandFileName(context)})"); case CommandType.File: return($"$file({CommandUrl(context)}, {CommandArgument(context)}, {GetOptionsForFile(context)})"); case CommandType.Dialog: if (Action == DialogAction.Unknown) { throw new XamlException($"Action required for {Command} command"); } String action = Action.ToString().ToKebabCase(); Boolean bNullable = false; if (Action == DialogAction.Show) { bNullable = true; // Nullable actions ??? } if (indirect) { String arg3 = "this"; if (!IsArgumentEmpty(context)) { arg3 = CommandArgument(context); } // command, url, data return($"{{cmd:$dialog, isDialog:true, arg1:'{action}', arg2:{CommandUrl(context, decorate:true)}, arg3: '{arg3}'}}"); } return($"$dialog('{action}', {CommandUrl(context)}, {CommandArgument(context, bNullable)}, {GetData(context, func:true)}, {GetOptions(context)})"); case CommandType.EUSign: return($"$eusign({CommandUrl(context)}, {CommandArgument(context)})"); default: throw new NotImplementedException($"command '{Command}' yet not implemented"); } }
void RenderCell(TagBuilder td, RenderContext context) { 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"); 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"); } MergeContent(td, context); var colSpanBind = GetBinding(nameof(ColSpan)); if (colSpanBind != null) { td.MergeAttribute(":colspan", colSpanBind.GetPath(context)); } else { MergeAttributeInt32(td, context, nameof(ColSpan), "colspan", ColSpan); } var rowSpanBind = GetBinding(nameof(RowSpan)); if (rowSpanBind != null) { td.MergeAttribute(":rowspan", rowSpanBind.GetPath(context)); } else { MergeAttributeInt32(td, context, nameof(RowSpan), "rowspan", RowSpan); } td.RenderStart(context); RenderContent(context); /* * no use, the content in the attribute * if (Validate) * { * var val = new TagBuilder("validator-control"); * val.MergeAttribute(":item", "row"); * val.MergeAttribute("prop", "Sum"); * val.Render(context); * }*/ td.RenderEnd(context); }
internal override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null) { if (SkipRender(context)) { return; } var dataGrid = new TagBuilder("data-grid", null, IsInGrid); onRender?.Invoke(dataGrid); MergeBindingAttributeBool(dataGrid, context, ":compact", nameof(Compact), Compact); MergeAttributes(dataGrid, context, MergeAttrMode.Margin | MergeAttrMode.Visibility); dataGrid.MergeAttribute("key", Guid.NewGuid().ToString()); // disable vue reusing if (Height != null) { dataGrid.MergeStyle("height", Height.Value); } if (FixedHeader) { dataGrid.MergeAttribute(":fixed-header", "true"); } if (HeadersVisibility == HeadersVisibility.None) { dataGrid.MergeAttribute(":hide-header", "true"); } if (Style != DataGridStyle.Default) { dataGrid.AddCssClass($"data-grid-{Style.ToString().ToKebabCase()}"); } if (RowDetails != null) { dataGrid.MergeAttribute(":row-details", "true"); dataGrid.MergeAttribute("row-details-activate", RowDetails.Activate.ToString().ToLowerInvariant()); var vBind = RowDetails.GetBinding("Visible"); if (vBind != null) { dataGrid.MergeAttribute("row-details-visible", vBind.Path /*!without context!*/); } } var isb = GetBinding(nameof(ItemsSource)); if (isb != null) { dataGrid.MergeAttribute(":items-source", isb.GetPath(context)); } MergeBoolAttribute(dataGrid, context, nameof(Hover), Hover); MergeBoolAttribute(dataGrid, context, nameof(Striped), Striped); MergeBoolAttribute(dataGrid, context, nameof(Border), Border); MergeBoolAttribute(dataGrid, context, nameof(Sort), Sort); dataGrid.MergeAttribute(":route-query", "$query"); // always! if (!String.IsNullOrEmpty(EmptyPanelDelegate)) { dataGrid.MergeAttribute(":empty-panel-callback", $"$delegate('{EmptyPanelDelegate}')"); } var dblClickBind = GetBindingCommand(nameof(DoubleClick)); if (dblClickBind != null) { // Function! dataGrid.MergeAttribute(":doubleclick", "() => " + dblClickBind.GetCommand(context)); } if (MarkerStyle != RowMarkerStyle.None) { dataGrid.MergeAttribute("mark-style", MarkerStyle.ToString().ToKebabCase()); } var mbind = GetBinding(nameof(Mark)); if (mbind != null) { dataGrid.MergeAttribute("mark", mbind.Path); // without context!!! } else if (Mark != MarkStyle.Default) { throw new XamlException("The Mark property must be a binding"); } var rbbind = GetBinding(nameof(RowBold)); if (rbbind != null) { dataGrid.MergeAttribute("row-bold", rbbind.GetPath(context)); } else if (RowBold != null) { throw new XamlException("The RowBold property must be a binding"); } // TODO: binding for GridLines ??? if (GridLines != GridLinesVisibility.None) { dataGrid.MergeAttribute("grid", GridLines.ToString()); } var groupByBind = GetBinding(nameof(GroupBy)); if (groupByBind != null) { dataGrid.MergeAttribute(":group-by", groupByBind.GetPath(context)); } else if (_groupBy != null) { dataGrid.MergeAttribute(":group-by", _groupBy.GetJsValue(context)); } dataGrid.RenderStart(context); Int32 colIndex = 0; foreach (var col in Columns) { col.RenderColumn(context, colIndex); colIndex++; } RenderRowDetails(context); RenderEmptyPanel(context); dataGrid.RenderEnd(context); }
public override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null) { if (CheckDisabledModel(context)) { return; } var combo = new TagBuilder("select", null, IsInGrid); onRender?.Invoke(combo); combo.MergeAttribute("is", "combobox"); combo.MergeAttribute("v-cloak", String.Empty); combo.MergeAttribute("display", DisplayProperty); if (Style != ComboBoxStyle.Default) { combo.AddCssClass($"combo-{Style.ToString().ToLowerInvariant()}"); } MergeAttributes(combo, context); MergeAlign(combo, context, Align); MergeBoolAttribute(combo, context, nameof(ShowValue), ShowValue); SetSize(combo, nameof(ComboBox)); MergeDisabled(combo, context); var isBind = GetBinding(nameof(ItemsSource)); if (isBind != null) { combo.MergeAttribute(":items-source", isBind.GetPath(context)); if (_children != null) { if (Children.Count != 1) { throw new XamlException("The ComboBox with the specified ItemsSource must have only one ComboBoxItem element"); } var elem = Children[0]; var contBind = elem.GetBinding("Content"); if (contBind == null) { throw new XamlException("ComboBoxItem. Content binging must be specified"); } combo.MergeAttribute(":name-prop", $"'{contBind.Path}'"); /*without context!*/ var valBind = elem.GetBinding("Value"); if (valBind == null) { throw new XamlException("ComboBoxItem. Value binging must be specified"); } combo.MergeAttribute(":value-prop", $"'{valBind.Path}'"); /*without context!*/ } } MergeValue(combo, context); combo.RenderStart(context); if (_children != null && isBind == null) { foreach (var ch in Children) { ch.RenderElement(context); } } RenderPopover(context); RenderHint(context); RenderLink(context); combo.RenderEnd(context); }
void RenderLoadIndicator(RenderContext context) { new TagBuilder("div", "load-indicator") .MergeAttribute("v-show", "$isLoading") .Render(context); }
public override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null) { var dialog = new TagBuilder("div", "modal"); dialog.MergeAttribute("id", context.RootId); dialog.MergeAttribute("v-cloak", String.Empty); dialog.AddCssClassBoolNo(UserSelect, "user-select"); dialog.MergeAttribute("data-controller-attr", GetControllerAttributes()); dialog.AddCssClassBool(Maximize, "maximize"); dialog.AddCssClassBool(ButtonOnTop, "button-on-top"); if (!String.IsNullOrEmpty(TestId) && context.IsDebugConfiguration) { dialog.MergeAttribute("test-id", TestId); } if (Maximize) { dialog.MergeAttribute("v-maximize", "true"); } else { SetSize(dialog); } dialog.RenderStart(context); if (ShowWaitCursor) { new TagBuilder("wait-cursor", "dialog") .MergeAttribute(":ready", "$data.$ready") .Render(context, TagRenderMode.Normal); } RenderHeader(context); RenderLoadIndicator(context); var content = new TagBuilder("div", "modal-content"); OnCreateContent(content); if (Height != null) { content.MergeStyle("min-height", Height.Value); } if (Padding != null) { Padding.MergeStyles("padding", content); } content.AddCssClassBool(IsContentIsIFrame, "content-iframe"); // bug fix (3px height) if (Background != BackgroundStyle.Default) { content.AddCssClass("background-" + Background.ToString().ToKebabCase()); } content.AddCssClassBool(Overflow, "overflow"); content.RenderStart(context); if (Taskpad != null) { var grid = new TagBuilder("div", "dialog-grid"); if (Taskpad is Taskpad tp && tp.Width != null) { grid.MergeStyle("grid-template-columns", $"1fr {tp.Width.Value}"); } grid.RenderStart(context); var gridContent = new TagBuilder("div", "dialog-grid-content"); gridContent.RenderStart(context); RenderChildren(context); gridContent.RenderEnd(context); Taskpad.RenderElement(context); grid.RenderEnd(context); } else { RenderChildren(context); } content.RenderEnd(context); RenderFooter(context); RenderAccelCommands(context); dialog.RenderEnd(context); }
internal abstract void RenderElement(RenderContext context, Action <TagBuilder> onRender = null);
public override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null) { /* TODO: * 1. Horizontal splitter */ if (SkipRender(context)) { return; } var spl = new TagBuilder("div", "splitter"); onRender?.Invoke(spl); spl.MergeAttribute("key", Guid.NewGuid().ToString()); // disable vue reusing MergeAttributes(spl, context); if (Height != null) { spl.MergeStyle("height", Height.Value); } if (MinWidth != null) { spl.MergeStyle("min-width", MinWidth.Value); } spl.AddCssClass(Orientation.ToString().ToLowerInvariant()); // width GridLength p1w = GetWidth(Children[0]) ?? GridLength.Fr1(); GridLength p2w = GetWidth(Children[1]) ?? GridLength.Fr1(); String rowsCols = Orientation == Orientation.Vertical ? "grid-template-columns" : "grid-template-rows"; spl.MergeStyle(rowsCols, $"{p1w} 5px {p2w}"); spl.RenderStart(context); // first part var p1 = new TagBuilder("div", "spl-part spl-first"); p1.RenderStart(context); Children[0].RenderElement(context); p1.RenderEnd(context); new TagBuilder("div", "spl-handle") .MergeAttribute(Orientation == Orientation.Vertical ? "v-resize" : "h-resize", String.Empty) //.MergeAttribute("key", Guid.NewGuid().ToString()) // disable vue reusing .MergeAttribute("first-pane-width", p1w?.Value.ToString()) .MergeAttribute("data-min-width", GetMinWidth(Children[0])?.Value.ToString()) .MergeAttribute("second-min-width", GetMinWidth(Children[1])?.Value.ToString()) .Render(context); // second part var p2 = new TagBuilder("div", "spl-part spl-second"); p2.RenderStart(context); Children[1].RenderElement(context); p2.RenderEnd(context); // drag-handle new TagBuilder("div", "drag-handle") .Render(context); spl.RenderEnd(context); }