Commit d4f6b1b75818bc5adb8c8ec34e771246d114539a

  • avatar
  • tomas-muller <muller @uni…me.org> (Committer)
  • Thu Apr 30 23:30:41 EEST 2015
  • avatar
  • tomas-muller <muller @uni…me.org> (Author)
  • Thu Apr 30 23:30:41 EEST 2015
Rooms: new gwt-based Rooms page

- added new gwt-based Rooms page
 - using a Room Filter just like on the Events page
   (flag:Events shows all event rooms of a department, not just the enabled ones)
 - rooms table support sorting, an ability to show/hide columns, and can display much more data than the old one
 - added ability to export CSV/PDF files
 - more features to follow...
JavaSource/org/unitime/timetable/export/rooms/RoomsExportCSV.java
(134 / 0)
  
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*/
20package org.unitime.timetable.export.rooms;
21
22import java.io.IOException;
23import java.util.List;
24
25import org.springframework.stereotype.Service;
26import org.unitime.timetable.export.CSVPrinter;
27import org.unitime.timetable.export.ExportHelper;
28import org.unitime.timetable.gwt.shared.RoomInterface.RoomDetailInterface;
29import org.unitime.timetable.gwt.shared.RoomInterface.RoomFlag;
30import org.unitime.timetable.security.rights.Right;
31
32/**
33 * @author Tomas Muller
34 */
35@Service("org.unitime.timetable.export.Exporter:rooms.csv")
36public class RoomsExportCSV extends RoomsExporter {
37
38 @Override
39 public String reference() { return "rooms.csv"; }
40
41 @Override
42 protected void print(ExportHelper helper, List<RoomDetailInterface> rooms, String department, int roomCookieFlags, int deptMode, boolean gridAsText, boolean vertical, String mode) throws IOException {
43 if (checkRights(helper))
44 helper.getSessionContext().hasPermission(Right.RoomsExportCsv);
45
46 Printer printer = new CSVPrinter(helper.getWriter(), false);
47 helper.setup(printer.getContentType(), reference(), false);
48 hideColumns(printer, rooms, roomCookieFlags);
49 print(printer, rooms, deptMode);
50 }
51
52 @Override
53 protected void hideColumn(Printer out, List<RoomDetailInterface> rooms, RoomFlag flag) {
54 switch (flag) {
55 case SHOW_TYPE: out.hideColumn(1); break;
56 case SHOW_CAPACITY: out.hideColumn(2); break;
57 case SHOW_EXAM_CAPACITY: out.hideColumn(3); break;
58 case SHOW_AREA: out.hideColumn(4); break;
59 case SHOW_COORDINATES: out.hideColumn(5); out.hideColumn(6); break;
60 case SHOW_IGNORE_DISTANCES: out.hideColumn(7); break;
61 case SHOW_IGNORE_ROOM_CHECK: out.hideColumn(8); break;
62 case SHOW_PREFERENCE: out.hideColumn(9); break;
63 case SHOW_AVAILABILITY: out.hideColumn(10); break;
64 case SHOW_DEPARTMENTS: out.hideColumn(11); break;
65 case SHOW_CONTROLLING_DEPARTMENT: out.hideColumn(12); break;
66 case SHOW_EXAM_TYPES: out.hideColumn(13); break;
67 case SHOW_PERIOD_PREFERENCES: out.hideColumn(14); break;
68 case SHOW_EVENT_DEPARTMENT: out.hideColumn(15); break;
69 case SHOW_EVENT_STATUS: out.hideColumn(16); break;
70 case SHOW_EVENT_AVAILABILITY: out.hideColumn(17); break;
71 case SHOW_EVENT_MESSAGE: out.hideColumn(18); break;
72 case SHOW_BREAK_TIME: out.hideColumn(19); break;
73 case SHOW_GROUPS: out.hideColumn(20); break;
74 case SHOW_FEATURES: out.hideColumn(21); break;
75 }
76 }
77
78 protected void print(Printer out, List<RoomDetailInterface> rooms, int deptMode) throws IOException {
79 out.printHeader(
80 /* 0 */ MESSAGES.colName().replace("<br>", "\n"),
81 /* 1 */ MESSAGES.colType().replace("<br>", "\n"),
82 /* 2 */ MESSAGES.colCapacity().replace("<br>", "\n"),
83 /* 3 */ MESSAGES.colExaminationCapacity().replace("<br>", "\n"),
84 /* 4 */ MESSAGES.colArea().replace("<br>", "\n").replace("&sup2;", "2"),
85 /* 5 */ MESSAGES.colCoordinateX().replace("<br>", "\n"),
86 /* 6 */ MESSAGES.colCoordinateY().replace("<br>", "\n"),
87 /* 7 */ MESSAGES.colDistances().replace("<br>", "\n"),
88 /* 8 */ MESSAGES.colRoomCheck().replace("<br>", "\n"),
89 /* 9 */ MESSAGES.colPreference().replace("<br>", "\n"),
90 /* 10 */ MESSAGES.colAvailability().replace("<br>", "\n"),
91 /* 11 */ MESSAGES.colDepartments().replace("<br>", "\n"),
92 /* 12 */ MESSAGES.colControl().replace("<br>", "\n"),
93 /* 13 */ MESSAGES.colExamTypes().replace("<br>", "\n"),
94 /* 14 */ MESSAGES.colPeriodPreferences().replace("<br>", "\n"),
95 /* 15 */ MESSAGES.colEventDepartment().replace("<br>", "\n"),
96 /* 16 */ MESSAGES.colEventStatus().replace("<br>", "\n"),
97 /* 17 */ MESSAGES.colEventAvailability().replace("<br>", "\n"),
98 /* 18 */ MESSAGES.colEventMessage().replace("<br>", "\n"),
99 /* 19 */ MESSAGES.colBreakTime().replace("<br>", "\n"),
100 /* 20 */ MESSAGES.colGroups().replace("<br>", "\n"),
101 /* 21 */ MESSAGES.colFeatures().replace("<br>", "\n")
102 );
103
104
105 for (RoomDetailInterface room: rooms) {
106 out.printLine(
107 room.hasDisplayName() ? MESSAGES.label(room.getLabel(), room.getDisplayName()) : room.getLabel(),
108 room.getRoomType().getLabel(),
109 room.getCapacity() == null ? "0" : room.getCapacity().toString(),
110 room.getExamCapacity() == null ? "" : room.getExamCapacity().toString(),
111 room.getArea() == null ? "" : room.getArea().toString(),
112 room.getX() == null ? "" : room.getX().toString(),
113 room.getY() == null ? "" : room.getY().toString(),
114 room.isIgnoreRoomCheck() ? MESSAGES.exportFalse() : MESSAGES.exportTrue(),
115 room.isIgnoreTooFar() ? MESSAGES.exportFalse() : MESSAGES.exportTrue(),
116 pref2string(room.getDepartments(), deptMode, "\n"),
117 room.getAvailability(),
118 dept2string(room.getDepartments(), deptMode, "\n"),
119 dept2string(room.getControlDepartment(), deptMode),
120 examTypes2string(room.getExamTypes(), "\n"),
121 room.getPeriodPreference(),
122 dept2string(room.getEventDepartment(), deptMode),
123 room.getEventStatus() != null ? CONSTANTS.eventStatusAbbv()[room.getEventStatus()] : room.getDefaultEventStatus() != null ? CONSTANTS.eventStatusAbbv()[room.getDefaultEventStatus()] : "",
124 room.getEventAvailability(),
125 room.getEventNote() != null ? room.getEventNote() : room.getDefaultEventNote(),
126 room.getBreakTime() != null ? room.getBreakTime().toString() : room.getDefaultBreakTime() != null ? room.getDefaultBreakTime().toString() : "",
127 groups2string(room.getGroups(), "\n"),
128 features2string(room.getFeatures(), "\n")
129 );
130 out.flush();
131 }
132 out.close();
133 }
134}
JavaSource/org/unitime/timetable/export/rooms/RoomsExportPDF.java
(350 / 0)
  
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*/
20package org.unitime.timetable.export.rooms;
21
22import java.io.IOException;
23import java.util.ArrayList;
24import java.util.Collection;
25import java.util.Date;
26import java.util.Hashtable;
27import java.util.List;
28
29import org.springframework.stereotype.Service;
30import org.unitime.timetable.export.ExportHelper;
31import org.unitime.timetable.export.PDFPrinter;
32import org.unitime.timetable.export.PDFPrinter.A;
33import org.unitime.timetable.gwt.shared.RoomInterface.DepartmentInterface;
34import org.unitime.timetable.gwt.shared.RoomInterface.ExamTypeInterface;
35import org.unitime.timetable.gwt.shared.RoomInterface.FeatureInterface;
36import org.unitime.timetable.gwt.shared.RoomInterface.GroupInterface;
37import org.unitime.timetable.gwt.shared.RoomInterface.RoomDetailInterface;
38import org.unitime.timetable.gwt.shared.RoomInterface.RoomFlag;
39import org.unitime.timetable.model.ExamType;
40import org.unitime.timetable.model.Location;
41import org.unitime.timetable.model.MidtermPeriodPreferenceModel;
42import org.unitime.timetable.model.PeriodPreferenceModel;
43import org.unitime.timetable.model.PreferenceLevel;
44import org.unitime.timetable.model.dao.LocationDAO;
45import org.unitime.timetable.security.rights.Right;
46import org.unitime.timetable.util.Constants;
47import org.unitime.timetable.util.Formats;
48import org.unitime.timetable.util.Formats.Format;
49import org.unitime.timetable.webutil.RequiredTimeTable;
50
51/**
52 * @author Tomas Muller
53 */
54@Service("org.unitime.timetable.export.Exporter:rooms.pdf")
55public class RoomsExportPDF extends RoomsExporter {
56
57 @Override
58 public String reference() { return "rooms.pdf"; }
59
60 @Override
61 protected void print(ExportHelper helper, List<RoomDetailInterface> rooms, String department, int roomCookieFlags, int deptMode, boolean gridAsText, boolean vertical, String mode) throws IOException {
62 if (checkRights(helper))
63 helper.getSessionContext().hasPermission(Right.RoomsExportPdf);
64
65 Printer printer = new PDFPrinter(helper.getOutputStream(), false);
66 helper.setup(printer.getContentType(), reference(), false);
67 hideColumns(printer, rooms, roomCookieFlags);
68 print(printer, rooms, department, deptMode, gridAsText, vertical, mode);
69 }
70
71 @Override
72 protected void hideColumn(Printer out, List<RoomDetailInterface> rooms, RoomFlag flag) {
73 switch (flag) {
74 case SHOW_TYPE: out.hideColumn(1); break;
75 case SHOW_CAPACITY: out.hideColumn(2); break;
76 case SHOW_EXAM_CAPACITY: out.hideColumn(3); break;
77 case SHOW_AREA: out.hideColumn(4); break;
78 case SHOW_COORDINATES: out.hideColumn(5); break;
79 case SHOW_IGNORE_DISTANCES: out.hideColumn(6); break;
80 case SHOW_IGNORE_ROOM_CHECK: out.hideColumn(7); break;
81 case SHOW_PREFERENCE: out.hideColumn(8); break;
82 case SHOW_AVAILABILITY: out.hideColumn(9); break;
83 case SHOW_DEPARTMENTS: out.hideColumn(10); break;
84 case SHOW_CONTROLLING_DEPARTMENT: out.hideColumn(11); break;
85 case SHOW_EXAM_TYPES: out.hideColumn(12); break;
86 case SHOW_PERIOD_PREFERENCES: out.hideColumn(13); break;
87 case SHOW_EVENT_DEPARTMENT: out.hideColumn(14); break;
88 case SHOW_EVENT_STATUS: out.hideColumn(15); break;
89 case SHOW_EVENT_AVAILABILITY: out.hideColumn(16); break;
90 case SHOW_EVENT_MESSAGE: out.hideColumn(17); break;
91 case SHOW_BREAK_TIME: out.hideColumn(18); break;
92 case SHOW_GROUPS: out.hideColumn(19); break;
93 case SHOW_FEATURES: out.hideColumn(20); break;
94 }
95 }
96
97 protected void print(Printer out, List<RoomDetailInterface> rooms, String department, int deptMode, boolean gridAsText, boolean vertical, String mode) throws IOException {
98 out.printHeader(
99 /* 0 */ MESSAGES.colName().replace("<br>", "\n"),
100 /* 1 */ MESSAGES.colType().replace("<br>", "\n"),
101 /* 2 */ MESSAGES.colCapacity().replace("<br>", "\n"),
102 /* 3 */ MESSAGES.colExaminationCapacity().replace("<br>", "\n"),
103 /* 4 */ MESSAGES.colArea().replace("<br>", "\n").replace("&sup2;", "2"),
104 /* 5 */ MESSAGES.colCoordinates().replace("<br>", "\n"),
105 /* 6 */ MESSAGES.colDistances().replace("<br>", "\n"),
106 /* 7 */ MESSAGES.colRoomCheck().replace("<br>", "\n"),
107 /* 8 */ MESSAGES.colPreference().replace("<br>", "\n"),
108 /* 9 */ MESSAGES.colAvailability().replace("<br>", "\n"),
109 /* 10 */ MESSAGES.colDepartments().replace("<br>", "\n"),
110 /* 11 */ MESSAGES.colControl().replace("<br>", "\n"),
111 /* 12 */ MESSAGES.colExamTypes().replace("<br>", "\n"),
112 /* 13 */ MESSAGES.colPeriodPreferences().replace("<br>", "\n"),
113 /* 14 */ MESSAGES.colEventDepartment().replace("<br>", "\n"),
114 /* 15 */ MESSAGES.colEventStatus().replace("<br>", "\n"),
115 /* 16 */ MESSAGES.colEventAvailability().replace("<br>", "\n"),
116 /* 17 */ MESSAGES.colEventMessage().replace("<br>", "\n"),
117 /* 18 */ MESSAGES.colBreakTime().replace("<br>", "\n"),
118 /* 19 */ MESSAGES.colGroups().replace("<br>", "\n"),
119 /* 20 */ MESSAGES.colFeatures().replace("<br>", "\n")
120 );
121
122 Format<Number> af = Formats.getNumberFormat(CONSTANTS.roomAreaFormat());
123 Format<Number> cf = Formats.getNumberFormat(CONSTANTS.roomCoordinateFormat());
124
125 for (RoomDetailInterface room: rooms) {
126 ((PDFPrinter)out).printLine(
127 name(room, department),
128 new A(room.getRoomType().getLabel()),
129 new A(room.getCapacity() == null ? "0" : room.getCapacity().toString()).right(),
130 new A(room.getExamCapacity() == null ? "" : room.getExamCapacity().toString()).right(),
131 new A(room.getArea() == null ? "" : af.format(room.getArea())).right(),
132 new A(room.hasCoordinates() ? cf.format(room.getX()) + "," + cf.format(room.getY()) : ""),
133 new A(room.isIgnoreRoomCheck() ? MESSAGES.exportFalse() : MESSAGES.exportTrue()),
134 new A(room.isIgnoreTooFar() ? MESSAGES.exportFalse() : MESSAGES.exportTrue()),
135 pref2a(room.getDepartments(), deptMode),
136 availability(room, false, gridAsText, vertical, mode),
137 dept2a(room.getDepartments(), room.getControlDepartment(), deptMode),
138 new A(dept2string(room.getControlDepartment(), deptMode)).color(room.getControlDepartment() == null ? null : room.getControlDepartment().getColor()),
139 examTypes2a(room.getExamTypes()),
140 periodPreferences(room, department, gridAsText, vertical),
141 new A(dept2string(room.getEventDepartment(), deptMode)).color(room.getEventDepartment() == null ? null : room.getEventDepartment().getColor()),
142 new A(room.getEventStatus() != null ? CONSTANTS.eventStatusAbbv()[room.getEventStatus()] : room.getDefaultEventStatus() != null ? CONSTANTS.eventStatusAbbv()[room.getDefaultEventStatus()] : "").italic(),
143 availability(room, true, gridAsText, vertical, mode),
144 new A(room.getEventNote() != null ? room.getEventNote() : room.getDefaultEventNote()),
145 new A(room.getBreakTime() != null ? room.getBreakTime().toString() : room.getDefaultBreakTime() != null ? room.getDefaultBreakTime().toString() : ""),
146 groups2a(room.getGroups()),
147 features2a(room.getFeatures())
148 );
149 out.flush();
150 }
151 out.close();
152 }
153
154 protected A availability(RoomDetailInterface room, boolean events, boolean gridAsText, boolean vertical, String mode) {
155 A ret = null;
156 if (gridAsText) {
157 ret = new A(events ? room.getEventAvailability() : room.getAvailability());
158 } else {
159 Location location = LocationDAO.getInstance().get(room.getUniqueId());
160 RequiredTimeTable rtt = (events ? location.getEventAvailabilityTable() : location.getRoomSharingTable());
161 rtt.getModel().setDefaultSelection(mode);
162 ret = new A(rtt.createBufferedImage(vertical, false));
163 }
164 if (!events && room.getRoomSharingNote() != null)
165 ret.add(new A(room.getRoomSharingNote()));
166 //else if (events && (room.hasEventNote() || room.hasDefaultEventNote()))
167 // ret.add(new A(room.hasEventNote() ? room.getEventNote() : room.getDefaultEventNote()));
168 return ret;
169 }
170
171 protected A periodPreferences(RoomDetailInterface room, String department, boolean gridAsText, boolean vertical) {
172 Location location = LocationDAO.getInstance().get(room.getUniqueId());
173 for (ExamType type: location.getExamTypes())
174 if (type.getReference().equals(department)) {
175 if (type.getType() == ExamType.sExamTypeMidterm) {
176 return new PDFMidtermPeriodPreferenceModel(location, type).toA();
177 } else {
178 PDFPeriodPreferenceModel px = new PDFPeriodPreferenceModel(location, type);
179 if (gridAsText)
180 return px.toA();
181 else
182 return new A(new RequiredTimeTable(px).createBufferedImage(vertical, false));
183 }
184 }
185 return new A();
186 }
187
188 protected A name(RoomDetailInterface room, String department) {
189 A a = new A(room.hasDisplayName() ? MESSAGES.label(room.getLabel(), room.getDisplayName()) : room.getLabel());
190 for (DepartmentInterface d: room.getDepartments())
191 if (d.getDeptCode().equals(department) && d.getPreference() != null)
192 a.setColor(d.getPreference().getColor());
193 return a;
194 }
195
196 protected A pref2a(Collection<DepartmentInterface> departments, int deptMode) {
197 if (departments == null || departments.isEmpty()) return new A();
198 A a = new A();
199 for (DepartmentInterface d: departments) {
200 if (d.getPreference() == null) continue;
201 a.add(new A(PreferenceLevel.prolog2abbv(d.getPreference().getCode()) + " " + dept2string(d, deptMode)).color(d.getPreference().getColor()));
202 }
203 return a;
204 }
205
206 protected A dept2a(Collection<DepartmentInterface> departments, DepartmentInterface control, int deptMode) {
207 if (departments == null || departments.isEmpty()) return new A();
208 A a = new A();
209 for (DepartmentInterface d: departments) {
210 A b = new A(dept2string(d, deptMode)).color(d.getColor());
211 if (d.equals(control)) b.underline();
212 a.add(b);
213 }
214 return a;
215 }
216
217 protected A examTypes2a(Collection<ExamTypeInterface> types) {
218 if (types == null || types.isEmpty()) return new A();
219 A a = new A();
220 for (ExamTypeInterface t: types) {
221 a.add(new A(t.getLabel()));
222 }
223 return a;
224 }
225
226 protected A features2a(Collection<FeatureInterface> features) {
227 if (features == null || features.isEmpty()) return new A();
228 A a = new A();
229 for (FeatureInterface f: features) {
230 if (f.getType() != null)
231 a.add(new A(f.getLabel() + " (" + f.getType().getAbbreviation() + ")").color(f.getDepartment() == null ? null : f.getDepartment().getColor()));
232 else if (f.getDepartment() != null)
233 a.add(new A(f.getLabel() + " (" + f.getDepartment().getExtAbbreviationWhenExist() + ")").color(f.getDepartment().getColor()));
234 else
235 a.add(new A(f.getLabel()));
236 }
237 return a;
238 }
239
240 protected A groups2a(Collection<GroupInterface> groups) {
241 if (groups == null || groups.isEmpty()) return new A();
242 A a = new A();
243 for (GroupInterface g: groups) {
244 a.add(new A(g.getLabel() + (g.getDepartment() == null ? "" : " (" + g.getDepartment().getExtAbbreviationWhenExist() + ")")
245 ).color(g.getDepartment() == null ? null : g.getDepartment().getColor()));
246 }
247 return a;
248 }
249
250 static class PDFMidtermPeriodPreferenceModel extends MidtermPeriodPreferenceModel {
251
252 PDFMidtermPeriodPreferenceModel(Location location, ExamType type) {
253 super(location.getSession(), type);
254 load(location);
255 }
256
257 List<A> toA(int fDate, int lDate, Hashtable<Integer,String> prefs) {
258 Formats.Format<Date> df = Formats.getDateFormat(Formats.Pattern.DATE_EXAM_PERIOD);
259 String dates = df.format(getDate(fDate))+(fDate==lDate?"":" - "+df.format(getDate(lDate)));
260 String lastPref = null; int fStart = -1, lStart = -1;
261 List<A> ret = new ArrayList<A>();
262 for (int start: iStarts) {
263 String pref = prefs.get(start);
264 if (pref==null) continue;
265 if (lastPref==null) {
266 lastPref = pref; fStart = start;
267 } else if (!pref.equals(lastPref)) {
268 if (iLocation && PreferenceLevel.sNeutral.equals(lastPref)) {
269 //
270 } else if (!iLocation && PreferenceLevel.sProhibited.equals(lastPref)) {
271 //
272 } else {
273 String startTime = Constants.toTime(Constants.SLOT_LENGTH_MIN*fStart+Constants.FIRST_SLOT_TIME_MIN);
274 String endTime = Constants.toTime(Constants.SLOT_LENGTH_MIN*(lStart+iLength.get(lStart))+Constants.FIRST_SLOT_TIME_MIN);
275 ret.add(new A(PreferenceLevel.prolog2abbv(lastPref)+" "+dates+" "+(iStarts.size()==2?fStart==iStarts.first()?"Early":"Late":startTime)+(fStart==lStart?"":" - "+endTime)).color(PreferenceLevel.prolog2color(lastPref)));
276 }
277 lastPref = pref; fStart = start;
278 }
279 lStart = start;
280 }
281 if (lastPref!=null) {
282 if (iLocation && PreferenceLevel.sNeutral.equals(lastPref)) {
283 //
284 } else if (!iLocation && PreferenceLevel.sProhibited.equals(lastPref)) {
285 //
286 } else {
287 String startTime = Constants.toTime(Constants.SLOT_LENGTH_MIN*fStart+Constants.FIRST_SLOT_TIME_MIN);
288 String endTime = Constants.toTime(Constants.SLOT_LENGTH_MIN*(lStart+iLength.get(lStart))+Constants.FIRST_SLOT_TIME_MIN);
289 if (fStart==iStarts.first()) {
290 ret.add(new A(PreferenceLevel.prolog2abbv(lastPref)+" "+dates).color(PreferenceLevel.prolog2color(lastPref)));
291
292 } else {
293 ret.add(new A(PreferenceLevel.prolog2abbv(lastPref)+" "+dates+" "+(iStarts.size()==2?fStart==iStarts.first()?"Early":"Late":startTime)+(fStart==lStart?"":" - "+endTime)).color(PreferenceLevel.prolog2color(lastPref)));
294 }
295 }
296 }
297 return ret;
298 }
299
300 A toA() {
301 if (iStarts.isEmpty()) return new A();
302 A ret = new A();
303 Hashtable<Integer,String> fPref = null;
304 int fDate = -1, lDate = -1;
305 for (Integer date: iDates) {
306 Hashtable<Integer,String> pref = iPreferences.get(date);
307 if (fPref==null) {
308 fPref = pref; fDate = date;
309 } else if (!fPref.equals(pref)) {
310 for (A b: toA(fDate, lDate, fPref)) ret.add(b);
311 fPref = pref; fDate = date;
312 }
313 lDate = date;
314 }
315 if (fPref!=null) {
316 for (A b: toA(fDate, lDate, fPref)) ret.add(b);
317 }
318 return ret;
319 }
320 }
321
322 class PDFPeriodPreferenceModel extends PeriodPreferenceModel {
323 PDFPeriodPreferenceModel(Location location, ExamType type) {
324 super(location.getSession(), type.getUniqueId());
325 load(location);
326 }
327
328 A toA() {
329 A ret = new A();
330 for (int d=0;d<getNrDays();d++) {
331 String pref = null; int a = 0, b = 0;
332 for (int t=0;t<getNrTimes();t++) {
333 String p = getPreference(d,t);
334 if (pref==null || !pref.equals(p)) {
335 if (pref!=null && !"@".equals(pref) && !PreferenceLevel.sNeutral.equals(pref)) {
336 ret.add(new A(PreferenceLevel.prolog2abbv(pref)+" "+getDayHeader(d).replace("<br>", " ")+" "+getStartTime(a)+" - "+getEndTime(b)).color(PreferenceLevel.prolog2color(pref)));
337 }
338 pref = p; a = b = t;
339 } else {
340 b = t;
341 }
342 }
343 if (pref!=null && !"@".equals(pref) && !PreferenceLevel.sNeutral.equals(pref)) {
344 ret.add(new A(PreferenceLevel.prolog2abbv(pref)+" "+getDayHeader(d).replace("<br>", " ")+" "+getStartTime(a)+" - "+getEndTime(b)).color(PreferenceLevel.prolog2color(pref)));
345 }
346 }
347 return ret;
348 }
349 }
350}
JavaSource/org/unitime/timetable/export/rooms/RoomsExporter.java
(229 / 0)
  
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*/
20package org.unitime.timetable.export.rooms;
21
22import java.io.IOException;
23import java.util.ArrayList;
24import java.util.Collection;
25import java.util.Collections;
26import java.util.Enumeration;
27import java.util.List;
28
29import org.unitime.localization.impl.Localization;
30import org.unitime.timetable.defaults.CommonValues;
31import org.unitime.timetable.defaults.UserProperty;
32import org.unitime.timetable.events.EventAction.EventContext;
33import org.unitime.timetable.export.ExportHelper;
34import org.unitime.timetable.export.Exporter;
35import org.unitime.timetable.gwt.client.rooms.RoomsComparator;
36import org.unitime.timetable.gwt.resources.GwtConstants;
37import org.unitime.timetable.gwt.resources.GwtMessages;
38import org.unitime.timetable.gwt.shared.EventInterface.FilterRpcRequest;
39import org.unitime.timetable.gwt.shared.EventInterface.FilterRpcResponse;
40import org.unitime.timetable.gwt.shared.EventInterface.FilterRpcResponse.Entity;
41import org.unitime.timetable.gwt.shared.RoomInterface.DepartmentInterface;
42import org.unitime.timetable.gwt.shared.RoomInterface.ExamTypeInterface;
43import org.unitime.timetable.gwt.shared.RoomInterface.FeatureInterface;
44import org.unitime.timetable.gwt.shared.RoomInterface.GroupInterface;
45import org.unitime.timetable.gwt.shared.RoomInterface.RoomDetailInterface;
46import org.unitime.timetable.gwt.shared.RoomInterface.RoomFilterRpcRequest;
47import org.unitime.timetable.gwt.shared.RoomInterface.RoomFlag;
48import org.unitime.timetable.gwt.shared.RoomInterface.RoomsPageMode;
49import org.unitime.timetable.model.Session;
50import org.unitime.timetable.model.dao.SessionDAO;
51import org.unitime.timetable.security.UserAuthority;
52import org.unitime.timetable.security.UserContext;
53import org.unitime.timetable.security.context.UniTimeUserContext;
54import org.unitime.timetable.security.rights.Right;
55import org.unitime.timetable.server.rooms.RoomDetailsBackend;
56import org.unitime.timetable.webutil.RequiredTimeTable;
57
58/**
59 * @author Tomas Muller
60 */
61public abstract class RoomsExporter implements Exporter {
62 protected static final GwtMessages MESSAGES = Localization.create(GwtMessages.class);
63 protected static final GwtConstants CONSTANTS = Localization.create(GwtConstants.class);
64
65 @Override
66 public void export(ExportHelper helper) throws IOException {
67 Long sessionId = helper.getAcademicSessionId();
68 if (sessionId == null)
69 throw new IllegalArgumentException("Academic session not provided, please set the term parameter.");
70
71 Session session = SessionDAO.getInstance().get(sessionId);
72 if (session == null)
73 throw new IllegalArgumentException("Given academic session no longer exists.");
74
75 RoomFilterRpcRequest request = new RoomFilterRpcRequest();
76 request.setCommand(FilterRpcRequest.Command.ENUMERATE);
77 request.setSessionId(sessionId);
78 for (Enumeration<String> e = helper.getParameterNames(); e.hasMoreElements(); ) {
79 String command = e.nextElement();
80 if (command.equals("r:text")) {
81 request.setText(helper.getParameter("r:text"));
82 } else if (command.startsWith("r:")) {
83 for (String value: helper.getParameterValues(command))
84 request.addOption(command.substring(2), value);
85 }
86 }
87 request.setOption("flag", "gridAsText");
88
89 UserContext u = helper.getSessionContext().getUser();
90 String user = helper.getParameter("user");
91 if (u == null && user != null && !checkRights(helper)) {
92 u = new UniTimeUserContext(user, null, null, null);
93 String role = helper.getParameter("role");
94 if (role != null) {
95 for (UserAuthority a: u.getAuthorities()) {
96 if (a.getAcademicSession() != null && a.getAcademicSession().getQualifierId().equals(sessionId) && role.equals(a.getRole())) {
97 u.setCurrentAuthority(a); break;
98 }
99 }
100 }
101 }
102 EventContext context = new EventContext(helper.getSessionContext(), u, sessionId);
103 if (u != null && u.getExternalUserId() != null)
104 request.setOption("user", u.getExternalUserId());
105
106 int deptMode = 0;
107 if (helper.getParameter("dm") != null)
108 deptMode = Integer.parseInt(helper.getParameter("dm"));
109
110 if (!helper.isRequestEncoded())
111 context.checkPermission(Right.Rooms);
112
113 FilterRpcResponse response = new FilterRpcResponse();
114 new RoomDetailsBackend().enumarate(request, response, context);
115
116 List<RoomDetailInterface> rooms = new ArrayList<RoomDetailInterface>();
117 if (response.hasResults()) {
118 for (Entity e: response.getResults())
119 rooms.add((RoomDetailInterface)e);
120 }
121
122 if (helper.getParameter("sort") != null) {
123 RoomsComparator cmp = null;
124 try {
125 int sort = Integer.parseInt(helper.getParameter("sort"));
126 if (sort > 0) {
127 cmp = new RoomsComparator(RoomsComparator.Column.values()[sort - 1], true);
128 } else if (sort < 0) {
129 cmp = new RoomsComparator(RoomsComparator.Column.values()[-1 - sort], false);
130 }
131 } catch (Exception e) {}
132 if (cmp != null)
133 Collections.sort(rooms, cmp);
134 }
135
136 int roomCookieFlags = (helper.getParameter("flags") == null ? RoomsPageMode.COURSES.getFlags() : Integer.parseInt(helper.getParameter("flags")));
137
138 boolean vertical = true;
139 if (helper.getParameter("horizontal") != null)
140 vertical = "0".equals(helper.getParameter("horizontal"));
141 else if (context.getUser() != null)
142 vertical = CommonValues.VerticalGrid.eq(context.getUser().getProperty(UserProperty.GridOrientation));
143
144 String mode = helper.getParameter("mode");
145 if (mode == null && context.getUser() != null)
146 mode = RequiredTimeTable.getTimeGridSize(context.getUser());
147
148 boolean gridAsText = (context.getUser() == null ? false : CommonValues.TextGrid.eq(UserProperty.GridOrientation.get(context.getUser())));
149
150 print(helper, rooms, request.getOption("department"), roomCookieFlags, deptMode, gridAsText, vertical, mode);
151 }
152
153 protected abstract void print(ExportHelper helper, List<RoomDetailInterface> rooms, String department, int roomCookieFlags, int deptMode, boolean gridAsText, boolean vertical, String mode) throws IOException;
154
155 protected boolean checkRights(ExportHelper helper) {
156 return !helper.isRequestEncoded();
157 }
158
159 protected void hideColumns(Printer out, List<RoomDetailInterface> rooms, int roomCookieFlags) {
160 for (RoomFlag flag: RoomFlag.values()) {
161 if (!flag.in(roomCookieFlags)) hideColumn(out, rooms, flag);
162 }
163 }
164
165 protected void hideColumn(Printer out, List<RoomDetailInterface> rooms, RoomFlag flag) {}
166
167 protected String dept2string(DepartmentInterface d, int deptMode) {
168 if (d == null) return "";
169 switch (deptMode) {
170 case 0: return d.getDeptCode();
171 case 1: return d.getExtAbbreviationWhenExist();
172 case 2: return d.getExtLabelWhenExist();
173 case 3: return d.getExtAbbreviationWhenExist() + " - " + d.getExtLabelWhenExist();
174 case 4: return d.getDeptCode() + " - " + d.getExtLabelWhenExist();
175 default: return d.getDeptCode();
176 }
177 }
178
179 protected String dept2string(Collection<DepartmentInterface> departments, int deptMode, String separator) {
180 if (departments == null || departments.isEmpty()) return "";
181 String ret = "";
182 for (DepartmentInterface d: departments) {
183 ret += (ret.isEmpty() ? "" : separator) + dept2string(d, deptMode);
184 }
185 return ret;
186 }
187
188 protected String pref2string(Collection<DepartmentInterface> departments, int deptMode, String separator) {
189 if (departments == null || departments.isEmpty()) return "";
190 String ret = "";
191 for (DepartmentInterface d: departments) {
192 if (d.getPreference() == null) continue;
193 ret += (ret.isEmpty() ? "" : separator) + d.getPreference().getName() + " " + dept2string(d, deptMode);
194 }
195 return ret;
196 }
197
198 protected String examTypes2string(Collection<ExamTypeInterface> types, String separator) {
199 if (types == null || types.isEmpty()) return "";
200 String ret = "";
201 for (ExamTypeInterface t: types) {
202 ret += (ret.isEmpty() ? "" : separator) + t.getLabel();
203 }
204 return ret;
205 }
206
207 protected String features2string(Collection<FeatureInterface> features, String separator) {
208 if (features == null || features.isEmpty()) return "";
209 String ret = "";
210 for (FeatureInterface f: features) {
211 if (f.getType() != null)
212 ret += (ret.isEmpty() ? "" : separator) + f.getLabel() + " (" + f.getType().getAbbreviation() + ")";
213 else if (f.getDepartment() != null)
214 ret += (ret.isEmpty() ? "" : separator) + f.getLabel() + " (" + f.getDepartment().getExtAbbreviationWhenExist() + ")";
215 else
216 ret += (ret.isEmpty() ? "" : separator) + f.getLabel();
217 }
218 return ret;
219 }
220
221 protected String groups2string(Collection<GroupInterface> groups, String separator) {
222 if (groups == null || groups.isEmpty()) return "";
223 String ret = "";
224 for (GroupInterface g: groups) {
225 ret += (ret.isEmpty() ? "" : separator) + g.getLabel() + (g.getDepartment() == null ? "" : " (" + g.getDepartment().getExtAbbreviationWhenExist() + ")");
226 }
227 return ret;
228 }
229}
JavaSource/org/unitime/timetable/gwt/client/Pages.java
(5 / 0)
  
