Adding VectorGraphic media type.

This commit is contained in:
Sipke Schoorstra 2014-11-07 16:34:09 -08:00
parent 7c6acd59c5
commit 41bb95cfd3
10 changed files with 189 additions and 2 deletions

View File

@ -0,0 +1,16 @@
using Orchard.ContentManagement.Drivers;
using Orchard.MediaLibrary.Models;
namespace Orchard.MediaLibrary.Drivers {
public class VectorGraphicPartDriver : ContentPartDriver<VectorGraphicPart> {
protected override DriverResult Display(VectorGraphicPart part, string displayType, dynamic shapeHelper) {
return Combined(
ContentShape("Parts_VectorGraphic_Metadata", () => shapeHelper.Parts_VectorGraphic_Metadata()),
ContentShape("Parts_VectorGraphic_Summary", () => shapeHelper.Parts_VectorGraphic_Summary()),
ContentShape("Parts_VectorGraphic", () => shapeHelper.Parts_VectorGraphic()),
ContentShape("Parts_VectorGraphic_SummaryAdmin", () => shapeHelper.Parts_VectorGraphic_SummaryAdmin())
);
}
}
}

View File

@ -0,0 +1,66 @@
using System;
using System.IO;
using System.Linq;
using Orchard.ContentManagement;
using Orchard.ContentManagement.MetaData;
using Orchard.MediaLibrary.Models;
namespace Orchard.MediaLibrary.Factories {
public class VectorGraphicFactorySelector : IMediaFactorySelector {
private readonly IContentManager _contentManager;
private readonly IContentDefinitionManager _contentDefinitionManager;
public VectorGraphicFactorySelector(IContentManager contentManager, IContentDefinitionManager contentDefinitionManager) {
_contentManager = contentManager;
_contentDefinitionManager = contentDefinitionManager;
}
public MediaFactorySelectorResult GetMediaFactory(Stream stream, string mimeType, string contentType) {
if (!mimeType.StartsWith("image/svg")) {
return null;
}
if (!String.IsNullOrEmpty(contentType)) {
var contentDefinition = _contentDefinitionManager.GetTypeDefinition(contentType);
if (contentDefinition == null || contentDefinition.Parts.All(x => x.PartDefinition.Name != typeof(VectorGraphicPart).Name)) {
return null;
}
}
return new MediaFactorySelectorResult {
Priority = -5,
MediaFactory = new VectorGraphicFactory(_contentManager)
};
}
}
public class VectorGraphicFactory : IMediaFactory {
private readonly IContentManager _contentManager;
public VectorGraphicFactory(IContentManager contentManager) {
_contentManager = contentManager;
}
public MediaPart CreateMedia(Stream stream, string path, string mimeType, string contentType) {
if (String.IsNullOrEmpty(contentType)) {
contentType = "VectorGraphic";
}
var part = _contentManager.New<MediaPart>(contentType);
part.LogicalType = "VectorGraphic";
part.MimeType = mimeType;
part.Title = Path.GetFileNameWithoutExtension(path);
var imagePart = part.As<VectorGraphicPart>();
if (imagePart == null) {
return null;
}
return part;
}
}
}

View File

