Skip to content

Commit

Permalink
SAK-43407 SWITCH: Email Archive : tabs consistency (sakaiproject#8012)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgarciaentornos authored Mar 13, 2020
1 parent 67250e7 commit 51cf02d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ list.last =Last

pagsiz = Page size must be a positive number.\n

options = Options
perm = Permissions

rem = Remove
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class MailboxAction extends PagedResourceActionII

private static final int FORM_ALIAS_MAX_LENGTH = 99;

private static final String FORM_ITEM_NUMBER = "item_number";
private static final String FORM_ITEM_NUMBER = "item_number";

/** List request parameters. */
private static final String VIEW_ID = "view-id";
Expand Down Expand Up @@ -144,15 +144,15 @@ public class MailboxAction extends PagedResourceActionII
/** paging */

private static final String STATE_MSG_VIEW_ID = "msg-id";
/** State to cache the count of messages */

/** State to cache the count of messages */

private static final String STATE_COUNT = "state-cached-count";

private static final String STATE_COUNT_SEARCH = "state-cached-count-search";

/** Default for search suppression threshold */
private final int MESSAGE_THRESHOLD_DEFAULT = 2500;
private final int MESSAGE_THRESHOLD_DEFAULT = 2500;

private AliasService aliasService;

Expand Down Expand Up @@ -185,27 +185,24 @@ protected int sizeResources(SessionState state)
}

// We must talk to the Storage to count the messages
try
{
try {
MailArchiveChannel channel = MailArchiveService.getMailArchiveChannel((String) state.getAttribute(STATE_CHANNEL_REF));

int cCount = 0;
if(search == null) {
cCount = channel.getCount();
cCount = channel.getCount();
} else {
cCount = channel.getCount((Filter) getSearchFilter(search, 0, 0));
cCount = channel.getCount((Filter) getSearchFilter(search, 0, 0));
}

lastCount = new Integer(cCount);
state.setAttribute(STATE_COUNT, lastCount);
state.setAttribute(STATE_COUNT_SEARCH, search);
return cCount;
} catch (Exception e) {
log.warn("failed search={} exception={}", search, e.getMessage());
}
catch (Exception e)
{
log.warn("failed search={} exeption={}", search, e.getMessage());
}
return 0;
return 0;
}

