Skip to content

Commit 316dd34

Browse files
committed
Examination Assignment: GWT
- Examination Assignment page rewritten to GWT (set unitime.legacy.examAssignment to true for the old Struts-based page)
1 parent 9c1d4c0 commit 316dd34

23 files changed

Lines changed: 2868 additions & 37 deletions

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

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

22+
import java.net.URLEncoder;
2223
import java.util.Date;
24+
import java.util.Enumeration;
2325

2426
import org.apache.struts2.convention.annotation.Action;
2527
import org.apache.struts2.convention.annotation.Result;
2628
import org.apache.struts2.tiles.annotation.TilesDefinition;
2729
import org.apache.struts2.tiles.annotation.TilesPutAttribute;
2830
import org.unitime.localization.impl.Localization;
2931
import org.unitime.localization.messages.ExaminationMessages;
32+
import org.unitime.timetable.defaults.ApplicationProperty;
3033
import org.unitime.timetable.defaults.SessionAttribute;
3134
import org.unitime.timetable.form.ExamInfoForm;
3235
import org.unitime.timetable.model.ExamPeriod;
@@ -72,6 +75,18 @@ public class ExamInfoAction extends UniTimeAction<ExamInfoForm> {
7275
public void setDelete(Long delete) { this.delete = delete; }
7376

7477
public String execute() throws Exception {
78+
if (ApplicationProperty.LegacyExamAssignment.isFalse()) {
79+
String url = "examAssignment?menu=hide";
80+
boolean first = false;
81+
for (Enumeration<String> e = getRequest().getParameterNames(); e.hasMoreElements(); ) {
82+
String param = e.nextElement();
83+
url += (first ? "?" : "&") + param + "=" + URLEncoder.encode(getRequest().getParameter(param), "utf-8");
84+
first = false;
85+
}
86+
response.sendRedirect(url);
87+
return null;
88+
}
89+
7590
if (form == null) {
7691
form = new ExamInfoForm();
7792
form.reset();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3818,6 +3818,11 @@ public enum ApplicationProperty {
38183818
@Description("Examination Timetable: switch the user interface back to the old (Struts-based) examination timetable page")
38193819
LegacyExamGrid("unitime.legacy.examGrid"),
38203820

3821+
@Type(Boolean.class)
3822+
@DefaultValue("false")
3823+
@Description("Examination Assignment: switch the user interface back to the old (Struts-based) examination assignment page")
3824+
LegacyExamAssignment("unitime.legacy.examAssignment"),
3825+
38213826
@Type(Boolean.class)
38223827
@DefaultValue("false")
38233828
@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/events/RoomFilterBackend.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,15 @@ protected List<Location> locations(Long sessionId, Map<String, Set<String>> opti
385385
Set<String> flag = (options == null || "flag".equals(ignoreCommand) ? null : options.get("flag"));
386386
Set<String> departments = (options == null || "department".equals(ignoreCommand) ? null : options.get("department"));
387387
boolean nearby = (flag != null && (flag.contains("nearby") || flag.contains("Nearby")));
388+
boolean examcap = (flag != null && (flag.contains("examcap") || flag.contains("Examination Capacity")));
388389

389390
Set<String> featureTypes = new HashSet<String>();
390391
for (RoomFeatureType ft: RoomFeatureTypeDAO.getInstance().findAll())
391392
if (showRoomFeature(ft)) featureTypes.add(ft.getReference().toLowerCase().replace(' ', '_'));
392393

393394
List<Location> ret = new ArrayList<Location>();
394395
for (Location location: locations) {
395-
if (query != null && !query.match(new LocationMatcher(location, featureTypes, departments))) continue;
396+
if (query != null && !query.match(new LocationMatcher(location, featureTypes, departments).setUseExamCapacity(examcap))) continue;
396397
if (nearby && building != null && !building.isEmpty() && (!(location instanceof Room) || !building.contains(((Room)location).getBuilding().getAbbreviation()))) continue;
397398
ret.add(location);
398399
}
@@ -417,7 +418,7 @@ protected List<Location> locations(Long sessionId, Map<String, Set<String>> opti
417418
if (!coord.isEmpty()) {
418419
for (Location location: locations) {
419420
if (building != null && !building.isEmpty() && (location instanceof Room) && building.contains(((Room)location).getBuilding().getAbbreviation())) continue;
420-
if (query != null && !query.match(new LocationMatcher(location, featureTypes, departments))) continue;
421+
if (query != null && !query.match(new LocationMatcher(location, featureTypes, departments).setUseExamCapacity(examcap))) continue;
421422
Coordinates c = new Coordinates(location);
422423
Double distance = null;
423424
for (Coordinates x: coord) {
@@ -465,10 +466,15 @@ private String suggestionQuery(String query) {
465466
@Override
466467
public void suggestions(RoomFilterRpcRequest request, FilterRpcResponse response, EventContext context) {
467468
fixRoomFeatureTypes(request);
469+
470+
Set<String> flag = request.getOptions("flag");
471+
boolean examcap = (flag != null && (flag.contains("examcap") || flag.contains("Examination Capacity")));
468472

469473
Map<Long, Double> distances = new HashMap<Long, Double>();
470474
for (Location location: locations(request.getSessionId(), request.getOptions(), new Query(suggestionQuery(request.getText())), 20, distances, null, context)) {
471475
String hint = location.getRoomTypeLabel() + (location.getCapacity() == null ? "" : ", " + MESSAGES.hintRoomCapacity(location.getCapacity().toString()));
476+
if (examcap)
477+
hint = location.getRoomTypeLabel() + (location.getExamCapacity() == null ? "" : ", " + MESSAGES.hintRoomCapacity(location.getExamCapacity().toString()));
472478
Double dist = distances.get(location.getUniqueId());
473479
if (dist != null) hint += ", " + MESSAGES.hintRoomDistance(String.valueOf(Math.round(dist)));
474480
response.addSuggestion(location.getLabelWithDisplayName(), location.getLabel(), "(" + hint + ")");
@@ -556,16 +562,19 @@ public static class LocationMatcher implements TermMatcher {
556562
private Location iLocation;
557563
private Set<String> iFeatureTypes = null;
558564
private Set<String> iDepartments = null;
565+
private boolean iUseExamCapacity = false;
559566

560567
public LocationMatcher(Location location, Set<String> featureTypes) {
561568
this(location, featureTypes, null);
562569
}
563-
570+
564571
public LocationMatcher(Location location, Set<String> featureTypes, Set<String> departments) {
565572
iLocation = location;
566573
iFeatureTypes = featureTypes;
567574
iDepartments = departments;
568575
}
576+
577+
public LocationMatcher setUseExamCapacity(boolean useExamCapacity) { iUseExamCapacity = useExamCapacity; return this; }
569578

570579
public Location getLocation() { return iLocation; }
571580

@@ -629,7 +638,8 @@ public boolean match(String attr, String term) {
629638
min = Integer.parseInt(a); max = Integer.parseInt(b);
630639
} catch (NumberFormatException e) {}
631640
}
632-
return min <= getLocation().getCapacity() && getLocation().getCapacity() <= max;
641+
Integer capacity = (iUseExamCapacity ? getLocation().getExamCapacity() : getLocation().getCapacity());
642+
return capacity != null && min <= capacity && capacity <= max;
633643
} else if ("flag".equals(attr) && "event".equalsIgnoreCase(term)) {
634644
return getLocation().getEventDepartment() != null && getLocation().getEventDepartment().isAllowEvents() && getLocation().getEffectiveEventStatus() != RoomTypeOption.Status.NoEventManagement;
635645
} else if ("department".equals(attr) || "dept".equals(attr) || "event".equals(attr) || "control".equals(attr)) {
@@ -757,6 +767,11 @@ public RoomQuery getQuery(Long sessionId, Map<String, Set<String>> options, Even
757767
}
758768
}
759769

770+
771+
Set<String> flags = (options == null ? null : options.get("flag"));
772+
boolean nearby = (flags != null && (flags.contains("nearby") || flags.contains("Nearby")));
773+
boolean examcap = (flags != null && (flags.contains("examcap") || flags.contains("Examination Capacity")));
774+
760775
Set<String> size = (options == null ? null : options.get("size"));
761776
if (size != null && !size.isEmpty()) {
762777
String term = size.iterator().next();
@@ -787,22 +802,19 @@ public RoomQuery getQuery(Long sessionId, Map<String, Set<String>> options, Even
787802
}
788803
if (min > 0) {
789804
if (max < Integer.MAX_VALUE) {
790-
query.addWhere("size", "l.capacity >= :Xmin and l.capacity <= :Xmax");
805+
query.addWhere("size", examcap ? "l.examCapacity >= :Xmin and l.examCapacity <= :Xmax" : "l.capacity >= :Xmin and l.capacity <= :Xmax");
791806
query.addParameter("size", "Xmin", min);
792807
query.addParameter("size", "Xmax", max);
793808
} else {
794-
query.addWhere("size", "l.capacity >= :Xmin");
809+
query.addWhere("size", examcap ? "l.examCapacity >= :Xmin" : "l.capacity >= :Xmin");
795810
query.addParameter("size", "Xmin", min);
796811
}
797812
} else if (max < Integer.MAX_VALUE) {
798-
query.addWhere("size", "l.capacity <= :Xmax");
813+
query.addWhere("size", examcap ? "l.examCapacity <= :Xmax" : "l.capacity <= :Xmax");
799814
query.addParameter("size", "Xmax", max);
800815
}
801816
}
802817

803-
Set<String> flags = (options == null ? null : options.get("flag"));
804-
boolean nearby = (flags != null && (flags.contains("nearby") || flags.contains("Nearby")));
805-
806818
Set<String> buildings = (options == null ? null : options.get("building"));
807819
if (buildings != null && !buildings.isEmpty() && !nearby) {
808820
String building = "";

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.unitime.timetable.gwt.client.events.EventRoomAvailability;
3131
import org.unitime.timetable.gwt.client.exams.AssignedExamsPage;
3232
import org.unitime.timetable.gwt.client.exams.ExamAssignmentChangesPage;
33+
import org.unitime.timetable.gwt.client.exams.ExamAssignmentPage;
3334
import org.unitime.timetable.gwt.client.exams.ExamConflictBasedStatisticsPage;
3435
import org.unitime.timetable.gwt.client.exams.ExamDetailPage;
3536
import org.unitime.timetable.gwt.client.exams.ExamDistributionsEditPage;
@@ -463,6 +464,10 @@ public enum Pages {
463464
public Widget create() { return new ExamGridPage(); }
464465
public String name(GwtMessages messages) { return messages.pageExaminationTimetable(); }
465466
}),
467+
examAssignment(new PageFactory() {
468+
public Widget create() { return new ExamAssignmentPage(); }
469+
public String name(GwtMessages messages) { return messages.pageExaminationAssignment(); }
470+
}),
466471
;
467472

468473
private PageFactory iFactory;

JavaSource/org/unitime/timetable/gwt/client/exams/AssignedExamsPage.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.google.gwt.user.client.ui.Anchor;
5757
import com.google.gwt.user.client.ui.Composite;
5858
import com.google.gwt.user.client.ui.ListBox;
59+
import com.google.gwt.user.client.ui.RootPanel;
5960
import com.google.gwt.user.client.ui.SimplePanel;
6061

6162
public class AssignedExamsPage extends Composite {
@@ -179,6 +180,7 @@ public void onSuccess(ClassesFilterResponse result) {
179180
}
180181
DomEvent.fireNativeEvent(Document.get().createChangeEvent(), list);
181182
}
183+
createTriggers();
182184
if (autoSearch)
183185
search(null);
184186
}
@@ -289,5 +291,27 @@ protected void export(String format) {
289291
+ (sort == null ? "" : "&sort=" + sort)
290292
+ iFilter.getFullQuery());
291293
}
294+
295+
public static native void createTriggers()/*-{
296+
$wnd.refreshPage = function() {
297+
@org.unitime.timetable.gwt.client.exams.AssignedExamsPage::__search()();
298+
};
299+
}-*/;
300+
301+
public static void __search() {
302+
final int left = Window.getScrollLeft();
303+
final int top = Window.getScrollTop();
304+
AssignedExamsPage page = (AssignedExamsPage)RootPanel.get("UniTimeGWT:Body").getWidget(0);
305+
page.search(new AsyncCallback<Boolean>() {
306+
@Override
307+
public void onFailure(Throwable caught) {
308+
}
309+
@Override
310+
public void onSuccess(Boolean result) {
311+
if (result)
312+
Window.scrollTo(left, top);
313+
}
314+
});
315+
}
292316

293317
}

JavaSource/org/unitime/timetable/gwt/client/exams/ExamAssignmentChangesPage.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.google.gwt.user.client.ui.Anchor;
5757
import com.google.gwt.user.client.ui.Composite;
5858
import com.google.gwt.user.client.ui.ListBox;
59+
import com.google.gwt.user.client.ui.RootPanel;
5960
import com.google.gwt.user.client.ui.SimplePanel;
6061

6162
public class ExamAssignmentChangesPage extends Composite {
@@ -179,6 +180,7 @@ public void onSuccess(ClassesFilterResponse result) {
179180
}
180181
DomEvent.fireNativeEvent(Document.get().createChangeEvent(), list);
181182
}
183+
createTriggers();
182184
if (autoSearch)
183185
search(null);
184186
}
@@ -289,5 +291,26 @@ protected void export(String format) {
289291
+ (sort == null ? "" : "&sort=" + sort)
290292
+ iFilter.getFullQuery());
291293
}
294+
295+
public static native void createTriggers()/*-{
296+
$wnd.refreshPage = function() {
297+
@org.unitime.timetable.gwt.client.exams.ExamAssignmentChangesPage::__search()();
298+
};
299+
}-*/;
292300

301+
public static void __search() {
302+
final int left = Window.getScrollLeft();
303+
final int top = Window.getScrollTop();
304+
ExamAssignmentChangesPage page = (ExamAssignmentChangesPage)RootPanel.get("UniTimeGWT:Body").getWidget(0);
305+
page.search(new AsyncCallback<Boolean>() {
306+
@Override
307+
public void onFailure(Throwable caught) {
308+
}
309+
@Override
310+
public void onSuccess(Boolean result) {
311+
if (result)
312+
Window.scrollTo(left, top);
313+
}
314+
});
315+
}
293316
}

0 commit comments

Comments
 (0)