コード例 #1
0
        public void Vizualize([NotNull] HtmlTextWriter htmlTextWriter,
                              [NotNull] HtmlReportBlock block,
                              IReadOnlyDictionary <string, object> parameterValues,
                              IReadOnlyCollection <ReportQueryResult> queryResults,
                              long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            if (string.IsNullOrEmpty(block.Template))
            {
                return;
            }

            var iteratorStyle = new HtmlStyle();

            iteratorStyle.Set(HtmlStyleKey.Width, "100%");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, iteratorStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Div);

            var renderedTemplate = GetTemplate(block, parameterValues, queryResults);

            htmlTextWriter.Write(renderedTemplate);

            htmlTextWriter.RenderEndTag();             // div
        }
コード例 #2
0
ファイル: HtmlStyleTest.cs プロジェクト: OakRaven/ltaf
        public void RawStyleGet()
        {
            HtmlStyle style = new HtmlStyle();

            style.LoadDescriptors("foo:foo1;bar:bar1;");
            UnitTestAssert.AreEqual("foo:foo1;bar:bar1;", style.RawStyle);
        }
コード例 #3
0
        public void ConvertAttributesToString_MultipleMixed_ReturnSeparated()
        {
            // Arrange
            List <HtmlAttribute> attributes = new List <HtmlAttribute>()
            {
                HtmlClass.Create("no-border"),
                HtmlAttribute.Create("att-1", "1"),
                HtmlAttribute.Create("att-1", "2"),
                HtmlStyle.Create("display", "table"),
                HtmlStyle.Create("border", "1px solid #999"),
                HtmlAttribute.Create("att-1", "2"),
                HtmlStyle.Create("font-family", "Tahoma"),
                HtmlStyle.Create("color", "#555"),
                HtmlStyle.Create("font-family", "Arial"),
                HtmlAttribute.Create("att-2", "1"),
                HtmlAttribute.Create("att-3", "3"),
                HtmlClass.Create("no-border"),
                HtmlClass.Create("bold"),
                HtmlStyle.Create("font-family", "Arial")
            };
            var output = @" att-1=""1 2"" att-2=""1"" att-3=""3"" class=""bold no-border"" style=""border: 1px solid #999; color: #555; display: table; font-family: Arial Tahoma;""";

            // Act
            var result = HtmlHelper.ConvertAttributesToString(attributes);

            // Assert
            Assert.Equal(output, result);
        }
コード例 #4
0
        public void Vizualize([NotNull] HtmlTextWriter htmlTextWriter,
                              [NotNull] ImageReportBlock block,
                              IReadOnlyDictionary <string, object> parameterValues,
                              IReadOnlyCollection <ReportQueryResult> queryResults,
                              long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            var imgStyle = new HtmlStyle();

            imgStyle
            .Set(HtmlStyleKey.Width, _htmlEncoder.Encode(block.Width))
            .Set(HtmlStyleKey.Height, _htmlEncoder.Encode(block.Height));

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Alt, block.Alt);
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Src, block.Source);
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, imgStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Img);
            htmlTextWriter.RenderEndTag();
        }
コード例 #5
0
        public void SetGetValuesFromDOM()
        {
            // HtmlControl/Elements now have a generic SetValue/GetValue that allows developers
            // to set/get values directly from the DOM for any property on the control. Whether it is inherited,
            // readonly or an emitted attribute.

            // Get whether a checkbox is enabled or disabled.
            HtmlInputCheckBox cks = Find.ById <HtmlInputCheckBox>("checkbox1");
            bool disabled         = cks.GetValue <bool>("disabled");

            // Disable it
            cks.SetValue <string>("disabled", "true");
            Assert.IsTrue(cks.GetValue <bool>("disabled"));

            // Is it visible. IsVisible follows the CSS chain to determine if the
            // element is actually visible or not. An element is visible when
            // the CSS the display style is not 'none' and the visibility style
            // is not 'hidden'.
            Assert.IsTrue(cks.IsVisible());

            // Get the color style
            HtmlSpan  mySpan     = Find.ById <HtmlSpan>("Warning");
            HtmlStyle styleColor = mySpan.GetStyle("color");
            string    strColor   = mySpan.GetStyleValue("color");

            // Getting the computed style will follow the CSS chain and return the
            // style.
            HtmlStyle styleMargin = mySpan.GetComputedStyle("margin");
            string    strMargin   = mySpan.GetComputedStyleValue("margin");
        }
