Beispiel #1
0
        public ActionResult Execute(UI.Action action)
        {
            var searchFieldIds = action
                                 .Parameters
                                 .Where(p => p.ParameterType == ParameterType.AutoCompleteSearchFieldId)
                                 .Select(p => Convert.ToInt32(p.DefaultValue))
                                 .ToList();

            var displayFieldIds = action
                                  .Parameters
                                  .Where(p => p.ParameterType == ParameterType.AutoCompleteDisplayFieldId)
                                  .Select(p => Convert.ToInt32(p.DefaultValue))
                                  .ToList();

            var searchFields  = DbEditorService.GetFields(searchFieldIds);
            var displayFields = DbEditorService.GetFields(displayFieldIds);

            var templateName = searchFields.First().Template.Name;

            var result = DbDocumentService.GetDocuments(displayFields, searchFields, DAL.Models.OperationType.StartsWith, action.Value);

            return(new ActionResult()
            {
                ActionType = action.ActionType,
                Success = true,
                Data = result
            });
        }
Beispiel #2
0
        public ActionResult Execute(UI.Action action)
        {
            var filters = action.ViewData.Filters;

            var viewId = Convert.ToInt32(filters.First().Props["ViewId"]);

            var dalViewDef = DbEditorService.GetViewDeep(viewId);

            var viewBehaviour = BehaviourSelector.ViewBehaviours[Mapper.Map <UI.ViewType>(dalViewDef.ViewType)](CurrentUser);

            var pageNumParam       = action.Parameters.FirstOrDefault(p => p.ParameterType == ParameterType.PageNumber);
            var pageSizeParam      = action.Parameters.FirstOrDefault(p => p.ParameterType == ParameterType.PageSize);
            var sortFieldParam     = action.Parameters.FirstOrDefault(p => p.ParameterType == ParameterType.SortFieldId);
            var sortDirectionParam = action.Parameters.FirstOrDefault(p => p.ParameterType == ParameterType.SortDirection);

            bool hasPageAndSortInfo = true;

            if (string.IsNullOrEmpty(pageNumParam.DefaultValue) ||
                string.IsNullOrEmpty(pageSizeParam.DefaultValue) ||
                string.IsNullOrEmpty(sortFieldParam.DefaultValue) ||
                string.IsNullOrEmpty(sortDirectionParam.DefaultValue))
            {
                hasPageAndSortInfo = false;
            }

            DAL.Models.DbSearchRequestParams sortAndPageParams = DAL.Models.DbSearchRequestParams.GetDefault(dalViewDef);

            if (hasPageAndSortInfo)
            {
                var pageNum     = Convert.ToInt32(pageNumParam.DefaultValue);
                var pageSize    = Convert.ToInt32(pageSizeParam.DefaultValue);
                var sortFieldId = Convert.ToInt32(sortFieldParam.DefaultValue);
                var sortDir     = sortDirectionParam.DefaultValue;

                var sortField = DbEditorService.GetField(sortFieldId);

                sortAndPageParams = new DAL.Models.DbSearchRequestParams(pageNum, pageSize, sortField, sortDir);
            }


            var ticketSet = DbDocumentService.GetDocuments(dalViewDef, filters.Select(f => (IFilterWithValue)f).ToList(), sortAndPageParams);

            var viewDef = Mapper.Map <UI.ViewDefinition>(dalViewDef);
            var view    = BehaviourSelector.ViewBehaviours[Mapper.Map <UI.ViewType>(viewDef.ViewType)](CurrentUser).Make(viewDef, ticketSet, null, null);

            return(new ActionResult()
            {
                Success = true,
                ActionType = action.ActionType,
                Data = view
            });
        }
Beispiel #3
0
        public ActionResult Execute(UI.Action action)
        {
            var filterIdParameter = action.Parameters.FirstOrDefault(p => p.ParameterType == ParameterType.FilterId);
            var dbFilterDef       = DbEditorService.GetFilter(Convert.ToInt32(filterIdParameter.DefaultValue));

            if (dbFilterDef == null)
            {
                throw new CustomValidationException("Filter is not defined for this action.");
            }

            var filterDef = Mapper.Map <UI.FilterDefinition>(dbFilterDef);

            var filter = BehaviourSelector.FilterBehaviours[Mapper.Map <UI.FilterType>(filterDef.FilterType)](CurrentUser).Make(filterDef, null);

            var dbViewDef = DbEditorService.GetViewDeep(filterDef.ViewId);

            var filterValues = new Dictionary <DAL.Models.Filter, object>()
            {
                { dbFilterDef, null }
            };

            var searchParams = DAL.Models.DbSearchRequestParams.GetDefault(dbViewDef);
            var tickets      = DbDocumentService.GetDocuments(dbViewDef, new List <IFilterWithValue>()
            {
                filter
            }, searchParams);

            var viewDef = Mapper.Map <UI.ViewDefinition>(dbViewDef);
            var view    = BehaviourSelector.ViewBehaviours[Mapper.Map <UI.ViewType>(viewDef.ViewType)](CurrentUser).Make(viewDef, tickets, null, null);

            var result = new ActionResult()
            {
                Success    = true,
                ActionType = action.ActionType,
                Data       = view
            };

            return(result);
        }
