1

问题:

我有一种情况,我必须用 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 模型。事实上,以上所有文件都只是这样。

我只是无法让地理对象编辑视图显示在图像(媒体)编辑视图中。

我需要帮助!

4

1 回答 1

1

我得到了工作的代码。

原来我必须将 Driver 和 Handler 类声明为public.

几个月前我刚从 PHP 切换到 ASP.NET,所以如果我们没有声明任何范围 PHP 会将其视为公共的,我认为它与 ASP.NET 相同。

除此之外,代码本身没有其他问题。

于 2014-03-27T10:08:53.583 回答