Exemple #1
0
        public virtual Preset Init(IUiFasade uiFasade)
        {
            _config = uiFasade.GetViewModelConfig(OwnerMnemonic);
            IsInit = true;

            return this;
        }
        public List<EditorViewModel> GetEditors(ViewModelConfig viewModelConfig)
        {
            if (viewModelConfig == null)
            {
                return new List<EditorViewModel>();
            }

            var cache = GetCache();

            if (cache.ContainsKey(viewModelConfig.Mnemonic))
                return cache[viewModelConfig.Mnemonic];

            lock (_CacheLock)
            {
                if (!cache.ContainsKey(viewModelConfig.Mnemonic))
                {
                    var type = viewModelConfig.TypeEntity;

                    var editors = new List<EditorViewModel>();

                    editors.AddRange(type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                        .Select(x => GetEditor(viewModelConfig, x, type))
                        .Where(x => x != null));

                    cache.Add(viewModelConfig.Mnemonic, editors.OrderBy(m => m.Order).ToList());    
                }

                return cache[viewModelConfig.Mnemonic];
            }
        }
Exemple #3
0
 public DashboardWidget(ViewModelConfig config)
 {
     this.Icon = config.Icon;
     this.Mnemonic = config.Mnemonic;
     this.Title = config.With(x => x.DetailView.Title) ?? config.Title;
     this.PanelName = config.With(x => x.ListView.Name) ?? "main";
 }
        protected void Application_Start()
        {
            //AreaRegistration.RegisterAllAreas();

            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            ViewModelConfig.RegisterViewModels();
        }
        public ListBoContractResolver(string mnemonic, IUiFasade uiFasade)
        {
            _uiFasade = uiFasade;

            if (!String.IsNullOrEmpty(mnemonic))
            {
                _config = uiFasade.GetViewModelConfig(mnemonic);
                _columns = uiFasade.GetColumns(mnemonic);
            }
        }
        public BoContractResolver(string mnemonic, IUiFasade uiFasade)
        {
            _uiFasade = uiFasade;

            if (!String.IsNullOrEmpty(mnemonic))
            {
                _config = uiFasade.GetViewModelConfig(mnemonic);
                _editors = uiFasade.GetEditors(mnemonic);
            }
        }
        public MainWindowViewModel()
        {
            if (Config == null)
            {
                Config = new ViewModelConfig(this);
            }

            if (Instance == null)
            {
                Instance = this;
            }

            Init();
        }
        public MainWindowViewModel()
        {
            Helper.CheckSession();

            if (Config == null)
            {
                Config = new ViewModelConfig(this);
            }

            if (Instance == null)
            {
                Instance = this;
            }

            Init();
        }