コード例 #6
0
        private void RenderHeader(HtmlTextWriter htmlWriter, TableReportBlock block, QueryResult queryBlock, long userId)
        {
            var tableHeadStyle = new HtmlStyle();

            tableHeadStyle.Set(HtmlStyleKey.Border, $"{block.BorderPx}px solid black");

            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Thead);
            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);

            // ReSharper disable once LoopCanBePartlyConvertedToQuery
            foreach (var column in queryBlock.Columns)
            {
                htmlWriter.AddAttribute(HtmlTextWriterAttribute.Style, tableHeadStyle.ToString());
                htmlWriter.RenderBeginTag(HtmlTextWriterTag.Th);

                _blockVizualizationManager.Vizualize(
                    htmlWriter,
                    (dynamic)block.HeaderLabel,
                    new ConcurrentDictionary <string, object>(
                        new[]
                {
                    new KeyValuePair <string, object>(TableReportBlockParameters.ColumnHeader, column.Name)
                }),
                    null,
                    userId);

                htmlWriter.RenderEndTag();                 // Th
            }

            htmlWriter.RenderEndTag();             // tr
            htmlWriter.RenderEndTag();             // thead
        }
コード例 #7
0
        public void Equals_Null()
        {
            // Arrange
            var orig = HtmlStyle.Create(name, value);

            // Assert
            Assert.False(orig.Equals(null));
        }
コード例 #8
0
        public void ToString_ReturnString()
        {
            // Arrange
            var obj = HtmlStyle.Create(name, value);

            // Assert
            Assert.Equal($@"style=""{name}: {value}""", obj.ToString());
        }
コード例 #9
0
        public void Constrcutor_Empty()
        {
            // Act
            var obj = new HtmlStyle();

            // Assert
            Assert.Null(obj.Name);
            Assert.Null(obj.Value);
        }
コード例 #10
0
        public void Equals_OtherObject()
        {
            // Arrange
            var orig = HtmlStyle.Create(name, value);
            var str  = $@"{name}=""{value}""";

            // Assert
            Assert.False(orig.Equals(str));
        }
コード例 #11
0
        public void Equals_IsEqual()
        {
            // Arrange
            var orig = HtmlStyle.Create(name, value);
            var copy = HtmlStyle.Create(name, value);

            // Assert
            Assert.True(orig.Equals(copy));
        }
コード例 #12
0
        public void Equals_IsNotEqual()
        {
            // Arrange
            var orig  = HtmlStyle.Create(name, value);
            var other = HtmlStyle.Create("not", "same");

            // Assert
            Assert.False(orig.Equals(other));
        }
コード例 #13
0
        public void Constructor_SetValues()
        {
            // Act
            var obj = new HtmlStyle(name, value);

            // Assert
            Assert.Equal(name, obj.Name);
            Assert.Equal(value, obj.Value);
        }
コード例 #14
0
        public void Create_ReturnNewInstance()
        {
            // Act
            var obj = HtmlStyle.Create(name, value);

            // Assert
            Assert.Equal(name, obj.Name);
            Assert.Equal(value, obj.Value);
            Assert.IsType <HtmlStyle>(obj);
        }
コード例 #15
0
        public void Vizualize(
            [NotNull] HtmlTextWriter htmlTextWriter,
            [NotNull] ChartReportBlock block,
            IReadOnlyDictionary <string, object> parameterValues,
            [NotNull] IReadOnlyCollection <ReportQueryResult> queryResults,
            long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }
            if (queryResults == null)
            {
                throw new ArgumentNullException(nameof(queryResults));
            }

            var query =
                queryResults.SingleOrDefault(_ => _.Key.Equals(block.QueryKey, StringComparison.InvariantCultureIgnoreCase));

            if (query == null)
            {
                throw new QueryResultNotFoundException(block);
            }

            var chartId = Guid.NewGuid().ToString("N");

            var chartDivStyle = new HtmlStyle();

            chartDivStyle
            .Set(HtmlStyleKey.Width, "100%")
            .Set(HtmlStyleKey.Float, "left");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, chartDivStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Div);

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, chartId);
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Height, block.HeightPx.ToString());
            htmlTextWriter.RenderBeginTag("canvas");
            htmlTextWriter.RenderEndTag();             // canvas

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Script);

            var script = GenerateScript(block, chartId, query);

            htmlTextWriter.Write(script);

            htmlTextWriter.RenderEndTag();             // Script
            htmlTextWriter.RenderEndTag();             // div
        }
