FEATURE: add support for _url to link to a url

This new feature means that if you name a column `xyz_url` then the return
value will be treated as a URL.

If you would like to name the link use the format `name,https://cnn.com`
This commit is contained in:
Sam Saffron 2019-05-13 14:41:37 +10:00
parent 817a233cef
commit 29862defaa
4 changed files with 83 additions and 43 deletions

View File

@ -33,6 +33,20 @@ function bound_date_replacement(str, ctx) {
const esc = Handlebars.Utils.escapeExpression; const esc = Handlebars.Utils.escapeExpression;
// consider moving this elsewhere
function guessUrl(t) {
let [dest, name] = [t, t];
const split = t.split(/,(.+)/);
if (split.length > 1) {
name = split[0];
dest = split[1];
}
return [dest, name];
}
const QueryRowContentComponent = Ember.Component.extend( const QueryRowContentComponent = Ember.Component.extend(
bufferedRender({ bufferedRender({
tagName: "tr", tagName: "tr",
@ -70,6 +84,12 @@ const QueryRowContentComponent = Ember.Component.extend(
ctx[t.name] = parentView[`lookup${t.name.capitalize()}`](id); ctx[t.name] = parentView[`lookup${t.name.capitalize()}`](id);
} }
if (t.name === "url") {
let [url, name] = guessUrl(value);
ctx["href"] = url;
ctx["target"] = name;
}
if ( if (
t.name === "category" || t.name === "category" ||
t.name === "badge" || t.name === "badge" ||

View File

@ -0,0 +1 @@
<a href="{{href}}">{{target}}</a>

View File

@ -80,6 +80,11 @@ class Queries
"id": -14, "id": -14,
"name": "Group Members Reply Count", "name": "Group Members Reply Count",
"description": "Number of replies by members of a group over a given time period. Requires 'group_name', 'start_date', and 'end_date' parameters. Dates need to be in the form 'yyyy-mm-dd'. Accepts an 'include_pms' parameter." "description": "Number of replies by members of a group over a given time period. Requires 'group_name', 'start_date', and 'end_date' parameters. Dates need to be in the form 'yyyy-mm-dd'. Accepts an 'include_pms' parameter."
},
"total-assigned-topics-report": {
"id": -15,
"name": "Total topics assigned per user",
"description": "Count of assigned topis per user linking to assign list"
} }
}.with_indifferent_access }.with_indifferent_access
@ -438,6 +443,18 @@ class Queries
ORDER BY reply_count DESC, tu.user_id ORDER BY reply_count DESC, tu.user_id
SQL SQL
queries["total-assigned-topics-report"]["sql"] = <<~SQL
SELECT value::int user_id,
count(*)::varchar || ',/u/' || username_lower || '/activity/assigned' assigned_url
FROM topic_custom_fields tf
JOIN topics t on t.id = topic_id
JOIN users u on u.id = value::int
WHERE tf.name = 'assigned_to_id'
AND t.deleted_at IS NULL
GROUP BY value::int, username_lower
ORDER BY count(*) DESC, username_lower
SQL
# convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc. # convert query ids from "mostcommonlikers" to "-1", "mostmessages" to "-2" etc.
queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" } queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" }
queries queries

View File

@ -177,6 +177,8 @@ SQL
def self.add_extra_data(pg_result) def self.add_extra_data(pg_result)
needed_classes = {} needed_classes = {}
ret = {}
col_map = {}
pg_result.fields.each_with_index do |col, idx| pg_result.fields.each_with_index do |col, idx|
rgx = column_regexes.find { |r| r.match col } rgx = column_regexes.find { |r| r.match col }
@ -188,11 +190,11 @@ SQL
cls = $1.to_sym cls = $1.to_sym
needed_classes[cls] ||= [] needed_classes[cls] ||= []
needed_classes[cls] << idx needed_classes[cls] << idx
elsif col =~ /^\w+_url$/
col_map[idx] = "url"
end end
end end
ret = {}
col_map = {}
needed_classes.each do |cls, column_nums| needed_classes.each do |cls, column_nums|
next unless column_nums.present? next unless column_nums.present?
support_info = extra_data_pluck_fields[cls] support_info = extra_data_pluck_fields[cls]
@ -1126,9 +1128,9 @@ SQL
json[:explain] = result[:explain] if opts[:explain] json[:explain] = result[:explain] if opts[:explain]
if !params[:download] if !params[:download]
ext = DataExplorer.add_extra_data(pg_result) relations, colrender = DataExplorer.add_extra_data(pg_result)
json[:colrender] = ext[1] json[:relations] = relations
json[:relations] = ext[0] json[:colrender] = colrender
end end
json[:rows] = pg_result.values json[:rows] = pg_result.values