Localized -> LocalizationPart

- updating part names to conform to a <name>Part convention

--HG--
branch : dev
rename : src/Orchard.Web/Core/Localization/Drivers/LocalizationDriver.cs => src/Orchard.Web/Core/Localization/Drivers/LocalizationPartDriver.cs
rename : src/Orchard.Web/Core/Localization/Handlers/LocalizationHandler.cs => src/Orchard.Web/Core/Localization/Handlers/LocalizationPartHandler.cs
rename : src/Orchard.Web/Core/Localization/Models/Localized.cs => src/Orchard.Web/Core/Localization/Models/LocalizationPart.cs
rename : src/Orchard.Web/Core/Localization/Models/LocalizedRecord.cs => src/Orchard.Web/Core/Localization/Models/LocalizationPartRecord.cs
This commit is contained in:
Nathan Heskew
2010-07-23 00:22:13 -07:00
parent 221efe54ac
commit 5cf9e62f84
11 changed files with 47 additions and 47 deletions

View File

@@ -35,7 +35,7 @@ namespace Orchard.Core.Localization.Controllers {
if (contentItem == null)
return new NotFoundResult();
if (!contentItem.Is<Localized>() || contentItem.As<Localized>().MasterContentItem != null) {
if (!contentItem.Is<LocalizationPart>() || contentItem.As<LocalizationPart>().MasterContentItem != null) {
var metadata = _contentManager.GetItemMetadata(contentItem);
return RedirectToAction(Convert.ToString(metadata.EditorRouteValues["action"]), metadata.EditorRouteValues);
}
@@ -71,7 +71,7 @@ namespace Orchard.Core.Localization.Controllers {
}
else { // create
contentItemTranslation = _contentManager.New(contentItem.ContentType);
var localized = contentItemTranslation.As<Localized>();
var localized = contentItemTranslation.As<LocalizationPart>();
localized.MasterContentItem = contentItem;
localized.Culture = _cultureManager.GetCultureByName(viewModel.SelectedCulture);
_contentManager.Create(contentItemTranslation, VersionOptions.Draft);

View File

@@ -10,7 +10,7 @@ namespace Orchard.Core.Localization.DataMigrations {
public int Create() {
//CREATE TABLE Localization_LocalizedRecord (Id INTEGER not null, CultureId INTEGER, MasterContentItemId INTEGER, primary key (Id));
SchemaBuilder.CreateTable("LocalizedRecord", table => table
SchemaBuilder.CreateTable("LocalizationPartRecord", table => table
.ContentPartRecord()
.Column<int>("CultureId")
.Column<int>("MasterContentItemId")
@@ -19,7 +19,7 @@ namespace Orchard.Core.Localization.DataMigrations {
return 1;
}
public int UpdateFrom1() {
ContentDefinitionManager.AlterPartDefinition(typeof(Localized).Name, cfg => cfg
ContentDefinitionManager.AlterPartDefinition(typeof(LocalizationPart).Name, cfg => cfg
.WithLocation(new Dictionary<string, ContentLocation> {
{"Default", new ContentLocation { Zone = "primary", Position = "5" }},
{"Editor", new ContentLocation { Zone = "primary", Position = "1" }},

View File

@@ -12,17 +12,17 @@ using Orchard.Localization.Services;
namespace Orchard.Core.Localization.Drivers {
[UsedImplicitly]
public class LocalizationDriver : ContentPartDriver<Localized> {
public class LocalizationPartDriver : ContentPartDriver<LocalizationPart> {
private const string TemplatePrefix = "Localization";
private readonly ICultureManager _cultureManager;
private readonly ILocalizationService _localizationService;
public LocalizationDriver(ICultureManager cultureManager, ILocalizationService localizationService) {
public LocalizationPartDriver(ICultureManager cultureManager, ILocalizationService localizationService) {
_cultureManager = cultureManager;
_localizationService = localizationService;
}
protected override DriverResult Display(Localized part, string displayType) {
protected override DriverResult Display(LocalizationPart part, string displayType) {
var model = new ContentLocalizationsViewModel(part) {
Localizations = GetDisplayLocalizations(part)
};
@@ -30,7 +30,7 @@ namespace Orchard.Core.Localization.Drivers {
return ContentPartTemplate(model, "Parts/Localization.ContentTranslations", TemplatePrefix).LongestMatch(displayType, "Summary", "SummaryAdmin").Location(part.GetLocation(displayType));
}
protected override DriverResult Editor(Localized part) {
protected override DriverResult Editor(LocalizationPart part) {
var localizations = GetEditorLocalizations(part).ToList();
var model = new EditLocalizationViewModel {
SelectedCulture = part.Culture != null ? part.Culture.Culture : null,
@@ -42,7 +42,7 @@ namespace Orchard.Core.Localization.Drivers {
return ContentPartTemplate(model, "Parts/Localization.Translation", TemplatePrefix).Location(part.GetLocation("Editor"));
}
protected override DriverResult Editor(Localized part, IUpdateModel updater) {
protected override DriverResult Editor(LocalizationPart part, IUpdateModel updater) {
var model = new EditLocalizationViewModel();
if (updater != null && updater.TryUpdateModel(model, TemplatePrefix, null, null)) {
_localizationService.SetContentCulture(part, model.SelectedCulture);
@@ -51,10 +51,10 @@ namespace Orchard.Core.Localization.Drivers {
return Editor(part);
}
private IEnumerable<Localized> GetDisplayLocalizations(Localized part) {
private IEnumerable<LocalizationPart> GetDisplayLocalizations(LocalizationPart part) {
return _localizationService.GetLocalizations(part.ContentItem)
.Select(c => {
var localized = c.ContentItem.As<Localized>();
var localized = c.ContentItem.As<LocalizationPart>();
if (localized.Culture == null) {
localized.Culture = _cultureManager.GetCultureByName(_cultureManager.GetCurrentCulture(new HttpContextWrapper(HttpContext.Current)));
}
@@ -62,9 +62,9 @@ namespace Orchard.Core.Localization.Drivers {
}).ToList();
}
private IEnumerable<Localized> GetEditorLocalizations(Localized part) {
private IEnumerable<LocalizationPart> GetEditorLocalizations(LocalizationPart part) {
return _localizationService.GetLocalizations(part.ContentItem)
.Select(c => c.ContentItem.As<Localized>())
.Select(c => c.ContentItem.As<LocalizationPart>())
.Where(l => l.MasterContentItem != null).ToList();
}
}

View File

@@ -9,20 +9,20 @@ using Orchard.Localization.Services;
namespace Orchard.Core.Localization.Handlers {
[UsedImplicitly]
public class LocalizationHandler : ContentHandler {
public class LocalizationPartHandler : ContentHandler {
private readonly ICultureManager _cultureManager;
private readonly IContentManager _contentManager;
public LocalizationHandler(IRepository<LocalizedRecord> localizedRepository, ICultureManager cultureManager, IContentManager contentManager) {
public LocalizationPartHandler(IRepository<LocalizationPartRecord> localizedRepository, ICultureManager cultureManager, IContentManager contentManager) {
_cultureManager = cultureManager;
_contentManager = contentManager;
T = NullLocalizer.Instance;
Filters.Add(StorageFilter.For(localizedRepository));
OnInitializing<Localized>(InitializePart);
OnInitializing<LocalizationPart>(InitializePart);
OnIndexed<Localized>((context, localized) => context.DocumentIndex
OnIndexed<LocalizationPart>((context, localized) => context.DocumentIndex
.Add("culture", CultureInfo.GetCultureInfo(localized.Culture != null ? localized.Culture.Culture : _cultureManager.GetSiteCulture()).LCID)
.Store()
);
@@ -30,17 +30,17 @@ namespace Orchard.Core.Localization.Handlers {
public Localizer T { get; set; }
void InitializePart(InitializingContentContext context, Localized localized) {
localized.CultureField.Setter(cultureRecord => {
localized.Record.CultureId = cultureRecord.Id;
void InitializePart(InitializingContentContext context, LocalizationPart localizationPart) {
localizationPart.CultureField.Setter(cultureRecord => {
localizationPart.Record.CultureId = cultureRecord.Id;
return cultureRecord;
});
localized.MasterContentItemField.Setter(masterContentItem => {
localized.Record.MasterContentItemId = masterContentItem.ContentItem.Id;
localizationPart.MasterContentItemField.Setter(masterContentItem => {
localizationPart.Record.MasterContentItemId = masterContentItem.ContentItem.Id;
return masterContentItem;
});
localized.CultureField.Loader(ctx => _cultureManager.GetCultureById(localized.Record.CultureId));
localized.MasterContentItemField.Loader(ctx => _contentManager.Get(localized.Record.MasterContentItemId));
localizationPart.CultureField.Loader(ctx => _cultureManager.GetCultureById(localizationPart.Record.CultureId));
localizationPart.MasterContentItemField.Loader(ctx => _contentManager.Get(localizationPart.Record.MasterContentItemId));
}
}
}

View File

@@ -4,7 +4,7 @@ using Orchard.ContentManagement.Utilities;
using Orchard.Localization.Records;
namespace Orchard.Core.Localization.Models {
public sealed class Localized : ContentPart<LocalizedRecord> {
public sealed class LocalizationPart : ContentPart<LocalizationPartRecord> {
private readonly LazyField<CultureRecord> _culture = new LazyField<CultureRecord>();
private readonly LazyField<IContent> _masterContentItem = new LazyField<IContent>();

View File

@@ -1,7 +1,7 @@
using Orchard.ContentManagement.Records;
namespace Orchard.Core.Localization.Models {
public class LocalizedRecord : ContentPartRecord {
public class LocalizationPartRecord : ContentPartRecord {
public virtual int CultureId { get; set; }
public virtual int MasterContentItemId { get; set; }
}

View File

@@ -4,9 +4,9 @@ using Orchard.Core.Localization.Models;
namespace Orchard.Core.Localization.Services {
public interface ILocalizationService : IDependency {
Localized GetLocalizedContentItem(IContent masterContentItem, string culture);
LocalizationPart GetLocalizedContentItem(IContent masterContentItem, string culture);
string GetContentCulture(IContent contentItem);
void SetContentCulture(IContent contentItem, string culture);
IEnumerable<Localized> GetLocalizations(IContent contentItem);
IEnumerable<LocalizationPart> GetLocalizations(IContent contentItem);
}
}

View File

@@ -15,45 +15,45 @@ namespace Orchard.Core.Localization.Services {
_cultureManager = cultureManager;
}
Localized ILocalizationService.GetLocalizedContentItem(IContent content, string culture) {
return _contentManager.Query(content.ContentItem.ContentType).Join<LocalizedRecord>()
LocalizationPart ILocalizationService.GetLocalizedContentItem(IContent content, string culture) {
return _contentManager.Query(content.ContentItem.ContentType).Join<LocalizationPartRecord>()
.List()
.Select(i => i.As<Localized>())
.Select(i => i.As<LocalizationPart>())
.Where(l => l.MasterContentItem != null && l.MasterContentItem.ContentItem.Id == content.ContentItem.Id && string.Equals(l.Culture.Culture, culture, StringComparison.OrdinalIgnoreCase))
.SingleOrDefault();
}
string ILocalizationService.GetContentCulture(IContent content) {
var localized = content.As<Localized>();
var localized = content.As<LocalizationPart>();
return localized != null && localized.Culture != null
? localized.Culture.Culture
: _cultureManager.GetSiteCulture();
}
void ILocalizationService.SetContentCulture(IContent content, string culture) {
var localized = content.As<Localized>();
var localized = content.As<LocalizationPart>();
if (localized == null || localized.MasterContentItem == null)
return;
localized.Culture = _cultureManager.GetCultureByName(culture);
}
IEnumerable<Localized> ILocalizationService.GetLocalizations(IContent content) {
var localized = content.As<Localized>();
IEnumerable<LocalizationPart> ILocalizationService.GetLocalizations(IContent content) {
var localized = content.As<LocalizationPart>();
//todo: (heskew) get scheduled content as well
if (localized.MasterContentItem != null)
return _contentManager.Query(VersionOptions.Latest, localized.ContentItem.ContentType).Join<LocalizedRecord>()
return _contentManager.Query(VersionOptions.Latest, localized.ContentItem.ContentType).Join<LocalizationPartRecord>()
.List()
.Select(i => i.As<Localized>())
.Select(i => i.As<LocalizationPart>())
.Where(l => l.Id != localized.ContentItem.Id
&& (l.Id == localized.MasterContentItem.ContentItem.Id
|| l.MasterContentItem != null && l.MasterContentItem.ContentItem.Id == localized.MasterContentItem.ContentItem.Id));
return _contentManager.Query(VersionOptions.Latest, localized.ContentItem.ContentType).Join<LocalizedRecord>()
return _contentManager.Query(VersionOptions.Latest, localized.ContentItem.ContentType).Join<LocalizationPartRecord>()
.List()
.Select(i => i.As<Localized>())
.Select(i => i.As<LocalizationPart>())
.Where(l => l.MasterContentItem != null && l.MasterContentItem.ContentItem.Id == localized.ContentItem.Id);
}
}

View File

@@ -3,13 +3,13 @@ using Orchard.Core.Localization.Models;
namespace Orchard.Core.Localization.ViewModels {
public class ContentLocalizationsViewModel {
public ContentLocalizationsViewModel(Localized part) {
public ContentLocalizationsViewModel(LocalizationPart part) {
MasterId = part.MasterContentItem != null
? part.MasterContentItem.ContentItem.Id
: part.Id;
}
public int? MasterId { get; private set; }
public IEnumerable<Localized> Localizations { get; set; }
public IEnumerable<LocalizationPart> Localizations { get; set; }
}
}

View File

@@ -108,7 +108,7 @@
<Compile Include="Localization\Controllers\AdminController.cs" />
<Compile Include="Localization\DataMigrations\LocalizationDataMigration.cs" />
<Compile Include="Localization\ViewModels\AddLocalizationViewModel.cs" />
<Compile Include="Localization\Drivers\LocalizationDriver.cs" />
<Compile Include="Localization\Drivers\LocalizationPartDriver.cs" />
<Compile Include="Navigation\DataMigrations\NavigationDataMigration.cs" />
<Compile Include="Reports\ViewModels\DisplayReportViewModel.cs" />
<Compile Include="Reports\ViewModels\ReportsAdminIndexViewModel.cs" />
@@ -156,9 +156,9 @@
<Compile Include="Feeds\Rss\RssResult.cs" />
<Compile Include="HomePage\Controllers\HomeController.cs" />
<Compile Include="HomePage\Routes.cs" />
<Compile Include="Localization\Handlers\LocalizationHandler.cs" />
<Compile Include="Localization\Models\Localized.cs" />
<Compile Include="Localization\Models\LocalizedRecord.cs" />
<Compile Include="Localization\Handlers\LocalizationPartHandler.cs" />
<Compile Include="Localization\Models\LocalizationPart.cs" />
<Compile Include="Localization\Models\LocalizationPartRecord.cs" />
<Compile Include="Navigation\AdminMenu.cs" />
<Compile Include="Navigation\Controllers\AdminController.cs" />
<Compile Include="Navigation\Models\MenuItem.cs" />

View File

@@ -195,7 +195,7 @@ namespace Orchard.Setup.Services {
.DisplayedAs("Blog Post")
.WithPart("CommentsPart")
.WithPart("TagsPart")
.WithPart("Localized")
.WithPart("LocalizationPart")
.Creatable()
.Indexed());
contentDefinitionManager.AlterTypeDefinition("Page", cfg => cfg
@@ -206,7 +206,7 @@ namespace Orchard.Setup.Services {
.WithPart("BodyPart")
.WithPart("CommentsPart")
.WithPart("TagsPart")
.WithPart("Localized")
.WithPart("LocalizationPart")
.Creatable()
.Indexed());
contentDefinitionManager.AlterPartDefinition("BodyPart", cfg => cfg