예제 #1
0
        public override object GetValue(TemplateParameters p)
        {
            var entity   = (Lite <Entity>)p.Rows.DistinctSingle(p.Columns[EntityToken]);
            var fallback = (string)p.Rows.DistinctSingle(p.Columns[ParsedToken.QueryToken]);

            return(entity == null ? null : TranslatedInstanceLogic.TranslatedField(entity, Route, fallback));
        }
예제 #2
0
        public static List <Lite <DashboardEntity> > Autocomplete(string subString, int limit)
        {
            var isAllowed = Schema.Current.GetInMemoryFilter <DashboardEntity>(userInterface: false);

            return(Dashboards.Value.Values
                   .Where(d => d.EntityType == null && isAllowed(d))
                   .Select(d => d.ToLite(TranslatedInstanceLogic.TranslatedField(d, d => d.DisplayName)))
                   .Autocomplete(subString, limit).ToList());
        }
예제 #3
0
        public static List <Lite <UserQueryEntity> > GetUserQueriesEntity(Type entityType)
        {
            var isAllowed = Schema.Current.GetInMemoryFilter <UserQueryEntity>(userInterface: false);

            return(UserQueriesByTypeForQuickLinks.Value.TryGetC(entityType).EmptyIfNull()
                   .Select(lite => UserQueries.Value.GetOrThrow(lite))
                   .Where(uq => isAllowed(uq))
                   .Select(uq => uq.ToLite(TranslatedInstanceLogic.TranslatedField(uq, d => d.DisplayName)))
                   .ToList());
        }
예제 #4
0
        public static List <Lite <UserQueryEntity> > GetUserQueries(object queryName, bool appendFilterOnly = false)
        {
            var isAllowed = Schema.Current.GetInMemoryFilter <UserQueryEntity>(userInterface: false);

            return(UserQueriesByQuery.Value.TryGetC(queryName).EmptyIfNull()
                   .Select(lite => UserQueries.Value.GetOrThrow(lite))
                   .Where(uq => isAllowed(uq) && (!appendFilterOnly || uq.AppendFilters))
                   .Select(d => d.ToLite(TranslatedInstanceLogic.TranslatedField(d, d => d.DisplayName)))
                   .ToList());
        }
예제 #5
0
    public static List <Lite <UserChartEntity> > GetUserCharts(object queryName)
    {
        var isAllowed = Schema.Current.GetInMemoryFilter <UserChartEntity>(userInterface: false);

        return(UserChartsByQuery.Value.TryGetC(queryName).EmptyIfNull()
               .Select(lite => UserCharts.Value.GetOrThrow(lite))
               .Where(uc => isAllowed(uc))
               .Select(uc => uc.ToLite(TranslatedInstanceLogic.TranslatedField(uc, d => d.DisplayName)))
               .ToList());
    }
예제 #6
0
 public List <CategoryWithProducts> Catalog()
 {
     return(ProductLogic.ActiveProducts.Value.Select(a => new CategoryWithProducts
     {
         Category = a.Key.ToLite(),
         Picture = a.Key.Picture?.BinaryFile,
         LocCategoryName = TranslatedInstanceLogic.TranslatedField(a.Key.ToLite(), prCategoryName, null, a.Key.CategoryName),
         LocDescription = TranslatedInstanceLogic.TranslatedField(a.Key.ToLite(), prDescription, null, a.Key.Description),
         Products = a.Value
     }).ToList());
 }
예제 #7
0
        public static List <Lite <DashboardEntity> > GetDashboardsEntity(Type entityType)
        {
            var isAllowed = Schema.Current.GetInMemoryFilter <DashboardEntity>(userInterface: false);

            return(DashboardsByType.Value.TryGetC(entityType)
                   .EmptyIfNull()
                   .Select(lite => Dashboards.Value.GetOrThrow(lite))
                   .Where(d => isAllowed(d))
                   .Select(d => d.ToLite(TranslatedInstanceLogic.TranslatedField(d, d => d.DisplayName)))
                   .ToList());
        }
