Skip to content

Commit

Permalink
MID-4137 main left menu state is now stored in session
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Sep 12, 2017
1 parent c76f5d2 commit 9b2ea53
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 15 deletions.
Expand Up @@ -33,8 +33,6 @@ public class SideBarMenuItem implements Serializable {
private IModel<String> name;
private List<MainMenuItem> items;

private boolean expanded = true;

public SideBarMenuItem(IModel<String> name) {
this.name = name;
}
Expand All @@ -46,14 +44,6 @@ public List<MainMenuItem> getItems() {
return items;
}

public boolean isExpanded() {
return expanded;
}

public void setExpanded(boolean expanded) {
this.expanded = expanded;
}

public IModel<String> getName() {
return name;
}
Expand Down
Expand Up @@ -18,6 +18,7 @@
import com.evolveum.midpoint.web.component.util.SimplePanel;
import com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour;
import com.evolveum.midpoint.web.security.SecurityUtils;
import com.evolveum.midpoint.web.session.SessionStorage;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.WebMarkupContainer;
Expand All @@ -28,6 +29,7 @@
import org.apache.wicket.model.PropertyModel;

import java.util.List;
import java.util.Map;

/**
* @author Viliam Repan (lazyman)
Expand Down Expand Up @@ -62,8 +64,20 @@ protected void populateItem(final ListItem<SideBarMenuItem> item) {

@Override
protected void onEvent(AjaxRequestTarget target) {
SideBarMenuItem menuItem = item.getModelObject();
menuItem.setExpanded(!menuItem.isExpanded());
SideBarMenuItem mainMenu = item.getModelObject();

SessionStorage storage = getPageBase().getSessionStorage();
Map<String, Boolean> menuState = storage.getMainMenuState();

String menuLabel = mainMenu.getName().getObject();
// we'll use menu label as key
Boolean expanded = menuState.get(menuLabel);

if (expanded == null) {
expanded = true;
}

menuState.put(menuLabel, !expanded);

target.add(sidebar);
}
Expand All @@ -77,7 +91,7 @@ protected void onEvent(AjaxRequestTarget target) {
public boolean isVisible() {
SideBarMenuItem mainMenu = item.getModelObject();

return !mainMenu.isExpanded();
return !isMenuExpanded(mainMenu);
}
});
item.add(icon);
Expand Down Expand Up @@ -141,12 +155,22 @@ public boolean isVisible() {
@Override
public boolean isVisible() {
SideBarMenuItem mainMenu = item.getModelObject();

return mainMenu.isExpanded();
return isMenuExpanded(mainMenu);
}
});
}
};
sidebar.add(menuItems);
}

private boolean isMenuExpanded(SideBarMenuItem mainMenu) {
SessionStorage storage = getPageBase().getSessionStorage();
Map<String, Boolean> menuState = storage.getMainMenuState();

String menuLabel = mainMenu.getName().getObject();
// we'll use menu label as key
Boolean expanded = menuState.get(menuLabel);

return expanded != null ? expanded : true;
}
}
Expand Up @@ -52,6 +52,12 @@ public class SessionStorage implements Serializable, DebugDumpable {

private static final String KEY_TASKS = "tasks";

/**
* Contains state for first level menu items. Key is menu label text, value if true then
* menu is expanded, if false menu is minimized.
*/
private Map<String, Boolean> mainMenuState = new HashMap<>();

/**
* Store session information for user preferences about paging size in midPoint GUI
* */
Expand All @@ -66,6 +72,10 @@ public Map<String, PageStorage> getPageStorageMap() {
return pageStorageMap;
}

public Map<String, Boolean> getMainMenuState() {
return mainMenuState;
}

public ConfigurationStorage getConfiguration() {
if (pageStorageMap.get(KEY_CONFIGURATION) == null) {
pageStorageMap.put(KEY_CONFIGURATION, new ConfigurationStorage());
Expand Down

0 comments on commit 9b2ea53

Please sign in to comment.