mirror of
https://gitee.com/nocobase/nocobase.git
synced 2024-12-04 13:18:55 +08:00
fix: add sticky parameter to sort action
This commit is contained in:
parent
b101760092
commit
eba121b998
@ -533,7 +533,7 @@ export async function sort(ctx: Context, next: Next) {
|
||||
const Model = ctx.db.getModel(resourceName);
|
||||
const table = ctx.db.getTable(resourceName);
|
||||
|
||||
const { field, target } = values;
|
||||
const { sticky, field, target } = values;
|
||||
if (!values.field || typeof target === 'undefined') {
|
||||
return next();
|
||||
}
|
||||
@ -559,6 +559,7 @@ export async function sort(ctx: Context, next: Next) {
|
||||
},
|
||||
transaction
|
||||
});
|
||||
|
||||
if (!source) {
|
||||
await transaction.rollback();
|
||||
throw new Error(`resource(${resourceKey}) does not exist`);
|
||||
@ -627,6 +628,7 @@ export async function sort(ctx: Context, next: Next) {
|
||||
} else {
|
||||
Object.assign(updates, {
|
||||
[sortAttr]: await sortField.getNextValue({
|
||||
next: sticky ? 'min' : 'max',
|
||||
where: targetScopeWhere,
|
||||
transaction
|
||||
})
|
||||
|
@ -789,10 +789,10 @@ export class SORT extends NUMBER {
|
||||
return DataTypes.INTEGER;
|
||||
}
|
||||
|
||||
public async getNextValue(this: SORT, { where, transaction }) {
|
||||
public async getNextValue(this: SORT, { where, transaction, next: n = 'max' }) {
|
||||
const table = this.context.sourceTable;
|
||||
const Model = table.getModel();
|
||||
const { name, next = 'max' } = this.options;
|
||||
const { name, next = n } = this.options;
|
||||
const extremum: number = await Model[next](name, { where, transaction }) || 0;
|
||||
return extremum + (next === 'max' ? 1 : -1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user