3131import org.unitime.timetable.gwt.client.reservations.ReservationsPage;
3232import org.unitime.timetable.gwt.client.rooms.RoomPicturesPage;
3333import org.unitime.timetable.gwt.client.rooms.RoomSharingPage;
34import org.unitime.timetable.gwt.client.rooms.RoomsPage;
3435import org.unitime.timetable.gwt.client.rooms.TravelTimes;
3536import org.unitime.timetable.gwt.client.sectioning.SectioningReports;
3637import org.unitime.timetable.gwt.client.sectioning.SectioningStatusPage;
146146 roompictures(new PageFactory() {
147147 public Widget create() { return new RoomPicturesPage(); }
148148 public String name(GwtMessages messages) { return messages.pageRoomPictures(); }
149 }),
150 rooms(new PageFactory() {
151 public Widget create() { return new RoomsPage(); }
152 public String name(GwtMessages messages) { return messages.pageRooms(); }
149153 }),
150154 ;
151155
JavaSource/org/unitime/timetable/gwt/client/rooms/RoomCookie.java
(145 / 0)
  
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*/
20package org.unitime.timetable.gwt.client.rooms;
21
22import java.util.Date;
23
24import org.unitime.timetable.gwt.resources.GwtConstants;
25import org.unitime.timetable.gwt.shared.RoomInterface.RoomFlag;
26import org.unitime.timetable.gwt.shared.RoomInterface.RoomsPageMode;
27
28import com.google.gwt.core.client.GWT;
29import com.google.gwt.user.client.Cookies;
30
31/**
32 * @author Tomas Muller
33 */
34public class RoomCookie {
35 private static RoomCookie sInstance = null;
36 protected static final GwtConstants CONSTANTS = GWT.create(GwtConstants.class);
37
38 private int[] iFlags = null;
39 private String[] iHash = null;
40 private int iSortRoomsBy = 0;
41 private int iDeptMode = 1;
42 private boolean iRoomsHorizontal = true;
43 private String iMode = "";
44
45 private RoomCookie() {
46 iFlags = new int[RoomsPageMode.values().length];
47 iHash = new String[RoomsPageMode.values().length];
48 for (int i = 0; i < iFlags.length; i++) {
49 iFlags[i] = RoomsPageMode.values()[i].getFlags();
50 iHash[i] = RoomsPageMode.values()[i].getQuery();
51 }
52 try {
53 String cookie = Cookies.getCookie("UniTime:Room");
54 if (cookie != null) {
55 String[] params = cookie.split("\\|");
56 int idx = 0;
57 iSortRoomsBy = Integer.valueOf(params[idx++]);
58 iRoomsHorizontal = !"F".equals(params[idx++]);
59 iMode = params[idx++];
60 iDeptMode = Integer.valueOf(params[idx++]);
61 for (int i = 0; i < iFlags.length; i++) {
62 iFlags[i] = Integer.parseInt(params[idx++]);
63 iHash[i] = params[idx++];
64 }
65 }
66 } catch (Exception e) {
67 }
68 }
69
70 private void save() {
71 String cookie = iSortRoomsBy + "|" + (iRoomsHorizontal ? "T" : "F") + "|" + iMode + "|" + iDeptMode;
72 for (int i = 0; i < iFlags.length; i++) {
73 cookie += "|" + iFlags[i] + "|" + (iHash[i] == null ? "" : iHash[i]);
74 }
75 Date expires = new Date(new Date().getTime() + 604800000l); // expires in 7 days
76 Cookies.setCookie("UniTime:Room", cookie, expires);
77 }
78
79 public static RoomCookie getInstance() {
80 if (sInstance == null)
81 sInstance = new RoomCookie();
82 return sInstance;
83 }
84
85 public boolean get(RoomsPageMode mode, RoomFlag f) { return f.in(iFlags[mode.ordinal()]); }
86 public void set(RoomsPageMode mode, RoomFlag f, boolean value) {
87 iFlags[mode.ordinal()] = (value ? f.set(iFlags[mode.ordinal()]) : f.clear(iFlags[mode.ordinal()]));
88 save();
89 }
90 public int getFlags(RoomsPageMode mode) { return iFlags[mode.ordinal()]; }
91
92 public boolean hasHash(RoomsPageMode mode) {
93 return iHash[mode.ordinal()] != null && !iHash[mode.ordinal()].isEmpty();
94 }
95
96 public String getHash(RoomsPageMode mode) {
97 return iHash[mode.ordinal()];
98 }
99
100 public void setHash(RoomsPageMode mode, String hash) {
101 iHash[mode.ordinal()] = hash;
102 save();
103 }
104
105 public int getRoomsSortBy() {
106 return iSortRoomsBy;
107 }
108
109 public void setSortRoomsBy(int sortRoomsBy) {
110 iSortRoomsBy = sortRoomsBy;
111 save();
112 }
113
114 public boolean areRoomsHorizontal() {
115 return iRoomsHorizontal;
116 }
117
118 public void setRoomsHorizontal(boolean roomsHorizontal) {
119 iRoomsHorizontal = roomsHorizontal;
120 save();
121 }
122
123 public String getMode() {
124 return iMode;
125 }
126
127 public boolean hasMode() {
128 return !iMode.isEmpty();
129 }
130
131 public void setMode(boolean horizontal, String mode) {
132 iRoomsHorizontal = horizontal;
133 iMode = (mode == null ? "" : mode);
134 save();
135 }
136
137 public int getDeptMode() {
138 return iDeptMode;
139 }
140
141 public void setDeptMode(int deptMode) {
142 iDeptMode = deptMode;
143 save();
144 }
145}
JavaSource/org/unitime/timetable/gwt/client/rooms/RoomFilterBox.java
(39 / 0)
  
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*/
20package org.unitime.timetable.gwt.client.rooms;
21
22import org.unitime.timetable.gwt.shared.AcademicSessionProvider;
23import org.unitime.timetable.gwt.shared.RoomInterface.RoomFilterRpcRequest;
24
25/**
26 * @author Tomas Muller
27 */
28public class RoomFilterBox extends org.unitime.timetable.gwt.client.events.RoomFilterBox {
29
30 public RoomFilterBox(AcademicSessionProvider session) {
31 super(session);
32 }
33
34 @Override
35 public RoomFilterRpcRequest createRpcRequest() {
36 return new RoomFilterRpcRequest();
37 }
38
39}
JavaSource/org/unitime/timetable/gwt/client/rooms/RoomSharingWidget.java
(8 / 11)
  
