Skip to content

Commit

Permalink
SAK-29478 Added sitestats visit integration
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianfish committed Jun 29, 2015
1 parent 977ef0c commit 5676200
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,10 @@
# DEFAULT: true
# roster_view_email=false

# Whether to allow site visit data to be displayed with each member
# DEFAULT: false
# roster.showVisits=true

## SEARCH
# Elastic search is the default search as of Sakai 10
# For more information please see this confluence page
Expand Down
4 changes: 4 additions & 0 deletions roster2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
<groupId>org.sakaiproject.profile2</groupId>
<artifactId>profile2-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.sitestats</groupId>
<artifactId>sitestats-api</artifactId>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Expand Down
14 changes: 14 additions & 0 deletions roster2/src/handlebars/members.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
<div class="roster-table-cell">{{role}}</div>
</div>

{{#if ../viewSiteVisits}}
<div class="roster-table-row">
<div class="roster-table-cell">{{translate 'total_visits'}}</div>
<div class="roster-table-cell">{{totalSiteVisits}}</div>
</div>

{{#if formattedLastVisitTime}}
<div class="roster-table-row roster-last-visit-time">
<div class="roster-table-cell">{{translate 'last_visit'}}</div>
<div class="roster-table-cell roster-last-visit-time-cell">{{formattedLastVisitTime}}</div>
</div>
{{/if}}
{{/if}}

{{#if hasGroups}}
<div class="roster-table-row">
<div class="roster-table-cell">{{translate 'groups'}}</div>
Expand Down
6 changes: 6 additions & 0 deletions roster2/src/handlebars/permissions.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<td align="center"><input type="checkbox" class="roster_permission_checkbox" {{#if (roleAllowed permission='roster.viewofficialphoto')}}checked="checked"{{/if}}" id="{{name}}:roster.viewofficialphoto"/></td>
{{/each}}
</tr>
<tr>
<td align="left">viewsitevisits</td>
{{#each roles}}
<td align="center"><input type="checkbox" class="roster_permission_checkbox" {{#if (roleAllowed permission='roster.viewsitevisits')}}checked="checked"{{/if}}" id="{{name}}:roster.viewsitevisits"/></td>
{{/each}}
</tr>
<tr>
<td align="left">export</td>
{{#each roles}}
Expand Down
4 changes: 4 additions & 0 deletions roster2/src/i18n/org/sakaiproject/roster/i18n/ui.properties
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ roster_cancel_button = Cancel
groups = Groups:
pick_group_instruction = Pick a group
roles_label = Roles:
total_visits = Total Visits
last_visit = Last Visit
months = Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec
no_visits_yet = None yet
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ public interface RosterFunctions {
public static final String ROSTER_FUNCTION_VIEWPROFILE = ROSTER_FUNCTION_PREFIX + "viewprofile";
public static final String ROSTER_FUNCTION_VIEWEMAIL = ROSTER_FUNCTION_PREFIX + "viewemail";
public static final String ROSTER_FUNCTION_VIEWOFFICIALPHOTO = ROSTER_FUNCTION_PREFIX + "viewofficialphoto";
public static final String ROSTER_FUNCTION_VIEWSITEVISITS = ROSTER_FUNCTION_PREFIX + "viewsitevisits";

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public class RosterMember {
private Map<String, String> groups = new HashMap<String, String>();
@Getter @Setter
private int connectionStatus; // connection status to the current user
@Getter @Setter
private int totalSiteVisits;
@Getter @Setter
private long lastVisitTime;

public void addGroup(String groupId, String groupTitle) {

Expand Down
6 changes: 6 additions & 0 deletions roster2/src/java/org/sakaiproject/roster/api/SakaiProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

import org.sakaiproject.memory.api.Cache;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.sitestats.api.SitePresenceTotal;
import org.sakaiproject.user.api.User;


/**
* Roster interface to Sakai functionality.
*
Expand Down Expand Up @@ -218,4 +220,8 @@ public Boolean hasUserGroupPermission(String userId, String permission,
* Attempts to retrieve the search index for the specified site.
*/
public Map<String, String> getSearchIndex(String siteId);

public Map<String, SitePresenceTotal> getPresenceTotalsForSite(String siteId);

public boolean getShowVisits();
}
15 changes: 15 additions & 0 deletions roster2/src/java/org/sakaiproject/roster/impl/SakaiProxyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import org.sakaiproject.site.api.Group;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.sitestats.api.SitePresenceTotal;
import org.sakaiproject.sitestats.api.StatsManager;
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.tool.api.ToolManager;
import org.sakaiproject.user.api.User;
Expand Down Expand Up @@ -93,6 +95,7 @@ public class SakaiProxyImpl implements SakaiProxy {
private ServerConfigurationService serverConfigurationService;
private SessionManager sessionManager;
private SiteService siteService;
private StatsManager statsManager;
private ToolManager toolManager;
private UserDirectoryService userDirectoryService;
private RosterMemberComparator memberComparator;
Expand Down Expand Up @@ -133,6 +136,10 @@ public void init() {
functionManager.registerFunction(RosterFunctions.ROSTER_FUNCTION_VIEWOFFICIALPHOTO, true);
}

if (!registered.contains(RosterFunctions.ROSTER_FUNCTION_VIEWSITEVISITS)) {
functionManager.registerFunction(RosterFunctions.ROSTER_FUNCTION_VIEWSITEVISITS, true);
}

memberComparator = new RosterMemberComparator(getFirstNameLastName());
}

Expand Down Expand Up @@ -1112,4 +1119,12 @@ public Map<String, String> getSearchIndex(String siteId) {
return null;
}
}

public Map<String, SitePresenceTotal> getPresenceTotalsForSite(String siteId) {
return statsManager.getPresenceTotalsForSite(siteId);
}

public boolean getShowVisits() {
return serverConfigurationService.getBoolean("roster.showVisits", false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@
import org.sakaiproject.entitybroker.exception.EntityException;
import org.sakaiproject.entitybroker.util.AbstractEntityProvider;
import org.sakaiproject.roster.api.RosterData;
import org.sakaiproject.roster.api.RosterFunctions;
import org.sakaiproject.roster.api.RosterMember;
import org.sakaiproject.roster.api.RosterMemberComparator;
import org.sakaiproject.roster.api.SakaiProxy;
import org.sakaiproject.sitestats.api.SitePresenceTotal;
import org.sakaiproject.user.api.User;

import lombok.Setter;
Expand Down Expand Up @@ -70,7 +72,7 @@ public class RosterSiteEntityProvider extends AbstractEntityProvider implements
public final static String KEY_PAGE = "page";
public final static String KEY_ENROLLMENT_SET_ID = "enrollmentSetId";
public final static String KEY_ENROLLMENT_STATUS = "enrollmentStatus";

@Setter
private SakaiProxy sakaiProxy;

Expand Down Expand Up @@ -165,9 +167,32 @@ public Object getMembership(EntityReference reference, Map<String, Object> param
data.setMembers(subList);
data.setMembersTotal(membershipsSize);

boolean showVisits = sakaiProxy.getShowVisits();

Map<String, SitePresenceTotal> sitePresenceTotals = new HashMap<String, SitePresenceTotal>();

if (showVisits) {
sitePresenceTotals = sakaiProxy.getPresenceTotalsForSite(siteId);
}

boolean viewSiteVisits
= developerHelperService.isUserAllowedInEntityReference("/user/" + userId
, RosterFunctions.ROSTER_FUNCTION_VIEWSITEVISITS
, "/site/" + siteId);

System.out.println("viewSiteVisits: " + viewSiteVisits);

Map<String, Integer> roleCounts = new HashMap<String, Integer>();

for (RosterMember member : membership) {
if (showVisits && viewSiteVisits) {
String memberUserId = member.getUserId();
if (sitePresenceTotals.containsKey(memberUserId)) {
SitePresenceTotal spt = sitePresenceTotals.get(memberUserId);
member.setTotalSiteVisits(spt.getTotalVisits());
member.setLastVisitTime(spt.getLastVisitTime().getTime());
}
}
String memberRoleId = member.getRole();
if (!roleCounts.containsKey(memberRoleId)) {
roleCounts.put(memberRoleId, 1);
Expand Down
1 change: 1 addition & 0 deletions roster2/src/webapp/WEB-INF/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<property name="serverConfigurationService"><ref bean="org.sakaiproject.component.api.ServerConfigurationService"/></property>
<property name="sessionManager"><ref bean="org.sakaiproject.tool.api.SessionManager"/></property>
<property name="siteService"><ref bean="org.sakaiproject.site.api.SiteService"/></property>
<property name="statsManager"><ref bean="org.sakaiproject.sitestats.api.StatsManager"/></property>
<property name="toolManager"><ref bean="org.sakaiproject.tool.api.ToolManager"/></property>
<property name="userDirectoryService"><ref bean="org.sakaiproject.user.api.UserDirectoryService"/></property>
</bean>
Expand Down
74 changes: 13 additions & 61 deletions roster2/src/webapp/css/roster.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
table.rosterPageHeader {
width:95%;
}
.rosterPageHeaderLeft {
vertical-align:top;
text-align:left;
}
.rosterPageHeaderRight {
vertical-align:top;
text-align:right;
}
*/

.filterLabel {
vertical-align:top;
Expand Down Expand Up @@ -72,37 +56,6 @@ table.rosterPageHeader {
padding-right:10px;
}

/*
table.rosterPicturesFilter {
width:20em;
}
table.rosterPictures {
width:20em;
}
table.rosterPictures td {
width:160px;
height:15em;
vertical-align:top;
word-break:break-all;
word-wrap:break-word;
padding-bottom:1em;
}
table.rosterPicturesSingleColumn {
width:320px;
}
table.rosterPicturesSingleColumn td {
width:160px;
vertical-align:top;
padding-bottom:1em;
word-break:break-all;
word-wrap:break-word;
}
*/

.rosterPicture {
border:1px solid #bbb;
width:expression(160 + "px"); /* used for IE */
Expand All @@ -122,18 +75,6 @@ table.rosterPicturesSingleColumn td {
background-image: url(/library/image/silk/email.png);
}

/* mouse-over actions on tables */

/*
.rosterTableRow {
background-color:#FFFFFF;
}
.rosterTableRowHighlight {
background-color:#FFFFC0;
}
*/

@media print { .noprint { display: none; } }

#roster_type_selector {
Expand Down Expand Up @@ -227,10 +168,14 @@ table.rosterPicturesSingleColumn td {
padding-right: 10px;
}

.roster-last-visit-time-cell {
font-size: 0.8em;
}

/* Table display for large screen sizes */
@media only screen and (min-width: 800px) and (max-width: 1100px) {
.roster-member {
font-size: 0.85em;
font-size: 0.75em;
}
.roster-groups-selector {
max-width: 100px !important;
Expand Down Expand Up @@ -292,12 +237,13 @@ table.rosterPicturesSingleColumn td {

.roster-table-row {
display: inline-block;
width: 15%;
width: 9%;
}

.roster-table-cell {
display: inline-block;
vertical-align: middle;
font-size: 0.8em;
}

.roster-table-cell:first-child {
Expand All @@ -313,4 +259,10 @@ table.rosterPicturesSingleColumn td {
padding: 0px;
max-width: 200px;
}
.roster-last-visit-time {
width: 12%;
}
.roster-last-visit-time-cell {
font-size: 0.7em;
}
}
26 changes: 26 additions & 0 deletions roster2/src/webapp/js/roster.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@
});

roster.i18n = $.i18n.map;

roster.i18n.months = roster.i18n.months.split(',');

/*
roster.monthMappings = {};
roster.i18n.months.forEach(function (m, i) {
roster.monthMappings[m] = i + 1;
});
*/

roster.ADMIN = 'admin';

Expand Down Expand Up @@ -406,6 +415,12 @@
}

m.enrollmentStatusText = roster.site.enrollmentStatusCodes[m.enrollmentStatusId];

if (m.totalSiteVisits > 0) {
m.formattedLastVisitTime = roster.formatDate(m.lastVisitTime);
} else {
m.formattedLastVisitTime = roster.i18n.no_visits_yet;
}
});

roster.renderMembers(members, $('#roster-members'), enrollmentsMode);
Expand Down Expand Up @@ -524,6 +539,7 @@
'viewPicture': true,
'currentUserId': roster.userId,
'viewOfficialPhoto': roster.currentUserPermissions.viewOfficialPhoto,
'viewSiteVisits': roster.currentUserPermissions.viewSiteVisits,
'viewConnections': (undefined != window.friendStatus)
};

Expand Down Expand Up @@ -563,6 +579,16 @@
}).join();
};

roster.formatDate = function (time) {

var d = new Date(time);
var hours = d.getHours();
if (hours < 10) hours = '0' + hours;
var minutes = d.getMinutes();
if (minutes < 10) minutes = '0' + minutes;
return d.getDate() + " " + roster.i18n.months[d.getMonth()] + " " + d.getFullYear() + " @ " + hours + ":" + minutes;
};

// Functions and attributes added. All the code from hereon is executed
// after load.

Expand Down
2 changes: 2 additions & 0 deletions roster2/src/webapp/js/roster_permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ roster.RosterPermissions = function (permissions) {
self.viewProfile = true;
} else if ('roster.viewofficialphoto' === p) {
self.viewOfficialPhoto = true;
} else if ('roster.viewsitevisits' === p) {
self.viewSiteVisits = true;
} else if ('roster.viewemail' === p) {
self.viewEmail = true;
} else if ('site.upd' === p) { // sakai permissions
Expand Down

0 comments on commit 5676200

Please sign in to comment.