--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-07-14 14:43:20 -07:00
15 changed files with 1397 additions and 1753 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -6,9 +6,9 @@ html.dyn input.hinted {
color:#ccc; color:#ccc;
font-style:italic; font-style:italic;
} }
input#ScheduledPublishUtcDate { input#CommonAspect_ScheduledPublishUtcDate {
width:56%; width:56%;
} }
input#ScheduledPublishUtcTime { input#CommonAspect_ScheduledPublishUtcTime {
width:36%; width:36%;
} }

View File

@@ -1,12 +1,15 @@
using System.Linq; using System.Collections.Generic;
using System.Linq;
using System.Web; using System.Web;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common; using Orchard.Core.Common;
using Orchard.Core.Localization.Models; using Orchard.Core.Localization.Models;
using Orchard.Core.Localization.Services; using Orchard.Core.Localization.Services;
using Orchard.Core.Localization.ViewModels; using Orchard.Core.Localization.ViewModels;
using Orchard.Localization.Services; using Orchard.Localization.Services;
using Orchard.Settings;
namespace Orchard.Core.Localization.Drivers { namespace Orchard.Core.Localization.Drivers {
[UsedImplicitly] [UsedImplicitly]
@@ -20,20 +23,21 @@ namespace Orchard.Core.Localization.Drivers {
Services = services; Services = services;
} }
protected virtual ISite CurrentSite { get; private set; }
public IOrchardServices Services { get; set; } public IOrchardServices Services { get; set; }
protected override DriverResult Display(Localized part, string displayType) { protected override DriverResult Display(Localized part, string displayType) {
var model = new ContentLocalizationsViewModel(part) { var model = new ContentLocalizationsViewModel(part) {
CanLocalize = Services.Authorizer.Authorize(Permissions.ChangeOwner) && _cultureManager.ListCultures()
.Where(s => s != _cultureManager.GetCurrentCulture(new HttpContextWrapper(HttpContext.Current)) && s != _localizationService.GetContentCulture(part.ContentItem))
.Count() > 0,
Localizations = _localizationService.GetLocalizations(part.ContentItem) Localizations = _localizationService.GetLocalizations(part.ContentItem)
.Select(c => {
var localized = c.ContentItem.As<Localized>();
if (localized.Culture == null)
localized.Culture = _cultureManager.GetCultureByName(_cultureManager.GetCurrentCulture(new HttpContextWrapper(HttpContext.Current)));
return c;
}).ToList()
}; };
return ContentPartTemplate(model, "Parts/Localization.ContentTranslations").LongestMatch(displayType, "Summary", "SummaryAdmin").Location("primary", "5"); return ContentPartTemplate(model, "Parts/Localization.ContentTranslations").LongestMatch(displayType, "Summary", "SummaryAdmin").Location("primary", "5");
} }
protected override DriverResult Editor(Localized part) {
return ContentPartTemplate(new SelectLocalizationsViewModel(part), "Parts/Localization.ContentTranslations").Location("secondary", "5");
}
} }
} }

View File

@@ -8,4 +8,4 @@ description: The localization module enables the localization of content items.
features: features:
Localization: Localization:
Description: Localize content items. Description: Localize content items.
Category: Core Category: Content

View File

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

View File

@@ -30,21 +30,23 @@ namespace Orchard.Core.Localization.Services {
: _cultureManager.GetSiteCulture(); : _cultureManager.GetSiteCulture();
} }
IEnumerable<IContent> ILocalizationService.GetLocalizations(IContent content) { IEnumerable<Localized> ILocalizationService.GetLocalizations(IContent content) {
var localized = content.As<Localized>(); var localized = content.As<Localized>();
//todo: (heskew) get scheduled content as well //todo: (heskew) get scheduled content as well
if (localized.MasterContentItem != null) if (localized.MasterContentItem != null)
return _contentManager.Query(VersionOptions.Latest, content.ContentItem.ContentType).Join<LocalizedRecord>() return _contentManager.Query(VersionOptions.Latest, localized.ContentItem.ContentType).Join<LocalizedRecord>()
.List() .List()
.Select(i => i.As<Localized>()) .Select(i => i.As<Localized>())
.Where(l => l.Id != content.ContentItem.Id && (l.Id == localized.MasterContentItem.ContentItem.Id || l.MasterContentItem != null && l.MasterContentItem.ContentItem.Id == localized.MasterContentItem.ContentItem.Id)); .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, content.ContentItem.ContentType).Join<LocalizedRecord>() return _contentManager.Query(VersionOptions.Latest, localized.ContentItem.ContentType).Join<LocalizedRecord>()
.List() .List()
.Select(i => i.As<Localized>()) .Select(i => i.As<Localized>())
.Where(l => l.MasterContentItem != null && l.MasterContentItem.ContentItem.Id == content.ContentItem.Id); .Where(l => l.MasterContentItem != null && l.MasterContentItem.ContentItem.Id == localized.ContentItem.Id);
} }
} }
} }

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Core.Localization.Models;
namespace Orchard.Core.Localization.ViewModels { namespace Orchard.Core.Localization.ViewModels {
public class ContentLocalizationsViewModel { public class ContentLocalizationsViewModel {
@@ -8,7 +9,6 @@ namespace Orchard.Core.Localization.ViewModels {
} }
public int Id { get; private set; } public int Id { get; private set; }
public bool CanLocalize { get; set; } public IEnumerable<Localized> Localizations { get; set; }
public IEnumerable<IContent> Localizations { get; set; }
} }
} }

