Problem:
I have situation where I have to tag the media items with geoIDs. I have been trying to replicate the functionalists of Tags Module and have created the models, Views, Drives and Handler for GeoObject. My problem is that when I load the edit view of an Image, I don't get my GeoObject edit view.
Here's my Handler:
class GeoObjectsPartHandler:ContentHandler {
public GeoObjectsPartHandler(IRepository<GeoObjectsPartRecord> repository, IGeoObjectService geoObjectService)
{
Filters.Add(StorageFilter.For(repository));
OnIndexing<GeoObjectsPart>(
(context, geoObjectsPart) =>
{
foreach (var geoObject in geoObjectsPart.CurrentGeoObjects)
{
context.DocumentIndex.Add("geoObjects", geoObject.GeoObjectName).Analyze();
}
});
}
}
Driver:
[UsedImplicitly]
class GeoObjectsPartDriver: ContentPartDriver<GeoObjectsPart>
{
private static readonly char[] _disalowedChars = new[] { '<', '>', '*', '%', ':', '&', '\\', '"', '|' };
private const string TemplateName = "Parts/GeoObjects";
private readonly INotifier _notifier;
private readonly IGeoObjectService _geoObjectService;
public GeoObjectsPartDriver(IGeoObjectService geoObjectService, INotifier notifier)
{
_geoObjectService = geoObjectService;
_notifier = notifier;
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
protected override string Prefix
{
get { return "GeoObjects"; }
}
protected override DriverResult Editor(GeoObjectsPart part, dynamic shapeHelper)
{
return ContentShape("Parts_GeoObjects_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: BuildEditorViewModel(part), Prefix: Prefix));
}
protected override DriverResult Editor(GeoObjectsPart part, IUpdateModel updater, dynamic shapeHelper)
{
var model = new EditGeoObjectsViewModel();
return ContentShape("Parts_GeoObjects_Edit",
() => shapeHelper.EditorTemplate(TemplateName: TemplateName, Model: model, Prefix: Prefix));
}
private static EditGeoObjectsViewModel BuildEditorViewModel(GeoObjectsPart part)
{
return new EditGeoObjectsViewModel
{
GeoObjects = string.Join(", ", part.CurrentGeoObjects.Select((t, i) => t.GeoObjectName).ToArray())
};
}
protected override void Importing(GeoObjectsPart part, ImportContentContext context)
{
var geoObjectString = context.Attribute(part.PartDefinition.Name, "GeoObjects");
}
protected override void Exporting(GeoObjectsPart part, ExportContentContext context)
{
context.Element(part.PartDefinition.Name).SetAttributeValue("GeoObjects", String.Join(",", part.CurrentGeoObjects.Select(t => t.GeoObjectName)));
}
}
Migration:
using Orchard.Data.Migration;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
namespace ePageo.TUI.MediaManager
{
public class MediaManagerDataMigration : DataMigrationImpl
{
public int Create()
{
SchemaBuilder.CreateTable("GeoObjectsPartRecord",
table => table
.ContentPartRecord()
);
SchemaBuilder.CreateTable("GeoObjectRecord",
table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<string>("GeoObjectName")
);
SchemaBuilder.CreateTable("ContentGeoObjectRecord",
table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<int>("GeoObjectRecord_Id")
.Column<int>("GeoObjectsPartRecord_Id")
);
ContentDefinitionManager.AlterPartDefinition("GeoObjectsPart", builder => builder.Attachable());
return 1;
}
public int UpdateFrom1()
{
ContentDefinitionManager.AlterPartDefinition("GeoObjectsPart", builder => builder
.WithDescription("Allows to add Geo-object ids to the particular media Item."));
return 2;
}
public int UpdateFrom2()
{
ContentDefinitionManager.AlterTypeDefinition("Image", td => td
.WithPart("GeoObjectsPart")
);
ContentDefinitionManager.AlterTypeDefinition("Video", td => td
.WithPart("GeoObjectsPart")
);
ContentDefinitionManager.AlterTypeDefinition("Audio", td => td
.WithPart("GeoObjectsPart")
);
ContentDefinitionManager.AlterTypeDefinition("Document", td => td
.WithPart("GeoObjectsPart")
);
ContentDefinitionManager.AlterTypeDefinition("OEmbed", td => td
.WithPart("GeoObjectsPart")
);
return 3;
}
}
}
Placement.info:
<Placement>
<Place Parts_GeoObjects_Edit="Content:12"/>
</Placement>
I don't think I have problem in my model since its the exact replication of Orchard Tags Models. In fact all of the above files are just that.
I just cannot get the Geo Object edit view to show up in Image (Media) edit view.
I need help!
I got the code to work.
Turns out I had to declare the Driver and Handler classes to public
.
I just switched from PHP to ASP.NET few months ago so since if we did not declare any scope PHP would take it as public, I thought it'd be the same with ASP.NET.
The code itself had no other problem except for that.