@PropertyField(
key = "metric",
name = "metric",
- type = PropertyType.METRIC),
+ type = PropertyType.METRIC,
+ options = {"regexp_on_key: new_.*"}
+ ),
@PropertyField(
key = "password",
name = "password",
/**
* Options for *_LIST types
*
- * @since 3.0
+ * @since 3.0 Options for property of type PropertyType.SINGLE_SELECT_LIST</code>
+ *
+ * @since 3.3 Options for property of type PropertyType.METRIC</code>.
+ * If no option is specified, any metric will match.
+ * If options are specified, all must match for the metric to be displayed.
+ * Three types of filter are supported <code>key:REGEXP</code>, <code>domain:REGEXP</code> and <code>type:comma_separated__list_of_types</code>.
+ * For example <code>key:new_.*</code> will match any metric which key starts by <code>new_</code>.
+ * For example <code>type:INT,FLOAT</code> will match any metric of type <code>INT</code> or <code>FLOAT</code>.
+ * For example <code>type:NUMERIC</code> will match any metric of numerictype.
*/
String[] options() default {};
end
name
end
+
+ def metrics_for_property(property)
+ Metric.all.select(&:display?).sort_by(&:short_name).select do |metric|
+ property.options.blank? || property.options.any? { |option| metric_matches(metric, option) }
+ end
+ end
+
+ def metric_matches(metric, option)
+ if /key:(.*)/.match(option)
+ Regexp.new(Regexp.last_match(1).strip).match(metric.key)
+ elsif /domain:(.*)/.match(option)
+ Regexp.new(Regexp.last_match(1)).match(metric.domain)
+ elsif /type:(.*)/.match(option)
+ false
+ Regexp.last_match(1).split(',').any? { |type| (type == metric.value_type) || ((type == 'NUMERIC') && metric.numeric?) }
+ else
+ false
+ end
+ end
end
<select name="<%= name -%>" id="<%= id -%>">
<option value=""><%= message('default') -%></option>
<%
- metrics_per_domain={}
- Metric.all.select { |m| m.display? }.sort_by { |m| m.short_name }.each do |metric|
- domain=metric.domain || ''
- metrics_per_domain[domain]||=[]
- metrics_per_domain[domain]<<metric
- end
-
- metrics_per_domain.keys.sort.each do |domain|
-%>
-
- <optgroup label="<%= h domain -%>">
-<%
- metrics_per_domain[domain].each do |m|
- selected_attr = (m.key==value || m.id==value) ? " selected='selected'" : ''
-%>
- <option value="<%= m.key -%>" <%= selected_attr -%>><%= m.short_name -%></option>
-<%
+ metrics_per_domain={}
+ metrics_for_property(property).each do |metric|
+ domain=metric.domain || ''
+ metrics_per_domain[domain]||=[]
+ metrics_per_domain[domain]<<metric
end
-%>
- </optgroup>
-<%
- end
-%>
+
+ metrics_per_domain.keys.sort.each do |domain|
+ %>
+ <optgroup label="<%= h domain -%>">
+ <% metrics_per_domain[domain].each do |m|
+ selected_attr = (m.key==value || m.id==value) ? " selected='selected'" : ''
+ %>
+ <option value="<%= m.key -%>" <%= selected_attr -%>><%= m.short_name -%></option>
+ <% end -%>
+ </optgroup>
+ <% end -%>
</select>
\ No newline at end of file