Last active
October 30, 2017 20:20
-
-
Save naepalm/80ac4c75186a79a936ab to your computer and use it in GitHub Desktop.
Grid view & controls for Skybrud's strongly typed models with Responsive BP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model GridControl | |
@using Grid.Web | |
@using Skybrud.Umbraco.GridData | |
@try | |
{ | |
<text>@Html.Partial(Model.EditorView(), Model)</text> | |
} | |
catch (Exception ex) { | |
<pre>@ex.ToString()</pre> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Skybrud.Umbraco.GridData.Values | |
@model Skybrud.Umbraco.GridData.GridControl | |
@Html.Raw(Model.GetValue<GridControlEmbedValue>()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Skybrud.Umbraco.GridData.Values | |
@inherits UmbracoViewPage<Skybrud.Umbraco.GridData.GridControl> | |
@if (Model.Value != null) | |
{ | |
var value = Model.GetValue<GridControlMacroValue>(); | |
string macroAlias = value.MacroAlias; | |
ViewDataDictionary parameters = new ViewDataDictionary(); | |
foreach (dynamic mpd in value.Parameters) | |
{ | |
parameters.Add(mpd.Name, mpd.Value); | |
} | |
<text> | |
@Umbraco.RenderMacro(macroAlias, parameters) | |
</text> | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Skybrud.Umbraco.GridData.Config | |
@using Skybrud.Umbraco.GridData.Values | |
@model Skybrud.Umbraco.GridData.GridControl | |
@if (Model.Value != null) | |
{ | |
var value = Model.GetValue<GridControlMediaValue>(); | |
var config = (GridEditorMediaConfig)Model.Editor.Config; | |
var url = value.Image; | |
if(config != null && config.Size != null) | |
{ | |
url += "?width=" + config.Size.Width; | |
url += "&height=" + config.Size.Height; | |
if(value.FocalPoint != null){ | |
url += "¢er=" + value.FocalPoint.Top +"," + value.FocalPoint.Left; | |
url += "&mode=crop"; | |
} | |
} | |
<img src="@url" alt="@(value.JObject.GetValue("altText"))"> | |
if (value.Caption != null) | |
{ | |
<p class="caption">@(value.Caption)</p> | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model Skybrud.Umbraco.GridData.GridControl | |
@using Skybrud.Umbraco.GridData.Values | |
@using Umbraco.Web.Templates | |
@Html.Raw(TemplateUtilities.ParseInternalLinks(Model.GetValue<GridControlRichTextValue>().Value)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model Skybrud.Umbraco.GridData.GridControl | |
@using Skybrud.Umbraco.GridData.Config | |
@using Skybrud.Umbraco.GridData.Values | |
@{ | |
var config = (GridEditorTextConfig)Model.Editor.Config; | |
if (config.Markup != null) | |
{ | |
var markup = config.Markup; | |
markup = markup.Replace("#value#", Model.GetValue<GridControlTextValue>().Value); | |
markup = markup.Replace("#style#", config.Style); | |
<text> | |
@Html.Raw(markup) | |
</text> | |
} | |
else | |
{ | |
<text> | |
<div style="@config.Style">@(Model.GetValue<GridControlTextValue>().Value)</div> | |
</text> | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Mvc; | |
using Newtonsoft.Json.Linq; | |
using Skybrud.Umbraco.GridData; | |
namespace Grid.Web | |
{ | |
public static class GridExtensions | |
{ | |
public static string EditorView(this GridControl control) | |
{ | |
string view = control.Editor.Render ?? control.Editor.View; | |
view = view.ToLower().Replace(".html", ".cshtml"); | |
if (!view.Contains("/")) | |
{ | |
view = "grid/editors/" + view; | |
} | |
return view; | |
} | |
public static MvcHtmlString RenderAttributes(this GridRow row) | |
{ | |
var attrs = new List<string>(); | |
var cfg = row.Config.JObject; | |
var style = row.Styles.JObject; | |
if (cfg != null) | |
{ | |
attrs.AddRange(cfg.Properties().Select(property => property.Name + "=\"" + property.Value + "\"")); | |
} | |
if (style != null) | |
{ | |
var cssVals = style.Properties().Select(property => property.Name + ":" + property.Value + ";").ToList(); | |
if (cssVals.Any()) | |
attrs.Add("style=\"" + string.Join(" ", cssVals) + "\""); | |
} | |
return new MvcHtmlString(string.Join(" ", attrs)); | |
} | |
public static MvcHtmlString RenderAttributes(this GridArea area) | |
{ | |
var attrs = new List<string>(); | |
var cfg = area.Config.JObject; | |
var style = area.Styles.JObject; | |
if (cfg != null) | |
{ | |
attrs.AddRange(cfg.Properties().Select(property => property.Name + "=\"" + property.Value + "\"")); | |
} | |
if (style != null) | |
{ | |
var cssVals = style.Properties().Select(property => property.Name + ":" + property.Value + ";").ToList(); | |
if (cssVals.Any()) | |
attrs.Add("style=\"" + string.Join(" ", cssVals) + "\""); | |
} | |
return new MvcHtmlString(string.Join(" ", attrs)); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Grid.Web | |
@using Skybrud.Umbraco.GridData | |
@inherits UmbracoViewPage<GridDataModel> | |
@* | |
Razor helpers located at the bottom of this file | |
*@ | |
@if (Model != null) | |
{ | |
if (Model.Sections.Any()) | |
{ | |
var oneColumn = ((System.Collections.ICollection)Model.Sections).Count == 1; | |
if (oneColumn) | |
{ | |
foreach (var section in Model.Sections) | |
{ | |
<section class="gridview"> | |
@foreach (var row in section.Rows) | |
{ | |
@RenderRow(row, true) | |
} | |
</section> | |
} | |
} | |
else | |
{ | |
<section class="row clearfix gridview"> | |
@foreach (var s in Model.Sections) | |
{ | |
<div class="[email protected]"> | |
@foreach (var row in s.Rows) | |
{ | |
@RenderRow(row, false) | |
} | |
</div> | |
} | |
</section> | |
} | |
} | |
} | |
@helper RenderRow(GridRow row, bool singleColumn) | |
{ | |
<div class="row clearfix @row.Name.ToLower().Replace(' ', '-')" @row.RenderAttributes()> | |
@foreach (var area in row.Areas) | |
{ | |
if (@area.Controls.Any()) | |
{ | |
<div class="[email protected]" @area.RenderAttributes()> | |
@foreach (var control in area.Controls) | |
{ | |
if (control != null && control.Editor != null && control.Editor.View != null) | |
{ | |
<text>@Html.Partial("grid/editors/base", control)</text> | |
} | |
} | |
</div> | |
} | |
} | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment