示例#1
0
        private DriverResult DisplayDetail(DashboardPart part, dynamic shapeHelper)
        {
            if (this.services.WorkContext.CurrentUser == null)
            {
                return(null);
            }

            var contentQuery  = this.services.ContentManager.HqlQuery().ForVersion(VersionOptions.Published);
            var statusRecords = this.basicDataService.GetStatusRecords().OrderBy(c => c.OrderId).ToList();

            DashboardViewModel model = new DashboardViewModel();

            model.CurrentUserId = this.services.WorkContext.CurrentUser.Id;
            model.IsCustomer    = this.crmContentOwnershipService.IsCurrentUserCustomer();
            model.IsOperator    = this.services.Authorizer.Authorize(Permissions.OperatorPermission);
            dynamic state = new JObject();

            // Query items created by customer
            if (model.IsCustomer)
            {
                // Ticket contentType
                state.ContentTypes = "Ticket";
                contentQuery       = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, "Content", "ContentTypes", state);

                state.RequestingUser_Id = model.CurrentUserId.ToString(CultureInfo.InvariantCulture);
                contentQuery            = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, TicketFieldsFilter.CategoryName, TicketFieldsFilter.RequestingUserType, state);

                var userTicketsCountByStateIds = groupQuery.GetCount(contentQuery, "TicketPartRecord", "StatusRecord.Id");

                model.CurrentUserRequestingTickets = new Collection <dynamic>();
                CRMHelper.AddStatusGroupRecordsToModel(statusRecords, userTicketsCountByStateIds, model.CurrentUserRequestingTickets);

                // overrude items of current users
                state.MaxDueDate = DateTime.UtcNow.Date;
                contentQuery     = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, TicketFieldsFilter.CategoryName, TicketFieldsFilter.TicketDueDateType, state);
                model.CurrentUserOverrudeRequestingTicketCount = contentQuery.Count();
            }

            // Query the counts of the current user tickets group by stateId
            // *******************************************************
            if (model.IsOperator)
            {
                // Ticket contentType
                state.ContentTypes = "Ticket";
                contentQuery       = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, "Content", "ContentTypes", state);

                dynamic temp = new
                {
                    Users         = new int[] { model.CurrentUserId },
                    Teams         = new int[] { },
                    BusinessUnits = new int[] { },
                    AccessType    = ContentItemPermissionAccessTypes.Assignee
                };

                contentQuery = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, ContentItemPermissionFilter.CategoryName, ContentItemPermissionFilter.AnySelectedUserTeamBusinessUnit, temp);

                var userTicketsCountByStateIds = groupQuery.GetCount(contentQuery, "TicketPartRecord", "StatusRecord.Id");

                model.CurrentUserTickets = new Collection <dynamic>();
                CRMHelper.AddStatusGroupRecordsToModel(statusRecords, userTicketsCountByStateIds, model.CurrentUserTickets);

                // overrude items of current users
                state.MaxDueDate = DateTime.UtcNow.Date;
                contentQuery     = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, TicketFieldsFilter.CategoryName, TicketFieldsFilter.TicketDueDateType, state);
                model.CurrentUserOverrudeItemsCount = contentQuery.Count();
                //*******************************************************
            }

            bool isAdmin = this.services.Authorizer.Authorize(Permissions.AdvancedOperatorPermission);

            if (isAdmin)
            {
                // Query the counts of the whole tickets in the system based on stateId
                state = new JObject();

                contentQuery = this.services.ContentManager.HqlQuery().ForVersion(VersionOptions.Published);

                state.ContentTypes = "Ticket";
                contentQuery       = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, "Content", "ContentTypes", state);
                var ticketCountsByStateIds = groupQuery.GetCount(contentQuery, "TicketPartRecord", "StatusRecord.Id");

                model.AllTickets = new Collection <dynamic>();
                CRMHelper.AddStatusGroupRecordsToModel(statusRecords, ticketCountsByStateIds, model.AllTickets);

                state.MaxDueDate            = DateTime.UtcNow.Date;
                contentQuery                = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, TicketFieldsFilter.CategoryName, TicketFieldsFilter.TicketDueDateType, state);
                model.AllOverrudeItemsCount = contentQuery.Count();
            }

            // get items without any owner
            contentQuery       = this.services.ContentManager.HqlQuery().ForVersion(VersionOptions.Published);
            state.ContentTypes = "Ticket";
            contentQuery       = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, "Content", "ContentTypes", state);
            contentQuery       = this.projectionManagerWithDynamicSort.ApplyFilter(contentQuery, ContentItemPermissionFilter.CategoryName, "ContentItemPermissionPartRecord.ItemsWithoutAnyOwner", state);
            model.AllItemsWithoutOwnerCount = contentQuery.Count();

            // get overrude items count

            // display
            // 1) Number of your open, new, in progress, and closed tickets
            // 2) number of the unassigned, new, open, in progress and closed tickets in the system.
            return(ContentShape("Parts_Dashboard",
                                () => shapeHelper.Parts_Dashboard(
                                    Model: model
                                    )));
        }
        protected override DriverResult Display(TicketsForContentItemPart part, string displayType, dynamic shapeHelper)
        {
            if (this.crmContentOwnershipService.IsCurrentUserOperator() && displayType == "Detail")
            {
                var context = workContextAccessor.GetContext();
                var layout  = context.Layout;

                // for the ticket related pages, we don't render any menu
                if (layout.TicketRelatedPage != null && layout.TicketRelatedPage == true)
                {
                    return(null);
                }

                var settings = part.TypePartDefinition.Settings.GetModel <TicketsForContentItemPartSettings>();

                if (!settings.DoNotRenderTicketsFlipFlop)
                {
                    this.RenderFlipFlop(shapeHelper);
                }

                var statusRecords = this.basicDataService.GetStatusRecords().OrderBy(c => c.OrderId).ToList();

                var contentQuery = searchTicketService.CreateQuery(new PostedTicketSearchViewModel
                {
                    Users                = new int[] { },
                    BusinessUnits        = new int[] { },
                    RelatedContentItemId = part.ContentItem.Id,
                    IncludeAllVisibleItemsBySelectedGroupsAndUsers = true
                });

                var ticketsCountByStateIds = groupQuery.GetCount(contentQuery, "TicketPartRecord", "StatusRecord.Id");

                var ticketsCountWithLabels = new Collection <dynamic>();
                CRMHelper.AddStatusGroupRecordsToModel(statusRecords, ticketsCountByStateIds, ticketsCountWithLabels);

                // overrude items of current users
                var overrudeTicketCount = searchTicketService.CountByDatabase(new PostedTicketSearchViewModel
                {
                    Users                = new int[] { },
                    BusinessUnits        = new int[] { },
                    RelatedContentItemId = part.ContentItem.Id,
                    DueDate              = PostedTicketSearchViewModel.OverDueDate,
                    IncludeAllVisibleItemsBySelectedGroupsAndUsers = true
                });

                var unassignedTicketCount = searchTicketService.CountByDatabase(new PostedTicketSearchViewModel
                {
                    Users                = new int[] { },
                    BusinessUnits        = new int[] { },
                    RelatedContentItemId = part.ContentItem.Id,
                    Unassigned           = true
                });

                dynamic model = new ExpandoObject();
                model.TicketsGroupByStatus  = ticketsCountWithLabels;
                model.OverrudeTicketCount   = overrudeTicketCount;
                model.UnAssignedTicketCount = unassignedTicketCount;
                model.Part = part;
                return(ContentShape("Parts_TicketsForContentItem",
                                    () => shapeHelper.Parts_TicketsForContentItem(
                                        Model: model
                                        )));
            }
            else
            {
                return(null);
            }
        }