parent
ddf9a32ea9
commit
ad67b9ba24
@ -1,9 +1,11 @@
|
|||||||
const BOARD = 'BOARD';
|
const BOARD = 'BOARD';
|
||||||
const LIST = 'LIST';
|
const LIST = 'LIST';
|
||||||
const CARD = 'CARD';
|
const CARD = 'CARD';
|
||||||
|
const TASK = 'TASK';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
BOARD,
|
BOARD,
|
||||||
LIST,
|
LIST,
|
||||||
CARD,
|
CARD,
|
||||||
|
TASK,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,20 @@
|
|||||||
|
import { createSelector } from 'redux-orm';
|
||||||
|
|
||||||
|
import orm from '../orm';
|
||||||
|
|
||||||
|
export const makeTaskByIdSelector = () =>
|
||||||
|
createSelector(
|
||||||
|
orm,
|
||||||
|
(_, id) => id,
|
||||||
|
({ Task }, id) => {
|
||||||
|
const taskModel = Task.withId(id);
|
||||||
|
|
||||||
|
if (!taskModel) {
|
||||||
|
return taskModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
return taskModel.ref;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const taskByIdSelector = makeTaskByIdSelector();
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
const POSITION_GAP = 65535;
|
||||||
|
|
||||||
|
module.exports.up = async (knex) => {
|
||||||
|
await knex.schema.table('task', (table) => {
|
||||||
|
/* Columns */
|
||||||
|
|
||||||
|
table.specificType('position', 'double precision');
|
||||||
|
|
||||||
|
/* Indexes */
|
||||||
|
|
||||||
|
table.index('position');
|
||||||
|
});
|
||||||
|
|
||||||
|
const tasks = await knex('task').orderBy(['card_id', 'id']);
|
||||||
|
|
||||||
|
let prevCardId;
|
||||||
|
let position;
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
|
for (task of tasks) {
|
||||||
|
if (task.card_id === prevCardId) {
|
||||||
|
position += POSITION_GAP;
|
||||||
|
} else {
|
||||||
|
prevCardId = task.card_id;
|
||||||
|
position = POSITION_GAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
await knex('task')
|
||||||
|
.update({
|
||||||
|
position,
|
||||||
|
})
|
||||||
|
.where('id', task.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return knex.schema.table('task', (table) => {
|
||||||
|
table.dropNullable('position');
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.down = async (knex) =>
|
||||||
|
knex.schema.table('task', (table) => {
|
||||||
|
table.dropColumn('position');
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue