Ejemplo n.º 1
0
        public IActionResult CreateQueryView(Guid entityid)
        {
            if (entityid.Equals(Guid.Empty))
            {
                return(NotFound());
            }
            var entity = _entityFinder.FindById(entityid);

            if (entity == null)
            {
                return(NotFound());
            }
            EditQueryViewModel model = new EditQueryViewModel
            {
                SolutionId     = SolutionId.Value,
                EntityId       = entityid,
                EntityMetaData = entity,
                StateCode      = RecordState.Enabled,
                Buttons        = _ribbuttonFinder.Query(n => n
                                                        .Where(f => f.EntityId == entityid && f.StateCode == RecordState.Enabled &&
                                                               (f.ShowArea == RibbonButtonArea.ListHead || f.ShowArea == RibbonButtonArea.ListRow)))
            };

            return(View(model));
        }
Ejemplo n.º 2
0
        public IActionResult Get(Guid entityId, RibbonButtonArea?showarea)
        {
            FilterContainer <RibbonButton.Domain.RibbonButton> filter = FilterContainerBuilder.Build <RibbonButton.Domain.RibbonButton>();

            filter.And(x => x.EntityId == entityId);
            if (showarea.HasValue)
            {
                filter.And(x => x.ShowArea == showarea.Value);
            }
            var result = _ribbonButtonFinder.Query(x => x.Where(filter));

            return(JOk(result));
        }
Ejemplo n.º 3
0
        public IActionResult Dialog([FromBody] CustomButtonsDialogModel model)
        {
            FilterContainer <RibbonButton.Domain.RibbonButton> container = FilterContainerBuilder.Build <RibbonButton.Domain.RibbonButton>();

            container.And(n => n.EntityId == model.EntityId);
            if (model.ButtonArea.HasValue)
            {
                container.And(n => n.ShowArea == model.ButtonArea.Value);
            }
            var result = _ribbonButtonFinder.Query(x => x
                                                   .Where(container)
                                                   );

            model.Buttons = result;

            return(View(model));
        }
Ejemplo n.º 4
0
        public IActionResult Get(Guid entityid)
        {
            if (entityid.Equals(Guid.Empty))
            {
                return(NotFound());
            }
            var entity = _entityFinder.FindById(entityid);

            if (entity == null)
            {
                return(NotFound());
            }
            EditQueryViewModel model = new EditQueryViewModel();

            model.SolutionId     = SolutionId.Value;
            model.EntityId       = entityid;
            model.EntityMetaData = entity;
            model.IsDisabled     = false;
            model.Buttons        = _ribbuttonFinder.Query(n => n
                                                          .Where(f => f.EntityId == entityid && f.StateCode == RecordState.Enabled &&
                                                                 (f.ShowArea == RibbonButtonArea.ListHead || f.ShowArea == RibbonButtonArea.ListRow)));
            return(JOk(model));
        }