/*
Expand All @@ -220,8 +217,7 @@ protected List readResourcesPage(SessionState state, int first, int last)
boolean ascending = ((Boolean) state.getAttribute(STATE_ASCENDING)).booleanValue();
int sort = ((Integer) state.getAttribute(STATE_SORT)).intValue();
String search = (String) state.getAttribute(STATE_SEARCH);



try
{
MailArchiveChannel channel = MailArchiveService.getMailArchiveChannel((String) state.getAttribute(STATE_CHANNEL_REF));
Expand Down Expand Up @@ -268,8 +264,7 @@ protected void initState(SessionState state, VelocityPortlet portlet, JetspeedRu
String channel = StringUtils.trimToNull(config.getInitParameter(PARAM_CHANNEL));
if (channel == null)
{
channel = MailArchiveService.channelReference(ToolManager.getCurrentPlacement().getContext(),
SiteService.MAIN_CONTAINER);
channel = MailArchiveService.channelReference(ToolManager.getCurrentPlacement().getContext(), SiteService.MAIN_CONTAINER);
}
state.setAttribute(STATE_CHANNEL_REF, channel);

Expand Down Expand Up @@ -317,7 +312,7 @@ public String buildMainPanelContext(VelocityPortlet portlet, Context context, Ru
}

// Put this back only for Confirm
String deleteConfirm = (String) state.getAttribute(STATE_DELETE_CONFIRM_ID);
String deleteConfirm = (String) state.getAttribute(STATE_DELETE_CONFIRM_ID);
state.removeAttribute(STATE_DELETE_CONFIRM_ID);

if ("list".equals(mode))
Expand Down Expand Up @@ -395,14 +390,14 @@ private String buildViewModeContext(VelocityPortlet portlet, Context context, Ru
log.warn("Cannot find channel {}", channelRef);
}

// Read a single message
List messagePage = readResourcesPage(state, viewPos, viewPos);
// Read a single message
List messagePage = readResourcesPage(state, viewPos, viewPos);
if ( messagePage != null ) {
Message msg = (Message) messagePage.get(0);
context.put("email",msg);
allowDelete = channel.allowRemoveMessage(msg);
// Sadly this is the only way to send this to a menu pick :(
state.setAttribute(STATE_DELETE_CONFIRM_ID, msg.getId());
state.setAttribute(STATE_DELETE_CONFIRM_ID, msg.getId());
} else {
log.warn("Could not retrieve message {}", channelRef);
context.put("message", rb.getString("thiemames1"));
Expand All @@ -413,25 +408,18 @@ private String buildViewModeContext(VelocityPortlet portlet, Context context, Ru
context.put("contentTypeImageService", ContentTypeImageService.getInstance());

// build the menu
Menu bar = new MenuImpl(portlet, rundata, (String) state.getAttribute(STATE_ACTION));
buildMenu(context, "view");

// bar.add( new MenuEntry(rb.getString("listall"), "doList"));
// addViewPagingMenus(bar, state);

if (((Boolean) state.getAttribute(STATE_VIEW_HEADERS)).booleanValue())
{
bar.add(new MenuEntry(rb.getString("hidehead"), "doHide_headers"));
Menu submenu = new MenuImpl(portlet, rundata, (String) state.getAttribute(STATE_ACTION));
if (((Boolean) state.getAttribute(STATE_VIEW_HEADERS)).booleanValue()) {
submenu.add(new MenuEntry(rb.getString("hidehead"), "doHide_headers"));
} else {
submenu.add(new MenuEntry(rb.getString("viehea"), "doView_headers"));
}
else
{
bar.add(new MenuEntry(rb.getString("viehea"), "doView_headers"));
if (allowDelete) {
submenu.add(new MenuEntry(rb.getString("del"), "doRemove"));
}
if (allowDelete) bar.add(new MenuEntry(rb.getString("del"), "doRemove"));

// make sure there's not leading or trailing dividers
bar.adjustDividers();

context.put(Menu.CONTEXT_MENU, bar);
context.put("submenu", submenu);

return (String) getContext(rundata).get("template") + "-view";

Expand All @@ -445,7 +433,7 @@ private String buildConfirmModeContext(VelocityPortlet portlet, Context context,
// get the message
context.put("tlang", rb);

String id = (String) state.getAttribute(STATE_DELETE_CONFIRM_ID);
String id = (String) state.getAttribute(STATE_DELETE_CONFIRM_ID);

MailArchiveMessage message = null;
try
Expand Down Expand Up @@ -492,22 +480,7 @@ private String buildListModeContext(VelocityPortlet portlet, Context context, Ru
context.put("mailarchive_title", toolTitle);

// build the menu
Menu bar = new MenuImpl(portlet, rundata, (String) state.getAttribute(STATE_ACTION));

if (SiteService.allowUpdateSite(ToolManager.getCurrentPlacement().getContext()))
{
bar.add(new MenuDivider());

// add options if allowed
addOptionsMenu(bar, (JetspeedRunData) rundata);

bar.add(new MenuEntry(rb.getString("perm"), "doPermissions"));
}

// make sure there's not leading or trailing dividers
bar.adjustDividers();

context.put(Menu.CONTEXT_MENU, bar);
buildMenu(context, "list");

// Decide if we are going to allow searching...
int numMessages = sizeResources(state);
Expand Down Expand Up @@ -762,27 +735,23 @@ public void doRemove_confirmed(RunData data, Context context)
SessionState state = ((JetspeedRunData) data).getPortletSessionState(peid);

// Grab and remove immedaitely
String msgId = (String) state.getAttribute(STATE_DELETE_CONFIRM_ID);
state.removeAttribute(STATE_DELETE_CONFIRM_ID);
String msgId = (String) state.getAttribute(STATE_DELETE_CONFIRM_ID);
state.removeAttribute(STATE_DELETE_CONFIRM_ID);
state.removeAttribute(STATE_COUNT);
state.removeAttribute(STATE_COUNT_SEARCH);

// remove
try
{
try {
MailArchiveChannel channel = MailArchiveService.getMailArchiveChannel((String) state.getAttribute(STATE_CHANNEL_REF));

if (msgId != null)
if (msgId != null) {
channel.removeMessage(msgId);
else
} else {
addAlert(state, rb.getString("thimeshas"));
}
catch (PermissionException e)
{
}
} catch (PermissionException e) {
addAlert(state, rb.getString("youdonot3"));
}
catch (IdUnusedException e)
{
} catch (IdUnusedException e) {
addAlert(state, rb.getString("thimeshas"));
}

Expand Down Expand Up @@ -833,6 +802,9 @@ public void doOptions(RunData runData, Context context)
public String buildOptionsPanelContext(VelocityPortlet portlet, Context context, RunData rundata, SessionState state)
{

// build the menu
buildMenu(context, "options");

context.put("tlang", rb);
// provide "pagesize" with the current page size setting
context.put("pagesize", ((Integer) state.getAttribute(STATE_PAGESIZE)).toString());
Expand Down Expand Up @@ -903,14 +875,11 @@ public void doUpdate(RunData data, Context context)
state.setAttribute(STATE_OPTION_ALIAS, alias);

MailArchiveChannel channel = null;
try
{
try {
channel = MailArchiveService.getMailArchiveChannel((String) state.getAttribute(STATE_CHANNEL_REF));
}
catch (Exception e)
{
} catch (Exception e) {
addAlert(state, rb.getString("cannot1"));
channel = null;
channel = null;
}

if (channel == null)
Expand Down Expand Up @@ -975,19 +944,15 @@ public void doUpdate(RunData data, Context context)

if (ok)
{
try
{
try {
if ( alias == null ) {
aliasService.removeTargetAliases(channel.getReference());
} else {
aliasService.setAlias(alias, channel.getReference());
}
}
catch (IdInvalidException iie) {
addAlert(state, rb.getString("theemaali4"));
}
catch (Exception any)
{
} catch (IdInvalidException iie) {
addAlert(state, rb.getString("theemaali4"));
} catch (Exception any) {
addAlert(state, rb.getString("theemaali2"));
}
}
Expand Down Expand Up @@ -1116,7 +1081,7 @@ public void doPermissions(RunData data, Context context)
String key = entry.getKey();
pRbValues.put(key, entry.getValue());
}
state.setAttribute("permissionDescriptions", pRbValues);
state.setAttribute("permissionDescriptions", pRbValues);

} // doPermissions

Expand All @@ -1143,8 +1108,7 @@ public String getSearchString()
/**
* Does this object satisfy the criteria of the filter?
*
* @param o
* The object to test.
* @param o The object to test.
* @return true if the object is accepted by the filter, false if not.
*/
public boolean accept(Object o)
Expand Down Expand Up @@ -1172,15 +1136,35 @@ public boolean accept(Object o)
}
}

