mirror of
https://github.com/hcengineering/platform.git
synced 2025-01-08 21:27:45 +03:00
Fix IssueStatus order (#2038)
Signed-off-by: Dvinyanin Alexandr <dvinyanin.alexandr@gmail.com>
This commit is contained in:
parent
6a7fa08fbd
commit
bb187fce40
@ -291,7 +291,7 @@ export function createModel (builder: Builder): void {
|
||||
icon: tracker.icon.CategoryBacklog,
|
||||
color: 0,
|
||||
defaultStatusName: 'Backlog',
|
||||
order: 0
|
||||
order: 2
|
||||
},
|
||||
tracker.issueStatusCategory.Backlog
|
||||
)
|
||||
@ -317,7 +317,7 @@ export function createModel (builder: Builder): void {
|
||||
icon: tracker.icon.CategoryStarted,
|
||||
color: 2,
|
||||
defaultStatusName: 'In Progress',
|
||||
order: 2
|
||||
order: 0
|
||||
},
|
||||
tracker.issueStatusCategory.Started
|
||||
)
|
||||
|
@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import core, { Doc, generateId, Ref, TxOperations } from '@anticrm/core'
|
||||
import core, { Doc, generateId, Ref, SortingOrder, TxOperations, TxResult } from '@anticrm/core'
|
||||
import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@anticrm/model'
|
||||
import { IssueStatus, IssueStatusCategory, Team, genRanks, Issue } from '@anticrm/tracker'
|
||||
import { DOMAIN_TRACKER } from '.'
|
||||
@ -80,7 +80,11 @@ async function createDefaultTeam (tx: TxOperations): Promise<void> {
|
||||
// Create new if not deleted by customers.
|
||||
if (current === undefined && currentDeleted === undefined) {
|
||||
const defaultStatusId: Ref<IssueStatus> = generateId()
|
||||
const categories = await tx.findAll(tracker.class.IssueStatusCategory, {})
|
||||
const categories = await tx.findAll(
|
||||
tracker.class.IssueStatusCategory,
|
||||
{},
|
||||
{ sort: { order: SortingOrder.Ascending } }
|
||||
)
|
||||
|
||||
await tx.createDoc<Team>(
|
||||
tracker.class.Team,
|
||||
@ -102,11 +106,35 @@ async function createDefaultTeam (tx: TxOperations): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function fixTeamIssueStatusesOrder (tx: TxOperations, team: Team): Promise<TxResult> {
|
||||
const statuses = await tx.findAll(
|
||||
tracker.class.IssueStatus,
|
||||
{ attachedTo: team._id },
|
||||
{ lookup: { category: tracker.class.IssueStatusCategory } }
|
||||
)
|
||||
statuses.sort((a, b) => (a.$lookup?.category?.order ?? 0) - (b.$lookup?.category?.order ?? 0))
|
||||
const issueStatusRanks = genRanks(statuses.length)
|
||||
return statuses.map((status) => {
|
||||
const rank = issueStatusRanks.next().value
|
||||
if (rank === undefined || status.rank === rank) return undefined
|
||||
return tx.update(status, { rank })
|
||||
})
|
||||
}
|
||||
|
||||
async function fixTeamsIssueStatusesOrder (tx: TxOperations): Promise<void> {
|
||||
const teams = await tx.findAll(tracker.class.Team, {})
|
||||
await Promise.all(teams.map((team) => fixTeamIssueStatusesOrder(tx, team)))
|
||||
}
|
||||
|
||||
async function upgradeTeamIssueStatuses (tx: TxOperations): Promise<void> {
|
||||
const teams = await tx.findAll(tracker.class.Team, { issueStatuses: undefined })
|
||||
|
||||
if (teams.length > 0) {
|
||||
const categories = await tx.findAll(tracker.class.IssueStatusCategory, {})
|
||||
const categories = await tx.findAll(
|
||||
tracker.class.IssueStatusCategory,
|
||||
{},
|
||||
{ sort: { order: SortingOrder.Ascending } }
|
||||
)
|
||||
|
||||
for (const team of teams) {
|
||||
const defaultStatusId: Ref<IssueStatus> = generateId()
|
||||
@ -232,6 +260,7 @@ async function createDefaults (tx: TxOperations): Promise<void> {
|
||||
|
||||
async function upgradeTeams (tx: TxOperations): Promise<void> {
|
||||
await upgradeTeamIssueStatuses(tx)
|
||||
await fixTeamsIssueStatusesOrder(tx)
|
||||
}
|
||||
|
||||
async function upgradeIssues (tx: TxOperations): Promise<void> {
|
||||
|
@ -43,7 +43,7 @@
|
||||
tracker.class.IssueStatus,
|
||||
{ attachedTo: currentSpace },
|
||||
(result) => {
|
||||
statuses = result
|
||||
statuses = [...result]
|
||||
},
|
||||
{
|
||||
lookup: { category: tracker.class.IssueStatusCategory },
|
||||
|
@ -48,15 +48,17 @@
|
||||
await client.update(value, { status: newStatus })
|
||||
}
|
||||
}
|
||||
$: query = '_id' in value ? { atachedTo: value.space } : {}
|
||||
client
|
||||
.findAll(tracker.class.IssueStatus, query, {
|
||||
lookup: { category: tracker.class.IssueStatusCategory },
|
||||
sort: { order: SortingOrder.Ascending }
|
||||
})
|
||||
.then((result) => {
|
||||
if (!statuses) statuses = result
|
||||
})
|
||||
$: if (!statuses) {
|
||||
const query = '_id' in value ? { attachedTo: value.space } : {}
|
||||
client
|
||||
.findAll(tracker.class.IssueStatus, query, {
|
||||
lookup: { category: tracker.class.IssueStatusCategory },
|
||||
sort: { rank: SortingOrder.Ascending }
|
||||
})
|
||||
.then((result) => {
|
||||
statuses = result
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if value && statuses}
|
||||
|
Loading…
Reference in New Issue
Block a user