コード例 #16
0
ファイル: HtmlStyleTest.cs プロジェクト: OakRaven/ltaf
        public void TestInitialize()
        {
            _style = new HtmlStyle();

            StringBuilder descriptors = new StringBuilder();

            descriptors.Append("visibility:hidden;position:fixed;color:green;backgroundcolor:blue;backgroundimage:fooimage;");
            descriptors.Append("bottom:1px;left:2px;right:3px;top:4px;borderspacing:5px;height:6px;width:7px;");
            descriptors.Append("paddingtop:8px;paddingleft:9px;paddingright:10px;paddingbottom:11px;size:12px;");
            descriptors.Append("textindent:13px;align:justify;verticalalign:middle;whitespace:nowrap;display:inline;overflow:scroll;");
            _style.LoadDescriptors(descriptors.ToString());
        }
コード例 #17
0
ファイル: Styler.cs プロジェクト: hipparchus2000/SockMin
 private void InitStyle(Guid connectionId)
 {
     if (_htmlStyle == null)
     {
         //fetch the style to use
         var connection = _connectionRepo.All().Single(c => c.Id == connectionId);
         _htmlStyle = _userRepo.All().Single(u => u.Id == connection.UserId).HtmlStyle;
         if (_htmlStyle == null)
         {
             _htmlStyle = _htmlStyleRepo.All().Single(h => h.IsDefault);
         }
     }
 }
コード例 #18
0
		public HtmlStyle HeaderTextStyle {get;set;}  //  p

		public GridStyleBase(){
			RowStyle = new HtmlRowStyle();
			AlternateRowStyle = new HtmlRowStyle();
			CellStyle = new HtmlCellStyle();
			TableStyle = new HtmlTableStyle();
			TableStyle.FontFamily="Century Gothic, Arial, Helvetica, sans-serif";
			TableStyle.FontSize.Value=95;
			TableStyle.FontSize.Unit="%";
			HeaderStyle= new HtmlTableStyle();
			FooterStyle = new HtmlTableStyle();
			TitleStyle = new HtmlStyle();
			FootNoteStyle = new HtmlStyle();
			HeaderCellStyle= new HtmlCellStyle();
			FooterCellStyle = new HtmlCellStyle();
			HeaderTextStyle = new HtmlStyle();
		}
コード例 #19
0
        public void Vizualize(
            [NotNull] HtmlTextWriter htmlTextWriter,
            [NotNull] LabelReportBlock block,
            IReadOnlyDictionary <string, object> parameterValues,
            IReadOnlyCollection <ReportQueryResult> queryResults,
            long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            var labelStyle = new HtmlStyle();

            labelStyle
            .Set(HtmlStyleKey.Display, "inline-block")
            .Set("word-break", "break-all")
            .Set("white-space", "pre-wrap")
            .Set("word-wrap", "break-word")
            .Set(HtmlStyleKey.Color, block.Color.ToRgb())
            .Set(HtmlStyleKey.FontFamily, block.FontStyle.FontFamily)
            .Set(HtmlStyleKey.FontStyle, block.FontStyle.Italic ? "italic" : "normal")
            .Set(HtmlStyleKey.FontSize, $"{block.FontStyle.FontSizePx}px")
            .Set(HtmlStyleKey.FontWeight, block.FontStyle.Bold ? "bold" : "normal")
            .Set(HtmlStyleKey.TextAlign, block.HorizontalAlign.ToString())
            .Set(HtmlStyleKey.VerticalAlign, block.VerticalAlign.ToString())
            .Set(HtmlStyleKey.Width, "100%");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, labelStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Label);

            if (!string.IsNullOrEmpty(block.Text))
            {
                var renderedTemplate = RenderTemplate(block, parameterValues);

                renderedTemplate = _htmlEncoder.Encode(renderedTemplate);

                htmlTextWriter.Write(renderedTemplate);
            }

            htmlTextWriter.RenderEndTag();             // label
        }
