mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
. Dashboards impl checkpoint
- Dashboard configuration wizard - column editing based on layout selection - persistence of changes made in wizard git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3361 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -37,7 +37,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class DashboardManager
|
||||
public class DashboardManager
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(DashboardManager.class);
|
||||
|
||||
@@ -115,41 +115,10 @@ public final class DashboardManager
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the DashDefinition as the zero based index, working from the left most column
|
||||
* top-bottom then working left-right.
|
||||
*
|
||||
* @param index Zero based index from the left most column working top-bottom then left-right
|
||||
*
|
||||
* @return DashletDefinition if found or null if no dashlet at the specified index
|
||||
*/
|
||||
private static DashletDefinition getDashletDefinitionByIndex(PageConfig config, int index)
|
||||
{
|
||||
DashletDefinition def = null;
|
||||
|
||||
LayoutDefinition layoutDef = config.getCurrentPage().getLayoutDefinition();
|
||||
List<Column> columns = config.getCurrentPage().getColumns();
|
||||
int columnCount = columns.size();
|
||||
int selectedColumn = index / layoutDef.ColumnLength;
|
||||
if (selectedColumn < columnCount)
|
||||
{
|
||||
List<DashletDefinition> dashlets = columns.get(selectedColumn).getDashlets();
|
||||
if (index % layoutDef.ColumnLength < dashlets.size())
|
||||
{
|
||||
def = dashlets.get(index % layoutDef.ColumnLength);
|
||||
}
|
||||
}
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Searching for dashlet at index: " + index +
|
||||
" and found " + (def != null ? def.JSPPage : null));
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the PageConfig for the current My Alfresco dashboard page
|
||||
*/
|
||||
private PageConfig getPageConfig()
|
||||
public PageConfig getPageConfig()
|
||||
{
|
||||
if (this.pageConfig == null)
|
||||
{
|
||||
@@ -189,7 +158,7 @@ public final class DashboardManager
|
||||
}
|
||||
}
|
||||
|
||||
// persist the config for this user
|
||||
// persist the initial config for this user
|
||||
//PreferencesService.getPreferences().setValue(PREF_DASHBOARD, pageConfig.toXML());
|
||||
}
|
||||
|
||||
@@ -199,6 +168,15 @@ public final class DashboardManager
|
||||
return this.pageConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the supplied PageConfig for the current user
|
||||
*/
|
||||
public void savePageConfig(PageConfig config)
|
||||
{
|
||||
this.pageConfig = config;
|
||||
PreferencesService.getPreferences().setValue(PREF_DASHBOARD, this.pageConfig.toXML());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The externally configured WebClient config element for the Dashboards
|
||||
*/
|
||||
@@ -210,6 +188,37 @@ public final class DashboardManager
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the DashDefinition as the zero based index, working from the left most column
|
||||
* top-bottom then working left-right.
|
||||
*
|
||||
* @param index Zero based index from the left most column working top-bottom then left-right
|
||||
*
|
||||
* @return DashletDefinition if found or null if no dashlet at the specified index
|
||||
*/
|
||||
private static DashletDefinition getDashletDefinitionByIndex(PageConfig config, int index)
|
||||
{
|
||||
DashletDefinition def = null;
|
||||
|
||||
LayoutDefinition layoutDef = config.getCurrentPage().getLayoutDefinition();
|
||||
List<Column> columns = config.getCurrentPage().getColumns();
|
||||
int columnCount = columns.size();
|
||||
int selectedColumn = index / layoutDef.ColumnLength;
|
||||
if (selectedColumn < columnCount)
|
||||
{
|
||||
List<DashletDefinition> dashlets = columns.get(selectedColumn).getDashlets();
|
||||
if (index % layoutDef.ColumnLength < dashlets.size())
|
||||
{
|
||||
def = dashlets.get(index % layoutDef.ColumnLength);
|
||||
}
|
||||
}
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Searching for dashlet at index: " + index +
|
||||
" and found " + (def != null ? def.JSPPage : null));
|
||||
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dashlet rendering list.
|
||||
|
@@ -17,11 +17,16 @@
|
||||
package org.alfresco.web.bean.dashboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.component.UISelectMany;
|
||||
import javax.faces.component.UISelectOne;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.wizard.BaseWizardBean;
|
||||
@@ -36,14 +41,44 @@ import org.alfresco.web.ui.common.component.description.UIDescription;
|
||||
*/
|
||||
public class DashboardWizard extends BaseWizardBean
|
||||
{
|
||||
private static final String COMPONENT_COLUMNDASHLETS = "column-dashlets";
|
||||
|
||||
private static final String COMPONENT_ALLDASHLETS = "all-dashlets";
|
||||
|
||||
private static final String MSG_COLUMN = "dashboard_column";
|
||||
|
||||
/** List of icons items to display as selectable Layout definitions */
|
||||
private List<UIListItem> layoutIcons = null;
|
||||
|
||||
/** List of descriptions of the layouts */
|
||||
private List<UIDescription> layoutDescriptions= null;
|
||||
private List<UIDescription> layoutDescriptions = null;
|
||||
|
||||
/** List of SelectItem objects representing the available dashlets */
|
||||
private List<SelectItem> dashlets = null;
|
||||
|
||||
/** Currently selected layout */
|
||||
private String layout = DashboardManager.LAYOUT_DEFAULT;
|
||||
private String layout;
|
||||
|
||||
/** Currently selected column to edit */
|
||||
private int column;
|
||||
|
||||
/** The PageConfig holding the columns/dashlets during editing */
|
||||
private PageConfig editConfig;
|
||||
|
||||
/** The DashboardManager instance */
|
||||
private DashboardManager dashboardManager;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Bean setters
|
||||
|
||||
/**
|
||||
* @param dashboardManager The dashboardManager to set.
|
||||
*/
|
||||
public void setDashboardManager(DashboardManager dashboardManager)
|
||||
{
|
||||
this.dashboardManager = dashboardManager;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
@@ -56,14 +91,17 @@ public class DashboardWizard extends BaseWizardBean
|
||||
{
|
||||
super.init(parameters);
|
||||
|
||||
|
||||
this.editConfig = new PageConfig(this.dashboardManager.getPageConfig());
|
||||
this.layout = this.editConfig.getCurrentPage().getLayoutDefinition().Id;
|
||||
this.column = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String)
|
||||
*/
|
||||
protected String finishImpl(FacesContext context, String outcome) throws Exception
|
||||
{
|
||||
this.dashboardManager.savePageConfig(this.editConfig);
|
||||
return outcome;
|
||||
}
|
||||
|
||||
@@ -74,7 +112,7 @@ public class DashboardWizard extends BaseWizardBean
|
||||
{
|
||||
LayoutDefinition def = DashboardManager.getDashboardConfig().getLayoutDefinition(this.layout);
|
||||
String label = def.Label;
|
||||
if (label == null || label.length() == 0)
|
||||
if (label == null)
|
||||
{
|
||||
label = Application.getMessage(FacesContext.getCurrentInstance(), def.LabelId);
|
||||
}
|
||||
@@ -92,7 +130,6 @@ public class DashboardWizard extends BaseWizardBean
|
||||
*/
|
||||
public String getLayout()
|
||||
{
|
||||
// TODO: implement - need current PageConfig from DashboardManager
|
||||
return this.layout;
|
||||
}
|
||||
|
||||
@@ -102,6 +139,106 @@ public class DashboardWizard extends BaseWizardBean
|
||||
public void setLayout(String layout)
|
||||
{
|
||||
this.layout = layout;
|
||||
LayoutDefinition def = DashboardManager.getDashboardConfig().getLayoutDefinition(layout);
|
||||
this.editConfig.getCurrentPage().setLayoutDefinition(def);
|
||||
if (this.column >= def.Columns)
|
||||
{
|
||||
this.column = def.Columns - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the number of columns in the selected page layout
|
||||
*/
|
||||
public int getColumnCount()
|
||||
{
|
||||
return DashboardManager.getDashboardConfig().getLayoutDefinition(getLayout()).Columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the array of UI select items representing the columns that can be configured
|
||||
*/
|
||||
public SelectItem[] getColumns()
|
||||
{
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
LayoutDefinition layoutDef = DashboardManager.getDashboardConfig().getLayoutDefinition(getLayout());
|
||||
SelectItem[] columns = new SelectItem[layoutDef.Columns];
|
||||
for (int i=0; i<layoutDef.Columns; i++)
|
||||
{
|
||||
String label = Application.getMessage(fc, MSG_COLUMN) + " " + Integer.toString(i + 1);
|
||||
columns[i] = new SelectItem(i, label);
|
||||
}
|
||||
return columns;
|
||||
}
|
||||
|
||||
public int getColumn()
|
||||
{
|
||||
return this.column;
|
||||
}
|
||||
|
||||
public void setColumn(int column)
|
||||
{
|
||||
if (column != this.column)
|
||||
{
|
||||
// setting this value will cause various List getters to return
|
||||
// different values on the next page refresh
|
||||
this.column = column;
|
||||
}
|
||||
}
|
||||
|
||||
public List<SelectItem> getAllDashlets()
|
||||
{
|
||||
if (this.dashlets == null)
|
||||
{
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
DashboardsConfigElement config = DashboardManager.getDashboardConfig();
|
||||
Collection<DashletDefinition> dashletDefs = config.getDashlets();
|
||||
List<SelectItem> dashlets = new ArrayList<SelectItem>(dashletDefs.size());
|
||||
for (DashletDefinition dashletDef : dashletDefs)
|
||||
{
|
||||
String label = dashletDef.Label;
|
||||
if (label == null)
|
||||
{
|
||||
label = Application.getMessage(fc, dashletDef.LabelId);
|
||||
}
|
||||
String description = dashletDef.Description;
|
||||
if (description == null)
|
||||
{
|
||||
description = Application.getMessage(fc, dashletDef.DescriptionId);
|
||||
}
|
||||
if (description != null)
|
||||
{
|
||||
// append description of the dashlet if set
|
||||
label = label + " (" + description + ')';
|
||||
}
|
||||
SelectItem item = new SelectItem(dashletDef.Id, label);
|
||||
dashlets.add(item);
|
||||
}
|
||||
this.dashlets = dashlets;
|
||||
}
|
||||
return this.dashlets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the List of SelectItem objects representing the dashlets displayed in the
|
||||
* currently selected column.
|
||||
*/
|
||||
public List<SelectItem> getColumnDashlets()
|
||||
{
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
|
||||
Column column = this.editConfig.getCurrentPage().getColumns().get(this.column);
|
||||
List<SelectItem> dashlets = new ArrayList<SelectItem>(column.getDashlets().size());
|
||||
for (DashletDefinition dashletDef : column.getDashlets())
|
||||
{
|
||||
String label = dashletDef.Label;
|
||||
if (label == null)
|
||||
{
|
||||
label = Application.getMessage(fc, dashletDef.LabelId);
|
||||
}
|
||||
dashlets.add(new SelectItem(dashletDef.Id, label));
|
||||
}
|
||||
return dashlets;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,12 +280,12 @@ public class DashboardWizard extends BaseWizardBean
|
||||
|
||||
// build UIListItem to represent the layout image
|
||||
String label = layoutDef.Label;
|
||||
if (label == null || label.length() == 0)
|
||||
if (label == null)
|
||||
{
|
||||
label = Application.getMessage(context, layoutDef.LabelId);
|
||||
}
|
||||
String desc = layoutDef.Description;
|
||||
if (desc == null || desc.length() == 0)
|
||||
if (desc == null)
|
||||
{
|
||||
desc = Application.getMessage(context, layoutDef.DescriptionId);
|
||||
}
|
||||
@@ -170,4 +307,48 @@ public class DashboardWizard extends BaseWizardBean
|
||||
this.layoutIcons = icons;
|
||||
this.layoutDescriptions = descriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action event handler called to Add dashlets to the selection for a column
|
||||
*/
|
||||
public void addDashlets(ActionEvent event)
|
||||
{
|
||||
UISelectMany dashletPicker = (UISelectMany)event.getComponent().findComponent(COMPONENT_ALLDASHLETS);
|
||||
UISelectOne dashletColumn = (UISelectOne)event.getComponent().findComponent(COMPONENT_COLUMNDASHLETS);
|
||||
|
||||
// get the IDs of the selected Dashlet definitions
|
||||
Object[] selected = dashletPicker.getSelectedValues();
|
||||
|
||||
// get the column to add the dashlets too
|
||||
DashboardsConfigElement config = DashboardManager.getDashboardConfig();
|
||||
LayoutDefinition layoutDef = this.editConfig.getCurrentPage().getLayoutDefinition();
|
||||
Column column = this.editConfig.getCurrentPage().getColumns().get(this.column);
|
||||
// add each selected dashlet to the column
|
||||
for (int i=0; i<selected.length && column.getDashlets().size() < layoutDef.ColumnLength; i++)
|
||||
{
|
||||
column.addDashlet(config.getDashletDefinition((String)selected[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action handler called to Remove a dashlet from the selection for a column
|
||||
*/
|
||||
public void removeDashlet(ActionEvent event)
|
||||
{
|
||||
UISelectOne dashletColumn = (UISelectOne)event.getComponent().findComponent(COMPONENT_COLUMNDASHLETS);
|
||||
|
||||
// get the ID of the selected Dashlet definition
|
||||
String dashletId = (String)dashletColumn.getValue();
|
||||
Column column = this.editConfig.getCurrentPage().getColumns().get(this.column);
|
||||
|
||||
// remove the selected dashlet from the column
|
||||
for (int i=0; i<column.getDashlets().size(); i++)
|
||||
{
|
||||
if (column.getDashlets().get(i).Id.equals(dashletId))
|
||||
{
|
||||
column.getDashlets().remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -57,6 +57,33 @@ final class PageConfig
|
||||
private List<Page> pages = new ArrayList<Page>(4);
|
||||
private int currentPageIndex = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public PageConfig()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @param copy PageConfig to copy
|
||||
*/
|
||||
public PageConfig(PageConfig copy)
|
||||
{
|
||||
this.pages = new ArrayList<Page>(copy.pages.size());
|
||||
for (Page page : copy.pages)
|
||||
{
|
||||
// invoke the copy constructor on each Page
|
||||
// which in turn calls the copy constructor of child classes
|
||||
this.pages.add(new Page(page));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current page in the config
|
||||
*/
|
||||
public Page getCurrentPage()
|
||||
{
|
||||
if (currentPageIndex < pages.size())
|
||||
@@ -69,11 +96,23 @@ final class PageConfig
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Page to the list
|
||||
*
|
||||
* @param page Page to add
|
||||
*/
|
||||
public void addPage(Page page)
|
||||
{
|
||||
pages.add(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Page with the specified page Id
|
||||
*
|
||||
* @param pageId Of the page to return
|
||||
*
|
||||
* @return Page or null if not found
|
||||
*/
|
||||
public Page getPage(String pageId)
|
||||
{
|
||||
Page foundPage = null;
|
||||
@@ -228,6 +267,12 @@ final class Page
|
||||
private LayoutDefinition layoutDef;
|
||||
private List<Column> columns = new ArrayList<Column>(4);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param id
|
||||
* @param layout
|
||||
*/
|
||||
public Page(String id, LayoutDefinition layout)
|
||||
{
|
||||
if (id == null || id.length() == 0)
|
||||
@@ -242,6 +287,22 @@ final class Page
|
||||
this.layoutDef = layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy Constructor
|
||||
*
|
||||
* @param copy Page to build a copy from
|
||||
*/
|
||||
public Page(Page copy)
|
||||
{
|
||||
this.id = copy.id;
|
||||
this.layoutDef = copy.layoutDef;
|
||||
for (Column column : copy.columns)
|
||||
{
|
||||
Column cloneColumn = new Column(column);
|
||||
addColumn(cloneColumn);
|
||||
}
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return this.id;
|
||||
@@ -252,6 +313,26 @@ final class Page
|
||||
return this.layoutDef;
|
||||
}
|
||||
|
||||
public void setLayoutDefinition(LayoutDefinition layout)
|
||||
{
|
||||
if (layout == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Layout for a Dashboard Page is mandatory.");
|
||||
}
|
||||
|
||||
// correct column collection based on new layout definition
|
||||
while (this.columns.size() < layout.Columns)
|
||||
{
|
||||
addColumn(new Column());
|
||||
}
|
||||
if (this.columns.size() > layout.Columns)
|
||||
{
|
||||
this.columns = this.columns.subList(0, layout.Columns);
|
||||
}
|
||||
|
||||
this.layoutDef = layout;
|
||||
}
|
||||
|
||||
public void addColumn(Column column)
|
||||
{
|
||||
this.columns.add(column);
|
||||
@@ -271,6 +352,23 @@ final class Column
|
||||
{
|
||||
private List<DashletDefinition> dashlets = new ArrayList<DashletDefinition>(4);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public Column()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*
|
||||
* @param copy Column to copy
|
||||
*/
|
||||
public Column(Column copy)
|
||||
{
|
||||
this.dashlets = (List<DashletDefinition>)((ArrayList<DashletDefinition>)copy.dashlets).clone();
|
||||
}
|
||||
|
||||
public void addDashlet(DashletDefinition dashlet)
|
||||
{
|
||||
dashlets.add(dashlet);
|
||||
|
Reference in New Issue
Block a user