IDEMPIERE-1362 Implement support to register/unregister available dashboard content. Fixed double click on item doesn't work. Fixed changes on list doesn't always saved. Fixed gadget being display on side and center pane. Fixed dashboard preference being stored as ad_user_id+ad_role_id+ad_org_id instead of ad_user_id+ad_role_id

This commit is contained in:
Heng Sin Low 2013-09-13 12:22:10 +08:00
parent f8c42adcb7
commit bba389c81c
4 changed files with 75 additions and 32 deletions

View File

@ -56,7 +56,7 @@ public class MDashboardContent extends X_PA_DashboardContent
return new Query(ctx, Table_Name, whereClause.toString(), null)
.setParameters(parameters)
.setOnlyActiveRecords(false)
.setOnlyActiveRecords(true)
.setApplyAccessFilter(true, false)
.setOrderBy(COLUMNNAME_ColumnNo+","+COLUMNNAME_AD_Client_ID+","+COLUMNNAME_Line);
}

View File

@ -35,7 +35,9 @@ public class MDashboardPreference extends X_PA_DashboardPreference
public static int getForSessionColumnCount(boolean isShowInDashboard, int AD_User_ID, int AD_Role_ID)
{
int noOfCols = getForSessionQuery(isShowInDashboard, AD_User_ID, AD_Role_ID).aggregate("DISTINCT "+COLUMNNAME_ColumnNo, Query.AGGREGATE_COUNT, Integer.class);
int noOfCols = getForSessionQuery(isShowInDashboard, AD_User_ID, AD_Role_ID)
.setOnlyActiveRecords(true)
.aggregate("DISTINCT "+COLUMNNAME_ColumnNo, Query.AGGREGATE_COUNT, Integer.class);
return noOfCols;
}
@ -51,7 +53,9 @@ public class MDashboardPreference extends X_PA_DashboardPreference
StringBuilder whereClause = new StringBuilder(COLUMNNAME_IsShowInDashboard).append("=?")
.append(" AND ").append(COLUMNNAME_AD_Role_ID).append("=?")
.append(" AND ").append(COLUMNNAME_AD_User_ID).append("=?");
.append(" AND ").append(COLUMNNAME_AD_User_ID).append("=?")
.append(" AND ").append(COLUMNNAME_AD_Org_ID).append("=0");
List<Object> parameters = new ArrayList<Object>();
parameters.add(isShowInDashboard);
@ -60,7 +64,7 @@ public class MDashboardPreference extends X_PA_DashboardPreference
return new Query(ctx, Table_Name, whereClause.toString(), null)
.setParameters(parameters)
.setOnlyActiveRecords(true)
.setOnlyActiveRecords(false)
.setApplyAccessFilter(true, false)
.setOrderBy(COLUMNNAME_ColumnNo+","+COLUMNNAME_AD_Client_ID+","+COLUMNNAME_Line);
}
@ -77,7 +81,8 @@ public class MDashboardPreference extends X_PA_DashboardPreference
StringBuilder whereClause = new StringBuilder()
.append(COLUMNNAME_AD_Role_ID).append("=?")
.append(" AND ").append(COLUMNNAME_AD_User_ID).append("=?");
.append(" AND ").append(COLUMNNAME_AD_User_ID).append("=?")
.append(" AND ").append(COLUMNNAME_AD_Org_ID).append("=0");
List<Object> parameters = new ArrayList<Object>();
parameters.add(AD_Role_ID);

View File

