Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rh/supervisor view #1347

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Keas.Mvc/Controllers/ReportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace Keas.Mvc.Controllers
{
[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public class ReportController : SuperController
{
private readonly ApplicationDbContext _context;
Expand All @@ -35,6 +34,7 @@ public async Task<ActionResult> Index()
return View(model);
}

[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<ActionResult> PersonActions(DateTime? startDate, DateTime? endDate)
{
var team = await _context.Teams.SingleAsync(a => a.Slug == Team);
Expand Down Expand Up @@ -64,13 +64,14 @@ public async Task<ActionResult> PersonActions(DateTime? startDate, DateTime? end
return View(model);
}

[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<ActionResult> ExpiringItems(DateTime? expiresBefore = null, string showType = "All")
{
var model = await _reportService.ExpiringItems(null, Team, expiresBefore, showType);
return View(model);
}


[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<ActionResult> SupervisorDirectReports(int personID = 0)
{
var model = await SupervisorReportViewModel.Create(_context, Team, personID);
Expand Down Expand Up @@ -132,6 +133,7 @@ public async Task<IActionResult> PersonTeamList(int personId)
}


[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<IActionResult> UnAcceptedItems(string showType = "All")
{
var userRoles = await _securityService.GetUserRoleNamesInTeamOrAdmin(Team);
Expand All @@ -140,6 +142,7 @@ public async Task<IActionResult> UnAcceptedItems(string showType = "All")

}

[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<IActionResult> KeyValues()
{
var model = await KeyValueReportViewModel.Create(_context, Team);
Expand Down Expand Up @@ -187,11 +190,13 @@ public async Task<IActionResult> EquipmentHistoryReport(int id)
return View(await _reportService.EquipmentHistory(null, Team, id)) ;
}

[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<IActionResult> PersonEquipmentHistoryReport(int id)
{
return View(await _reportService.PersonEquipmentHistory(null, Team, id));
}

[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<IActionResult> AccessReport()
{
var accessList = await _reportService.AccessList(null, Team);
Expand Down Expand Up @@ -238,6 +243,7 @@ public async Task<IActionResult> CompletedDocuments(DateTime? start = null, Date
return View(model);
}

[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<IActionResult> PeopleInTeam(bool hideInactive = true)
{
var team = await _context.Teams.SingleAsync(a => a.Slug == Team);
Expand All @@ -256,6 +262,7 @@ public async Task<IActionResult> PeopleInTeam(bool hideInactive = true)
return View(model);
}

[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<IActionResult> PeopleLeavingWithAssets()
{
var theDate = DateTime.UtcNow.AddDays(30).Date;
Expand All @@ -265,6 +272,7 @@ public async Task<IActionResult> PeopleLeavingWithAssets()
return View(peopleQuery);
}

[Authorize(Policy = AccessCodes.Codes.AnyRole)]
public async Task<IActionResult> InActiveSpaces()
{
var spaceQuery = await _reportService.InactiveSpaces(Team);
Expand Down
64 changes: 64 additions & 0 deletions Keas.Mvc/Controllers/SupervisorController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using Keas.Core.Data;
using Keas.Mvc.Models;
using Keas.Mvc.Services;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Keas.Core.Helper;
using Microsoft.AspNetCore.Authorization;

namespace Keas.Mvc.Controllers
{
[Authorize]
public class SupervisorController : SuperController
{
private readonly ApplicationDbContext _context;
private readonly ISecurityService _securityService;
private readonly ITeamsManager _teamsManager;


public SupervisorController(ApplicationDbContext context, ISecurityService _securityService, IEventService _eventService, ITeamsManager teamsManager)
{
_context = context;
this._securityService = _securityService;
_teamsManager = teamsManager;
}

public IActionResult RefreshPermissions()
{
_teamsManager.ClearTeams();
return RedirectToAction("SelectTeam");
}

public async Task<IActionResult> MyStaff()
{
var person = await _securityService.GetPerson(Team);
if(person == null){
Message = "You are not yet added to the system.";
return RedirectToAction("NoAccess","Home");
}
var viewmodel = await MyStaffListModel.Create(_context, person);

return View(viewmodel);
}

public async Task<IActionResult> StaffStuff(int id) // id of staff being viewed
{
var supervisor = await _securityService.GetPerson(Team);
if(supervisor == null){
Message = "You are not yet added to the system.";
return RedirectToAction("NoAccess","Home");
}
var underling = await _context.People.Include(p=> p.Team).FirstOrDefaultAsync(p=> p.Id==id && p.SupervisorId == supervisor.Id);
if(underling == null){
return RedirectToAction("AccessDenied","Account"); // is this the best way to do this? -river
}
var viewmodel = await MyStaffListItem.Create(_context, underling);

return View(viewmodel);
}

}
}
80 changes: 80 additions & 0 deletions Keas.Mvc/Models/MyStaffListModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System.Collections.Generic;
using Keas.Core.Data;
using Keas.Core.Domain;
using System.Linq;
using System.Threading.Tasks;
using Keas.Mvc.Services;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq.Expressions;

namespace Keas.Mvc.Models
{
public class MyStaffListModel
{
public List<Person> People { get; set; }

public static async Task<MyStaffListModel> Create(ApplicationDbContext context, Person person)
{
var viewModel = new MyStaffListModel
{
People = await context.People.Where(p => p.TeamId == person.TeamId && p.Active && p.SupervisorId == person.Id)
.Include(p => p.Team)
.OrderBy(p => p.LastName).ThenBy(p => p.FirstName)
.AsNoTracking().ToListAsync()
};
return viewModel;
}

}

public class MyStaffListItem
{
public Person Person { get; set;}
public List<KeySerial> KeySerials { get; set; }
public List<Equipment> Equipment { get; set; }
public List<Access> Access { get; set; }
public List<Workstation> Workstations { get; set; }
public List<Document> Documents { get; set; }
public Func<string, string> DocumentUrlResolver { get; set; }
public List<History> Histories { get; set; }
public bool PendingItems { get; set; }
public IEnumerable<Team> TeamsWithPendingAssignments { get; set; }


public static async Task<MyStaffListItem> Create(ApplicationDbContext context, Person person)
{
var viewModel = new MyStaffListItem
{
Person = person,
KeySerials = await context.KeySerials.Include(s=> s.Key).ThenInclude(k=> k.KeyXSpaces).ThenInclude(kxp=> kxp.Space).Include(s=> s.KeySerialAssignment)
.Where(s=> s.KeySerialAssignment.Person==person).AsNoTracking().ToListAsync(),
Equipment = await context.Equipment.Include(e => e.Space).Include(e=> e.Assignment).Where(e => e.Assignment.Person == person).AsNoTracking().ToListAsync(),
Access = await context.Access
.Where(x => x.Active && x.Assignments.Any(y => y.Person == person))
.Select(a => new Access()
{
Id = a.Id,
Name = a.Name,
Assignments = a.Assignments.Where(b => b.Person == person).Select(
c => new AccessAssignment()
{
AccessId = c.AccessId,
ExpiresAt = c.ExpiresAt,
Id = c.Id
}
).ToList()
})
.AsNoTracking().ToListAsync(),
Workstations = await context.Workstations.Include(w=> w.Assignment).Include(w=> w.Space).Where(w=> w.Assignment.Person==person).AsNoTracking().ToListAsync(),
Documents = await context.Documents.Where(d => d.Person == person).AsNoTracking().ToListAsync(),
Histories = await context.Histories.Where(x => x.Target == person)
.OrderByDescending(x => x.ActedDate)
.Take(10).AsNoTracking().ToListAsync()
};

return viewModel;
}

}
}
12 changes: 11 additions & 1 deletion Keas.Mvc/Views/Confirm/MyStuff.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@
</div>
</div>
<div class="card-content">
<div class="card people-color">
<div class="card-header-people">
<div class="card-head">
<h2><i class="fas fa-key fa-xs"></i> People</h2>
</div>
</div>
<div class="card-content">
<a asp-action="MyStaff" asp-controller="Supervisor">View All People You Supervise</a>
</div>
</div>
<div class="card keys-color">
<div class="card-header-keys">
<div class="card-head">
Expand Down Expand Up @@ -207,7 +217,7 @@
<td><a href="@Model.DocumentUrlResolver(document.EnvelopeId)" target="_blank">View</a></td>
</tr>
}
@if(!Model.Workstations.Any()){
@if(!Model.Documents.Any()){
<tr>
<td colspan="4">You have no documents assigned.</td>
</tr>
Expand Down
49 changes: 34 additions & 15 deletions Keas.Mvc/Views/Report/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
</ul>
</div>
}
@if (Model.Contains(Role.Codes.KeyMaster) || Model.Contains(Role.Codes.EquipmentMaster) || Model.Contains(Role.Codes.AccessMaster) // basically Codes.AnyRole
|| Model.Contains(Role.Codes.SpaceMaster) || Model.Contains(Role.Codes.DocumentMaster) || Model.Contains(Role.Codes.Admin) || Model.Contains(Role.Codes.PersonManager))
{
<div class="report-list people-color col-md-3">
<h3><i class="fas fa-users fa-xs"></i> People Reports</h3>
<ul>
Expand All @@ -54,6 +57,7 @@
}
</ul>
</div>
}
@if (Model.Contains(Role.Codes.SpaceMaster) || Model.Contains(Role.Codes.DepartmentalAdmin))
{
<div class="report-list spaces-color col-md-3">
Expand Down Expand Up @@ -108,22 +112,37 @@
</ul>
</div>
}
<div class="report-list general-color col-md-3">
<h3><i class="fas fa-list fa-xs"></i> General Reports</h3>
<ul>
<li>
<a asp-action="ExpiringItems">Expiring <span style="white-space: nowrap;">Items <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></span></a>
</li>
@if (Model.Contains(Role.Codes.EquipmentMaster) || Model.Contains(Role.Codes.DepartmentalAdmin) || Model.Contains(Role.Codes.KeyMaster) || Model.Contains(Role.Codes.SpaceMaster))
{
@if (Model.Contains(Role.Codes.KeyMaster) || Model.Contains(Role.Codes.EquipmentMaster) || Model.Contains(Role.Codes.AccessMaster) // basically Codes.AnyRole
|| Model.Contains(Role.Codes.SpaceMaster) || Model.Contains(Role.Codes.DocumentMaster) || Model.Contains(Role.Codes.Admin) || Model.Contains(Role.Codes.PersonManager))
{
<div class="report-list general-color col-md-3">
<h3><i class="fas fa-list fa-xs"></i> General Reports</h3>
<ul>
<li>
<a asp-action="ExpiringItems">Expiring <span style="white-space: nowrap;">Items <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></span></a>
</li>
@if (Model.Contains(Role.Codes.EquipmentMaster) || Model.Contains(Role.Codes.DepartmentalAdmin) || Model.Contains(Role.Codes.KeyMaster) || Model.Contains(Role.Codes.SpaceMaster))
{
<li>
<a asp-action="UnAcceptedItems">Items Pending <span style="white-space: nowrap;">Acceptance <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></span></a>
</li>
}
<li>
<a asp-action="InActiveSpaces">InActive Spaces With <span style="white-space: nowrap;">Assets <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></span></a>
</li>
</ul>
</div>
}
<div class="report-list general-color col-md-3">
<h3><i class="fas fa-hdd fa-xs"></i> Personal Reports</h3>
<ul>
<li>
<a asp-action="UnAcceptedItems">Items Pending <span style="white-space: nowrap;">Acceptance <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></span></a>
</li>
}
<li>
<a asp-action="InActiveSpaces">InActive Spaces With <span style="white-space: nowrap;">Assets <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></span></a>
</li>
</ul>
<a asp-action="MyStaff" asp-controller="Supervisor">View All People You<span style="white-space: nowrap;"> Supervise <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></span></a>
</li>
<li>
<a asp-action="SupervisedEquipmentReport">TODO: View All Equipment of People You<span style="white-space: nowrap;"> Supervise <i class="fas fa-chevron-right fa-sm" aria-hidden="true"></i></span></a>
</li>
</ul>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions Keas.Mvc/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
<li class='@(activeMenu == "MyStuff" ? "nav-item nav-active" : "nav-item")'>
<a class="nav-link" asp-controller="Confirm" asp-action="MyStuff">My Stuff</a>
</li>
<li class='@(activeMenu == "Report" ? "nav-item nav-active" : "nav-item")'>
<a class="nav-link" asp-controller="Report" asp-action="Index">Reports</a>
</li>
}

if ((await AuthorizationService.AuthorizeAsync(User, AccessCodes.Codes.DepartmentAdminAccess)).Succeeded || (await AuthorizationService.AuthorizeAsync(User, AccessCodes.Codes.PersonManagerAccess)).Succeeded)
Expand Down
52 changes: 52 additions & 0 deletions Keas.Mvc/Views/Supervisor/MyStaff.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@using Keas.Core.Extensions
@model Keas.Mvc.Models.MyStaffListModel

@{
ViewData["Title"] = "MyStaff";
}

<div class="card">
<div class="card-header-primary">
<div class="row justify-content-between">
<div class="card-head">
<h2>MyStaff</h2>
</div>
</div>
</div>
<div class="card-content">
<div class="card people-color">
<div class="card-header-people">
<div class="card-head">
<h2><i class="fas fa-hdd fa-xs"></i> People</h2></div>
</div>
<div class="card-content">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Stuff</th>
</tr>
</thead>
<tbody>
@foreach (var person in Model.People) {
<tr>
<td>@Html.DisplayFor(modelItem => person.NameV2)</td>
<td>@Html.DisplayFor(modelItem => person.Email)</td>
<td>
@Html.ActionLink("View", "StaffStuff", "Supervisor", new { id= @person.Id })
</td>
</tr>
}
@if(!Model.People.Any()){
<tr>
<td colspan="4">You do not supervise anyone.</td>
</tr>
}
</tbody>
</table>
</div>
</div>

</div>
</div>
Loading