Skip to content

Commit

Permalink
Restore caching for the EmployeeList module
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-yagodin committed Jun 25, 2020
1 parent cfa55de commit 17c9eb9
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions R7.University.Employees/ViewEmployeeList.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using System;
using System.Linq;
using System.Web;
using System.Web.Caching;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
Expand Down Expand Up @@ -87,14 +88,11 @@ protected ISecurityContext SecurityContext

internal EmployeeListViewModel GetViewModel ()
{
// TODO: Restore caching
/*var cacheKey = "//r7_University/Modules/EmployeeList?TabModuleId=" + TabModuleId;
var cacheKey = "//r7_University/Modules/EmployeeList?TabModuleId=" + TabModuleId;
return DataCache.GetCachedData<EmployeeListViewModel> (
new CacheItemArgs (cacheKey, UniversityConfig.Instance.DataCacheTime, CacheItemPriority.Normal),
c => GetViewModel_Internal ()
).SetContext (ViewModelContext);
*/
return GetViewModel_Internal ().SetContext (ViewModelContext);
}

internal EmployeeListViewModel GetViewModel_Internal ()
Expand Down Expand Up @@ -130,14 +128,14 @@ internal EmployeeListViewModel GetViewModel_Internal ()
protected override void OnLoad (EventArgs e)
{
base.OnLoad (e);

try {
var now = HttpContext.Current.Timestamp;
// get employees
var employees = GetViewModel ().Employees
.Where (empl => IsEditable || (empl.IsPublished (now) && empl.Positions.Any (p => p.Division.IsPublished (now))));
// check if we have some content to display,

// check if we have some content to display,
// otherwise display a message for module editors or hide module from regular users
if (employees.IsNullOrEmpty ()) {
if (IsEditable) {
Expand Down Expand Up @@ -169,16 +167,16 @@ public ModuleActionCollection ModuleActions
var actions = new ModuleActionCollection ();

actions.Add (
GetNextActionID (),
GetNextActionID (),
LocalizeString ("AddEmployee.Action"),
ModuleActionType.AddContent,
"",
"",
UniversityIcons.Add,
Null.IsNull (Settings.DivisionID) ?
EditUrl ("EditEmployee")
// pass division_id to select division in which to add employee
: EditUrl ("division_id", Settings.DivisionID.ToString (), "EditEmployee"),
false,
false,
SecurityAccessLevel.Edit,
SecurityContext.CanAdd (typeof (EmployeeInfo)),
false
Expand Down Expand Up @@ -220,7 +218,7 @@ protected void listEmployees_ItemDataBound (object sender, System.Web.UI.WebCont
var linkEdit = (HyperLink) e.Item.FindControl ("linkEdit");
var imageEdit = (Image) e.Item.FindControl ("imageEdit");
var imagePhoto = (Image) e.Item.FindControl ("imagePhoto");
var linkDetails = (HyperLink) e.Item.FindControl ("linkDetails");
var linkDetails = (HyperLink) e.Item.FindControl ("linkDetails");
var linkFullName = (HyperLink) e.Item.FindControl ("linkFullName");
var labelAcademicDegreeAndTitle = (Label) e.Item.FindControl ("labelAcademicDegreeAndTitle");
var labelPositions = (Label) e.Item.FindControl ("labelPositions");
Expand All @@ -244,7 +242,7 @@ protected void listEmployees_ItemDataBound (object sender, System.Web.UI.WebCont
// make edit link visible in edit mode
linkEdit.Visible = IsEditable;
imageEdit.Visible = IsEditable;

// mark non-published employees, as they visible only to editors
if (!employee.IsPublished (now)) {
if (e.Item.ItemType == ListItemType.Item) {
Expand Down Expand Up @@ -282,16 +280,16 @@ protected void listEmployees_ItemDataBound (object sender, System.Web.UI.WebCont
var achievements = employee.Achievements
.Select (ea => new EmployeeAchievementViewModel (ea, ViewModelContext))
.Where (ach => ach.IsTitle);

var titles = achievements.Select (ach => UniversityFormatHelper.FormatShortTitle (ach.ShortTitle, ach.Title, ach.TitleSuffix).FirstCharToLower ());

// employee title achievements
var strTitles = FormatHelper.JoinNotNullOrEmpty (", ", titles);
if (!string.IsNullOrWhiteSpace (strTitles))
labelAcademicDegreeAndTitle.Text = "&nbsp;&ndash; " + strTitles;
else
labelAcademicDegreeAndTitle.Visible = false;

// phones
var phones = FormatHelper.JoinNotNullOrEmpty (", ", employee.Phone, employee.CellPhone);
if (!string.IsNullOrWhiteSpace (phones))
Expand All @@ -302,15 +300,15 @@ protected void listEmployees_ItemDataBound (object sender, System.Web.UI.WebCont
// email
if (!string.IsNullOrWhiteSpace (employee.Email)) {
linkEmail.NavigateUrl = "mailto:" + employee.Email;
linkEmail.Text = employee.Email;
linkEmail.Text = employee.Email;
}
else
linkEmail.Visible = false;

// secondary email
if (!string.IsNullOrWhiteSpace (employee.SecondaryEmail)) {
linkSecondaryEmail.NavigateUrl = "mailto:" + employee.SecondaryEmail;
linkSecondaryEmail.Text = employee.SecondaryEmail;
linkSecondaryEmail.Text = employee.SecondaryEmail;
}
else
linkSecondaryEmail.Visible = false;
Expand Down Expand Up @@ -338,7 +336,7 @@ protected void listEmployees_ItemDataBound (object sender, System.Web.UI.WebCont
.OrderByDescending (op => op.DivisionID == Settings.DivisionID)
.ThenByDescending (op => op.Position.Weight)
.GroupByDivision (HttpContext.Current.Timestamp, IsEditable);

// build positions value
var positionsVisible = false;
if (!gops.IsNullOrEmpty ()) {
Expand Down

0 comments on commit 17c9eb9

Please sign in to comment.