如何在果园中添加新的工单摘要?

How to add new ticket summary in orchard?

我已经创建了一个工单仪表板,在我使用我的管理员帐户登录后,它会显示两个工单摘要。一个是 "Your ticket summary",另一个是 "All ticket summary"。现在我打算让我的管理员帐户查看其他帐户的工单摘要(如 this),但我不知道如何将其添加到工单仪表板上,有人可以告诉我该怎么做吗?

我猜你在之前 post 中也作为评论提出了这个问题!但无论如何,

有几种方法可以做到这一点。 Orchard Collaboration 使用小部件来表示工单摘要(对于用户和管理员)。主要逻辑在 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
                ));
    }