@ -129,16 +129,16 @@ public class DashboardController implements EventListener<Event> {
int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
int AD_Role_ID = Env.getAD_Role_ID(Env.getCtx());
MDashboardPreference[] dps = MDashboardPreference.getForSession(isShowInDashboard,AD_User_ID, AD_Role_ID);
MDashboardPreference[] dps = MDashboardPreference.getForSession(AD_User_ID, AD_Role_ID);
MDashboardContent [] dcs = MDashboardContentAccess.get(Env.getCtx(), AD_Role_ID, AD_User_ID, null,isShowInDashboard);
if(dps.length == 0){
createDashboardPreference(AD_User_ID, AD_Role_ID,isShowInDashboard);
dps = MDashboardPreference.getForSession(isShowInDashboard,AD_User_ID, AD_Role_ID);
createDashboardPreference(AD_User_ID, AD_Role_ID,true);
createDashboardPreference(AD_User_ID, AD_Role_ID,false);
dps = MDashboardPreference.getForSession(AD_User_ID, AD_Role_ID);
}else{
if(dps.length < dcs.length){
updatePreferences(dps, dcs,Env.getCtx());
dps = MDashboardPreference.getForSession(isShowInDashboard,AD_User_ID, AD_Role_ID);
if(updatePreferences(dps, dcs,Env.getCtx())){
dps = MDashboardPreference.getForSession(AD_User_ID, AD_Role_ID);
}
}
@ -149,10 +149,12 @@ public class DashboardController implements EventListener<Event> {
int extraWidth = 100 - (noOfCols <= 0 ? dashboardWidth : width * noOfCols) - (100 - dashboardWidth - 1);
for (final MDashboardPreference dp : dps)
{
if(!dp.isActive())
continue;
if (dp.isShowInDashboard() != isShowInDashboard)
continue;
MDashboardContent dc = new MDashboardContent(dp.getCtx(), dp.getPA_DashboardContent_ID(), dp.get_TrxName());
int columnNo = dp.getColumnNo();
@ -524,7 +526,7 @@ public class DashboardController implements EventListener<Event> {
for (MDashboardContent dc : dcs)
{
MDashboardPreference preference = new MDashboardPreference(Env.getCtx(), 0, null);
preference.setAD_Org_ID(Env.getAD_Org_ID(Env.getCtx()));
preference.setAD_Org_ID(0);
preference.setAD_Role_ID(AD_Role_ID);
preference.set_ValueNoCheck("AD_User_ID", AD_User_ID);
preference.setColumnNo(dc.getColumnNo());
@ -539,7 +541,8 @@ public class DashboardController implements EventListener<Event> {
}
public void updatePreferences(MDashboardPreference[] dps,MDashboardContent[] dcs, Properties ctx) {
private boolean updatePreferences(MDashboardPreference[] dps,MDashboardContent[] dcs, Properties ctx) {
boolean change = false;
for (int i = 0; i < dcs.length; i++) {
boolean isNew = true;
for (int j = 0; j < dps.length; j++) {
@ -549,7 +552,7 @@ public class DashboardController implements EventListener<Event> {
}
if (isNew) {
MDashboardPreference preference = new MDashboardPreference(ctx,0, null);
preference.setAD_Org_ID(Env.getAD_Org_ID(Env.getCtx()));
preference.setAD_Org_ID(0);
preference.setAD_Role_ID(Env.getAD_Role_ID(ctx));
preference.set_ValueNoCheck("AD_User_ID",Env.getAD_User_ID(ctx));
preference.setColumnNo(dcs[i].getColumnNo());
@ -559,9 +562,10 @@ public class DashboardController implements EventListener<Event> {
preference.setPA_DashboardContent_ID(dcs[i].getPA_DashboardContent_ID());
preference.saveEx();
if (!change) change = true;
}
}
return change;
}
private void saveDashboardPreference(Vlayout layout)

View File

@ -50,6 +50,7 @@ import org.zkoss.zk.ui.event.DropEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.MouseEvent;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Hlayout;
import org.zkoss.zul.Vbox;
@ -158,15 +159,17 @@ public class WGadgets extends Window implements EventListener<Event>{
bRemove.setImage(ThemeManager.getThemeResource("images/Previous24.png"));
bRemove.addEventListener(Events.ON_CLICK, actionListener);
final EventListener<Event> crossListMouseListener = new DragListener();
yesList.addOnDropListener(crossListMouseListener);
noList.addOnDropListener(crossListMouseListener);
final EventListener<Event> moveListener = new MoveListener();
yesList.addOnDropListener(moveListener);
yesList.addDoubleClickListener(moveListener);
noList.addOnDropListener(moveListener);
noList.addDoubleClickListener(moveListener);
yesList.setItemDraggable(true);
yesList.setDroppable("true");
yesList.addEventListener(Events.ON_DROP, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
crossListMouseListener.onEvent(event);
moveListener.onEvent(event);
}
});
noList.setItemDraggable(true);
@ -174,7 +177,7 @@ public class WGadgets extends Window implements EventListener<Event>{
noList.addEventListener(Events.ON_DROP, new EventListener<Event>() {
@Override
public void onEvent(Event event) throws Exception {
crossListMouseListener.onEvent(event);
moveListener.onEvent(event);
}
});
@ -236,12 +239,14 @@ public class WGadgets extends Window implements EventListener<Event>{
String query = " SELECT ct.PA_DashboardContent_ID, ct.Name "
+" FROM PA_DashboardContent ct"
+" WHERE ct.AD_Client_ID IN (0,?)"
+" AND ct.IsActive='Y'"
+" AND ct.PA_DashboardContent_ID NOT IN ("
+" SELECT pre.PA_DashboardContent_ID"
+" FROM PA_DashboardPreference pre"
+" WHERE pre.AD_Client_ID IN (0,?)"
+" AND pre.AD_Role_ID = ?"
+" AND pre.AD_User_ID = ?"
+" AND pre.AD_Org_ID=0 "
+" AND pre.IsActive='Y') ";
ResultSet rs = null;
@ -272,6 +277,7 @@ public class WGadgets extends Window implements EventListener<Event>{
String where=" AD_User_ID=?"
+" AND AD_Role_ID=?"
+" AND AD_Client_ID=?"
+" AND AD_Org_ID=0"
+" AND IsActive='Y'";
Query query1 =new Query(ctx,MDashboardPreference.Table_Name, where, null);
@ -282,8 +288,10 @@ public class WGadgets extends Window implements EventListener<Event>{
for(int i = 0; i < preference.size() ; i++){
int ID = preference.get(i).getPA_DashboardContent_ID();
MDashboardContent content = new MDashboardContent(ctx, ID, null);
if (!dirtyList.containsKey(content.getPA_DashboardContent_ID())) {
yesItems.add(content);
if (content.isActive()) {
if (!dirtyList.containsKey(content.getPA_DashboardContent_ID())) {
yesItems.add(content);
}
}
}
}
@ -338,9 +346,10 @@ public class WGadgets extends Window implements EventListener<Event>{
MDashboardContent content = new MDashboardContent(Env.getCtx(),selObject.m_key, null);
String where=" AD_Client_ID=?"
+" AND PA_DashboardContent_ID=?";
+" AND PA_DashboardContent_ID=?"
+" AND AD_Role_ID=? AND AD_User_ID=? AND AD_Org_ID=0";
Query query = new Query(ctx, MDashboardPreference.Table_Name, where, null);
query.setParameters(new Object[]{AD_Client_ID, content.getPA_DashboardContent_ID()});
query.setParameters(AD_Client_ID, content.getPA_DashboardContent_ID(), AD_Role_ID, AD_User_ID);
MDashboardPreference pre = query.setOnlyActiveRecords(false).first();
@ -350,7 +359,7 @@ public class WGadgets extends Window implements EventListener<Event>{
pre.setIsShowInDashboard(content.isShowInDashboard());
}else{
pre = new MDashboardPreference(Env.getCtx(), 0, null);
pre.setAD_Org_ID(Env.getAD_Org_ID(Env.getCtx()));
pre.setAD_Org_ID(0);
pre.setAD_Role_ID(AD_Role_ID);
pre.set_ValueNoCheck("AD_User_ID",AD_User_ID);
pre.setColumnNo(content.getColumnNo());
@ -363,8 +372,19 @@ public class WGadgets extends Window implements EventListener<Event>{
}else{
if(pre != null){
pre.setIsActive(false);
dirtyList.put(pre.getPA_DashboardContent_ID(), pre);
}else{
pre = new MDashboardPreference(Env.getCtx(), 0, null);
pre.setAD_Org_ID(0);
pre.setAD_Role_ID(AD_Role_ID);
pre.set_ValueNoCheck("AD_User_ID",AD_User_ID);
pre.setColumnNo(content.getColumnNo());
pre.setIsCollapsedByDefault(content.isCollapsedByDefault());
pre.setIsShowInDashboard(content.isShowInDashboard());
pre.setLine(content.getLine());
pre.setPA_DashboardContent_ID(content.getPA_DashboardContent_ID());
pre.setIsActive(false);
}
dirtyList.put(pre.getPA_DashboardContent_ID(), pre);
}
}
refresh();
@ -491,13 +511,13 @@ public class WGadgets extends Window implements EventListener<Event>{
* @author eslatis
*
*/
private class DragListener implements EventListener<Event>
private class MoveListener implements EventListener<Event>
{
/**
* Creates a ADSortTab.DragListener.
*/
public DragListener()
public MoveListener()
{
}
@ -526,7 +546,7 @@ public class WGadgets extends Window implements EventListener<Event>{
if (listFrom != listTo)
{
migrateLists (listFrom,listTo); //,endIndex);
migrateLists (listFrom,listTo);
}
else
{
@ -534,6 +554,20 @@ public class WGadgets extends Window implements EventListener<Event>{
;
}
}
else if (event instanceof MouseEvent)
{
Listbox listFrom = null;
Listbox listTo = null;
ListItem fromItem = (ListItem) event.getTarget();
listFrom = (Listbox) fromItem.getListbox();
listTo = listFrom==yesList ? noList : yesList;
if (!fromItem.isSelected())
fromItem.setSelected(true);
migrateLists (listFrom,listTo);
}
}
}
}