Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAK-49250 Site Archive No pagination, no ability to sort columns and no search #13231

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions admin-tools/src/bundle/archive.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,16 @@ archive.download.size = Size
archive.download.hash = Hash <small>(SHA-1)</small>
archive.download.auth = Archive download is limited to administrators.
archive.download.none = No archives are available to download at this time.

archive.search=Search
archive.search.placeholder=Search by site ID or title
archive.search.button=Search
archive.search.clear=Clear Search
archive.search.no.results=No archives found matching your search.

archive.list.youare=Viewing {0} to {1} of {2} items
archive.list.show=Show {0} items
archive.list.first=Go to first page
archive.list.previous.withsize=Previous {0}
archive.list.next.withsize=Next {0}
archive.list.last=Go to last page
129 changes: 124 additions & 5 deletions admin-tools/src/java/org/sakaiproject/archive/tool/ArchiveAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ public class ArchiveAction extends VelocityPortletPaneledAction {
private static final String SINGLE_MODE = "single";
private static final String DOWNLOAD_MODE = "download";
private static final String STATE_SUCCESS_MESSAGE = "successMessage";
private static final String STATE_SEARCH = "search";

private static final String STATE_CURRENT_PAGE = "current-page";
private static final String STATE_PAGESIZE = "pagesize";

/** Resource bundle using current language locale */
private static ResourceLoader rb = new ResourceLoader("archive");

Expand Down Expand Up @@ -140,6 +144,13 @@ protected void initState(SessionState state, HttpServletRequest req, HttpServlet
maxJobTime = Long.valueOf(serverConfigurationService.getInt("archive.max.job.time", MAX_JOB_TIME_DEFAULT));

state.setAttribute(STATE_MODE, SINGLE_MODE);

if (state.getAttribute(STATE_PAGESIZE) == null) {
state.setAttribute(STATE_PAGESIZE, Integer.valueOf(10));
}
if (state.getAttribute(STATE_CURRENT_PAGE) == null) {
state.setAttribute(STATE_CURRENT_PAGE, Integer.valueOf(1));
}
}


Expand Down Expand Up @@ -242,6 +253,9 @@ public String buildDownloadContext(VelocityPortlet portlet, Context context, Run
context.put("tlang",rb);
buildMenu(context, DOWNLOAD_MODE);

String search = (String) state.getAttribute(STATE_SEARCH);
context.put("search", search);

//get list of existing archives
File[] files = {};
Path sakaiHome = Paths.get(serverConfigurationService.getSakaiHomePath());
Expand All @@ -259,13 +273,14 @@ public String buildDownloadContext(VelocityPortlet portlet, Context context, Run
}

List<SparseFile> zips = new ArrayList<SparseFile>();
List<SparseFile> filteredZips = new ArrayList<SparseFile>();

SimpleDateFormat dateFormatIn = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat dateFormatOut = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Calendar calendar = Calendar.getInstance();

//porcess the list. also get the hash for the file if it exists
//process the list. also get the hash for the file if it exists
for(File f: files) {

String absolutePath = f.getAbsolutePath();
Expand Down Expand Up @@ -311,8 +326,49 @@ public String buildDownloadContext(VelocityPortlet portlet, Context context, Run

zips.add(sf);
}

context.put("archives", zips);

// Filter based on search term if present
if (search != null) {
for (SparseFile sf : zips) {
if (StringUtils.containsIgnoreCase(sf.getSiteId(), search) ||
(sf.getSiteTitle() != null && StringUtils.containsIgnoreCase(sf.getSiteTitle(), search))) {
filteredZips.add(sf);
}
}

if (filteredZips.isEmpty()) {
context.put("noSearchResults", rb.getString("archive.search.no.results"));
}
} else {
filteredZips = zips;
}

List<SparseFile> displayZips = (!filteredZips.isEmpty() || search == null) ? filteredZips : new ArrayList<>();

int totalItems = displayZips.size();
int pageSize = state.getAttribute("pagesize") != null ? ((Integer) state.getAttribute("pagesize")).intValue() : 10;
int currentPage = state.getAttribute("current-page") != null ? ((Integer) state.getAttribute("current-page")).intValue() : 1;
int startIndex = (currentPage - 1) * pageSize;
int endIndex = Math.min(startIndex + pageSize, totalItems);

context.put("totalNumber", totalItems);
context.put("pagesize", pageSize);
context.put("numbers", new Integer[]{startIndex + 1, endIndex, totalItems});
context.put("goFPButton", currentPage > 1 ? "true" : "false");
context.put("goPPButton", currentPage > 1 ? "true" : "false");
context.put("goNPButton", endIndex < totalItems ? "true" : "false");
context.put("goLPButton", endIndex < totalItems ? "true" : "false");

List<Integer[]> sizeList = new ArrayList<>();
sizeList.add(new Integer[]{10});
sizeList.add(new Integer[]{20});
sizeList.add(new Integer[]{50});
sizeList.add(new Integer[]{100});
sizeList.add(new Integer[]{200});
context.put("sizeList", sizeList);

List<SparseFile> pagedZips = displayZips.subList(startIndex, endIndex);
context.put("archives", pagedZips);

return "-download";
}
Expand Down Expand Up @@ -589,10 +645,55 @@ public void doView_batch(RunData data){
* @param data RunData
*/
public void doView_download(RunData data){
SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());
SessionState state = ((JetspeedRunData)data).getPortletSessionState(((JetspeedRunData)data).getJs_peid());
state.setAttribute(STATE_MODE, DOWNLOAD_MODE);
}


public void doChange_pagesize(RunData data) {
SessionState state = ((JetspeedRunData)data).getPortletSessionState(((JetspeedRunData)data).getJs_peid());
String newPageSize = data.getParameters().getString("selectPageSize");
if (newPageSize != null) {
state.setAttribute("pagesize", Integer.valueOf(newPageSize));
state.setAttribute("current-page", Integer.valueOf(1));
}
}

public void doList_first(RunData data) {
SessionState state = ((JetspeedRunData)data).getPortletSessionState(((JetspeedRunData)data).getJs_peid());
state.setAttribute("current-page", Integer.valueOf(1));
}

public void doList_prev(RunData data) {
SessionState state = ((JetspeedRunData)data).getPortletSessionState(((JetspeedRunData)data).getJs_peid());
Integer currentPage = (Integer) state.getAttribute("current-page");
if (currentPage != null && currentPage > 1) {
state.setAttribute("current-page", Integer.valueOf(currentPage - 1));
}
}


public void doList_next(RunData data) {
SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());
Integer currentPage = (Integer) state.getAttribute("current-page");
Integer pageSize = state.getAttribute("pagesize") != null ? (Integer) state.getAttribute("pagesize") : 10;
Integer totalItems = state.getAttribute("totalNumber") != null ? (Integer) state.getAttribute("totalNumber") : 0;

int totalPages = (totalItems + pageSize - 1) / pageSize;
if (currentPage != null && currentPage < totalPages) {
state.setAttribute("current-page", currentPage + 1);
}
}

public void doList_last(RunData data) {
SessionState state = ((JetspeedRunData) data).getPortletSessionState(((JetspeedRunData) data).getJs_peid());
Integer pageSize = state.getAttribute("pagesize") != null ? (Integer) state.getAttribute("pagesize") : 10;
Integer totalItems = state.getAttribute("totalNumber") != null ? (Integer) state.getAttribute("totalNumber") : 0;

int lastPage = (totalItems + pageSize - 1) / pageSize;
state.setAttribute("current-page", lastPage);
}

/**
* Process that archives the sites
* @param sites list of SparseSite
Expand Down Expand Up @@ -660,7 +761,6 @@ private void archiveSites(List<SparseSite> sites, String selectedTerm, Session c
}



}

//complete
Expand Down Expand Up @@ -743,6 +843,25 @@ private void buildMenu(Context context, String page) {
context.put(Menu.CONTEXT_ACTION, "ArchiveAction");
}

public void doSearch(RunData data, Context context) {
SessionState state = ((JetspeedRunData)data).getPortletSessionState(((JetspeedRunData)data).getJs_peid());
String search = StringUtils.trimToNull(data.getParameters().getString("search"));

if (search != null) {
state.setAttribute(STATE_SEARCH, search);
} else {
state.removeAttribute(STATE_SEARCH);
}

state.setAttribute(STATE_CURRENT_PAGE, Integer.valueOf(1));
}

public void doSearch_clear(RunData data, Context context) {
SessionState state = ((JetspeedRunData)data).getPortletSessionState(((JetspeedRunData)data).getJs_peid());
state.removeAttribute(STATE_SEARCH);
state.setAttribute(STATE_CURRENT_PAGE, Integer.valueOf(1));
}

} // ArchiveAction


Expand Down
Loading
Loading