Commit 93f22eca authored by chenos's avatar chenos
Browse files

小细节补充

No related merge requests found
Showing with 128 additions and 4 deletions
+128 -4
......@@ -8,6 +8,8 @@ import get from 'lodash/get';
import './style.less';
import Field from '../Field';
import cloneDeep from 'lodash/cloneDeep';
import { Checkbox, message } from 'antd';
import api from '@/api-client';
export const SortableItem = sortableElement(props => <tr {...props} />);
export const SortableContainer = sortableContainer(props => <tbody {...props} />);
......@@ -58,11 +60,38 @@ export const components = ({data = {}, rowKey, mutate, onMoved, isFieldComponent
};
};
export function fields2columns(fields) {
export function fields2columns(fields, ctx: any = {}) {
const columns: any[] = fields.map(item => {
const field = cloneDeep(item);
field.render = (value, record) => field.interface === 'sort' ? <DragHandle/> : <Field data={record} viewType={'table'} schema={field} value={value}/>;
field.className = `${field.className||''} noco-field-${field.interface}`;
if (field.editable && field.interface === 'boolean') {
field.title = (
<span>
<Checkbox onChange={async (e) => {
try {
await api.resource(field.resource).update({
associatedKey: ctx.associatedKey,
// resourceKey: data.id,
// tableName: data.tableName||'pages',
values: {
accessible: e.target.checked,
},
});
message.success('保存成功');
if (ctx.refresh) {
ctx.refresh();
}
} catch (error) {
message.error('保存失败');
}
}}/>
{' '}
{field.title}
</span>
);
}
return {
...field,
...(field.component||{}),
......
......@@ -154,7 +154,7 @@ export function Table(props: TableProps) {
indicator: icon,
// className: 'spinning--absolute m32',
}}
columns={fields2columns(fields)}
columns={fields2columns(fields, {associatedKey, refresh})}
dataSource={data?.list||(data as any)}
onChange={(pagination, filters, sorter, extra) => {
run({...params[0], sorter});
......
......@@ -3,6 +3,69 @@ import Database from '@nocobase/database';
import { flatToTree } from '../utils';
import { Op } from 'sequelize';
async function getRoutes(ctx) {
const database: Database = ctx.db;
const Page = database.getModel('pages');
const Collection = database.getModel('collections');
let pages = await Page.findAll(Page.parseApiJson(ctx.state.developerMode ? {
filter: {
'parent_id.$notNull': true,
},
sort: ['sort'],
} : {
filter: {
'parent_id.$notNull': true,
developerMode: {'$isFalsy': true},
},
sort: ['sort'],
}));
const items = [];
for (const page of pages) {
items.push({
routable_type: 'pages',
routable_id: page.id,
});
if (page.get('path') === '/collections') {
const collections = await Collection.findAll(Collection.parseApiJson(ctx.state.developerMode ? {
filter: {
showInDataMenu: true,
},
sort: ['sort'],
}: {
filter: {
developerMode: {'$isFalsy': true},
showInDataMenu: true,
},
sort: ['sort'],
}));
for (const collection of collections) {
items.push({
routable_type: 'collections',
routable_id: collection.id,
});
const views = await collection.getViews({
where: {
[Op.or]: [
{ showInDataMenu: true },
{ default: true }
]
},
order: [['sort', 'asc']]
});
if (views.length > 1) {
for (const view of views) {
items.push({
routable_id: view.id,
routable_type: 'views',
});
}
}
}
}
}
return items;
}
export async function list(ctx: actions.Context, next: actions.Next) {
const database: Database = ctx.db;
const { associatedKey, associated } = ctx.action.params;
......@@ -125,6 +188,22 @@ export async function update(ctx: actions.Context, next: actions.Next) {
}
} = ctx.action.params;
if (!resourceKey) {
if (accessible === false) {
await associated.updateAssociations({
routes: [],
});
} else if (accessible === true) {
const routes = await getRoutes(ctx);
// console.log(routes);
await associated.updateAssociations({
routes,
});
}
ctx.body = {};
return next();
}
console.log(ctx.action.params, { routable_type: tableName, routable_id: resourceKey });
let [route] = await associated.getRoutes({
where: { routable_type: tableName, routable_id: resourceKey },
......
import { Op } from 'sequelize';
import { actions } from '@nocobase/actions';
import _ from 'lodash';
export async function list(ctx: actions.Context, next: actions.Next) {
const { associated } = ctx.action.params;
......@@ -16,8 +17,8 @@ export async function list(ctx: actions.Context, next: actions.Next) {
item.set('permissions', [permission]); // 输出
}
});
next();
});
await next();
}
export async function get(ctx: actions.Context, next: actions.Next) {
......@@ -26,7 +27,22 @@ export async function get(ctx: actions.Context, next: actions.Next) {
associated
} = ctx.action.params;
ctx.body = await ctx.ac.as(associated).can(resourceKey).permissions();
const permissions = await ctx.ac.as(associated).can(resourceKey).permissions();
const permission = await associated.getPermissions({
where: {
collection_name: resourceKey,
},
plain: true,
limit: 1,
});
console.log(permission);
ctx.body = {
...permissions,
description: _.get(permission, 'description'),
};
await next();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment