2016-08-02 42 views
1

我已經創建了票據儀表板,並且在用我的管理員帳戶登錄後會顯示兩張票據摘要。一個是「您的機票摘要」和另一個「所有機票摘要」。現在我打算讓我的管理員帳戶查看其他帳戶的票證摘要(如this),但我不知道如何將其添加到票據儀表板中,有人可以告訴我該怎麼做?如何在果園中添加新的票務摘要?

回答

1

我想你也是在上一篇文章中作爲評論提問的問題!但無論如何,

有幾種方法可以做到這一點。 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 
       )); 
    } 

您需要創建一個類似於那個的新Widget。 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 
       )); 
    }