Skip to content

Commit

Permalink
[new] usePluralNames option for RootDataView and EasyDataViewDispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergiy Korzh committed Feb 3, 2024
1 parent 308e60c commit fc22caa
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
9 changes: 6 additions & 3 deletions easydata.js/packs/crud/src/views/easy_data_view_dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions easydata.js/packs/crud/src/views/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface EasyDataViewDispatcherOptions extends EasyDataViewOptions {
basePath? : string;
rootEntity?: string,
container?: HTMLElement | string;
usePluralNames?: boolean;
}
21 changes: 17 additions & 4 deletions easydata.js/packs/crud/src/views/root_data_view.ts
Original file line number Diff line number Diff line change
@@ -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 += `<h1>${i18n.getText('RootViewTitle')}</h1>`;
utils.assign(this.options, options);

this.renderEntitySelector();
}
Expand All @@ -30,14 +39,18 @@ 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', () => {
setLocation(`${this.basePath}/${decodeURIComponent(ent.id)}`);
})
.addChild('div', b => {
b.addClass('ed-entity-item-caption')
.addText(ent.captionPlural || ent.caption);
.addText(entCaption);
});

if (ent.description) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace EasyData.EntityFrameworkCore
{
/// <summary>
/// Build entity metadata.
/// Builds entity metadata.
/// </summary>
public class MetadataCustomizer
{
Expand All @@ -21,7 +21,7 @@ public MetadataCustomizer(MetaData metadata)

/// <summary>
/// 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
/// </summary>
/// <typeparam name="TEntity">Entity type.</typeparam>
/// <returns>An instance of IMetaEntityCustomizer&lt;TEntity&gt;.</returns>
Expand Down
1 change: 1 addition & 0 deletions playground/EasyDataAspNetCoreTest01/Pages/Crud.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
easydata.runDispatcher({
basePath: 'crud',
endpoint: '/api/easy-crud',
usePluralNames: false
//dataTable: {
// elasticChunks: true
//}
Expand Down

0 comments on commit fc22caa

Please sign in to comment.