Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroCano committed May 20, 2020
2 parents f3fe11f + b795baa commit f748754
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 33 deletions.
3 changes: 2 additions & 1 deletion Signum.Engine/Basics/SemiSymbolLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Signum.Engine.Maps;
using Signum.Entities;
using Signum.Entities.Basics;
using Signum.Utilities;
using Signum.Utilities.ExpressionTrees;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static void Start(SchemaBuilder sb, Func<IEnumerable<T>> getSemiSymbols)
}
}

static void SymbolLogic_Retrieved(T ident)
static void SymbolLogic_Retrieved(T ident, PostRetrievingContext ctx)
{
if (!avoidCache && ident.Key.HasText())
try
Expand Down
2 changes: 1 addition & 1 deletion Signum.Engine/Basics/SymbolLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void Start(SchemaBuilder sb, Func<IEnumerable<T>> getSymbols)
}
}

static void SymbolLogic_Retrieved(T ident)
static void SymbolLogic_Retrieved(T ident, PostRetrievingContext ctx)
{
if (!avoidCache)
try
Expand Down
4 changes: 2 additions & 2 deletions Signum.Engine/Patterns/VirtualMList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static FluentInclude<T> WithVirtualMList<T, L>(this FluentInclude<T> fi,

if (defLazyRetrieve)
{
sb.Schema.EntityEvents<T>().Retrieved += (T e) =>
sb.Schema.EntityEvents<T>().Retrieved += (T e, PostRetrievingContext ctx) =>
{
if (ShouldAvoidMListType(typeof(L)))
return;
Expand All @@ -126,7 +126,7 @@ public static FluentInclude<T> WithVirtualMList<T, L>(this FluentInclude<T> fi,
query.ToVirtualMListWithOrder() :
query.ToVirtualMList();
mlist.AssignAndPostRetrieving(newList);
mlist.AssignAndPostRetrieving(newList, ctx);
};
}

Expand Down
17 changes: 10 additions & 7 deletions Signum.Engine/Retriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public async Task CompleteAllPrivate(CancellationToken? token)

cc.Complete(ident, this);

retrieved.Add((type: ident.GetType(), id : ident.Id), ident);
retrieved.Add((type: ident.GetType(), id: ident.Id), ident);
dic.Remove(ident.Id);
}
}
Expand Down Expand Up @@ -267,25 +267,26 @@ public async Task CompleteAllPrivate(CancellationToken? token)

var currentlyRetrieved = retrieved.Values.ToHashSet();
var currentlyModifiableRetrieved = modifiablePostRetrieving.ToHashSet(Signum.Utilities.DataStructures.ReferenceEqualityComparer<Modifiable>.Default);
var ctx = new PostRetrievingContext();
foreach (var entity in currentlyRetrieved)
{
entity.PostRetrieving();
Schema.Current.OnRetrieved(entity);
entity.PostRetrieving(ctx);
Schema.Current.OnRetrieved(entity, ctx);
entityCache.Add(entity);
}

foreach (var embedded in currentlyModifiableRetrieved)
embedded.PostRetrieving();
embedded.PostRetrieving(ctx);

ModifiedState ms = ModifiedState;
foreach (var entity in currentlyRetrieved)
{
entity.Modified = ms;
entity.Modified = ctx.ForceModifiedState.TryGetS(entity) ?? ms;
entity.IsNew = false;
}

foreach (var embedded in currentlyModifiableRetrieved)
embedded.Modified = ms;
embedded.Modified = ctx.ForceModifiedState.TryGetS(embedded) ?? ms;

if (liteRequests != null && liteRequests.Count > 0 ||
requests != null && requests.Count > 0 ||
Expand Down Expand Up @@ -351,7 +352,7 @@ class ChildRetriever : IRetriever
public IRetriever? Parent => parent;
public ChildRetriever(IRetriever parent, EntityCache.RealEntityCache entityCache)
{
this.parent= parent;
this.parent = parent;
this.entityCache = entityCache;
}

Expand Down Expand Up @@ -399,4 +400,6 @@ public ModifiedState ModifiedState
get { return this.entityCache.IsSealed ? ModifiedState.Sealed : ModifiedState.Clean; }
}
}


}
10 changes: 5 additions & 5 deletions Signum.Engine/Schema/EntityEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ void IEntityEvents.OnSaved(Entity entity, SavedEventArgs args)

}

void IEntityEvents.OnRetrieved(Entity entity)
void IEntityEvents.OnRetrieved(Entity entity, PostRetrievingContext ctx)
{
Retrieved?.Invoke((T)entity);
Retrieved?.Invoke((T)entity, ctx);
}