コード例 #20
0
        }                                                    //  p

        public GridStyleBase()
        {
            RowStyle                  = new HtmlRowStyle();
            AlternateRowStyle         = new HtmlRowStyle();
            CellStyle                 = new HtmlCellStyle();
            TableStyle                = new HtmlTableStyle();
            TableStyle.FontFamily     = "Century Gothic, Arial, Helvetica, sans-serif";
            TableStyle.FontSize.Value = 95;
            TableStyle.FontSize.Unit  = "%";
            HeaderStyle               = new HtmlTableStyle();
            FooterStyle               = new HtmlTableStyle();
            TitleStyle                = new HtmlStyle();
            FootNoteStyle             = new HtmlStyle();
            HeaderCellStyle           = new HtmlCellStyle();
            FooterCellStyle           = new HtmlCellStyle();
            HeaderTextStyle           = new HtmlStyle();
        }
コード例 #21
0
        private void RenderBody(HtmlTextWriter htmlWriter, TableReportBlock block, QueryResult queryBlock, long userId)
        {
            var tableBodyStyle = new HtmlStyle();

            tableBodyStyle.Set(HtmlStyleKey.Border, $"{block.BorderPx}px solid black");

            htmlWriter.RenderBeginTag(HtmlTextWriterTag.Tbody);

            foreach (var row in queryBlock.Items)
            {
                htmlWriter.AddAttribute(HtmlTextWriterAttribute.Style, tableBodyStyle.ToString());
                htmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);

                foreach (var column in queryBlock.Columns)
                {
                    htmlWriter.AddAttribute(HtmlTextWriterAttribute.Style, tableBodyStyle.ToString());
                    htmlWriter.RenderBeginTag(HtmlTextWriterTag.Td);

                    var columnItem = row.Value.GetType()
                                     .GetProperty(column.Code)
                                     .GetValue(row.Value);

                    if (columnItem != null)
                    {
                        _blockVizualizationManager.Vizualize(
                            htmlWriter,
                            (dynamic)block.BodyLabel,
                            new ConcurrentDictionary <string, object>(
                                new[]
                        {
                            new KeyValuePair <string, object>(TableReportBlockParameters.RowColumnItem, columnItem.ToString())
                        }),
                            null,
                            userId);
                    }

                    htmlWriter.RenderEndTag();                     // Td
                }

                htmlWriter.RenderEndTag();                 // Tr
            }

            htmlWriter.RenderEndTag();             // Tbody
        }
コード例 #22
0
        public void ConvertAttributesToString_MultipleStyles_ReturnStyleCombined()
        {
            // Arrange
            List <HtmlAttribute> attributes = new List <HtmlAttribute>()
            {
                HtmlStyle.Create("font-family", "Tahoma"),
                HtmlStyle.Create("color", "#555"),
                HtmlStyle.Create("font-family", "Arial"),
                HtmlStyle.Create("display", "table"),
                HtmlStyle.Create("border", "1px solid #999"),
                HtmlStyle.Create("font-family", "Arial")
            };
            var output = @" style=""border: 1px solid #999; color: #555; display: table; font-family: Arial Tahoma;""";

            // act
            var result = HtmlHelper.ConvertAttributesToString(attributes);

            // Assert
            Assert.Equal(output, result);
        }
コード例 #23
0
        /// <summary>
        /// extend
        /// from array node get html
        /// </summary>
        /// <param name="arr"></param>
        /// <returns></returns>
        public static string GetHtmlFromJsonArray(JArray arr, HtmlStyle style = HtmlStyle.HasHtmlHeader)
        {
            JsonLoadSettings setting = new JsonLoadSettings();

            setting.CommentHandling = CommentHandling.Load;
            StringBuilder str = new StringBuilder();

            if (style != HtmlStyle.NoHtmlHeader)
            {
                str.Append("<!DOCTYPE html><html>" + GetTableBeautifulCss() + "<body>");
            }
            else
            {
                str.Append(GetTableBeautifulCss());
            }
            BuildTableFromJsonArray(arr, str);
            if (style != HtmlStyle.NoHtmlHeader)
            {
                str.Append("</body></html>");
            }
            return(str.ToString());
        }
