delete ZeroVue; fixes for vite publish

This commit is contained in:
2022-01-18 20:07:09 +01:00
parent 68f238f03b
commit 8c69ea12ac
11 changed files with 49 additions and 374 deletions
+4 -4
View File
@@ -273,7 +273,7 @@ deps/*.dll
zero.Commerce/
zero.Stories/
zero.Forms/
zero.Web.UI/package.json
zero.Web.UI/package-lock.json
zero.Web.UI/app/core/plugins.js
zero.Web.UI/dist
zero.Backoffice.UI/package.json
zero.Backoffice.UI/package-lock.json
zero.Backoffice.UI/app/core/plugins.js
zero.Backoffice.UI/dist
+7 -7
View File
@@ -1,15 +1,15 @@
/// <reference types="vite/client" />
declare module '*.vue' {
import { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
}
declare module 'vue' {
import { CompatVue } from '@vue/runtime-dom'
const Vue: CompatVue
export default Vue
export * from '@vue/runtime-dom'
}
declare module '*.vue' {
import { DefineComponent } from 'vue'
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
}
@@ -6,8 +6,8 @@
<script>
import api from './api';
import { extendObject } from '../../utils';
import api from '../api';
import { extendObject } from '../../../utils';
export default {
name: 'uiMailtemplatepicker',
+11 -1
View File
@@ -11,6 +11,7 @@ if (!process.env.ZERO_PLUGINS)
{
//loadedPlugins = ["../zero.Commerce/Plugin", "../zero.Stories/Plugin", "../zero.Forms/Plugin", "../../Laola/Laola.Backoffice/Plugin"];
loadedPlugins = ["../plugins/zero.Commerce/Backoffice/Plugin", "../../Laola/Laola.Backoffice/Plugin"]
//loadedPlugins = ["../plugins/zero.Commerce/Backoffice/Plugin"]
//loadedPlugins = [];
}
@@ -77,7 +78,7 @@ let config = defineConfig({
},
resolve: {
alias: {
vue: '@vue/compat',
vue: path.resolve(__dirname, 'node_modules/@vue/compat'),
zero: path.resolve(__dirname, 'app'),
...pluginAliases,
}
@@ -106,6 +107,9 @@ let config = defineConfig({
// 'tiptap': 'tiptap/dist/tiptap.esm.js',
//},
rollupOptions: {
external: {
'@vue/compat': 'xoo/xoo.js'
},
output: {
format: 'es',
entryFileNames: `[name].js`,
@@ -122,6 +126,12 @@ if (process.env.NODE_ENV === 'production')
{
config.base = '/zero/';
//config.alias.tiptap = 'node_modules/tiptap/dist/tiptap.esm.js';
//config.alias.tiptap = 'node_modules/tiptap/dist/tiptap.esm.js';
//config.alias.underscore = 'node_modules/underscore/underscore-esm.js';
//config.alias.axios = 'node_modules/axios/dist/axios.js';
config.resolve.alias.dayjs = 'node_modules/dayjs/esm/index.js';
//config.alias.tiptap = 'node_modules/tiptap/dist/tiptap.esm.js';
}
export default config;
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using System.IO;
using zero.Api.Controllers;
using zero.Backoffice.Services;
@@ -9,17 +11,15 @@ namespace zero.Backoffice.Controllers;
[DisableBrowserCacheFilter]
public class ZeroIndexController : Controller
{
IZeroVue ZeroVue { get; set; }
IZeroOptions Options { get; set; }
IAuthenticationService AuthService { get; set; }
IIconService IconRepository { get; set; }
IWebHostEnvironment Env { get; set; }
public ZeroIndexController(IZeroVue zeroVue, IZeroOptions options, IAuthenticationService authService, IIconService iconRepository)
public ZeroIndexController(IZeroOptions options, IIconService iconRepository, IWebHostEnvironment env)
{
ZeroVue = zeroVue;
Options = options;
AuthService = authService;
IconRepository = iconRepository;
Env = env;
}
@@ -30,54 +30,27 @@ public class ZeroIndexController : Controller
return RedirectToAction("ZeroBackoffice", "Setup");
}
string config = await ZeroVue.ConfigAsJson();
int port = Options.For<BackofficeOptions>().DevServer.Port;
string domain = "http://localhost:" + port;
string content = TokenReplacement.Apply(await LoadTemplate("zero.Backoffice.Resources.backoffice.tpl.html"), new()
Dictionary<string, string> model = new()
{
{ "css", String.Empty },
{ "js", String.Join(String.Empty, GetJsModules(domain, new[] { "/vite/client", "/app/app.ts" })) },
{ "svg", await IconRepository.GetCompiledSvg() },
{ "config", config }
});
{ "top", String.Empty },
{ "bottom", String.Join(String.Empty, GetJsModules(domain, new[] { "/vite/client", "/app/app.ts" })) },
{ "svg", await IconRepository.GetCompiledSvg() }
};
return Content(content, "text/html");
//if (AuthService.IsLoggedIn())
//{
// return await RenderBackoffice(domain, config);
//}
//else
//{
// return await RenderAuth(domain, config);
//}
}
async Task<ActionResult> RenderAuth(string domain, string config)
{
string content = TokenReplacement.Apply(await LoadTemplate("zero.Backoffice.Resources.auth.tpl.html"), new()
if (!Env.IsDevelopment() || true)
{
{ "css", String.Empty },
{ "js", String.Join(String.Empty, GetJsModules(domain, new[] { "/vite/client", "/app/app-auth.js" })) },
{ "svg", await IconRepository.GetCompiledSvg() },
{ "config", config }
});
return Content(content, "text/html");
}
async Task<ActionResult> RenderBackoffice(string domain, string config)
{
string content = TokenReplacement.Apply(await LoadTemplate("zero.Backoffice.Resources.backoffice.tpl.html"), new()
{
{ "css", String.Empty },
{ "js", String.Join(String.Empty, GetJsModules(domain, new[] { "/vite/client", "/app/app.js" })) },
{ "svg", await IconRepository.GetCompiledSvg() },
{ "config", config }
});
model["bottom"] = String.Empty;
model["top"] = @"
<script type='module' crossorigin src='/zero/index.js'></script>
<link rel='modulepreload' href='/zero/vendor.js' />
<link rel='stylesheet' href='/zero/index.css' />
";
}
string content = TokenReplacement.Apply(await LoadTemplate("zero.Backoffice.Resources.backoffice.tpl.html"), model);
return Content(content, "text/html");
}
@@ -94,11 +67,4 @@ public class ZeroIndexController : Controller
using StreamReader reader = new(stream);
return await reader.ReadToEndAsync();
}
}
public class ZeroBackofficeModel
{
public int Port { get; set; }
public IZeroVue Vue { get; set; }
}
}
+1 -2
View File
@@ -28,7 +28,6 @@ public class ZeroBackofficePlugin : ZeroPlugin
services.AddOptions<BackofficeOptions>().Bind(configuration.GetSection("Zero:Backoffice")).Configure<IWebHostEnvironment>(ConfigureOptions);
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, ZeroBackofficeMvcOptions>());
services.AddHostedService<ZeroDevService>();
services.AddTransient<IZeroVue, ZeroVue>();
services.AddSingleton<IMapperProfile, AccountMapperProfile>();
services.AddScoped<IPageTreeService, PageTreeService>();
@@ -70,7 +69,7 @@ public class ZeroBackofficePlugin : ZeroPlugin
Prefix = "fth"
});
options.SupportedLanguages = new string[2] { "en-US", "de-DE" };
options.SupportedLanguages = new string[1] { "en-US" }; //, "de-DE" };
options.DefaultLanguage = options.SupportedLanguages[0];
}
}
-25
View File
@@ -1,25 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="robots" content="noindex,nofollow">
<meta name="author" content="brothers">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="expires" content="0">
<link rel="icon" type="image/png" href="/assets/zero-icon.png" sizes="32x32">
<link rel="image_src" type="image/png" href="/assets/zero-icon.png" sizes="192x192" />
<link rel="shortcut icon" type="image/png" href="/assets/zero-icon.png" sizes="196x196">
<base href="~/">
{css}
<title>zero says hi</title>
</head>
<body class="theme-light theme-rounded">
<div id="app"></div>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">{svg}</svg>
{js}
</body>
</html>
@@ -11,15 +11,15 @@
<link rel="icon" type="image/png" href="/assets/zero-icon.png" sizes="32x32">
<link rel="image_src" type="image/png" href="/assets/zero-icon.png" sizes="192x192" />
<link rel="shortcut icon" type="image/png" href="/assets/zero-icon.png" sizes="196x196">
<base href="~/">
{css}
<base href="/">
{top}
<title>zero</title>
</head>
<body class="theme-light theme-rounded">
<div id="app"></div>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">{svg}</svg>
{js}
{bottom}
</body>
</html>
-8
View File
@@ -1,8 +0,0 @@
namespace zero.Backoffice;
public class ZeroBackofficeModel
{
public int Port { get; set; }
public IZeroVue Vue { get; set; }
}
-266
View File
@@ -1,266 +0,0 @@
using Microsoft.Extensions.Logging;
using System.Text.Json;
namespace zero.Backoffice;
public class ZeroVue : IZeroVue
{
protected IZeroOptions Options { get; private set; }
protected IPaths Paths { get; private set; }
protected IApplicationStore ApplicationStore { get; private set; }
protected IAuthenticationService AuthenticationApi { get; private set; }
protected IEnumerable<IZeroPlugin> Plugins { get; private set; }
protected IEnumerable<IBackofficeSection> Sections { get; private set; }
protected IEnumerable<ISettingsGroup> SettingsGroups { get; private set; }
protected IZeroContext Context { get; private set; }
protected ILogger<IZeroVue> Logger { get; private set; }
protected IZeroStore Store { get; private set; }
public ZeroVue(IZeroOptions options, IPaths paths, IApplicationStore applicationStore, IAuthenticationService authenticationApi,
IEnumerable<IZeroPlugin> plugins, IZeroContext context, ILogger<IZeroVue> logger, IZeroStore store,
IEnumerable<IBackofficeSection> sections, IEnumerable<ISettingsGroup> settingsGroups)
{
Paths = paths;
Options = options;
ApplicationStore = applicationStore;
AuthenticationApi = authenticationApi;
Plugins = plugins;
Context = context;
Logger = logger;
Store = store;
Sections = sections;
SettingsGroups = settingsGroups;
}
/// <inheritdoc/>
public async Task<ZeroVueConfig> Config()
{
ZeroVueConfig config = new();
config.Path = Options.ZeroPath.EnsureEndsWith('/');
config.ApiPath = config.Path + "api/";
config.PluginPath = "@/Plugins";
config.Version = Options.Version;
config.PluginCount = Plugins.Count();
config.ErrorFieldNone = Constants.ErrorFieldNone;
config.Alias = CreateAliases();
config.AppId = Context.AppId;
//config.SharedAppId = Constants.Database.SharedAppId; // TODO appx
config.MultiApps = Options.Applications.Count > 1;
ZeroUser user = await AuthenticationApi.GetUser();
if (user != null)
{
config.User = new
{
Id = user.Id,
AvatarId = user.AvatarId,
Email = user.Email,
IsSuper = user.IsSuper,
Name = user.Name,
Roles = user.RoleIds
};
config.Applications = await CreateApplications();
config.Plugins = Plugins.Select(x => new ZeroVuePlugin()
{
Name = x.Options.Name,
Description = x.Options.Description,
PluginPath = x.Options.PluginPath
}).ToList();
config.Services = new()
{
YouTubeApiKey = Options.For<ExternalServicesOptions>().YouTubeApiKey
};
config.Blueprints = CreateBlueprints();
}
return config;
}
/// <inheritdoc/>
public async Task<string> ConfigAsJson()
{
return JsonSerializer.Serialize(await Config(), new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
});
}
/// <summary>
/// Create aliases
/// </summary>
Dictionary<string, Dictionary<string, string>> CreateAliases()
{
Dictionary<string, Dictionary<string, string>> aliases = new Dictionary<string, Dictionary<string, string>>();
Dictionary<string, string> sections = new Dictionary<string, string>();
sections.Add("dashboard", Constants.Sections.Dashboard);
sections.Add("pages", Constants.Sections.Pages);
sections.Add("spaces", Constants.Sections.Spaces);
sections.Add("media", Constants.Sections.Media);
sections.Add("settings", Constants.Sections.Settings);
Dictionary<string, string> settings = new Dictionary<string, string>();
settings.Add("applications", Constants.Settings.Applications);
settings.Add("countries", Constants.Settings.Countries);
settings.Add("logging", Constants.Settings.Logging);
settings.Add("languages", Constants.Settings.Languages);
settings.Add("translations", Constants.Settings.Translations);
settings.Add("mails", Constants.Settings.Mails);
settings.Add("updates", Constants.Settings.Updates);
settings.Add("users", Constants.Settings.Users);
settings.Add("integrations", Constants.Settings.Integrations);
aliases.Add("sections", sections);
aliases.Add("settings", settings);
aliases.Add("pages", new Dictionary<string, string>()
{
{ "folder", Constants.Pages.FolderAlias }
});
return aliases;
}
/// <summary>
/// Get all visible applications
/// </summary>
async Task<List<ZeroVueApplication>> CreateApplications()
{
IEnumerable<Application> applications = await ApplicationStore.LoadAll();
string[] mediaIds = applications.Select(x => x.IconId).Where(x => x != null).ToArray();
Dictionary<string, Media.Media> media = await Store.Session().LoadAsync<Media.Media>(mediaIds);
return applications.OrderBy(app => app.Sort).Select(app => new ZeroVueApplication()
{
Id = app.Id,
Name = app.Name,
Image = app.IconId.IsNullOrEmpty() ? null : media.GetValueOrDefault(app.IconId)?.ImageMeta?.Thumbnails.GetValueOrDefault("thumb")
}).ToList();
}
List<ZeroVueBlueprint> CreateBlueprints()
{
List<ZeroVueBlueprint> items = new();
if (!Options.For<BlueprintOptions>().Enabled)
{
return items;
}
foreach (Blueprint blueprint in Options.For<BlueprintOptions>())
{
string[] unlocked = blueprint.GetUnlockedFieldNames().ToArray();
items.Add(new()
{
Alias = blueprint.Alias,
Enabled = true,
Unlocked = unlocked
});
}
return items;
}
}
public interface IZeroVue
{
/// <summary>
/// Creates the zero configuration for vue
/// </summary>
Task<ZeroVueConfig> Config();
/// <summary>
/// Creates the zero configuration for vue
/// </summary>
Task<string> ConfigAsJson();
}
public class ZeroVueConfig
{
public string Path { get; set; }
public string ApiPath { get; set; }
public string PluginPath { get; set; }
public IList<ZeroVuePlugin> Plugins { get; set; } = new List<ZeroVuePlugin>();
public string Version { get; set; }
public int PluginCount { get; set; }
public string ErrorFieldNone { get; set; }
public string AppId { get; set; }
public bool MultiApps { get; set; }
public dynamic User { get; set; }
public IList<ZeroVueApplication> Applications { get; set; } = new List<ZeroVueApplication>();
public Dictionary<string, Dictionary<string, string>> Alias { get; set; } = new Dictionary<string, Dictionary<string, string>>();
public Dictionary<string, object> Overrides { get; set; } = new Dictionary<string, object>();
public ZeroVueServices Services { get; set; } = new();
public IList<ZeroVueBlueprint> Blueprints { get; set; } = new List<ZeroVueBlueprint>();
}
public class ZeroVuePlugin
{
public string Name { get; set; }
public string Description { get; set; }
public string PluginPath { get; set; }
}
public class ZeroVueApplication
{
public string Id { get; set; }
public string Name { get; set; }
public string Image { get; set; }
}
public class ZeroVueServices
{
public string YouTubeApiKey { get; set; }
}
public class ZeroVueBlueprint
{
public string Alias { get; set; }
public bool Enabled { get; set; }
public string[] Unlocked { get; set; } = Array.Empty<string>();
}
-1
View File
@@ -18,7 +18,6 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\auth.tpl.html" />
<EmbeddedResource Include="Resources\backoffice.tpl.html" />
</ItemGroup>