if (type != null || userType != UserType.ANYONE) {
queryFilter = new QueryFilter<Object>() {
@Override
public boolean include(Object item) {
State itemState = State.getInstance(item);
boolean typeOk = true;
boolean userOk = true;
if (type != null) {
ObjectType itemType = item instanceof Draft ? ((Draft) item).getObjectType() : itemState.getType();
typeOk = itemType != null && itemType.getGroups().contains(type.getInternalName());
}
if (userType != UserType.ANYONE) {
ToolUser updateUser = itemState.as(Content.ObjectModification.class).getUpdateUser();
if (userType == UserType.ME) {
userOk = page.getUser().equals(updateUser);
} else if (user instanceof ToolUser) {
userOk = user.equals(updateUser);
} else if (user instanceof ToolRole && updateUser != null) {
userOk = user.equals(updateUser.getRole());
}
}
return typeOk && userOk;
}
};
}
int limit = page.pageParam(int.class, "limit", 20);
PaginatedResult<?> drafts = draftsQuery.
and("* matches *").
and(Content.UPDATE_DATE_FIELD + " != missing").
and(page.siteItemsPredicate()).
sortDescending(Content.UPDATE_DATE_FIELD).
selectFiltered(page.param(long.class, "offset"), limit, queryFilter);
page.writeStart("div", "class", "widget widget-unpublishedDrafts");
page.writeStart("h1", "class", "icon icon-object-draft");
page.writeHtml("Unpublished Drafts");
page.writeEnd();
page.writeStart("form",
"method", "get",
"action", page.url(null));
page.writeStart("ul", "class", "oneLine");
if (workflowStateLabels.size() > 1) {
page.writeStart("li");
page.writeStart("select",
"data-bsp-autosubmit", "",
"name", "state");
page.writeStart("option", "value", "");
page.writeHtml("Any Statuses");
page.writeEnd();
for (Map.Entry<String, String> entry : workflowStateLabels.entrySet()) {
String key = entry.getKey();
page.writeStart("option",
"selected", key.equals(state) ? "selected" : null,
"value", key);
page.writeHtml(entry.getValue());
page.writeEnd();
}
page.writeEnd();
page.writeEnd();
}
page.writeStart("li");
page.writeTypeSelect(
ObjectType.getInstance(Content.class).as(ToolUi.class).findDisplayTypes(),
type,
"Any Types",
"name", "typeId",
"data-bsp-autosubmit", "",
"data-searchable", true);
page.writeEnd();
page.writeStart("li");
page.writeHtml("by ");
page.writeStart("select",
"data-bsp-autosubmit", "",
"name", "userType");
for (UserType t : UserType.values()) {
if (t != UserType.ROLE || Query.from(ToolRole.class).first() != null) {
page.writeStart("option",
"selected", t.equals(userType) ? "selected" : null,
"value", t.name());
page.writeHtml(t.getDisplayName());
page.writeEnd();
}
}
page.writeEnd();
page.writeHtml(" ");
Query<?> userQuery;
if (userType == UserType.ROLE) {
userQuery = Query.from(ToolRole.class).sortAscending("name");
} else if (userType == UserType.USER) {
userQuery = Query.from(ToolUser.class).sortAscending("name");
} else {
userQuery = null;
}
if (userQuery != null) {
if (userQuery.hasMoreThan(250)) {
State userState = State.getInstance(user);
page.writeElement("input",
"type", "text",
"class", "objectId",
"data-bsp-autosubmit", "",
"data-editable", false,
"data-label", userState != null ? userState.getLabel() : null,
"data-typeIds", ObjectType.getInstance(ToolRole.class).getId(),
"name", userParameter,
"value", userState != null ? userState.getId() : null);
} else {
page.writeStart("select",
"name", userParameter,
"data-bsp-autosubmit", "",
"data-searchable", "true");
page.writeStart("option", "value", "").writeEnd();
for (Object v : userQuery.selectAll()) {
State userState = State.getInstance(v);
page.writeStart("option",
"value", userState.getId(),
"selected", v.equals(user) ? "selected" : null);
page.writeHtml(userState.getLabel());
page.writeEnd();
}
page.writeEnd();
}
}
page.writeEnd();
page.writeEnd();
page.writeEnd();
if (drafts.getItems().isEmpty()) {
String label = state != null ? workflowStateLabels.get(state) : null;
page.writeStart("div", "class", "message message-info");
page.writeHtml("No ");
page.writeHtml(label != null ? label.toLowerCase(Locale.ENGLISH) : "matching");
page.writeHtml(" items.");
page.writeEnd();
} else {
page.writeStart("ul", "class", "pagination");
if (drafts.hasPrevious()) {
page.writeStart("li", "class", "first");
page.writeStart("a", "href", page.url("", "offset", drafts.getFirstOffset()));
page.writeHtml("Newest");
page.writeEnd();
page.writeEnd();
page.writeStart("li", "class", "previous");
page.writeStart("a", "href", page.url("", "offset", drafts.getPreviousOffset()));
page.writeHtml("Newer ");
page.writeHtml(drafts.getLimit());
page.writeEnd();
page.writeEnd();
}
page.writeStart("li");
page.writeStart("form",
"data-bsp-autosubmit", "",
"method", "get",
"action", page.url(null));
page.writeStart("select", "name", "limit");
for (int l : LIMITS) {
page.writeStart("option",
"value", l,
"selected", limit == l ? "selected" : null);
page.writeHtml("Show ");
page.writeHtml(l);
page.writeEnd();
}
page.writeEnd();
page.writeEnd();
page.writeEnd();
if (drafts.hasNext()) {
page.writeStart("li", "class", "next");
page.writeStart("a", "href", page.url("", "offset", drafts.getNextOffset()));
page.writeHtml("Older ");
page.writeHtml(drafts.getLimit());
page.writeEnd();
page.writeEnd();
}
page.writeEnd();
page.writeStart("table", "class", "links table-striped pageThumbnails");
page.writeStart("tbody");
for (Object item : drafts.getItems()) {
if (item instanceof Draft) {
Draft draft = (Draft) item;
item = draft.getObject();
if (item == null) {
continue;
}
State itemState = State.getInstance(item);
if (!itemState.isVisible() &&
draft.getObjectChanges().isEmpty()) {
continue;
}
UUID draftId = draft.getId();
page.writeStart("tr", "data-preview-url", "/_preview?_cms.db.previewId=" + draftId);
page.writeStart("td");
page.writeStart("span", "class", "visibilityLabel");
page.writeHtml("Update");
page.writeEnd();
page.writeEnd();
page.writeStart("td");
page.writeHtml(page.getTypeLabel(item));
page.writeEnd();
page.writeStart("td", "data-preview-anchor", "");
page.writeStart("a",
"target", "_top",
"href", page.url("/content/edit.jsp",
"id", itemState.getId(),
"draftId", draftId));
page.writeHtml(itemState.getLabel());
page.writeEnd();
page.writeEnd();
page.writeStart("td");
page.writeObjectLabel(draft.as(Content.ObjectModification.class).getUpdateUser());
page.writeEnd();
page.writeEnd();
} else {
State itemState = State.getInstance(item);
UUID itemId = itemState.getId();
page.writeStart("tr", "data-preview-url", "/_preview?_cms.db.previewId=" + itemId);
page.writeStart("td");
page.writeStart("span", "class", "visibilityLabel");
page.writeHtml(itemState.getVisibilityLabel());
page.writeEnd();
page.writeEnd();
page.writeStart("td");
page.writeHtml(page.getTypeLabel(item));
page.writeEnd();
page.writeStart("td", "data-preview-anchor", "");
page.writeStart("a", "href", page.url("/content/edit.jsp", "id", itemId), "target", "_top");
page.writeHtml(itemState.getLabel());
page.writeEnd();
page.writeEnd();
page.writeStart("td");
page.writeObjectLabel(itemState.as(Content.ObjectModification.class).getUpdateUser());
page.writeEnd();
page.writeEnd();
}
}
page.writeEnd();