Skip to content

Commit

Permalink
Fixes #177 (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBleijendaal authored Aug 29, 2022
1 parent af3acf6 commit d17ce98
Show file tree
Hide file tree
Showing 27 changed files with 343 additions and 105 deletions.
52 changes: 52 additions & 0 deletions QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,58 @@ editor set up for editing an entity:

![CMS](examples/images/docs3.png)

### Fields

Fields are either display elements in Views, or editors in Editors. They bind to properties in the
entity you have connected to the collection. Displays and editors have the following methods to
configure them:

#### SetName (display + editor)

Sets the name in the associated table cell or label.

#### SetDescription (display + editor)

Sets a small text under the name.

#### SetDetails (display + editor)

Sets a free html element under the display or editor.

#### SetPlaceholder (editor)

Sets the placeholder text for editors.

#### SetType (display + editor)

Sets the type of the display or editor.

#### VisibleWhen (display + editor)

Allows for configuring a `Func` that controls when the field is visible.

#### DisableWhen (editor)

Allows for configuring a `Func` that controls when the editor is disabled.

#### SetOrderByExpression (display + editor)

Sets the order by expression used in list views to control the order in which the data is displayed.

#### SetDataCollection (editor)

Sets the associated data collection used by dropdown (and related) editors. See "DataCollection".

#### SetConfiguration (display + editor)

Allows for configuring an async `Func` that feeds configuration (any type of object) into
the field for the field to use. This object can be anything, and can be used to customize the field, or
add custom logic to the field. As it is async, it can even be a database call or any other async process.

#### SetCollectionRelation (editor)

Sets the associated collection used for making and breaking releations between entities. See "Relations".

### Buttons

The default buttons in RapidCMS will provide the bulk of the operations you will need when
Expand Down
3 changes: 1 addition & 2 deletions examples/RapidCMS.Example.Maui/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.RegisterBlazorMauiWebView()
.UseMauiApp<App>();

builder.Services.AddBlazorWebView();
builder.Services.AddMauiBlazorWebView();

builder.Services.AddAuthorizationCore();

Expand Down
5 changes: 1 addition & 4 deletions examples/RapidCMS.Example.Maui/Platforms/Windows/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Maui;
using Microsoft.Maui.Hosting;
using Microsoft.UI.Xaml;
using Windows.ApplicationModel;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
Expand All @@ -19,16 +18,14 @@ public partial class App : MauiWinUIApplication
/// </summary>
public App()
{
this.InitializeComponent();
InitializeComponent();
}

protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
base.OnLaunched(args);

