Skip to content

Commit

Permalink
Merge pull request #11 from jcdcdev/dev
Browse files Browse the repository at this point in the history
feature: multi target (Umbraco 10-13)
  • Loading branch information
jcdcdev authored Jan 4, 2024
2 parents 7cee6ec + 9719b8f commit 1bf041e
Show file tree
Hide file tree
Showing 115 changed files with 4,244 additions and 452 deletions.
3 changes: 2 additions & 1 deletion .github/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Umbraco.Community.SimpleDashboards

[![Downloads](https://img.shields.io/nuget/dt/Umbraco.Community.SimpleDashboards?color=cc9900)](https://www.nuget.org/packages/Umbraco.Community.SimpleDashboards/)
[![Umbraco Version](https://img.shields.io/badge/Umbraco-10.4+-%233544B1?style=flat&logo=umbraco)](https://umbraco.com/products/umbraco-cms/)
[![NuGet](https://img.shields.io/nuget/vpre/Umbraco.Community.SimpleDashboards?color=0273B3)](https://www.nuget.org/packages/Umbraco.Community.SimpleDashboards)
[![GitHub license](https://img.shields.io/github/license/jcdcdev/Umbraco.Community.SimpleDashboards?color=8AB803)](https://github.com/jcdcdev/Umbraco.Community.SimpleDashboards/blob/main/LICENSE)
[![Downloads](https://img.shields.io/nuget/dt/Umbraco.Community.SimpleDashboards?color=cc9900)](https://www.nuget.org/packages/Umbraco.Community.SimpleDashboards/)

This packages aims to help developers quickly put together Umbraco Dashboards using C# only.

Expand Down
415 changes: 13 additions & 402 deletions src/.editorconfig

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,13 @@ appsettings-schema.json
# Temp folder containing Examine indexes, NuCache, MediaCache, etc.
/umbraco/Data/TEMP/

# SQLite database files - enable if you don't want to commit your test DB to the repo
#/umbraco/Data/*.sqlite.db
#/umbraco/Data/*.sqlite.db-shm
#/umbraco/Data/*.sqlite.db-wal
# SQLite database files
/umbraco/Data/*.sqlite.db
/umbraco/Data/*.sqlite.db-shm
/umbraco/Data/*.sqlite.db-wal

# Log files
/umbraco/Logs/

# Media files
/wwwroot/media/

# Test Site App_Plugins packages folder (exclude here as in Umbraco.Community.SimpleDashboards project)
/App_Plugins/Umbraco.Community.SimpleDashboards/
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Umbraco.Community.SimpleDashboards.Core;

namespace Umbraco.Community.SimpleDashboards.TestSite.Dashboards;
namespace TestSite.Ten.Dashboards;

public class BasicDashboard : SimpleDashboard
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using jcdcdev.Umbraco.Core.AccessRule;
using Umbraco.Community.SimpleDashboards.Core;

namespace Umbraco.Community.SimpleDashboards.TestSite.Dashboards;
namespace TestSite.Ten.Dashboards;

// Control order of where dashboard shows
[Umbraco.Cms.Core.Composing.Weight(-100)]
Expand All @@ -15,8 +15,8 @@ public ExampleDashboard()
SetName("Example Dashboard Name (en-GB)", "en-GB");

// Show dashboard in the Media & Content sections
AddSection(Cms.Core.Constants.Applications.Media);
AddSection(Cms.Core.Constants.Applications.Content);
AddSection(Umbraco.Cms.Core.Constants.Applications.Media);
AddSection(Umbraco.Cms.Core.Constants.Applications.Content);

// Allow Editors
AddAccessRule(SimpleAccessRule.AllowEditorGroup);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Umbraco.Community.SimpleDashboards.Core;

namespace Umbraco.Community.SimpleDashboards.TestSite.Dashboards;
namespace TestSite.Ten.Dashboards;

public class NoViewDashboard : SimpleDashboard
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace Umbraco.Community.SimpleDashboards.TestSite
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace TestSite.Ten
{
public class Program
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59495",
"sslPort": 44315
"applicationUrl": "http://localhost:16958",
"sslPort": 44316
}
},
"profiles": {
Expand All @@ -20,7 +20,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:44315;http://localhost:59495",
"applicationUrl": "https://localhost:44316;http://localhost:16958",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
namespace Umbraco.Community.SimpleDashboards.TestSite
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Extensions;

namespace TestSite.Ten
{
public class Startup
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>TestSite.Ten</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Umbraco.Cms" Version="10.6.1" />
<PackageReference Include="Umbraco.Cms" Version="10.4.0"/>
</ItemGroup>

<ItemGroup>
<!-- Opt-in to app-local ICU to ensure consistent globalization APIs across different platforms -->
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9" />
<RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2.0.9" Condition="$(RuntimeIdentifier.StartsWith('linux')) or $(RuntimeIdentifier.StartsWith('win')) or ('$(RuntimeIdentifier)' == '' and !$([MSBuild]::IsOSPlatform('osx')))" />
<PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9"/>
<RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2.0.9" Condition="$(RuntimeIdentifier.StartsWith('linux')) or $(RuntimeIdentifier.StartsWith('win')) or ('$(RuntimeIdentifier)' == '' and !$([MSBuild]::IsOSPlatform('osx')))"/>
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.*.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Umbraco.Community.SimpleDashboards\Umbraco.Community.SimpleDashboards.csproj" />
</ItemGroup>

<PropertyGroup>
Expand All @@ -26,21 +37,4 @@
<RazorCompileOnPublish>false</RazorCompileOnPublish>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Umbraco.Community.SimpleDashboards\Umbraco.Community.SimpleDashboards.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="appsettings.*.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
</ItemGroup>

<ItemGroup>
<_ContentIncludedByDefault Remove="Views\Partials\blockgrid\area.cshtml" />
<_ContentIncludedByDefault Remove="Views\Partials\blockgrid\areas.cshtml" />
<_ContentIncludedByDefault Remove="Views\Partials\blockgrid\default.cshtml" />
<_ContentIncludedByDefault Remove="Views\Partials\blockgrid\items.cshtml" />
<_ContentIncludedByDefault Remove="Views\Partials\blocklist\default.cshtml" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Community.SimpleDashboards.Web;

namespace TestSite.Ten.Views.Components;

public class ExampleDashboardAsyncViewComponent : DashboardAsyncViewComponent
{
public override async Task<IViewComponentResult> InvokeAsync(DashboardModel model)
{
// Simulate async workload
await Task.Delay(TimeSpan.FromMilliseconds(1));
return Content($"Hello {model.Dashboard.Alias}");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc;
using Umbraco.Community.SimpleDashboards.Web;

namespace Umbraco.Community.SimpleDashboards.TestSite.Views.Components;
namespace TestSite.Ten.Views.Components;

public class ExampleDashboardViewComponent : DashboardViewComponent
{
Expand Down
10 changes: 10 additions & 0 deletions src/TestSite.10/Views/Partials/blockgrid/area.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@using Umbraco.Extensions
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockGridArea>

<div class="umb-block-grid__area"
data-area-col-span="@Model.ColumnSpan"
data-area-row-span="@Model.RowSpan"
data-area-alias="@Model.Alias"
style="--umb-block-grid--grid-columns: @Model.ColumnSpan;--umb-block-grid--area-column-span: @Model.ColumnSpan; --umb-block-grid--area-row-span: @Model.RowSpan;">
@await Html.GetBlockGridItemsHtmlAsync(Model)
</div>
13 changes: 13 additions & 0 deletions src/TestSite.10/Views/Partials/blockgrid/areas.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@using Umbraco.Extensions
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockGridItem>
@{
if (Model?.Areas.Any() != true) { return; }
}

<div class="umb-block-grid__area-container"
style="--umb-block-grid--area-grid-columns: @(Model.AreaGridColumns?.ToString() ?? Model.GridColumns?.ToString() ?? "12");">
@foreach (var area in Model.Areas)
{
@await Html.GetBlockGridItemAreaHtmlAsync(area)
}
</div>
11 changes: 11 additions & 0 deletions src/TestSite.10/Views/Partials/blockgrid/default.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@using Umbraco.Extensions
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockGridModel>
@{
if (Model?.Any() != true) { return; }
}

<div class="umb-block-grid"
data-grid-columns="@(Model.GridColumns?.ToString() ?? "12");"
style="--umb-block-grid--grid-columns: @(Model.GridColumns?.ToString() ?? "12");">
@await Html.GetBlockGridItemsHtmlAsync(Model)
</div>
36 changes: 36 additions & 0 deletions src/TestSite.10/Views/Partials/blockgrid/items.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@using Umbraco.Cms.Core.Models.Blocks
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<IEnumerable<BlockGridItem>>
@{
if (Model?.Any() != true) { return; }
}

<div class="umb-block-grid__layout-container">
@foreach (var item in Model)
{

<div
class="umb-block-grid__layout-item"
data-content-element-type-alias="@item.Content.ContentType.Alias"
data-content-element-type-key="@item.Content.ContentType.Key"
data-element-udi="@item.ContentUdi"
data-col-span="@item.ColumnSpan"
data-row-span="@item.RowSpan"
style=" --umb-block-grid--item-column-span: @item.ColumnSpan; --umb-block-grid--item-row-span: @item.RowSpan; ">
@{
var partialViewName = "blockgrid/Components/" + item.Content.ContentType.Alias;
try
{
@await Html.PartialAsync(partialViewName, item)
}
catch (InvalidOperationException)
{
<p>
<strong>Could not render component of type: @(item.Content.ContentType.Alias)</strong>
<br/>
This likely happened because the partial view <em>@partialViewName</em> could not be found.
</p>
}
}
</div>
}
</div>
13 changes: 13 additions & 0 deletions src/TestSite.10/Views/Partials/blocklist/default.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.BlockListModel>
@{
if (Model?.Any() != true) { return; }
}
<div class="umb-block-list">
@foreach (var block in Model)
{
if (block?.ContentUdi == null) { continue; }
var data = block.Content;

@await Html.PartialAsync("blocklist/Components/" + data.ContentType.Alias, block)
}
</div>
106 changes: 106 additions & 0 deletions src/TestSite.10/Views/Partials/grid/bootstrap3-fluid.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@using System.Web
@using Microsoft.AspNetCore.Html
@using Newtonsoft.Json.Linq
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<dynamic>

@*
Razor helpers located at the bottom of this file
*@

@if (Model is JObject && Model?.sections is not null)
{
var oneColumn = ((System.Collections.ICollection)Model.sections).Count == 1;

<div class="umb-grid">
@if (oneColumn)
{
foreach (var section in Model.sections)
{
<div class="grid-section">
@foreach (var row in section.rows)
{
renderRow(row);
}
</div>
}
}
else
{
<div class="row clearfix">
@foreach (var sec in Model.sections)
{
<div class="grid-section">
<div class="[email protected] column">
@foreach (var row in sec.rows)
{
renderRow(row);
}
</div>
</div>
}
</div>
}
</div>
}

@functions{

private async Task renderRow(dynamic row)
{
<div @RenderElementAttributes(row)>
<div class="row clearfix">
@foreach (var area in row.areas)
{
<div class="[email protected] column">
<div @RenderElementAttributes(area)>
@foreach (var control in area.controls)
{
if (control?.editor?.view != null)
{
<text>@await Html.PartialAsync("grid/editors/base", (object)control)</text>
}
}
</div>
</div>
}
</div>
</div>
}
}

@functions{

public static HtmlString RenderElementAttributes(dynamic contentItem)
{
var attrs = new List<string>();
JObject cfg = contentItem.config;

if (cfg != null)
{
foreach (JProperty property in cfg.Properties())
{
var propertyValue = HttpUtility.HtmlAttributeEncode(property.Value.ToString());
attrs.Add(property.Name + "=\"" + propertyValue + "\"");
}
}

JObject style = contentItem.styles;

if (style != null) {
var cssVals = new List<string>();
foreach (JProperty property in style.Properties())
{
var propertyValue = property.Value.ToString();
if (string.IsNullOrWhiteSpace(propertyValue) == false)
{
cssVals.Add(property.Name + ":" + propertyValue + ";");
}
}

if (cssVals.Any())
attrs.Add("style='" + HttpUtility.HtmlAttributeEncode(string.Join(" ", cssVals)) + "'");
}

return new HtmlString(string.Join(" ", attrs));
}
}
Loading

0 comments on commit 1bf041e

Please sign in to comment.