コード例 #24
0
        private void RenderTable(
            HtmlTextWriter htmlTextWriter,
            TableReportBlock block,
            QueryResult queryBlock,
            long userId)
        {
            var tableStyle = new HtmlStyle();

            tableStyle
            .Set(HtmlStyleKey.Width, "100%")
            .Set(HtmlStyleKey.Border, $"{block.BorderPx}px solid black")
            .Set(HtmlStyleKey.BorderCollapse, "collapse");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, tableStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Table);

            RenderHeader(htmlTextWriter, block, queryBlock, userId);

            RenderBody(htmlTextWriter, block, queryBlock, userId);

            htmlTextWriter.RenderEndTag();             // Table
        }
コード例 #25
0
        /// <summary>
        /// get a html code from json line
        /// json should be show in a html table
        /// </summary>
        /// <param name="json">must be a json object , except json array</param>
        /// <param name="style"></param>
        /// <returns></returns>
        public static string GetHtml(string json, HtmlStyle style = HtmlStyle.HasHtmlHeader)
        {
            JsonLoadSettings setting = new JsonLoadSettings();

            setting.CommentHandling = CommentHandling.Load;
            JObject       jb  = JObject.Parse(json, setting);
            StringBuilder str = new StringBuilder();

            if (style != HtmlStyle.NoHtmlHeader)
            {
                str.Append("<!DOCTYPE html><html>" + GetTableBeautifulCss() + "<body>");
            }
            else
            {
                str.Append(GetTableBeautifulCss());
            }
            BuildTableFromJsonObject(jb, str);
            if (style != HtmlStyle.NoHtmlHeader)
            {
                str.Append("</body></html>");
            }
            return(str.ToString());
        }
コード例 #26
0
        public void Vizualize(
            [NotNull] HtmlTextWriter htmlTextWriter,
            [NotNull] IteratorReportBlock block,
            IReadOnlyDictionary <string, object> parameterValues,
            IReadOnlyCollection <ReportQueryResult> queryResults,
            long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            if (string.IsNullOrEmpty(block.QueryKey))
            {
                throw new IncorrectBlockQueryKeyException(block);
            }

            var query = queryResults
                        .SingleOrDefault(_ => _.Key.Equals(block.QueryKey, StringComparison.InvariantCultureIgnoreCase));

            if (query == null)
            {
                throw new QueryResultNotFoundException(block);
            }

            if (block.Child == null)
            {
                return;
            }

            var iteratorStyle = new HtmlStyle();

            iteratorStyle.Set(HtmlStyleKey.Width, "100%");
            iteratorStyle.Set(HtmlStyleKey.Float, "none");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, iteratorStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Div);

            var i = 1;

            var queryItemKey = $"{query.Key}Item";

            foreach (var resultItem in query.Result.Items)
            {
                htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, iteratorStyle.ToString());
                htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, $"{block.Id}-Item{i}");
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Div);

                var childParameters = parameterValues.ToDictionary(
                    paramValue => paramValue.Key,
                    paramValue => paramValue.Value);

                childParameters.Add(queryItemKey, resultItem.Value);

                _reportBlockVizualizationManager.Vizualize(
                    htmlTextWriter,
                    (dynamic)block.Child,
                    childParameters,
                    queryResults,
                    userId);

                htmlTextWriter.RenderEndTag();                 // div

                i++;
            }

            htmlTextWriter.RenderEndTag();             // div
        }
コード例 #27
0
ファイル: HtmlStyleTest.cs プロジェクト: OakRaven/ltaf
        public void RawStyleGet_EmptyStyle()
        {
            HtmlStyle style = new HtmlStyle();

            UnitTestAssert.IsNull(style.RawStyle);
        }