View File

@@ -1,16 +1,10 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.ContentLocalizationsViewModel>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.ContentLocalizationsViewModel>" %>
<%@ Import Namespace="Orchard.Core.Localization.Models" %>
<%@ Import Namespace="Orchard.ContentManagement" %>
<% <%
Html.RegisterStyle("admin.css"); %> Html.RegisterStyle("admin.css"); %>
<% if (Model.Localizations.Count() > 0 || Model.CanLocalize) { %>
<div class="content-localization"><% <div class="content-localization"><%
if (Model.Localizations.Count() > 0) { %> if (Model.Localizations.Count() > 0) { %>
<%--//todo: need this info in the view model--%> <%--//todo: need this info in the view model--%>
<div class="content-localizations"><h4><%:T("Other localizations:") %></h4><%:Html.UnorderedList(Model.Localizations, (c, i) => Html.ItemDisplayLink(c.ContentItem.As<Localized>().Culture != null ? c.ContentItem.As<Localized>().Culture.Culture : "[site's default culture]", c), "localizations") %></div><% <div class="content-localizations"><h4><%:T("Translations:") %></h4><%:Html.UnorderedList(Model.Localizations, (c, i) => Html.ItemDisplayLink(c.Culture.Culture, c), "localizations") %></div><%
}
if (Model.CanLocalize) { %>
<div class="add-localization"><%:Html.ActionLink(T("+ New translation").Text, "translate", "admin", new { area = "Localization", id = Model.Id }, null)%></div><%
} %> } %>
</div><% <div class="add-localization"><%:Html.ActionLink(T("+ New translation").Text, "translate", "admin", new { area = "Localization", id = Model.Id }, null)%></div>
} %> </div>

View File

@@ -1,16 +1,10 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.ContentLocalizationsViewModel>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.ContentLocalizationsViewModel>" %>
<%@ Import Namespace="Orchard.Core.Localization.Models" %>
<%@ Import Namespace="Orchard.ContentManagement" %>
<% <%
Html.RegisterStyle("base.css"); %> Html.RegisterStyle("base.css"); %>
<% if (Model.Localizations.Count() > 0 || Model.CanLocalize) { %>
<div class="content-localization"><% <div class="content-localization"><%
if (Model.Localizations.Count() > 0) { %> if (Model.Localizations.Count() > 0) { %>
<%--//todo: need this info in the view model--%> <%--//todo: need this info in the view model--%>
<div class="content-localizations"><%:Html.UnorderedList(Model.Localizations, (c, i) => Html.ItemDisplayLink(c.ContentItem.As<Localized>().Culture != null ? c.ContentItem.As<Localized>().Culture.Culture : "[site's default culture]", c), "localizations") %></div><% <div class="content-localizations"><%:Html.UnorderedList(Model.Localizations, (c, i) => Html.ItemDisplayLink(c.Culture.Culture, c), "localizations") %></div><%
}
if (Model.CanLocalize) { %>
<div class="add-localization"><%:Html.ActionLink(T("+ New translation").Text, "translate", "admin", new { area = "Localization", id = Model.Id }, null)%></div><%
} %> } %>
</div><% <div class="add-localization"><%:Html.ActionLink(T("+ New translation").Text, "translate", "admin", new { area = "Localization", id = Model.Id }, null)%></div>
} %> </div>

View File

@@ -1,5 +0,0 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<Orchard.Core.Localization.ViewModels.SelectLocalizationsViewModel>" %>
<fieldset class="localization translations">
<legend>Publish also in</legend>
[translations to publish]
</fieldset>

View File

@@ -266,7 +266,6 @@
<Content Include="Localization\Styles\base.css" /> <Content Include="Localization\Styles\base.css" />
<Content Include="Localization\Views\DisplayTemplates\Parts\Localization.ContentTranslations.Summary.ascx" /> <Content Include="Localization\Views\DisplayTemplates\Parts\Localization.ContentTranslations.Summary.ascx" />
<Content Include="Localization\Views\DisplayTemplates\Parts\Localization.ContentTranslations.ascx" /> <Content Include="Localization\Views\DisplayTemplates\Parts\Localization.ContentTranslations.ascx" />
<Content Include="Localization\Views\EditorTemplates\Parts\Localization.ContentTranslations.ascx" />
<Content Include="Reports\Module.txt" /> <Content Include="Reports\Module.txt" />
<Content Include="Reports\Views\Admin\Display.aspx" /> <Content Include="Reports\Views\Admin\Display.aspx" />
<Content Include="Reports\Views\Admin\Index.aspx" /> <Content Include="Reports\Views\Admin\Index.aspx" />

View File