Beispiel #4
0
        public View Make(ViewDefinition definition, DAL.Models.DbSearchResponse ticketSet, View parentNode, Action <UI.View> viewAction)
        {
            var view = new View()
            {
                ViewType   = Mapper.Map <UI.ViewType>(definition.ViewType),
                ParentNode = parentNode
            };

            var ticket = ticketSet.Tickets.FirstOrDefault();

            // TODO
            //view.DocId = (ticket != null) ? (int?)Convert.ToInt32(ticket["Id"]) : null;

            view.Props = new Dictionary <string, object>()
            {
                { "Name", definition.Name },
                { "TemplateId", definition.TemplateId },
                { "OrderIndex", definition.OrderIndex },
                { "DisplayName", definition.DisplayName },
                { "GridWidth", definition.GridWidth },
                { "LinkedFieldId", definition.LinkedFieldId },
                { "Active", false }
            };

            view.Controls = definition
                            .Controls
                            .Select(c => BehaviourSelector.ControlBehaviours[Mapper.Map <UI.ControlType>(c.ControlType)](CurrentUser).Make(c, ticketSet, view, null))
                            .ToList();

            view.Filters = definition
                           .Filters
                           .Select(f => BehaviourSelector.FilterBehaviours[Mapper.Map <UI.FilterType>(f.FilterType)](CurrentUser).Make(f, view))
                           .ToList();

            foreach (var childViewDef in definition.ChildViews)
            {
                View childView;

                if (childViewDef.ViewType == DAL.Models.ViewType.Table)
                {
                    var parentFilters = ticketSet.Request.Filters;

                    var searchParams = DAL.Models.DbSearchRequestParams.GetDefault((DAL.Models.View)childViewDef.Entity);
                    searchParams.SearchWithInnerJoin = true;
                    var linkedTickets = DbDocumentService.GetDocuments((DAL.Models.View)childViewDef.Entity, parentFilters, searchParams);

                    childView = BehaviourSelector.ViewBehaviours[Mapper.Map <UI.ViewType>(childViewDef.ViewType)](CurrentUser)
                                .Make(childViewDef, linkedTickets, null, null);
                }
                else
                {
                    childView = BehaviourSelector.ViewBehaviours[Mapper.Map <UI.ViewType>(childViewDef.ViewType)](CurrentUser)
                                .Make(childViewDef, ticketSet, null, null);
                }

                view.ChildViews.Add(childView);
            }

            if (definition.ChildViews.Any(cv => cv.ViewType == DAL.Models.ViewType.Tab))
            {
                var parentView = new View()
                {
                    ViewType   = ViewType.TabContainer,
                    ParentNode = parentNode
                };



                var tabViews = view.ChildViews.Where(v => v.ViewType == ViewType.Tab);

                view.ChildViews = view.ChildViews.Except(tabViews).ToList();

                view.ViewType        = ViewType.Tab;
                view.ParentNode      = parentView;
                view.Props["Active"] = true;

                parentView.DocId = view.DocId;
                parentView.Props = view.Props;

                parentView.ChildViews.AddRange((new List <View>()
                {
                    view
                }).Union(tabViews));

                return(parentView);
            }
            else
            {
                return(view);
            }
        }
