feat(admin): scopes page

This commit is contained in:
FoskyM 2023-10-01 19:41:37 +08:00
parent bcddcfc468
commit 10bb43a6f0
No known key found for this signature in database
GPG key ID: 42C0ED6994AD7E9C
8 changed files with 108 additions and 11 deletions

BIN
js/dist/admin.js generated vendored

Binary file not shown.

BIN
js/dist/admin.js.map generated vendored

Binary file not shown.

BIN
js/dist/forum.js generated vendored

Binary file not shown.

BIN
js/dist/forum.js.map generated vendored

Binary file not shown.

View file

@ -1,10 +1,7 @@
import app from 'flarum/admin/app'; import app from 'flarum/admin/app';
import Page from 'flarum/common/components/Page'; import Page from 'flarum/common/components/Page';
import AdminPage from 'flarum/admin/components/AdminPage';
import Button from 'flarum/common/components/Button'; import Button from 'flarum/common/components/Button';
import Client from "../../common/models/Client";
export default class ClientsPage extends Page { export default class ClientsPage extends Page {
settingName = 'collapsible-posts.reasons';
translationPrefix = 'foskym-oauth-center.admin.clients.'; translationPrefix = 'foskym-oauth-center.admin.clients.';
clients = []; clients = [];
oninit(vnode) { oninit(vnode) {

View file

@ -1,11 +1,102 @@
import app from 'flarum/admin/app';
import Page from 'flarum/common/components/Page'; import Page from 'flarum/common/components/Page';
import Button from 'flarum/common/components/Button';
import Select from 'flarum/common/components/Select';
import CheckBox from 'flarum/common/components/Checkbox';
export default class ScopesPage extends Page { export default class ScopesPage extends Page {
translationPrefix = 'foskym-oauth-center.admin.scopes.';
scopes = [];
oninit(vnode) {
super.oninit(vnode);
this.fields = [
'scope',
'resource_path',
'method',
'is_default',
'scope_name',
'scope_icon',
'scope_desc'
];
app.store.find('oauth-scopes').then(r => {
this.scopes = r;
this.fields.map(key => console.log(this.scopes[0][key]))
m.redraw();
});
}
view() { view() {
return ( return (
<div> <div class={"OAuthCenter-scopesPage"}>
<h2>Scopes Page</h2> {
m('.Form-group', [
m('table', [
m('thead', m('tr', [
this.fields.map(key => m('th', app.translator.trans(this.translationPrefix + key))),
m('th'),
])),
m('tbody', [
this.scopes.map((scope, index) => m('tr', [
this.fields.map(key =>
m('td', key === 'method' ? Select.component({
options: {
'GET': 'GET',
'POST': 'POST',
'PUT': 'PUT',
'DELETE': 'DELETE',
'PATCH': 'PATCH',
},
value: scope[key]() || 'GET',
onchange: (event) => {
this.saveScopeInfo(index, key, event.target.value);
},
}) : key === 'is_default' ? CheckBox.component({
state: scope[key]() || false,
onchange: (event) => {
this.saveScopeInfo(index, key, event.target.checked ? 1 : 0);
},
}) : m('input.FormControl', {
type: 'text',
value: scope[key]() || '',
onchange: (event) => {
this.saveScopeInfo(index, key, event.target.value);
},
}))
),
m('td', Button.component({
className: 'Button Button--icon',
icon: 'fas fa-times',
onclick: () => {
this.scopes[index].delete();
this.scopes.splice(index, 1);
},
})),
])),
m('tr', m('td', {
colspan: 7,
}, Button.component({
className: 'Button Button--block',
onclick: () => {
const scope = app.store.createRecord('oauth-scopes');
scope.save({}).then(this.scopes.push(scope));
},
}, app.translator.trans(this.translationPrefix + 'add_button')))),
]),
]),
])
}
</div> </div>
); );
} }
saveScopeInfo(index, key, value) {
console.log(index, key, value);
this.scopes[index].save({
[key]: value,
});
}
} }

View file

@ -29,7 +29,7 @@
max-width: 100% !important; max-width: 100% !important;
} }
.OAuthCenter-clientsPage { .OAuthCenter-clientsPage, .OAuthCenter-scopesPage {
table { table {
width: 100%; width: 100%;

View file

@ -20,6 +20,15 @@ foskym-oauth-center:
client_icon: 图标 client_icon: 图标
client_home: 主页 client_home: 主页
add_button: 添加应用 add_button: 添加应用
scopes:
scope: 权限标识
resource_path: 资源路径
method: 请求方法
is_default: 默认
scope_name: 名称
scope_icon: 图标
scope_desc: 描述
add_button: 添加权限
forum: forum:
page: page: