From 22b60943be61418ffbb148b1cd81286479e655ae Mon Sep 17 00:00:00 2001 From: kunaljaykam Date: Wed, 29 Jan 2025 14:14:13 +0530 Subject: [PATCH] save progress --- admin-tools/src/bundle/archive.properties | 13 ++ .../archive/tool/ArchiveAction.java | 146 +++++++++++++++++- .../vm/archive/chef_archive-download.vm | 93 +++++++++++ 3 files changed, 246 insertions(+), 6 deletions(-) diff --git a/admin-tools/src/bundle/archive.properties b/admin-tools/src/bundle/archive.properties index 7ba0196a4975..45cab3bf553d 100644 --- a/admin-tools/src/bundle/archive.properties +++ b/admin-tools/src/bundle/archive.properties @@ -46,3 +46,16 @@ archive.download.size = Size archive.download.hash = Hash (SHA-1) 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 \ No newline at end of file diff --git a/admin-tools/src/java/org/sakaiproject/archive/tool/ArchiveAction.java b/admin-tools/src/java/org/sakaiproject/archive/tool/ArchiveAction.java index 2f8ee36f6658..20a9e72e39ef 100644 --- a/admin-tools/src/java/org/sakaiproject/archive/tool/ArchiveAction.java +++ b/admin-tools/src/java/org/sakaiproject/archive/tool/ArchiveAction.java @@ -86,14 +86,18 @@ @Slf4j public class ArchiveAction extends VelocityPortletPaneledAction { - private static final long serialVersionUID = 1L; private static final String STATE_MODE = "mode"; private static final String BATCH_MODE = "batch"; private static final String BATCH_ARCHIVE_CONFIRM_MODE = "batch-archive-confirm"; 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"; + // Pagination state constants + 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"); @@ -140,6 +144,14 @@ 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); + + // Initialize pagination state if not set + 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)); + } } @@ -242,6 +254,10 @@ public String buildDownloadContext(VelocityPortlet portlet, Context context, Run context.put("tlang",rb); buildMenu(context, DOWNLOAD_MODE); + // Add search context + String search = (String) state.getAttribute(STATE_SEARCH); + context.put("search", search); + //get list of existing archives File[] files = {}; Path sakaiHome = Paths.get(serverConfigurationService.getSakaiHomePath()); @@ -259,13 +275,14 @@ public String buildDownloadContext(VelocityPortlet portlet, Context context, Run } List zips = new ArrayList(); + List filteredZips = new ArrayList(); 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(); @@ -311,8 +328,50 @@ 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; + } + + // If we have filtered results or no search, use those + List 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 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 pagedZips = displayZips.subList(startIndex, endIndex); + context.put("archives", pagedZips); return "-download"; } @@ -589,10 +648,67 @@ 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); } + /** + * Handle a request to change the page size + */ + 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)); + } + } + + /** + * Handle a request to go to the first page + */ + public void doList_first(RunData data) { + SessionState state = ((JetspeedRunData)data).getPortletSessionState(((JetspeedRunData)data).getJs_peid()); + state.setAttribute("current-page", Integer.valueOf(1)); + } + + /** + * Handle a request to go to the previous page + */ + 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)); + } + } + + /** + * Handle a request to go to the next page todo + */ + 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); + } + } + /** + * Handle a request to go to the last page + */ +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 @@ -660,7 +776,6 @@ private void archiveSites(List sites, String selectedTerm, Session c } - } //complete @@ -743,6 +858,25 @@ private void buildMenu(Context context, String page) { context.put(Menu.CONTEXT_ACTION, "ArchiveAction"); } + /** + * Handle a request to search todo, shouldn't store nulls + */ + public void doSearch(RunData data, Context context) { + SessionState state = ((JetspeedRunData)data).getPortletSessionState(((JetspeedRunData)data).getJs_peid()); + String search = StringUtils.trimToNull(data.getParameters().getString("search")); + state.setAttribute(STATE_SEARCH, search); + state.setAttribute(STATE_CURRENT_PAGE, Integer.valueOf(1)); + } + + /** + * Handle a request to clear the search + */ + 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 diff --git a/admin-tools/src/webapp/vm/archive/chef_archive-download.vm b/admin-tools/src/webapp/vm/archive/chef_archive-download.vm index 973b77962f4d..84e07b34c4ab 100644 --- a/admin-tools/src/webapp/vm/archive/chef_archive-download.vm +++ b/admin-tools/src/webapp/vm/archive/chef_archive-download.vm @@ -6,6 +6,99 @@

$tlang.getString("archive.download.heading")

+ #if($noSearchResults) +
$noSearchResults
+ #end + +
+
+
+
+ + +
+
+ + #if ($search) + + #end +
+ +
+
+ + #if($archives.size() > 0) +
+ #if($totalNumber>0) +
+ $tlang.getFormattedMessage("archive.list.youare", $numbers) +
+ #end + #if ($pagesize != 0) + #if ($goFPButton == "true") +
+ + +
+ #else +
+ + +
+ #end + #if ($goPPButton == "true") +
+ + +
+ #else +
+ + +
+ #end + #end +
+ + $tlang.getString("archive.list.listnavselect") + + +
+ #if ($pagesize != 0) + #if ($goNPButton == "true") +
+ + +
+ #else +
+ + +
+ #end + #if ($goLPButton == "true") +
+ + +
+ #else +
+ + +
+ #end + #end +
+ #end +
+ #if($archives.size() == 0)

$tlang.getString("archive.download.none")

#else