Exemple #9
0
 public void CreateInstance()
 {
     ModelConfigurator      = new ModelConfig();
     ViewModelConfigurator  = new ViewModelConfig();
     ControllerConfigurator = new ControllerConfig();
 }
 public CommonEditorViewModel(ViewModelConfig viewModelConfig, List<EditorViewModel> editors)
 {
     ViewModelConfig = viewModelConfig;
     Editors = editors;
 }
        //Private
        private EditorViewModel GetEditor(ViewModelConfig viewModelConfig, PropertyInfo prop, Type type)
        {
            var detailViewAttr = prop.GetCustomAttribute<DetailViewAttribute>();

            var systemPropertyAttr = prop.GetCustomAttribute<SystemPropertyAttribute>();

            if (detailViewAttr == null && systemPropertyAttr != null)
            {
                detailViewAttr = new DetailViewAttribute()
                {
                    Name = prop.Name,
                    Visible = false
                };
            }

            if (detailViewAttr != null)
            {
                var maxLengthAttr = prop.GetCustomAttribute<MaxLengthAttribute>();
                var jsonIgnoreAttr = prop.GetCustomAttribute<JsonIgnoreAttribute>();

                bool hideLabel = detailViewAttr.HideLabel;

                if (!hideLabel)
                    hideLabel = String.IsNullOrEmpty(detailViewAttr.Name);

                var editor = new EditorViewModel
                {
                    Mnemonic = detailViewAttr.Mnemonic,
                    ParentViewModelConfig = viewModelConfig,
                    Title = detailViewAttr.Name ?? prop.Name,
                    Description = detailViewAttr.Description,
                    PropertyName = prop.Name,
                    PropertyType = prop.PropertyType,
                    IsLabelVisible = !hideLabel,
                    TabName = detailViewAttr.TabName ?? "[0]Основное",
                    GroupName = detailViewAttr.GroupName ?? Guid.NewGuid().ToString("N"),
                    IsReadOnly = !prop.CanWrite || detailViewAttr.ReadOnly,
                    IsRequired = detailViewAttr.Required,
                    Order = detailViewAttr.Order,
                    MaxLength = maxLengthAttr != null ? (int?)maxLengthAttr.Length : null,
                    DeferredLoading = detailViewAttr.DeferredLoading,
                    Width = detailViewAttr.Width != 0 ? (int?)detailViewAttr.Width : null,
                    Height = detailViewAttr.Height != 0 ? (int?)detailViewAttr.Height : null,
                    JsonIgnore = jsonIgnoreAttr != null,
                    IsSystemPropery = systemPropertyAttr != null,
                    Visible = detailViewAttr.Visible,
                    EditorType =
                        prop.PropertyType.IsBaseCollection()
                            ? prop.PropertyType.GetGenericType().GenericTypeArguments[0]
                            : prop.PropertyType,
                    Relationship = GetRelationship(prop.PropertyType, type),
                };

                var dataTypeAttr = prop.GetCustomAttribute<PropertyDataTypeAttribute>();

                if (dataTypeAttr == null)
                {
                    if (editor.EditorType == typeof(string) && editor.MaxLength == null)
                        editor.EditorTemplate = "MultilineText";
                    else if (editor.EditorType == typeof(int) || editor.EditorType == typeof(int?))
                        editor.EditorTemplate = "Integer";
                    else if (editor.EditorType == typeof(decimal) || editor.EditorType == typeof(decimal?))
                        editor.EditorTemplate = "Currency";
                    else if (editor.EditorType == typeof(double) || editor.EditorType == typeof(double?))
                        editor.EditorTemplate = "Double";
                    else if (editor.EditorType == typeof(DateTime) || editor.EditorType == typeof(DateTime?))
                        editor.EditorTemplate = "Date";
                    else if (editor.EditorType.IsEnum())
                        editor.EditorTemplate = "Enum";
                    else if (editor.EditorType == typeof(Period))
                        editor.EditorTemplate = "Period";
                    else if (editor.EditorType == typeof(Icon))
                        editor.EditorTemplate = "Icon";
                    else if (typeof(MultilanguageText).IsAssignableFrom(editor.EditorType))
                        editor.EditorTemplate = "Multilanguage";
                    else if (editor.EditorType == typeof(Url))
                        editor.EditorTemplate = "ComplexUrl";
                    else if (editor.EditorType == typeof(UrlMultilanguageText))
                        editor.EditorTemplate = "UrlMultilanguageText";
                    else if (editor.EditorType == typeof(LinkBaseObject))
                        editor.EditorTemplate = "LinkBaseObject";
                    else if (editor.EditorType == typeof(MultiEnum))
                        editor.EditorTemplate = "MultiEnum";
                    //else if (editor.EditorType == typeof(ValidationObjectBinding))
                    //    editor.EditorTemplate = "ValidationObjectBinding";
                    else
                    {
                        Type easyCollectionEntry =
                            prop.PropertyType.GetEntryOfUnboundedTypeOfCollection(typeof(EasyCollectionEntry<>));

                        if (easyCollectionEntry != null)
                        {
                            editor.EditorTemplate = "EasyCollection";
                            editor.ViewModelConfig = _viewModelConfigService.Get(easyCollectionEntry);
                        }
                        else
                        {
                            switch (editor.Relationship)
                            {
                                case Relationship.OneToMany:
                                    if (typeof(FileData).IsAssignableFrom(editor.EditorType))
                                        editor.EditorTemplate = "Files";
                                    else if (typeof(Base.LinkedObjects.Entities.Link).IsAssignableFrom(editor.EditorType))
                                        editor.EditorTemplate = "ListLinkedОbjects";
                                    else
                                        editor.EditorTemplate = "OneToMany";

                                    break;

                                case Relationship.ManyToMany:
                                    editor.EditorTemplate = "ManyToMany";
                                    break;

                                case Relationship.One:
                                    editor.EditorTemplate = "BaseObjectOne";
                                    break;

                                case Relationship.None:
                                    editor.EditorTemplate = editor.EditorType.Name;
                                    break;
                            }
                        }
                    }
                }
                else
                {
                    editor.EditorTemplate = dataTypeAttr.DataType != PropertyDataType.Custom
                        ? dataTypeAttr.DataType.ToString()
                        : dataTypeAttr.CustomDataType;

                    editor.EditorTemplateParams = dataTypeAttr.Params;
                }


                var configEditor = viewModelConfig.DetailView.Editors.FirstOrDefault(m => m.PropertyName == editor.PropertyName);

                if (configEditor != null)
                {
                    if (configEditor.Mnemonic != null)
                        editor.Mnemonic = configEditor.Mnemonic;

                    if (configEditor.Title != null)
                        editor.Title = configEditor.Title;

                    if (configEditor.IsLabelVisible != null)
                        editor.IsLabelVisible = configEditor.IsLabelVisible.Value;

                    if (configEditor.EditorTemplate != null)
                        editor.EditorTemplate = configEditor.EditorTemplate;

                    if (configEditor.TabName != null)
                        editor.TabName = configEditor.TabName;

                    if (configEditor.IsReadOnly != null)
                        editor.IsReadOnly = configEditor.IsReadOnly.Value;

                    if (configEditor.IsRequired != null)
                        editor.IsRequired = configEditor.IsRequired.Value;

                    if (configEditor.Order != null)
                        editor.Order = configEditor.Order.Value;

                    if (configEditor.Visible != null)
                        editor.Visible = configEditor.Visible.Value;
                }

                if (editor.ViewModelConfig == null)
                {
                    editor.ViewModelConfig = _viewModelConfigService.Get(editor.Mnemonic) ?? _viewModelConfigService.Get(editor.EditorType);

                    if (editor.ViewModelConfig == null && prop.PropertyType.IsAssignableFromBase())
                        throw new Exception(String.Format("The configuration file is not configured for type \"{0}\"", editor.EditorType.Name));
                }


                if (String.IsNullOrEmpty(editor.Mnemonic))
                    editor.Mnemonic = type.GetTypeName();

                return editor;
            }

            return null;
        }
