Skip to content

Commit

Permalink
Instructors: Note
Browse files Browse the repository at this point in the history
- a few adjustments to the Instructors table to avoid extremely wide tables
  - instructor notes can be wrapped and has a max-width (Note column)
  - positions (Position column) and teaching preferences (Teaching Preference column) can be wrapped
  • Loading branch information
tomas-muller committed Dec 5, 2024
1 parent ede87cb commit 4bf160f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 16 additions & 2 deletions JavaSource/org/unitime/commons/web/WebTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class WebTable {
protected boolean iBlankWhenSame = false;

protected WebTableTweakStyle iWebTableTweakStyle = null;
protected WebTableCellStyle iWebTableCellStyle = null;

/** creates a WebTable instance */
public WebTable(int columns, String name, String[] headers, String[] align, boolean[] asc) {
Expand Down Expand Up @@ -114,11 +115,20 @@ public void setWebTableTweakStyle(WebTableTweakStyle style) {
iWebTableTweakStyle = style;
}

public void setCellStyle(WebTableCellStyle style) {
iWebTableCellStyle = style;
}

public String getStyle(WebTableLine line, WebTableLine next, int order) {
String style = (iRowStyle==null?"":iRowStyle+";")+(iWebTableTweakStyle==null?"":iWebTableTweakStyle.getStyleHtml(line, next, order));
return (style==null || style.length()==0? "" : "style=\""+style+"\"");
}

public String getCellStyle(WebTableLine line, int column, String defaultStyle) {
String style = (iWebTableCellStyle == null ? null : iWebTableCellStyle.getCellStyleHtml(line, column));
return (style == null ? defaultStyle : "style=\""+style+"\"");
}

/** sets row (cell) style */
public void setRowStyle(String style) {
iRowStyle = (iRowStyle == null ? "" : iRowStyle + ";") + style;
Expand Down Expand Up @@ -369,7 +379,7 @@ public String printTable(int ordCol) {
blank=false;
if (!blank && line[i] != null) {
sb.append("<td "
+ style
+ getCellStyle(wtline, i, style)
+ " align=\""
+ (iAlign != null ? align(iAlign[i], rtl) : (rtl ? "right" : "left"))
+ "\""
Expand All @@ -382,7 +392,7 @@ public String printTable(int ordCol) {
+ "</td>");
} else {
sb.append("<td "
+ style
+ getCellStyle(wtline, i, style)
+ " "
+ (i == line.length - 1
? " colspan=" + last + " "
Expand Down Expand Up @@ -662,6 +672,10 @@ public static interface WebTableTweakStyle {
public String getStyleHtml(WebTableLine currentLine, WebTableLine nextLine, int orderBy);
}

public static interface WebTableCellStyle {
public String getCellStyleHtml(WebTableLine currentLine, int column);
}

protected CSVField csvField(String text) {
if (text == null) return new CSVField("");
if (text.indexOf("@@")<0) return new CSVField(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ public int compare(InstructorAttributeType o1, InstructorAttributeType o2) {
fixedHeaders2.length + (hasInstructorSurvey ? 1 : 0)];
String[] aligns = new String[headers.length];
boolean[] asc = new boolean[headers.length];
final String[] cs = new String[headers.length];
int idx = 0;
for (String h: fixedHeaders1) {
headers[idx] = h;
aligns[idx] = "left";
asc[idx] = true;
idx++;
}
// position -- can be wrapped
cs[2] = "border-bottom: 1px dashed #9CB0CE;";
// note -- can be wrapped, set max width
cs[3] = "white-space: pre-wrap; max-width: 300px; border-bottom: 1px dashed #9CB0CE;";
if (hasCoursePrefs) {
headers[idx] = "<BR>" + MSG.columnCoursePref();
aligns[idx] = "left";
Expand All @@ -140,6 +145,7 @@ public int compare(InstructorAttributeType o1, InstructorAttributeType o2) {
headers[idx] = MSG.columnTeachingPreference();
aligns[idx] = "left";
asc[idx] = true;
cs[idx] = "border-bottom: 1px dashed #9CB0CE;";
idx++;
}
if (hasUnavailableDates) {
Expand Down Expand Up @@ -177,6 +183,12 @@ public int compare(InstructorAttributeType o1, InstructorAttributeType o2) {
WebTable webTable = new WebTable(headers.length, "", "instructorSearch.action?order=%%&deptId=" + deptId, headers, aligns, asc);
webTable.setRowStyle("white-space:nowrap;");
webTable.enableHR("#9CB0CE");
webTable.setCellStyle(new WebTable.WebTableCellStyle() {
@Override
public String getCellStyleHtml(WebTableLine currentLine, int column) {
return cs[column];
}
});


String instructorNameFormat = UserProperty.NameFormat.get(context.getUser());
Expand Down

0 comments on commit 4bf160f

Please sign in to comment.