diff --git a/dev/generator/src/issues.ts b/dev/generator/src/issues.ts index 31f3af85b7..8bd619702a 100644 --- a/dev/generator/src/issues.ts +++ b/dev/generator/src/issues.ts @@ -65,11 +65,7 @@ export async function generateIssues ( } async function genIssue (client: TxOperations): Promise { - const lastOne = await client.findOne( - tracker.class.Issue, - { status: object.status }, - { sort: { rank: SortingOrder.Descending } } - ) + const lastOne = await client.findOne(tracker.class.Issue, {}, { sort: { rank: SortingOrder.Descending } }) const incResult = await client.updateDoc( tracker.class.Team, core.space.Space, diff --git a/models/tracker/src/migration.ts b/models/tracker/src/migration.ts index 432f3a811c..3664304607 100644 --- a/models/tracker/src/migration.ts +++ b/models/tracker/src/migration.ts @@ -13,10 +13,20 @@ // limitations under the License. // -import core, { Doc, DocumentUpdate, generateId, Ref, SortingOrder, TxOperations, TxResult } from '@hcengineering/core' +import core, { + Doc, + DocumentUpdate, + DOMAIN_TX, + generateId, + Ref, + SortingOrder, + TxOperations, + TxResult +} from '@hcengineering/core' import { createOrUpdate, MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@hcengineering/model' import tags from '@hcengineering/tags' import { + calcRank, genRanks, Issue, IssueStatus, @@ -327,6 +337,45 @@ async function createDefaults (tx: TxOperations): Promise { ) } +async function fillRank (client: MigrationClient): Promise { + const docs = await client.find(DOMAIN_TRACKER, { + _class: tracker.class.Issue, + rank: '' + }) + let last = ( + await client.find( + DOMAIN_TRACKER, + { + _class: tracker.class.Issue, + rank: { $ne: '' } + }, + { + sort: { rank: SortingOrder.Descending }, + limit: 1 + } + ) + )[0] + for (const doc of docs) { + const rank = calcRank(last) + await client.update( + DOMAIN_TRACKER, + { + _id: doc._id + }, + { + rank + } + ) + await client.update( + DOMAIN_TX, + { 'tx.objectId': doc._id, 'tx._class': core.class.TxCreateDoc }, + { 'tx.attributes.rank': rank } + ) + doc.rank = rank + last = doc + } +} + async function upgradeTeams (tx: TxOperations): Promise { await upgradeTeamIssueStatuses(tx) await fixTeamsIssueStatusesOrder(tx) @@ -375,6 +424,7 @@ export const trackerOperation: MigrateOperation = { ) await Promise.all([migrateIssueProjects(client), migrateParentIssues(client)]) await migrateIssueParentInfo(client) + await fillRank(client) }, async upgrade (client: MigrationUpgradeClient): Promise { const tx = new TxOperations(client, core.account.System) diff --git a/plugins/board-resources/src/components/CreateCard.svelte b/plugins/board-resources/src/components/CreateCard.svelte index c9b5cc4f3c..43e4614935 100644 --- a/plugins/board-resources/src/components/CreateCard.svelte +++ b/plugins/board-resources/src/components/CreateCard.svelte @@ -49,11 +49,7 @@ throw new Error('sequence object not found') } - const lastOne = await client.findOne( - board.class.Card, - { state: state._id }, - { sort: { rank: SortingOrder.Descending } } - ) + const lastOne = await client.findOne(board.class.Card, {}, { sort: { rank: SortingOrder.Descending } }) const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true) const value: AttachedData = { diff --git a/plugins/board-resources/src/components/KanbanView.svelte b/plugins/board-resources/src/components/KanbanView.svelte index 5a76ffa3f9..cd9610fab3 100644 --- a/plugins/board-resources/src/components/KanbanView.svelte +++ b/plugins/board-resources/src/components/KanbanView.svelte @@ -70,7 +70,7 @@ const client = getClient() async function addItem (title: any) { - const lastOne = await client.findOne(task.class.State, { space }, { sort: { rank: SortingOrder.Descending } }) + const lastOne = await client.findOne(task.class.State, {}, { sort: { rank: SortingOrder.Descending } }) await client.createDoc(task.class.State, space, { title, color: 9, diff --git a/plugins/board-resources/src/components/add-card/AddCard.svelte b/plugins/board-resources/src/components/add-card/AddCard.svelte index 244cfb9600..148578542a 100644 --- a/plugins/board-resources/src/components/add-card/AddCard.svelte +++ b/plugins/board-resources/src/components/add-card/AddCard.svelte @@ -36,11 +36,7 @@ throw new Error('sequence object not found') } - const lastOne = await client.findOne( - board.class.Card, - { state: state._id }, - { sort: { rank: SortingOrder.Descending } } - ) + const lastOne = await client.findOne(board.class.Card, {}, { sort: { rank: SortingOrder.Descending } }) const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true) const value: AttachedData = { diff --git a/plugins/board-resources/src/utils/CardUtils.ts b/plugins/board-resources/src/utils/CardUtils.ts index 956abd1d1e..b04c9e8fd5 100644 --- a/plugins/board-resources/src/utils/CardUtils.ts +++ b/plugins/board-resources/src/utils/CardUtils.ts @@ -24,7 +24,7 @@ export async function createCard ( throw new Error('sequence object not found') } - const lastOne = await client.findOne(board.class.Card, { state }, { sort: { rank: SortingOrder.Descending } }) + const lastOne = await client.findOne(board.class.Card, {}, { sort: { rank: SortingOrder.Descending } }) const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true) const value: AttachedData = { diff --git a/plugins/lead-resources/src/components/CreateLead.svelte b/plugins/lead-resources/src/components/CreateLead.svelte index 10247aab73..66bb1f108f 100644 --- a/plugins/lead-resources/src/components/CreateLead.svelte +++ b/plugins/lead-resources/src/components/CreateLead.svelte @@ -63,11 +63,7 @@ throw new Error('sequence object not found') } - const lastOne = await client.findOne( - lead.class.Lead, - { state: state._id }, - { sort: { rank: SortingOrder.Descending } } - ) + const lastOne = await client.findOne(lead.class.Lead, {}, { sort: { rank: SortingOrder.Descending } }) const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true) const value: AttachedData = { diff --git a/plugins/recruit-resources/src/components/CreateApplication.svelte b/plugins/recruit-resources/src/components/CreateApplication.svelte index 3f0d05d251..8865b2ae60 100644 --- a/plugins/recruit-resources/src/components/CreateApplication.svelte +++ b/plugins/recruit-resources/src/components/CreateApplication.svelte @@ -116,11 +116,7 @@ throw new Error('sequence object not found') } - const lastOne = await client.findOne( - recruit.class.Applicant, - { state: state._id }, - { sort: { rank: SortingOrder.Descending } } - ) + const lastOne = await client.findOne(recruit.class.Applicant, {}, { sort: { rank: SortingOrder.Descending } }) const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true) const candidateInstance = await client.findOne(contact.class.Person, { _id: _candidate }) diff --git a/plugins/recruit-resources/src/components/CreateVacancy.svelte b/plugins/recruit-resources/src/components/CreateVacancy.svelte index 68d1ec8030..c7fa0e8c09 100644 --- a/plugins/recruit-resources/src/components/CreateVacancy.svelte +++ b/plugins/recruit-resources/src/components/CreateVacancy.svelte @@ -15,11 +15,11 @@