web/elements: allow app.model names for ak-object-changelog

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-11-26 12:04:46 +01:00
parent 0948e0ee1c
commit 80364b04a9
2 changed files with 25 additions and 10 deletions

View File

@ -27,19 +27,38 @@ export class ObjectChangelog extends Table<Event> {
targetModelPk!: string | number; targetModelPk!: string | number;
@property() @property()
targetModelApp!: string; targetModelApp?: string;
private _targetModelName: string = "";
@property() @property()
targetModelName!: string; set targetModelName(value: string) {
this._targetModelName = value;
this.fetch();
}
get targetModelName(): string {
return this._targetModelName;
}
async apiEndpoint(page: number): Promise<AKResponse<Event>> { async apiEndpoint(page: number): Promise<AKResponse<Event>> {
let modelName = this._targetModelName;
let appName = this.targetModelApp;
if (this._targetModelName.indexOf(".") !== -1) {
const parts = this._targetModelName.split(".");
appName = parts[0];
modelName = parts[1];
}
if (this._targetModelName === "") {
return Promise.reject();
}
return new EventsApi(DEFAULT_CONFIG).eventsEventsList({ return new EventsApi(DEFAULT_CONFIG).eventsEventsList({
action: "model_", action: "model_",
page: page, page: page,
ordering: this.order, ordering: this.order,
pageSize: (await uiConfig()).pagination.perPage, pageSize: (await uiConfig()).pagination.perPage,
contextModelApp: this.targetModelApp, contextModelApp: appName,
contextModelName: this.targetModelName, contextModelName: modelName,
contextModelPk: this.targetModelPk.toString(), contextModelPk: this.targetModelPk.toString(),
}); });
} }

View File

@ -19,7 +19,7 @@ import { groupBy } from "../../utils";
import "../EmptyState"; import "../EmptyState";
import "../chips/Chip"; import "../chips/Chip";
import "../chips/ChipGroup"; import "../chips/ChipGroup";
import { getURLParams, updateURLParams } from "../router/RouteMatch"; import { getURLParam, updateURLParams } from "../router/RouteMatch";
import "./TablePagination"; import "./TablePagination";
import "./TableSearch"; import "./TableSearch";
@ -116,7 +116,7 @@ export abstract class Table<T> extends LitElement {
order?: string; order?: string;
@property({ type: String }) @property({ type: String })
search?: string; search: string = getURLParam("search", "");
@property({ type: Boolean }) @property({ type: Boolean })
checkbox = false; checkbox = false;
@ -397,10 +397,6 @@ export abstract class Table<T> extends LitElement {
} }
firstUpdated(): void { firstUpdated(): void {
const params = getURLParams();
if ("search" in params) {
this.search = params.search;
}
this.fetch(); this.fetch();
} }