问题:
我有一种情况,我必须用 geoID 标记媒体项目。我一直在尝试复制标签模块的功能,并为 GeoObject 创建了模型、视图、驱动器和处理程序。我的问题是,当我加载图像的编辑视图时,我没有得到我的 GeoObject 编辑视图。
这是我的处理程序:
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();
}
});
}
}
司机:
[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)));
}
}
移民:
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>
<Place Parts_GeoObjects_Edit="Content:12"/>
</Placement>
我认为我的模型没有问题,因为它完全复制了 Orchard Tags 模型。事实上,以上所有文件都只是这样。
我只是无法让地理对象编辑视图显示在图像(媒体)编辑视图中。
我需要帮助!