public void TestAdHocParams() { var breakpoint = new ResponsiveBreakpoint().MaxImages(5).BytesStep(20) .MinWidth(200).MaxWidth(1000).CreateDerived(false); ImageUploadParams uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), Tags = m_apiTag }; uploadParams.AddCustomParam("public_id", GetUniquePublicId()); uploadParams.AddCustomParam("IgnoredEmptyParameter", ""); uploadParams.AddCustomParam("responsive_breakpoints", JsonConvert.SerializeObject(new List <ResponsiveBreakpoint> { breakpoint })); uploadParams.AddCustomParam("IgnoredNullParameter", null); var paramsDict = uploadParams.ToParamsDictionary(); Assert.IsFalse(paramsDict.ContainsKey("IgnoredEmptyParameter")); Assert.IsFalse(paramsDict.ContainsKey("IgnoredNullParameter")); ImageUploadResult result = m_cloudinary.Upload(uploadParams); Assert.NotNull(result.ResponsiveBreakpoints); //todo: check it in netCore Assert.AreEqual(1, result.ResponsiveBreakpoints.Count); Assert.AreEqual(5, result.ResponsiveBreakpoints[0].Breakpoints.Count); Assert.AreEqual(1000, result.ResponsiveBreakpoints[0].Breakpoints[0].Width); Assert.AreEqual(200, result.ResponsiveBreakpoints[0].Breakpoints[4].Width); }
public void TestResponsiveBreakpointsToJson() { var responsiveBreakpoint = new ResponsiveBreakpoint().ToString(Formatting.None); Assert.AreEqual("{\"create_derived\":true}", responsiveBreakpoint, "an empty ResponsiveBreakpoint should have create_derived=true"); var expectedToken1 = JToken.Parse("{\"create_derived\":false,\"max_width\":500,\"min_width\":100,\"max_images\":5,\"transformation\":\"a_45\"}"); IEnumerable <string> expectedList1 = expectedToken1.Children().Select(s => s.ToString(Formatting.None)); var breakpoint = new ResponsiveBreakpoint().CreateDerived(false) .Transformation(m_simpleTransformationAngle) .MaxWidth(500) .MinWidth(100) .MaxImages(5); var actualList1 = breakpoint.Children().Select(s => s.ToString(Formatting.None)); CollectionAssert.AreEquivalent(expectedList1, actualList1); breakpoint.Transformation(m_transformationAngleExtended); var expectedToken2 = JToken.Parse("{\"create_derived\":false,\"max_width\":500,\"min_width\":100,\"max_images\":5,\"transformation\":\"a_45,c_scale,h_210\"}"); var expectedList2 = expectedToken2.Children().Select(s => s.ToString(Formatting.None)); var actualList2 = breakpoint.Children().Select(s => s.ToString(Formatting.None)); CollectionAssert.AreEquivalent(expectedList2, actualList2); }
public void TestResponsiveBreakpointsFormat() { var breakpoint = new ResponsiveBreakpoint() .Transformation(m_simpleTransformationAngle) .MaxImages(1) .Format(FILE_FORMAT_GIF); ImageUploadParams uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), PublicId = GetUniquePublicId(), Tags = m_apiTag, ResponsiveBreakpoints = new List <ResponsiveBreakpoint> { breakpoint } }; ImageUploadResult result = m_cloudinary.Upload(uploadParams); Assert.Null(result.Error); Assert.NotNull(result.ResponsiveBreakpoints, "result should include 'ResponsiveBreakpoints'"); Assert.AreEqual(1, result.ResponsiveBreakpoints.Count); Assert.AreEqual(TRANSFORM_A_45, result.ResponsiveBreakpoints[0].Transformation); StringAssert.EndsWith(FILE_FORMAT_GIF, result.ResponsiveBreakpoints[0].Breakpoints[0].Url, $"generated breakpoint should have '{FILE_FORMAT_GIF}' extension"); }
public void TestAdHocParams() { var breakpoint = new ResponsiveBreakpoint().MaxImages(5).BytesStep(20) .MinWidth(200).MaxWidth(1000).CreateDerived(false); ImageUploadParams uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath) }; uploadParams.AddCustomParam("public_id", "test_ad_hoc_params_id"); uploadParams.AddCustomParam("tags", "test"); uploadParams.AddCustomParam("IgnoredEmptyParameter", ""); uploadParams.AddCustomParam("responsive_breakpoints", JsonConvert.SerializeObject(new List<ResponsiveBreakpoint> { breakpoint })); uploadParams.AddCustomParam("IgnoredNullParameter", null); var paramsDict = uploadParams.ToParamsDictionary(); Assert.AreEqual(3, paramsDict.Count); Assert.IsFalse(paramsDict.ContainsKey("IgnoredEmptyParameter")); Assert.IsFalse(paramsDict.ContainsKey("IgnoredNullParameter")); ImageUploadResult result = m_cloudinary.Upload(uploadParams); Assert.AreEqual(1, result.ResponsiveBreakpoints.Count); Assert.AreEqual(5, result.ResponsiveBreakpoints[0].Breakpoints.Count); Assert.AreEqual(1000, result.ResponsiveBreakpoints[0].Breakpoints[0].Width); Assert.AreEqual(200, result.ResponsiveBreakpoints[0].Breakpoints[4].Width); }
public void TestResponsiveBreakpoints() { var publicId = GetUniquePublicId(); var breakpoint = new ResponsiveBreakpoint().MaxImages(5).BytesStep(20) .MinWidth(200).MaxWidth(1000).CreateDerived(false); var breakpoint2 = new ResponsiveBreakpoint().Transformation(m_simpleTransformation).MaxImages(4) .BytesStep(20).MinWidth(100).MaxWidth(900).CreateDerived(false); // An array of breakpoints var uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), PublicId = publicId, Tags = m_apiTag, ResponsiveBreakpoints = new List <ResponsiveBreakpoint> { breakpoint, breakpoint2 } }; var result = m_cloudinary.Upload(uploadParams); Assert.Null(result.Error); Assert.NotNull(result.ResponsiveBreakpoints, "result should include 'ResponsiveBreakpoints'"); Assert.AreEqual(2, result.ResponsiveBreakpoints.Count); Assert.AreEqual(5, result.ResponsiveBreakpoints[0].Breakpoints.Count); Assert.AreEqual(1000, result.ResponsiveBreakpoints[0].Breakpoints[0].Width); Assert.AreEqual(200, result.ResponsiveBreakpoints[0].Breakpoints[4].Width); Assert.AreEqual(4, result.ResponsiveBreakpoints[1].Breakpoints.Count); Assert.AreEqual(900, result.ResponsiveBreakpoints[1].Breakpoints[0].Width); Assert.AreEqual(100, result.ResponsiveBreakpoints[1].Breakpoints[3].Width); // responsive breakpoints for Explicit() var exp = new ExplicitParams(publicId) { EagerTransforms = new List <Transformation>() { m_simpleTransformation }, Type = STORAGE_TYPE_UPLOAD, Tags = m_apiTag, ResponsiveBreakpoints = new List <ResponsiveBreakpoint> { breakpoint2.CreateDerived(true) } }; ExplicitResult expResult = m_cloudinary.Explicit(exp); Assert.AreEqual(1, expResult.ResponsiveBreakpoints.Count); Assert.AreEqual(4, expResult.ResponsiveBreakpoints[0].Breakpoints.Count); Assert.AreEqual(900, expResult.ResponsiveBreakpoints[0].Breakpoints[0].Width); Assert.AreEqual(100, expResult.ResponsiveBreakpoints[0].Breakpoints[3].Width); }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { if (!isVisible) { output.SuppressOutput(); return; } #region << Init >> if (String.IsNullOrWhiteSpace(Id)) { Id = "wv-" + Guid.NewGuid(); } //Records Count if (VerticalAlign != VerticalAlignmentType.None) { context.Items[typeof(VerticalAlignmentType)] = VerticalAlign; } var content = await output.GetChildContentAsync(); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(content.GetContent()); var actionTagHelperList = htmlDoc.DocumentNode.Descendants("tr"); RecordsCount = actionTagHelperList.Count(); #endregion #region << Setup wrapper >> var wrapperEl = new TagBuilder("div"); var classList = new List <string>(); classList.Add("erp-list"); wrapperEl.Attributes.Add("id", Id); if (ResponsiveBreakpoint != CssBreakpoint.None) { var cssClass = $"{(ResponsiveBreakpoint == CssBreakpoint.XSmall ? "table-responsive" : $"table-responsive-{ResponsiveBreakpoint.GetLabel()}")}"; classList.Add(cssClass); } if (!String.IsNullOrWhiteSpace(Name)) { classList.Add($"erp-list-{Name}"); } if (!String.IsNullOrWhiteSpace(Prefix)) { wrapperEl.Attributes.Add("data-list-query-prefix", $"{Prefix}"); } wrapperEl.Attributes.Add("class", String.Join(" ", classList)); output.PreElement.AppendHtml(wrapperEl.RenderStartTag()); output.PostElement.AppendHtml(wrapperEl.RenderEndTag()); #endregion output.TagName = "table"; #region << Table >> output.AddCssClass("table"); #region << Css classes >> if (Striped) { output.AddCssClass("table-striped"); } if (Small) { output.AddCssClass("table-sm"); } if (Bordered) { output.AddCssClass("table-bordered"); } if (Borderless) { output.AddCssClass("table-borderless"); } if (Hover) { output.AddCssClass("table-hover"); } if (!String.IsNullOrWhiteSpace(Class)) { output.AddCssClass(Class); } if (Id != null) { output.Attributes.Add("id", $"list-table-{Id}"); } #endregion #endregion #region << Thead >> if (HasThead) { var theadEl = new TagBuilder("thead"); var trEl = new TagBuilder("tr"); foreach (var column in Columns) { var thEl = new TagBuilder("th"); var columnCssList = new List <string>(); if (!String.IsNullOrWhiteSpace(column.Class)) { columnCssList.Add(column.Class); } thEl.Attributes.Add("data-filter-name", $"{column.Name}"); if (!String.IsNullOrEmpty(column.Width)) { thEl.Attributes.Add("style", $"width:{column.Width};"); } thEl.AddCssClass(String.Join(" ", columnCssList)); var sortedColumn = ""; if (ViewContext.HttpContext.Request.Query.ContainsKey((String.IsNullOrWhiteSpace(Prefix) ? "" : Prefix) + QueryStringSortBy)) { sortedColumn = ViewContext.HttpContext.Request.Query[(String.IsNullOrWhiteSpace(Prefix) ? "" : Prefix) + QueryStringSortBy]; } var sortOrder = ""; if (ViewContext.HttpContext.Request.Query.ContainsKey((String.IsNullOrWhiteSpace(Prefix) ? "" : Prefix) + QueryStringSortOrder)) { sortOrder = ViewContext.HttpContext.Request.Query[(String.IsNullOrWhiteSpace(Prefix) ? "" : Prefix) + QueryStringSortOrder]; } thEl.InnerHtml.AppendHtml(column.Label); if (column.Sortable) { var columnSortOrder = ""; if (sortedColumn == column.Name) { columnSortOrder = sortOrder; } var sortLink = new TagBuilder("a"); sortLink.AddCssClass("sort-link"); sortLink.Attributes.Add("href", "javascript:void(0)"); sortLink.Attributes.Add("data-dataname", $"{column.Name}"); var sortMarkerEl = new TagBuilder("span"); sortMarkerEl.AddCssClass($"ml-1 sort-marker {columnSortOrder}"); var caretUpIcon = new TagBuilder("span"); caretUpIcon.AddCssClass("fa fa-caret-up"); sortMarkerEl.InnerHtml.AppendHtml(caretUpIcon); var caretDownIcon = new TagBuilder("span"); caretDownIcon.AddCssClass("fa fa-caret-down"); sortMarkerEl.InnerHtml.AppendHtml(caretDownIcon); sortLink.InnerHtml.AppendHtml(sortMarkerEl); sortLink.InnerHtml.AppendHtml(new TagBuilder("em")); thEl.InnerHtml.AppendHtml(sortLink); } trEl.InnerHtml.AppendHtml(thEl); } theadEl.InnerHtml.AppendHtml(trEl); output.PreContent.AppendHtml(theadEl); } #endregion #region << Tbody >> var tbodyEl = new TagBuilder("tbody"); output.PreContent.AppendHtml(tbodyEl.RenderStartTag()); output.PostContent.AppendHtml(tbodyEl.RenderEndTag()); #endregion #region << Tfoot >> if (HasTfoot) { var tfootEl = new TagBuilder("tfoot"); var trEl = new TagBuilder("tr"); var tdEl = new TagBuilder("td"); tdEl.Attributes.Add("colspan", Columns.Count.ToString()); if (TotalCount > (PageSize * Page) || Page != 1) { var inputGroupEl = new TagBuilder("div"); inputGroupEl.AddCssClass("input-group float-right input-group-sm pager-goto"); var inputPrependEl = new TagBuilder("span"); inputPrependEl.AddCssClass("input-group-prepend"); var inputPrependTextEl = new TagBuilder("span"); inputPrependTextEl.AddCssClass("input-group-text"); inputPrependTextEl.InnerHtml.Append("page"); inputPrependEl.InnerHtml.AppendHtml(inputPrependTextEl); inputGroupEl.InnerHtml.AppendHtml(inputPrependEl); var inputCtrEl = new TagBuilder("input"); inputCtrEl.AddCssClass("form-control"); inputCtrEl.Attributes.Add("value", Page.ToString()); inputCtrEl.Attributes.Add("id", $"list-pager-form-{Id}"); inputGroupEl.InnerHtml.AppendHtml(inputCtrEl); tdEl.InnerHtml.AppendHtml(inputGroupEl); } else { var floatEl = new TagBuilder("div"); floatEl.AddCssClass("pager-info float-right"); var divider = new TagBuilder("span"); divider.AddCssClass("divider go-gray mr-2 ml-2"); divider.InnerHtml.Append("|"); floatEl.InnerHtml.AppendHtml(divider); var spanEl = new TagBuilder("span"); spanEl.InnerHtml.AppendHtml("Single page"); floatEl.InnerHtml.AppendHtml(spanEl); tdEl.InnerHtml.AppendHtml(floatEl); } if (TotalCount != 0) { var upperRecordCount = Page * PageSize; if (TotalCount < upperRecordCount) { upperRecordCount = TotalCount; } var floatEl = new TagBuilder("div"); floatEl.AddCssClass("pager-info float-right"); var pageString = $"{(Page - 1) * PageSize + 1}-{upperRecordCount} of {TotalCount}"; floatEl.InnerHtml.Append(pageString); tdEl.InnerHtml.AppendHtml(floatEl); } if (PageSize == RecordsCount || Page != 1) { var pagePrevDisabled = Page == 1; var pageNextDisabled = (TotalCount <= (PageSize * Page)); var btnGroupEl = new TagBuilder("div"); btnGroupEl.AddCssClass("btn-group float-left pager"); var prevBtnEl = new TagBuilder("button"); prevBtnEl.Attributes.Add("type", "button"); prevBtnEl.Attributes.Add("title", "Previous page"); prevBtnEl.AddCssClass($"btn-sm btn-outline-secondary {(pagePrevDisabled ? "disabled" : "")}"); if (pagePrevDisabled) { prevBtnEl.Attributes.Add("disabled", "disabled"); } prevBtnEl.Attributes.Add("onclick", $"ErpListChangePage('{(String.IsNullOrWhiteSpace(Prefix) ? "" : Prefix) + QueryStringPage}',{Page - 1})"); var prevBtnIconEl = new TagBuilder("span"); prevBtnIconEl.AddCssClass("fa fa-fw fa-angle-left mr-1"); prevBtnEl.InnerHtml.AppendHtml(prevBtnIconEl); prevBtnEl.InnerHtml.Append("Prev"); btnGroupEl.InnerHtml.AppendHtml(prevBtnEl); var nextBtnEl = new TagBuilder("button"); nextBtnEl.Attributes.Add("type", "button"); nextBtnEl.Attributes.Add("title", "Next page"); nextBtnEl.AddCssClass($"btn btn-sm btn-outline-secondary {(pageNextDisabled ? "disabled" : "")}"); if (pageNextDisabled) { nextBtnEl.Attributes.Add("disabled", "disabled"); } nextBtnEl.Attributes.Add("onclick", $"ErpListChangePage('{(String.IsNullOrWhiteSpace(Prefix) ? "" : Prefix) + QueryStringPage}',{Page + 1})"); nextBtnEl.InnerHtml.Append("Next"); var nextBtnIconEl = new TagBuilder("span"); nextBtnIconEl.AddCssClass("fa fa-fw fa-angle-right ml-1"); nextBtnEl.InnerHtml.AppendHtml(nextBtnIconEl); btnGroupEl.InnerHtml.AppendHtml(nextBtnEl); tdEl.InnerHtml.AppendHtml(btnGroupEl); } trEl.InnerHtml.AppendHtml(tdEl); tfootEl.InnerHtml.AppendHtml(trEl); output.PostContent.AppendHtml(tfootEl); } #endregion var jsCompressor = new JavaScriptCompressor(); #region << Init Scripts >> var tagHelperInitialized = false; if (ViewContext.HttpContext.Items.ContainsKey(typeof(WvGrid) + "-sort")) { var tagHelperContext = (WvTagHelperContext)ViewContext.HttpContext.Items[typeof(WvGrid) + "-sort"]; tagHelperInitialized = tagHelperContext.Initialized; } if (!tagHelperInitialized) { var scriptContent = FileService.GetEmbeddedTextResource("sort-and-page.js", "WebVella.Erp.Web.TagHelpers.WvGrid"); var scriptEl = new TagBuilder("script"); scriptEl.Attributes.Add("type", "text/javascript"); scriptEl.InnerHtml.AppendHtml(jsCompressor.Compress(scriptContent)); output.PostElement.AppendHtml(scriptEl); ViewContext.HttpContext.Items[typeof(WvGrid) + "-sort"] = new WvTagHelperContext() { Initialized = true }; } #endregion #region << Add Inline Init Script for this instance >> var initScript = new TagBuilder("script"); initScript.Attributes.Add("type", "text/javascript"); var scriptTemplate = @" $(function(){ ErpListPagerInputSubmit(""list-pager-form-{{Id}}"",""{{QueryStringPage}}""); ErpListSortInit(""{{Id}}"",""{{QueryStringSortBy}}"",""{{QueryStringSortOrder}}""); });" ; scriptTemplate = scriptTemplate.Replace("{{Id}}", Id.ToString()); scriptTemplate = scriptTemplate.Replace("{{QueryStringSortBy}}", (String.IsNullOrWhiteSpace(Prefix) ? "" : Prefix) + QueryStringSortBy); scriptTemplate = scriptTemplate.Replace("{{QueryStringSortOrder}}", (String.IsNullOrWhiteSpace(Prefix) ? "" : Prefix) + QueryStringSortOrder); scriptTemplate = scriptTemplate.Replace("{{QueryStringPage}}", (String.IsNullOrWhiteSpace(Prefix) ? "" : Prefix) + QueryStringPage); initScript.InnerHtml.AppendHtml(jsCompressor.Compress(scriptTemplate)); output.PostElement.AppendHtml(initScript); #endregion context.Items["Id"] = Id; context.Items["Culture"] = Culture; context.Items["QueryStringSortBy"] = QueryStringSortBy; context.Items["QueryStringSortOrder"] = QueryStringSortOrder; context.Items["QueryStringPage"] = QueryStringPage; context.Items["HasThead"] = HasThead; if (!String.IsNullOrWhiteSpace(Prefix)) { context.Items["Prefix"] = Prefix; } if (!String.IsNullOrWhiteSpace(Name)) { context.Items["Name"] = Name; } if (Columns.Any()) { context.Items["Columns"] = Columns; } if (VerticalAlign != VerticalAlignmentType.None) { context.Items[typeof(VerticalAlignmentType)] = VerticalAlign; } //return Task.CompletedTask; }
public void TestResponsiveBreakpointsToJson() { var responsiveBreakpoint = new ResponsiveBreakpoint().ToString(Formatting.None); Assert.AreEqual("{\"create_derived\":true}", responsiveBreakpoint, "an empty ResponsiveBreakpoint should have create_derived=true"); var expectedToken1 = JToken.Parse("{\"create_derived\":false,\"max_width\":500,\"min_width\":100,\"max_images\":5,\"transformation\":\"a_45\"}"); IEnumerable<string> expectedList1 = expectedToken1.Children().Select(s => s.ToString(Formatting.None)); Transformation transform = new Transformation().Angle(45); var breakpoint = new ResponsiveBreakpoint().CreateDerived(false) .Transformation(transform) .MaxWidth(500) .MinWidth(100) .MaxImages(5); var actualList1 = breakpoint.Children().Select(s => s.ToString(Formatting.None)); CollectionAssert.AreEquivalent(expectedList1, actualList1); breakpoint.Transformation(transform.Height(210).Crop("scale")); var expectedToken2 = JToken.Parse("{\"create_derived\":false,\"max_width\":500,\"min_width\":100,\"max_images\":5,\"transformation\":\"a_45,c_scale,h_210\"}"); var expectedList2 = expectedToken2.Children().Select(s => s.ToString(Formatting.None)); var actualList2 = breakpoint.Children().Select(s => s.ToString(Formatting.None)); CollectionAssert.AreEquivalent(expectedList2, actualList2); }
public void TestResponsiveBreakpoints() { var breakpoint = new ResponsiveBreakpoint().MaxImages(5).BytesStep(20) .MinWidth(200).MaxWidth(1000).CreateDerived(false); var breakpoint2 = new ResponsiveBreakpoint().Transformation(new Transformation().Width(0.9).Crop("scale").Radius(50)).MaxImages(4).BytesStep(20) .MinWidth(100).MaxWidth(900).CreateDerived(false); // An array of breakpoints ImageUploadParams uploadParams = new ImageUploadParams() { File = new FileDescription(m_testImagePath), PublicId = "responsiveBreakpoint_id", Tags = "test", ResponsiveBreakpoints = new List<ResponsiveBreakpoint> { breakpoint, breakpoint2 } }; ImageUploadResult result = m_cloudinary.Upload(uploadParams); Assert.Null(result.Error); Assert.NotNull(result.ResponsiveBreakpoints, "result should include 'ResponsiveBreakpoints'"); Assert.AreEqual(2, result.ResponsiveBreakpoints.Count); Assert.AreEqual(5, result.ResponsiveBreakpoints[0].Breakpoints.Count); Assert.AreEqual(1000, result.ResponsiveBreakpoints[0].Breakpoints[0].Width); Assert.AreEqual(200, result.ResponsiveBreakpoints[0].Breakpoints[4].Width); Assert.AreEqual(4, result.ResponsiveBreakpoints[1].Breakpoints.Count); Assert.AreEqual(900, result.ResponsiveBreakpoints[1].Breakpoints[0].Width); Assert.AreEqual(100, result.ResponsiveBreakpoints[1].Breakpoints[3].Width); // responsive breakpoints for Explicit() ExplicitParams exp = new ExplicitParams("responsiveBreakpoint_id") { EagerTransforms = new List<Transformation>() { new Transformation().Crop("scale").Width(2.0) }, Type = "upload", ResponsiveBreakpoints = new List<ResponsiveBreakpoint> { breakpoint2.CreateDerived(true) } }; ExplicitResult expResult = m_cloudinary.Explicit(exp); Assert.AreEqual(1, expResult.ResponsiveBreakpoints.Count); Assert.AreEqual(4, expResult.ResponsiveBreakpoints[0].Breakpoints.Count); Assert.AreEqual(900, expResult.ResponsiveBreakpoints[0].Breakpoints[0].Width); Assert.AreEqual(100, expResult.ResponsiveBreakpoints[0].Breakpoints[3].Width); }