BTW while working on that I have noticed that sorting on that table does not work if you select "Platform", "Other labels" or "Locked", that is all *derived* fields, to see that just click on one of these headings.
I don't know the easy way to really fix that but at least we should consider blocking the sorting event on these columns so end users will not hit the "FieldError" Cannot resolve the keyword..." Julius -----Original Message----- From: Gawlas, Julius Sent: Tuesday, February 12, 2013 10:13 AM To: [email protected] Cc: Gawlas, Julius Subject: [PATCH] Break labels in host table into multiple lines if they exceed the limit If host has many labels the display in create job will create a very wide table pushing the selected hosts way to the right making it almost impossible to use. This change will break labels column into separate lines if labales length exceeded 80 charactes. This will also apply to Host List page. Added function to Utils to break string into multiple lines. --- frontend/client/src/autotest/afe/HostTable.java | 15 +++++++++- frontend/client/src/autotest/common/Utils.java | 31 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/frontend/client/src/autotest/afe/HostTable.java b/frontend/client/src/autotest/afe/HostTable.java index 8b1b526..407a058 100644 --- a/frontend/client/src/autotest/afe/HostTable.java +++ b/frontend/client/src/autotest/afe/HostTable.java @@ -1,12 +1,15 @@ package autotest.afe; +import autotest.common.Utils; import autotest.common.table.DataSource; import autotest.common.table.DynamicTable; -import java.util.ArrayList; -import java.util.Arrays; +import com.google.gwt.json.client.JSONObject; +import com.google.gwt.json.client.JSONString; public class HostTable extends DynamicTable { + private final int MAX_LABELS_COLUMN_WIDTH = 80; + protected static final String[][] HOST_COLUMNS = { {"hostname", "Hostname"}, {"platform", "Platform"}, {HostDataSource.OTHER_LABELS, "Other labels"}, {"status", "Status"}, @@ -20,4 +23,12 @@ public class HostTable extends DynamicTable { public HostTable(String[][] columns, DataSource dataSource) { super(columns, dataSource); } + + @Override + protected void preprocessRow(JSONObject host) { + // break labels column into separate lines if longer than some limit + String otherLabels = Utils.jsonToString(host.get(HostDataSource.OTHER_LABELS)); + host.put(HostDataSource.OTHER_LABELS, + new JSONString(Utils.splitIntoLines(otherLabels, MAX_LABELS_COLUMN_WIDTH))); + } } diff --git a/frontend/client/src/autotest/common/Utils.java b/frontend/client/src/autotest/common/Utils.java index 303d378..a0820dc 100644 --- a/frontend/client/src/autotest/common/Utils.java +++ b/frontend/client/src/autotest/common/Utils.java @@ -318,4 +318,35 @@ public class Utils { public static String getBaseUrl() { return Window.Location.getProtocol() + "//" + Window.Location.getHost(); } + + /** + * Split string into multiple lines, preserving words, insert "\n" at the end of lines + * @param input text to be split + * @param maxCharInLine maximum number of characters allowed in a line + * @return + */ + public static String splitIntoLines(String input, int maxCharInLine){ + StringBuilder output = new StringBuilder(input.length()); + int lineLen = 0; + String[] words = input.split("\\s"); // split on all whitespace + int wordIndex = 0; + while (wordIndex < words.length) { + String word = words[wordIndex++]; + while(word.length() > maxCharInLine) { // break words longer than line limit + output.append(word.substring(0, maxCharInLine-lineLen) + "\n"); + word = word.substring(maxCharInLine - lineLen); + lineLen = 0; + } + if (lineLen + word.length() > maxCharInLine) { // break before word breaks line limit + output.append("\n"); + lineLen = 0; + if ( word.length() == 0 ) // skip line ending blanks + continue; + } + output.append(word + " "); + lineLen += word.length() + 1; + } + return output.toString(); + } + } -- 1.7.7.6 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