public Entity? OnAlternativeRetrieving(PrimaryKey id)
Expand Down Expand Up @@ -215,7 +215,7 @@ Action<T, M, IRetriever> CreateSetter()
if (mlist == null)
return;
((IMListPrivate)mlist).AssignAndPostRetrieving((IMListPrivate)value!);
((IMListPrivate)mlist).AssignAndPostRetrieving((IMListPrivate)value!, null!);
retriever.ModifiablePostRetrieving((Modifiable)(object)mlist);
};
Expand Down Expand Up @@ -245,7 +245,7 @@ Action<T, M, IRetriever> CreateSetter()
}

public delegate void PreSavingEventHandler<T>(T ident, PreSavingContext ctx) where T : Entity;
public delegate void RetrievedEventHandler<T>(T ident) where T : Entity;
public delegate void RetrievedEventHandler<T>(T ident, PostRetrievingContext ctx) where T : Entity;
public delegate void SavingEventHandler<T>(T ident) where T : Entity;
public delegate void SavedEventHandler<T>(T ident, SavedEventArgs args) where T : Entity;
public delegate FilterQueryResult<T>? FilterQueryEventHandler<T>() where T : Entity;
Expand Down Expand Up @@ -297,7 +297,7 @@ internal interface IEntityEvents
void OnSaving(Entity entity);
void OnSaved(Entity entity, SavedEventArgs args);

void OnRetrieved(Entity entity);
void OnRetrieved(Entity entity, PostRetrievingContext ctx);

IDisposable? OnPreUnsafeDelete(IQueryable entityQuery);
IDisposable? OnPreUnsafeUpdate(IUpdateable update);
Expand Down
6 changes: 3 additions & 3 deletions Signum.Engine/Schema/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ internal void OnSaved(Entity entity, SavedEventArgs args)
entityEventsGlobal.OnSaved(entity, args);
}

internal void OnRetrieved(Entity entity)
internal void OnRetrieved(Entity entity, PostRetrievingContext ctx)
{
AssertAllowed(entity.GetType(), inUserInterface: false);

IEntityEvents? ee = entityEvents.TryGetC(entity.GetType());

if (ee != null)
ee.OnRetrieved(entity);
ee.OnRetrieved(entity, ctx);

entityEventsGlobal.OnRetrieved(entity);
entityEventsGlobal.OnRetrieved(entity, ctx);
}

internal IDisposable? OnPreUnsafeDelete<T>(IQueryable<T> entityQuery) where T : Entity
Expand Down
14 changes: 7 additions & 7 deletions Signum.Entities/MList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,12 @@ void IMListPrivate.SetOldIndex(int index)
this.innerList[index] = new RowIdElement(prev.Element, prev.RowId!.Value, index);
}

void IMListPrivate.ExecutePostRetrieving()
void IMListPrivate.ExecutePostRetrieving(PostRetrievingContext ctx)
{
this.PostRetrieving();
this.PostRetrieving(ctx);
}

protected internal override void PostRetrieving()
protected internal override void PostRetrieving(PostRetrievingContext ctx)
{
if (this.innerList.Any(a => a.RowId == null))
return; //The MList was changed in the entity PostRetriever, like UserChart Columns
Expand Down Expand Up @@ -775,10 +775,10 @@ bool IMListPrivate<T>.IsEqualTo(List<MList<T>.RowIdElement> newList, bool orderM

}

public void AssignAndPostRetrieving(IMListPrivate newList)
public void AssignAndPostRetrieving(IMListPrivate newList, PostRetrievingContext ctx)
{
this.AssignMList((MList<T>)newList);
this.PostRetrieving();
this.PostRetrieving(ctx);
}

public void Insert(int? index, object? value)
Expand Down Expand Up @@ -809,15 +809,15 @@ public interface IMListPrivate

int Count { get; }

void ExecutePostRetrieving();
void ExecutePostRetrieving(PostRetrievingContext ctx);
void SetOldIndex(int index);
PrimaryKey? GetRowId(int index);
void SetRowId(int index, PrimaryKey rowId);
void ForceRowId(int index, PrimaryKey rowId);

void InnerListModified(IList? newItems, IList? oldItems);

void AssignAndPostRetrieving(IMListPrivate newList);
void AssignAndPostRetrieving(IMListPrivate newList, PostRetrievingContext ctx);
}

public interface IMListPrivate<T> : IMListPrivate
Expand Down
2 changes: 1 addition & 1 deletion Signum.Entities/ModelEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protected internal override void PreSaving(PreSavingContext ctx)

}

protected internal override void PostRetrieving()
protected internal override void PostRetrieving(PostRetrievingContext ctx)
{
throw new InvalidOperationException("ModelEntities are not meant to be retrieved");
}
Expand Down
10 changes: 8 additions & 2 deletions Signum.Entities/Modifiable.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using Signum.Utilities;
using Signum.Utilities.DataStructures;
using System.Diagnostics;
using System.Collections.Generic;

