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 { BelongsToManyRepository, Collection, HasManyRepository, TargetKey, Model, Op } from '@nocobase/database';
|
||||||
import { Context } from '@nocobase/actions';
|
import { Context } from '@nocobase/actions';
|
||||||
|
import { pick } from 'lodash';
|
||||||
|
|
||||||
import { SortField } from './sort-field';
|
import { SortField } from './sort-field';
|
||||||
|
|
||||||
@ -84,12 +85,15 @@ export class SortableCollection {
|
|||||||
|
|
||||||
// insert source position to target position
|
// insert source position to target position
|
||||||
async move(sourceInstanceId: TargetKey, targetInstanceId: TargetKey, options: MoveOptions = {}) {
|
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);
|
const targetInstance = await this.collection.repository.findByTargetKey(targetInstanceId);
|
||||||
|
|
||||||
if (this.scopeKey && sourceInstance.get(this.scopeKey) !== targetInstance.get(this.scopeKey)) {
|
if (this.scopeKey && sourceInstance.get(this.scopeKey) !== targetInstance.get(this.scopeKey)) {
|
||||||
await sourceInstance.update({
|
[sourceInstance] = await this.collection.repository.update({
|
||||||
[this.scopeKey]: targetInstance.get(this.scopeKey),
|
filterByTk: sourceInstanceId,
|
||||||
|
values: {
|
||||||
|
[this.scopeKey]: targetInstance.get(this.scopeKey),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,18 +101,17 @@ export class SortableCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async changeScope(sourceInstanceId: TargetKey, targetScope: any, method?: string) {
|
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];
|
const targetScopeValue = targetScope[this.scopeKey];
|
||||||
|
|
||||||
if (targetScopeValue && sourceInstance.get(this.scopeKey) !== targetScopeValue) {
|
if (targetScopeValue && sourceInstance.get(this.scopeKey) !== targetScopeValue) {
|
||||||
await sourceInstance.update(
|
[sourceInstance] = await this.collection.repository.update({
|
||||||
{
|
filterByTk: sourceInstanceId,
|
||||||
|
values: {
|
||||||
[this.scopeKey]: targetScopeValue,
|
[this.scopeKey]: targetScopeValue,
|
||||||
},
|
},
|
||||||
{
|
silent: false,
|
||||||
silent: false,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (method === 'prepend') {
|
if (method === 'prepend') {
|
||||||
await this.sticky(sourceInstanceId);
|
await this.sticky(sourceInstanceId);
|
||||||
@ -117,15 +120,13 @@ export class SortableCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async sticky(sourceInstanceId: TargetKey) {
|
async sticky(sourceInstanceId: TargetKey) {
|
||||||
const sourceInstance = await this.collection.repository.findByTargetKey(sourceInstanceId);
|
await this.collection.repository.update({
|
||||||
await sourceInstance.update(
|
filterByTk: sourceInstanceId,
|
||||||
{
|
values: {
|
||||||
[this.field.get('name')]: 0,
|
[this.field.get('name')]: 0,
|
||||||
},
|
},
|
||||||
{
|
silent: true,
|
||||||
silent: true,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async sameScopeMove(sourceInstance: Model, targetInstance: Model, options: MoveOptions) {
|
async sameScopeMove(sourceInstance: Model, targetInstance: Model, options: MoveOptions) {
|
||||||
@ -172,13 +173,14 @@ export class SortableCollection {
|
|||||||
silent: true,
|
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,
|
[fieldName]: targetSort,
|
||||||
},
|
},
|
||||||
{
|
silent: true,
|
||||||
silent: true,
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user