Author: sletellier Date: 2011-07-08 11:02:02 +0200 (Fri, 08 Jul 2011) New Revision: 116 Url: http://chorem.org/repositories/revision/vradi/116 Log: - Fix search with query - Refator Grid usage - Add form tables in user preference pages Added: trunk/vradi-web/src/main/java/org/chorem/vradi/actions/AbstractGridAction.java trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormNoteGridAction.java Modified: trunk/vradi-web/pom.xml trunk/vradi-web/src/main/java/org/chorem/vradi/actions/AbstractEditAction.java trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormGridAction.java trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormNoteAction.java trunk/vradi-web/src/main/java/org/chorem/vradi/actions/SavedQueriesAction.java trunk/vradi-web/src/main/java/org/chorem/vradi/actions/SearchAction.java trunk/vradi-web/src/main/resources/struts.xml trunk/vradi-web/src/main/webapp/WEB-INF/jsp/searchPanel.jsp trunk/vradi-web/src/main/webapp/WEB-INF/jsp/userPreference.jsp Modified: trunk/vradi-web/pom.xml =================================================================== --- trunk/vradi-web/pom.xml 2011-07-06 14:23:24 UTC (rev 115) +++ trunk/vradi-web/pom.xml 2011-07-08 09:02:02 UTC (rev 116) @@ -120,7 +120,6 @@ <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-json-plugin</artifactId> - <scope>runtime</scope> </dependency> <dependency> Modified: trunk/vradi-web/src/main/java/org/chorem/vradi/actions/AbstractEditAction.java =================================================================== --- trunk/vradi-web/src/main/java/org/chorem/vradi/actions/AbstractEditAction.java 2011-07-06 14:23:24 UTC (rev 115) +++ trunk/vradi-web/src/main/java/org/chorem/vradi/actions/AbstractEditAction.java 2011-07-08 09:02:02 UTC (rev 116) @@ -37,7 +37,7 @@ /** * - * @param includes comma seperated list of pattern + * @param excludeString comma seperated list of pattern */ public void setExcludes(String excludeString) { // remove all blank and newline @@ -48,7 +48,7 @@ /** * - * @param includes comma seperated list of pattern + * @param includeString comma seperated list of pattern */ public void setIncludes(String includeString) { // remove all blank and newline Added: trunk/vradi-web/src/main/java/org/chorem/vradi/actions/AbstractGridAction.java =================================================================== --- trunk/vradi-web/src/main/java/org/chorem/vradi/actions/AbstractGridAction.java (rev 0) +++ trunk/vradi-web/src/main/java/org/chorem/vradi/actions/AbstractGridAction.java 2011-07-08 09:02:02 UTC (rev 116) @@ -0,0 +1,139 @@ +package org.chorem.vradi.actions; + +import org.chorem.vradi.beans.FormPagedResult; +import org.chorem.vradi.entities.Form; +import java.util.List; + +/** + * @author sletellier + */ +public abstract class AbstractGridAction extends VradiBaseAction { + + //Your result List + protected List<Form> gridModel; + //get how many rows we want to have into the grid - rowNum attribute in the grid + protected Integer rows = 0; + //Get the requested page. By default grid sets this to 1. + protected Integer page = 0; + // sorting order - asc or desc + protected String sord; + // get index row - i.e. user click to sort. + protected String sidx; + // Search Field + protected String searchField; + // The Search String + protected String searchString; + // he Search Operation ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'] + protected String searchOper; + // Your Total Pages + protected Integer total = 0; + // All Record + protected Integer records = 0; + + public List<Form> getGridModel() { + return gridModel; + } + + public void setGridModel(List<Form> gridModel) { + this.gridModel = gridModel; + } + + public Integer getRows() { + return rows; + } + + public void setRows(Integer rows) { + this.rows = rows; + } + + public Integer getPage() { + return page; + } + + public void setPage(Integer page) { + this.page = page; + } + + public String getSord() { + return sord; + } + + public void setSord(String sord) { + this.sord = sord; + } + + public String getSidx() { + return sidx; + } + + public void setSidx(String sidx) { + this.sidx = sidx; + } + + public String getSearchField() { + return searchField; + } + + public void setSearchField(String searchField) { + this.searchField = searchField; + } + + public String getSearchString() { + return searchString; + } + + public void setSearchString(String searchString) { + this.searchString = searchString; + } + + public String getSearchOper() { + return searchOper; + } + + public void setSearchOper(String searchOper) { + this.searchOper = searchOper; + } + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + public Integer getRecords() { + return records; + } + + public void setRecords(Integer records) { + this.records = records; + } + + @Override + public String execute() { + FormPagedResult result = new FormPagedResult(); + + // Do search + result.setNbFormsToShow(getRows()); + result.setPageToShow(getPage()); + result.setAscending(getSord().equalsIgnoreCase("asc")); + result.setFieldToSort(getSidx()); + + // Get result for action + result = getFormPagedResult(result); + + setRecords(result.getTotalFoundFormNb()); + + //calculate the total pages for the query + setTotal((int) Math.ceil((double) getRecords() / (double) getRows())); + + // Update result info + List<String> formsIdsToShow = result.getFormsIdsToShow(); + setGridModel(getProxy().restore(Form.class, formsIdsToShow)); + return SUCCESS; + } + + + public abstract FormPagedResult getFormPagedResult(FormPagedResult result); +} Modified: trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormGridAction.java =================================================================== --- trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormGridAction.java 2011-07-06 14:23:24 UTC (rev 115) +++ trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormGridAction.java 2011-07-08 09:02:02 UTC (rev 116) @@ -1,130 +1,19 @@ package org.chorem.vradi.actions; -import org.apache.struts2.interceptor.ServletRequestAware; import org.chorem.vradi.beans.FormPagedResult; import org.chorem.vradi.beans.QueryParameters; -import org.chorem.vradi.entities.Form; import org.chorem.vradi.services.VradiException; import org.chorem.vradi.services.search.UnsupportedQueryException; -import javax.servlet.http.HttpServletRequest; -import java.util.List; - /** * Action to display struts2-jquery grid * * @author sletellier */ -public class FormGridAction extends VradiBaseAction implements ServletRequestAware { +public class FormGridAction extends AbstractGridAction { - protected HttpServletRequest request; - //Your result List - protected List<Form> gridModel; - //get how many rows we want to have into the grid - rowNum attribute in the grid - protected Integer rows = 0; - //Get the requested page. By default grid sets this to 1. - protected Integer page = 0; - // sorting order - asc or desc - protected String sord; - // get index row - i.e. user click to sort. - protected String sidx; - // Search Field - protected String searchField; - // The Search String - protected String searchString; - // he Search Operation ['eq','ne','lt','le','gt','ge','bw','bn','in','ni','ew','en','cn','nc'] - protected String searchOper; - // Your Total Pages - protected Integer total = 0; - // All Record - protected Integer records = 0; protected String query; - @Override - public void setServletRequest(HttpServletRequest request) { - this.request = request; - } - - public List<Form> getGridModel() { - return gridModel; - } - - public void setGridModel(List<Form> gridModel) { - this.gridModel = gridModel; - } - - public Integer getRows() { - return rows; - } - - public void setRows(Integer rows) { - this.rows = rows; - } - - public Integer getPage() { - return page; - } - - public void setPage(Integer page) { - this.page = page; - } - - public String getSord() { - return sord; - } - - public void setSord(String sord) { - this.sord = sord; - } - - public String getSidx() { - return sidx; - } - - public void setSidx(String sidx) { - this.sidx = sidx; - } - - public String getSearchField() { - return searchField; - } - - public void setSearchField(String searchField) { - this.searchField = searchField; - } - - public String getSearchString() { - return searchString; - } - - public void setSearchString(String searchString) { - this.searchString = searchString; - } - - public String getSearchOper() { - return searchOper; - } - - public void setSearchOper(String searchOper) { - this.searchOper = searchOper; - } - - public Integer getTotal() { - return total; - } - - public void setTotal(Integer total) { - this.total = total; - } - - public Integer getRecords() { - return records; - } - - public void setRecords(Integer records) { - this.records = records; - } - public String getQuery() { return query; } @@ -133,18 +22,11 @@ this.query = query; } - public String getJSON() { - + @Override + public FormPagedResult getFormPagedResult(FormPagedResult result) { // Build search String query = getQuery(); QueryParameters queryParameters = new QueryParameters(query); - - // Do search - FormPagedResult result = new FormPagedResult(); - result.setNbFormsToShow(getRows()); - result.setPageToShow(getPage()); - result.setAscending(getSord().equalsIgnoreCase("asc")); - result.setFieldToSort(getSidx()); try { result = getDataService().findForms(queryParameters, result); @@ -153,15 +35,6 @@ } catch (UnsupportedQueryException eee) { log.error("Unsuported query", eee); } - - List<String> formsIdsToShow = result.getFormsIdsToShow(); - List<Form> forms = getProxy().restore(Form.class, formsIdsToShow); - setGridModel(forms); - setRecords(result.getTotalFoundFormNb()); - - //calculate the total pages for the query - setTotal((int) Math.ceil((double)getRecords() / (double)getRows())); - - return SUCCESS; + return result; } } Modified: trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormNoteAction.java =================================================================== --- trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormNoteAction.java 2011-07-06 14:23:24 UTC (rev 115) +++ trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormNoteAction.java 2011-07-08 09:02:02 UTC (rev 116) @@ -8,6 +8,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.vradi.entities.FormNote; import org.chorem.vradi.entities.FormNoteImpl; +import org.chorem.vradi.entities.FormNoteState; import org.chorem.vradi.entities.VradiUser; import org.nuiton.jrst.JRST; import org.nuiton.wikitty.WikittyProxy; @@ -94,7 +95,7 @@ formNote.setSummary(StringUtils.trimToEmpty(summary)); formNote.setContent(StringUtils.trimToEmpty(content)); formNote.setSeekingPartner(false); - formNote.setState("Open"); + formNote.setState(FormNoteState.OPEN.getValue()); formNote.addHistory(String.format("%tF creation", formNote.getCreationDate())); proxy.store(formNote); Added: trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormNoteGridAction.java =================================================================== --- trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormNoteGridAction.java (rev 0) +++ trunk/vradi-web/src/main/java/org/chorem/vradi/actions/FormNoteGridAction.java 2011-07-08 09:02:02 UTC (rev 116) @@ -0,0 +1,87 @@ +package org.chorem.vradi.actions; + +import org.chorem.vradi.beans.FormPagedResult; +import org.chorem.vradi.entities.Form; +import org.chorem.vradi.entities.FormNote; +import org.chorem.vradi.entities.FormNoteState; +import org.nuiton.wikitty.search.Criteria; +import org.nuiton.wikitty.search.PagedResult; +import org.nuiton.wikitty.search.Search; +import org.nuiton.wikitty.search.operators.Element; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * @author sletellier + */ +public class FormNoteGridAction extends AbstractGridAction { + + protected boolean opened; + + public boolean isOpened() { + return opened; + } + + public void setOpened(boolean opened) { + this.opened = opened; + } + + @Override + public FormPagedResult getFormPagedResult(FormPagedResult result) { + String userId = getUser().getWikittyId(); + FormNoteState state; + if (opened) { + state = FormNoteState.OPEN; + } else { + state = FormNoteState.CLOSE; + } + Criteria criteriaFormNote = Search.query().eq(FormNote.FQ_FIELD_FORMNOTE_PARTNERS, userId) + .eq(FormNote.FQ_FIELD_FORMNOTE_STATE, state.getValue()).criteria(); + + // Extract forms + PagedResult<FormNote> formNotes = getProxy().findAllByCriteria(FormNote.class, criteriaFormNote); + + Set<String> ids = new HashSet<String>(); + for (FormNote formNote : formNotes) { + ids.add(formNote.getForm()); + } + + if (!ids.isEmpty()) { + + // Remove null ids + ids.remove(null); + + // FIXME sletellier 20110706 : Refactor this with SearchManager + Criteria criteria = Search.query().in(Element.ELT_ID, + ids).criteria(); + + // add index restriction + // last index can be -1 (all value in UI) + int firstIndex = (result.getPageToShow() - 1) * result.getNbFormsToShow(); + int lastIndex = result.getPageToShow() * result.getNbFormsToShow() - 1; + if (firstIndex >= 0 && lastIndex > 0 && lastIndex > firstIndex) { + criteria.setFirstIndex(firstIndex).setEndIndex(lastIndex); + } + + // Add field restriction + if (result.getFieldToSort() != null) { + if (!result.isAscending()) { + criteria.addSortDescending(result.getFieldToSort()); + } else { + criteria.addSortAscending(result.getFieldToSort()); + } + } + + //finds the forms + PagedResult<Form> queryResult = getProxy().findAllByCriteria(Form.class, criteria); + List<Form> all = new ArrayList<Form>(queryResult.getAll()); + result.setFormsToShow(all); + result.setTotalFoundFormNb(queryResult.getNumFound()); + } + + return result; + } +} Modified: trunk/vradi-web/src/main/java/org/chorem/vradi/actions/SavedQueriesAction.java =================================================================== --- trunk/vradi-web/src/main/java/org/chorem/vradi/actions/SavedQueriesAction.java 2011-07-06 14:23:24 UTC (rev 115) +++ trunk/vradi-web/src/main/java/org/chorem/vradi/actions/SavedQueriesAction.java 2011-07-08 09:02:02 UTC (rev 116) @@ -4,6 +4,7 @@ import org.apache.struts2.interceptor.ServletRequestAware; import org.chorem.vradi.VradiSession; import org.chorem.vradi.entities.Query; +import org.chorem.vradi.entities.QueryImpl; import org.chorem.vradi.entities.VradiUser; import javax.servlet.http.HttpServletRequest; Modified: trunk/vradi-web/src/main/java/org/chorem/vradi/actions/SearchAction.java =================================================================== --- trunk/vradi-web/src/main/java/org/chorem/vradi/actions/SearchAction.java 2011-07-06 14:23:24 UTC (rev 115) +++ trunk/vradi-web/src/main/java/org/chorem/vradi/actions/SearchAction.java 2011-07-08 09:02:02 UTC (rev 116) @@ -79,11 +79,6 @@ this.request = request; } - @Override - public String execute() throws Exception { - return refreshForm(); - } - public String refreshForm() { String selectedQuery = getSelectedQuery(); if (!StringUtils.isEmpty(selectedQuery)) { Modified: trunk/vradi-web/src/main/resources/struts.xml =================================================================== --- trunk/vradi-web/src/main/resources/struts.xml 2011-07-06 14:23:24 UTC (rev 115) +++ trunk/vradi-web/src/main/resources/struts.xml 2011-07-08 09:02:02 UTC (rev 116) @@ -21,6 +21,15 @@ <package name="publicArea" extends="struts-default"> <result-types> <result-type name="json" class="org.apache.struts2.json.JSONResult"/> + <!-- FIXME sletellier 20110708 : in this case, gridModel is not serialized :(, try to find a better way--> + <!--<result-type name="tableModel-json" class="org.apache.struts2.json.JSONResult">--> + <!--<param name="ignoreHierarchy">false</param>--> + <!--<param name="includeProperties">gridModel,rows,page,sord,sidx,searchField,searchString,searchOper,total,records</param>--> + <!--</result-type>--> + <result-type name="tableModel-json" class="org.apache.struts2.json.JSONResult"> + <param name="ignoreHierarchy">false</param> + <param name="excludeProperties">formPagedResult,vradiSession,user,proxy,dataService,config,session,text,safeText,actionErrors,actionMessages,errorMessages,errors,fieldErrors,locale,texts,textProvider,container</param> + </result-type> <result-type name="wikitty-json" class="org.apache.struts2.json.JSONResult"> <param name="includeProperties">id,extensionNames\[\d+\],fieldValue\..*\..*</param> <param name="root">wikitty</param> @@ -137,12 +146,20 @@ +--> <action name="formGrid" class="org.chorem.vradi.actions.FormGridAction"> <param name="query"/> - <result name="success" type="json"/> + <result name="success" type="tableModel-json"/> </action> <!-- - | Form grid + | Form note grid +--> + <action name="formNoteGrid" class="org.chorem.vradi.actions.FormNoteGridAction"> + <param name="opened"/> + <result name="success" type="tableModel-json"/> + </action> + + <!-- + | Saved queries panel + +--> <action name="savedQueries" class="org.chorem.vradi.actions.SavedQueriesAction"> <result name="success" type="json"/> </action> Modified: trunk/vradi-web/src/main/webapp/WEB-INF/jsp/searchPanel.jsp =================================================================== --- trunk/vradi-web/src/main/webapp/WEB-INF/jsp/searchPanel.jsp 2011-07-06 14:23:24 UTC (rev 115) +++ trunk/vradi-web/src/main/webapp/WEB-INF/jsp/searchPanel.jsp 2011-07-08 09:02:02 UTC (rev 116) @@ -31,7 +31,7 @@ href="%{saveQueryUrl}" value="%{saveQueryText}" targets="empty" - onSuccessTopics="updateQueries" + onSuccessTopics="updateQueries,updateGrid" button="true"/> <s:url id="switchQueryUrl" value="/fragment/switchQueryActivation.action"/> Modified: trunk/vradi-web/src/main/webapp/WEB-INF/jsp/userPreference.jsp =================================================================== --- trunk/vradi-web/src/main/webapp/WEB-INF/jsp/userPreference.jsp 2011-07-06 14:23:24 UTC (rev 115) +++ trunk/vradi-web/src/main/webapp/WEB-INF/jsp/userPreference.jsp 2011-07-08 09:02:02 UTC (rev 116) @@ -7,16 +7,15 @@ <%@page import="org.chorem.vradi.actions.RestoreUserAction"%> <%@page import="com.opensymphony.xwork2.ActionContext"%> <%@page import="org.chorem.vradi.entities.VradiUser"%> -<%@ page import="org.nuiton.wikitty.WikittyUtil" %> -<%@ page import="org.nuiton.wikitty.search.Search" %> -<%@ page import="org.nuiton.wikitty.search.operators.Element" %> +<%@ page import="org.chorem.vradi.entities.Infogene" %> +<%@ page import="static org.nuiton.i18n.I18n._" %> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags"%> <%@taglib prefix="sj" uri="/struts-jquery-tags"%> <%@ taglib prefix="ws" uri="/wikitty-struts" %> +<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %> - <% RestoreUserAction action = RestoreUserAction.getAction(); VradiUser user = action.getUser(); @@ -36,7 +35,27 @@ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title><s:text name="vradi.userPreference.title" /></title> <s:head/> + <sj:head compressed="false" + jquerytheme="redmond" + debug="true" + jqueryui="true"/> <%--<sj:head jquerytheme="sunny"/>--%> + <script type="text/javascript"> + + /* + * Format a Column as Link + */ + function formatLink(cellvalue, options, row) { + return "<a href='/formNoteList/" + cellvalue + ".action'><%=_("vradi.form.editAction")%></a>"; + } + <%-- Table --%> + $.subscribe('rowselect', function(event, data) { + var id = event.originalEvent.id; + var wikittyId = id.substring(10, id.length); + window.open("/formView/" + wikittyId + ".action"); + }); + </script> + </head> <body> <h1><s:text name="vradi.userPreference.title" /></h1> @@ -199,7 +218,55 @@ <div> <h2><s:text name="vradi.userPreference.note.open" /></h2> - TODO + <s:url id="resultOpenedUrl" action="formNoteGrid"> + <s:param name="opened" value="true"/> + </s:url> + <s:set id="creationDateText"> + <s:text name="vradi.form.creationDate"/> + </s:set> + <s:set id="objetText"> + <s:text name="vradi.form.object"/> + </s:set> + <s:set id="actionText"> + <s:text name="vradi.form.action"/> + </s:set> + <s:set id="fqCreationDate"> + <%=Infogene.FQ_FIELD_INFOGENE_CREATIONDATE%> + </s:set> + <s:set id="fqObjet"> + <%=Infogene.FQ_FIELD_INFOGENE_OBJET%> + </s:set> + + <sjg:grid id="formResult" + dataType="json" + href="%{resultOpenedUrl}" + pager="true" + gridModel="gridModel" + rowList="10,100,1000" + rowNum="10" + rownumbers="true" + autowidth="true" + onSelectRowTopics="rowselect"> + + <sjg:gridColumn name="creationDate" + index="%{fqCreationDate}" + title="%{creationDateText}" + formatter="date" + formatoptions="{newformat : 'd/m/Y H:i', srcformat : 'Y-m-d H:i:s'}" + sortable="true" + width="30"/> + + <sjg:gridColumn name="objet" + index="%{fqObjet}" + title="%{objetText}" + sortable="true"/> + + <sjg:gridColumn name="wikittyId" + title="%{actionText}" + formatter="formatLink" + width="10"/> + + </sjg:grid> </div> <!-- @@ -208,7 +275,55 @@ <div> <h2><s:text name="vradi.userPreference.note.close" /></h2> - TODO + <s:url id="resultClosedUrl" action="formNoteGrid"> + <s:param name="opened" value="false"/> + </s:url> + <s:set id="creationDateText"> + <s:text name="vradi.form.creationDate"/> + </s:set> + <s:set id="objetText"> + <s:text name="vradi.form.object"/> + </s:set> + <s:set id="actionText"> + <s:text name="vradi.form.action"/> + </s:set> + <s:set id="fqCreationDate"> + <%=Infogene.FQ_FIELD_INFOGENE_CREATIONDATE%> + </s:set> + <s:set id="fqObjet"> + <%=Infogene.FQ_FIELD_INFOGENE_OBJET%> + </s:set> + + <sjg:grid id="resultUrl" + dataType="json" + href="%{resultClosedUrl}" + pager="true" + gridModel="gridModel" + rowList="10,100,1000" + rowNum="10" + rownumbers="true" + autowidth="true" + onSelectRowTopics="rowselect"> + + <sjg:gridColumn name="creationDate" + index="%{fqCreationDate}" + title="%{creationDateText}" + formatter="date" + formatoptions="{newformat : 'd/m/Y H:i', srcformat : 'Y-m-d H:i:s'}" + sortable="true" + width="30"/> + + <sjg:gridColumn name="objet" + index="%{fqObjet}" + title="%{objetText}" + sortable="true"/> + + <sjg:gridColumn name="wikittyId" + title="%{actionText}" + formatter="formatLink" + width="10"/> + + </sjg:grid> </div> </body>