Files
wekan/models/positionHistory.js
T
Lauri Ojansivu bb4a013939 Collection schemas share one createdAt and one modifiedAt autoValue.
34 schema files wrote the same two autoValue functions out by hand, 65
times in five spellings: createdAt set on insert and $setOnInsert on upsert,
unset otherwise; modifiedAt set on every write. They are now
createdAtAutoValue and modifiedAtAutoValue in models/lib/schemaTimestamps.js,
named by each field as `autoValue: createdAtAutoValue`. models/settings.js,
which may not use import statements, requires them.

Schemas whose rule differs keep their own: changeHistory keeps a createdAt
the caller set, and listSyncCredentials' updatedAt does not unset.

tests/schemaTimestamps runs both functions in SimpleSchema's insert, upsert,
update and validation contexts, and fails when a schema writes either one
out by hand again.

Thanks to xet7 !
2026-11-21 18:27:03 +02:00

152 lines
3.8 KiB
JavaScript

import { Mongo } from 'meteor/mongo';
import { ReactiveCache } from '/imports/reactiveCache';
import { createdAtAutoValue, modifiedAtAutoValue } from '/models/lib/schemaTimestamps';
const { SimpleSchema } = require('/imports/simpleSchema');
/**
* PositionHistory collection to track original positions of swimlanes, lists, and cards
* before the list naming feature was added in commit 719ef87efceacfe91461a8eeca7cf74d11f4cc0a
*/
const PositionHistory = new Mongo.Collection('positionHistory');
PositionHistory.attachSchema(
new SimpleSchema({
boardId: {
/**
* The board ID this position history belongs to
*/
type: String,
},
entityType: {
/**
* Type of entity: 'swimlane', 'list', or 'card'
*/
type: String,
allowedValues: ['swimlane', 'list', 'card'],
},
entityId: {
/**
* The ID of the entity (swimlane, list, or card)
*/
type: String,
},
originalPosition: {
/**
* The original position data before any changes
*/
type: Object,
blackbox: true,
},
originalSwimlaneId: {
/**
* The original swimlane ID (for lists and cards)
*/
type: String,
optional: true,
},
originalListId: {
/**
* The original list ID (for cards)
*/
type: String,
optional: true,
},
originalTitle: {
/**
* The original title before any changes
*/
type: String,
optional: true,
},
createdAt: {
/**
* When this position history was created
*/
type: Date,
autoValue: createdAtAutoValue,
},
updatedAt: {
/**
* When this position history was last updated
*/
type: Date,
autoValue: modifiedAtAutoValue,
},
}),
);
PositionHistory.helpers({
/**
* Get the original position data
*/
getOriginalPosition() {
return this.originalPosition;
},
/**
* Get the original title
*/
getOriginalTitle() {
return this.originalTitle || '';
},
/**
* Get the original swimlane ID
*/
getOriginalSwimlaneId() {
return this.originalSwimlaneId;
},
/**
* Get the original list ID
*/
getOriginalListId() {
return this.originalListId;
},
/**
* Check if this entity has been moved from its original position
*/
hasMoved() {
if (this.entityType === 'swimlane') {
return this.originalPosition.sort !== undefined;
} else if (this.entityType === 'list') {
return this.originalPosition.sort !== undefined ||
this.originalSwimlaneId !== this.entityId;
} else if (this.entityType === 'card') {
return this.originalPosition.sort !== undefined ||
this.originalSwimlaneId !== this.entityId ||
this.originalListId !== this.entityId;
}
return false;
},
/**
* Get a human-readable description of the original position
*/
getOriginalPositionDescription() {
const position = this.originalPosition;
if (!position) return 'Unknown position';
if (this.entityType === 'swimlane') {
return `Original position: ${position.sort || 0}`;
} else if (this.entityType === 'list') {
const swimlaneInfo = this.originalSwimlaneId ?
` in swimlane ${this.originalSwimlaneId}` :
' in default swimlane';
return `Original position: ${position.sort || 0}${swimlaneInfo}`;
} else if (this.entityType === 'card') {
const swimlaneInfo = this.originalSwimlaneId ?
` in swimlane ${this.originalSwimlaneId}` :
' in default swimlane';
const listInfo = this.originalListId ?
` in list ${this.originalListId}` :
'';
return `Original position: ${position.sort || 0}${swimlaneInfo}${listInfo}`;
}
return 'Unknown position';
}
});
export default PositionHistory;