move basic stuff into ZeroVue config which is loaded by vue on startup
This commit is contained in:
@@ -117,7 +117,7 @@
|
||||
font-size: var(--font-size);
|
||||
padding: 0 var(--padding);
|
||||
height: 50px;
|
||||
color: var(--color-fg-reverse-mid);
|
||||
color: var(--color-fg);
|
||||
position: relative;
|
||||
transition: color 0.2s ease;
|
||||
|
||||
@@ -147,7 +147,7 @@
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
color: var(--color-fg-mid);
|
||||
color: var(--color-fg);
|
||||
|
||||
&:hover
|
||||
{
|
||||
|
||||
@@ -2,8 +2,6 @@ import { extend as _extend, each as _each } from 'underscore';
|
||||
|
||||
export default {
|
||||
|
||||
cache: zero.translations,
|
||||
|
||||
localize(key, options)
|
||||
{
|
||||
let params = _extend({
|
||||
@@ -24,19 +22,9 @@ export default {
|
||||
}
|
||||
|
||||
key = hasAtSign ? key.slice(1) : key;
|
||||
let value = this.cache;
|
||||
const value = zero.translations[key];
|
||||
|
||||
for (let part of key.split('.'))
|
||||
{
|
||||
if (!value[part])
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
value = value[part];
|
||||
}
|
||||
|
||||
if (!value || value === this.cache || typeof value !== 'string')
|
||||
if (!value || typeof value !== 'string')
|
||||
{
|
||||
return '[' + key + ']';
|
||||
}
|
||||
|
||||
+20
-52
@@ -12,14 +12,14 @@
|
||||
|
||||
<nav class="app-nav-inner">
|
||||
<template v-for="section in sections">
|
||||
<router-link :to="getLink(section)" class="app-nav-item" :class="{ 'has-children': hasChildren(section) }">
|
||||
<router-link :to="section.url" class="app-nav-item" :class="{ 'has-children': hasChildren(section) }">
|
||||
<i class="app-nav-item-icon" :class="section.icon" :style="{ color: false && section.color ? section.color : null }"></i>
|
||||
{{section.name | localize}}
|
||||
<i v-if="hasChildren(section)" class="app-nav-item-arrow fth-chevron-down"></i>
|
||||
</router-link>
|
||||
<transition name="app-nav-children">
|
||||
<div class="app-nav-children" v-if="hasChildren(section) && $route.path.indexOf('/' + section.alias) > -1">
|
||||
<router-link v-for="child in section.children" v-bind:key="child.alias" :to="getLink(section, child)" class="app-nav-child">
|
||||
<router-link v-for="child in section.children" v-bind:key="child.alias" :to="child.url" class="app-nav-child">
|
||||
{{child.name | localize}}
|
||||
</router-link>
|
||||
</div>
|
||||
@@ -40,51 +40,39 @@
|
||||
|
||||
|
||||
<script>
|
||||
import ApplicationsApi from 'zeroresources/applications.js'
|
||||
import SectionsApi from 'zeroresources/sections.js'
|
||||
import { map as _map } from 'underscore';
|
||||
|
||||
export default {
|
||||
name: 'app-navigation',
|
||||
|
||||
data: () => ({
|
||||
applications: [],
|
||||
applications: zero.applications,
|
||||
applicationItems: [],
|
||||
sections: []
|
||||
sections: zero.sections
|
||||
}),
|
||||
|
||||
mounted ()
|
||||
{
|
||||
//console.info(this.$router.history.current.path);
|
||||
|
||||
SectionsApi.getAll().then(items =>
|
||||
this.applicationItems = _map(this.applications, item =>
|
||||
{
|
||||
this.sections = items;
|
||||
return {
|
||||
application: item,
|
||||
active: item.name === "Brothers", // TODO correct active application
|
||||
name: item.name
|
||||
};
|
||||
});
|
||||
ApplicationsApi.getAll().then(items =>
|
||||
{
|
||||
this.applications = items;
|
||||
|
||||
this.applicationItems = _map(items, item =>
|
||||
this.applicationItems.push({
|
||||
type: 'separator'
|
||||
});
|
||||
|
||||
this.applicationItems.push({
|
||||
name: 'Add new application...',
|
||||
icon: 'fth-plus',
|
||||
action(item, dropdown)
|
||||
{
|
||||
return {
|
||||
application: item,
|
||||
active: item.name === "Brothers", // TODO correct active application
|
||||
name: item.name
|
||||
};
|
||||
});
|
||||
|
||||
this.applicationItems.push({
|
||||
type: 'separator'
|
||||
});
|
||||
this.applicationItems.push({
|
||||
name: 'Add new application...',
|
||||
icon: 'fth-plus',
|
||||
action(item, dropdown)
|
||||
{
|
||||
console.info('add');
|
||||
}
|
||||
});
|
||||
console.info('add');
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -96,26 +84,6 @@
|
||||
return section.children && section.children.length > 0;
|
||||
},
|
||||
|
||||
getName(section)
|
||||
{
|
||||
return section.alias.charAt(0).toUpperCase() + section.alias.slice(1);
|
||||
},
|
||||
|
||||
getLink(section, child)
|
||||
{
|
||||
//if (section.alias === "dashboard" && !child)
|
||||
//{
|
||||
// return '/';
|
||||
//}
|
||||
|
||||
if (!child)
|
||||
{
|
||||
return '/' + section.alias;
|
||||
}
|
||||
|
||||
return '/' + section.alias + '/' + child.alias;
|
||||
},
|
||||
|
||||
applicationChanged(item, dropdown)
|
||||
{
|
||||
console.info('change');
|
||||
|
||||
+2
-1
@@ -82,7 +82,7 @@ namespace zero.Web
|
||||
var section = new Section("commerce", "Commerce", "fth-shopping-bag", "#52bba1");
|
||||
section.Children.Add(new Section("orders", "Orders"));
|
||||
section.Children.Add(new Section("customers", "Customers"));
|
||||
section.Children.Add(new Section("catalogue", "Catalogue"));
|
||||
section.Children.Add(new Section("catalogue & ÖBB", "Catalogue"));
|
||||
section.Children.Add(new Section("promotions", "Promotions"));
|
||||
section.Children.Add(new Section("channels", "Channels"));
|
||||
opts.Sections.Insert(3, section);
|
||||
@@ -131,6 +131,7 @@ namespace zero.Web
|
||||
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
||||
// TODO move registration into core
|
||||
services.AddTransient<IZeroVue, ZeroVue>();
|
||||
services.AddTransient<ISetupApi, SetupApi>();
|
||||
services.AddTransient<ISectionsApi, SectionsApi>();
|
||||
services.AddTransient<IApplicationsApi, ApplicationsApi>();
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
@using zero.Core.Extensions
|
||||
@using System.Text
|
||||
@using Microsoft.AspNetCore.Hosting
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@model zero.Core.ZeroOptions
|
||||
@inject IWebHostEnvironment Env
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@inject zero.Web.IZeroVue ZeroVue
|
||||
@{
|
||||
Layout = null;
|
||||
string path = System.IO.Path.Combine(Env.ContentRootPath, "Resources/Localization/zero.en-us.json");
|
||||
string text = System.IO.File.ReadAllText(path, Encoding.UTF8);
|
||||
}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
@@ -28,8 +22,7 @@
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.zero = window.zero || {};
|
||||
zero.path = "@Model.BackofficePath.EnsureEndsWith('/')";
|
||||
zero.translations = @Html.Raw(text);
|
||||
zero = @Html.Raw(await ZeroVue.ConfigAsJson());
|
||||
</script>
|
||||
<script src="~/Assets/app.js" asp-append-version="true"></script>
|
||||
</body>
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using zero.Core;
|
||||
using zero.Core.Api;
|
||||
using zero.Core.Entities;
|
||||
using zero.Core.Extensions;
|
||||
|
||||
namespace zero.Web
|
||||
{
|
||||
public class ZeroVue : IZeroVue
|
||||
{
|
||||
protected IZeroConfiguration Config { get; private set; }
|
||||
|
||||
protected IWebHostEnvironment Environment { get; private set; }
|
||||
|
||||
protected IApplicationsApi ApplicationsApi { get; private set; }
|
||||
|
||||
protected ZeroOptions Options { get; private set; }
|
||||
|
||||
|
||||
public ZeroVue(IZeroConfiguration config, IWebHostEnvironment env, IOptionsMonitor<ZeroOptions> options, IApplicationsApi applicationsApi)
|
||||
{
|
||||
config = Config;
|
||||
Environment = env;
|
||||
Options = options.CurrentValue;
|
||||
ApplicationsApi = applicationsApi;
|
||||
//zero.path = "@Model.BackofficePath.EnsureEndsWith('/')";
|
||||
//zero.translations = @Html.Raw(text);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<string> ConfigAsJson()
|
||||
{
|
||||
ZeroVueConfig config = new ZeroVueConfig();
|
||||
|
||||
config.Path = Options.BackofficePath.EnsureEndsWith('/');
|
||||
config.Sections = CreateSections();
|
||||
config.Translations = CreateTranslations();
|
||||
config.Applications = await CreateApplications();
|
||||
|
||||
return JsonSerializer.Serialize(config, new JsonSerializerOptions()
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates the sections
|
||||
/// </summary>
|
||||
IList<ZeroVueSection> CreateSections()
|
||||
{
|
||||
List<ZeroVueSection> sections = new List<ZeroVueSection>();
|
||||
|
||||
foreach (ISection section in Options.Sections)
|
||||
{
|
||||
ZeroVueSection vueSection = new ZeroVueSection()
|
||||
{
|
||||
Alias = section.Alias,
|
||||
Name = section.Name,
|
||||
Icon = section.Icon,
|
||||
Color = section.Color,
|
||||
Url = Alias.Generate(section.Alias).EnsureStartsWith('/'),
|
||||
Children = new List<ZeroVueSection>()
|
||||
};
|
||||
|
||||
foreach (ISection child in section.Children)
|
||||
{
|
||||
vueSection.Children.Add(new ZeroVueSection()
|
||||
{
|
||||
Alias = child.Alias,
|
||||
Name = child.Name,
|
||||
Url = vueSection.Url.EnsureEndsWith('/') + Alias.Generate(child.Alias)
|
||||
});
|
||||
}
|
||||
|
||||
sections.Add(vueSection);
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get all visible applications
|
||||
/// </summary>
|
||||
async Task<List<ZeroVueApplication>> CreateApplications()
|
||||
{
|
||||
IList<Application> applications = await ApplicationsApi.GetAll();
|
||||
|
||||
return applications.OrderBy(app => app.Sort).Select(app => new ZeroVueApplication()
|
||||
{
|
||||
Id = app.Id,
|
||||
Name = app.Name
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates all translations for the project
|
||||
/// </summary>
|
||||
Dictionary<string, string> CreateTranslations()
|
||||
{
|
||||
string path = Path.Combine(Environment.ContentRootPath, "Resources/Localization/zero.en-us.json");
|
||||
string text = File.ReadAllText(path, Encoding.UTF8);
|
||||
|
||||
JObject json = JObject.Parse(text);
|
||||
IEnumerable<JToken> tokens = json.Descendants().Where(p => p.Count() == 0);
|
||||
|
||||
return tokens.Aggregate(new Dictionary<string, string>(), (properties, token) =>
|
||||
{
|
||||
properties.Add(token.Path, token.ToString());
|
||||
return properties;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface IZeroVue
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates the zero configuration for vue
|
||||
/// </summary>
|
||||
Task<string> ConfigAsJson();
|
||||
}
|
||||
|
||||
|
||||
public class ZeroVueConfig
|
||||
{
|
||||
public string Path { get; set; }
|
||||
|
||||
public IList<ZeroVueSection> Sections { get; set; } = new List<ZeroVueSection>();
|
||||
|
||||
public IList<ZeroVueApplication> Applications { get; set; } = new List<ZeroVueApplication>();
|
||||
|
||||
public Dictionary<string, string> Translations { get; set; } = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
|
||||
public class ZeroVueSection
|
||||
{
|
||||
public string Alias { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Icon { get; set; }
|
||||
|
||||
public string Color { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
public IList<ZeroVueSection> Children { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class ZeroVueApplication
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -42,4 +42,8 @@
|
||||
<ProjectReference Include="..\zero.Core\zero.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="App\Mixins\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user