如何在果园中添加新的票证摘要?

时间:2016-08-02 06:07:21

标签: orchardcms

我创建了一个故障单仪表板,在我使用管理员帐户登录后,它将显示两个故障单摘要。一个是"您的门票摘要"和其他"所有门票摘要"。现在,我计划让我的管理员帐户查看其他帐户的故障单摘要(例如this),但我不知道如何将其添加到故障单仪表板上有人告诉我该怎么做?

1 个答案:

答案 0 :(得分:1)

我猜你在上一篇文章中也提到了这个问题!但无论如何,

有几种方法可以做到这一点。 Orchard Collaboration使用窗口小部件来表示Ticket Summaries(用户和管理员)。主要逻辑在Modules / Orchard.CRM.Core / Drivers的DashboardDriver中。

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
                ));
    }

您需要创建一个类似于该窗口小部件的新窗口小部件。 DashboardDriver表示已登录用户的票证以及所有票证的摘要。在新窗口小部件中,您只能表示用户的摘要票证。新窗口小部件必须具有UserId属性,并表示该用户的票证摘要,而不是已登录用户。像这样:

       private DriverResult DisplayDetail(NewUserDashboardPart 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 = NewUserDashboardPart.UserId;
        dynamic state = new JObject();

        // Query the counts of the current user tickets group by stateId
        // *******************************************************
             // 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();
            //*******************************************************

        // 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
                ));
    }