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;
// 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(
bufferedRender({
tagName: "tr",
@ -70,6 +84,12 @@ const QueryRowContentComponent = Ember.Component.extend(
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 (
t.name === "category" ||
t.name === "badge" ||

View File

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

View File

@ -80,6 +80,11 @@ class Queries
"id": -14,
"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."
},
"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
@ -438,6 +443,18 @@ class Queries
ORDER BY reply_count DESC, tu.user_id
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.
queries.transform_keys!.with_index { |key, idx| "-#{idx + 1}" }
queries

View File

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