コード例 #28
0
        public void HtmlStyleClass()
        {
            // Verify the color of the warning text is Red
            HtmlSpan  warningSpan       = Find.ById <HtmlSpan>("Warning");
            HtmlStyle warningColorStyle = warningSpan.GetStyle("color");

            // Verify the style's value is a color value.
            // In reality it's not necessary to test using both IsColor and IsInt.
            // They're both used here for demonstration purposes only.
            Assert.IsTrue(warningColorStyle.IsColor());
            Assert.IsFalse(warningColorStyle.IsInt());
            Color warningColor = warningColorStyle.ToColor();

            Assert.AreEqual <Color>(Color.Red, warningColor);

            // If we don't want to use Assert, we can use IsSameColor instead.
            if (!HtmlStyle.IsSameColor(Color.Red, warningColor))
            {
                Log.WriteLine(LogType.Error, string.Format("Warning color is not red. It is {0}", warningColor.ToString()));
            }

            // We have the option of converting a .NET Color object into an HTML color string
            string htmlColorString = HtmlStyle.ToHtmlColor(Color.SaddleBrown);

            htmlColorString = HtmlStyle.ToHtmlColor(Color.FromArgb(33, 44, 55));

            // Let's log the name and value of all the styles attached to this element
            foreach (string strStyle in warningSpan.Styles)
            {
                // NOTE: Some of the styles have a '-' in the middle of the name in the HTML (e.g. TEXT-ALIGN).
                // But when we go to fetch the styles attributes by that name, it doesn't exist in JavaScript.
                // The equivalent does exist without the '-'. So we will blindly strip out any '-' characters
                // prior to calling GetStyle in order to convert it to be JavaScript compatible.
                string    modStyle = strStyle.Replace("-", "");
                HtmlStyle aStyle   = warningSpan.GetStyle(modStyle);
                Log.WriteLine(LogType.Information, string.Format("Style name: {0}, Style Value {1}",
                                                                 aStyle.Name, aStyle.Value));
            }

            // Verify the margin is set to 30 units (but note we don't know what the unit of measure is)
            HtmlStyle warningMarginStyle = warningSpan.GetStyle("margin");

            Assert.IsTrue(warningMarginStyle.IsInt());
            int warningMargin = warningMarginStyle.ToInt();

            // Unfortunately the value we get from Firefox is different than all other browsers.
            if (ActiveBrowser.BrowserType == BrowserType.FireFox)
            {
                Assert.AreEqual(30303030, warningMargin);
            }
            else
            {
                Assert.AreEqual(30, warningMargin);
            }

            // GetStyle returns the value of an explicit style applied to the element.
            // If the element does not have an explicit style applied, GetStyle returns an empty value.
            // Since our warning span does not have the backgroundColor style explicitly applied to it,
            // GetStyle returns a style with an empty value.
            HtmlStyle backgroundStyle = warningSpan.GetStyle("backgroundColor");

            Assert.IsTrue(string.IsNullOrEmpty(backgroundStyle.Value), "Actual padding value was: \"{0}\"", backgroundStyle.Value);
            // However GetComputedStyle will follow the CSS until it finds the currently active style value.
            // Our warning span is contained within a form that has a backgroundColor style.
            // Therefore GetComputedStyle on the warning span will return the value set in the parent form tag.
            backgroundStyle = warningSpan.GetComputedStyle("backgroundColor");
            Assert.IsFalse(string.IsNullOrEmpty(backgroundStyle.Value), "Actual padding value was: \"{0}\"", backgroundStyle.Value);
        }
コード例 #29
0
        public void Vizualize(
            [NotNull] HtmlTextWriter htmlTextWriter,
            [NotNull] HtmlDocReportBlock block,
            IReadOnlyDictionary <string, object> parameterValues,
            IReadOnlyCollection <ReportQueryResult> queryResults,
            long userId)
        {
            if (htmlTextWriter == null)
            {
                throw new ArgumentNullException(nameof(htmlTextWriter));
            }
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            var docType = new StringBuilder(block.WithHeader ? "<!DOCTYPE html>" : string.Empty);

            htmlTextWriter.Write(docType);

            if (block.WithHeader)
            {
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Html);
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Head);
                htmlTextWriter.AddAttribute("charset", "UTF-8");
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Meta);
                htmlTextWriter.RenderEndTag();                 // meta
            }

            RenderChartScript(htmlTextWriter);

            if (block.WithHeader)
            {
                htmlTextWriter.RenderEndTag();                 // head
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Body);
            }

            var containerStyle = new HtmlStyle();

            containerStyle
            .Set(HtmlStyleKey.Width, block.Width)
            .Set(HtmlStyleKey.AlignContent, "center")
            .Set(HtmlStyleKey.Margin, "0 auto");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, containerStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Div);             // div

            _reportBlockVizualizationManager.Vizualize(
                htmlTextWriter,
                (dynamic)block.Child,
                parameterValues,
                queryResults,
                userId);

            htmlTextWriter.RenderEndTag();             // div

            // ReSharper disable once InvertIf
            if (block.WithHeader)
            {
                htmlTextWriter.RenderEndTag();                 // body
                htmlTextWriter.RenderEndTag();                 // html
            }
        }
