Convert AchiveLater to new Shape API

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-10-18 13:17:37 -07:00
parent 134700079e
commit b88df3db38
6 changed files with 34 additions and 37 deletions

View File

@@ -29,22 +29,26 @@ namespace ArchiveLater.Drivers {
public IOrchardServices Services { get; set; }
protected override DriverResult Display(ArchiveLaterPart part, string displayType, dynamic shapeHelper) {
var metadata = shapeHelper.Parts_ArchiveLater_Metadata(ContentPart: part, ScheduledArchiveUtc: part.ScheduledArchiveUtc.Value);
if (!string.IsNullOrWhiteSpace(displayType))
metadata.Metadata.Type = string.Format("{0}.{1}", metadata.Metadata.Type, displayType);
var location = part.GetLocation(displayType);
return ContentShape(metadata).Location(location);
return ContentShape("Parts_ArchiveLater_Metadata_SummaryAdmin",
shape => {
part.ScheduledArchiveUtc.Value = DateTime.UtcNow.AddDays(5);
return shape
.ContentPart(part)
.ScheduledArchiveUtc(part.ScheduledArchiveUtc.Value)
.IsPublished(part.ContentItem.VersionRecord != null && part.ContentItem.VersionRecord.Published);
});
}
protected override DriverResult Editor(ArchiveLaterPart part, dynamic shapeHelper) {
return ArchiveEditor(part, null);
return ArchiveEditor(part, null, shapeHelper);
}
protected override DriverResult Editor(ArchiveLaterPart instance, IUpdateModel updater, dynamic shapeHelper) {
return ArchiveEditor(instance, updater);
return ArchiveEditor(instance, updater, shapeHelper);
}
DriverResult ArchiveEditor(ArchiveLaterPart part, IUpdateModel updater) {
DriverResult ArchiveEditor(ArchiveLaterPart part, IUpdateModel updater, dynamic shapeHelper) {
var model = new ArchiveLaterViewModel(part);
if ( updater != null && updater.TryUpdateModel(model, TemplatePrefix, null, null) ) {
@@ -53,14 +57,14 @@ namespace ArchiveLater.Drivers {
if (DateTime.TryParse(string.Format("{0} {1}", model.ScheduledArchiveDate, model.ScheduledArchiveTime), out scheduled))
model.ScheduledArchiveUtc = scheduled.ToUniversalTime();
_archiveLaterService.ArchiveLater(model.ContentItem, model.ScheduledArchiveUtc.HasValue ? model.ScheduledArchiveUtc.Value : DateTime.MaxValue);
//Services.Notifier.Information(T("{0} has been scheduled for publishing!", model.ContentItem.TypeDefinition.DisplayName));
}
else {
//_archiveLaterService.RemoveArchiveLaterTasks(model.ContentItem);
_archiveLaterService.RemoveArchiveLaterTasks(model.ContentItem);
}
}
return ContentPartTemplate(model, "Parts/ArchiveLater", TemplatePrefix).Location(part.GetLocation("Editor"));
return ContentShape("Parts_ArchiveLater_Edit",
() => shapeHelper.EditorTemplate(TemplateName: "Parts/ArchiveLater", Model: model, Prefix: Prefix));
}
}
}
}

View File

@@ -1,25 +1,12 @@
using System.Collections.Generic;
using Orchard.ArchiveLater.Models;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;
namespace Orchard.ArchiveLater {
public class Migrations : DataMigrationImpl {
public int Create() {
ContentDefinitionManager.AlterPartDefinition(typeof(ArchiveLaterPart).Name, cfg => cfg
.WithLocation(new Dictionary<string, ContentLocation> {
{"Default", new ContentLocation { Zone = "metadata", Position = "2" }},
{"Editor", new ContentLocation { Zone = "secondary", Position = "2" }}
}));
ContentDefinitionManager.AlterPartDefinition("ArchiveLaterPart", builder => builder.Attachable());
return 1;
}
public int UpdateFrom1() {
ContentDefinitionManager.AlterPartDefinition("ArchiveLaterPart", builder => builder.Attachable());
return 2;
}
}
}
}

View File

@@ -98,10 +98,14 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Views\Parts\ArchiveLater.Metadata.cshtml" />
<Content Include="Views\Parts\ArchiveLater.Metadata.SummaryAdmin.cshtml" />
<Content Include="Views\EditorTemplates\Parts\ArchiveLater.cshtml" />
</ItemGroup>
<ItemGroup>
<None Include="Placement.info">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -0,0 +1,6 @@
<Placement>
<Match DisplayType="SummaryAdmin">
<Place Parts_ArchiveLater_Metadata_SummaryAdmin="Meta:2"/>
</Match>
<Place Parts_ArchiveLater_Edit="Secondary:2"/>
</Placement>

View File

@@ -1,14 +1,11 @@
@model Orchard.ArchiveLater.ViewModels.ArchiveLaterViewModel
@using Orchard.Mvc.Html;
@using Orchard.Mvc.Html;
@if ((Model.IsPublished && Model.ScheduledArchiveUtc.HasValue && Model.ScheduledArchiveUtc.Value > DateTime.UtcNow)) {
@if ((Model.IsPublished && Model.ScheduledArchiveUtc != null && Model.ScheduledArchiveUtc > DateTime.UtcNow)) {
<ul class="pageStatus">
<li>
<img class="icon" src="@ResolveUrl("~/Modules/ArchiveLater/Content/Admin/images/scheduled.gif")" alt="@T("Scheduled")" title="@T("The page is scheduled for archiving")" />@T("Unpublish on")
@Html.DateTime(Model.ScheduledArchiveUtc.Value.ToLocalTime(), T("M/d/yyyy h:mm tt"))
<img class="icon" src="@Href("~/Modules/Orchard.ArchiveLater/Content/Admin/images/scheduled.gif")" alt="@T("Scheduled")" title="@T("The page is scheduled for archiving")" />@T("Unpublish on")
@Html.DateTime((DateTime)Model.ScheduledArchiveUtc.ToLocalTime(), T("M/d/yyyy h:mm tt"))
&nbsp;&#124;&nbsp;
</li>
</ul>
}

View File

@@ -1 +0,0 @@
@model Orchard.ArchiveLater.ViewModels.ArchiveLaterViewModel