Skip to content

Commit 6f0e1d2

Browse files
committed
Select Academic Session/Select User Role: GWT
- Select Academic Session/Select User Role page rewritten to GWT (set unitime.legacy.selectPrimaryRole to true for the old Struts-based page) - a few improvements has been done in the new version of the page - added a toggle to hide inactive academic sessions (e.g., test and finished sessions) - highlight the academic session used last time
1 parent 94b6038 commit 6f0e1d2

19 files changed

Lines changed: 395 additions & 1 deletion

JavaSource/org/unitime/localization/messages/CourseMessages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6096,4 +6096,7 @@ public interface CourseMessages extends Messages {
60966096

60976097
@DefaultMessage("No preferences")
60986098
String altNoPreferences();
6099+
6100+
@DefaultMessage("Include inactive academic sessions")
6101+
String checkIncludeInactiveSessions();
60996102
}

JavaSource/org/unitime/timetable/action/RoleListAction.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
package org.unitime.timetable.action;
2121

22+
import java.net.URLEncoder;
23+
import java.util.Enumeration;
2224
import java.util.HashSet;
2325
import java.util.Set;
2426

@@ -34,6 +36,7 @@
3436
import org.unitime.commons.web.WebTable;
3537
import org.unitime.localization.impl.Localization;
3638
import org.unitime.localization.messages.CourseMessages;
39+
import org.unitime.timetable.defaults.ApplicationProperty;
3740
import org.unitime.timetable.defaults.SessionAttribute;
3841
import org.unitime.timetable.form.RoleListForm;
3942
import org.unitime.timetable.model.Roles;
@@ -92,6 +95,18 @@ public String execute() throws Exception {
9295

9396
if (user.getAuthorities().isEmpty()) return "norole";
9497

98+
if (ApplicationProperty.LegacySelectPrimaryRole.isFalse()) {
99+
String url = "selectPrimaryRole";
100+
boolean first = true;
101+
for (Enumeration<String> e = getRequest().getParameterNames(); e.hasMoreElements(); ) {
102+
String param = e.nextElement();
103+
url += (first ? "?" : "&") + param + "=" + URLEncoder.encode(getRequest().getParameter(param), "utf-8");
104+
first = false;
105+
}
106+
response.sendRedirect(url);
107+
return null;
108+
}
109+
95110
// Form submitted
96111
if (form.getAuthority() != null) {
97112
UserAuthority authority = user.getAuthority(form.getAuthority());

JavaSource/org/unitime/timetable/defaults/ApplicationProperty.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,6 +3833,11 @@ public enum ApplicationProperty {
38333833
@Description("Enrollment Audit PDF Reports: switch the user interface back to the old (Struts-based) enrollment audit PDF reports page")
38343834
LegacyEnrollmentAuditPDFReports("unitime.legacy.enrollmentAuditPdfReport"),
38353835

3836+
@Type(Boolean.class)
3837+
@DefaultValue("false")
3838+
@Description("Select User Role / Select Academic Session: switch the user interface back to the old (Struts-based) select user role page")
3839+
LegacySelectPrimaryRole("unitime.legacy.selectPrimaryRole"),
3840+
38363841
@Type(Boolean.class)
38373842
@DefaultValue("false")
38383843
@Description("Student Scheduling: provide associated (parent) course -- a student requesting both courses cannot get the course without also getting the associated course")

JavaSource/org/unitime/timetable/defaults/UserProperty.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*/
2828
public enum UserProperty {
2929
LastAcademicSession("LastUsed.acadSessionId", "Last used academic session id"),
30+
LastAuthority("LastUsed.authority", "Last used authority"),
3031

3132
CourseOfferingNoteDisplay("crsOffrNoteDisplay", CommonValues.NoteAsIcon, "Display an icon or shortened text when a course offering has a schedule note."),
3233
SchedulePrintNoteDisplay("printNoteDisplay", CommonValues.NoteAsIcon, "Display an icon or shortened text when a class has a schedule print note."),

JavaSource/org/unitime/timetable/gwt/client/Pages.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.unitime.timetable.gwt.client.offerings.OfferingDetailPage;
7171
import org.unitime.timetable.gwt.client.offerings.SubpartDetailPage;
7272
import org.unitime.timetable.gwt.client.offerings.SubpartEditPage;
73+
import org.unitime.timetable.gwt.client.page.SelectUserRolePage;
7374
import org.unitime.timetable.gwt.client.page.SolverWarnings;
7475
import org.unitime.timetable.gwt.client.pointintimedata.PointInTimeDataReportsPage;
7576
import org.unitime.timetable.gwt.client.reservations.ReservationEdit;
@@ -478,6 +479,10 @@ public enum Pages {
478479
public Widget create() { return new EnrollmentAuditPdfReportPage(); }
479480
public String name(GwtMessages messages) { return messages.pageEnrollmentAuditPDFReports(); }
480481
}),
482+
selectPrimaryRole(new PageFactory() {
483+
public Widget create() { return new SelectUserRolePage(); }
484+
public String name(GwtMessages messages) { return messages.pageSelectUserRole(); }
485+
}),
481486
;
482487

483488
private PageFactory iFactory;

JavaSource/org/unitime/timetable/gwt/client/ToolBox.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ public native static String eval(String script) /*-{
267267
public static void checkAccess(Throwable t) {
268268
if (t != null && t instanceof GwtRpcException && t.getCause() != null) t = t.getCause();
269269
if (t != null && t instanceof PageAccessException) {
270-
open(GWT.getHostPageBaseURL() + "login.action?menu=hide&m=" + URL.encodeQueryString(t.getMessage())+"&target=" + URL.encodeQueryString(Window.Location.getHref()));
270+
String url = Window.Location.getHref();
271+
if (url.startsWith(GWT.getHostPageBaseURL()))
272+
url = url.substring(GWT.getHostPageBaseURL().length());
273+
open(GWT.getHostPageBaseURL() + "login.action?menu=hide&m=" + URL.encodeQueryString(t.getMessage())+"&target=" + URL.encodeQueryString(url));
271274
/*
272275
UniTimeFrameDialog.openDialog("UniTime " + CONSTANTS.version() + "| Log In", "login.action?menu=hide&m=" + URL.encodeQueryString(t.getMessage())
273276
+"&target=" + URL.encodeQueryString(Window.Location.getHref()), "700px", "420px");
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/*
2+
* Licensed to The Apereo Foundation under one or more contributor license
3+
* agreements. See the NOTICE file distributed with this work for
4+
* additional information regarding copyright ownership.
5+
*
6+
* The Apereo Foundation licenses this file to you under the Apache License,
7+
* Version 2.0 (the "License"); you may not use this file except in
8+
* compliance with the License. You may obtain a copy of the License at:
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
*
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
package org.unitime.timetable.gwt.client.page;
21+
22+
import org.unitime.localization.messages.CourseMessages;
23+
import org.unitime.timetable.gwt.client.ToolBox;
24+
import org.unitime.timetable.gwt.client.tables.TableInterface;
25+
import org.unitime.timetable.gwt.client.tables.TableWidget;
26+
import org.unitime.timetable.gwt.client.widgets.SimpleForm;
27+
import org.unitime.timetable.gwt.client.widgets.UniTimeHeaderPanel;
28+
import org.unitime.timetable.gwt.command.client.GwtRpcRequest;
29+
import org.unitime.timetable.gwt.command.client.GwtRpcResponse;
30+
import org.unitime.timetable.gwt.command.client.GwtRpcService;
31+
import org.unitime.timetable.gwt.command.client.GwtRpcServiceAsync;
32+
import org.unitime.timetable.gwt.resources.GwtMessages;
33+
34+
import com.google.gwt.core.client.GWT;
35+
import com.google.gwt.event.logical.shared.ValueChangeEvent;
36+
import com.google.gwt.event.logical.shared.ValueChangeHandler;
37+
import com.google.gwt.user.client.History;
38+
import com.google.gwt.user.client.Window;
39+
import com.google.gwt.user.client.rpc.AsyncCallback;
40+
import com.google.gwt.user.client.ui.CheckBox;
41+
import com.google.gwt.user.client.ui.Composite;
42+
import com.google.gwt.user.client.ui.Label;
43+
44+
public class SelectUserRolePage extends Composite {
45+
private static final CourseMessages COURSE = GWT.create(CourseMessages.class);
46+
private static final GwtMessages MESSAGES = GWT.create(GwtMessages.class);
47+
protected static GwtRpcServiceAsync RPC = GWT.create(GwtRpcService.class);
48+
49+
SimpleForm iPanel = new SimpleForm();
50+
CheckBox iInactive;
51+
UniTimeHeaderPanel iHeader, iFooter;
52+
Label iMessage = null;
53+
54+
public SelectUserRolePage() {
55+
iPanel.addStyleName("unitime-SelectUserRolePage");
56+
initWidget(iPanel);
57+
iInactive = new CheckBox(COURSE.checkIncludeInactiveSessions());
58+
iInactive.setValue("1".equals(ToolBox.getCookie("SelectUserRole.Inactive")));
59+
iInactive.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
60+
@Override
61+
public void onValueChange(ValueChangeEvent<Boolean> event) {
62+
ToolBox.setCookie("SelectUserRole.Inactive", event.getValue() ? "1" : "0");
63+
populate(null);
64+
}
65+
});
66+
History.addValueChangeHandler(new ValueChangeHandler<String>() {
67+
@Override
68+
public void onValueChange(ValueChangeEvent<String> event) {
69+
if (event.getValue() != null)
70+
populate(event.getValue());
71+
}
72+
});
73+
iInactive.setVisible(false);
74+
iMessage = new Label();
75+
iMessage.addStyleName("unitime-Message");
76+
77+
iHeader = new UniTimeHeaderPanel(COURSE.sectSelectAcademicSession());
78+
iPanel.addHeaderRow(iHeader);
79+
iFooter = new UniTimeHeaderPanel();
80+
iFooter.insertLeft(iInactive, false);
81+
82+
populate(null);
83+
}
84+
85+
protected void populate(String auth) {
86+
SelectUserRoleRequest request = new SelectUserRoleRequest();
87+
request.setTarget(Window.Location.getParameter("target"));
88+
request.setList("Y".equalsIgnoreCase(Window.Location.getParameter("list")));
89+
request.setIncludeInactive(iInactive.getValue());
90+
request.setAuthority(auth);
91+
iHeader.showLoading();
92+
RPC.execute(request, new AsyncCallback<SelectUserRoleReponse>() {
93+
@Override
94+
public void onFailure(Throwable caught) {
95+
iHeader.setErrorMessage(MESSAGES.failedToInitialize(caught.getMessage()));
96+
UniTimeNotifications.error(MESSAGES.failedToInitialize(caught.getMessage()), caught);
97+
ToolBox.checkAccess(caught);
98+
}
99+
100+
@Override
101+
public void onSuccess(SelectUserRoleReponse response) {
102+
if (response.hasUrl()) {
103+
if (response.getUrl().startsWith(GWT.getHostPageBaseURL()))
104+
ToolBox.open(response.getUrl());
105+
else
106+
ToolBox.open(GWT.getHostPageBaseURL() + response.getUrl());
107+
}
108+
iHeader.clear();
109+
iPanel.clear();
110+
if (response.hasMessage()) {
111+
iMessage.setText(response.getMessage());
112+
iPanel.addRow(iMessage);
113+
}
114+
iPanel.addHeaderRow(iHeader);
115+
if (response.hasTable()) {
116+
iHeader.setHTML(response.getTable().getName());
117+
iPanel.addRow(new TableWidget(response.getTable()));
118+
iPanel.addBottomRow(iFooter);
119+
}
120+
if (response.hasPageName())
121+
UniTimePageLabel.getInstance().setPageName(response.getPageName());
122+
iInactive.setVisible(response.hasInactive());
123+
}
124+
});
125+
}
126+
127+
128+
public static class SelectUserRoleRequest implements GwtRpcRequest<SelectUserRoleReponse>{
129+
private String iTarget;
130+
private boolean iList = false;
131+
private boolean iInactive = false;
132+
private String iAuthority;
133+
134+
public boolean isList() { return iList; }
135+
public void setList(boolean list) { iList = list; }
136+
public String getTarget() { return iTarget; }
137+
public void setTarget(String target) { iTarget = target; }
138+
public boolean hasTarget() { return iTarget != null && !iTarget.isEmpty(); }
139+
public void setIncludeInactive(boolean includeInactive) { iInactive = includeInactive; }
140+
public boolean isIncludeInactive() { return iInactive; }
141+
public void setAuthority(String authority) { iAuthority = authority; }
142+
public String getAuthority() { return iAuthority; }
143+
public boolean hasAuthority() { return iAuthority != null && !iAuthority.isEmpty(); }
144+
}
145+
146+
public static class SelectUserRoleReponse implements GwtRpcResponse {
147+
public String iMessage;
148+
public String iPageName;
149+
public TableInterface iTable;
150+
public String iUrl;
151+
private boolean iHasInactive = false;
152+
153+
public String getMessage() { return iMessage; }
154+
public boolean hasMessage() { return iMessage != null && !iMessage.isEmpty(); }
155+
public void setMessage(String message) { iMessage = message; }
156+
public TableInterface getTable() { return iTable; }
157+
public boolean hasTable() { return iTable != null; }
158+
public void setTable(TableInterface table) { iTable = table; }
159+
public String getPageName() { return iPageName; }
160+
public void setPageName(String pageName) { iPageName = pageName; }
161+
public boolean hasPageName() { return iPageName != null && !iPageName.isEmpty(); }
162+
public void setUrl(String url) { iUrl = url; }
163+
public String getUrl() { return iUrl; }
164+
public boolean hasUrl() { return iUrl != null && !iUrl.isEmpty(); }
165+
public void setHasInactive(boolean hasInactive) { iHasInactive = hasInactive; }
166+
public boolean hasInactive() { return iHasInactive; }
167+
}
168+
}

JavaSource/org/unitime/timetable/gwt/resources/GwtMessages.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4087,6 +4087,10 @@ public interface GwtMessages extends Messages {
40874087
@DefaultMessage("Enrollment Audit PDF Reports")
40884088
@DoNotTranslate
40894089
String pageEnrollmentAuditPDFReports();
4090+
4091+
@DefaultMessage("Select User Role")
4092+
@DoNotTranslate
4093+
String pageSelectUserRole();
40904094

40914095
@DefaultMessage("N/A")
40924096
String itemNotApplicable();

JavaSource/org/unitime/timetable/security/context/HttpSessionContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ public String getHttpSessionId() {
112112
}
113113
}
114114

115+
public HttpSession getHttpSession() { return iSession; }
116+
117+
115118
@Override
116119
public void checkPermission(Right right) {
117120
unitimePermissionCheck.checkPermission(getUser(), null, null, right);

JavaSource/org/unitime/timetable/security/context/UniTimeUserContext.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ public void setCurrentAuthority(UserAuthority authority) {
395395
super.setCurrentAuthority(authority);
396396
if (authority.getAcademicSession() != null)
397397
setProperty(UserProperty.LastAcademicSession, authority.getAcademicSession().getQualifierId().toString());
398+
if (authority.getAuthority() != null)
399+
setProperty(UserProperty.LastAuthority, authority.getAuthority());
398400
}
399401

400402
@Override

0 commit comments

Comments
 (0)