On 02/25/2013 02:41 PM, Julius Gawlas wrote:
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 40 charactes. This will also apply to
Host List page.
Added function to Utils to break string into multiple lines.
Looks good, applied to next. Don't forget next time to sign off your
patches.
Cheers,
Lucas
---
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..63d1caa 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 = 40;
+
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();
+ }
+
}
_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel