mirror of
https://github.com/hcengineering/platform.git
synced 2026-10-01 05:55:09 +02:00
Merge 9522 9513 (#8103)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com> Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com> Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com> Signed-off-by: Andrey Sobolev <haiodo@gmail.com> Co-authored-by: Denis Bykhov <bykhov.denis@gmail.com> Co-authored-by: Alexander Onnikov <aonnikov@hardcoreeng.com> Co-authored-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
co-authored by
Denis Bykhov
Alexander Onnikov
Victor Ilyushchenko
parent
9eba1cdf07
commit
05f1d8395a
@@ -166,7 +166,7 @@ export async function createControlledDocMetadata (
|
||||
space,
|
||||
{
|
||||
documents: 0,
|
||||
title: `${prefix}-${seqNumber} ${specTitle}`
|
||||
title: `${specCode} ${specTitle}`
|
||||
},
|
||||
metaId
|
||||
)
|
||||
|
||||
@@ -156,17 +156,25 @@ export function isFolder (doc: ProjectDocument | undefined): boolean {
|
||||
return doc !== undefined && doc.document === documents.ids.Folder
|
||||
}
|
||||
|
||||
function getDocumentSortSequence (doc: ControlledDocument | undefined): number[] {
|
||||
return doc !== undefined ? [doc.seqNumber, doc.major, doc.minor, doc.createdOn ?? 0] : [0, 0, 0, 0]
|
||||
}
|
||||
|
||||
export function compareDocumentVersions (
|
||||
doc1: ControlledDocument | undefined,
|
||||
doc2: ControlledDocument | undefined
|
||||
): number {
|
||||
const s0 = getDocumentSortSequence(doc1)
|
||||
const s1 = getDocumentSortSequence(doc2)
|
||||
return s0.reduce((r, v, i) => (r !== 0 ? r : s1[i] - v), 0)
|
||||
}
|
||||
|
||||
function extractPresentableStateFromDocumentBundle (bundle: DocumentBundle, prjmeta: ProjectMeta): DocumentBundle {
|
||||
bundle = { ...bundle }
|
||||
|
||||
const person = getCurrentEmployee()
|
||||
const documentById = toIdMap(bundle.ControlledDocument)
|
||||
|
||||
const getSortSequence = (prjdoc: ProjectDocument): number[] => {
|
||||
const doc = documentById.get(prjdoc.document as Ref<ControlledDocument>)
|
||||
return doc !== undefined ? [doc.seqNumber, doc.major, doc.minor, doc.createdOn ?? 0] : [0, 0, 0, 0]
|
||||
}
|
||||
|
||||
const prjdoc = bundle.ProjectDocument.filter((prjdoc) => {
|
||||
if (prjdoc.attachedTo !== prjmeta._id) return false
|
||||
if (isFolder(prjdoc)) return true
|
||||
@@ -174,9 +182,10 @@ function extractPresentableStateFromDocumentBundle (bundle: DocumentBundle, prjm
|
||||
const isPublicState = doc?.state === DocumentState.Effective || doc?.state === DocumentState.Archived
|
||||
return doc !== undefined && (isPublicState || isCollaborator(doc, person))
|
||||
}).sort((a, b) => {
|
||||
const s0 = getSortSequence(a)
|
||||
const s1 = getSortSequence(b)
|
||||
return s0.reduce((r, v, i) => (r !== 0 ? r : s1[i] - v), 0)
|
||||
return compareDocumentVersions(
|
||||
documentById.get(a.document as Ref<ControlledDocument>),
|
||||
documentById.get(b.document as Ref<ControlledDocument>)
|
||||
)
|
||||
})[0]
|
||||
|
||||
const doc = prjdoc !== undefined ? documentById.get(prjdoc.document as Ref<ControlledDocument>) : undefined
|
||||
|
||||
Reference in New Issue
Block a user