5050import com.google.gwt.event.logical.shared.ValueChangeEvent;
5151import com.google.gwt.event.logical.shared.ValueChangeHandler;
5252import com.google.gwt.event.shared.HandlerRegistration;
53import com.google.gwt.user.client.Cookies;
5453import com.google.gwt.user.client.rpc.AsyncCallback;
5554import com.google.gwt.user.client.ui.AbsolutePanel;
5655import com.google.gwt.user.client.ui.Button;
168168
169169 iModeSelection.setSelectedIndex(0);
170170
171 String cookie = Cookies.getCookie("UniTime:RoomSharing");
172 if (cookie != null) {
173 try {
174 for (int i = 0; i < iModel.getModes().size(); i++)
175 if (cookie.startsWith(iModel.getModes().get(i).toString())) {
176 iModeSelection.setSelectedIndex(i); break;
177 }
178 iHorizontal.setValue(cookie.endsWith("|1"));
179 } catch (Exception e) {}
171 RoomCookie cookie = RoomCookie.getInstance();
172 if (cookie.hasMode()) {
173 for (int i = 0; i < iModel.getModes().size(); i++)
174 if (cookie.getMode().equals(iModel.getModes().get(i).toHex())) {
175 iModeSelection.setSelectedIndex(i); break;
176 }
177 iHorizontal.setValue(cookie.areRoomsHorizontal());
180178 } else {
181179 iHorizontal.setValue(model.isDefaultHorizontal());
182180 iModeSelection.setSelectedIndex(iModel.getDefaultMode());
256256
257257 public void setMode(final RoomSharingDisplayMode mode, final boolean horizontal) {
258258 iMode = mode;
259 Cookies.setCookie("UniTime:RoomSharing", mode.toString() + "|" + (horizontal ? "1" : "0"));
259 RoomCookie.getInstance().setMode(horizontal, mode.toHex());
260260 iPanel.clear();
261261
262262 if (horizontal) {
JavaSource/org/unitime/timetable/gwt/client/rooms/RoomsComparator.java
(133 / 0)
  
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*/
20package org.unitime.timetable.gwt.client.rooms;
21
22import java.util.Comparator;
23
24import org.unitime.timetable.gwt.shared.RoomInterface.RoomDetailInterface;
25
26/**
27 * @author Tomas Muller
28 */
29public class RoomsComparator implements Comparator<RoomDetailInterface> {
30 public static enum Column {
31 NAME, TYPE, CAPACITY, EXAM_CAPACITY, DISTANCE, ROOM_CHECK, CONTROL, EVENT_DEPT, EVENT_STATUS, EVENT_MESSAGE, BREAK_TIME,
32 }
33 private Column iColumn;
34 private boolean iAsc;
35
36 public int compareById(RoomDetailInterface r1, RoomDetailInterface r2) {
37 return compare(r1.getUniqueId(), r2.getUniqueId());
38 }
39
40 public int compareByName(RoomDetailInterface r1, RoomDetailInterface r2) {
41 return compare(r1.getLabel(), r2.getLabel());
42 }
43
44 public int compareByType(RoomDetailInterface r1, RoomDetailInterface r2) {
45 return compare(r1.getRoomType().getLabel(), r2.getRoomType().getLabel());
46 }
47
48 public int compareByCapacity(RoomDetailInterface r1, RoomDetailInterface r2) {
49 return -compare(r1.getCapacity(), r2.getCapacity());
50 }
51
52 public int compareByExamCapacity(RoomDetailInterface r1, RoomDetailInterface r2) {
53 return -compare(r1.getExamCapacity() == null ? r1.getCapacity() : r1.getExamCapacity(),
54 r2.getExamCapacity() == null ? r2.getCapacity() : r2.getExamCapacity());
55 }
56
57 public int compareByDistance(RoomDetailInterface r1, RoomDetailInterface r2) {
58 return -compare(r1.isIgnoreTooFar(), r2.isIgnoreTooFar());
59 }
60
61 public int compareByRoomCheck(RoomDetailInterface r1, RoomDetailInterface r2) {
62 return -compare(r1.isIgnoreRoomCheck(), r2.isIgnoreRoomCheck());
63 }
64
65 public int compareByControl(RoomDetailInterface r1, RoomDetailInterface r2) {
66 return compare(r1.getControlDepartment() == null ? null : r1.getControlDepartment().getAbbreviationOrCode(),
67 r2.getControlDepartment() == null ? null : r2.getControlDepartment().getAbbreviationOrCode());
68 }
69
70 public int compareByEventDepartment(RoomDetailInterface r1, RoomDetailInterface r2) {
71 return compare(r1.getEventDepartment() == null ? null : r1.getEventDepartment().getAbbreviationOrCode(),
72 r2.getEventDepartment() == null ? null : r2.getEventDepartment().getAbbreviationOrCode());
73 }
74
75 public int compareByEventStatus(RoomDetailInterface r1, RoomDetailInterface r2) {
76 return compare(r1.getEventStatus(), r2.getEventStatus());
77 }
78
79 public int compareByEventMessage(RoomDetailInterface r1, RoomDetailInterface r2) {
80 return compare(r1.getEventNote(), r2.getEventNote());
81 }
82
83 public int compareByBreakTime(RoomDetailInterface r1, RoomDetailInterface r2) {
84 return compare(r1.getBreakTime(), r2.getBreakTime());
85 }
86
87 protected int compareByColumn(RoomDetailInterface r1, RoomDetailInterface r2) {
88 switch (iColumn) {
89 case NAME: return compareByName(r1, r2);
90 case TYPE: return compareByType(r1, r2);
91 case CAPACITY: return compareByCapacity(r1, r2);
92 case EXAM_CAPACITY: return compareByExamCapacity(r1, r2);
93 case DISTANCE: return compareByDistance(r1, r2);
94 case ROOM_CHECK: return compareByRoomCheck(r1, r2);
95 case CONTROL: return compareByControl(r1, r2);
96 case EVENT_DEPT: return compareByEventDepartment(r1, r2);
97 case EVENT_STATUS: return compareByEventStatus(r1, r2);
98 case EVENT_MESSAGE: return compareByEventMessage(r1, r2);
99 case BREAK_TIME: return compareByBreakTime(r1, r2);
100 default: return compareByName(r1, r2);
101 }
102 }
103
104 public RoomsComparator(Column column, boolean asc) {
105 iColumn = column;
106 iAsc = asc;
107 }
108
109 @Override
110 public int compare(RoomDetailInterface r1, RoomDetailInterface r2) {
111 int cmp = compareByColumn(r1, r2);
112 if (cmp == 0) cmp = compareByName(r1, r2);
113 if (cmp == 0) cmp = compareById(r1, r2);
114 return (iAsc ? cmp : -cmp);
115 }
116
117 protected int compare(String s1, String s2) {
118 if (s1 == null || s1.isEmpty()) {
119 return (s2 == null || s2.isEmpty() ? 0 : 1);
120 } else {
121 return (s2 == null || s2.isEmpty() ? -1 : s1.compareToIgnoreCase(s2));
122 }
123 }
124
125 protected int compare(Number n1, Number n2) {
126 return (n1 == null ? n2 == null ? 0 : -1 : n2 == null ? -1 : Double.compare(n1.doubleValue(), n2.doubleValue()));
127 }
128
129 protected int compare(Boolean b1, Boolean b2) {
130 return (b1 == null ? b2 == null ? 0 : -1 : b2 == null ? -1 : (b1.booleanValue() == b2.booleanValue()) ? 0 : (b1.booleanValue() ? 1 : -1));
131 }
132
133}
JavaSource/org/unitime/timetable/gwt/client/rooms/RoomsPage.java
(337 / 0)
  
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*/
20package org.unitime.timetable.gwt.client.rooms;
21
22import java.util.ArrayList;
23import java.util.List;
24import java.util.Map;
25import java.util.Set;
26
27import org.unitime.timetable.gwt.client.ToolBox;
28import org.unitime.timetable.gwt.client.aria.AriaButton;
29import org.unitime.timetable.gwt.client.page.UniTimeNotifications;
30import org.unitime.timetable.gwt.client.rooms.TravelTimes.TravelTimeResponse;
31import org.unitime.timetable.gwt.client.rooms.TravelTimes.TravelTimesRequest;
32import org.unitime.timetable.gwt.client.widgets.LoadingWidget;
33import org.unitime.timetable.gwt.client.widgets.FilterBox.Chip;
34import org.unitime.timetable.gwt.command.client.GwtRpcService;
35import org.unitime.timetable.gwt.command.client.GwtRpcServiceAsync;
36import org.unitime.timetable.gwt.resources.GwtMessages;
37import org.unitime.timetable.gwt.resources.GwtResources;
38import org.unitime.timetable.gwt.shared.AcademicSessionProvider;
39import org.unitime.timetable.gwt.shared.EventInterface.EncodeQueryRpcRequest;
40import org.unitime.timetable.gwt.shared.EventInterface.EncodeQueryRpcResponse;
41import org.unitime.timetable.gwt.shared.EventInterface.FilterRpcRequest;
42import org.unitime.timetable.gwt.shared.EventInterface.FilterRpcResponse;
43import org.unitime.timetable.gwt.shared.RoomInterface.RoomDetailInterface;
44import org.unitime.timetable.gwt.shared.RoomInterface.RoomFlag;
45import org.unitime.timetable.gwt.shared.RoomInterface.RoomPropertiesInterface;
46import org.unitime.timetable.gwt.shared.RoomInterface.RoomPropertiesRequest;
47import org.unitime.timetable.gwt.shared.RoomInterface.RoomsPageMode;
48
49import com.google.gwt.core.client.GWT;
50import com.google.gwt.dom.client.Style.Cursor;
51import com.google.gwt.dom.client.Style.Unit;
52import com.google.gwt.event.dom.client.ClickEvent;
53import com.google.gwt.event.dom.client.ClickHandler;
54import com.google.gwt.event.logical.shared.ValueChangeEvent;
55import com.google.gwt.event.logical.shared.ValueChangeHandler;
56import com.google.gwt.http.client.URL;
57import com.google.gwt.user.client.Command;
58import com.google.gwt.user.client.History;
59import com.google.gwt.user.client.Window.Location;
60import com.google.gwt.user.client.rpc.AsyncCallback;
61import com.google.gwt.user.client.ui.Composite;
62import com.google.gwt.user.client.ui.HasHorizontalAlignment;
63import com.google.gwt.user.client.ui.HasVerticalAlignment;
64import com.google.gwt.user.client.ui.HorizontalPanel;
65import com.google.gwt.user.client.ui.Label;
66import com.google.gwt.user.client.ui.MenuBar;
67import com.google.gwt.user.client.ui.MenuItem;
68import com.google.gwt.user.client.ui.PopupPanel;
69import com.google.gwt.user.client.ui.SimplePanel;
70import com.google.gwt.user.client.ui.UIObject;
71import com.google.gwt.user.client.ui.VerticalPanel;
72
73/**
74 * @author Tomas Muller
75 */
76public class RoomsPage extends Composite {
77 protected static final GwtMessages MESSAGES = GWT.create(GwtMessages.class);
78 public static final GwtResources RESOURCES = GWT.create(GwtResources.class);
79 private static GwtRpcServiceAsync RPC = GWT.create(GwtRpcService.class);
80
81 private RoomFilterBox iFilter = null;
82 private AriaButton iSearch = null;
83 private AriaButton iNew = null;
84 private AriaButton iExport = null;
85 private RoomsTable iRoomsTable = null;
86
87 private VerticalPanel iRoomsPanel = null;
88
89 private SimplePanel iPanel = null;
90 private HorizontalPanel iFilterPanel = null;
91 private RoomsPageMode iMode = RoomsPageMode.COURSES;
92 private RoomPropertiesInterface iProperties = null;
93
94 public RoomsPage() {
95 if (Location.getParameter("mode") != null)
96 iMode = RoomsPageMode.valueOf(Location.getParameter("mode").toUpperCase());
97
98 iPanel = new SimplePanel();
99
100 iRoomsPanel = new VerticalPanel();
101
102 iFilterPanel = new HorizontalPanel();
103 iFilterPanel.setSpacing(3);
104
105 Label filterLabel = new Label(MESSAGES.propFilter());
106 iFilterPanel.add(filterLabel);
107 iFilterPanel.setCellVerticalAlignment(filterLabel, HasVerticalAlignment.ALIGN_MIDDLE);
108
109 iFilter = new RoomFilterBox(new Session());
110 iFilter.setValue("department:Managed");
111 iFilterPanel.add(iFilter);
112
113 iSearch = new AriaButton(MESSAGES.buttonSearch());
114 iSearch.addStyleName("unitime-NoPrint");
115 iFilterPanel.add(iSearch);
116
117 iExport = new AriaButton(MESSAGES.buttonExport());
118 iExport.addStyleName("unitime-NoPrint");
119 iExport.setEnabled(false);
120 iFilterPanel.add(iExport);
121
122 iNew = new AriaButton(MESSAGES.buttonAddNew());
123 iNew.setEnabled(false);
124 iNew.addStyleName("unitime-NoPrint");
125 iFilterPanel.add(iNew);
126
127 iRoomsPanel.add(iFilterPanel);
128 iRoomsPanel.setCellHorizontalAlignment(iFilterPanel, HasHorizontalAlignment.ALIGN_CENTER);
129
130 iRoomsTable = new RoomsTable(iMode);
131 iRoomsTable.getElement().getStyle().setMarginTop(10, Unit.PX);
132
133 iRoomsPanel.add(iRoomsTable);
134
135 iRoomsPanel.setWidth("100%");
136
137 iPanel.setWidget(iRoomsPanel);
138
139 initWidget(iPanel);
140
141 iSearch.addClickHandler(new ClickHandler() {
142 @Override
143 public void onClick(ClickEvent event) {
144 History.newItem(iFilter.getValue(), false);
145 search();
146 }
147 });
148
149 History.addValueChangeHandler(new ValueChangeHandler<String>() {
150 @Override
151 public void onValueChange(ValueChangeEvent<String> event) {
152 iFilter.setValue(event.getValue(), true);
153 if (!iFilter.getValue().isEmpty())
154 search();
155 }
156 });
157
158 if (History.getToken() != null)
159 iFilter.setValue(History.getToken(), true);
160 else
161 iFilter.setValue(RoomCookie.getInstance().getHash(iMode), true);
162
163 RPC.execute(new RoomPropertiesRequest(), new AsyncCallback<RoomPropertiesInterface>() {
164 @Override
165 public void onFailure(Throwable caught) {
166 }
167
168 @Override
169 public void onSuccess(RoomPropertiesInterface result) {
170 iProperties = result;
171 if (iProperties.isCanExportCsv() || iProperties.isCanExportPdf())
172 iExport.setEnabled(true);
173 }
174 });
175
176 iExport.addClickHandler(new ClickHandler() {
177 @Override
178 public void onClick(ClickEvent event) {
179 final PopupPanel popup = new PopupPanel(true);
180 MenuBar menu = new MenuBar(true);
181 if (iProperties.isCanExportPdf()) {
182 MenuItem exportPdf = new MenuItem(MESSAGES.opExportPDF(), true, new Command() {
183 @Override
184 public void execute() {
185 popup.hide();
186 export("rooms.pdf");
187 }
188 });
189 exportPdf.getElement().getStyle().setCursor(Cursor.POINTER);
190 menu.addItem(exportPdf);
191 }
192 if (iProperties.isCanExportCsv()) {
193 MenuItem exportCsv = new MenuItem(MESSAGES.opExportCSV(), true, new Command() {
194 @Override
195 public void execute() {
196 popup.hide();
197 export("rooms.csv");
198 }
199 });
200 exportCsv.getElement().getStyle().setCursor(Cursor.POINTER);
201 menu.addItem(exportCsv);
202 }
203 popup.add(menu);
204 popup.showRelativeTo((UIObject)event.getSource());
205 menu.focus();
206 }
207 });
208 }
209
210 protected void export(String format) {
211 RPC.execute(EncodeQueryRpcRequest.encode(query(format)), new AsyncCallback<EncodeQueryRpcResponse>() {
212 @Override
213 public void onFailure(Throwable caught) {
214 }
215 @Override
216 public void onSuccess(EncodeQueryRpcResponse result) {
217 ToolBox.open(GWT.getHostPageBaseURL() + "export?q=" + result.getQuery());
218 }
219 });
220 }
221
222 protected String query(String format) {
223 RoomCookie cookie = RoomCookie.getInstance();
224 int flags = cookie.getFlags(iMode);
225 for (RoomFlag f: RoomFlag.values())
226 if (!f.isShowWhenEmpty() && !f.in(iRoomsTable.getFlags()))
227 flags = f.clear(flags);
228 String query = "output=" + format + "&flags=" + flags + "&sort=" + cookie.getRoomsSortBy() +
229 "&horizontal=" + (cookie.areRoomsHorizontal() ? "1" : "0") + (cookie.hasMode() ? "&mode=" + cookie.getMode() : "") +
230 "&dm=" + cookie.getDeptMode();
231 if (iProperties.getAcademicSessionId() != null)
232 query += "&sid=" + iProperties.getAcademicSessionId();
233
234 FilterRpcRequest rooms = iFilter.getElementsRequest();
235 if (rooms.hasOptions()) {
236 for (Map.Entry<String, Set<String>> option: rooms.getOptions().entrySet()) {
237 for (String value: option.getValue()) {
238 query += "&r:" + option.getKey() + "=" + URL.encodeQueryString(value);
239 }
240 }
241 }
242
243 if (rooms.getText() != null && !rooms.getText().isEmpty())
244 query += "&r:text=" + URL.encodeQueryString(rooms.getText());
245
246 return query;
247 }
248
249 protected void search() {
250 iRoomsTable.clearTable(1);
251 LoadingWidget.execute(iFilter.getElementsRequest(), new AsyncCallback<FilterRpcResponse>() {
252 @Override
253 public void onFailure(Throwable caught) {
254 iFilter.setErrorHint(MESSAGES.failedToLoadRooms(caught.getMessage()));
255 UniTimeNotifications.error(MESSAGES.failedToLoadRooms(caught.getMessage()), caught);
256 }
257 @Override
258 public void onSuccess(FilterRpcResponse result) {
259 iFilter.clearHint();
260 if (result == null || result.getResults() == null || result.getResults().isEmpty()) {
261 iFilter.setErrorHint(MESSAGES.errorNoRoomsMatchingFilter());
262 } else {
263 Chip dept = iFilter.getChip("department");
264 for (FilterRpcResponse.Entity entity: result.getResults())
265 iRoomsTable.addRoom((RoomDetailInterface)entity, dept == null ? null : dept.getValue());
266 }
267 }
268 }, MESSAGES.waitLoadingRooms());
269 }
270
271 private class Session implements AcademicSessionProvider {
272 private List<AcademicSessionChangeHandler> iHandlers = new ArrayList<AcademicSessionProvider.AcademicSessionChangeHandler>();
273 private Long iId;
274 private String iName;
275
276 private Session() {
277 RPC.execute(TravelTimesRequest.init(), new AsyncCallback<TravelTimeResponse>() {
278
279 @Override
280 public void onFailure(Throwable caught) {
281 iFilter.setErrorHint(MESSAGES.failedToInitialize(caught.getMessage()));
282 ToolBox.checkAccess(caught);
283 }
284
285 @Override
286 public void onSuccess(TravelTimeResponse result) {
287 iId = result.getSessionId(); iName = result.getSessionName();
288 fireChange();
289 }
290 });
291 }
292
293 @Override
294 public void selectSession(Long sessionId, AsyncCallback<Boolean> callback) {
295 callback.onSuccess(false);
296 }
297
298 @Override
299 public String getAcademicSessionName() {
300 return iName;
301 }
302
303 @Override
304 public Long getAcademicSessionId() {
305 return iId;
306 }
307
308 @Override
309 public void addAcademicSessionChangeHandler(AcademicSessionChangeHandler handler) {
310 iHandlers.add(handler);
311 }
312
313 @Override
314 public AcademicSessionInfo getAcademicSessionInfo() {
315 return null;
316 }
317
318 private void fireChange() {
319 AcademicSessionProvider.AcademicSessionChangeEvent event = new AcademicSessionProvider.AcademicSessionChangeEvent() {
320 @Override
321 public Long getNewAcademicSessionId() {
322 return iId;
323 }
324 @Override
325 public Long getOldAcademicSessionId() {
326 return null;
327 }
328 @Override
329 public boolean isChanged() {
330 return true;
331 }
332 };
333 for (AcademicSessionChangeHandler h: iHandlers)
334 h.onAcademicSessionChange(event);
335 }
336 }
337}
JavaSource/org/unitime/timetable/gwt/client/rooms/RoomsTable.java
(932 / 0)
  
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*/
20package org.unitime.timetable.gwt.client.rooms;
21
22import java.util.ArrayList;
23import java.util.HashMap;
24import java.util.List;
25import java.util.Map;
26
27import org.unitime.timetable.gwt.client.widgets.P;
28import org.unitime.timetable.gwt.client.widgets.UniTimeTable;
29import org.unitime.timetable.gwt.client.widgets.UniTimeTableHeader;
30import org.unitime.timetable.gwt.client.widgets.UniTimeTableHeader.AriaOperation;
31import org.unitime.timetable.gwt.client.widgets.UniTimeTableHeader.Operation;
32import org.unitime.timetable.gwt.command.client.GwtRpcService;
33import org.unitime.timetable.gwt.command.client.GwtRpcServiceAsync;
34import org.unitime.timetable.gwt.resources.GwtAriaMessages;
35import org.unitime.timetable.gwt.resources.GwtConstants;
36import org.unitime.timetable.gwt.resources.GwtMessages;
37import org.unitime.timetable.gwt.resources.GwtResources;
38import org.unitime.timetable.gwt.shared.RoomInterface.DepartmentInterface;
39import org.unitime.timetable.gwt.shared.RoomInterface.ExamTypeInterface;
40import org.unitime.timetable.gwt.shared.RoomInterface.FeatureInterface;
41import org.unitime.timetable.gwt.shared.RoomInterface.GroupInterface;
42import org.unitime.timetable.gwt.shared.RoomInterface.RoomDetailInterface;
43import org.unitime.timetable.gwt.shared.RoomInterface.RoomFlag;
44import org.unitime.timetable.gwt.shared.RoomInterface.RoomPropertyInterface;
45import org.unitime.timetable.gwt.shared.RoomInterface.RoomsPageMode;
46
47import com.google.gwt.core.client.GWT;
48import com.google.gwt.event.dom.client.MouseOutEvent;
49import com.google.gwt.event.dom.client.MouseOutHandler;
50import com.google.gwt.event.dom.client.MouseOverEvent;
51import com.google.gwt.event.dom.client.MouseOverHandler;
52import com.google.gwt.user.client.TakesValue;
53import com.google.gwt.user.client.ui.HTML;
54import com.google.gwt.user.client.ui.HasHorizontalAlignment;
55import com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant;
56import com.google.gwt.user.client.ui.Image;
57import com.google.gwt.user.client.ui.Label;
58import com.google.gwt.user.client.ui.Widget;
59
60/**
61 * @author Tomas Muller
62 */
63public class RoomsTable extends UniTimeTable<RoomDetailInterface>{
64 protected static final GwtMessages MESSAGES = GWT.create(GwtMessages.class);
65 protected static final GwtAriaMessages ARIA = GWT.create(GwtAriaMessages.class);
66 protected static final GwtResources RESOURCES = GWT.create(GwtResources.class);
67 protected static final GwtConstants CONSTANTS = GWT.create(GwtConstants.class);
68 protected static final GwtRpcServiceAsync RPC = GWT.create(GwtRpcService.class);
69
70 private int iFlags = 0;
71 private RoomsComparator.Column iSortBy = null;
72 private boolean iAsc = true;
73 private RoomsPageMode iMode = null;
74
75 public RoomsTable(RoomsPageMode mode) {
76 setStyleName("unitime-Rooms");
77 iMode = mode;
78
79 List<UniTimeTableHeader> header = new ArrayList<UniTimeTableHeader>();
80
81 UniTimeTableHeader hName = new UniTimeTableHeader(MESSAGES.colName());
82 header.add(hName);
83
84 UniTimeTableHeader hType = new UniTimeTableHeader(MESSAGES.colType());
85 header.add(hType);
86
87 UniTimeTableHeader hCapacity = new UniTimeTableHeader(MESSAGES.colCapacity(), HasHorizontalAlignment.ALIGN_RIGHT);
88 header.add(hCapacity);
89
90 UniTimeTableHeader hExamCapacity = new UniTimeTableHeader(MESSAGES.colExaminationCapacity(), HasHorizontalAlignment.ALIGN_RIGHT);
91 header.add(hExamCapacity);
92
93 UniTimeTableHeader hArea = new UniTimeTableHeader(MESSAGES.colArea(), HasHorizontalAlignment.ALIGN_RIGHT);
94 header.add(hArea);
95
96 UniTimeTableHeader hCoordinates = new UniTimeTableHeader(MESSAGES.colCoordinates());
97 header.add(hCoordinates);
98
99 UniTimeTableHeader hDistances = new UniTimeTableHeader(MESSAGES.colDistances());
100 header.add(hDistances);
101
102 UniTimeTableHeader hRoomCheck = new UniTimeTableHeader(MESSAGES.colRoomCheck());
103 header.add(hRoomCheck);
104
105 UniTimeTableHeader hPreference = new UniTimeTableHeader(MESSAGES.colPreference());
106 header.add(hPreference);
107
108 UniTimeTableHeader hAvailability = new UniTimeTableHeader(MESSAGES.colAvailability());
109 header.add(hAvailability);
110
111 UniTimeTableHeader hDepartments = new UniTimeTableHeader(MESSAGES.colDepartments());
112 header.add(hDepartments);
113
114 UniTimeTableHeader hControl = new UniTimeTableHeader(MESSAGES.colControl());
115 header.add(hControl);
116
117 UniTimeTableHeader hExamTypes = new UniTimeTableHeader(MESSAGES.colExamTypes());
118 header.add(hExamTypes);
119
120 UniTimeTableHeader hPeriodPrefs = new UniTimeTableHeader(MESSAGES.colPeriodPreferences());
121 header.add(hPeriodPrefs);
122
123 UniTimeTableHeader hEventDepartment = new UniTimeTableHeader(MESSAGES.colEventDepartment());
124 header.add(hEventDepartment);
125
126 UniTimeTableHeader hEventStatus = new UniTimeTableHeader(MESSAGES.colEventStatus());
127 header.add(hEventStatus);
128
129 UniTimeTableHeader hEventAvailability = new UniTimeTableHeader(MESSAGES.colEventAvailability());
130 header.add(hEventAvailability);
131
132 UniTimeTableHeader hEventMessage = new UniTimeTableHeader(MESSAGES.colEventMessage());
133 header.add(hEventMessage);
134
135 UniTimeTableHeader hBreakTime = new UniTimeTableHeader(MESSAGES.colBreakTime());
136 header.add(hBreakTime);
137
138 UniTimeTableHeader hGroups = new UniTimeTableHeader(MESSAGES.colGroups());
139 header.add(hGroups);
140
141 UniTimeTableHeader hFeatures = new UniTimeTableHeader(MESSAGES.colFeatures());
142 header.add(hFeatures);
143
144 addRow(null, header);
145
146 addHideOperation(hType, RoomFlag.SHOW_TYPE);
147 addHideOperation(hCapacity, RoomFlag.SHOW_CAPACITY);
148 addHideOperation(hExamCapacity, RoomFlag.SHOW_EXAM_CAPACITY);
149 addHideOperation(hArea, RoomFlag.SHOW_AREA);
150 addHideOperation(hCoordinates, RoomFlag.SHOW_COORDINATES);
151 addHideOperation(hDistances, RoomFlag.SHOW_IGNORE_DISTANCES);
152 addHideOperation(hRoomCheck, RoomFlag.SHOW_IGNORE_ROOM_CHECK);
153 addHideOperation(hPreference, RoomFlag.SHOW_PREFERENCE);
154 addHideOperation(hAvailability, RoomFlag.SHOW_AVAILABILITY);
155 addHideOperation(hDepartments, RoomFlag.SHOW_DEPARTMENTS);
156 addHideOperation(hControl, RoomFlag.SHOW_CONTROLLING_DEPARTMENT);
157 addHideOperation(hExamTypes, RoomFlag.SHOW_EXAM_TYPES);
158 addHideOperation(hPeriodPrefs, RoomFlag.SHOW_PERIOD_PREFERENCES);
159 addHideOperation(hEventDepartment, RoomFlag.SHOW_EVENT_DEPARTMENT);
160 addHideOperation(hEventStatus, RoomFlag.SHOW_EVENT_STATUS);
161 addHideOperation(hEventAvailability, RoomFlag.SHOW_EVENT_AVAILABILITY);
162 addHideOperation(hEventMessage, RoomFlag.SHOW_EVENT_MESSAGE);
163 addHideOperation(hBreakTime, RoomFlag.SHOW_BREAK_TIME);
164 addHideOperation(hGroups, RoomFlag.SHOW_GROUPS);
165 addHideOperation(hFeatures, RoomFlag.SHOW_FEATURES);
166
167 for (final DeptMode d: DeptMode.values()) {
168 Operation op = new Operation() {
169 @Override
170 public void execute() {
171 RoomCookie.getInstance().setDeptMode(d.ordinal());
172 for (int r = 1; r < getRowCount(); r++) {
173 for (int c = 0; c < getCellCount(r); c++) {
174 Widget w = getWidget(r, c);
175 if (w instanceof DepartmentCell)
176 ((DepartmentCell)w).refresh();
177 }
178 }
179 }
180 @Override
181 public boolean isApplicable() {
182 return getRowCount() > 0;
183 }
184 @Override
185 public boolean hasSeparator() {
186 return d.ordinal() == 0;
187 }
188 @Override
189 public String getName() {
190 if (RoomCookie.getInstance().getDeptMode() == d.ordinal())
191 return MESSAGES.opUncheck(d.getName());
192 else
193 return MESSAGES.opCheck(d.getName());
194 }
195 };
196 hDepartments.addOperation(op);
197 hControl.addOperation(op);
198 hEventDepartment.addOperation(op);
199 }
200
201 addSortByOperation(hName, RoomsComparator.Column.NAME);
202 addSortByOperation(hType, RoomsComparator.Column.TYPE);
203 addSortByOperation(hCapacity, RoomsComparator.Column.CAPACITY);
204 addSortByOperation(hExamCapacity, RoomsComparator.Column.EXAM_CAPACITY);
205 addSortByOperation(hDistances, RoomsComparator.Column.DISTANCE);
206 addSortByOperation(hRoomCheck, RoomsComparator.Column.ROOM_CHECK);
207 addSortByOperation(hControl, RoomsComparator.Column.CONTROL);
208 addSortByOperation(hEventDepartment, RoomsComparator.Column.EVENT_DEPT);
209 addSortByOperation(hEventStatus, RoomsComparator.Column.EVENT_STATUS);
210 addSortByOperation(hEventMessage, RoomsComparator.Column.EVENT_MESSAGE);
211 addSortByOperation(hBreakTime, RoomsComparator.Column.BREAK_TIME);
212
213 for (int i = 0; i < getCellCount(0); i++)
214 getCellFormatter().setStyleName(0, i, "unitime-ClickableTableHeader");
215
216 resetVisibility();
217 setSortBy(RoomCookie.getInstance().getRoomsSortBy());
218 }
219
220 public boolean hasSortBy() { return iSortBy != null; }
221 public int getSortBy() { return iSortBy == null ? 0 : iAsc ? 1 + iSortBy.ordinal() : -1 - iSortBy.ordinal(); }
222 public void setSortBy(int sortBy) {
223 if (sortBy == 0) {
224 iSortBy = null;
225 iAsc = true;
226 } else if (sortBy > 0) {
227 iSortBy = RoomsComparator.Column.values()[sortBy - 1];
228 iAsc = true;
229 } else {
230 iSortBy = RoomsComparator.Column.values()[-1 - sortBy];
231 iAsc = false;
232 }
233 sort();
234 }
235
236 protected void addSortByOperation(final UniTimeTableHeader header, final RoomsComparator.Column sortBy) {
237 header.addOperation(new Operation() {
238 @Override
239 public void execute() {
240 if (header.getOrder() != null)
241 iAsc = !header.getOrder();
242 else
243 iAsc = true;
244 iSortBy = sortBy;
245 RoomCookie.getInstance().setSortRoomsBy(getSortBy());
246 sort();
247 }
248 @Override
249 public boolean isApplicable() { return getRowCount() > 1; }
250 @Override
251 public boolean hasSeparator() { return true; }
252 @Override
253 public String getName() { return MESSAGES.opSortBy(header.getHTML()); }
254 });
255 }
256
257 public void sort() {
258 if (iSortBy == null) return;
259 UniTimeTableHeader header = null;
260 switch (iSortBy) {
261 case NAME:
262 header = getHeader(MESSAGES.colName());
263 break;
264 case TYPE:
265 header = getHeader(MESSAGES.colType());
266 break;
267 case CAPACITY:
268 header = getHeader(MESSAGES.colCapacity());
269 break;
270 case EXAM_CAPACITY:
271 header = getHeader(MESSAGES.colExaminationCapacity());
272 break;
273 case DISTANCE:
274 header = getHeader(MESSAGES.colDistances());
275 break;
276 case ROOM_CHECK:
277 header = getHeader(MESSAGES.colRoomCheck());
278 break;
279 case CONTROL:
280 header = getHeader(MESSAGES.colControl());
281 break;
282 case EVENT_DEPT:
283 header = getHeader(MESSAGES.colEventDepartment());
284 break;
285 case EVENT_STATUS:
286 header = getHeader(MESSAGES.colEventStatus());
287 break;
288 case EVENT_MESSAGE:
289 header = getHeader(MESSAGES.colEventMessage());
290 break;
291 case BREAK_TIME:
292 header = getHeader(MESSAGES.colBreakTime());
293 break;
294 }
295 sort(header, new RoomsComparator(iSortBy, iAsc), true);
296 }
297
298 protected Operation addHideOperation(final UniTimeTableHeader header, final RoomFlag flag, final Check separator) {
299 Operation op = new AriaOperation() {
300 @Override
301 public void execute() {
302 boolean visible = isColumnVisible(header.getColumn());
303 setColumnVisible(header.getColumn(), !visible);
304 RoomCookie.getInstance().set(iMode, flag, !visible);
305 }
306 @Override
307 public boolean isApplicable() {
308 if (!flag.isShowWhenEmpty())
309 return flag.in(iFlags);
310 return true;
311 }
312 @Override
313 public boolean hasSeparator() {
314 return separator != null && separator.isChecked();
315 }
316 @Override
317 public String getName() { return isColumnVisible(header.getColumn()) ? MESSAGES.opHide(header.getHTML().replace("<br>", " ")) : MESSAGES.opShow(header.getHTML().replace("<br>", " ")); }
318 @Override
319 public String getAriaLabel() { return isColumnVisible(header.getColumn()) ? ARIA.opHide(header.getHTML().replace("<br>", " ")) : ARIA.opShow(header.getHTML().replace("<br>", " ")); }
320 };
321 getHeader(MESSAGES.colName()).addOperation(op);
322 switch (flag) {
323 case SHOW_EVENT_AVAILABILITY:
324 case SHOW_EVENT_DEPARTMENT:
325 case SHOW_EVENT_MESSAGE:
326 case SHOW_EVENT_STATUS:
327 case SHOW_BREAK_TIME:
328 getHeader(MESSAGES.colEventAvailability()).addOperation(op);
329 getHeader(MESSAGES.colEventDepartment()).addOperation(op);
330 getHeader(MESSAGES.colEventMessage()).addOperation(op);
331 getHeader(MESSAGES.colEventStatus()).addOperation(op);
332 getHeader(MESSAGES.colBreakTime()).addOperation(op);
333 break;
334 case SHOW_CAPACITY:
335 case SHOW_EXAM_CAPACITY:
336 case SHOW_AREA:
337 case SHOW_COORDINATES:
338 getHeader(MESSAGES.colExaminationCapacity()).addOperation(op);
339 getHeader(MESSAGES.colCapacity()).addOperation(op);
340 getHeader(MESSAGES.colArea()).addOperation(op);
341 getHeader(MESSAGES.colCoordinates()).addOperation(op);
342 break;
343 case SHOW_DEPARTMENTS:
344 case SHOW_CONTROLLING_DEPARTMENT:
345 case SHOW_AVAILABILITY:
346 getHeader(MESSAGES.colDepartments()).addOperation(op);
347 getHeader(MESSAGES.colControl()).addOperation(op);
348 getHeader(MESSAGES.colAvailability()).addOperation(op);
349 break;
350 case SHOW_IGNORE_DISTANCES:
351 case SHOW_IGNORE_ROOM_CHECK:
352 getHeader(MESSAGES.colRoomCheck()).addOperation(op);
353 getHeader(MESSAGES.colDistances()).addOperation(op);
354 break;
355 case SHOW_PERIOD_PREFERENCES:
356 case SHOW_EXAM_TYPES:
357 getHeader(MESSAGES.colExaminationCapacity()).addOperation(op);
358 getHeader(MESSAGES.colExamTypes()).addOperation(op);
359 getHeader(MESSAGES.colPeriodPreferences()).addOperation(op);
360 break;
361 default:
362 header.addOperation(op);
363 }
364 return op;
365 }
366
367 protected Operation addHideOperation(final UniTimeTableHeader header, final RoomFlag flag) {
368 return addHideOperation(header, flag, null);
369 }
370
371 protected Integer getRow(Long roomId) {
372 for (int row = 1; row < getRowCount(); row++) {
373 RoomDetailInterface room = getData(row);
374 if (room != null && roomId.equals(room.getUniqueId())) return row;
375 }
376 return null;
377 }
378
379 public int addRoom(final RoomDetailInterface room, String department) {
380 RoomCookie cookie = RoomCookie.getInstance();
381
382 List<Widget> widgets = new ArrayList<Widget>();
383 final Label roomLabel = new Label(room.hasDisplayName() ? MESSAGES.label(room.getLabel(), room.getDisplayName()) : room.getLabel());
384 roomLabel.addMouseOverHandler(new MouseOverHandler() {
385 @Override
386 public void onMouseOver(MouseOverEvent event) {
387 RoomHint.showHint(roomLabel.getElement(), room.getUniqueId(), room.getPrefix(), room.getProperty("distance", null), true);
388 }
389 });
390 roomLabel.addMouseOutHandler(new MouseOutHandler() {
391 @Override
392 public void onMouseOut(MouseOutEvent event) {
393 RoomHint.hideHint();
394 }
395 });
396 if (department != null) {
397 for (DepartmentInterface d: room.getDepartments()) {
398 if (department.equals(d.getDeptCode()) && d.getPreference() != null) {
399 roomLabel.getElement().getStyle().setColor(d.getPreference().getColor());
400 room.setPrefix(d.getPreference().getName());
401 }
402 }
403 }
404 widgets.add(roomLabel);
405
406 widgets.add(new Label(room.getRoomType().getLabel()));
407
408 widgets.add(new IntegerCell(room.getCapacity()));
409 widgets.add(new IntegerCell(room.getExamCapacity()));
410 if (room.getExamCapacity() != null) show(RoomFlag.SHOW_EXAM_CAPACITY);
411
412 widgets.add(new RoomAreaCell(room.getArea()));
413 if (room.getArea() != null) show(RoomFlag.SHOW_AREA);
414
415 widgets.add(new Label(room.hasCoordinates() ? MESSAGES.coordinates(room.getX(), room.getY()) : ""));
416 if (room.hasCoordinates()) show(RoomFlag.SHOW_COORDINATES);
417
418 widgets.add(new Image(!room.isIgnoreTooFar() ? RESOURCES.on() : RESOURCES.off()));
419 widgets.add(new Image(!room.isIgnoreRoomCheck() ? RESOURCES.on() : RESOURCES.off()));
420
421 widgets.add(new PreferenceCell(room.getDepartments()));
422 if (room.hasPreference(department)) show(RoomFlag.SHOW_PREFERENCE);
423
424 if (room.getAvailability() != null) {
425 final HTML availability = new HTML(room.getAvailability());
426 availability.addMouseOverHandler(new MouseOverHandler() {
427 @Override
428 public void onMouseOver(MouseOverEvent event) {
429 RoomSharingHint.showHint(availability.getElement(), room.getUniqueId(), false);
430 }
431 });
432 availability.addMouseOutHandler(new MouseOutHandler() {
433 @Override
434 public void onMouseOut(MouseOutEvent event) {
435 RoomSharingHint.hideHint();
436 }
437 });
438 if (room.getRoomSharingNote() != null && !room.getRoomSharingNote().isEmpty()) {
439 P p = new P();
440 p.add(availability);
441 P note = new P("note");
442 note.setHTML(room.getRoomSharingNote());
443 note.setTitle(room.getRoomSharingNote());
444 p.add(note);
445 widgets.add(p);
446 } else {
447 widgets.add(availability);
448 }
449 } else if (room.isCanSeeAvailability()) {
450 final Image availability = new Image("pattern?loc=" + room.getUniqueId() + "&v=" + (cookie.areRoomsHorizontal() ? "0" : "1") + (cookie.hasMode() ? "&s=" + cookie.getMode() : ""));
451 availability.addMouseOverHandler(new MouseOverHandler() {
452 @Override
453 public void onMouseOver(MouseOverEvent event) {
454 RoomSharingHint.showHint(availability.getElement(), room.getUniqueId(), false);
455 }
456 });
457 availability.addMouseOutHandler(new MouseOutHandler() {
458 @Override
459 public void onMouseOut(MouseOutEvent event) {
460 RoomSharingHint.hideHint();
461 }
462 });
463 if (room.getRoomSharingNote() != null && !room.getRoomSharingNote().isEmpty()) {
464 P p = new P();
465 p.add(availability);
466 P note = new P("note");
467 note.setHTML(room.getRoomSharingNote());
468 note.setTitle(room.getRoomSharingNote());
469 p.add(note);
470 widgets.add(p);
471 } else {
472 widgets.add(availability);
473 }
474 }
475
476 widgets.add(new DepartmentCell(room.getDepartments(), room.getControlDepartment()));
477 widgets.add(new DepartmentCell(room.getControlDepartment()));
478
479 widgets.add(new ExamTypesCell(room.getUniqueId(), room.getExamTypes()));
480 if (!room.getExamTypes().isEmpty()) show(RoomFlag.SHOW_EXAM_TYPES);
481
482 Widget periodPrefs = null;
483 if (room.getPeriodPreference() != null) {
484 final HTML availability = new HTML(room.getPeriodPreference());
485 for (final ExamTypeInterface t: room.getExamTypes()) {
486 if (t.getReference().equals(department)) {
487 availability.addMouseOverHandler(new MouseOverHandler() {
488 @Override
489 public void onMouseOver(MouseOverEvent event) {
490 PeriodPreferencesHint.showHint(availability.getElement(), room.getUniqueId(), t.getId());
491 }
492 });
493 availability.addMouseOutHandler(new MouseOutHandler() {
494 @Override
495 public void onMouseOut(MouseOutEvent event) {
496 PeriodPreferencesHint.hideHint();
497 }
498 });
499 break;
500 }
501 }
502 periodPrefs = availability;
503 show(RoomFlag.SHOW_PERIOD_PREFERENCES);
504 } else {
505 for (final ExamTypeInterface t: room.getExamTypes()) {
506 if (t.getReference().equals(department)) {
507 final Image pattern = new Image("pattern?loc=" + room.getUniqueId() + "&xt=" + t.getId() + "&v=" + (cookie.areRoomsHorizontal() ? "0" : "1") + (cookie.hasMode() ? "&s=" + cookie.getMode() : ""));
508 show(RoomFlag.SHOW_PERIOD_PREFERENCES);
509 pattern.addMouseOverHandler(new MouseOverHandler() {
510 @Override
511 public void onMouseOver(MouseOverEvent event) {
512 PeriodPreferencesHint.showHint(pattern.getElement(), room.getUniqueId(), t.getId());
513 }
514 });
515 pattern.addMouseOutHandler(new MouseOutHandler() {
516 @Override
517 public void onMouseOut(MouseOutEvent event) {
518 PeriodPreferencesHint.hideHint();
519 }
520 });
521 periodPrefs = pattern; break;
522 }
523 }
524 }
525 widgets.add(periodPrefs == null ? new Label("") : periodPrefs);
526
527 final DepartmentCell edc = new DepartmentCell(room.getEventDepartment());
528 if (room.getEventDepartment() != null && room.isCanSeeEventAvailability()) {
529 edc.addMouseOverHandler(new MouseOverHandler() {
530 @Override
531 public void onMouseOver(MouseOverEvent event) {
532 RoomSharingHint.showHint(edc.getElement(), room.getUniqueId(), true);
533 }
534 });
535 edc.addMouseOutHandler(new MouseOutHandler() {
536 @Override
537 public void onMouseOut(MouseOutEvent event) {
538 RoomSharingHint.hideHint();
539 }
540 });
541 show(RoomFlag.SHOW_EVENT_DEPARTMENT);
542 }
543 widgets.add(edc);
544
545 widgets.add(new StatusCell(room.getEventStatus(), room.getDefaultEventStatus()));
546 if (room.getEventStatus() != null || room.getDefaultEventStatus() != null) show(RoomFlag.SHOW_EVENT_STATUS);
547
548 Widget eventAvail = null;
549 if (room.getEventAvailability() != null) {
550 final HTML availability = new HTML(room.getEventAvailability());
551 availability.addMouseOverHandler(new MouseOverHandler() {
552 @Override
553 public void onMouseOver(MouseOverEvent event) {
554 RoomSharingHint.showHint(availability.getElement(), room.getUniqueId(), true);
555 }
556 });
557 availability.addMouseOutHandler(new MouseOutHandler() {
558 @Override
559 public void onMouseOut(MouseOutEvent event) {
560 RoomSharingHint.hideHint();
561 }
562 });
563 eventAvail = availability;
564 show(RoomFlag.SHOW_EVENT_AVAILABILITY);
565 } else if (room.isCanSeeEventAvailability()) {
566 final Image availability = new Image("pattern?loc=" + room.getUniqueId() + "&e=1&v=" + (cookie.areRoomsHorizontal() ? "0" : "1") + (cookie.hasMode() ? "&s=" + cookie.getMode() : ""));
567 availability.addMouseOverHandler(new MouseOverHandler() {
568 @Override
569 public void onMouseOver(MouseOverEvent event) {
570 RoomSharingHint.showHint(availability.getElement(), room.getUniqueId(), true);
571 }
572 });
573 availability.addMouseOutHandler(new MouseOutHandler() {
574 @Override
575 public void onMouseOut(MouseOutEvent event) {
576 RoomSharingHint.hideHint();
577 }
578 });
579 eventAvail = availability;
580 show(RoomFlag.SHOW_EVENT_AVAILABILITY);
581 }
582 widgets.add(eventAvail == null ? new Label("") : eventAvail);
583
584 widgets.add(new NoteCell(room.getEventNote(), room.getDefaultEventNote()));
585 if (room.hasEventNote() || room.hasDefaultEventNote()) show(RoomFlag.SHOW_EVENT_MESSAGE);
586
587 widgets.add(new BreakTimeCell(room.getBreakTime(), room.getDefaultBreakTime()));
588 if (room.getBreakTime() != null) show(RoomFlag.SHOW_BREAK_TIME);
589
590 widgets.add(new GroupsCell(room.getGroups()));
591 widgets.add(new FeaturesCell(room.getFeatures()));
592
593 int row = addRow(room, widgets);
594 getRowFormatter().setStyleName(row, "row");
595 for (int col = 0; col < getCellCount(row); col++)
596 getCellFormatter().setStyleName(row, col, "cell");
597 return row;
598 }
599
600 protected int getColumn(RoomFlag flag) {
601 switch (flag) {
602 case SHOW_AREA:
603 return getHeader(MESSAGES.colArea()).getColumn();
604 case SHOW_AVAILABILITY:
605 return getHeader(MESSAGES.colAvailability()).getColumn();
606 case SHOW_BREAK_TIME:
607 return getHeader(MESSAGES.colBreakTime()).getColumn();
608 case SHOW_CAPACITY:
609 return getHeader(MESSAGES.colCapacity()).getColumn();
610 case SHOW_CONTROLLING_DEPARTMENT:
611 return getHeader(MESSAGES.colControl()).getColumn();
612 case SHOW_COORDINATES:
613 return getHeader(MESSAGES.colCoordinates()).getColumn();
614 case SHOW_PREFERENCE:
615 return getHeader(MESSAGES.colPreference()).getColumn();
616 case SHOW_DEPARTMENTS:
617 return getHeader(MESSAGES.colDepartments()).getColumn();
618 case SHOW_EVENT_AVAILABILITY:
619 return getHeader(MESSAGES.colEventAvailability()).getColumn();
620 case SHOW_EVENT_DEPARTMENT:
621 return getHeader(MESSAGES.colEventDepartment()).getColumn();
622 case SHOW_EVENT_MESSAGE:
623 return getHeader(MESSAGES.colEventMessage()).getColumn();
624 case SHOW_EVENT_STATUS:
625 return getHeader(MESSAGES.colEventStatus()).getColumn();
626 case SHOW_EXAM_CAPACITY:
627 return getHeader(MESSAGES.colExaminationCapacity()).getColumn();
628 case SHOW_EXAM_TYPES:
629 return getHeader(MESSAGES.colExamTypes()).getColumn();
630 case SHOW_FEATURES:
631 return getHeader(MESSAGES.colFeatures()).getColumn();
632 case SHOW_GROUPS:
633 return getHeader(MESSAGES.colGroups()).getColumn();
634 case SHOW_IGNORE_DISTANCES:
635 return getHeader(MESSAGES.colDistances()).getColumn();
636 case SHOW_IGNORE_ROOM_CHECK:
637 return getHeader(MESSAGES.colRoomCheck()).getColumn();
638 case SHOW_PERIOD_PREFERENCES:
639 return getHeader(MESSAGES.colPeriodPreferences()).getColumn();
640 default:
641 return 0;
642 }
643 }
644
645 protected void resetVisibility() {
646 RoomCookie cookie = RoomCookie.getInstance();
647 for (RoomFlag flag: RoomFlag.values()) {
648 setColumnVisible(getColumn(flag), cookie.get(iMode, flag) && flag.isShowWhenEmpty());
649 }
650 }
651
652 protected void show(RoomFlag f) {
653 int col = getColumn(f);
654 if (RoomCookie.getInstance().get(iMode, f) && !isColumnVisible(col)) setColumnVisible(col, true);
655 if (!f.isShowWhenEmpty())
656 iFlags = f.set(iFlags);
657 }
658
659 @Override
660 public void clearTable(int headerRows) {
661 super.clearTable(headerRows);
662 resetVisibility();
663 iFlags = 0;
664 }
665
666 public int getFlags() { return iFlags; }
667
668 public static class WaitingCell extends Image implements UniTimeTable.HasColSpan, UniTimeTable.HasCellAlignment {
669 private int iColSpan;
670 public WaitingCell(int colspan) {
671 super(RESOURCES.loading_small());
672 iColSpan = colspan;
673 }
674
675 @Override
676 public int getColSpan() {
677 return iColSpan;
678 }
679
680 @Override
681 public HorizontalAlignmentConstant getCellAlignment() {
682 return HasHorizontalAlignment.ALIGN_CENTER;
683 }
684 }
685
686 public static class IntegerCell extends Label implements UniTimeTable.HasCellAlignment, UniTimeTable.HasColSpan, TakesValue<Integer> {
687
688 public IntegerCell(Integer value) {
689 super();
690 setValue(value);
691 }
692
693 @Override
694 public void setValue(Integer value) {
695 setText(value == null ? "" : value.toString());
696 }
697
698 @Override
699 public Integer getValue() {
700 return getText().isEmpty() ? null : new Integer(getText());
701 }
702
703 @Override
704 public HorizontalAlignmentConstant getCellAlignment() {
705 return HasHorizontalAlignment.ALIGN_RIGHT;
706 }
707
708 @Override
709 public int getColSpan() {
710 return 1;
711 }
712 }
713
714 public static class RoomAreaCell extends HTML implements UniTimeTable.HasCellAlignment {
715 public RoomAreaCell(Double value) {
716 super(value == null ? "" : MESSAGES.roomArea(value));
717 }
718
719 @Override
720 public HorizontalAlignmentConstant getCellAlignment() {
721 return HasHorizontalAlignment.ALIGN_RIGHT;
722 }
723 }
724
725 public static class FeaturesCell extends P {
726 public FeaturesCell(List<? extends FeatureInterface> features) {
727 super();
728 setStyleName("features");
729 for (FeatureInterface feature: features) {
730 P p = new P("feature");
731 p.setText(feature.getLabel());
732 if (feature.getTitle() != null) p.setTitle(feature.getTitle());
733 if (feature.getDepartment() != null) {
734 p.setText(feature.getLabel() + " (" + feature.getDepartment().getExtAbbreviationWhenExist() + ")");
735 if (feature.getDepartment().getColor() != null)
736 p.getElement().getStyle().setColor(feature.getDepartment().getColor());
737 }
738 if (feature.getType() != null)
739 p.setText(feature.getLabel() + " (" + feature.getType().getAbbreviation() + ")");
740 add(p);
741 }
742 }
743 }
744
745 public static class GroupsCell extends P {
746 public GroupsCell(List<? extends GroupInterface> groups) {
747 super();
748 setStyleName("groups");
749 for (GroupInterface group: groups) {
750 P p = new P("group");
751 p.setText(group.getLabel());
752 if (group.getTitle() != null) p.setTitle(group.getTitle());
753 if (group.getDepartment() != null) {
754 p.setText(group.getLabel() + " (" + group.getDepartment().getExtAbbreviationWhenExist() + ")");
755 if (group.getDepartment().getColor() != null)
756 p.getElement().getStyle().setColor(group.getDepartment().getColor());
757 }
758 add(p);
759 }
760 }
761 }
762
763 public static class NoteCell extends P {
764 public NoteCell(String note, String defaultNote) {
765 super("note");
766 if (note != null) {
767 setHTML(note.replace("\\n", "<br>"));
768 setTitle(note);
769 } else if (defaultNote != null) {
770 addStyleName("default");
771 setHTML(defaultNote.replace("\\n", "<br>"));
772 setTitle(defaultNote);
773 }
774 }
775 }
776
777 public static class StatusCell extends P {
778 public StatusCell(Integer status, Integer defaultStatus) {
779 super("status");
780 if (status != null) {
781 setHTML(CONSTANTS.eventStatusAbbv()[status]);
782 setTitle(CONSTANTS.eventStatusName()[status]);
783 } else if (defaultStatus != null) {
784 addStyleName("default");
785 setText(CONSTANTS.eventStatusAbbv()[defaultStatus]);
786 setTitle(CONSTANTS.eventStatusName()[defaultStatus]);
787 } else {
788 setHTML(CONSTANTS.eventStatusAbbv()[0]);
789 setTitle(CONSTANTS.eventStatusName()[0]);
790 }
791 }
792 }
793
794 public static class BreakTimeCell extends P {
795 public BreakTimeCell(Integer breakTime, Integer defaultBreakTime) {
796 super("break");
797 if (breakTime != null) {
798 if (breakTime != 0)
799 setText(breakTime.toString());
800 } else if (defaultBreakTime != null) {
801 addStyleName("default");
802 if (defaultBreakTime != 0)
803 setText(defaultBreakTime.toString());
804 }
805 }
806 }
807
808 public static class DepartmentCell extends P {
809 Map<DepartmentInterface, P> iP = new HashMap<DepartmentInterface, P>();
810
811 public DepartmentCell(DepartmentInterface... departments) {
812 super("departments");
813 for (DepartmentInterface department: departments) {
814 if (department == null) continue;
815 P p = new P("department");
816 p.setText(toString(department));
817 if (department.getTitle() != null) p.setTitle(department.getTitle());
818 if (department.getColor() != null)
819 p.getElement().getStyle().setColor(department.getColor());
820 add(p);
821 iP.put(department, p);
822 }
823 }
824
825 public DepartmentCell(List<DepartmentInterface> departments, DepartmentInterface control) {
826 super("departments");
827 for (DepartmentInterface department: departments) {
828 P p = new P("department");
829 p.setText(toString(department));
830 if (department.getTitle() != null) p.setTitle(department.getTitle());
831 if (department.getColor() != null)
832 p.getElement().getStyle().setColor(department.getColor());
833 if (department.equals(control))
834 p.addStyleName("control");
835 iP.put(department, p);
836 add(p);
837 }
838 }
839
840 protected String toString(DepartmentInterface d) {
841 RoomCookie cookie = RoomCookie.getInstance();
842 switch (DeptMode.values()[cookie.getDeptMode()]) {
843 case ABBV:
844 return d.getExtAbbreviationWhenExist();
845 case CODE:
846 return d.getDeptCode();
847 case ABBV_NAME:
848 return d.getExtAbbreviationWhenExist() + " - " + d.getExtLabelWhenExist();
849 case CODE_NAME:
850 return d.getDeptCode() + " - " + d.getLabel();
851 case NAME:
852 return d.getExtLabelWhenExist();
853 default:
854 return d.getExtAbbreviationWhenExist();
855 }
856 }
857
858 public void refresh() {
859 for (Map.Entry<DepartmentInterface, P> e: iP.entrySet())
860 e.getValue().setText(toString(e.getKey()));
861 }
862 }
863
864 public static class PreferenceCell extends DepartmentCell {
865 public PreferenceCell(List<DepartmentInterface> departments) {
866 addStyleName("departments");
867 for (DepartmentInterface department: departments) {
868 if (department.getPreference() == null) continue;
869 P p = new P("department");
870 p.setText(toString(department));
871 p.setTitle(department.getPreference().getName() + " " + department.getLabel());
872 p.getElement().getStyle().setColor(department.getPreference().getColor());
873 iP.put(department, p);
874 add(p);
875 }
876 }
877 }
878
879 public static class ExamTypesCell extends P {
880 public ExamTypesCell(final Long roomId, List<ExamTypeInterface> examTypes) {
881 super("exam-types");
882 for (final ExamTypeInterface examType: examTypes) {
883 final P p = new P(examType.isFinal() ? "final" : "midterm");
884 p.setText(examType.getReference());
885 p.setTitle(examType.getLabel());
886 p.addMouseOverHandler(new MouseOverHandler() {
887 @Override
888 public void onMouseOver(MouseOverEvent event) {
889 PeriodPreferencesHint.showHint(p.getElement(), roomId, examType.getId());
890 }
891 });
892 p.addMouseOutHandler(new MouseOutHandler() {
893 @Override
894 public void onMouseOut(MouseOutEvent event) {
895 PeriodPreferencesHint.hideHint();
896 }
897 });
898 add(p);
899 }
900 }
901 }
902
903 public static class RoomCell extends Label {
904 public RoomCell(RoomPropertyInterface property) {
905 super(property == null ? "" : property.getLabel());
906 if (property != null) {
907 if (property.getTitle() != null)
908 setTitle(property.getTitle());
909 if (property.getColor() != null)
910 getElement().getStyle().setColor(property.getColor());
911 }
912 }
913 }
914
915 public interface Check {
916 public boolean isChecked();
917 }
918
919 public static enum DeptMode {
920 CODE(MESSAGES.fieldCode()),
921 ABBV(MESSAGES.fieldAbbreviation()),
922 NAME(MESSAGES.fieldName()),
923 ABBV_NAME(MESSAGES.fieldAbbv() + " - " + MESSAGES.fieldName()),
924 CODE_NAME(MESSAGES.fieldCode() + " - " + MESSAGES.fieldName());
925
926 private String iName;
927
928 DeptMode(String name) { iName = name; }
929
930 public String getName() { return iName; }
931 }
932}
JavaSource/org/unitime/timetable/gwt/resources/GwtConstants.java
(28 / 0)
  
211211
212212 @DefaultBooleanValue(false)
213213 boolean displayMidtermPeriodPreferencesAsCalendar();
214
215 @DefaultStringArrayValue({
216 "No Event Management",
217 "Authenticated Users Can Request Events Managers Can Approve",
218 "Departmental Users Can Request Events Managers Can Approve",
219 "Event Managers Can Request Or Approve Events",
220 "Authenticated Users Can Request Events No Approval",
221 "Departmental Users Can Request Events No Approval",
222 "Event Managers Can Request Events No Approval",
223 })
224 String[] eventStatusName();
225
226 @DefaultStringArrayValue({
227 "Disabled",
228 "Enabled",
229 "Only Department",
230 "Only Managers",
231 "Enabled<br>No Approval",
232 "Only Department<br>No Approval",
233 "Only Managers<br>No Approval",
234 })
235 String[] eventStatusAbbv();
236
237 @DefaultStringValue("#,##0.##")
238 String roomAreaFormat();
239
240 @DefaultStringValue("#0.0###")
241 String roomCoordinateFormat();
214242}
JavaSource/org/unitime/timetable/gwt/resources/GwtMessages.java
(93 / 0)
  
409409
410410 @DefaultMessage("Capacity")
411411 String colCapacity();
412
413 @DefaultMessage("Exam<br>Capacity")
414 String colExaminationCapacity();
412415
413416 @DefaultMessage("Approved")
414417 String colApproval();
608608 @DefaultMessage("Picture")
609609 String colPicture();
610610
611 @DefaultMessage("Building")
612 String colBuilding();
613
614 @DefaultMessage("Room")
615 String colRoom();
616
617 @DefaultMessage("Area [ft&sup2;]")
618 String colArea();
619
620 @DefaultMessage("Coordinates")
621 String colCoordinates();
622
623 @DefaultMessage("Longitude")
624 String colCoordinateX();
625
626 @DefaultMessage("Latitude")
627 String colCoordinateY();
628
629 @DefaultMessage("Distances")
630 String colDistances();
631
632 @DefaultMessage("Room<br>Check")
633 String colRoomCheck();
634
635 @DefaultMessage("Preference")
636 String colPreference();
637
638 @DefaultMessage("Availability")
639 String colAvailability();
640
641 @DefaultMessage("Departments")
642 String colDepartments();
643
644 @DefaultMessage("Control")
645 String colControl();
646
647 @DefaultMessage("Examination<br>Types")
648 String colExamTypes();
649
650 @DefaultMessage("Period<br>Preferences")
651 String colPeriodPreferences();
652
653 @DefaultMessage("Event<br>Department")
654 String colEventDepartment();
655
656 @DefaultMessage("Event<br>Availability")
657 String colEventAvailability();
658
659 @DefaultMessage("Event<br>Status")
660 String colEventStatus();
661
662 @DefaultMessage("Event<br>Message")
663 String colEventMessage();
664
665 @DefaultMessage("Break<br>Time")
666 String colBreakTime();
667
668 @DefaultMessage("Groups")
669 String colGroups();
670
671 @DefaultMessage("Features")
672 String colFeatures();
673
611674 @DefaultMessage("Last Change")
612675 String colLastChange();
613676
12251225
12261226 @DefaultMessage("Loading room pictures...")
12271227 String waitLoadingRoomPictures();
1228
1229 @DefaultMessage("Loading rooms...")
1230 String waitLoadingRooms();
12281231
12291232 @DefaultMessage("Failed to load {0}: {1}")
12301233 String failedLoad(String name, String reason);
14331433 @DefaultMessage("Failed to upload room picture: {0}")
14341434 String failedToUploadRoomPicture(String reason);
14351435
1436 @DefaultMessage("Failed to load period preferences: {0}")
1437 String failedToLoadPeriodPreferences(String reason);
1438
1439 @DefaultMessage("Failed to initialize: {0}")
1440 String failedToInitialize(String reason);
1441
14361442 @DefaultMessage("There are more than {0} meetings matching the filter. Only {0} meetings are loaded.")
14371443 String warnTooManyMeetings(int maximum);
14381444
20502050
20512051 @DefaultMessage("Room Pictures")
20522052 String pageRoomPictures();
2053
2054 @DefaultMessage("Rooms")
2055 String pageRooms();
20532056
20542057 @DefaultMessage("N/A")
20552058 String itemNotApplicable();
32233223
32243224 @DefaultMessage("<i>{0} -- not approved</i>")
32253225 String gridEventHeaderNotApproved(String header);
3226
3227 @DefaultMessage("{0,number,#,##0.##} ft&sup2;")
3228 String roomArea(Double area);
3229
3230 @DefaultMessage("{0,number,#0.0###}, {1,number,#0.0###}")
3231 String coordinates(Double x, Double y);
3232
3233 @DefaultMessage("{0} Examination Rooms")
3234 String examinationRooms(String examTypeName);
3235
3236 @DefaultMessage("No")
3237 String exportFalse();
3238
3239 @DefaultMessage("Yes")
3240 String exportTrue();
32263241}
JavaSource/org/unitime/timetable/gwt/server/PatternServlet.java
(25 / 2)
  
2929import javax.servlet.http.HttpServletResponse;
3030
3131import org.cpsolver.coursett.model.TimeLocation;
32import org.unitime.localization.impl.Localization;
33import org.unitime.timetable.defaults.CommonValues;
34import org.unitime.timetable.defaults.UserProperty;
35import org.unitime.timetable.gwt.resources.GwtConstants;
3236import org.unitime.timetable.model.Exam;
3337import org.unitime.timetable.model.ExamPeriod;
3438import org.unitime.timetable.model.Location;
4242import org.unitime.timetable.model.dao.ExamPeriodDAO;
4343import org.unitime.timetable.model.dao.LocationDAO;
4444import org.unitime.timetable.model.dao.TimePatternDAO;
45import org.unitime.timetable.security.SessionContext;
46import org.unitime.timetable.security.context.HttpSessionContext;
4547import org.unitime.timetable.webutil.RequiredTimeTable;
4648
4749/**
5151 */
5252public class PatternServlet extends HttpServlet {
5353 private static final long serialVersionUID = 1L;
54 protected static final GwtConstants CONSTANTS = Localization.create(GwtConstants.class);
5455
56 protected SessionContext getSessionContext() {
57 return HttpSessionContext.getSessionContext(getServletContext());
58 }
59
5560 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
56 boolean vertical = "1".equals(request.getParameter("v"));
61 SessionContext context = getSessionContext();
62 boolean vertical = true;
63 if (request.getParameter("v") != null)
64 vertical = "1".equals(request.getParameter("v"));
65 else if (request.getParameter("c") != null)
66 vertical = "0".equals(request.getParameter("c").split("\\|")[5]);
67 else
68 vertical = CommonValues.VerticalGrid.eq(context.getUser().getProperty(UserProperty.GridOrientation));
5769 RequiredTimeTable rtt = null;
5870 if (request.getParameter("tp") != null) {
5971 TimePattern p = TimePatternDAO.getInstance().get(Long.valueOf(request.getParameter("tp")));
111111 } catch (NumberFormatException e) {
112112 rtt.getModel().setDefaultSelection(request.getParameter("s"));
113113 }
114 } if (request.getParameter("p") != null)
114 } else {
115 String defaultGridSize = RequiredTimeTable.getTimeGridSize(context.getUser());
116 if (defaultGridSize != null)
117 rtt.getModel().setDefaultSelection(defaultGridSize);
118 }
119 if (request.getParameter("p") != null)
115120 rtt.getModel().setPreferences(request.getParameter("p"));
116121 boolean hc = ("1".equals(request.getParameter("hc")));
117122
JavaSource/org/unitime/timetable/gwt/shared/EventInterface.java
(6 / 0)
  
15651565 }
15661566
15671567 public Long getUniqueId() { return iUniqueId; }
1568 public void setUniqueId(Long uniqueId) { iUniqueId = uniqueId; }
1569
15681570 public String getAbbreviation() { return iAbbv; }
1571 public void setAbbreviation(String abbreviation) { iAbbv = abbreviation; }
1572
15691573 public String getName() { return iName; }
1574 public void setName(String name) { iName = name; }
1575
15701576 public int getCount() { return iCount; }
15711577 public void setCount(int count) { iCount = count; }
15721578 public void incCount() { iCount ++; }
JavaSource/org/unitime/timetable/gwt/shared/RoomInterface.java
(775 / 0)
  
