Exemplo n.º 1
0
 public ContextualOperationContext(SelectedItemsMenuContext ctx, OperationInfo info, ContextualOperationSettings <T> settings, EntityOperationSettings <T> entityOperationSettings)
 {
     this.Context                 = ctx;
     this.OperationInfo           = info;
     this.OperationSettings       = settings;
     this.Entities                = Context.Lites.Cast <Lite <T> >().ToList();
     this.EntityOperationSettings = entityOperationSettings;
 }
Exemplo n.º 2
0
        public virtual MenuItemBlock ContextualItemsHelper_GetEntityOperationMenuItem(SelectedItemsMenuContext ctx)
        {
            if (ctx.Lites.IsNullOrEmpty())
            {
                return(null);
            }

            if (ctx.Implementations.IsByAll)
            {
                return(null);
            }

            var type = ctx.Lites.Select(a => a.EntityType).Distinct().Only();

            if (type == null)
            {
                return(null);
            }

            var context = (from oi in OperationInfos(type)
                           where oi.IsEntityOperation
                           let os = GetSettings <EntityOperationSettingsBase>(type, oi.OperationSymbol)
                                    let osc = os == null ? null :
                                              ctx.Lites.Count == 1 ? os.ContextualUntyped: os.ContextualFromManyUntyped
                                              let coc = newContextualOperationContext.GetInvoker(os?.OverridenType ?? type)(ctx, oi, osc, os)
                                                        let defaultBehaviour = oi.Lite == true && (ctx.Lites.Count == 1 || oi.OperationType != OperationType.ConstructorFrom)
                                                                               where os == null ? defaultBehaviour :
                                                                               !os.ContextualUntyped.HasIsVisible ? defaultBehaviour && !os.HasIsVisible && (!os.HasClick || os.ContextualUntyped.HasClick) :
                                                                               os.ContextualUntyped.OnIsVisible(coc)
                                                                               select coc).ToList();

            if (context.IsEmpty())
            {
                return(null);
            }

            if (ctx.Lites.Count == 1)
            {
                if (context.Any(eomi => eomi.OperationInfo.HasCanExecute == true))
                {
                    Dictionary <OperationSymbol, string> canExecutes = OperationLogic.ServiceCanExecute(Database.Retrieve(ctx.Lites.Single()));
                    foreach (var coc in context)
                    {
                        var ce = canExecutes.TryGetC(coc.OperationInfo.OperationSymbol);
                        if (ce != null)
                        {
                            coc.CanExecute = ce;
                        }
                    }
                }
            }
            else
            {
                var cleanKeys = context.Where(cod => cod.CanExecute == null && cod.OperationInfo.HasStates == true)
                                .Select(kvp => kvp.OperationInfo.OperationSymbol).ToList();

                if (cleanKeys.Any())
                {
                    Dictionary <OperationSymbol, string> canExecutes = OperationLogic.GetContextualCanExecute(ctx.Lites, cleanKeys);
                    foreach (var cod in context)
                    {
                        var ce = canExecutes.TryGetC(cod.OperationInfo.OperationSymbol);
                        if (ce.HasText())
                        {
                            cod.CanExecute = ce;
                        }
                    }
                }
            }

            List <IMenuItem> menuItems = context
                                         .Where(coc => !coc.HideOnCanExecute || coc.CanExecute == null)
                                         .Select(coc => CreateContextual(coc, DefaultEntityClick))
                                         .OrderBy(a => a.Order).Cast <IMenuItem>().ToList();

            if (menuItems.IsEmpty())
            {
                return(null);
            }

            return(new MenuItemBlock {
                Header = SearchMessage.Operation.NiceToString(), Items = menuItems
            });
        }
Exemplo n.º 3
0
        public virtual MenuItemBlock ContextualItemsHelper_GetConstructorFromManyMenuItems(SelectedItemsMenuContext ctx)
        {
            if (ctx.Lites.IsNullOrEmpty())
            {
                return(null);
            }

            var type = ctx.Lites.Select(a => a.EntityType).Distinct().Only();

            if (type == null)
            {
                return(null);
            }

            List <IMenuItem> menuItems =
                (from oi in OperationInfos(type)
                 where oi.OperationType == OperationType.ConstructorFromMany
                 let os = GetSettings <ContextualOperationSettingsBase>(type, oi.OperationSymbol)
                          let coc = newContextualOperationContext.GetInvoker(os?.OverridenType ?? oi.BaseType)(ctx, oi, os, null)
                                    where os == null || !os.HasIsVisible || os.OnIsVisible(coc)
                                    select CreateContextual(coc, _coc => JsModule.Operations["constructFromManyDefault"](_coc.Options(), JsFunction.Event)))
                .OrderBy(a => a.Order)
                .Cast <IMenuItem>()
                .ToList();

            if (menuItems.IsEmpty())
            {
                return(null);
            }

            return(new MenuItemBlock {
                Header = SearchMessage.Create.NiceToString(), Items = menuItems
            });
        }