Exemple #12
0
        public static async Task<DataSourceResult> ToDataSourceResultAsync(this IQueryable queryable, DataSourceRequest request, IBaseObjectCRUDService service, ViewModelConfig config)
        {
            var result = new DataSourceResult();

            bool execute = true;

            if (config.ListView.DataSource != null && config.ListView.DataSource.ExecuteQueryBeforeApplyClientFilter)
            {
                queryable = (await queryable.ToEnumerableAsync()).AsQueryable();
                execute = false;
            }

            var data = queryable;

            var filters = new List<IFilterDescriptor>();

            if (request.Filters != null)
            {
                KendoExtensions.PatchFilter(ref data, request.Filters);

                filters.AddRange(request.Filters);
            }

            if (filters.Any())
            {
                data = data.Where(filters);
            }

            var sort = new List<SortDescriptor>();

            if (request.Sorts != null)
            {
                sort.AddRange(request.Sorts);
            }

            var temporarySortDescriptors = new List<SortDescriptor>();

            IList<GroupDescriptor> groups = new List<GroupDescriptor>();

            if (request.Groups != null)
            {
                groups.AddRange(request.Groups);
            }

            var aggregates = new List<AggregateDescriptor>();

            if (request.Aggregates != null)
            {
                aggregates.AddRange(request.Aggregates);
            }

            if (aggregates.Any())
            {
                IQueryable source = data;

                if (filters.Any())
                {
                    source = source.Where(filters);
                }
                
                result.AggregateResults = source.Aggregate(aggregates.SelectMany(a => a.Aggregates));

                if (groups.Any() && aggregates.Any())
                {
                    groups.Each(g => g.AggregateFunctions.AddRange(aggregates.SelectMany(a => a.Aggregates)));
                }
            }

            result.Total = await data.CountAsync();

            if (groups.Any())
            {
                groups.Reverse().Each(groupDescriptor =>
                {
                    var sortDescriptor = new SortDescriptor
                    {
                        Member = groupDescriptor.Member,
                        SortDirection = groupDescriptor.SortDirection
                    };

                    sort.Insert(0, sortDescriptor);
                    temporarySortDescriptors.Add(sortDescriptor);
                });
            }

            if (sort.Any())
            {
                data = data.Sort(sort);
            }

            var notPagedData = data;

            data = data.Page(request.Page - 1, request.PageSize);

            if (groups.Any())
            {
                //TODO: 
                data = (await data.ToEnumerableAsync()).AsQueryable();
                execute = false;

                data = data.GroupBy(groups);
            }

            if (execute)
                result.Data = await data.ToEnumerableAsync();
            else
                result.Data = data;


            temporarySortDescriptors.Each(sortDescriptor => sort.Remove(sortDescriptor));

            return result;
        }