예제 #8
0
        public static ToolbarResponse?GetCurrentToolbarResponse(ToolbarLocation location)
        {
            var curr = GetCurrent(location);

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

            var responses = ToResponseList(TranslatedInstanceLogic.TranslatedMList(curr, c => c.Elements).ToList());

            if (responses.Count == 0)
            {
                return(null);
            }

            return(new ToolbarResponse
            {
                type = ToolbarElementType.Header,
                content = curr.ToLite(),
                label = TranslatedInstanceLogic.TranslatedField(curr, a => a.Name),
                elements = responses,
            });
        }
예제 #9
0
        public static void Start(SchemaBuilder sb)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                sb.Include <ToolbarEntity>()
                .WithSave(ToolbarOperation.Save)
                .WithDelete(ToolbarOperation.Delete)
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name,
                    e.Owner,
                    e.Priority
                });

                sb.Include <ToolbarMenuEntity>()
                .WithSave(ToolbarMenuOperation.Save)
                .WithDelete(ToolbarMenuOperation.Delete)
                .WithQuery(() => e => new
                {
                    Entity = e,
                    e.Id,
                    e.Name
                });

                UserAssetsImporter.Register <ToolbarEntity>("Toolbar", ToolbarOperation.Save);
                UserAssetsImporter.Register <ToolbarMenuEntity>("ToolbarMenu", ToolbarMenuOperation.Save);

                RegisterDelete <UserQueryEntity>(sb);
                RegisterDelete <UserChartEntity>(sb);
                RegisterDelete <QueryEntity>(sb);
                RegisterDelete <DashboardEntity>(sb);
                RegisterDelete <ToolbarMenuEntity>(sb);
                RegisterDelete <WorkflowEntity>(sb);

                RegisterContentConfig <ToolbarMenuEntity>(
                    lite => true,
                    lite => TranslatedInstanceLogic.TranslatedField(ToolbarMenus.Value.GetOrCreate(lite), a => a.Name));

                RegisterContentConfig <UserQueryEntity>(
                    lite => { var uq = UserQueryLogic.UserQueries.Value.GetOrCreate(lite); return(InMemoryFilter(uq) && QueryLogic.Queries.QueryAllowed(uq.Query.ToQueryName(), true)); },
                    lite => TranslatedInstanceLogic.TranslatedField(UserQueryLogic.UserQueries.Value.GetOrCreate(lite), a => a.DisplayName));

                RegisterContentConfig <UserChartEntity>(
                    lite => { var uc = UserChartLogic.UserCharts.Value.GetOrCreate(lite); return(InMemoryFilter(uc) && QueryLogic.Queries.QueryAllowed(uc.Query.ToQueryName(), true)); },
                    lite => TranslatedInstanceLogic.TranslatedField(UserChartLogic.UserCharts.Value.GetOrCreate(lite), a => a.DisplayName));

                RegisterContentConfig <QueryEntity>(
                    lite => IsQueryAllowed(lite),
                    lite => QueryUtils.GetNiceName(QueryLogic.QueryNames.GetOrThrow(lite.ToString() !)));

                RegisterContentConfig <DashboardEntity>(
                    lite => InMemoryFilter(DashboardLogic.Dashboards.Value.GetOrCreate(lite)),
                    lite => TranslatedInstanceLogic.TranslatedField(DashboardLogic.Dashboards.Value.GetOrCreate(lite), a => a.DisplayName));

                RegisterContentConfig <PermissionSymbol>(
                    lite => PermissionAuthLogic.IsAuthorized(SymbolLogic <PermissionSymbol> .ToSymbol(lite.ToString() !)),
                    lite => SymbolLogic <PermissionSymbol> .ToSymbol(lite.ToString() !).NiceToString());

                RegisterContentConfig <WorkflowEntity>(
                    lite => { var wf = WorkflowLogic.WorkflowGraphLazy.Value.GetOrCreate(lite); return(InMemoryFilter(wf.Workflow) && wf.IsStartCurrentUser()); },
                    lite => TranslatedInstanceLogic.TranslatedField(WorkflowLogic.WorkflowGraphLazy.Value.GetOrCreate(lite).Workflow, a => a.Name));



                //    { typeof(QueryEntity), a => IsQueryAllowed((Lite<QueryEntity>)a) },
                //{ typeof(PermissionSymbol), a => PermissionAuthLogic.IsAuthorized((PermissionSymbol)a.RetrieveAndRemember()) },
                //{ typeof(UserQueryEntity), a => ,
                //{ typeof(UserChartEntity), a => { var uc = UserChartLogic.UserCharts.Value.GetOrCreate((Lite<UserChartEntity>)a); return InMemoryFilter(uc) && QueryLogic.Queries.QueryAllowed(uc.Query.ToQueryName(), true); } },
                //{ typeof(DashboardEntity), a => InMemoryFilter(DashboardLogic.Dashboards.Value.GetOrCreate((Lite<DashboardEntity>)a)) },
                //{ typeof(WorkflowEntity), a => { var wf = WorkflowLogic.WorkflowGraphLazy.Value.GetOrCreate((Lite<WorkflowEntity>)a); return InMemoryFilter(wf.Workflow) && wf.IsStartCurrentUser(); } },


                Toolbars = sb.GlobalLazy(() => Database.Query <ToolbarEntity>().ToDictionary(a => a.ToLite()),
                                         new InvalidateWith(typeof(ToolbarEntity)));

                ToolbarMenus = sb.GlobalLazy(() => Database.Query <ToolbarMenuEntity>().ToDictionary(a => a.ToLite()),
                                             new InvalidateWith(typeof(ToolbarMenuEntity)));
            }
        }
