From e2e1614fbd3e8181c2a6003a84dc13b3c5c37076 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Sun, 23 Jan 2022 15:22:28 +0100 Subject: [PATCH] meta info in settings --- zero.Backoffice.UI/app/directives/v-date.ts | 2 +- .../app/modules/settings/settings.vue | 34 ++++++++++++++++++- zero.Backoffice.UI/index.html | 1 + .../Configuration/BackofficeOptions.cs | 5 --- .../Controllers/ZeroIndexController.cs | 25 ++++++++++++-- zero.Backoffice/Resources/backoffice.tpl.html | 1 + zero.Backoffice/ZeroBackofficeMetaInfo.cs | 15 ++++++++ .../Persistence/ZeroPersistenceModule.cs | 8 +++-- 8 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 zero.Backoffice/ZeroBackofficeMetaInfo.cs diff --git a/zero.Backoffice.UI/app/directives/v-date.ts b/zero.Backoffice.UI/app/directives/v-date.ts index 8a9230c6..47275819 100644 --- a/zero.Backoffice.UI/app/directives/v-date.ts +++ b/zero.Backoffice.UI/app/directives/v-date.ts @@ -14,6 +14,6 @@ export default (el, binding) => return; } - el.innerHTML = formatDate(binding.value); + el.innerHTML = formatDate(binding.value, binding.arg); } }; \ No newline at end of file diff --git a/zero.Backoffice.UI/app/modules/settings/settings.vue b/zero.Backoffice.UI/app/modules/settings/settings.vue index b0a180f8..5f187819 100644 --- a/zero.Backoffice.UI/app/modules/settings/settings.vue +++ b/zero.Backoffice.UI/app/modules/settings/settings.vue @@ -18,7 +18,17 @@ - + @@ -34,6 +44,7 @@ page: true, appCount: 0, groups: [], + meta: null, tokens: { 'zero_version': '0.0.1', 'plugin_count': 3 @@ -42,6 +53,8 @@ mounted() { + this.meta = JSON.parse(document.getElementById('zero-meta').innerHTML); + this.groups = useUiStore().settingGroups; this.appCount = useAppStore().applications.length; @@ -149,4 +162,23 @@ top: -4px; right: -4px; } + + .settings-footer + { + font-size: var(--font-size-xs); + color: var(--color-text-dim); + display: flex; + gap: var(--padding); + + p + { + margin: 0; + line-height: 1.4; + } + + .-version + { + color: var(--color-text); + } + } \ No newline at end of file diff --git a/zero.Backoffice.UI/index.html b/zero.Backoffice.UI/index.html index d0b32514..e35c5c6d 100644 --- a/zero.Backoffice.UI/index.html +++ b/zero.Backoffice.UI/index.html @@ -20,6 +20,7 @@ + diff --git a/zero.Backoffice/Configuration/BackofficeOptions.cs b/zero.Backoffice/Configuration/BackofficeOptions.cs index 20a7ba76..5eafc93c 100644 --- a/zero.Backoffice/Configuration/BackofficeOptions.cs +++ b/zero.Backoffice/Configuration/BackofficeOptions.cs @@ -2,11 +2,6 @@ public class BackofficeOptions { - /// - /// Hash for all zero assets - /// - public string AssetHash { get; set; } - /// /// Public path to zero assets /// diff --git a/zero.Backoffice/Controllers/ZeroIndexController.cs b/zero.Backoffice/Controllers/ZeroIndexController.cs index 7dbcda5f..3f7ceebf 100644 --- a/zero.Backoffice/Controllers/ZeroIndexController.cs +++ b/zero.Backoffice/Controllers/ZeroIndexController.cs @@ -2,6 +2,8 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Hosting; using System.IO; +using System.Reflection; +using System.Text.Json; using zero.Api.Controllers; using zero.Backoffice.Services; @@ -16,6 +18,8 @@ public class ZeroIndexController : Controller IWebHostEnvironment Env { get; set; } IBackofficeAssetFileSystem AssetFileSystem { get; set; } + static string MetaInfoJson { get; set; } + public ZeroIndexController(IZeroOptions options, IIconService iconRepository, IWebHostEnvironment env, IBackofficeAssetFileSystem assetFileSystem) { Options = options; @@ -37,16 +41,19 @@ public class ZeroIndexController : Controller int port = options.DevServer.Port; string domain = "http://localhost:" + port; + MetaInfoJson ??= JsonSerializer.Serialize(GetMetaInfo()); + Dictionary model = new() { { "top", String.Empty }, { "bottom", String.Join(String.Empty, GetJsModules(domain, new[] { "/vite/client", "/app/app.ts" })) }, - { "svg", await IconRepository.GetCompiledSvg() } + { "svg", await IconRepository.GetCompiledSvg() }, + { "meta", MetaInfoJson } }; if (!Env.IsDevelopment()) { - string html = System.IO.File.ReadAllText(Path.Combine(Env.WebRootPath, "zero/index.html")); + string html = TokenReplacement.Apply(System.IO.File.ReadAllText(Path.Combine(Env.WebRootPath, "zero/index.html")), model); return Content(html, "text/html"); //string assetHash = options.AssetHash; //string suffix = assetHash.HasValue() ? "?v=" + assetHash : String.Empty; @@ -64,6 +71,20 @@ public class ZeroIndexController : Controller } + ZeroBackofficeMetaInfo GetMetaInfo() + { + Assembly assembly = Assembly.GetEntryAssembly(); + FileInfo assemblyFileInfo = new(assembly.Location); + + return new() + { + AppVersion = assembly.GetCustomAttribute().InformationalVersion, + ZeroVersion = Options.Version, + AppLastModifiedDate = assemblyFileInfo.LastWriteTime + }; + } + + IEnumerable GetJsModules(string domain, string[] modules) { return modules.Select(path => $""); diff --git a/zero.Backoffice/Resources/backoffice.tpl.html b/zero.Backoffice/Resources/backoffice.tpl.html index 29302f78..ba239606 100644 --- a/zero.Backoffice/Resources/backoffice.tpl.html +++ b/zero.Backoffice/Resources/backoffice.tpl.html @@ -20,6 +20,7 @@
{svg} {bottom} + \ No newline at end of file diff --git a/zero.Backoffice/ZeroBackofficeMetaInfo.cs b/zero.Backoffice/ZeroBackofficeMetaInfo.cs new file mode 100644 index 00000000..2608dd21 --- /dev/null +++ b/zero.Backoffice/ZeroBackofficeMetaInfo.cs @@ -0,0 +1,15 @@ +using System.Text.Json.Serialization; + +namespace zero.Backoffice; + +internal class ZeroBackofficeMetaInfo +{ + [JsonPropertyName("zeroVersion")] + public string ZeroVersion { get; set; } + + [JsonPropertyName("appVersion")] + public string AppVersion { get; set; } + + [JsonPropertyName("appLastModifiedDate")] + public DateTimeOffset AppLastModifiedDate { get; set; } +} \ No newline at end of file diff --git a/zero.Core/Persistence/ZeroPersistenceModule.cs b/zero.Core/Persistence/ZeroPersistenceModule.cs index 91ac0e44..3f197f6b 100644 --- a/zero.Core/Persistence/ZeroPersistenceModule.cs +++ b/zero.Core/Persistence/ZeroPersistenceModule.cs @@ -1,6 +1,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Raven.Client.Documents; +using Raven.Client.Documents.Indexes; using Raven.Client.Http; namespace zero.Persistence; @@ -24,11 +25,12 @@ internal class ZeroPersistenceModule : ZeroModule protected ZeroDocumentStore CreateRavenStore(IServiceProvider services) { IZeroOptions options = services.GetService(); + RavenOptions ravenOptions = options.For(); IZeroDocumentConventionsBuilder conventionsBuilder = services.GetService(); IZeroDocumentStore store = new ZeroDocumentStore(options) { - Urls = new string[1] { options.For().Url }, + Urls = new string[1] { ravenOptions.Url }, Conventions = { AggressiveCache = @@ -46,8 +48,8 @@ internal class ZeroPersistenceModule : ZeroModule // create all indexes if (options.Initialized) { - //var indexes = options.Raven.Indexes.BuildAll(options, store); - //IndexCreation.CreateIndexes(indexes, store, database: options.Raven.Database); + var indexes = ravenOptions.Indexes.BuildAll(options, store); + IndexCreation.CreateIndexes(indexes, store, database: ravenOptions.Database); } return (ZeroDocumentStore)raven;