namespace Signum.Entities
{
Expand Down Expand Up @@ -47,7 +48,7 @@ protected internal virtual void PreSaving(PreSavingContext ctx)
{
}

protected internal virtual void PostRetrieving()
protected internal virtual void PostRetrieving(PostRetrievingContext ctx)
{
}
}
Expand All @@ -67,6 +68,11 @@ public void InvalidateGraph()
}
}

public class PostRetrievingContext
{
public Dictionary<Modifiable, ModifiedState> ForceModifiedState = new Dictionary<Modifiable, ModifiedState>();
}

public enum ModifiedState
{
SelfModified,
Expand Down
2 changes: 1 addition & 1 deletion Signum.Entities/ModifiableEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public string ToStringProperty

#region Collection Events

protected internal override void PostRetrieving()
protected internal override void PostRetrieving(PostRetrievingContext ctx)
{
RebindEvents();
}
Expand Down
27 changes: 27 additions & 0 deletions Signum.React/Scripts/FindOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ export interface PinnedFilterParsed {
splitText?: boolean;
}

export function toPinnedFilterParsed(pf: PinnedFilter): PinnedFilterParsed {
return {
label: typeof pf.label == "function" ? pf.label() : pf.label,
row: pf.row,
column: pf.column,
active: pf.active,
splitText: pf.splitText
};
}

export interface FilterGroupOptionParsed {
groupOperation: FilterGroupOperation;
frozen: boolean;
Expand Down Expand Up @@ -222,6 +232,23 @@ export function withoutAggregate(fop: FilterOptionParsed): FilterOptionParsed |
};
}

export function withoutPinned(fop: FilterOptionParsed): FilterOptionParsed {

if (isFilterGroupOptionParsed(fop)) {
var newFilters = fop.filters.map(f => withoutPinned(f));
return ({
...fop,
filters: newFilters,
pinned: undefined,
}) as FilterOptionParsed;
};

return {
...fop,
pinned: undefined
};
}

export function getTokenParents(token: QueryToken | null | undefined): QueryToken[] {
const result: QueryToken[] = [];
while (token) {
Expand Down
6 changes: 3 additions & 3 deletions Signum.React/Scripts/Finder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
FindOptionsParsed, FilterOption, FilterOptionParsed, OrderOptionParsed, ValueFindOptionsParsed,
QueryToken, ColumnDescription, ColumnOption, ColumnOptionParsed, Pagination, ResultColumn,
ResultTable, ResultRow, OrderOption, SubTokensOptions, toQueryToken, isList, ColumnOptionsMode, FilterRequest, ModalFindOptions, OrderRequest, ColumnRequest,
isFilterGroupOption, FilterGroupOptionParsed, FilterConditionOptionParsed, isFilterGroupOptionParsed, FilterGroupOption, FilterConditionOption, FilterGroupRequest, FilterConditionRequest, PinnedFilter, SystemTime, QueryTokenType, hasAnyOrAll, hasAggregate, hasElement
isFilterGroupOption, FilterGroupOptionParsed, FilterConditionOptionParsed, isFilterGroupOptionParsed, FilterGroupOption, FilterConditionOption, FilterGroupRequest, FilterConditionRequest, PinnedFilter, SystemTime, QueryTokenType, hasAnyOrAll, hasAggregate, hasElement, toPinnedFilterParsed
} from './FindOptions';

import { PaginationMode, OrderType, FilterOperation, FilterType, UniqueType, QueryTokenMessage, FilterGroupOperation, PinnedFilterActive } from './Signum.Entities.DynamicQuery';
Expand Down Expand Up @@ -1024,7 +1024,7 @@ export class TokenCompleter {
token: fo.token && this.get(fo.token.toString()),
groupOperation: fo.groupOperation,
value: fo.value,
pinned: fo.pinned && { ...fo.pinned },
pinned: fo.pinned && toPinnedFilterParsed(fo.pinned),
filters: fo.filters.map(f => this.toFilterOptionParsed(f)),
frozen: false,
expanded: false,
Expand All @@ -1035,7 +1035,7 @@ export class TokenCompleter {
operation: fo.operation ?? "EqualTo",
value: fo.value,
frozen: fo.frozen || false,
pinned: fo.pinned && { ...fo.pinned },
pinned: fo.pinned && toPinnedFilterParsed(fo.pinned),
} as FilterConditionOptionParsed);
}
}
Expand Down
4 changes: 4 additions & 0 deletions Signum.React/Scripts/Globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ export function isNumber(n: any): boolean {
return !isNaN(parseFloat(n)) && isFinite(n);
}

export function softCast<T>(val: T): T {
return val;
}


String.prototype.replaceAll = function (this: string, from: string, to: string) {
return this.split(from).join(to)
Expand Down

0 comments on commit f748754

Please sign in to comment.