Microsoft.Maui.Essentials.Platform.OnLaunched(args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,42 @@
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">

<Identity
Name="6279BE06-CCF2-43B4-98E9-04A3E222977F"
Publisher="CN=User Name"
Version="1.0.0.0" />

<Properties>
<DisplayName>RapidCMS.Example.Maui</DisplayName>
<PublisherDisplayName>Microsoft</PublisherDisplayName>
<Logo>Assets\appiconStoreLogo.png</Logo>
</Properties>

<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>

<Resources>
<Resource Language="x-generate"/>
</Resources>

<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="RapidCMS.Example.Maui"
Description="RapidCMS.Example.Maui"
BackgroundColor="transparent"
Square150x150Logo="Assets\appiconMediumTile.png"
Square44x44Logo="Assets\appiconLogo.png">
<uap:DefaultTile
Wide310x150Logo="Assets\appiconWideTile.png"
Square71x71Logo="Assets\appiconSmallTile.png"
Square310x310Logo="Assets\appiconLargeTile.png"
ShortName="RapidCMS.Example.Maui">
<uap:ShowNameOnTiles>
<uap:ShowOn Tile="square150x150Logo"/>
<uap:ShowOn Tile="wide310x150Logo"/>
</uap:ShowNameOnTiles>
</uap:DefaultTile >
<uap:SplashScreen Image="Assets\appiconfgSplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>

<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
<Identity
Name="6279BE06-CCF2-43B4-98E9-04A3E222977F"
Publisher="CN=User Name"
Version="1.0.0.0" />

<Properties>
<DisplayName>RapidCMS.Example.Maui</DisplayName>
<PublisherDisplayName>Microsoft</PublisherDisplayName>
<Logo>Assets\appiconStoreLogo.png</Logo>
</Properties>

<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>

<Resources>
<Resource Language="x-generate"/>
</Resources>

<Applications>
<Application Id="App" Executable="$targetnametoken$.exe" EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="$placeholder$"
Description="$placeholder$"
Square150x150Logo="$placeholder$.png"
Square44x44Logo="$placeholder$.png"
BackgroundColor="transparent">
<uap:DefaultTile Square71x71Logo="$placeholder$.png" Wide310x150Logo="$placeholder$.png" Square310x310Logo="$placeholder$.png" />
<uap:SplashScreen Image="$placeholder$.png" />
</uap:VisualElements>
</Application>
</Applications>

<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>

</Package>
17 changes: 2 additions & 15 deletions examples/RapidCMS.Example.Maui/RapidCMS.Example.Maui.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks>net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks>
<Nullable>enable</Nullable>
<ProjectUISubcaption>Maui + Blazor WebAssembly</ProjectUISubcaption>
Expand All @@ -25,9 +25,7 @@
<!-- Required for C# Hot Reload -->
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>

<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</TargetPlatformMinVersion>
</PropertyGroup>
Expand All @@ -40,23 +38,12 @@
<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiImage Include="Resources\*" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.Contains('-windows'))">
<!-- Required - WinUI does not yet have buildTransitive for everything -->
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.0.30" />
</ItemGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
<OutputType>WinExe</OutputType>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
<Content Remove="Properties\launchSettings.json" />
</ItemGroup>
Expand Down
20 changes: 19 additions & 1 deletion examples/RapidCMS.Example.Shared/Collections/PersonCollection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Components;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using RapidCMS.Core.Abstractions.Config;
using RapidCMS.Core.Enums;
using RapidCMS.Core.Models.Configuration;
using RapidCMS.Core.Repositories;
using RapidCMS.Example.Shared.Components;
using RapidCMS.Example.Shared.Data;
Expand Down Expand Up @@ -70,6 +72,20 @@ public static void AddPersonCollection(this ICmsConfig config)
row.AddField(p => p.Id).SetType(EditorType.Readonly);
row.AddField(p => p.Name);

// the DisplayType Link requires an instance of Link to be configured to the editor.
// form elements can indicate that they want or require configuration by implementing either
// IWantConfiguration or INeedConfiguration.
row.AddField(p => p.Details.SocialUrl).SetName("Social account")
.SetType(DisplayType.Link)
.SetConfiguration(async (entity, state) =>
{
// this method can be async, making it possible to do some custom logic here before
// passing it into the form element
await Task.Delay(1000);

return new Link($"{entity.Name}'s account", false);
});

// the SaveExisting button is only displayed when an entity is edited
row.AddDefaultButton(DefaultButtonType.SaveExisting, isPrimary: true);
// the SaveNew button is only displayed when an entity is inserted
Expand Down Expand Up @@ -111,6 +127,8 @@ public static void AddPersonCollection(this ICmsConfig config)
// so using SetName this can be set to something more user friendly
.SetName("Email")
.SetDetails(new MarkupString("<p>An email adress looks like <code>name@domain.tld</code>.</p>"));

section.AddField(x => x.Details.SocialUrl);
});

// you can even have sections specifically for an entity type.
Expand Down
7 changes: 6 additions & 1 deletion examples/RapidCMS.Example.Shared/Data/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public object Clone()
Details = new PersonDetails
{
Bio = Details.Bio,
Email = Details.Email
Email = Details.Email,
SocialUrl = Details.SocialUrl
}
};
}
Expand All @@ -40,6 +41,10 @@ public class PersonDetails
[Required]
[MinLength(5)]
public string Email { get; set; } = default!;

[Url]
public string? SocialUrl { get; set; }

public string? Bio { get; set; }
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/RapidCMS.Core/Abstractions/Config/ICollectionConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ ICollectionDetailPageEditorConfig<TDetailEntity> AddDetailPage<TDetailEntity, TD
/// <param name="queryExpression">Query defining this data view</param>
/// <param name="orderByExpressions">Order by expressions for this data view</param>
/// <returns></returns>
ICollectionConfig<TEntity> AddDataView(string label, Expression<Func<TEntity, bool>> queryExpression, Action<IOrderByConfig<TEntity>>? orderByExpressions);
ICollectionConfig<TEntity> AddDataView(string label, Expression<Func<TEntity, bool>> queryExpression, Action<IOrderByConfig<TEntity>>? orderByExpressions = null);

