Add filter on locked_by user on AFE host lists
Signed-off-by: James Ren <[email protected]>
--- autotest/frontend/client/src/autotest/afe/HostTableDecorator.java
2010-05-14 14:04:10.000000000 -0700
+++ autotest/frontend/client/src/autotest/afe/HostTableDecorator.java
2010-05-14 14:04:10.000000000 -0700
@@ -1,5 +1,6 @@
package autotest.afe;
+import autotest.common.SimpleCallback;
import autotest.common.StaticDataRepository;
import autotest.common.Utils;
import autotest.common.table.BooleanFilter;
@@ -10,20 +11,25 @@
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONBoolean;
+import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
-class HostTableDecorator extends TableDecorator {
+import java.util.ArrayList;
+import java.util.List;
+
+class HostTableDecorator extends TableDecorator implements SimpleCallback {
SearchFilter hostnameFilter;
LabelFilter labelFilter;
ListFilter statusFilter;
BooleanFilter lockedFilter;
+ ListFilter lockedByFilter;
AclAccessibleFilter aclFilter;
AtomicGroupFilter excludeAtomicGroupsFilter;
-
+
static class AclAccessibleFilter extends CheckboxFilter {
private JSONValue username;
-
+
public AclAccessibleFilter() {
super("aclgroup__users__login");
username = new
JSONString(StaticDataRepository.getRepository().getCurrentUserLogin());
@@ -34,7 +40,7 @@
return username;
}
}
-
+
static class AtomicGroupFilter extends CheckboxFilter {
public AtomicGroupFilter() {
super("exclude_atomic_group_hosts");
@@ -45,31 +51,58 @@
return JSONBoolean.getInstance(true);
}
}
-
+
public HostTableDecorator(HostTable table, int rowsPerPage) {
super(table);
table.sortOnColumn("hostname"); /* Case sensitive name */
table.setRowsPerPage(rowsPerPage);
addPaginators();
-
+
StaticDataRepository staticData = StaticDataRepository.getRepository();
JSONArray statuses = staticData.getData("host_statuses").isArray();
String[] statusStrings = Utils.JSONtoStrings(statuses);
-
+
+ JSONArray users = staticData.getData("users").isArray();
+ List<String> userStrings = new ArrayList<String>();
+ for (int i = 0; i < users.size(); i++) {
+ JSONObject user = users.get(i).isObject();
+ userStrings.add(Utils.jsonToString(user.get("login")));
+ }
+
hostnameFilter = new SearchFilter("hostname", true);
labelFilter = new LabelFilter();
statusFilter = new ListFilter("status");
statusFilter.setChoices(statusStrings);
lockedFilter = new BooleanFilter("locked");
+ lockedByFilter = new ListFilter("locked_by__login");
+ lockedByFilter.setChoices(userStrings.toArray(new
String[userStrings.size()]));
aclFilter = new AclAccessibleFilter();
excludeAtomicGroupsFilter = new AtomicGroupFilter();
-
+
+ updateLockedByEnabled();
+ lockedFilter.addCallback(this);
+
addFilter("Hostname", hostnameFilter);
addControl("Platform", labelFilter.getPlatformWidget());
addFilter("Label", labelFilter);
addFilter("Status", statusFilter);
addFilter("Locked", lockedFilter);
+ addFilter("Locked By", lockedByFilter);
addFilter("ACL accessible only", aclFilter);
addFilter("Exclude atomic groups", excludeAtomicGroupsFilter);
}
+
+ @Override
+ public void doCallback(Object source) {
+ assert source == lockedFilter;
+ updateLockedByEnabled();
+ }
+
+ private void updateLockedByEnabled() {
+ if (lockedFilter.isActive() && lockedFilter.isSelected()) {
+ lockedByFilter.setEnabled(true);
+ } else {
+ lockedByFilter.setEnabled(false);
+ }
+ }
}
--- autotest/frontend/client/src/autotest/common/table/BooleanFilter.java
2010-05-14 14:04:10.000000000 -0700
+++ autotest/frontend/client/src/autotest/common/table/BooleanFilter.java
2010-05-14 14:04:10.000000000 -0700
@@ -5,7 +5,7 @@
public class BooleanFilter extends ListFilter {
private static final String[] choices = {"Yes", "No"};
-
+
public BooleanFilter(String fieldName) {
super(fieldName);
setChoices(choices);
@@ -16,4 +16,8 @@
String selected = getSelectedText();
params.put(fieldName, JSONBoolean.getInstance(selected.equals("Yes")));
}
+
+ public boolean isSelected() {
+ return getSelectedText().equals("Yes");
+ }
}
--- autotest/frontend/client/src/autotest/common/table/ListFilter.java
2010-05-14 14:04:10.000000000 -0700
+++ autotest/frontend/client/src/autotest/common/table/ListFilter.java
2010-05-14 14:04:10.000000000 -0700
@@ -10,7 +10,7 @@
public class ListFilter extends FieldFilter {
protected ListBox select;
protected String allValuesText = "All values";
-
+
public ListFilter(String fieldName) {
super(fieldName);
select = new ListBox(isMultipleSelect());
@@ -18,10 +18,10 @@
select.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
notifyListeners();
- }
+ }
});
}
-
+
/**
* Subclasses should override this if they wish to use a multi-select
listbox
* @return true if and only if the listbox should be multiple select
@@ -29,42 +29,44 @@
protected boolean isMultipleSelect() {
return false;
}
-
+
/**
* Set the text for that option that matches any value for this filter.
*/
public void setMatchAllText(String text) {
allValuesText = text;
- if (select.getItemCount() > 0)
+ if (select.getItemCount() > 0) {
select.setItemText(0, allValuesText);
+ }
}
-
+
@Override
public void setExactMatch(boolean isExactMatch) {
this.isExactMatch = isExactMatch;
}
-
+
protected String getItemText(int index) {
return select.getItemText(index);
}
-
+
protected String getSelectedText() {
int selected = select.getSelectedIndex();
- if (selected == -1)
+ if (selected == -1) {
return "";
+ }
return getItemText(selected);
}
@Override
public JSONValue getMatchValue() {
- return new JSONString(getSelectedText());
+ return new JSONString(getSelectedText());
}
-
+
@Override
public boolean isActive() {
- return !getSelectedText().equals(allValuesText);
+ return select.isEnabled() && !getSelectedText().equals(allValuesText);
}
-
+
@Override
public Widget getWidget() {
return select;
@@ -72,19 +74,21 @@
public void setChoices(String[] choices) {
String selectedValue = null;
- if (select.getSelectedIndex() != -1)
+ if (select.getSelectedIndex() != -1) {
selectedValue = getSelectedText();
-
+ }
+
select.clear();
select.addItem(allValuesText);
- for (int i = 0; i < choices.length; i++)
+ for (int i = 0; i < choices.length; i++) {
select.addItem(choices[i]);
-
+ }
+
if (selectedValue != null) {
setSelectedChoice(selectedValue);
}
}
-
+
public void setSelectedChoice(String choice) {
for(int i = 0; i < select.getItemCount(); i++) {
if(select.getItemText(i).equals(choice)) {
@@ -92,8 +96,12 @@
return;
}
}
-
+
select.addItem(choice);
select.setSelectedIndex(select.getItemCount() - 1);
}
+
+ public void setEnabled(boolean enabled) {
+ select.setEnabled(enabled);
+ }
}
\ No newline at end of file
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest