mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 23:49:27 +08:00
Merge branch 'next' into develop
This commit is contained in:
commit
30a30487b1
@ -9,6 +9,7 @@
|
||||
|
||||
import { BelongsToManyRepository, Collection, HasManyRepository, TargetKey, Model, Op } from '@nocobase/database';
|
||||
import { Context } from '@nocobase/actions';
|
||||
import { pick } from 'lodash';
|
||||
|
||||
import { SortField } from './sort-field';
|
||||
|
||||
@ -84,12 +85,15 @@ export class SortableCollection {
|
||||
|
||||
// insert source position to target position
|
||||
async move(sourceInstanceId: TargetKey, targetInstanceId: TargetKey, options: MoveOptions = {}) {
|
||||
const sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
|
||||
let sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
|
||||
const targetInstance = await this.collection.repository.findByTargetKey(targetInstanceId);
|
||||
|
||||
if (this.scopeKey && sourceInstance.get(this.scopeKey) !== targetInstance.get(this.scopeKey)) {
|
||||
await sourceInstance.update({
|
||||
[sourceInstance] = await this.collection.repository.update({
|
||||
filterByTk: sourceInstanceId,
|
||||
values: {
|
||||
[this.scopeKey]: targetInstance.get(this.scopeKey),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -97,18 +101,17 @@ export class SortableCollection {
|
||||
}
|
||||
|
||||
async changeScope(sourceInstanceId: TargetKey, targetScope: any, method?: string) {
|
||||
const sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
|
||||
let sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
|
||||
const targetScopeValue = targetScope[this.scopeKey];
|
||||
|
||||
if (targetScopeValue && sourceInstance.get(this.scopeKey) !== targetScopeValue) {
|
||||
await sourceInstance.update(
|
||||
{
|
||||
[sourceInstance] = await this.collection.repository.update({
|
||||
filterByTk: sourceInstanceId,
|
||||
values: {
|
||||
[this.scopeKey]: targetScopeValue,
|
||||
},
|
||||
{
|
||||
silent: false,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
if (method === 'prepend') {
|
||||
await this.sticky(sourceInstanceId);
|
||||
@ -117,15 +120,13 @@ export class SortableCollection {
|
||||
}
|
||||
|
||||
async sticky(sourceInstanceId: TargetKey) {
|
||||
const sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
|
||||
await sourceInstance.update(
|
||||
{
|
||||
await this.collection.repository.update({
|
||||
filterByTk: sourceInstanceId,
|
||||
values: {
|
||||
[this.field.get('name')]: 0,
|
||||
},
|
||||
{
|
||||
silent: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async sameScopeMove(sourceInstance: Model, targetInstance: Model, options: MoveOptions) {
|
||||
@ -172,13 +173,14 @@ export class SortableCollection {
|
||||
silent: true,
|
||||
});
|
||||
|
||||
await sourceInstance.update(
|
||||
{
|
||||
await this.collection.repository.update({
|
||||
filterByTk: (this.collection.isMultiFilterTargetKey()
|
||||
? pick(sourceInstance, this.collection.filterTargetKey)
|
||||
: sourceInstance.get(<string>this.collection.filterTargetKey)) as TargetKey,
|
||||
values: {
|
||||
[fieldName]: targetSort,
|
||||
},
|
||||
{
|
||||
silent: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user