Ejemplo n.º 5
0
        public IActionResult SubGridView(EntityGridModel model)
        {
            QueryView.Domain.QueryView queryView = null;
            if (model.QueryViewId.HasValue && !model.QueryViewId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(model.QueryViewId.Value);
            }
            else if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName);
            }
            else
            {
                return(NotFound());
            }
            if (queryView == null)
            {
                return(NotFound());
            }
            if (!queryView.IsDefault && queryView.AuthorizationEnabled)
            {
                if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray()))
                {
                    return(Unauthorized());
                }
            }
            model.QueryView = queryView;
            model.EntityId  = queryView.EntityId;

            FetchDescriptor fetch = new FetchDescriptor
            {
                Page        = model.Page,
                PageSize    = model.PageSize,
                FetchConfig = queryView.FetchConfig,
                GetAll      = !model.PagingEnabled
            };

            if (model.IsSortBySeted)
            {
                QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0);
                fetch.Sort = sort;
            }
            //查询关键字
            if (model.Q.IsNotEmpty())
            {
                fetch.Keyword = model.Q;
                fetch.Field   = model.QField;
            }
            var canFetch = true;

            //filter by relationship
            if (model.RelationShipName.IsNotEmpty())
            {
                var relationship = _relationShipFinder.FindByName(model.RelationShipName);
                if (relationship != null && model.ReferencedRecordId.HasValue && !model.ReferencedRecordId.Value.Equals(Guid.Empty))
                {
                    if (model.Filter == null)
                    {
                        model.Filter = new FilterExpression();
                    }
                    var condition = new ConditionExpression(relationship.ReferencingAttributeName, ConditionOperator.Equal, model.ReferencedRecordId);
                    model.Filter.AddCondition(condition);
                }
                model.RelationShipMeta = relationship;
            }
            if (model.RelationShipName.IsNotEmpty() && (!model.ReferencedRecordId.HasValue || model.ReferencedRecordId.Value.Equals(Guid.Empty)))
            {
                //如果被引用ID为空,则不查询数据
                canFetch = false;
            }
            fetch.Filter = model.Filter;
            if (canFetch)
            {
                fetch.User = CurrentUser;
                var datas = _fetchService.Execute(fetch);
                if (model.OnlyData)
                {
                    return(Content(datas.SerializeToJson()));
                }
                model.Grid             = _gridService.Build(queryView, _fetchService.QueryResolver.EntityList, _fetchService.QueryResolver.AttributeList);
                model.EntityList       = _fetchService.QueryResolver.EntityList;
                model.AttributeList    = _fetchService.QueryResolver.AttributeList;
                model.RelationShipList = _fetchService.QueryResolver.RelationShipList;
                model.Items            = datas.Items;
                model.TotalItems       = datas.TotalItems;
            }
            else
            {
                _fetchService.GetMetaDatas(fetch);
                model.Grid             = _gridService.Build(queryView, _fetchService.QueryResolver.EntityList, _fetchService.QueryResolver.AttributeList);
                model.EntityList       = _fetchService.QueryResolver.EntityList;
                model.AttributeList    = _fetchService.QueryResolver.AttributeList;
                model.RelationShipList = _fetchService.QueryResolver.RelationShipList;
                model.Items            = new List <dynamic>();
                model.TotalItems       = 0;
            }
            var buttons = _ribbonbuttonFinder.Query(n => n
                                                    .Where(w => w.StateCode == RecordState.Enabled && w.EntityId == model.EntityId.Value &&
                                                           (w.ShowArea == RibbonButtonArea.ListHead))
                                                    .Sort(s => s.SortAscending(f => f.DisplayOrder)));

            model.RibbonButtons = buttons;
            if (model.IsSortBySeted == false)
            {
                if (_fetchService.QueryExpression.Orders.NotEmpty())
                {
                    model.SortBy        = _fetchService.QueryExpression.Orders[0].AttributeName;
                    model.SortDirection = (int)_fetchService.QueryExpression.Orders[0].OrderType;
                }
            }
            return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model));
        }