@@ -20,7 +20,6 @@ namespace Orchard.Data.Migration.Interpreters {
private readonly ISession _session; private readonly ISession _session;
private readonly Dialect _dialect; private readonly Dialect _dialect;
private readonly List<string> _sqlStatements; private readonly List<string> _sqlStatements;
private readonly IDataServicesProviderFactory _dataServicesProviderFactory;
private readonly ISessionFactoryHolder _sessionFactoryHolder; private readonly ISessionFactoryHolder _sessionFactoryHolder;
private readonly IReportsCoordinator _reportsCoordinator; private readonly IReportsCoordinator _reportsCoordinator;
@@ -30,21 +29,18 @@ namespace Orchard.Data.Migration.Interpreters {
ShellSettings shellSettings, ShellSettings shellSettings,
ISessionLocator sessionLocator, ISessionLocator sessionLocator,
IEnumerable<ICommandInterpreter> commandInterpreters, IEnumerable<ICommandInterpreter> commandInterpreters,
IDataServicesProviderFactory dataServicesProviderFactory,
ISessionFactoryHolder sessionFactoryHolder, ISessionFactoryHolder sessionFactoryHolder,
IReportsCoordinator reportsCoordinator) { IReportsCoordinator reportsCoordinator) {
_shellSettings = shellSettings; _shellSettings = shellSettings;
_commandInterpreters = commandInterpreters; _commandInterpreters = commandInterpreters;
_session = sessionLocator.For(typeof(DefaultDataMigrationInterpreter)); _session = sessionLocator.For(typeof(DefaultDataMigrationInterpreter));
_sqlStatements = new List<string>(); _sqlStatements = new List<string>();
_dataServicesProviderFactory = dataServicesProviderFactory;
_sessionFactoryHolder = sessionFactoryHolder; _sessionFactoryHolder = sessionFactoryHolder;
_reportsCoordinator = reportsCoordinator; _reportsCoordinator = reportsCoordinator;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
var parameters = _sessionFactoryHolder.GetSessionFactoryParameters(); var configuration = _sessionFactoryHolder.GetConfiguration();
var configuration = _dataServicesProviderFactory.CreateProvider(parameters).BuildConfiguration(parameters);
_dialect = Dialect.GetDialect(configuration.Properties); _dialect = Dialect.GetDialect(configuration.Properties);
} }

View File

@@ -1,4 +1,7 @@
using NHibernate; using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using NHibernate;
using NHibernate.Cfg;
using Orchard.Data.Providers; using Orchard.Data.Providers;
using Orchard.Environment.Configuration; using Orchard.Environment.Configuration;
using Orchard.Environment.ShellBuilders.Models; using Orchard.Environment.ShellBuilders.Models;
@@ -9,6 +12,7 @@ using Orchard.Logging;
namespace Orchard.Data { namespace Orchard.Data {
public interface ISessionFactoryHolder : ISingletonDependency { public interface ISessionFactoryHolder : ISingletonDependency {
ISessionFactory GetSessionFactory(); ISessionFactory GetSessionFactory();
Configuration GetConfiguration();
SessionFactoryParameters GetSessionFactoryParameters(); SessionFactoryParameters GetSessionFactoryParameters();
} }
@@ -19,6 +23,7 @@ namespace Orchard.Data {
private readonly IAppDataFolder _appDataFolder; private readonly IAppDataFolder _appDataFolder;
private ISessionFactory _sessionFactory; private ISessionFactory _sessionFactory;
private Configuration _configuration;
public SessionFactoryHolder( public SessionFactoryHolder(
ShellSettings shellSettings, ShellSettings shellSettings,
@@ -46,17 +51,46 @@ namespace Orchard.Data {
return _sessionFactory; return _sessionFactory;
} }
public Configuration GetConfiguration() {
lock ( this ) {
if ( _configuration == null ) {
_configuration = BuildConfiguration();
}
}
return _configuration;
}
private ISessionFactory BuildSessionFactory() { private ISessionFactory BuildSessionFactory() {
Logger.Debug("Building session factory"); Logger.Debug("Building session factory");
var config = GetConfiguration();
return config.BuildSessionFactory();
}
private Configuration BuildConfiguration() {
var parameters = GetSessionFactoryParameters(); var parameters = GetSessionFactoryParameters();
var sessionFactory = _dataServicesProviderFactory Configuration config = null;
.CreateProvider(parameters) var bf = new BinaryFormatter();
.BuildConfiguration(parameters)
.BuildSessionFactory();
return sessionFactory; var filename = _appDataFolder.MapPath(_appDataFolder.Combine("Sites", "mappings.bin"));
if(_appDataFolder.FileExists(filename)) {
Logger.Debug("Loading mappings from cached file");
using ( var stream = File.OpenRead(filename) ) {
config = bf.Deserialize(stream) as Configuration;
}
}
else {
Logger.Debug("Generating mappings and cached file");
config = _dataServicesProviderFactory
.CreateProvider(parameters)
.BuildConfiguration(parameters);
using ( var stream = File.OpenWrite(filename) ) {
bf.Serialize(stream, config);
}
}
return config;
} }
public SessionFactoryParameters GetSessionFactoryParameters() { public SessionFactoryParameters GetSessionFactoryParameters() {