コード例 #30
0
        private void RenderTableContainer(HtmlTextWriter htmlTextWriter,
                                          ContainerReportBlock block,
                                          IReadOnlyDictionary <string, object> parameterValues,
                                          IReadOnlyCollection <ReportQueryResult> queryResults,
                                          long userId)
        {
            var baseDivStyle = new HtmlStyle();

            baseDivStyle
            .Set(HtmlStyleKey.Width, "100%")
            .Set(HtmlStyleKey.Float, "none");

            if (block.BreakPageBefore)
            {
                baseDivStyle.Set("page-break-before", "always");
            }

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, baseDivStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, block.Id);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Table);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tbody);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td);

            var innerDivStyle = new HtmlStyle();

            var backgroundColor = block.BackgroundColor.ToRgb();

            innerDivStyle
            .Set(HtmlStyleKey.BackgroundColor, backgroundColor)
            .Set(HtmlStyleKey.Width, "100%")

            // unnessesary for the inner div block
            .Set(HtmlStyleKey.MarginBottom, $"{block.MarginBottomPx}px")
            .Set(HtmlStyleKey.MarginLeft, $"{block.MarginLeftPx}px")
            .Set(HtmlStyleKey.MarginRight, $"{block.MarginRightPx}px")
            .Set(HtmlStyleKey.MarginTop, $"{block.MarginTopPx}px")
            .Set(HtmlStyleKey.PaddingBottom, $"{block.PaddingBottomPx}px")
            .Set(HtmlStyleKey.PaddingLeft, $"{block.PaddingLeftPx}px")
            .Set(HtmlStyleKey.PaddingRight, $"{block.PaddingRightPx}px")
            .Set(HtmlStyleKey.PaddingTop, $"{block.PaddingTopPx}px");

            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, innerDivStyle.ToString());
            htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, $"{block.Id}-Inner");
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Table);
            htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tbody);

            if (block.Orientation == ContainerOrientation.Horizontal)
            {
                htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
            }

            if (block.Childs != null)
            {
                var i = 0;

                foreach (var child in block.Childs)
                {
                    var divWidth = 100;

                    if (block.Orientation == ContainerOrientation.Horizontal)
                    {
                        if (block.ChildProportions == null)
                        {
                            divWidth = 100 / block.Childs.Length;
                        }
                        else
                        {
                            divWidth = block.ChildProportions[i];
                        }
                    }

                    if (block.Orientation == ContainerOrientation.Vertical)
                    {
                        htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
                    }

                    var childDivStyle = new HtmlStyle();

                    childDivStyle
                    .Set(HtmlStyleKey.BackgroundColor, backgroundColor)
                    .Set(HtmlStyleKey.Width, $"{divWidth}%");

                    htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Style, childDivStyle.ToString());
                    htmlTextWriter.AddAttribute(HtmlTextWriterAttribute.Id, $"{block.Id}-Child{i + 1}");

                    htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td);

                    _reportBlockVizualizationManager.Vizualize(
                        htmlTextWriter,
                        (dynamic)child,
                        parameterValues,
                        queryResults,
                        userId);

                    htmlTextWriter.RenderEndTag();                     // TD

                    if (block.Orientation == ContainerOrientation.Vertical)
                    {
                        htmlTextWriter.RenderEndTag();                         // TR
                    }

                    i++;
                }
            }

            if (block.Orientation == ContainerOrientation.Horizontal)
            {
                htmlTextWriter.RenderEndTag();         // TR
            }
            htmlTextWriter.RenderEndTag();             //outher table TBody
            htmlTextWriter.RenderEndTag();             //outher Table

            htmlTextWriter.RenderEndTag();             //outher table TD
            htmlTextWriter.RenderEndTag();             //outher table TR
            htmlTextWriter.RenderEndTag();             //outher table TBody
            htmlTextWriter.RenderEndTag();             //outher Table
        }