Exemple #13
0
        public List<ColumnViewModel> GetColumns(ViewModelConfig viewModelConfig)
        {
            var cache = GetCache();

            if (cache.ContainsKey(viewModelConfig.Mnemonic))
                return cache[viewModelConfig.Mnemonic];

            lock (CacheLock)
            {
                if (!cache.ContainsKey(viewModelConfig.Mnemonic))
                {
                    var type = viewModelConfig.TypeEntity;

                    var columns = new List<ColumnViewModel>();

                    foreach (
                        var prop in
                            type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                .Where(p => !p.IsDefined(typeof (JsonIgnoreAttribute), false)))
                    {
                        var listViewAttr = prop.GetCustomAttribute<ListViewAttribute>();
                        var detailViewAttr = prop.GetCustomAttribute<DetailViewAttribute>();

                        var systemPropertyAttr = prop.GetCustomAttribute<SystemPropertyAttribute>();

                        if (listViewAttr == null && systemPropertyAttr != null)
                        {
                            listViewAttr = new ListViewAttribute()
                            {
                                Name = prop.Name,
                                Hidden = true
                            };
                        }

                        if (listViewAttr != null)
                        {
                            var column = new ColumnViewModel()
                            {
                                Mnemonic = detailViewAttr.With(x => x.Mnemonic),
                                PropertyName = prop.Name,
                                PropertyInfo = prop,
                                Hidden = listViewAttr.Hidden,
                                Order = listViewAttr.Order,
                                Filterable = listViewAttr.Filterable,
                                Sortable = listViewAttr.Sortable,
                                Width = listViewAttr.Width != 0 ? (int?) listViewAttr.Width : null,
                                Height = listViewAttr.Height != 0 ? (int?) listViewAttr.Height : null,
                                IsSystemPropery = systemPropertyAttr != null,
                                Groupable = listViewAttr.Groupable,
                            };

                            var maxLengthAttr = prop.GetCustomAttribute<MaxLengthAttribute>();

                            if (maxLengthAttr != null)
                            {
                                column.MaxLength = maxLengthAttr.Length;
                            }

                            column.ColumnType = column.PropertyType.IsBaseCollection()
                                ? column.PropertyType.GetGenericType().GenericTypeArguments[0]
                                : column.PropertyType;

                            column.Title = listViewAttr.Name;

                            if (String.IsNullOrEmpty(column.Title))
                            {
                                if (detailViewAttr != null)
                                {
                                    column.Title = detailViewAttr.Name;
                                }

                                if (String.IsNullOrEmpty(column.Title))
                                {
                                    column.Title = prop.Name;
                                }
                            }

                            if (column.Order < 0 && detailViewAttr != null)
                            {
                                column.Order = detailViewAttr.Order;
                            }

                            var configColumn =
                                viewModelConfig.ListView.Columns.FirstOrDefault(
                                    m => m.PropertyName == column.PropertyName);

                            if (configColumn != null)
                            {
                                if (configColumn.Mnemonic != null)
                                    column.Mnemonic = configColumn.Mnemonic;

                                if (configColumn.Title != null)
                                    column.Title = configColumn.Title;

                                if (configColumn.Hidden.HasValue)
                                    column.Hidden = configColumn.Hidden.Value;

                                if (configColumn.Filterable.HasValue)
                                    column.Filterable = configColumn.Filterable.Value;

                                if (configColumn.Order.HasValue)
                                    column.Order = configColumn.Order.Value;

                                if (configColumn.Locked.HasValue)
                                    column.Locked = configColumn.Locked.Value;

                                if (configColumn.Lockable.HasValue)
                                    column.Lockable = configColumn.Lockable.Value;
                            }

                            column.ViewModelConfig = _viewModelConfigService.Get(column.Mnemonic) ??
                                                     _viewModelConfigService.Get(column.ColumnType);

                            if (column.ViewModelConfig == null && prop.PropertyType.IsAssignableFromBase())
                                throw new Exception(
                                    String.Format("The configuration file is not configured for type \"{0}\"",
                                        column.ColumnType.Name));

                            if (String.IsNullOrEmpty(column.Mnemonic))
                                column.Mnemonic = type.GetTypeName();

                            columns.Add(column);
                        }
                    }

                    cache.Add(viewModelConfig.Mnemonic, columns.OrderBy(m => m.Order).ToList());
                }
            }

            return cache[viewModelConfig.Mnemonic];
        }
Exemple #14
0
 public BaseObjectEditorVm(string name, PropertyInfo property, IEnumerable<ViewModelConfig> configs)
     : base(name, property)
 {
     this.Config = this.Type.TypeHierarchy().Join(configs, type => type, config => config.TypeEntity, (t, c) => c).FirstOrDefault();
 }