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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
146 changes: 140 additions & 6 deletions admin-tools/src/java/org/sakaiproject/archive/tool/ArchiveAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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));
}
}


Expand Down Expand Up @@ -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());
Expand All @@ -259,13 +275,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 +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<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 +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
Expand Down Expand Up @@ -660,7 +776,6 @@ private void archiveSites(List<SparseSite> sites, String selectedTerm, Session c
}



}

//complete
Expand Down Expand Up @@ -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


Expand Down
93 changes: 93 additions & 0 deletions admin-tools/src/webapp/vm/archive/chef_archive-download.vm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,99 @@
<h1>$tlang.getString("archive.download.heading")</h1>
</div>

#if($noSearchResults)
<div class="sak-banner-info">$noSearchResults</div>
#end

<div class="sakai-table-toolBar d-flex justify-content-between align-items-center">
<div class="sakai-table-filterContainer">
<form name="searchForm" class="form-inline" action="#toolForm("$action")" method="post" style="display: inline-block; margin-right: 1em;">
<div class="form-group" style="display: inline-block;">
<label for="search" class="sr-only">$tlang.getString("archive.search")</label>
<input type="text" size="20" name="search" id="search" class="form-control" value="$!search" placeholder="$tlang.getString('archive.search.placeholder')" />
</div>
<div class="act" style="display: inline-block;">
<input type="submit" name="eventSubmit_doSearch" value="$tlang.getString('archive.search.button')" class="btn btn-default" />
#if ($search)
<input type="submit" name="eventSubmit_doSearch_clear" value="$tlang.getString('archive.search.clear')" class="btn btn-default" />
#end
</div>
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
</div>

#if($archives.size() > 0)
<div class="listNav" style="display: inline-block;">
#if($totalNumber>0)
<div class="instruction" style="display: inline-block; margin-right: 1em;">
$tlang.getFormattedMessage("archive.list.youare", $numbers)
</div>
#end
#if ($pagesize != 0)
#if ($goFPButton == "true")
<form name="firstpageForm" class="inlineForm" method="post" action="#toolForm("$action")" style="display: inline-block;">
<input type="submit" name="eventSubmit_doList_first" value="|&lt;" title="$tlang.getString("archive.list.first")" />
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
#else
<form name="firstpageForm" class="inlineForm" method="post" action="#toolForm("$action")" style="display: inline-block;">
<input type="submit" name="eventSubmit_doList_first" value="|&lt;" disabled="disabled" />
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
#end
#if ($goPPButton == "true")
<form name="prevpageForm" class="inlineForm" method="post" action="#toolForm("$action")" style="display: inline-block;">
<input type="submit" name="eventSubmit_doList_prev" value="&lt;" title="$tlang.getFormattedMessage('archive.list.previous.withsize', $pagesize)" accesskey="p" />
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
#else
<form name="prevpageForm" class="inlineForm" method="post" action="#toolForm("$action")" style="display: inline-block;">
<input type="submit" name="eventSubmit_doList_prev" value="&lt;" disabled="disabled" />
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
#end
#end
<form name="pagesizeForm" class="inlineForm" method="post" action="#toolForm("$action")" style="display: inline-block;">
<input type="hidden" name="eventSubmit_doChange_pagesize" value="changepagesize" />
<span class="skip">$tlang.getString("archive.list.listnavselect")</span>
<select name="selectPageSize" onchange="document.pagesizeForm.submit();">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this element is missing an accessible name or label. That makes it hard for people using screen readers or voice control to use the control.

#foreach ($value in $sizeList)
#foreach($intValue in $value)
#set($ivalue=$intValue.intValue())
#end
<option value="$ivalue" #if($pagesize == $ivalue) selected="selected" #end>$tlang.getFormattedMessage("archive.list.show", $value)</option>
#end
</select>
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
#if ($pagesize != 0)
#if ($goNPButton == "true")
<form name="nextpageForm" class="inlineForm" method="post" action="#toolForm("$action")" style="display: inline-block;">
<input type="submit" name="eventSubmit_doList_next" value="&gt;" title="$tlang.getFormattedMessage('archive.list.next.withsize', $pagesize)" accesskey="n" />
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
#else
<form name="nextpageForm" class="inlineForm" method="post" action="#toolForm("$action")" style="display: inline-block;">
<input type="submit" name="eventSubmit_doList_next" value="&gt;" disabled="disabled" />
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
#end
#if ($goLPButton == "true")
<form name="lastpageForm" class="inlineForm" method="post" action="#toolForm("$action")" style="display: inline-block;">
<input type="submit" name="eventSubmit_doList_last" value="&gt;|" title="$tlang.getString('archive.list.last')" />
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
#else
<form name="lastpageForm" class="inlineForm" method="post" action="#toolForm("$action")" style="display: inline-block;">
<input type="submit" name="eventSubmit_doList_last" value="&gt;|" disabled="disabled" />
<input type="hidden" name="sakai_csrf_token" value="$sakai_csrf_token" />
</form>
#end
#end
</div>
#end
</div>

#if($archives.size() == 0)
<p>$tlang.getString("archive.download.none")</p>
#else
Expand Down
Loading