@ -30,6 +30,11 @@ namespace Orchard.MediaLibrary {
.WithDescription("Provides common metadata for an Image Media.")
);
ContentDefinitionManager.AlterPartDefinition("VectorGraphicPart", part => part
.Attachable()
.WithDescription("Provides common metadata for a Vector Graphic Media.")
);
ContentDefinitionManager.AlterPartDefinition("VideoPart", part => part
.Attachable()
.WithDescription("Provides common metadata for a Video Media.")
@ -61,6 +66,17 @@ namespace Orchard.MediaLibrary {
.WithPart("TitlePart")
);
ContentDefinitionManager.AlterTypeDefinition("VectorGraphic", td => td
.DisplayedAs("Vector Graphic")
.WithSetting("Stereotype", "Media")
.WithSetting("MediaFileNameEditorSettings.ShowFileNameEditor", "True")
.WithPart("IdentityPart")
.WithPart("CommonPart")
.WithPart("MediaPart")
.WithPart("VectorGraphicPart")
.WithPart("TitlePart")
);
ContentDefinitionManager.AlterTypeDefinition("Video", td => td
.DisplayedAs("Video")
.WithSetting("Stereotype", "Media")
@ -104,7 +120,7 @@ namespace Orchard.MediaLibrary {
.WithPart("TitlePart")
);
return 6;
return 7;
}
public int UpdateFrom2() {
@ -164,7 +180,7 @@ namespace Orchard.MediaLibrary {
return 4;
}
public int UpdateFrom4() {
SchemaBuilder.AlterTable("MediaPartRecord", t => t
@ -193,5 +209,25 @@ namespace Orchard.MediaLibrary {
return 6;
}
public int UpdateFrom6() {
ContentDefinitionManager.AlterPartDefinition("VectorGraphicPart", part => part
.Attachable()
.WithDescription("Provides common metadata for a Vector Graphic Media.")
);
ContentDefinitionManager.AlterTypeDefinition("VectorGraphic", td => td
.DisplayedAs("Vector Graphic")
.WithSetting("Stereotype", "Media")
.WithSetting("MediaFileNameEditorSettings.ShowFileNameEditor", "True")
.WithPart("IdentityPart")
.WithPart("CommonPart")
.WithPart("MediaPart")
.WithPart("VectorGraphicPart")
.WithPart("TitlePart")
);
return 7;
}
}
}

View File

@ -0,0 +1,6 @@
using Orchard.ContentManagement;
namespace Orchard.MediaLibrary.Models {
public class VectorGraphicPart : ContentPart {
}
}

View File

@ -104,6 +104,9 @@
</Content>
<Content Include="Scripts\Web.config" />
<Content Include="Styles\Web.config" />
<Compile Include="Drivers\VectorGraphicPartDriver.cs" />
<Compile Include="Factories\VectorGraphicFactory.cs" />
<Compile Include="Models\VectorGraphicPart.cs" />
<Compile Include="Models\IMediaFolder.cs" />
<Compile Include="MediaFileName\MediaFileNameDriver.cs" />
<Compile Include="MediaFileName\MediaFileNameEditorSettings.cs" />
@ -360,6 +363,21 @@
<ItemGroup>
<Content Include="Views\Parts\Media.Edit.FileName.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Parts\VectorGraphic.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Parts\VectorGraphic.Metadata.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Parts\VectorGraphic.Summary.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Parts\VectorGraphic.SummaryAdmin.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Views\Media-VectorGraphic.Thumbnail.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>

View File

@ -0,0 +1,14 @@
@using Orchard.ContentManagement
@using Orchard.MediaLibrary.Models
@using Orchard.Utility.Extensions
@model dynamic
@{
ContentItem contentItem = Model.ContentItem;
var media = contentItem.As<MediaPart>();
var vectorGraphic = contentItem.As<VectorGraphicPart>();
}
<div class="media-thumbnail media-thumbnail-@contentItem.ContentType.HtmlClassify() mime-type-@media.MimeType.HtmlClassify()">
<img width="200" height="200" src="@Url.Content(media.MediaUrl)" alt="@media.AlternateText" />
</div>

View File

@ -0,0 +1,4 @@
@using Orchard.MediaLibrary.Models
@{
VectorGraphicPart vectorGraphicPart = Model.ContentPart;
}

View File

@ -0,0 +1,11 @@
@using Orchard.ContentManagement
@using Orchard.MediaLibrary.Models
@{
VectorGraphicPart vectorGraphicPart = Model.ContentPart;
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
}
@* Use a 200x200 profile in order to reuse the general thumbnail *@
<a href="@Url.Content(mediaPart.MediaUrl)">
<img width="200" height="200" alt="@mediaPart.AlternateText" src="@mediaPart.MediaUrl" />
</a>

View File

@ -0,0 +1,9 @@
@using Orchard.ContentManagement
@using Orchard.MediaLibrary.Models
@{
VectorGraphicPart vectorGraphicPart = Model.ContentPart;
var mediaPart = ((ContentItem) Model.ContentItem).As<MediaPart>();
}
@* Use a 200x200 profile in order to reuse the general thumbnail *@
<img width="120" height="120" alt="@mediaPart.AlternateText" src="@mediaPart.MediaUrl" />

View File

@ -0,0 +1,7 @@
@using Orchard.ContentManagement
@using Orchard.MediaLibrary.Models
@{
VectorGraphicPart vectorGraphicPart = Model.ContentPart;
var mediaPart = ((ContentItem)Model.ContentItem).As<MediaPart>();
}
<img alt="@mediaPart.AlternateText" src="@Url.Content(mediaPart.MediaUrl)" />