Ejemplo n.º 6
0
        public IActionResult GetViewInfo(Guid?id, Guid?entityId, string entityName)
        {
            //视图信息
            List <QueryView.Domain.QueryView> views = null;
            //字段信息
            List <Schema.Domain.Attribute> attributes = null;
            //按钮信息
            List <RibbonButton.Domain.RibbonButton> buttons = null;
            //Web资源信息
            string      webResources   = null;
            List <Guid> webResourceIds = null;

            QueryView.Domain.QueryView queryView = null;

            //查询视图信息
            if (id.HasValue && !id.Value.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(id.Value);
                if (queryView != null)
                {
                    views = new List <QueryView.Domain.QueryView>
                    {
                        queryView
                    };
                }
            }
            else if (entityId.HasValue && !entityId.Equals(Guid.Empty))
            {
                views = _queryViewFinder.QueryAuthorized(n => n.Where(f => f.EntityId == entityId && f.StateCode == RecordState.Enabled)
                                                         .Sort(s => s.SortAscending(f => f.Name)));
                if (views.NotEmpty())
                {
                    queryView = views.First(x => x.IsDefault);
                }
            }
            else if (entityName.IsNotEmpty())
            {
                views = _queryViewFinder.QueryAuthorized(n => n.Where(f => f.EntityName == entityName && f.StateCode == RecordState.Enabled)
                                                         .Sort(s => s.SortAscending(f => f.Name)));
                if (views.NotEmpty())
                {
                    queryView = views.FirstOrDefault(x => x.IsDefault);
                }
            }
            if (queryView == null)
            {
                return(NotFound());
            }
            //查询字段
            var queryExp = new QueryExpression().DeserializeFromJson(queryView.FetchConfig);

            attributes = _queryMetadataFinder.GetAttributes(queryExp);
            //查询按钮
            FilterContainer <RibbonButton.Domain.RibbonButton> buttonFilter = FilterContainerBuilder.Build <RibbonButton.Domain.RibbonButton>()
                                                                              .And(w => w.StateCode == RecordState.Enabled && w.EntityId == queryView.EntityId &&
                                                                                   (w.ShowArea == RibbonButtonArea.ListHead || w.ShowArea == RibbonButtonArea.ListRow || w.ShowArea == RibbonButtonArea.SubGrid));

            if (queryView.IsCustomButton && queryView.CustomButtons.IsNotEmpty())
            {
                List <Guid> buttonid = new List <Guid>();
                buttonid = buttonid.DeserializeFromJson(queryView.CustomButtons);
                buttonFilter.And(w => w.RibbonButtonId.In(buttonid));
            }
            buttons = _ribbonbuttonFinder.Query(n => n
                                                .Where(buttonFilter)
                                                .Sort(s => s.SortAscending(f => f.DisplayOrder)));
            //查询Web资源信息
            if (queryView.LayoutConfig.IsNotEmpty())
            {
                QueryViewLayoutConfigModel layoutConfig = new QueryViewLayoutConfigModel().DeserializeFromJson(queryView.LayoutConfig);
                if (layoutConfig != null && layoutConfig.ClientResources.NotEmpty())
                {
                    webResourceIds = layoutConfig.ClientResources;
                }
            }
            if (buttons.NotEmpty())
            {
                buttons.ForEach(x =>
                {
                    if (x.JsLibrary != null)
                    {
                        string[] arr = x.JsLibrary.Split(":");
                        if (arr.Length > 1)
                        {
                            Guid webResourceId = Guid.Empty;
                            if (Guid.TryParse(arr[1], out webResourceId))
                            {
                                if (webResourceIds == null)
                                {
                                    webResourceIds = new List <Guid>();
                                }
                                webResourceIds.Add(webResourceId);
                            }
                        }
                    }
                });
            }
            if (webResourceIds.NotEmpty())
            {
                StringBuilder content = new StringBuilder();
                var           result  = _webResourceFinder.FindByIds(webResourceIds.ToArray());
                foreach (var item in result)
                {
                    content.Append(_webResourceContentCoder.CodeDecode(item.Content));
                }
                webResources = content.ToString();
            }
            else
            {
                webResources = T["notfound_record"];
            }
            List <Guid> noneReadFields = new List <Guid>();

            //获取字段权限
            if (!CurrentUser.IsSuperAdmin && attributes.Count(n => n.AuthorizationEnabled) > 0)
            {
                var securityFields = attributes.Where(n => n.AuthorizationEnabled).Select(f => f.AttributeId)?.ToList();
                if (securityFields.NotEmpty())
                {
                    //无权限的字段
                    noneReadFields = _systemUserPermissionService.GetNoneReadFields(CurrentUser.SystemUserId, securityFields);
                }
            }
            return(JOk(new { Views = views, Attributes = attributes, Buttons = buttons, WebResources = webResources, NoneReadFields = noneReadFields }));
        }