/**
* get the Message Threshold - above which searching is disabled
*/
private int getMessageThreshold()
{
return ServerConfigurationService.getInt("sakai.mailbox.search-threshold",
MESSAGE_THRESHOLD_DEFAULT);
}

/**
* get the Message Threshold - above which searching is disabled
*/
private int getMessageThreshold() {
return ServerConfigurationService.getInt("sakai.mailbox.search-threshold", MESSAGE_THRESHOLD_DEFAULT);
}

private void buildMenu(Context context, String page) {
//build the menu
Menu bar = new MenuImpl();
MenuEntry list = new MenuEntry(rb.getString("listall"), "doList");
MenuEntry options = new MenuEntry(rb.getString("options"), "doOptions");
MenuEntry permissions = new MenuEntry(rb.getString("perm"), "doPermissions");
switch(page) {
case "list":
list.setIsCurrent(true);
break;
case MODE_OPTIONS:
options.setIsCurrent(true);
break;
default:
}
bar.add(list);
if(allowedToOptions()) {
bar.add(options);
}
bar.add(permissions);

context.put(Menu.CONTEXT_MENU, bar);
}
} // MailboxAction

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#end

<div class="portletBody">
#if($menu)
#toolbar($menu)
#end
<div class="page-header">
<h1>$tlang.getString("cus.cus2")</h1>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
##<!-- $Header: /cvs/sakai2/legacy/tools/src/webapp/vm/email/chef_mailbox-view.vm,v 1.2 2005/05/06 18:51:57 gsilver.umich.edu Exp $ -->
<div class="portletBody">
#if($menu)#toolbar($menu)#end
<div class="page-header">
<h1>$tlang.getString("lis.viewmessage")</h1>
</div>
#if($submenu)
#toolbar($submenu)
#end
<div class="navPanel">
<div class="itemNav">
#if ($goPPButton)
Expand Down

0 comments on commit 51cf02d

Please sign in to comment.