FIX: Special attributes not working (#232)
# Context
Data explorer gives you the ability to use special attributes such as 👇
> SELECT TIMESTAMP 'yesterday' as reltime$time
# Problem
During the upgrade to ember octane these were neglected and did not work. This PR updates them to working condition.
# Additional
- Drop unused action of `saveDefaults`
This commit is contained in:
parent
389b8e15c9
commit
075a508e52
|
@ -1,31 +1,14 @@
|
||||||
import Component from "@glimmer/component";
|
import Component from "@glimmer/component";
|
||||||
import { categoryLinkHTML } from "discourse/helpers/category-link";
|
|
||||||
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
|
|
||||||
import { convertIconClass, iconHTML } from "discourse-common/lib/icon-library";
|
|
||||||
import getURL from "discourse-common/lib/get-url";
|
import getURL from "discourse-common/lib/get-url";
|
||||||
import { capitalize } from "@ember/string";
|
import { capitalize } from "@ember/string";
|
||||||
import { htmlSafe } from "@ember/template";
|
|
||||||
import { get } from "@ember/object";
|
|
||||||
import { isEmpty } from "@ember/utils";
|
|
||||||
import { escapeExpression } from "discourse/lib/utilities";
|
import { escapeExpression } from "discourse/lib/utilities";
|
||||||
import { cached } from "@glimmer/tracking";
|
import { cached } from "@glimmer/tracking";
|
||||||
import TextViewComponent from "./result-types/text";
|
import TextViewComponent from "./result-types/text";
|
||||||
|
|
||||||
export default class QueryRowContent extends Component {
|
export default class QueryRowContent extends Component {
|
||||||
constructor() {
|
|
||||||
super(...arguments);
|
|
||||||
|
|
||||||
this.helpers = {
|
|
||||||
"icon-or-image": icon_or_image_replacement,
|
|
||||||
"category-link": category_badge_replacement,
|
|
||||||
reltime: bound_date_replacement,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@cached
|
@cached
|
||||||
get results() {
|
get results() {
|
||||||
return this.args.columnComponents.map((t, idx) => {
|
return this.args.columnComponents.map((t, idx) => {
|
||||||
const params = {};
|
|
||||||
const value = this.args.row[idx],
|
const value = this.args.row[idx],
|
||||||
id = parseInt(value, 10);
|
id = parseInt(value, 10);
|
||||||
|
|
||||||
|
@ -58,16 +41,10 @@ export default class QueryRowContent extends Component {
|
||||||
ctx["target"] = name;
|
ctx["target"] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t.name === "category" || t.name === "badge" || t.name === "reltime") {
|
|
||||||
// only replace helpers if needed
|
|
||||||
params.helpers = this.helpers;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return {
|
return {
|
||||||
component: t.component || TextViewComponent,
|
component: t.component || TextViewComponent,
|
||||||
ctx,
|
ctx,
|
||||||
params,
|
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return "error";
|
return "error";
|
||||||
|
@ -76,32 +53,6 @@ export default class QueryRowContent extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function icon_or_image_replacement(str, ctx) {
|
|
||||||
str = get(ctx.contexts[0], str);
|
|
||||||
if (isEmpty(str)) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (str.indexOf("fa-") > -1) {
|
|
||||||
const icon = iconHTML(convertIconClass(str));
|
|
||||||
return htmlSafe(icon);
|
|
||||||
} else {
|
|
||||||
return htmlSafe("<img src='" + str + "'>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function category_badge_replacement(str, ctx) {
|
|
||||||
const category = get(ctx.contexts[0], str);
|
|
||||||
return categoryLinkHTML(category, {
|
|
||||||
allowUncategorized: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function bound_date_replacement(str, ctx) {
|
|
||||||
const value = get(ctx.contexts[0], str);
|
|
||||||
return htmlSafe(autoUpdatingRelativeAge(new Date(value), { title: true }));
|
|
||||||
}
|
|
||||||
|
|
||||||
function guessUrl(t) {
|
function guessUrl(t) {
|
||||||
let [dest, name] = [t, t];
|
let [dest, name] = [t, t];
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
title={{@ctx.badge.display_name}}
|
title={{@ctx.badge.display_name}}
|
||||||
data-badge-name={{@ctx.badge.name}}
|
data-badge-name={{@ctx.badge.name}}
|
||||||
>
|
>
|
||||||
{{icon-or-image @ctx.badge.icon}}
|
{{this.iconOrImageReplacement}}
|
||||||
<span class="badge-display-name">{{@ctx.badge.display_name}}</span>
|
<span class="badge-display-name">{{@ctx.badge.display_name}}</span>
|
||||||
</a>
|
</a>
|
|
@ -0,0 +1,19 @@
|
||||||
|
import Component from "@glimmer/component";
|
||||||
|
import { isEmpty } from "@ember/utils";
|
||||||
|
import { htmlSafe } from "@ember/template";
|
||||||
|
import { convertIconClass, iconHTML } from "discourse-common/lib/icon-library";
|
||||||
|
|
||||||
|
export default class Badge extends Component {
|
||||||
|
get iconOrImageReplacement() {
|
||||||
|
if (isEmpty(this.args.ctx.badge.icon)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.args.ctx.badge.icon.indexOf("fa-") > -1) {
|
||||||
|
const icon = iconHTML(convertIconClass(this.args.ctx.badge.icon));
|
||||||
|
return htmlSafe(icon);
|
||||||
|
} else {
|
||||||
|
return htmlSafe("<img src='" + this.args.ctx.badge.icon + "'>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
{{#if @ctx.category}}
|
{{#if @ctx.category}}
|
||||||
{{category-link @ctx.category}}
|
{{this.categoryBadgeReplacement}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<a href="{{@ctx.baseuri}}/t/{{@ctx.id}}">{{@ctx.id}}</a>
|
<a href="{{@ctx.baseuri}}/t/{{@ctx.id}}">{{@ctx.id}}</a>
|
||||||
{{/if}}
|
{{/if}}
|
|
@ -0,0 +1,10 @@
|
||||||
|
import Component from "@glimmer/component";
|
||||||
|
import { categoryLinkHTML } from "discourse/helpers/category-link";
|
||||||
|
|
||||||
|
export default class Category extends Component {
|
||||||
|
get categoryBadgeReplacement() {
|
||||||
|
return categoryLinkHTML(this.args.ctx.category, {
|
||||||
|
allowUncategorized: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1 +1 @@
|
||||||
{{html-safe @textValue}}
|
{{html-safe @ctx.value}}
|
|
@ -1 +1 @@
|
||||||
{{reltime @textValue}}
|
{{this.boundDateReplacement}}
|
|
@ -0,0 +1,11 @@
|
||||||
|
import Component from "@glimmer/component";
|
||||||
|
import { autoUpdatingRelativeAge } from "discourse/lib/formatter";
|
||||||
|
import { htmlSafe } from "@ember/template";
|
||||||
|
|
||||||
|
export default class Reltime extends Component {
|
||||||
|
get boundDateReplacement() {
|
||||||
|
return htmlSafe(
|
||||||
|
autoUpdatingRelativeAge(new Date(this.args.ctx.value), { title: true })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -277,11 +277,6 @@ export default class PluginsExplorerController extends Controller {
|
||||||
this.selectedItem.resetParams();
|
this.selectedItem.resetParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
saveDefaults() {
|
|
||||||
this.selectedItem.saveDefaults();
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
updateSortProperty(property) {
|
updateSortProperty(property) {
|
||||||
if (this.sortByProperty === property) {
|
if (this.sortByProperty === property) {
|
||||||
|
|
Loading…
Reference in New Issue