Changeset 7546
- Timestamp:
- Dec 10, 2018, 8:43:53 AM (4 years ago)
- Location:
- branches/3.13-stable
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.13-stable/src/core/net/sf/basedb/util/formatter/PropertyFilterFormatter.java
r7494 r7546 48 48 private final DbControl dc; 49 49 private final Formatter<Date> dateFormatter; 50 private final boolean tagElements; 50 51 51 52 /** … … 54 55 public PropertyFilterFormatter(DbControl dc, Formatter<Date> dateFormatter) 55 56 { 57 this(dc, dateFormatter, false); 58 } 59 60 /** 61 Create a new formatter with option to create HTML-like tags around elements. The 62 following tags are used: <value>, <name>, <operator>, <function> 63 @since 3.13.1 64 */ 65 public PropertyFilterFormatter(DbControl dc, Formatter<Date> dateFormatter, boolean tagElements) 66 { 56 67 this.dc = dc; 57 68 this.dateFormatter = dateFormatter; 58 }59 69 this.tagElements = tagElements; 70 } 60 71 61 72 /* … … 77 88 int startIndex = property.startsWith("##") ? 2 : 1; 78 89 int annotationTypeId = Values.getInt(property.substring(startIndex)); 79 sb.append("{").append(name OfItem(dc, Item.ANNOTATIONTYPE, annotationTypeId, false)).append("}");80 sb.append(" ").append(operator ).append(" ");90 sb.append("{").append(name(nameOfItem(dc, Item.ANNOTATIONTYPE, annotationTypeId, false))).append("}"); 91 sb.append(" ").append(operator(operator.toString())).append(" "); 81 92 if (operator.isListOperator() && value != null) 82 93 { … … 85 96 else 86 97 { 87 sb.append( quote).append(value).append(quote);98 sb.append(value(quote+value+quote)); 88 99 } 89 100 } … … 94 105 int fileTypeId = Values.getInt(property.substring(1, i)); 95 106 String fileFilter = property.substring(i+1, property.length()-1); 96 sb.append("{").append(name OfItem(dc, Item.DATAFILETYPE, fileTypeId, false)).append("#").append(fileFilter).append("}");97 sb.append(" ").append(operator ).append(" ");107 sb.append("{").append(name(nameOfItem(dc, Item.DATAFILETYPE, fileTypeId, false)+"#"+fileFilter)).append("}"); 108 sb.append(" ").append(operator(operator.toString())).append(" "); 98 109 if (operator.isListOperator() && value != null) 99 110 { … … 102 113 else 103 114 { 104 sb.append( quote).append(value).append(quote);115 sb.append(value(quote+value+quote)); 105 116 } 106 117 } … … 108 119 { 109 120 // Item list filter 110 sb.append(operator == Operator.EQ ? "memberOfList(" : "NOT memberOfList("); 111 sb.append(nameOfItem(dc, Item.ITEMLIST, Values.getInt(value), true)); 121 if (operator != Operator.EQ) sb.append(operator("NOT")); 122 sb.append(function("memberOfList")).append("("); 123 sb.append(value(nameOfItem(dc, Item.ITEMLIST, Values.getInt(value), true))); 112 124 sb.append(")"); 113 125 } … … 115 127 { 116 128 WellCoordinateFormatter formatter = new WellCoordinateFormatter(property.equals("bioWell.row")); 117 sb.append( property).append(" ").append(operator).append(" ");129 sb.append(name(property)).append(" ").append(operator(operator.toString())).append(" "); 118 130 List<Object> selected = filter.getValuesAsObjects(); 119 131 if (selected.size() > 1) sb.append("("); … … 124 136 sb.append(sep); 125 137 sep = ", "; 126 sb.append( formatter.format((Integer)index));138 sb.append(value(formatter.format((Integer)index))); 127 139 } 128 140 if (selected.size() > 1) sb.append(")"); … … 130 142 else if (property.equals("parentType")) 131 143 { 132 sb.append( property).append(" ").append(operator).append(" ");144 sb.append(name(property)).append(" ").append(operator(operator.toString())).append(" "); 133 145 List<Object> selected = filter.getValuesAsObjects(); 134 146 if (selected.size() > 1) sb.append("("); … … 139 151 sb.append(sep); 140 152 sep = ", "; 141 sb.append( Item.fromValue((Integer)index).toString());153 sb.append(value(Item.fromValue((Integer)index).toString())); 142 154 } 143 155 if (selected.size() > 1) sb.append(")"); … … 158 170 if (nameOfItemType != null) 159 171 { 160 sb.append( property).append(" ").append(operator).append(" ");172 sb.append(name(property)).append(" ").append(operator(operator.toString())).append(" "); 161 173 List<Object> itemIds = filter.getValuesAsObjects(); 162 174 if (itemIds.size() > 1) sb.append("("); … … 167 179 sb.append(sep); 168 180 sep = ", "; 169 sb.append( nameOfItem(dc, nameOfItemType, (Integer)id, true));181 sb.append(value(nameOfItem(dc, nameOfItemType, (Integer)id, true))); 170 182 } 171 183 if (itemIds.size() > 1) sb.append(")"); … … 177 189 property = property.substring(1); 178 190 } 179 sb.append( property).append(" ").append(operator).append(" ");191 sb.append(name(property)).append(" ").append(operator(operator.toString())).append(" "); 180 192 if (operator.isListOperator() && value != null) 181 193 { … … 188 200 value = dateFormatter.format((Date)Type.DATE.parseString(value)); 189 201 } 190 sb.append( quote).append(value).append(quote);202 sb.append(value(quote+value+quote)); 191 203 } 192 204 } … … 228 240 sb.append(sep); 229 241 sep = ", "; 230 sb.append( quote).append(v).append(quote);242 sb.append(value(quote+v+quote)); 231 243 } 232 244 if (values.length > 1) sb.append(")"); 233 245 234 246 } 247 248 private String value(String value) 249 { 250 return tagElements ? "<value>"+value+"</value>" : value; 251 } 252 253 private String name(String name) 254 { 255 return tagElements ? "<name>"+name+"</name>" : name; 256 } 257 private String operator(String op) 258 { 259 return tagElements ? "<operator>"+op+"</operator>" : op; 260 } 261 private String function(String function) 262 { 263 return tagElements ? "<function>"+function+"</function>" : function; 264 } 265 266 235 267 } -
branches/3.13-stable/www/views/itemlists/syncfilter/ajax.jsp
r6793 r7546 47 47 StringBuilder sb = new StringBuilder(); 48 48 Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(dc.getSessionControl()); 49 Formatter<PropertyFilter> filterFormatter = new PropertyFilterFormatter(dc, dateFormatter );49 Formatter<PropertyFilter> filterFormatter = new PropertyFilterFormatter(dc, dateFormatter, true); 50 50 for (int filterRow = 0; filterRow < syncFilter.getFilterRows(); filterRow++) 51 51 { 52 sb.append(filterRow > 0 ? "\n OR" : "");52 sb.append(filterRow > 0 ? "\n<operator>OR</operator> " : ""); 53 53 List<String> filters = SyncFilter.getFormattedAndSortedFilters(syncFilter.getPropertyFilters(filterRow), filterFormatter); 54 sb.append(Values.getString(filters, "\n AND", true));54 sb.append(Values.getString(filters, "\n <operator>AND</operator> ", true)); 55 55 } 56 56 return sb.toString(); … … 89 89 if (sourceItemType == syncFilter.getSourceItemType()) 90 90 { 91 json.put("filter", HTML.encodeTags(formatFilter(dc, syncFilter) ));91 json.put("filter", HTML.encodeTags(formatFilter(dc, syncFilter), "value|name|operator|function")); 92 92 } 93 93 } -
branches/3.13-stable/www/views/itemlists/syncfilter/edit_syncfilter.jsp
r6814 r7546 112 112 %> 113 113 <base:page type="popup" title="<%=title%>" id="edit-page"> 114 <base:head scripts="tabcontrol-2.js,~syncfilter.js" styles="tabcontrol.css ">114 <base:head scripts="tabcontrol-2.js,~syncfilter.js" styles="tabcontrol.css,~filtertext.css"> 115 115 <ext:scripts context="<%=jspContext%>" /> 116 116 <ext:stylesheets context="<%=jspContext%>" /> … … 178 178 <th class="subprompt"></th> 179 179 <td> 180 <pre class="messagecontainer note " id="filter-info" style="height: 12em; overflow: auto;"></pre>180 <pre class="messagecontainer note filtertext" id="filter-info" style="height: 12em;"></pre> 181 181 </td> 182 182 <td> -
branches/3.13-stable/www/views/itemlists/view_list.jsp
r7166 r7546 113 113 %> 114 114 <base:page title="<%=title%>" id="view-page"> 115 <base:head scripts="table.js,tabcontrol-2.js,~lists.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css ">115 <base:head scripts="table.js,tabcontrol-2.js,~lists.js" styles="table.css,toolbar.css,headertabcontrol.css,path.css,~syncfilter/filtertext.css"> 116 116 <ext:scripts context="<%=jspContext%>" /> 117 117 <ext:stylesheets context="<%=jspContext%>" /> … … 431 431 <% 432 432 int index = 0; 433 Formatter<PropertyFilter> filterFormatter = new PropertyFilterFormatter(dc, dateFormatter );433 Formatter<PropertyFilter> filterFormatter = new PropertyFilterFormatter(dc, dateFormatter, true); 434 434 for (SyncFilter sf : syncFilters) 435 435 { … … 442 442 for (int filterRow = 0; filterRow < sf.getFilterRows(); filterRow++) 443 443 { 444 sb.append(filterRow > 0 ? "\n OR" : "");444 sb.append(filterRow > 0 ? "\n<operator>OR</operator> " : ""); 445 445 List<String> filters = SyncFilter.getFormattedAndSortedFilters(sf.getPropertyFilters(filterRow), filterFormatter); 446 sb.append(Values.getString(filters, "\n AND", true));446 sb.append(Values.getString(filters, "\n <operator>AND</operator> ", true)); 447 447 } 448 448 boolean disabled = sf.isDisabled(); … … 516 516 } 517 517 %> 518 <pre id="syncfilter.<%=filterId%>"><%=HTML.encodeTags(sb.toString())%></pre></tbl:cell>518 <pre class="filtertext" id="syncfilter.<%=filterId%>"><%=HTML.encodeTags(sb.toString(), "value|name|operator|function")%></pre></tbl:cell> 519 519 <tbl:cell column="inSync"> 520 520 <base:icon
Note: See TracChangeset
for help on using the changeset viewer.