/// <summary>
/// Adds an entity variant to the collection. Entity variants are derivatives of TEntity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RapidCMS.Core.Abstractions.Config
public interface IDisplayFieldConfig<TEntity, TValue>
: IHasOrderBy<TEntity, IDisplayFieldConfig<TEntity, TValue>>,
IHasNameDescription<IDisplayFieldConfig<TEntity, TValue>>,
IHasConfigurability<IDisplayFieldConfig<TEntity, TValue>>
IHasConfigurability<TEntity, IDisplayFieldConfig<TEntity, TValue>>
where TEntity : IEntity
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IEditorFieldConfig<TEntity, TValue>
: IHasOrderBy<TEntity, IEditorFieldConfig<TEntity, TValue>>,
IHasNameDescription<IEditorFieldConfig<TEntity, TValue>>,
IHasPlaceholder<IEditorFieldConfig<TEntity, TValue>>,
IHasConfigurability<IEditorFieldConfig<TEntity, TValue>>
IHasConfigurability<TEntity, IEditorFieldConfig<TEntity, TValue>>
where TEntity : IEntity
{
/// <summary>
Expand Down
29 changes: 26 additions & 3 deletions src/RapidCMS.Core/Abstractions/Config/IHasConfigurability.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
namespace RapidCMS.Core.Abstractions.Config
using System;
using System.Threading.Tasks;
using RapidCMS.Core.Enums;

namespace RapidCMS.Core.Abstractions.Config
{
public interface IHasConfigurability<TReturn>
public interface IHasConfigurability<TEntity, TReturn>
{
/// <summary>
/// Sets configuration for the field. This will be made available in the component as Configuration property.
/// Use IWantConfiguration and IRequireConfiguration interfaces to gain access to the GetConfig() extension method.
/// </summary>
/// <typeparam name="TConfig"></typeparam>
/// <param name="config"></param>
/// <returns></returns>
TReturn SetConfiguration<TConfig>(TConfig config);
TReturn SetConfiguration<TConfig>(TConfig config) where TConfig : class;

/// <summary>
/// Sets configuration for the field. This will be made available in the component as Configuration property.
/// Use IWantConfiguration and IRequireConfiguration interfaces to gain access to the GetConfig() extension method.
/// </summary>
/// <typeparam name="TConfig"></typeparam>
/// <param name="config"></param>
/// <returns></returns>
TReturn SetConfiguration<TConfig>(Func<TEntity, EntityState, TConfig?> config) where TConfig : class;

/// <summary>
/// Sets configuration for the field. This will be made available in the component as Configuration property.
/// Use IWantConfiguration and IRequireConfiguration interfaces to gain access to the GetConfig() extension method.
/// </summary>
/// <typeparam name="TConfig"></typeparam>
/// <param name="config"></param>
/// <returns></returns>
TReturn SetConfiguration<TConfig>(Func<TEntity, EntityState, Task<TConfig?>> config) where TConfig : class;
}
}
13 changes: 13 additions & 0 deletions src/RapidCMS.Core/Abstractions/UI/IBaseUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
using RapidCMS.Core.Abstractions.Data;
using RapidCMS.Core.Enums;

namespace RapidCMS.Core.Abstractions.UI;

public interface IBaseUIElement
{
IEntity Entity { get; }
EntityState EntityState { get; }
Func<object, EntityState, Task<object?>>? Configuration { get; }
}
6 changes: 6 additions & 0 deletions src/RapidCMS.Core/Abstractions/UI/IRequireConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace RapidCMS.Core.Abstractions.UI;

public interface IRequireConfiguration<TConfig> : IBaseUIElement
where TConfig : class
{
}
6 changes: 6 additions & 0 deletions src/RapidCMS.Core/Abstractions/UI/IWantConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace RapidCMS.Core.Abstractions.UI;

public interface IWantConfiguration<TConfig> : IBaseUIElement
where TConfig : class
{
}
3 changes: 2 additions & 1 deletion src/RapidCMS.Core/Enums/DisplayType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum DisplayType
Custom = -1,

Label = 0,
Pre
Pre,
Link
}
}
Loading

0 comments on commit d17ce98

Please sign in to comment.