mirror of
https://github.com/discourse/discourse.git
synced 2026-07-29 23:58:12 -05:00
FEATURE: Add pagination to API keys page (#14777)
This commit is contained in:
@@ -1,14 +1,39 @@
|
||||
import Controller from "@ember/controller";
|
||||
import { action } from "@ember/object";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
|
||||
export default Controller.extend({
|
||||
actions: {
|
||||
revokeKey(key) {
|
||||
key.revoke().catch(popupAjaxError);
|
||||
},
|
||||
loading: false,
|
||||
|
||||
undoRevokeKey(key) {
|
||||
key.undoRevoke().catch(popupAjaxError);
|
||||
},
|
||||
@action
|
||||
revokeKey(key) {
|
||||
key.revoke().catch(popupAjaxError);
|
||||
},
|
||||
|
||||
@action
|
||||
undoRevokeKey(key) {
|
||||
key.undoRevoke().catch(popupAjaxError);
|
||||
},
|
||||
|
||||
@action
|
||||
loadMore() {
|
||||
if (this.loading || this.model.loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
const limit = 50;
|
||||
|
||||
this.set("loading", true);
|
||||
this.store
|
||||
.findAll("api-key", { offset: this.model.length, limit })
|
||||
.then((keys) => {
|
||||
this.model.addObjects(keys);
|
||||
if (keys.length < limit) {
|
||||
this.model.set("loaded", true);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.set("loading", false);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -5,67 +5,71 @@
|
||||
label="admin.api.new_key"}}
|
||||
|
||||
{{#if model}}
|
||||
<table class="api-keys grid">
|
||||
<thead>
|
||||
<th>{{i18n "admin.api.key"}}</th>
|
||||
<th>{{i18n "admin.api.description"}}</th>
|
||||
<th>{{i18n "admin.api.user"}}</th>
|
||||
<th>{{i18n "admin.api.created"}}</th>
|
||||
<th>{{i18n "admin.api.last_used"}}</th>
|
||||
<th> </th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each model as |k|}}
|
||||
<tr class={{if k.revoked_at "revoked"}}>
|
||||
<td class="key">
|
||||
{{#if k.revoked_at}}{{d-icon "times-circle"}}{{/if}}
|
||||
{{k.truncatedKey}}
|
||||
</td>
|
||||
<td class="key-description">
|
||||
{{k.shortDescription}}
|
||||
</td>
|
||||
<td class="key-user">
|
||||
<div class="label">{{i18n "admin.api.user"}}</div>
|
||||
{{#if k.user}}
|
||||
{{#link-to "adminUser" k.user}}
|
||||
{{avatar k.user imageSize="small"}}
|
||||
{{/link-to}}
|
||||
{{else}}
|
||||
{{i18n "admin.api.all_users"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="key-created">
|
||||
<div class="label">{{i18n "admin.api.created"}}</div>
|
||||
{{format-date k.created_at}}
|
||||
</td>
|
||||
<td class="key-last-used">
|
||||
<div class="label">{{i18n "admin.api.last_used"}}</div>
|
||||
{{#if k.last_used_at}}
|
||||
{{format-date k.last_used_at}}
|
||||
{{else}}
|
||||
{{i18n "admin.api.never_used"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="key-controls">
|
||||
{{d-button action=(route-action "show" k) icon="far-eye" title="admin.api.show_details"}}
|
||||
{{#if k.revoked_at}}
|
||||
{{d-button
|
||||
action=(action "undoRevokeKey")
|
||||
actionParam=k icon="undo"
|
||||
title="admin.api.undo_revoke"}}
|
||||
{{else}}
|
||||
{{d-button
|
||||
class="btn-danger"
|
||||
action=(action "revokeKey")
|
||||
actionParam=k
|
||||
icon="times"
|
||||
title="admin.api.revoke"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{#load-more selector=".api-keys tr" action=(action "loadMore")}}
|
||||
<table class="api-keys grid">
|
||||
<thead>
|
||||
<th>{{i18n "admin.api.key"}}</th>
|
||||
<th>{{i18n "admin.api.description"}}</th>
|
||||
<th>{{i18n "admin.api.user"}}</th>
|
||||
<th>{{i18n "admin.api.created"}}</th>
|
||||
<th>{{i18n "admin.api.last_used"}}</th>
|
||||
<th> </th>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{#each model as |k|}}
|
||||
<tr class={{if k.revoked_at "revoked"}}>
|
||||
<td class="key">
|
||||
{{#if k.revoked_at}}{{d-icon "times-circle"}}{{/if}}
|
||||
{{k.truncatedKey}}
|
||||
</td>
|
||||
<td class="key-description">
|
||||
{{k.shortDescription}}
|
||||
</td>
|
||||
<td class="key-user">
|
||||
<div class="label">{{i18n "admin.api.user"}}</div>
|
||||
{{#if k.user}}
|
||||
{{#link-to "adminUser" k.user}}
|
||||
{{avatar k.user imageSize="small"}}
|
||||
{{/link-to}}
|
||||
{{else}}
|
||||
{{i18n "admin.api.all_users"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="key-created">
|
||||
<div class="label">{{i18n "admin.api.created"}}</div>
|
||||
{{format-date k.created_at}}
|
||||
</td>
|
||||
<td class="key-last-used">
|
||||
<div class="label">{{i18n "admin.api.last_used"}}</div>
|
||||
{{#if k.last_used_at}}
|
||||
{{format-date k.last_used_at}}
|
||||
{{else}}
|
||||
{{i18n "admin.api.never_used"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
<td class="key-controls">
|
||||
{{d-button action=(route-action "show" k) icon="far-eye" title="admin.api.show_details"}}
|
||||
{{#if k.revoked_at}}
|
||||
{{d-button
|
||||
action=(action "undoRevokeKey")
|
||||
actionParam=k icon="undo"
|
||||
title="admin.api.undo_revoke"}}
|
||||
{{else}}
|
||||
{{d-button
|
||||
class="btn-danger"
|
||||
action=(action "revokeKey")
|
||||
actionParam=k
|
||||
icon="times"
|
||||
title="admin.api.revoke"}}
|
||||
{{/if}}
|
||||
</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{/load-more}}
|
||||
|
||||
{{conditional-loading-spinner condition=loading}}
|
||||
{{else}}
|
||||
<p>{{i18n "admin.api.none"}}</p>
|
||||
{{/if}}
|
||||
|
||||
Reference in New Issue
Block a user