-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add history project * save history json to disc * Returns history contents * added historyinfo tables * details in infinite editor and delet * localisation stuff * rename solution --------- Co-authored-by: Kevin Jump <[email protected]>
- Loading branch information
Showing
15 changed files
with
508 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Newtonsoft.Json; | ||
using Umbraco.Cms.Infrastructure.Migrations.Expressions.Delete; | ||
using Umbraco.Cms.Web.BackOffice.Controllers; | ||
using Umbraco.Cms.Web.Common.Attributes; | ||
using uSync.BackOffice; | ||
using uSync.BackOffice.Configuration; | ||
using uSync.BackOffice.Services; | ||
|
||
namespace uSync.History.Controllers | ||
{ | ||
[PluginController("uSync")] | ||
public class uSyncHistoryController : UmbracoAuthorizedApiController | ||
{ | ||
private readonly uSyncConfigService _configService; | ||
private readonly SyncFileService _syncFileService; | ||
|
||
public uSyncHistoryController(uSyncConfigService configService, SyncFileService syncFileService) | ||
{ | ||
_configService = configService; | ||
_syncFileService = syncFileService; | ||
} | ||
|
||
public bool GetApi() => true; | ||
|
||
public IEnumerable<HistoryInfo> GetHistory() | ||
{ | ||
var rootFolder = _syncFileService.GetAbsPath(_configService.GetRootFolder()); | ||
var historyFolder = Path.GetFullPath(Path.Combine(rootFolder, "..", "history")); | ||
var files = _syncFileService.GetFiles(historyFolder, "*.json") | ||
.Select(x => x.Substring(historyFolder.Length + 1)); | ||
|
||
var list = new List<HistoryInfo>(); | ||
foreach (var file in files) | ||
{ | ||
list.Add(LoadHistory(file)); | ||
} | ||
|
||
return list.OrderByDescending(x => x.Date); | ||
} | ||
|
||
public bool ClearHistory() | ||
{ | ||
// 1. get history folder | ||
var rootFolder = _syncFileService.GetAbsPath(_configService.GetRootFolder()); | ||
var historyFolder = Path.GetFullPath(Path.Combine(rootFolder, "..", "history")); | ||
// 2. get history files | ||
var files = _syncFileService.GetFiles(historyFolder, "*.json"); | ||
// 3. delet this | ||
foreach (var file in files) | ||
{ | ||
_syncFileService.DeleteFile(file); | ||
} | ||
// 4. truth | ||
return true; | ||
} | ||
|
||
public HistoryInfo LoadHistory(string filePath) | ||
{ | ||
var rootFolder = _syncFileService.GetAbsPath(_configService.GetRootFolder()); | ||
var historyFolder = Path.GetFullPath(Path.Combine(rootFolder, "..", "history")); | ||
var fullPath = Path.Combine(historyFolder, filePath); | ||
string contents = _syncFileService.LoadContent(fullPath); | ||
|
||
var actions = JsonConvert.DeserializeObject<HistoryInfo>(contents); | ||
|
||
actions.FilePath = filePath; | ||
|
||
return actions; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Newtonsoft.Json.Serialization; | ||
using Newtonsoft.Json; | ||
using uSync.BackOffice; | ||
|
||
namespace uSync.History | ||
{ | ||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] | ||
|
||
public class HistoryInfo | ||
{ | ||
public IEnumerable<uSyncAction> Actions { get; set; } | ||
|
||
public DateTime Date { get; set; } | ||
|
||
public string Username { get; set; } | ||
|
||
public string Method { get; set; } | ||
|
||
public string FilePath { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Razor"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<StaticWebAssetBasePath>App_Plugins</StaticWebAssetBasePath> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<Product>uSync.History</Product> | ||
<PackageId>uSync.History</PackageId> | ||
<Title>uSync.History</Title> | ||
|
||
<Authors>Kevin Jump and Henry Jump</Authors> | ||
<Company>Jumoo</Company> | ||
|
||
<PackageTags>umbraco usync</PackageTags> | ||
|
||
<RepositoryUrl>https://github.com/KevinJump/uSync</RepositoryUrl> | ||
|
||
<Description>Sync Umbraco to and from disk and between instances</Description> | ||
|
||
<EmbedUntrackedSources>true</EmbedUntrackedSources> | ||
<IncludeSymbols>false</IncludeSymbols> | ||
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\uSync.BackOffice\uSync.BackOffice.csproj" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using uSync.BackOffice.Models; | ||
|
||
namespace uSync.History | ||
{ | ||
public class uSyncHistory : ISyncAddOn | ||
{ | ||
public string Name => "uSync History"; | ||
|
||
public string Version => "1.0"; | ||
|
||
public string Icon => "icon-calendar-alt"; | ||
|
||
public string View => "/App_Plugins/uSyncHistory/dashboard.html"; | ||
|
||
public string Alias => "uSyncHistory"; | ||
|
||
public string DisplayName => "History"; | ||
|
||
public int SortOrder => 20; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using Microsoft.AspNetCore.Routing; | ||
using Umbraco.Cms.Core.Composing; | ||
using Umbraco.Cms.Core.DependencyInjection; | ||
using Umbraco.Cms.Core.Events; | ||
using Umbraco.Cms.Core.Notifications; | ||
using Umbraco.Cms.Core.Security; | ||
using Umbraco.Cms.Infrastructure.WebAssets; | ||
using Umbraco.Extensions; | ||
using uSync.BackOffice; | ||
using uSync.BackOffice.Configuration; | ||
using uSync.BackOffice.Controllers; | ||
using uSync.BackOffice.Hubs; | ||
using uSync.History.Controllers; | ||
|
||
namespace uSync.History | ||
{ | ||
public class uSyncHistoryComposer : IComposer | ||
{ | ||
public void Compose(IUmbracoBuilder builder) | ||
{ | ||
builder.AddNotificationHandler<ServerVariablesParsingNotification, uSyncHistoryServerVariablesHandler>(); | ||
|
||
builder.AddNotificationHandler<uSyncImportCompletedNotification, uSyncHistoryNotificationHandler>(); | ||
builder.AddNotificationHandler<uSyncExportCompletedNotification, uSyncHistoryNotificationHandler>(); | ||
// don't add if the filter is already there . | ||
if (!builder.ManifestFilters().Has<uSyncHistoryManifestFilter>()) | ||
{ | ||
// add the package manifest programatically. | ||
builder.ManifestFilters().Append<uSyncHistoryManifestFilter>(); | ||
} | ||
} | ||
} | ||
|
||
internal class uSyncHistoryServerVariablesHandler : INotificationHandler<ServerVariablesParsingNotification> | ||
{ | ||
private readonly uSyncConfigService _uSyncConfig; | ||
private readonly LinkGenerator _linkGenerator; | ||
private readonly uSyncHubRoutes _uSyncHubRoutes; | ||
private readonly IBackOfficeSecurityAccessor _securityAccessor; | ||
|
||
/// <inheritdoc cref="INotificationHandler{TNotification}" /> | ||
public uSyncHistoryServerVariablesHandler(LinkGenerator linkGenerator, | ||
uSyncConfigService uSyncConfigService, | ||
uSyncHubRoutes hubRoutes, | ||
IBackOfficeSecurityAccessor securityAccessor) | ||
{ | ||
_linkGenerator = linkGenerator; | ||
_uSyncConfig = uSyncConfigService; | ||
_uSyncHubRoutes = hubRoutes; | ||
_securityAccessor = securityAccessor; | ||
} | ||
|
||
|
||
/// <inheritdoc/> | ||
public void Handle(ServerVariablesParsingNotification notification) | ||
{ | ||
notification.ServerVariables.Add("uSyncHistory", new Dictionary<string, object> | ||
{ | ||
{ "Service", _linkGenerator.GetUmbracoApiServiceBaseUrl<uSyncHistoryController>(controller => controller.GetApi()) }, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Umbraco.Cms.Core.Manifest; | ||
|
||
namespace uSync.History | ||
{ | ||
internal class uSyncHistoryManifestFilter : IManifestFilter | ||
{ | ||
public void Filter(List<PackageManifest> manifests) | ||
{ | ||
manifests.Add(new PackageManifest | ||
{ | ||
PackageId = "uSyncHistory", | ||
PackageName = "uSync History", | ||
Version = "1.0", | ||
AllowPackageTelemetry = true, | ||
BundleOptions = BundleOptions.Independent, | ||
Scripts = new[] | ||
{ | ||
"/App_Plugins/uSyncHistory/dashboard.controller.js" | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using Newtonsoft.Json; | ||
using Umbraco.Cms.Core.Events; | ||
using Umbraco.Cms.Core.Security; | ||
using uSync.BackOffice; | ||
using uSync.BackOffice.Configuration; | ||
using uSync.BackOffice.Services; | ||
|
||
namespace uSync.History | ||
{ | ||
internal class uSyncHistoryNotificationHandler | ||
: INotificationHandler<uSyncImportCompletedNotification>, | ||
INotificationHandler<uSyncExportCompletedNotification> | ||
{ | ||
private readonly uSyncConfigService _configService; | ||
private readonly SyncFileService _syncFileService; | ||
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|
||
public uSyncHistoryNotificationHandler(uSyncConfigService configService, SyncFileService syncFileService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
{ | ||
_configService = configService; | ||
_syncFileService = syncFileService; | ||
_backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
} | ||
|
||
public void Handle(uSyncImportCompletedNotification notification) | ||
{ | ||
var changeActions = notification.Actions | ||
.Where(x => x.Change > Core.ChangeType.NoChange && x.Change < Core.ChangeType.Hidden) | ||
.ToList(); | ||
|
||
if (changeActions.Any()) | ||
{ | ||
SaveActions(changeActions, "Import"); | ||
} | ||
} | ||
|
||
public void Handle(uSyncExportCompletedNotification notification) | ||
{ | ||
var changeActions = notification.Actions | ||
.Where(x => x.Change > Core.ChangeType.NoChange && x.Change < Core.ChangeType.Hidden) | ||
.ToList(); | ||
|
||
if (changeActions.Any()) | ||
{ | ||
SaveActions(changeActions, "Export"); | ||
} | ||
} | ||
|
||
private void SaveActions(IEnumerable<uSyncAction> actions, string method) | ||
{ | ||
var historyInfo = new HistoryInfo | ||
{ | ||
Actions = actions, | ||
Date = DateTime.Now, | ||
Username = _backOfficeSecurityAccessor?.BackOfficeSecurity?.CurrentUser?.Username ?? "Background Process", | ||
Method = method | ||
}; | ||
|
||
var historyJson = JsonConvert.SerializeObject(historyInfo, Formatting.Indented); | ||
|
||
var rootFolder = _syncFileService.GetAbsPath(_configService.GetRootFolder()); | ||
var historyFile = Path.Combine(rootFolder, "..", "history", DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + ".json"); | ||
|
||
_syncFileService.CreateFoldersForFile(historyFile); | ||
|
||
_syncFileService.SaveFile(historyFile, historyJson); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8" standalone="yes"?> | ||
<language alias="en" intName="English (US)" localName="English (US)" lcid="" culture="en-US"> | ||
<creator> | ||
<name>Jumoo</name> | ||
<link>http://jumoo.uk</link> | ||
</creator> | ||
<area alias="uSyncHistory"> | ||
<key alias="title">History</key> | ||
<key alias="description">Things you have done.</key> | ||
<key alias="empty">u have not Synced anything.</key> | ||
<key alias="clearTitle">Are you sure?</key> | ||
<key alias="clearMessage">All history files will be permanently deleted.</key> | ||
</area> | ||
</language> |
Oops, something went wrong.