1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.web.dashboard;
35
36 import fr.paris.lutece.portal.business.dashboard.DashboardFactory;
37 import fr.paris.lutece.portal.business.dashboard.DashboardHome;
38 import fr.paris.lutece.portal.business.user.AdminUser;
39 import fr.paris.lutece.portal.service.admin.AdminUserService;
40 import fr.paris.lutece.portal.service.dashboard.DashboardService;
41 import fr.paris.lutece.portal.service.dashboard.IDashboardComponent;
42 import fr.paris.lutece.portal.service.message.AdminMessage;
43 import fr.paris.lutece.portal.service.message.AdminMessageService;
44 import fr.paris.lutece.portal.service.template.AppTemplateService;
45 import fr.paris.lutece.portal.service.util.AppLogService;
46 import fr.paris.lutece.portal.web.admin.AdminFeaturesPageJspBean;
47 import fr.paris.lutece.portal.web.constants.Messages;
48 import fr.paris.lutece.util.html.HtmlTemplate;
49 import fr.paris.lutece.util.string.StringUtil;
50
51 import org.apache.commons.lang.StringUtils;
52
53 import java.util.HashMap;
54 import java.util.List;
55 import java.util.Map;
56
57 import javax.servlet.http.HttpServletRequest;
58
59
60
61
62
63
64
65 public class DashboardJspBean extends AdminFeaturesPageJspBean
66 {
67
68 public static final String RIGHT_MANAGE_DASHBOARD = "CORE_DASHBOARD_MANAGEMENT";
69
70
71 private static final String PARAMETER_DASHBOARD_NAME = "dashboard_name";
72 private static final String PARAMETER_DASHBOARD_COLUMN = "dashboard_column";
73 private static final String PARAMETER_DASHBOARD_ORDER = "dashboard_order";
74 private static final String PARAMETER_COLUMN = "column";
75
76
77 private static final String MESSAGE_DASHBOARD_NOT_FOUND = "portal.dashboard.message.dashboardNotFound";
78
79
80 private static final String MARK_MAP_DASHBOARDS = "map_dashboards";
81 private static final String MARK_NOT_SET_DASHBOARDS = "not_set_dashboards";
82 private static final String MARK_COLUMN_COUNT = "column_count";
83 private static final String MARK_LIST_AVAILABLE_COLUMNS = "list_available_columns";
84 private static final String MARK_MAP_AVAILABLE_ORDERS = "map_available_orders";
85 private static final String MARK_MAP_COLUMN_ORDER_STATUS = "map_column_order_status";
86
87
88 private static final String TEMPLATE_MANAGE_DASHBOARDS = "/admin/dashboard/manage_dashboards.html";
89
90
91 private static final String JSP_MANAGE_DASHBOARDS = "ManageDashboards.jsp";
92 private DashboardService _service = DashboardService.getInstance( );
93
94
95
96
97
98
99 public String getManageDashboards( HttpServletRequest request )
100 {
101 AdminUser user = AdminUserService.getAdminUser( request );
102
103 Map<String, Object> model = new HashMap<String, Object>( );
104
105 Map<String, List<IDashboardComponent>> mapDashboards = _service.getAllSetDashboards( getUser( ) );
106 model.put( MARK_MAP_DASHBOARDS, mapDashboards );
107
108 List<IDashboardComponent> listNotSetDashboards = _service.getNotSetDashboards( );
109 model.put( MARK_NOT_SET_DASHBOARDS, listNotSetDashboards );
110
111 model.put( MARK_COLUMN_COUNT, _service.getColumnCount( ) );
112 model.put( MARK_MAP_AVAILABLE_ORDERS, _service.getMapAvailableOrders( ) );
113 model.put( MARK_LIST_AVAILABLE_COLUMNS, _service.getListAvailableColumns( ) );
114 model.put( MARK_MAP_COLUMN_ORDER_STATUS, _service.getOrderedColumnsStatus( ) );
115
116 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_DASHBOARDS, user.getLocale( ), model );
117
118 return getAdminPage( template.getHtml( ) );
119 }
120
121
122
123
124
125
126 public String doReorderColumn( HttpServletRequest request )
127 {
128 String strColumnName = request.getParameter( PARAMETER_COLUMN );
129
130 if ( StringUtils.isBlank( strColumnName ) )
131 {
132 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
133 }
134
135 int nColumn = 0;
136
137 try
138 {
139 nColumn = Integer.parseInt( strColumnName );
140 }
141 catch ( NumberFormatException nfe )
142 {
143 AppLogService.error( "DashboardJspBean.doReorderColumn : " + nfe.getMessage( ), nfe );
144
145 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
146 }
147
148 _service.doReorderColumn( nColumn );
149
150 return JSP_MANAGE_DASHBOARDS;
151 }
152
153
154
155
156
157
158 public String doMoveDashboard( HttpServletRequest request )
159 {
160 String strDashboardName = request.getParameter( PARAMETER_DASHBOARD_NAME );
161
162 if ( StringUtils.isBlank( strDashboardName ) )
163 {
164 return AdminMessageService.getMessageUrl( request, MESSAGE_DASHBOARD_NOT_FOUND, AdminMessage.TYPE_STOP );
165 }
166
167
168 IDashboardComponent dashboard = DashboardHome.findByPrimaryKey( strDashboardName );
169 int nOldOrder = 0;
170 int nOldColumn = 0;
171 boolean bCreate = false;
172
173 if ( dashboard == null )
174 {
175 bCreate = true;
176
177 if ( AppLogService.isDebugEnabled( ) )
178 {
179 AppLogService.debug( "Dashboard " + strDashboardName +
180 " has no property set. Retrieving from SpringContext" );
181 }
182
183 dashboard = DashboardFactory.getDashboardComponent( strDashboardName );
184
185 if ( dashboard == null )
186 {
187 return AdminMessageService.getMessageUrl( request, MESSAGE_DASHBOARD_NOT_FOUND, AdminMessage.TYPE_STOP );
188 }
189 }
190 else
191 {
192 nOldOrder = dashboard.getOrder( );
193 nOldColumn = dashboard.getZone( );
194 }
195
196
197 String strOrder = request.getParameter( PARAMETER_DASHBOARD_ORDER );
198 String strColumn = request.getParameter( PARAMETER_DASHBOARD_COLUMN );
199
200 int nOrder = StringUtil.getIntValue( strOrder, -1 );
201 int nColumn = StringUtil.getIntValue( strColumn, -1 );
202
203 dashboard.setOrder( nOrder );
204 dashboard.setZone( nColumn );
205
206 _service.doMoveDashboard( dashboard, nOldColumn, nOldOrder, bCreate );
207
208 return JSP_MANAGE_DASHBOARDS;
209 }
210 }