mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
Adding recently installed indication.
--HG-- branch : dev
This commit is contained in:
@@ -80,6 +80,7 @@ namespace Orchard.Themes.Controllers {
|
||||
})
|
||||
.Select(extensionDescriptor => new ThemeEntry(extensionDescriptor) {
|
||||
NeedsUpdate = featuresThatNeedUpdate.Contains(extensionDescriptor.Id),
|
||||
IsRecentlyInstalled = _themeService.UpdateIsRecentlyInstalled(extensionDescriptor),
|
||||
Enabled = _shellDescriptor.Features.Any(sf => sf.Name == extensionDescriptor.Id)
|
||||
})
|
||||
.ToArray();
|
||||
|
@@ -1,19 +1,51 @@
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Themes.Models {
|
||||
public class ThemeEntry {
|
||||
/// <summary>
|
||||
/// Represents a theme.
|
||||
/// </summary>
|
||||
public class ThemeEntry {
|
||||
/// <summary>
|
||||
/// Default constructor.
|
||||
/// </summary>
|
||||
public ThemeEntry() {}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a theme based on an extension descriptor.
|
||||
/// </summary>
|
||||
/// <param name="extensionDescriptor">The extension descriptor.</param>
|
||||
public ThemeEntry(ExtensionDescriptor extensionDescriptor) {
|
||||
Descriptor = extensionDescriptor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The theme's extension descriptor.
|
||||
/// </summary>
|
||||
public ExtensionDescriptor Descriptor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Boolean value indicating wether the theme is enabled.
|
||||
/// </summary>
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Boolean value indicating wether the theme needs a data update / migration.
|
||||
/// </summary>
|
||||
public bool NeedsUpdate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Boolean value indicating if the module needs a version update.
|
||||
/// </summary>
|
||||
public bool NeedsVersionUpdate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Boolean value indicating if the feature was recently installed.
|
||||
/// </summary>
|
||||
public bool IsRecentlyInstalled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The theme's name.
|
||||
/// </summary>
|
||||
public string Name { get { return Descriptor.Name; } }
|
||||
}
|
||||
}
|
||||
|
@@ -62,6 +62,7 @@
|
||||
<Compile Include="Preview\PreviewThemeFilter.cs" />
|
||||
<Compile Include="Preview\PreviewThemeSelector.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\IThemeService.cs" />
|
||||
<Compile Include="Services\SafeModeThemeSelector.cs" />
|
||||
<Compile Include="Services\SiteThemeSelector.cs" />
|
||||
<Compile Include="Services\SiteThemeService.cs" />
|
||||
|
@@ -0,0 +1,9 @@
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
|
||||
namespace Orchard.Themes.Services {
|
||||
public interface IThemeService : IDependency {
|
||||
void DisableThemeFeatures(string themeName);
|
||||
void EnableThemeFeatures(string themeName);
|
||||
bool UpdateIsRecentlyInstalled(ExtensionDescriptor module);
|
||||
}
|
||||
}
|
@@ -3,38 +3,30 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Routing;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Environment.Features;
|
||||
using Orchard.FileSystems.VirtualPath;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
|
||||
namespace Orchard.Themes.Services {
|
||||
public interface IThemeService : IDependency {
|
||||
void DisableThemeFeatures(string themeName);
|
||||
void EnableThemeFeatures(string themeName);
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
public class ThemeService : IThemeService {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IFeatureManager _featureManager;
|
||||
private readonly IEnumerable<IThemeSelector> _themeSelectors;
|
||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||
|
||||
public ThemeService(
|
||||
IShellDescriptorManager shellDescriptorManager,
|
||||
IExtensionManager extensionManager,
|
||||
IFeatureManager featureManager,
|
||||
IEnumerable<IThemeSelector> themeSelectors,
|
||||
|
||||
IWorkContextAccessor workContextAccessor,
|
||||
ShellDescriptor shellDescriptor,
|
||||
IOrchardServices orchardServices) {
|
||||
IVirtualPathProvider virtualPathProvider) {
|
||||
_extensionManager = extensionManager;
|
||||
_featureManager = featureManager;
|
||||
_themeSelectors = themeSelectors;
|
||||
_virtualPathProvider = virtualPathProvider;
|
||||
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
@@ -120,5 +112,30 @@ namespace Orchard.Themes.Services {
|
||||
}
|
||||
return themes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the recently installed flag by using the project's last written time.
|
||||
/// </summary>
|
||||
/// <param name="descriptor">The extension descriptor.</param>
|
||||
public bool UpdateIsRecentlyInstalled(ExtensionDescriptor descriptor) {
|
||||
string projectFile = GetManifestPath(descriptor);
|
||||
if (!string.IsNullOrEmpty(projectFile)) {
|
||||
// If project file was modified less than 24 hours ago, the module was recently deployed
|
||||
return DateTime.UtcNow.Subtract(_virtualPathProvider.GetFileLastWriteTimeUtc(projectFile)) < new TimeSpan(1, 0, 0, 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string GetManifestPath(ExtensionDescriptor descriptor) {
|
||||
string projectPath = _virtualPathProvider.Combine(descriptor.Location, descriptor.Id,
|
||||
"theme.txt");
|
||||
|
||||
if (!_virtualPathProvider.FileExists(projectPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return projectPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -51,3 +51,6 @@
|
||||
.themePreviewImage {
|
||||
height:300px;
|
||||
}
|
||||
.recentlyInstalledTheme {
|
||||
background-color: Gray;
|
||||
}
|
@@ -44,7 +44,9 @@
|
||||
} else {
|
||||
<ul class="templates">
|
||||
@foreach (ThemeEntry theme in Model.Themes) {
|
||||
<li>
|
||||
string themeClasses = theme.IsRecentlyInstalled ? "recentlyInstalledTheme" : string.Empty;
|
||||
|
||||
<li class="@themeClasses">
|
||||
<div>
|
||||
<h3>@theme.Name</h3>
|
||||
@Html.Image(Href(Html.ThemePath(Model.CurrentTheme.Descriptor, "/Theme.png")), Html.Encode(Model.CurrentTheme.Name), null)
|
||||
|
Reference in New Issue
Block a user