2020package org.unitime.timetable.gwt.shared;
2121
2222import java.util.ArrayList;
23import java.util.Date;
2324import java.util.HashMap;
2425import java.util.List;
2526import java.util.Map;
2929
3030import org.unitime.timetable.gwt.command.client.GwtRpcRequest;
3131import org.unitime.timetable.gwt.command.client.GwtRpcResponse;
32import org.unitime.timetable.gwt.command.client.GwtRpcResponseList;
33import org.unitime.timetable.gwt.shared.EventInterface.FilterRpcResponse;
3234
3335import com.google.gwt.user.client.rpc.IsSerializable;
3436
7676 public String toString() {
7777 return getFirstDay() + "|" + getLastDay() + "|" + getFirstSlot() + "|" + getLastSlot() + "|" + getStep();
7878 }
79
80 public String toHex() {
81 return Integer.toHexString(getStep() * 4064256 + getFirstDay() * 580608 + getLastDay() * 82944 + getFirstSlot() * 288 + (getLastSlot() % 288));
82 }
83
84 public static RoomSharingDisplayMode fromHex(String hexMode) {
85 int mode = Integer.parseInt(hexMode, 16);
86 RoomSharingDisplayMode m = new RoomSharingDisplayMode();
87 m.setStep(mode / 4064256);
88 m.setFirstDay((mode % 4064256) / 580608);
89 m.setLastDay((mode % 580608) / 82944);
90 m.setFirstSlot((mode % 82944) / 288);
91 m.setLastSlot(mode % 288 == 0 ? 288 : mode % 288);
92 return m;
93 }
7994 }
8095
8196 public static class RoomSharingOption implements IsSerializable {
544544
545545 public RoomPictureRequest.Apply getApply() { return iApply; }
546546 public void setApply(RoomPictureRequest.Apply apply) { iApply = apply; }
547 }
548
549 public static class RoomTypeInterface implements GwtRpcResponse {
550 private Long iId;
551 private String iLabel;
552 private boolean iRoom = false;
553
554 public RoomTypeInterface() {}
555
556 public RoomTypeInterface(Long id, String label, boolean room) {
557 iId = id; iLabel = label;
558 }
559
560 public Long getId() { return iId; }
561 public void setId(Long id) { iId = id; }
562
563 public String getLabel() { return iLabel; }
564 public void setLabel(String label) { iLabel = label; }
565
566 public boolean isRoom() { return iRoom; }
567 public void setRoom(boolean room) { iRoom = room; }
568
569 @Override
570 public int hashCode() { return getId().hashCode(); }
571
572 @Override
573 public boolean equals(Object object) {
574 if (object == null || !(object instanceof RoomTypeInterface)) return true;
575 return getId().equals(((RoomTypeInterface)object).getId());
576 }
577 }
578
579 public static class FeatureTypeInterface implements GwtRpcResponse {
580 private Long iId;
581 private String iAbbv;
582 private String iLabel;
583 private boolean iEvents = false;
584
585 public FeatureTypeInterface() {}
586
587 public FeatureTypeInterface(Long id, String abbv, String label, boolean events) {
588 iId = id; iAbbv = abbv; iLabel = label; iEvents = events;
589 }
590
591 public Long getId() { return iId; }
592 public void setId(Long id) { iId = id; }
593
594 public String getAbbreviation() { return iAbbv; }
595 public void setAbbreviation(String abbv) { iAbbv = abbv; }
596
597 public String getLabel() { return iLabel; }
598 public void setLabel(String label) { iLabel = label; }
599
600 public boolean isEvents() { return iEvents; }
601 public void setEvents(boolean events) { iEvents = events; }
602
603 @Override
604 public int hashCode() { return getId().hashCode(); }
605
606 @Override
607 public boolean equals(Object object) {
608 if (object == null || !(object instanceof FeatureTypeInterface)) return true;
609 return getId().equals(((FeatureTypeInterface)object).getId());
610 }
611 }
612
613 public static class RoomPropertyInterface implements GwtRpcResponse {
614 private Long iId;
615 private String iAbbv;
616 private String iLabel;
617 private String iColor;
618 private String iTitle;
619
620 public RoomPropertyInterface() {}
621
622 public RoomPropertyInterface(Long id, String label) {
623 iId = id; iLabel = label;
624 }
625
626 public RoomPropertyInterface(Long id, String abbv, String label) {
627 iId = id; iAbbv = abbv; iLabel = label;
628 }
629
630 public Long getId() { return iId; }
631 public void setId(Long id) { iId = id; }
632
633 public String getAbbreviation() { return iAbbv; }
634 public void setAbbreviation(String abbv) { iAbbv = abbv; }
635
636 public String getLabel() { return iLabel; }
637 public void setLabel(String label) { iLabel = label; }
638
639 public String getColor() { return iColor; }
640 public void setColor(String color) { iColor = color; }
641
642 public String getTitle() { return iTitle; }
643 public void setTitle(String title) { iTitle = title; }
644
645 @Override
646 public int hashCode() { return getId().hashCode(); }
647
648 @Override
649 public boolean equals(Object object) {
650 if (object == null || !(object instanceof RoomPropertyInterface)) return true;
651 return getId().equals(((RoomPropertyInterface)object).getId());
652 }
653 }
654
655 public static class BuildingInterface implements GwtRpcResponse {
656 private Long iId;
657 private String iLabel;
658
659 public BuildingInterface() {}
660
661 public BuildingInterface(Long id, String label) {
662 iId = id; iLabel = label;
663 }
664
665 public Long getId() { return iId; }
666 public void setId(Long id) { iId = id; }
667
668 public String getLabel() { return iLabel; }
669 public void setLabel(String label) { iLabel = label; }
670
671 @Override
672 public int hashCode() { return getId().hashCode(); }
673
674 @Override
675 public boolean equals(Object object) {
676 if (object == null || !(object instanceof BuildingInterface)) return true;
677 return getId().equals(((BuildingInterface)object).getId());
678 }
679 }
680
681 public static class ExamTypeInterface implements GwtRpcResponse {
682 private Long iId;
683 private String iReference;
684 private String iLabel;
685 private boolean iFinal = false;
686
687 public ExamTypeInterface() {}
688
689 public ExamTypeInterface(Long id, String reference, String label, boolean finalExams) {
690 iId = id; iReference = reference; iLabel = label; iFinal = finalExams;
691 }
692
693 public Long getId() { return iId; }
694 public void setId(Long id) { iId = id; }
695
696 public String getReference() { return iReference; }
697 public void setReference(String reference) { iReference = reference; }
698
699 public String getLabel() { return iLabel; }
700 public void setLabel(String label) { iLabel = label; }
701
702 public boolean isFinal() { return iFinal; }
703 public void setFinal(boolean finalExams) { iFinal = finalExams; }
704
705 @Override
706 public int hashCode() { return getId().hashCode(); }
707
708 @Override
709 public boolean equals(Object object) {
710 if (object == null || !(object instanceof ExamTypeInterface)) return true;
711 return getId().equals(((ExamTypeInterface)object).getId());
712 }
713 }
714
715 public static class DepartmentInterface extends RoomPropertyInterface {
716 private String iCode;
717 private boolean iExternal = false;
718 private String iExternalAbbv, iExternalLabel;
719 private PreferenceInterface iPreference;
720
721 public DepartmentInterface() {
722 super();
723 }
724
725 public String getDeptCode() { return iCode; }
726 public void setDeptCode(String code) { iCode = code; }
727 public String getAbbreviationOrCode() { return getAbbreviation() == null || getAbbreviation().isEmpty() ? getDeptCode() : getAbbreviation(); }
728 public String getExtAbbreviationOrCode() { return getExtAbbreviation() == null || getExtAbbreviation().isEmpty() ? getDeptCode() : getExtAbbreviation(); }
729
730 public boolean isExternal() { return iExternal; }
731 public void setExternal(boolean external) { iExternal = external; }
732
733 public String getExtAbbreviation() { return iExternalAbbv; }
734 public void setExtAbbreviation(String abbv) { iExternalAbbv = abbv; }
735 public String getExtAbbreviationWhenExist() { return getExtAbbreviation() == null || getExtAbbreviation().isEmpty() ? getAbbreviationOrCode() : getExtAbbreviation(); }
736
737 public String getExtLabel() { return iExternalLabel; }
738 public void setExtLabel(String label) { iExternalLabel = label; }
739 public String getExtLabelWhenExist() { return getExtLabel() == null || getExtLabel().isEmpty() ? getLabel() : getExtLabel(); }
740
741 public PreferenceInterface getPreference() { return iPreference; }
742 public void setPreference(PreferenceInterface preference) { iPreference = preference; }
743 }
744
745 public static class FeatureInterface extends RoomPropertyInterface {
746 private DepartmentInterface iDepartment = null;
747 private FeatureTypeInterface iType;
748
749 public FeatureInterface() {
750 super();
751 }
752
753 public FeatureInterface(Long id, String abbv, String label) {
754 super(id, abbv, label);
755 }
756
757 public boolean isDepartmental() { return iDepartment != null; }
758 public DepartmentInterface getDepartment() { return iDepartment; }
759 public void setDepartment(DepartmentInterface department) { iDepartment = department; }
760
761 public boolean hasType() { return iType != null; }
762 public FeatureTypeInterface getType() { return iType; }
763 public void setType(FeatureTypeInterface type) { iType = type; }
764 }
765
766 public static class GroupInterface extends RoomPropertyInterface {
767 private DepartmentInterface iDepartment = null;
768
769 public GroupInterface() {
770 super();
771 }
772
773 public GroupInterface(Long id, String abbv, String label) {
774 super(id, abbv, label);
775 }
776
777 public boolean isDepartmental() { return iDepartment != null; }
778 public DepartmentInterface getDepartment() { return iDepartment; }
779 public void setDepartment(DepartmentInterface department) { iDepartment = department; }
780 }
781
782 public static class RoomDetailInterface extends FilterRpcResponse.Entity {
783 private static final long serialVersionUID = 1L;
784
785 private BuildingInterface iBuilding;
786 private RoomTypeInterface iRoomType;
787 private Integer iCapacity, iExamCapacity;
788 private Double iX, iY, iArea;
789 private DepartmentInterface iControlDepartment, iEventDepartment;
790 private List<DepartmentInterface> iDepartments = new ArrayList<DepartmentInterface>();
791 private List<GroupInterface> iGroups = new ArrayList<GroupInterface>();
792 private List<FeatureInterface> iFeatures = new ArrayList<FeatureInterface>();
793 private List<ExamTypeInterface> iExamTypes = new ArrayList<ExamTypeInterface>();
794 private boolean iIgnoreTooFar = false, iIgnoreRoomCheck = false;
795 private String iPeriodPreference = null, iAvailability = null, iEventAvailability = null;
796 private String iRoomSharingNote = null, iEventNote = null, iDefaultEventNote = null;
797 private Integer iEventStatus = null, iBreakTime = null, iDefaultEventStatus = null, iDefaultBreakTime = null;
798 private String iPrefix = null;
799 private boolean iCanShowDetail = false, iCanSeeAvailability = false, iCanSeePeriodPreferences = false, iCanSeeEventAvailability = false;
800 private boolean iCanChange = false, iCanChangeAvailability = false, iCanChangeControll = false, iCanChangeExternalId = false, iCanChangeType = false, iCanChangeCapacity = false, iCanChangeExamStatus = false,
801 iCanChangeRoomProperties = false, iCanChangeEventProperties = false, iCanChangePicture = false, iCanChangePreferences = false,
802 iCanChangeGroups = false, iCanChangeFeatures = false, iCanChangeEventAvailability = false;
803 private boolean iCanDelete = false;
804
805 public RoomDetailInterface() {}
806
807 public RoomDetailInterface(Long uniqueId, String displayName, String label, String... properties) {
808 super(uniqueId, displayName, label, properties);
809 }
810
811 public RoomDetailInterface(FilterRpcResponse.Entity entity) {
812 setUniqueId(entity.getUniqueId());
813 setAbbreviation(entity.getAbbreviation());
814 setName(entity.getName());
815 String roomType = entity.getProperty("type", null);
816 if (roomType != null)
817 setRoomType(new RoomTypeInterface(-1l, roomType, true));
818 String capacity = entity.getProperty("capacity", null);
819 if (capacity != null)
820 setCapacity(Integer.valueOf(capacity));
821 }
822
823 public String getLabel() { return getName(); }
824
825 public String getDisplayName() { return getAbbreviation(); }
826 public boolean hasDisplayName() { return getAbbreviation() != null && !getAbbreviation().isEmpty(); }
827
828 public RoomTypeInterface getRoomType() { return iRoomType; }
829 public void setRoomType(RoomTypeInterface roomType) { iRoomType = roomType; }
830
831 public Integer getCapacity() { return iCapacity; }
832 public void setCapacity(Integer capacity) { iCapacity = capacity ; }
833
834 public Integer getExamCapacity() { return iExamCapacity; }
835 public void setExamCapacity(Integer capacity) { iExamCapacity = capacity ; }
836
837 public List<GroupInterface> getGroups() { return iGroups; }
838 public void addGroup(GroupInterface group) { iGroups.add(group); }
839 public boolean hasGroups() { return iGroups != null && !iGroups.isEmpty(); }
840
841 public boolean hasControlDepartment() { return iControlDepartment != null; }
842 public DepartmentInterface getControlDepartment() { return iControlDepartment; }
843 public void setControlDepartment(DepartmentInterface controlDepartment) { iControlDepartment = controlDepartment; }
844
845 public boolean hasEventDepartment() { return iEventDepartment != null; }
846 public DepartmentInterface getEventDepartment() { return iEventDepartment; }
847 public void setEventDepartment(DepartmentInterface eventDepartment) { iEventDepartment = eventDepartment; }
848
849 public List<FeatureInterface> getFeatures() { return iFeatures; }
850 public void addFeature(FeatureInterface feature) { iFeatures.add(feature); }
851 public boolean hasFeatures() { return iFeatures != null && !iFeatures.isEmpty(); }
852
853 public List<DepartmentInterface> getDepartments() { return iDepartments; }
854 public void addDepartment(DepartmentInterface department) { iDepartments.add(department); }
855 public boolean hasDepartments() { return iDepartments != null && !iDepartments.isEmpty(); }
856
857 public BuildingInterface getBuilding() { return iBuilding; }
858 public void setBuilding(BuildingInterface building) { iBuilding = building; }
859
860 public boolean hasCoordinates() { return iX != null && iY != null; }
861 public Double getX() { return iX; }
862 public void setX(Double x) { iX = x; }
863
864 public Double getY() { return iY; }
865 public void setY(Double y) { iY = y; }
866
867 public Double getArea() { return iArea; }
868 public void setArea(Double area) { iArea = area; }
869
870 public boolean hasPreference(String deptCode) {
871 for (DepartmentInterface d: getDepartments()) {
872 if (!d.getDeptCode().equals(deptCode) && d.getPreference() != null) return true;
873 }
874 return false;
875 }
876
877 public boolean isIgnoreRoomCheck() { return iIgnoreRoomCheck; }
878 public void setIgnoreRoomCheck(boolean ignoreRoomCheck) { iIgnoreRoomCheck = ignoreRoomCheck; }
879
880 public boolean isIgnoreTooFar() { return iIgnoreTooFar; }
881 public void setIgnoreTooFar(boolean ignoreTooFar) { iIgnoreTooFar = ignoreTooFar; }
882
883 public boolean hasExamTypes() { return iExamTypes != null && !iExamTypes.isEmpty(); }
884 public List<ExamTypeInterface> getExamTypes() { return iExamTypes; }
885 public void addExamRype(ExamTypeInterface type) { iExamTypes.add(type); }
886
887 public String getPeriodPreference() { return iPeriodPreference; }
888 public void setPeriodPreference(String pref) { iPeriodPreference = pref; }
889
890 public String getAvailability() { return iAvailability; }
891 public void setAvailability(String availability) { iAvailability = availability; }
892
893 public String getEventAvailability() { return iEventAvailability; }
894 public void setEventAvailability(String availability) { iEventAvailability = availability; }
895
896 public String getRoomSharingNote() { return iRoomSharingNote; }
897 public void setRoomSharingNote(String note) { iRoomSharingNote = note; }
898
899 public String getEventNote() { return iEventNote; }
900 public void setEventNote(String note) { iEventNote = note; }
901 public boolean hasEventNote() { return iEventNote != null && !iEventNote.isEmpty(); }
902
903 public Integer getEventStatus() { return iEventStatus; }
904 public void setEventStatus(Integer eventStatus) { iEventStatus = eventStatus; }
905
906 public Integer getBreakTime() { return iBreakTime; }
907 public void setBreakTime(Integer breakTime) { iBreakTime = breakTime; }
908
909 public String getDefaultEventNote() { return iDefaultEventNote; }
910 public void setDefaultEventNote(String note) { iDefaultEventNote = note; }
911 public boolean hasDefaultEventNote() { return iDefaultEventNote != null && !iDefaultEventNote.isEmpty(); }
912
913 public Integer getDefaultEventStatus() { return iDefaultEventStatus; }
914 public void setDefaultEventStatus(Integer eventStatus) { iDefaultEventStatus = eventStatus; }
915
916 public Integer getDefaultBreakTime() { return iDefaultBreakTime; }
917 public void setDefaultBreakTime(Integer breakTime) { iDefaultBreakTime = breakTime; }
918
919 public String getPrefix() { return iPrefix; }
920 public void setPrefix(String prefix) { iPrefix = prefix; }
921
922 public boolean isCanShowDetail() { return iCanShowDetail; }
923 public void setCanShowDetail(boolean canShowDetail) { iCanShowDetail = canShowDetail; }
924
925 public boolean isCanSeeAvailability() { return iCanSeeAvailability; }
926 public void setCanSeeAvailability(boolean canSeeAvailability) { iCanSeeAvailability = canSeeAvailability; }
927
928 public boolean isCanSeePeriodPreferences() { return iCanSeePeriodPreferences; }
929 public void setCanSeePeriodPreferences(boolean canSeePeriodPreferences) { iCanSeePeriodPreferences = canSeePeriodPreferences; }
930
931 public boolean isCanSeeEventAvailability() { return iCanSeeEventAvailability; }
932 public void setCanSeeEventAvailability(boolean canSeeEventAvailability) { iCanSeeEventAvailability = canSeeEventAvailability; }
933
934 public boolean isCanChange() { return iCanChange; }
935 public void setCanChange(boolean canChange) { iCanChange = canChange; }
936
937 public boolean isCanChangeAvailability() { return iCanChangeAvailability; }
938 public void setCanChangeAvailability(boolean canChangeAvailability) { iCanChangeAvailability = canChangeAvailability; }
939
940 public boolean isCanChangeControll() { return iCanChangeControll; }
941 public void setCanChangeControll(boolean canChangeControll) { iCanChangeControll = canChangeControll; }
942
943 public boolean isCanChangeExternalId() { return iCanChangeExternalId; }
944 public void setCanChangeExternalId(boolean canChangeExternalId) { iCanChangeExternalId = canChangeExternalId; }
945
946 public boolean isCanChangeType() { return iCanChangeType; }
947 public void setCanChangeType(boolean canChangeType) { iCanChangeType = canChangeType; }
948
949 public boolean isCanChangeCapacity() { return iCanChangeCapacity; }
950 public void setCanChangeCapacity(boolean canChangeCapacity) { iCanChangeCapacity = canChangeCapacity; }
951
952 public boolean isCanChangeExamStatus() { return iCanChangeExamStatus; }
953 public void setCanChangeExamStatus(boolean canChangeExamStatus) { iCanChangeExamStatus = canChangeExamStatus; }
954
955 public boolean isCanChangeRoomProperties() { return iCanChangeRoomProperties; }
956 public void setCanChangeRoomProperties(boolean canChangeRoomProperties) { iCanChangeRoomProperties = canChangeRoomProperties; }
957
958 public boolean isCanChangeEventProperties() { return iCanChangeEventProperties; }
959 public void setCanChangeEventProperties(boolean canChangeEventProperties) { iCanChangeEventProperties = canChangeEventProperties; }
960
961 public boolean isCanChangePicture() { return iCanChangePicture; }
962 public void setCanChangePicture(boolean canChangePicture) { iCanChangePicture = canChangePicture; }
963
964 public boolean isCanChangePreferences() { return iCanChangePreferences; }
965 public void setCanChangePreferences(boolean canChangePreferences) { iCanChangePreferences = canChangePreferences; }
966
967 public boolean isCanChangeGroups() { return iCanChangeGroups; }
968 public void setCanChangeGroups(boolean canChangeGroups) { iCanChangeGroups = canChangeGroups; }
969
970 public boolean isCanChangeFeatures() { return iCanChangeFeatures; }
971 public void setCanChangeFeatures(boolean canChangeFeatures) { iCanChangeFeatures = canChangeFeatures; }
972
973 public boolean isCanChangeEventAvailability() { return iCanChangeEventAvailability; }
974 public void setCanChangeEventAvailability(boolean canChangeEventAvailability) { iCanChangeEventAvailability = canChangeEventAvailability; }
975
976 public boolean isCanDelete() { return iCanDelete; }
977 public void setCanDelete(boolean canDelete) { iCanDelete = canDelete; }
978 }
979
980 public static class RoomDetailsRequest implements GwtRpcRequest<GwtRpcResponseList<RoomDetailInterface>> {
981 private List<Long> iLocationIds = new ArrayList<Long>();
982 private String iDepartment = null;
983
984 public RoomDetailsRequest() {}
985
986 public void setDepartment(String department) { iDepartment = department; }
987 public String getDepartment() { return iDepartment; }
988
989 public boolean hasLocationIds() { return iLocationIds != null && !iLocationIds.isEmpty(); }
990 public List<Long> getLocationIds() { return iLocationIds; }
991 public void addLocationId(Long locationId) { iLocationIds.add(locationId); }
992
993 public int size() { return iLocationIds == null ? 0 : iLocationIds.size(); }
994
995 public String toString() { return "" + getLocationIds(); }
996
997 public static RoomDetailsRequest load(Long... locationId) {
998 RoomDetailsRequest request = new RoomDetailsRequest();
999 for (Long id: locationId)
1000 request.addLocationId(id);
1001 return request;
1002 }
1003 }
1004
1005 public static class PreferenceInterface implements IsSerializable {
1006 private String iCode, iName;
1007 private String iColor;
1008 private Long iId;
1009 private boolean iEditable;
1010
1011 public PreferenceInterface() {}
1012 public PreferenceInterface(Long id, String color, String code, String name, boolean editable) {
1013 iId = id; iColor = color; iCode = code; iName = name; iEditable = editable;
1014 }
1015
1016 public String getColor() { return iColor; }
1017 public void setColor(String color) { iColor = color; }
1018
1019 public String getCode() { return iCode; }
1020 public void setCode(String code) { iCode = code; }
1021
1022 public String getName() { return iName; }
1023 public void setName(String name) { iName = name; }
1024
1025 public Long getId() { return iId; }
1026 public void setId(Long id) { iId = id; }
1027
1028 public void setEditable(boolean editable) { iEditable = editable; }
1029 public boolean isEditable() { return iEditable; }
1030
1031 @Override
1032 public boolean equals(Object o) {
1033 if (o == null || !(o instanceof PreferenceInterface)) return false;
1034 return getId().equals(((PreferenceInterface)o).getId());
1035 }
1036
1037 @Override
1038 public int hashCode() {
1039 return getId().hashCode();
1040 }
1041 }
1042
1043 public static class PeriodInterface implements IsSerializable {
1044 private Long iId;
1045 private int iDay, iStart, iLength;
1046
1047 public PeriodInterface() {}
1048
1049 public PeriodInterface(Long id, int day, int start, int length) {
1050 iId = id; iDay = day; iStart = start; iLength = length;
1051 }
1052
1053 public Long getId() { return iId; }
1054 public void setId(Long id) { iId = id; }
1055
1056 public int getDay() { return iDay; }
1057 public void setDay(int day) { iDay = day; }
1058
1059 public int getStartSlot() { return iStart; }
1060 public void setStartSlot(int start) { iStart = start; }
1061
1062 public int getLength() { return iLength; }
1063 public void setLength(int length) { iLength = length; }
1064
1065 }
1066
1067 public static class PeriodPreferenceModel implements IsSerializable, GwtRpcResponse {
1068 private ExamTypeInterface iExamType;
1069 private Long iLocationId;
1070 private Long iDefaultPreference;
1071 private Date iFirstDate;
1072 private TreeSet<Integer> iStarts = new TreeSet<Integer>();
1073 private TreeSet<Integer> iDays = new TreeSet<Integer>();
1074 private List<PreferenceInterface> iPreferences = new ArrayList<PreferenceInterface>();
1075 private List<PeriodInterface> iPeriods = new ArrayList<PeriodInterface>();
1076 private Map<Integer, Map<Integer, Long>> iModel;
1077
1078 public PeriodPreferenceModel() {}
1079
1080 public ExamTypeInterface getExamType() { return iExamType; }
1081 public void setExamType(ExamTypeInterface examType) { iExamType = examType; }
1082
1083 public void setLocationId(Long id) { iLocationId = id; }
1084 public Long getLocationId() { return iLocationId; }
1085
1086 public Date getFirstDate() { return iFirstDate; }
1087 public void setFirstDate(Date date) { iFirstDate = date; }
1088
1089 public TreeSet<Integer> getDays() { return iDays; }
1090 public TreeSet<Integer> getSlots() { return iStarts; }
1091 public int getLength(int slot) {
1092 for (PeriodInterface p: iPeriods)
1093 if (p.getStartSlot() == slot) return p.getLength();
1094 return 12;
1095 }
1096
1097 public void setDefaultPreference(PreferenceInterface preference) {
1098 iDefaultPreference = (preference == null ? null : preference.getId());
1099 }
1100
1101 public PreferenceInterface getDefaultPreference() {
1102 return getPreference(iDefaultPreference);
1103 }
1104
1105 public PreferenceInterface getPreference(Long id) {
1106 if (id == null) id = iDefaultPreference;
1107 if (iPreferences == null || id == null) return null;
1108 for (PreferenceInterface preference: iPreferences)
1109 if (preference.getId().equals(id)) return preference;
1110 return (!id.equals(iDefaultPreference) ? getPreference(iDefaultPreference) : null);
1111 }
1112
1113 public void addPreference(PreferenceInterface preference) {
1114 if (iPreferences == null) iPreferences = new ArrayList<PreferenceInterface>();
1115 iPreferences.add(preference);
1116 }
1117
1118 public List<PreferenceInterface> getPreferences() { return iPreferences; }
1119
1120 public void addPeriod(PeriodInterface period) {
1121 iPeriods.add(period);
1122 iDays.add(period.getDay());
1123 iStarts.add(period.getStartSlot());
1124 }
1125
1126 public List<PeriodInterface> getPeriods() { return iPeriods; }
1127 public PeriodInterface getPeriod(int day, int slot) {
1128 for (PeriodInterface p: iPeriods)
1129 if (p.getDay() == day && p.getStartSlot() == slot)
1130 return p;
1131 return null;
1132 }
1133
1134 public PreferenceInterface getPreference(int day, int slot) {
1135 if (iModel == null) return getPreference(iDefaultPreference);
1136 Map<Integer, Long> slot2id = iModel.get(day);
1137 return getPreference(slot2id == null ? null : slot2id.get(slot));
1138 }
1139
1140 public void setPreference(int day, int slot, Long optionId) {
1141 if (iModel == null) iModel = new HashMap<Integer, Map<Integer,Long>>();
1142 Map<Integer, Long> slot2id = iModel.get(day);
1143 if (slot2id == null) {
1144 slot2id = new HashMap<Integer, Long>();
1145 iModel.put(day, slot2id);
1146 }
1147 if (optionId == null)
1148 slot2id.remove(slot);
1149 else
1150 slot2id.put(slot, optionId);
1151 }
1152
1153 public void setPreference(int day, int slot, PreferenceInterface preference) {
1154 setPreference(day, slot, preference == null ? null : preference.getId());
1155 }
1156 }
1157
1158 public static class PeriodPreferenceRequest implements GwtRpcRequest<PeriodPreferenceModel> {
1159 public static enum Operation implements IsSerializable {
1160 LOAD,
1161 SAVE
1162 }
1163 private Operation iOperation;
1164 private Long iLocationId;
1165 private PeriodPreferenceModel iModel;
1166 private Long iExamTypeId = null;
1167
1168 public PeriodPreferenceRequest() {}
1169
1170 public Long getLocationId() { return iLocationId; }
1171 public void setLocationId(Long locationId) { iLocationId = locationId; }
1172
1173 public PeriodPreferenceModel getModel() { return iModel; }
1174 public void setModel(PeriodPreferenceModel model) { iModel = model; }
1175
1176 public Operation getOperation() { return iOperation; }
1177 public void setOperation(Operation operation) { iOperation = operation; }
1178
1179 public String toString() { return getOperation().name() + "[" + getLocationId() + "," + getExamTypeId() + "]"; }
1180
1181 public Long getExamTypeId() { return iExamTypeId; }
1182 public void setExamTypeId(Long examTypeId) { iExamTypeId = examTypeId; }
1183
1184 public static PeriodPreferenceRequest load(Long locationId, Long examTypeId) {
1185 PeriodPreferenceRequest request = new PeriodPreferenceRequest();
1186 request.setOperation(Operation.LOAD);
1187 request.setLocationId(locationId);
1188 request.setExamTypeId(examTypeId);
1189 return request;
1190 }
1191
1192 public static PeriodPreferenceRequest save(Long locationId, Long examTypeId, PeriodPreferenceModel model) {
1193 PeriodPreferenceRequest request = new PeriodPreferenceRequest();
1194 request.setOperation(Operation.SAVE);
1195 request.setLocationId(locationId);
1196 request.setModel(model);
1197 request.setExamTypeId(examTypeId);
1198 return request;
1199 }
1200 }
1201
1202 public static class RoomPropertiesRequest implements GwtRpcRequest<RoomPropertiesInterface> {
1203
1204 public RoomPropertiesRequest() {}
1205
1206 @Override
1207 public String toString() { return ""; }
1208 }
1209
1210 public static class RoomPropertiesInterface implements GwtRpcResponse {
1211 private Long iSessionId = null;
1212 private boolean iCanExportPdf = false, iCanExportCsv = false;
1213 private boolean iCanEditDepartments = false;
1214 private boolean iCanEditRoomExams = false;
1215 private boolean iCanAddRoom = false;
1216
1217 public RoomPropertiesInterface() {}
1218
1219 public Long getAcademicSessionId() { return iSessionId; }
1220 public void setAcademicSessionId(Long sessionId) { iSessionId = sessionId; }
1221
1222 public boolean isCanEditDepartments() { return iCanEditDepartments; }
1223 public void setCanEditDepartments(boolean canEditDepartments) { iCanEditDepartments = canEditDepartments; }
1224
1225 public boolean isCanExportPdf() { return iCanExportPdf; }
1226 public void setCanExportPdf(boolean canExportPdf) { iCanExportPdf = canExportPdf; }
1227
1228 public boolean isCanExportCsv() { return iCanExportCsv; }
1229 public void setCanExportCsv(boolean canExportCsv) { iCanExportCsv = canExportCsv; }
1230
1231 public boolean isCanEditRoomExams() { return iCanEditRoomExams; }
1232 public void setCanEditRoomExams(boolean canEditRoomExams) { iCanEditRoomExams = canEditRoomExams; }
1233
1234 public boolean isCanAddRoom() { return iCanAddRoom; }
1235 public void setCanAddRoom(boolean canAddRoom) { iCanAddRoom = canAddRoom; }
1236 }
1237
1238 public static enum RoomFlag implements IsSerializable {
1239 SHOW_TYPE,
1240 SHOW_CAPACITY,
1241 SHOW_EXAM_CAPACITY(false),
1242 SHOW_AREA(false),
1243 SHOW_COORDINATES(false),
1244 SHOW_IGNORE_DISTANCES,
1245 SHOW_IGNORE_ROOM_CHECK,
1246 SHOW_PREFERENCE(false),
1247 SHOW_AVAILABILITY,
1248 SHOW_DEPARTMENTS,
1249 SHOW_CONTROLLING_DEPARTMENT,
1250 SHOW_EXAM_TYPES(false),
1251 SHOW_PERIOD_PREFERENCES(false),
1252 SHOW_EVENT_DEPARTMENT(false),
1253 SHOW_EVENT_STATUS(false),
1254 SHOW_EVENT_AVAILABILITY(false),
1255 SHOW_EVENT_MESSAGE(false),
1256 SHOW_BREAK_TIME(false),
1257 SHOW_GROUPS,
1258 SHOW_FEATURES,
1259 ;
1260
1261 private boolean iShowWhenEmpty = true;
1262 RoomFlag(boolean showWhenEmpty) { iShowWhenEmpty = showWhenEmpty;}
1263 RoomFlag() {}
1264
1265 public boolean isShowWhenEmpty() { return iShowWhenEmpty; }
1266
1267 public int flag() { return 1 << ordinal(); }
1268 public boolean in(int flags) {
1269 return (flags & flag()) != 0;
1270 }
1271 public int set(int flags) {
1272 return (in(flags) ? flags : flags + flag());
1273 }
1274 public int clear(int flags) {
1275 return (in(flags) ? flags - flag() : flags);
1276 }
1277 }
1278
1279 public static enum RoomsPageMode implements IsSerializable {
1280 COURSES("department:Managed", RoomFlag.SHOW_TYPE, RoomFlag.SHOW_CAPACITY, RoomFlag.SHOW_AREA, RoomFlag.SHOW_AVAILABILITY, RoomFlag.SHOW_DEPARTMENTS, RoomFlag.SHOW_FEATURES, RoomFlag.SHOW_GROUPS),
1281 EXAMS("department:Managed", RoomFlag.SHOW_TYPE, RoomFlag.SHOW_CAPACITY, RoomFlag.SHOW_EXAM_CAPACITY, RoomFlag.SHOW_AREA,
1282 RoomFlag.SHOW_EXAM_TYPES, RoomFlag.SHOW_EXAM_CAPACITY, RoomFlag.SHOW_PERIOD_PREFERENCES, RoomFlag.SHOW_FEATURES, RoomFlag.SHOW_GROUPS),
1283 EVENTS("flag:Events department:Managed", RoomFlag.SHOW_TYPE, RoomFlag.SHOW_CAPACITY, RoomFlag.SHOW_AREA, RoomFlag.SHOW_EVENT_AVAILABILITY, RoomFlag.SHOW_EVENT_DEPARTMENT, RoomFlag.SHOW_EVENT_STATUS,
1284 RoomFlag.SHOW_EVENT_MESSAGE, RoomFlag.SHOW_FEATURES, RoomFlag.SHOW_GROUPS),
1285 ;
1286 private String iQuery;
1287 private int iFlags;
1288 RoomsPageMode(String query, RoomFlag... flags) {
1289 iQuery = query;
1290 iFlags = 0;
1291 for (RoomFlag f: flags) iFlags += f.flag();
1292 }
1293
1294 public String getQuery() { return iQuery; }
1295 public int getFlags() { return iFlags; }
1296 }
1297
1298 public static class RoomFilterRpcRequest extends org.unitime.timetable.gwt.shared.EventInterface.RoomFilterRpcRequest {
1299 private static final long serialVersionUID = 1L;
1300
1301 public RoomFilterRpcRequest() {
1302 super();
1303 }
5471304 }
5481305}
JavaSource/org/unitime/timetable/model/MidtermPeriodPreferenceModel.java
(5 / 5)
  
