From fc22caa8478c2732b1d260717e2722d8f2bd3664 Mon Sep 17 00:00:00 2001 From: Sergiy Korzh Date: Sat, 3 Feb 2024 14:13:12 +0200 Subject: [PATCH] [new] usePluralNames option for RootDataView and EasyDataViewDispatcher --- .../src/views/easy_data_view_dispatcher.ts | 9 +++++--- easydata.js/packs/crud/src/views/options.ts | 1 + .../packs/crud/src/views/root_data_view.ts | 21 +++++++++++++++---- .../MetaDataLoader/DbContextMetaDataLoader.cs | 5 ++--- .../ModelCustomizers/MetadataCustomizer.cs | 4 ++-- .../Pages/Crud.cshtml | 1 + 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/easydata.js/packs/crud/src/views/easy_data_view_dispatcher.ts b/easydata.js/packs/crud/src/views/easy_data_view_dispatcher.ts index 320657f4..561ebf0f 100644 --- a/easydata.js/packs/crud/src/views/easy_data_view_dispatcher.ts +++ b/easydata.js/packs/crud/src/views/easy_data_view_dispatcher.ts @@ -4,12 +4,11 @@ import { ProgressBar } from '../widgets/progress_bar'; import { DataContext } from '../main/data_context'; import { EntityDataView } from './entity_data_view'; import { EasyDataViewDispatcherOptions } from './options'; -import { RootDataView } from './root_data_view'; +import { RootDataView, RootDataViewOptions } from './root_data_view'; export class EasyDataViewDispatcher { private context: DataContext; private basePath: string; - private container: HTMLElement; private options: EasyDataViewDispatcherOptions = { @@ -114,7 +113,11 @@ export class EasyDataViewDispatcher { this.basePath, this.options); } else { - window['EDView'] = new RootDataView(this.container, this.context, this.basePath); + const rootViewOptions: RootDataViewOptions = {}; + if (typeof this.options.usePluralNames !== 'undefined') { + rootViewOptions.usePluralNames = this.options.usePluralNames; + } + window['EDView'] = new RootDataView(this.container, this.context, this.basePath, rootViewOptions); } } diff --git a/easydata.js/packs/crud/src/views/options.ts b/easydata.js/packs/crud/src/views/options.ts index 6c601528..f542cd5f 100644 --- a/easydata.js/packs/crud/src/views/options.ts +++ b/easydata.js/packs/crud/src/views/options.ts @@ -13,4 +13,5 @@ export interface EasyDataViewDispatcherOptions extends EasyDataViewOptions { basePath? : string; rootEntity?: string, container?: HTMLElement | string; + usePluralNames?: boolean; } \ No newline at end of file diff --git a/easydata.js/packs/crud/src/views/root_data_view.ts b/easydata.js/packs/crud/src/views/root_data_view.ts index 72d4836e..df244d8c 100644 --- a/easydata.js/packs/crud/src/views/root_data_view.ts +++ b/easydata.js/packs/crud/src/views/root_data_view.ts @@ -1,18 +1,27 @@ -import { i18n, MetaData } from '@easydata/core'; +import { i18n, utils, MetaData } from '@easydata/core'; import { domel } from '@easydata/ui'; import { setLocation } from '../utils/utils'; import { DataContext } from '../main/data_context'; +export interface RootDataViewOptions { + usePluralNames?: boolean; +} + export class RootDataView { private metaData: MetaData; + private options: RootDataViewOptions = { + usePluralNames: true + } constructor ( private slot: HTMLElement, private context: DataContext, - private basePath: string) { - + private basePath: string, + options?: RootDataViewOptions) + { this.metaData = this.context.getMetaData(); this.slot.innerHTML += `

${i18n.getText('RootViewTitle')}

`; + utils.assign(this.options, options); this.renderEntitySelector(); } @@ -30,6 +39,10 @@ export class RootDataView { .addChild('ul', b => { b.addClass('ed-entity-menu'); entities.forEach(ent => { + const entCaption = this.options.usePluralNames && ent.captionPlural + ? ent.captionPlural + : ent.caption; + b.addChild('li', b => { b.addClass('ed-entity-item') .on('click', () => { @@ -37,7 +50,7 @@ export class RootDataView { }) .addChild('div', b => { b.addClass('ed-entity-item-caption') - .addText(ent.captionPlural || ent.caption); + .addText(entCaption); }); if (ent.description) { diff --git a/easydata.net/src/EasyData.EntityFrameworkCore.Relational/MetaDataLoader/DbContextMetaDataLoader.cs b/easydata.net/src/EasyData.EntityFrameworkCore.Relational/MetaDataLoader/DbContextMetaDataLoader.cs index dc59b7a3..1b5bd234 100644 --- a/easydata.net/src/EasyData.EntityFrameworkCore.Relational/MetaDataLoader/DbContextMetaDataLoader.cs +++ b/easydata.net/src/EasyData.EntityFrameworkCore.Relational/MetaDataLoader/DbContextMetaDataLoader.cs @@ -137,10 +137,9 @@ public virtual void LoadFromDbContext() var entityTypes = GetEntityTypes(); if (Options.KeepDbSetDeclarationOrder) { - // EF Core keeps information about entity types - // in alphabetical order. + // EF Core keeps information about entity types in alphabetical order. // To make it possible to keep the original order - // we reoder the list of entities according to the orer of DbSets + // we reorder the list of entities according to the order of DbSets entityTypes = entityTypes.OrderBy(t => _dbSetTypes.TryGetValue(t.ClrType, out var index) ? index : int.MaxValue); diff --git a/easydata.net/src/EasyData.EntityFrameworkCore.Relational/ModelCustomizers/MetadataCustomizer.cs b/easydata.net/src/EasyData.EntityFrameworkCore.Relational/ModelCustomizers/MetadataCustomizer.cs index d4a79d60..b09dc008 100644 --- a/easydata.net/src/EasyData.EntityFrameworkCore.Relational/ModelCustomizers/MetadataCustomizer.cs +++ b/easydata.net/src/EasyData.EntityFrameworkCore.Relational/ModelCustomizers/MetadataCustomizer.cs @@ -4,7 +4,7 @@ namespace EasyData.EntityFrameworkCore { /// - /// Build entity metadata. + /// Builds entity metadata. /// public class MetadataCustomizer { @@ -21,7 +21,7 @@ public MetadataCustomizer(MetaData metadata) /// /// Gets the customizer for an entity by its type. - /// This is a virtual method that can be overriden in descendants + /// This is a virtual method that can be overridden in descendants /// /// Entity type. /// An instance of IMetaEntityCustomizer<TEntity>. diff --git a/playground/EasyDataAspNetCoreTest01/Pages/Crud.cshtml b/playground/EasyDataAspNetCoreTest01/Pages/Crud.cshtml index 3408a72e..73f5b119 100644 --- a/playground/EasyDataAspNetCoreTest01/Pages/Crud.cshtml +++ b/playground/EasyDataAspNetCoreTest01/Pages/Crud.cshtml @@ -17,6 +17,7 @@ easydata.runDispatcher({ basePath: 'crud', endpoint: '/api/easy-crud', + usePluralNames: false //dataTable: { // elasticChunks: true //}