mirror of
https://github.com/discourse/discourse.git
synced 2024-12-03 15:44:21 +08:00
aa88b07640
Continued work on moderate flags UI. In this PR admins are allowed to change the order of flags. The notify user flag is always on top but all other flags can be moved.
71 lines
1.9 KiB
Plaintext
71 lines
1.9 KiB
Plaintext
import Component from "@glimmer/component";
|
|
import { tracked } from "@glimmer/tracking";
|
|
import { action } from "@ember/object";
|
|
import { inject as service } from "@ember/service";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
import i18n from "discourse-common/helpers/i18n";
|
|
import { bind } from "discourse-common/utils/decorators";
|
|
import AdminFlagItem from "admin/components/admin-flag-item";
|
|
|
|
export default class AdminFlags extends Component {
|
|
@service site;
|
|
@tracked flags = this.site.flagTypes;
|
|
|
|
@bind
|
|
isFirstFlag(flag) {
|
|
return this.flags.indexOf(flag) === 1;
|
|
}
|
|
|
|
@bind
|
|
isLastFlag(flag) {
|
|
return this.flags.indexOf(flag) === this.flags.length - 1;
|
|
}
|
|
|
|
@action
|
|
moveFlagCallback(flag, direction) {
|
|
const fallbackFlags = [...this.flags];
|
|
|
|
const flags = this.flags;
|
|
|
|
const flagIndex = flags.indexOf(flag);
|
|
const targetFlagIndex = direction === "up" ? flagIndex - 1 : flagIndex + 1;
|
|
|
|
const targetFlag = flags[targetFlagIndex];
|
|
|
|
flags[flagIndex] = targetFlag;
|
|
flags[targetFlagIndex] = flag;
|
|
|
|
this.flags = flags;
|
|
|
|
return ajax(`/admin/config/flags/${flag.id}/reorder/${direction}`, {
|
|
type: "PUT",
|
|
}).catch((error) => {
|
|
this.flags = fallbackFlags;
|
|
return popupAjaxError(error);
|
|
});
|
|
}
|
|
|
|
<template>
|
|
<div class="container admin-flags">
|
|
<h1>{{i18n "admin.flags.title"}}</h1>
|
|
<table class="flags grid">
|
|
<thead>
|
|
<th>{{i18n "admin.flags.description"}}</th>
|
|
<th>{{i18n "admin.flags.enabled"}}</th>
|
|
</thead>
|
|
<tbody>
|
|
{{#each this.flags as |flag|}}
|
|
<AdminFlagItem
|
|
@flag={{flag}}
|
|
@moveFlagCallback={{this.moveFlagCallback}}
|
|
@isFirstFlag={{this.isFirstFlag flag}}
|
|
@isLastFlag={{this.isLastFlag flag}}
|
|
/>
|
|
{{/each}}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</template>
|
|
}
|