. 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:
Kevin Roast
2006-07-20 17:45:39 +00:00
parent e022ced825
commit 6cb76e8190
7 changed files with 383 additions and 66 deletions

View File

@@ -864,7 +864,13 @@ step_columns=Components
configure_dashboard_step2_title=Step Two - Select Components
configure_dashboard_step2_desc=Select the components for your dashboard and add them to the columns.
configure_dashboard_finish_instruction=To save the dashboard configuration click Finish. To review or change your selections click Back.
select_layout=Select the style of layout for your dashboard.
select_layout=Select the style of layout for your dashboard. Changing your existing dashboard layout to another with less columns will result in the additional columns being removed.
select_column=Select the column to configure
dashlet_list=Available Components
dashlet_btn_select=Add
dashlet_btn_remove=Remove
selected_dashlets=Selected Components
dashboard_column=Column
# My Alfresco Layouts messages
layout_single_label=Single Column
@@ -878,7 +884,7 @@ layout_three_column_desc=This layout displays components across three columns of
# My Alfresco Dashlet components messages
dashlet_gettingstarted_label=Getting Started
dashlet_gettingstarted_desc=This component displays helpful information and links for getting started with the Alfresco web-client application
dashlet_gettingstarted_desc=Displays helpful information for getting started with the Alfresco web-client
# User Console and Settings messages
title_user_console=User Options

View File

@@ -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.

View File

@@ -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;
/** 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,7 +91,9 @@ 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;
}
/**
@@ -64,6 +101,7 @@ public class DashboardWizard extends BaseWizardBean
*/
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;
}
}
}
}

View File

@@ -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);

View File

@@ -1456,28 +1456,8 @@
<value>#{NodeService}</value>
</managed-property>
<managed-property>
<property-name>fileFolderService</property-name>
<value>#{FileFolderService}</value>
</managed-property>
<managed-property>
<property-name>searchService</property-name>
<value>#{SearchService}</value>
</managed-property>
<managed-property>
<property-name>navigator</property-name>
<value>#{NavigationBean}</value>
</managed-property>
<managed-property>
<property-name>browseBean</property-name>
<value>#{BrowseBean}</value>
</managed-property>
<managed-property>
<property-name>dictionaryService</property-name>
<value>#{DictionaryService}</value>
</managed-property>
<managed-property>
<property-name>namespaceService</property-name>
<value>#{NamespaceService}</value>
<property-name>dashboardManager</property-name>
<value>#{DashboardManager}</value>
</managed-property>
</managed-bean>

View File

@@ -489,6 +489,11 @@ a.topToolbarLinkHighlight, a.topToolbarLinkHighlight:link, a.topToolbarLinkHighl
vertical-align: top;
}
.alignMiddle
{
vertical-align: middle;
}
.tableThirdWidth
{
width: 33%;

View File

@@ -32,3 +32,41 @@
}
</script>
</f:verbatim>
<h:panelGrid columns="1" cellpadding="2" cellspacing="0" border="0" width="100%">
<h:panelGroup rendered="#{WizardManager.bean.columnCount != 1}">
<h:outputText value="#{msg.select_column}:" />
<f:verbatim>&nbsp;</f:verbatim>
<h:selectOneMenu id="columns" value="#{WizardManager.bean.column}" onchange="document.forms['wizard'].submit(); return true;">
<f:selectItems value="#{WizardManager.bean.columns}" />
</h:selectOneMenu>
</h:panelGroup>
<h:panelGrid columns="3" cellpadding="2" cellspacing="0" border="0" columnClasses="alignTop,alignMiddle">
<h:panelGrid columns="1" cellpadding="2" border="0">
<h:outputText value="#{msg.dashlet_list}:" />
<%-- note this component ID is referenced in DashboardWizard --%>
<h:selectManyListbox id="all-dashlets" style="width:300px" size="8">
<f:selectItems value="#{WizardManager.bean.allDashlets}" />
</h:selectManyListbox>
</h:panelGrid>
<h:commandButton value="#{msg.dashlet_btn_select} >>" actionListener="#{WizardManager.bean.addDashlets}" />
<h:panelGrid columns="1" cellpadding="2" border="0">
<h:outputText value="#{msg.selected_dashlets}:" />
<h:panelGrid columns="2" cellpadding="2" cellspacing="0" border="0">
<%-- note this component ID is referenced in DashboardWizard --%>
<h:selectOneListbox id="column-dashlets" style="width:150px" size="8">
<f:selectItems value="#{WizardManager.bean.columnDashlets}" />
</h:selectOneListbox>
<h:panelGroup>
<h:commandButton value="+" style="width:24px" actionListener="#{WizardManager.bean.dashletUp}" />
<f:verbatim><br></f:verbatim>
<h:commandButton value="-" style="width:24px" actionListener="#{WizardManager.bean.dashletDown}"/>
</h:panelGroup>
</h:panelGrid>
<h:commandButton value="#{msg.dashlet_btn_remove}" actionListener="#{WizardManager.bean.removeDashlet}" />
</h:panelGrid>
</h:panelGrid>
</h:panelGrid>