Skip to content

Commit

Permalink
Fixing part display name edition (#1057)
Browse files Browse the repository at this point in the history
Fixes #1049
  • Loading branch information
sebastienros committed Oct 3, 2017
1 parent f75ec38 commit 81f641d
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public override IDisplayResult Edit(ContentPartDefinition contentPartDefinition)
model.Attachable = settings.Attachable;
model.Reusable = settings.Reusable;
model.Description = settings.Description;
model.DisplayName = settings.DisplayName;
model.ContentPartDefinition = contentPartDefinition;
return Task.CompletedTask;
}).Location("Content");
Expand All @@ -32,6 +34,7 @@ public override async Task<IDisplayResult> UpdateAsync(ContentPartDefinition con
context.Builder.Attachable(model.Attachable);
context.Builder.Reusable(model.Reusable);
context.Builder.WithDescription(model.Description);
context.Builder.WithDisplayName(model.DisplayName);
}

return Edit(contentPartDefinition, context.Updater);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
namespace OrchardCore.ContentTypes.ViewModels
using Microsoft.AspNetCore.Mvc.ModelBinding;
using OrchardCore.ContentManagement.Metadata.Models;

namespace OrchardCore.ContentTypes.ViewModels
{
public class ContentPartSettingsViewModel
{
public bool Attachable { get; set; }
public bool Reusable { get; set; }
public string Description { get; set; }
public string DisplayName { get; set; }

[BindNever]
public ContentPartDefinition ContentPartDefinition { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
<form asp-action="EditPart">
@Html.ValidationSummary()

<fieldset class="form-group">
<div class="row col-md ">
<label asp-for="DisplayName">@T["Display Name"]</label>
<input asp-for="DisplayName" class="form-control" />
<span class="hint">@T["Name of the type as it will be displayed in screens."]</span>
</div>
</fieldset>

<fieldset class="form-group">
<div class="row col-sm">
<label asp-for="Name">@T["Technical Name"]</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
@model ContentPartSettingsViewModel
@using OrchardCore.ContentManagement.Metadata.Settings
@model ContentPartSettingsViewModel

<fieldset class="form-group">
<div class="row col-md ">
<label asp-for="DisplayName" >@T["Display Name"]</label>
<input asp-for="DisplayName" class="form-control" placeholder="@Model.ContentPartDefinition.DisplayName()" />
<span class="hint">@T["Name of the part as it will be displayed in screens. Leave empty to use defaults."]</span>
</div>
</fieldset>

<fieldset class="form-group">
<div class="row col-lg ">
<label asp-for="Description">@T["Description"]</label>
@Html.ValidationMessageFor(m => m.Description)
<input asp-for="Description" class="form-control" />
<span class="hint">@T["Optionally provide a description for this part"]</span>
<span class="hint">@T["Optionally provide a description for this part."]</span>
</div>
</fieldset>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@model EditPartViewModel
@using OrchardCore.ContentManagement.Metadata.Settings
@model EditPartViewModel
<div class="properties">
<div class="related">
<a class="btn btn-primary btn-sm" asp-route-action="EditPart" asp-route-id="@Model.Name">@T["Edit"]</a>
</div>
<div>@Model.DisplayName</div>
<div>@Model.PartDefinition.DisplayName()</div>
@if (!string.IsNullOrWhiteSpace(Model.Description))
{
<span class="hint">@Model.Description</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Localization;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.ContentManagement.Metadata.Settings;
using OrchardCore.ContentTypes.Editors;
using OrchardCore.DisplayManagement.Views;
using OrchardCore.Templates.ViewModels;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Linq;

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using OrchardCore.ContentManagement.Metadata.Builders;
using System;
using OrchardCore.ContentManagement.Metadata.Builders;
using OrchardCore.ContentManagement.Metadata.Models;
using OrchardCore.Mvc.Utilities;

namespace OrchardCore.ContentManagement.Metadata.Settings
{
Expand Down Expand Up @@ -30,9 +32,26 @@ public static ContentPartDefinitionBuilder WithDescription(this ContentPartDefin
return builder.WithSetting(nameof(ContentPartSettings.Description), description);
}

public static ContentPartDefinitionBuilder WithDisplayName(this ContentPartDefinitionBuilder builder, string description)
{
return builder.WithSetting(nameof(ContentPartSettings.DisplayName), description);
}

public static string Description(this ContentPartDefinition part)
{
return part.Settings.ToObject<ContentPartSettings>().Description;
}

public static string DisplayName(this ContentPartDefinition part)
{
var displayName = part.Settings.ToObject<ContentPartSettings>().DisplayName;

if (String.IsNullOrEmpty(displayName))
{
displayName = part.Name.TrimEnd("Part");
}

return displayName;
}
}
}

0 comments on commit 81f641d

Please sign in to comment.