From 598d036d0bfb72a29696f26d3bf9f92ec5fd20b6 Mon Sep 17 00:00:00 2001 From: Tobias Klika Date: Fri, 4 Feb 2022 15:59:35 +0100 Subject: [PATCH] re-integrate backoffice search --- zero.Api/Configuration/ApiOptions.cs | 11 -- zero.Api/Endpoints/Search/SearchController.cs | 6 +- zero.Api/Endpoints/Search/SearchModule.cs | 8 - zero.Api/Plugin.cs | 4 +- zero.Backoffice.UI/app/app.vue | 1 - zero.Backoffice.UI/app/core/zeroRuntime.ts | 5 +- zero.Backoffice.UI/app/modules/index.ts | 3 +- zero.Backoffice.UI/app/modules/search/api.ts | 5 + .../app/modules/search/button.vue | 45 +++++ .../app/modules/search/index.ts | 7 + .../app/modules/search/overlay.vue | 173 ++++++++++++++++++ .../app/modules/search/plugin.ts | 11 ++ zero.Backoffice.UI/app/ui/app-navigation.vue | 7 +- zero.Backoffice.UI/old_app/app.vue | 2 +- zero.Core/Pages/ZeroPageModule.cs | 14 ++ .../Search/Indexes/zero_Search.cs | 6 +- .../Search/Models/SearchIndexMap.cs | 4 +- .../Search/Models/SearchResult.cs | 2 +- .../Search/SearchService.cs | 6 +- zero.Core/Search/ZeroSearchModule.cs | 19 ++ .../Search/ZeroSearchOptions.cs | 4 +- zero.Core/Usings.cs | 3 +- zero.Core/ZeroBuilder.cs | 1 + 23 files changed, 301 insertions(+), 46 deletions(-) delete mode 100644 zero.Api/Configuration/ApiOptions.cs create mode 100644 zero.Backoffice.UI/app/modules/search/api.ts create mode 100644 zero.Backoffice.UI/app/modules/search/button.vue create mode 100644 zero.Backoffice.UI/app/modules/search/index.ts create mode 100644 zero.Backoffice.UI/app/modules/search/overlay.vue create mode 100644 zero.Backoffice.UI/app/modules/search/plugin.ts rename zero.Api/Endpoints/Search/Indexes/zero_Backoffice_Search.cs => zero.Core/Search/Indexes/zero_Search.cs (72%) rename {zero.Api/Endpoints => zero.Core}/Search/Models/SearchIndexMap.cs (96%) rename {zero.Api/Endpoints => zero.Core}/Search/Models/SearchResult.cs (93%) rename {zero.Api/Endpoints => zero.Core}/Search/SearchService.cs (92%) create mode 100644 zero.Core/Search/ZeroSearchModule.cs rename zero.Api/Endpoints/Search/SearchOptions.cs => zero.Core/Search/ZeroSearchOptions.cs (68%) diff --git a/zero.Api/Configuration/ApiOptions.cs b/zero.Api/Configuration/ApiOptions.cs deleted file mode 100644 index 5c06b3a4..00000000 --- a/zero.Api/Configuration/ApiOptions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using zero.Api.Endpoints.Search; - -namespace zero.Api.Configuration; - -public class ApiOptions -{ - /// - /// Configure search maps - /// - public SearchOptions Search { get; set; } = new(); -} \ No newline at end of file diff --git a/zero.Api/Endpoints/Search/SearchController.cs b/zero.Api/Endpoints/Search/SearchController.cs index e57b6d51..5c43eb13 100644 --- a/zero.Api/Endpoints/Search/SearchController.cs +++ b/zero.Api/Endpoints/Search/SearchController.cs @@ -1,5 +1,5 @@ using Microsoft.AspNetCore.Mvc; -using zero.Api.Filters; +using zero.Search; namespace zero.Api.Endpoints.Search; @@ -16,6 +16,10 @@ public class SearchController : ZeroApiController [HttpGet("")] public async Task> Query([FromQuery] ListQuery query) { + if (!query.Search.HasValue()) + { + return new Paged(new List(), 0, query.Page, query.PageSize); + } return await Service.Query(query.Search); } } \ No newline at end of file diff --git a/zero.Api/Endpoints/Search/SearchModule.cs b/zero.Api/Endpoints/Search/SearchModule.cs index cb7d27ce..1a42e399 100644 --- a/zero.Api/Endpoints/Search/SearchModule.cs +++ b/zero.Api/Endpoints/Search/SearchModule.cs @@ -8,13 +8,5 @@ public class SearchModule : ZeroModule public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddSingleton(); - services.AddScoped(); - - //services.Configure(opts => - //{ - // opts.Indexes.Add(); - //}); - - services.AddOptions().Bind(configuration.GetSection("Zero:Search")); } } \ No newline at end of file diff --git a/zero.Api/Plugin.cs b/zero.Api/Plugin.cs index 23584ccd..887343d1 100644 --- a/zero.Api/Plugin.cs +++ b/zero.Api/Plugin.cs @@ -21,7 +21,6 @@ public class ZeroApiPlugin : ZeroPlugin public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { - services.AddOptions().Bind(configuration.GetSection("Zero:Api")).Configure(ConfigureOptions); services.TryAddEnumerable(ServiceDescriptor.Transient, ZeroApiMvcOptions>()); services.AddTransient(); services.AddTransient(); @@ -68,9 +67,8 @@ public class ZeroApiPlugin : ZeroPlugin } - protected void ConfigureOptions(ApiOptions options, IWebHostEnvironment env) + protected void ConfigureOptions(IWebHostEnvironment env) { - options.Search.Enabled = true; //Map().Display((x, res, opts) => //{ // PageType pageType = opts.Pages.GetByAlias(x.PageTypeAlias); diff --git a/zero.Backoffice.UI/app/app.vue b/zero.Backoffice.UI/app/app.vue index eb282450..20cb9080 100644 --- a/zero.Backoffice.UI/app/app.vue +++ b/zero.Backoffice.UI/app/app.vue @@ -59,7 +59,6 @@ { await this.startup(); } - } }); diff --git a/zero.Backoffice.UI/app/core/zeroRuntime.ts b/zero.Backoffice.UI/app/core/zeroRuntime.ts index b1458492..dcb87f06 100644 --- a/zero.Backoffice.UI/app/core/zeroRuntime.ts +++ b/zero.Backoffice.UI/app/core/zeroRuntime.ts @@ -22,7 +22,8 @@ import integrationPlugin, userPlugin, linksPlugin, - pageModulePlugin + pageModulePlugin, + searchPlugin } from '../modules'; import editorPlugin from '../editor/plugin'; import { ZeroSchema, ZeroSchemaExtension } from 'zero/schemas'; @@ -35,7 +36,7 @@ import { Emitter, EventType } from 'mitt'; plugins.push( editorPlugin, countryPlugin, applicationPlugin, settingsPlugin, languagePlugin, pagePlugin, linksPlugin, mediaPlugin, spacePlugin, mailTemplatePlugin, - translationPlugin, integrationPlugin, userPlugin, pageModulePlugin + translationPlugin, integrationPlugin, userPlugin, pageModulePlugin, searchPlugin ); diff --git a/zero.Backoffice.UI/app/modules/index.ts b/zero.Backoffice.UI/app/modules/index.ts index 8a6abd55..9c6812e5 100644 --- a/zero.Backoffice.UI/app/modules/index.ts +++ b/zero.Backoffice.UI/app/modules/index.ts @@ -11,4 +11,5 @@ export * from './translations'; export * from './integrations'; export * from './users'; export * from './links'; -export * from './pageModules'; \ No newline at end of file +export * from './pageModules'; +export * from './search'; \ No newline at end of file diff --git a/zero.Backoffice.UI/app/modules/search/api.ts b/zero.Backoffice.UI/app/modules/search/api.ts new file mode 100644 index 00000000..bbe65c28 --- /dev/null +++ b/zero.Backoffice.UI/app/modules/search/api.ts @@ -0,0 +1,5 @@ +import { get, post, put, del, ApiRequestConfig, ApiRequestQuery } from '../../services/request'; + +export default { + query: (term: string, query?: ApiRequestQuery, config?: ApiRequestConfig) => get("search", { ...config, params: { ...query, search: term } }) +}; \ No newline at end of file diff --git a/zero.Backoffice.UI/app/modules/search/button.vue b/zero.Backoffice.UI/app/modules/search/button.vue new file mode 100644 index 00000000..f9ad6b12 --- /dev/null +++ b/zero.Backoffice.UI/app/modules/search/button.vue @@ -0,0 +1,45 @@ + + + \ No newline at end of file diff --git a/zero.Backoffice.UI/app/modules/search/index.ts b/zero.Backoffice.UI/app/modules/search/index.ts new file mode 100644 index 00000000..0e771821 --- /dev/null +++ b/zero.Backoffice.UI/app/modules/search/index.ts @@ -0,0 +1,7 @@ +import api from './api'; +import plugin from './plugin'; + +export { + api as searchApi, + plugin as searchPlugin +}; \ No newline at end of file diff --git a/zero.Backoffice.UI/app/modules/search/overlay.vue b/zero.Backoffice.UI/app/modules/search/overlay.vue new file mode 100644 index 00000000..502a725d --- /dev/null +++ b/zero.Backoffice.UI/app/modules/search/overlay.vue @@ -0,0 +1,173 @@ + + + + + + \ No newline at end of file diff --git a/zero.Backoffice.UI/app/modules/search/plugin.ts b/zero.Backoffice.UI/app/modules/search/plugin.ts new file mode 100644 index 00000000..763cea24 --- /dev/null +++ b/zero.Backoffice.UI/app/modules/search/plugin.ts @@ -0,0 +1,11 @@ +import { ZeroPlugin, ZeroPluginOptions } from '../../core'; +import { defineAsyncComponent } from 'vue'; + +export default { + name: "zero.search", + + install(app: ZeroPluginOptions) + { + app.vue.component('app-search', defineAsyncComponent(() => import('./button.vue'))); + } +} as ZeroPlugin; \ No newline at end of file diff --git a/zero.Backoffice.UI/app/ui/app-navigation.vue b/zero.Backoffice.UI/app/ui/app-navigation.vue index ca547b29..d804c6c9 100644 --- a/zero.Backoffice.UI/app/ui/app-navigation.vue +++ b/zero.Backoffice.UI/app/ui/app-navigation.vue @@ -7,7 +7,7 @@ - +
@@ -173,11 +173,6 @@ { this.compact = !this.compact; localStorage.setItem(compactCacheKey, this.compact.toString()); - }, - - openSearch() - { - //EventHub.$emit('app.search.open'); } } }); diff --git a/zero.Backoffice.UI/old_app/app.vue b/zero.Backoffice.UI/old_app/app.vue index 513dd115..1f92b099 100644 --- a/zero.Backoffice.UI/old_app/app.vue +++ b/zero.Backoffice.UI/old_app/app.vue @@ -68,7 +68,7 @@ this.rerender(); }); - EventHub.$on('app.search.open', () => + this.zero.events.on('app.search.open', () => { this.search(); }); diff --git a/zero.Core/Pages/ZeroPageModule.cs b/zero.Core/Pages/ZeroPageModule.cs index e6b5ef6f..52932a3d 100644 --- a/zero.Core/Pages/ZeroPageModule.cs +++ b/zero.Core/Pages/ZeroPageModule.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using zero.Search; namespace zero.Pages; @@ -32,5 +33,18 @@ internal class ZeroPageModule : ZeroModule cfg.Add(Constants.Pages.FolderAlias, "@page.folder.name", "@page.folder.description", "fth-folder"); }); }); + + services.Configure(opts => + { + opts.Map().Display((x, res, opts) => + { + FlavorConfig flavor = opts.For().Get(x.Flavor); + if (flavor != null) + { + res.Icon = flavor.Icon; + } + res.Url = "/pages/edit/" + x.Id; + }); + }); } } \ No newline at end of file diff --git a/zero.Api/Endpoints/Search/Indexes/zero_Backoffice_Search.cs b/zero.Core/Search/Indexes/zero_Search.cs similarity index 72% rename from zero.Api/Endpoints/Search/Indexes/zero_Backoffice_Search.cs rename to zero.Core/Search/Indexes/zero_Search.cs index b5bfbe4f..df05089c 100644 --- a/zero.Api/Endpoints/Search/Indexes/zero_Backoffice_Search.cs +++ b/zero.Core/Search/Indexes/zero_Search.cs @@ -1,14 +1,14 @@ using Raven.Client.Documents; -namespace zero.Api.Endpoints.Search; +namespace zero.Search; -public class zero_Backoffice_Search : ZeroJavascriptIndex +public class zero_Search : ZeroJavascriptIndex { public override void Setup(IZeroOptions options, IDocumentStore store) { // TODO index.Conventions is null, but needed for collection name retrieval - foreach (var map in options.For()) + foreach (var map in options.For()) { Maps.Add(map.BuildInstruction(store)); } diff --git a/zero.Api/Endpoints/Search/Models/SearchIndexMap.cs b/zero.Core/Search/Models/SearchIndexMap.cs similarity index 96% rename from zero.Api/Endpoints/Search/Models/SearchIndexMap.cs rename to zero.Core/Search/Models/SearchIndexMap.cs index bc1f9c63..997a401e 100644 --- a/zero.Api/Endpoints/Search/Models/SearchIndexMap.cs +++ b/zero.Core/Search/Models/SearchIndexMap.cs @@ -1,6 +1,6 @@ using Raven.Client.Documents; -namespace zero.Api.Endpoints.Search; +namespace zero.Search; public class SearchIndexMap { @@ -66,7 +66,7 @@ public class SearchIndexMap : SearchIndexMap where T : ZeroEntity { internal SearchIndexMap(string icon = null) : base(typeof(T), icon) { } - public SearchIndexMap Icon(string icon) + public virtual SearchIndexMap Icon(string icon) { _Icon = icon; return this; diff --git a/zero.Api/Endpoints/Search/Models/SearchResult.cs b/zero.Core/Search/Models/SearchResult.cs similarity index 93% rename from zero.Api/Endpoints/Search/Models/SearchResult.cs rename to zero.Core/Search/Models/SearchResult.cs index 0536a3c4..7f4cd64f 100644 --- a/zero.Api/Endpoints/Search/Models/SearchResult.cs +++ b/zero.Core/Search/Models/SearchResult.cs @@ -1,4 +1,4 @@ -namespace zero.Api.Endpoints.Search; +namespace zero.Search; public class SearchResult { diff --git a/zero.Api/Endpoints/Search/SearchService.cs b/zero.Core/Search/SearchService.cs similarity index 92% rename from zero.Api/Endpoints/Search/SearchService.cs rename to zero.Core/Search/SearchService.cs index ab211af3..9dba36b6 100644 --- a/zero.Api/Endpoints/Search/SearchService.cs +++ b/zero.Core/Search/SearchService.cs @@ -2,7 +2,7 @@ using Raven.Client.Documents.Queries; using Raven.Client.Documents.Session; -namespace zero.Api.Endpoints.Search; +namespace zero.Search; public class SearchService : ISearchService { @@ -25,7 +25,7 @@ public class SearchService : ISearchService return "*" + x + "*"; }).ToArray(); - List results = await Store.Session().Query() + List results = await Store.Session().Query() .Statistics(out QueryStatistics stats) .Search(x => x.Name, searchParts, 2, @operator: SearchOperator.And) .Search(x => x.Fields, searchParts, 1, Raven.Client.Documents.SearchOptions.Or, @operator: SearchOperator.And) @@ -35,7 +35,7 @@ public class SearchService : ISearchService List items = new(); - IEnumerable maps = Options.For(); + IEnumerable maps = Options.For(); foreach (ZeroEntity result in results) { diff --git a/zero.Core/Search/ZeroSearchModule.cs b/zero.Core/Search/ZeroSearchModule.cs new file mode 100644 index 00000000..c424dca6 --- /dev/null +++ b/zero.Core/Search/ZeroSearchModule.cs @@ -0,0 +1,19 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace zero.Search; + +internal class ZeroSearchModule : ZeroModule +{ + public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) + { + services.AddScoped(); + + services.Configure(opts => + { + opts.Indexes.Add(); + }); + + services.AddOptions().Bind(configuration.GetSection("Zero:Search")); + } +} \ No newline at end of file diff --git a/zero.Api/Endpoints/Search/SearchOptions.cs b/zero.Core/Search/ZeroSearchOptions.cs similarity index 68% rename from zero.Api/Endpoints/Search/SearchOptions.cs rename to zero.Core/Search/ZeroSearchOptions.cs index 7fb7098e..01a93ae8 100644 --- a/zero.Api/Endpoints/Search/SearchOptions.cs +++ b/zero.Core/Search/ZeroSearchOptions.cs @@ -1,6 +1,6 @@ -namespace zero.Api.Endpoints.Search; +namespace zero.Search; -public class SearchOptions : List +public class ZeroSearchOptions : List { public bool Enabled { get; set; } diff --git a/zero.Core/Usings.cs b/zero.Core/Usings.cs index 9fc55ec8..34318fee 100644 --- a/zero.Core/Usings.cs +++ b/zero.Core/Usings.cs @@ -26,4 +26,5 @@ global using zero.Routing; global using zero.Stores; global using zero.Spaces; global using zero.Utils; -global using zero.Validation; \ No newline at end of file +global using zero.Validation; +global using zero.Search; \ No newline at end of file diff --git a/zero.Core/ZeroBuilder.cs b/zero.Core/ZeroBuilder.cs index 1892ecba..e4e4cc1c 100644 --- a/zero.Core/ZeroBuilder.cs +++ b/zero.Core/ZeroBuilder.cs @@ -56,6 +56,7 @@ public class ZeroBuilder Modules.Add(); Modules.Add(); Modules.Add(); + Modules.Add(); Modules.ConfigureServices(services, configuration);