4141 */
4242public class MidtermPeriodPreferenceModel {
4343 protected static GwtConstants CONSTANTS = Localization.create(GwtConstants.class);
44 private TreeSet<Integer> iDates = new TreeSet<Integer>();
45 private TreeSet<Integer> iStarts = new TreeSet<Integer>();
46 private Hashtable<Integer,Hashtable<Integer,String>> iPreferences = new Hashtable<Integer,Hashtable<Integer,String>>();
47 private Hashtable<Integer,Integer> iLength = new Hashtable<Integer,Integer>();
44 protected TreeSet<Integer> iDates = new TreeSet<Integer>();
45 protected TreeSet<Integer> iStarts = new TreeSet<Integer>();
46 protected Hashtable<Integer,Hashtable<Integer,String>> iPreferences = new Hashtable<Integer,Hashtable<Integer,String>>();
47 protected Hashtable<Integer,Integer> iLength = new Hashtable<Integer,Integer>();
4848 private TreeSet iPeriods = null;
4949 private Date iFirstDate = null, iLastDate = null;
50 private boolean iLocation = false;
50 protected boolean iLocation = false;
5151
5252 private ExamPeriod iPeriod = null;
5353 private Date iExamBeginDate = null;
JavaSource/org/unitime/timetable/model/RoomSharingModel.java
(1 / 1)
  
336336 iDefaultSelection = 0;
337337 if (selection==null) return;
338338 for (int i=0;i<getNrSelections();i++) {
339 if (selection.equalsIgnoreCase(getSelectionName(i).replaceAll("&times;","x").replaceAll("×", "x"))) {
339 if (selection.equals(iModes.get(i).toHex()) || selection.equalsIgnoreCase(getSelectionName(i).replaceAll("&times;","x").replaceAll("×", "x"))) {
340340 iDefaultSelection = i;
341341 break;
342342 }
JavaSource/org/unitime/timetable/server/rooms/RoomDetailsBackend.java
(251 / 0)
  
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*/
20package org.unitime.timetable.server.rooms;
21
22import java.util.HashMap;
23import java.util.List;
24import java.util.Map;
25import java.util.Set;
26
27import org.unitime.localization.impl.Localization;
28import org.unitime.localization.messages.CourseMessages;
29import org.unitime.timetable.defaults.CommonValues;
30import org.unitime.timetable.defaults.UserProperty;
31import org.unitime.timetable.events.RoomFilterBackend;
32import org.unitime.timetable.gwt.command.server.GwtRpcImplements;
33import org.unitime.timetable.gwt.resources.GwtMessages;
34import org.unitime.timetable.gwt.server.Query;
35import org.unitime.timetable.gwt.shared.EventInterface.FilterRpcResponse;
36import org.unitime.timetable.gwt.shared.EventInterface.FilterRpcResponse.Entity;
37import org.unitime.timetable.gwt.shared.RoomInterface.DepartmentInterface;
38import org.unitime.timetable.gwt.shared.RoomInterface.ExamTypeInterface;
39import org.unitime.timetable.gwt.shared.RoomInterface.FeatureInterface;
40import org.unitime.timetable.gwt.shared.RoomInterface.FeatureTypeInterface;
41import org.unitime.timetable.gwt.shared.RoomInterface.GroupInterface;
42import org.unitime.timetable.gwt.shared.RoomInterface.PreferenceInterface;
43import org.unitime.timetable.gwt.shared.RoomInterface.RoomDetailInterface;
44import org.unitime.timetable.gwt.shared.RoomInterface.RoomFilterRpcRequest;
45import org.unitime.timetable.gwt.shared.RoomInterface.RoomTypeInterface;
46import org.unitime.timetable.model.Department;
47import org.unitime.timetable.model.DepartmentRoomFeature;
48import org.unitime.timetable.model.DepartmentStatusType;
49import org.unitime.timetable.model.ExamType;
50import org.unitime.timetable.model.Location;
51import org.unitime.timetable.model.PreferenceLevel;
52import org.unitime.timetable.model.RoomDept;
53import org.unitime.timetable.model.RoomFeature;
54import org.unitime.timetable.model.RoomFeatureType;
55import org.unitime.timetable.model.RoomGroup;
56import org.unitime.timetable.model.RoomTypeOption;
57import org.unitime.timetable.security.SessionContext;
58import org.unitime.timetable.security.rights.Right;
59
60/**
61 * @author Tomas Muller
62 */
63@GwtRpcImplements(RoomFilterRpcRequest.class)
64public class RoomDetailsBackend extends RoomFilterBackend {
65 protected static final GwtMessages MESSAGES = Localization.create(GwtMessages.class);
66 public static final CourseMessages MSG = Localization.create(CourseMessages.class);
67
68 @Override
69 public FilterRpcResponse execute(org.unitime.timetable.gwt.shared.EventInterface.RoomFilterRpcRequest request, EventContext context) {
70 context.checkPermission(Right.Rooms);
71
72 return super.execute(request, context);
73 }
74
75 @Override
76 protected boolean checkEventStatus() { return false; }
77
78 @Override
79 protected boolean showRoomFeature(RoomFeatureType type) { return true; }
80
81 @Override
82 public RoomQuery getQuery(Long sessionId, Map<String, Set<String>> options) {
83 RoomQuery query = super.getQuery(sessionId, options);
84
85 Set<String> flags = (options == null ? null : options.get("flag"));
86 boolean fetch = (flags != null && flags.contains("fetch"));
87 if (fetch) {
88 query.addFrom("fetch", "left join fetch l.roomDepts Frd " +
89 " left join fetch l.examTypes Fxt" +
90 " left join fetch l.features Ff" +
91 " left join fetch l.roomGroups Fg" +
92 " left join fetch l.roomType Ft");
93 }
94
95 return query;
96 }
97
98 @Override
99 public void enumarate(org.unitime.timetable.gwt.shared.EventInterface.RoomFilterRpcRequest request, FilterRpcResponse response, EventContext context) {
100 fixRoomFeatureTypes(request);
101 request.addOption("flag", "fetch");
102
103 String department = request.getOption("department");
104 boolean filterDepartments = !context.getUser().getCurrentAuthority().hasRight(Right.DepartmentIndependent);
105 List<ExamType> types = ExamType.findAllApplicable(context.getUser(), DepartmentStatusType.Status.ExamView, DepartmentStatusType.Status.ExamTimetable);