Beispiel #5
0
        public ActionResult Execute(UI.Action action)
        {
            if (action.DocId == null)
            {
                throw new CustomValidationException("DocId not defined for action's parent control. Please assign Id field to control.");
            }

            var viewIdParameter = action.Parameters.FirstOrDefault(p => p.ParameterType == UI.ParameterType.ViewId);
            var anchorParameter = action.Parameters.FirstOrDefault(p => p.ParameterType == UI.ParameterType.ViewAnchor);


            var dbViewDef = DbEditorService.GetViewDeep(Convert.ToInt32(viewIdParameter.DefaultValue));
            var viewDef   = Mapper.Map <ViewDefinition>(dbViewDef);

            var fieldId = Convert.ToInt32(action.Props["FieldId"]);

            var field = DbEditorService.GetField(fieldId);

            var filter = new VirtualFilter()
            {
                Operation = DAL.Models.OperationType.EqualTo,
                ViewId    = dbViewDef.Id
            };

            filter.FilterFields = new List <IFilterField>()
            {
                new VirtualFilterField()
                {
                    ChainId = 0, Depth = 0, Filter = filter, Field = field
                }
            };

            var filterWithValue = new VirtualFilterWithValue()
            {
                Filter = filter, Value = action.DocId
            };

            var searchParams = DAL.Models.DbSearchRequestParams.GetDefault(dbViewDef);

            var ticketSet = DbDocumentService.GetDocuments(dbViewDef, new List <IFilterWithValue>()
            {
                filterWithValue
            }, searchParams);

            UI.View view;

            if (ticketSet.Tickets.Count == 1)
            {
                view = BehaviourSelector.ViewBehaviours[Mapper.Map <UI.ViewType>(dbViewDef.ViewType)](CurrentUser)
                       .Make(viewDef, ticketSet, null, null);

                var views = GetFlatListOfViews(view);

                if (anchorParameter != null && views.Count > 0)
                {
                    foreach (var v in views)
                    {
                        if (v.Props.ContainsKey("Active"))
                        {
                            v.Props["Active"] = (v.Definition?.Id == Convert.ToInt32(anchorParameter.DefaultValue));
                        }
                    }
                }
            }
            else
            {
                throw new CustomValidationException("Applying filters in goto action does not result in a single document.");
            }

            var result = new ActionResult()
            {
                Success    = true,
                ActionType = action.ActionType,
                Data       = view
            };

            return(result);
        }
Beispiel #6
0
        public ActionResult Execute(UI.Action action)
        {
            // Создаваемый шаблон
            var tempIdParam = action.Parameters.FirstOrDefault(p => p.ParameterType == UI.ParameterType.TemplateId);

            if (tempIdParam == null)
            {
                throw new CustomValidationException($"TemplateId parameter missing for action {action.Props["Id"]}.");
            }

            // Получаем модель шаблона по которой будем создавать документ
            var templateDef = DbEditorService.GetTemplate(Convert.ToInt32(tempIdParam.DefaultValue));

            // Создаем значения по умолчанию, которыми будет заполнен новый документ
            var values = templateDef.Fields
                         .Select(f => new KeyValuePair <DAL.Models.Field, object>(f, null))
                         .ToDictionary(kv => kv.Key, kv => kv.Value);

            // Проверяем есть ли параметры копирования значений в новый шаблон
            FillValues(action, templateDef, values);

            // Создаем документ шаблона и получаем его ID
            var docId = DbDocumentService.CreateDocument(values);

            // Страницу на которую мы перейдем и в которой будет созданный документ по шаблону
            var viewIdParam = action.Parameters.FirstOrDefault(p => p.ParameterType == UI.ParameterType.ViewId);

            // Проверка параметров
            if (viewIdParam != null)
            {
                // Проверяем есть ли на странице фильтр с помощью которого мы попадем на нее
                var viewDefDal   = DbEditorService.GetViewDeep(Convert.ToInt32(viewIdParam.DefaultValue));
                var filterDefDal = viewDefDal.Filters.FirstOrDefault();
                if (filterDefDal == null)
                {
                    throw new CustomValidationException($"View {viewDefDal.Id} must have a filter defined.");
                }
                // Создаем фильтр поля ID с помощью которого мы откроем страницу которая привязана к созданному документу
                // Заполняем его значением созданного документа
                var filterDef = Mapper.Map <UI.FilterDefinition>(filterDefDal);
                var filter    = BehaviourSelector.FilterBehaviours[Mapper.Map <UI.FilterType>(filterDef.FilterType)](CurrentUser).Make(filterDef, null);
                filter.Value = docId;

                // Ищем только что созданный документ по фильтру и открываем страницу с привязкой к этому документу
                var searchParams = DAL.Models.DbSearchRequestParams.GetDefault(viewDefDal);
                var ticketSet    = DbDocumentService.GetDocuments(viewDefDal, new List <DAL.Interfaces.IFilterWithValue>()
                {
                    filter
                }, searchParams);
                var viewDef = Mapper.Map <UI.ViewDefinition>(viewDefDal);
                var view    = BehaviourSelector.ViewBehaviours[Mapper.Map <UI.ViewType>(viewDef.ViewType)](CurrentUser).Make(viewDef, ticketSet, null, null);

                // Возвращаем страницу в качестве результата
                return(new ActionResult()
                {
                    ActionType = action.ActionType,
                    Data = view,
                    Success = true
                });
            }
            else
            {
                return(new ActionResult()
                {
                    ActionType = action.ActionType,
                    Success = true
                });
            }
        }