Ejemplo n.º 7
0
        public IActionResult GridView([FromBody] EntityGridModel model)
        {
            QueryView.Domain.QueryView queryView = null;
            if (model.QueryViewId.HasValue && !model.QueryViewId.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindById(model.QueryViewId.Value);
            }
            else if (model.EntityId.HasValue && !model.EntityId.Value.Equals(Guid.Empty))
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityId.Value);
            }
            else if (model.EntityName.IsNotEmpty())
            {
                queryView = _queryViewFinder.FindEntityDefaultView(model.EntityName);
            }
            else
            {
                return(NotFound());
            }
            if (queryView == null)

            {
                return(NotFound());
            }
            if (!queryView.IsDefault && queryView.AuthorizationEnabled)
            {
                if (!_roleObjectAccessService.Exists(queryView.QueryViewId, QueryViewDefaults.ModuleName, CurrentUser.Roles.Select(n => n.RoleId).ToArray()))
                {
                    return(Unauthorized());
                }
            }
            //EntityGridModel model = new EntityGridModel();
            model.QueryView    = queryView;
            model.EntityId     = queryView.EntityId;
            model.QueryViewId  = queryView.QueryViewId;
            model.TargetFormId = queryView.TargetFormId;
            if (model.IsEnabledViewSelector)
            {
                model.QueryViews = _queryViewFinder.QueryAuthorized(n => n.Where(f => f.EntityId == model.EntityId && f.StateCode == RecordState.Enabled)
                                                                    .Sort(s => s.SortAscending(f => f.Name)));
            }
            if (!model.PageSizeBySeted && CurrentUser.UserSettings.PagingLimit > 0)
            {
                model.PageSize = CurrentUser.UserSettings.PagingLimit;
            }
            FetchDescriptor fetch = new FetchDescriptor
            {
                User        = CurrentUser,
                Page        = model.Page,
                PageSize    = model.PageSize,
                FetchConfig = queryView.FetchConfig
            };

            if (model.IsSortBySeted)
            {
                QueryColumnSortInfo sort = new QueryColumnSortInfo(model.SortBy, model.SortDirection == 0);
                fetch.Sort = sort;
            }
            fetch.Filter = model.Filter;

            if (model.Q.IsNotEmpty())
            {
                fetch.Keyword = model.Q;
                fetch.Field   = model.QField;
            }
            //buttons
            if (model.IsShowButtons)
            {
                FilterContainer <RibbonButton.Domain.RibbonButton> buttonFilter = FilterContainerBuilder.Build <RibbonButton.Domain.RibbonButton>()
                                                                                  .And(w => w.StateCode == RecordState.Enabled && w.EntityId == model.EntityId.Value &&
                                                                                       (w.ShowArea == RibbonButtonArea.ListHead || w.ShowArea == RibbonButtonArea.ListRow));
                if (model.QueryView.IsCustomButton && model.QueryView.CustomButtons.IsNotEmpty())
                {
                    List <Guid> buttonid = new List <Guid>();
                    buttonid = buttonid.DeserializeFromJson(model.QueryView.CustomButtons);
                    buttonFilter.And(w => w.RibbonButtonId.In(buttonid));
                }
                var buttons = _ribbonbuttonFinder.Query(n => n
                                                        .Where(buttonFilter)
                                                        .Sort(s => s.SortAscending(f => f.DisplayOrder)));
                model.RibbonButtons = buttons;
            }

            //var datas = _fetchService.Execute(fetch);
            _fetchDataService.GetMetaDatas(fetch);
            model.Grid             = _gridService.Build(queryView, _fetchDataService.QueryResolver.EntityList, _fetchDataService.QueryResolver.AttributeList);
            model.EntityList       = _fetchDataService.QueryResolver.EntityList;
            model.AttributeList    = _fetchDataService.QueryResolver.AttributeList;
            model.RelationShipList = _fetchDataService.QueryResolver.RelationShipList;
            //model.Items = datas.Items;
            //model.TotalItems = datas.TotalItems;
            //model.TotalPages = datas.TotalPages;
            //aggregation
            if (queryView.AggregateConfig.IsNotEmpty())
            {
                var aggFields = new List <AggregateExpressionField>().DeserializeFromJson(queryView.AggregateConfig);
                if (aggFields.NotEmpty())
                {
                    var aggExp = new AggregateExpression
                    {
                        ColumnSet       = _fetchDataService.QueryExpression.ColumnSet,
                        Criteria        = _fetchDataService.QueryExpression.Criteria,
                        EntityName      = _fetchDataService.QueryExpression.EntityName,
                        LinkEntities    = _fetchDataService.QueryExpression.LinkEntities,
                        AggregateFields = aggFields
                    };
                    var aggDatas = _aggregateService.Execute(aggExp);
                    model.AggregationData = aggDatas.NotEmpty() ? aggDatas.First() : null;
                    model.AggregateFields = aggFields;
                }
            }
            if (model.IsSortBySeted == false)
            {
                if (_fetchDataService.QueryExpression.Orders.NotEmpty())
                {
                    model.SortBy        = _fetchDataService.QueryExpression.Orders[0].AttributeName;
                    model.SortDirection = (int)_fetchDataService.QueryExpression.Orders[0].OrderType;
                }
            }
            //字段权限
            model.NonePermissionFields = _fetchDataService.NonePermissionFields;

            return(View($"~/Views/Entity/{WebContext.ActionName}.cshtml", model));
        }