예제 #10
0
    public static void Start(IApplicationBuilder app, params ITranslator[] translators)
    {
        Translators = translators;

        SignumControllerFactory.RegisterArea(MethodInfo.GetCurrentMethod());

        ReflectionServer.RegisterLike(typeof(TranslationMessage), () => TranslationPermission.TranslateCode.IsAuthorized() || TranslationPermission.TranslateInstances.IsAuthorized());

        ReflectionServer.PropertyRouteExtension += (mi, pr) =>
        {
            var type = TranslatedInstanceLogic.TranslateableRoutes.TryGetC(pr.RootType)?.TryGetS(pr);
            if (type != null)
            {
                mi.Extension.Add("translatable", true);
            }
            return(mi);
        };

        var pairs = TranslatedInstanceLogic.TranslateableRoutes.Values.SelectMany(a => a.Keys)
                    .Select(pr => (type: pr.Parent !.Type, prop: pr.PropertyInfo !))
                    .Distinct()
                    .ToList();

        foreach (var(type, prop) in pairs)
        {
            var converters = SignumServer.WebEntityJsonConverterFactory.GetPropertyConverters(type);

            converters.Add(prop.Name.FirstLower() + "_translated", new PropertyConverter()
            {
                AvoidValidate          = true,
                CustomReadJsonProperty = (ref Utf8JsonReader reader, ReadJsonPropertyContext ctx) =>
                {
                    var pr = ctx.ParentPropertyRoute.Add(prop);

                    if (TranslatedInstanceLogic.RouteType(pr) == null)
                    {
                        return;
                    }

                    var discard = reader.GetString();
                },
                CustomWriteJsonProperty = (Utf8JsonWriter writer, WriteJsonPropertyContext ctx) =>
                {
                    var pr = ctx.ParentPropertyRoute.Add(prop);

                    if (TranslatedInstanceLogic.RouteType(pr) == null)
                    {
                        return;
                    }

                    var hastMList = pr.GetMListItemsRoute() != null;

                    var entity = ctx.Entity as Entity ?? (Entity?)EntityJsonContext.FindCurrentRootEntity();

                    var rowId = hastMList ? EntityJsonContext.FindCurrentRowId() : null;

                    writer.WritePropertyName(ctx.LowerCaseName);

                    var value = entity == null || entity.IsNew || hastMList && rowId == null /*UserQuery apply changes*/ ? null :
                                TranslatedInstanceLogic.TranslatedField(entity.ToLite(), pr, rowId, null !);

                    writer.WriteStringValue(value);
                }
            });