ezqms-1193: fix issues with drafting a controlled doc version from effective (#6535)

Signed-off-by: Alexey Zinoviev <alexey.zinoviev@xored.com>
This commit is contained in:
Alexey Zinoviev 2024-09-11 20:08:14 +04:00 committed by GitHub
parent 655cf13229
commit f87b0e264e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 70 additions and 31 deletions

4
.vscode/launch.json vendored
View File

@ -59,11 +59,11 @@
"args": ["src/__start.ts"],
"env": {
"ELASTIC_URL": "http://localhost:9200",
"MONGO_URL": "postgresql://postgres:example@localhost:5432;mongodb://localhost:27017",
"MONGO_URL": "mongodb://localhost:27017",
"APM_SERVER_URL2": "http://localhost:8200",
"METRICS_CONSOLE": "false",
"METRICS_FILE": "${workspaceRoot}/metrics.txt", // Show metrics in console evert 30 seconds.,
"STORAGE_CONFIG": "minio|localhost:9000?accessKey=minioadmin&secretKey=minioadmin",
"STORAGE_CONFIG": "minio|localhost?accessKey=minioadmin&secretKey=minioadmin",
"SERVER_SECRET": "secret",
"ENABLE_CONSOLE": "true",
"COLLABORATOR_URL": "ws://localhost:3078",

View File

@ -48,6 +48,10 @@
afterUpdate(adjustHeight)
function adjustHeight (): void {
if (input == null) {
return
}
input.style.height = 'auto'
input.style.height = `${input.scrollHeight + 2}px`
}

View File

@ -96,6 +96,7 @@
let innerWidth: number
let isTitlePressed: boolean = false
let creating: boolean = false
const notificationClient = getResource(notification.function.GetInboxNotificationsClient).then((res) => res())
@ -212,30 +213,41 @@
}
async function onCreateNewDraft (): Promise<void> {
if ($controlledDocument != null && $canCreateNewDraft && $documentLatestVersion != null) {
const latest = $documentLatestVersion
const version = { major: latest.major, minor: latest.minor + 1 }
const project = await getLatestProjectId($controlledDocument.space)
if (creating) {
return
}
if (project !== undefined) {
try {
const id = await createNewDraftForControlledDoc(
client,
$controlledDocument,
$controlledDocument.space,
version,
project
)
const loc = getProjectDocumentLink(id, project)
navigate(loc)
} catch (err) {
await setPlatformStatus(unknownError(err))
creating = true
try {
if ($controlledDocument != null && $canCreateNewDraft && $documentLatestVersion != null) {
const latest = $documentLatestVersion
const version = { major: latest.major, minor: latest.minor + 1 }
const project = await getLatestProjectId($controlledDocument.space)
if (project !== undefined) {
try {
const { id, success } = await createNewDraftForControlledDoc(
client,
$controlledDocument,
$controlledDocument.space,
version,
project
)
if (success) {
const loc = getProjectDocumentLink(id, project)
navigate(loc)
}
} catch (err) {
await setPlatformStatus(unknownError(err))
}
} else {
console.warn('No document project found for space', $controlledDocument.space)
}
} else {
console.warn('No document project found for space', $controlledDocument.space)
console.warn('Unexpected document state', $documentState)
}
} else {
console.warn('Unexpected document state', $documentState)
} finally {
creating = false
}
}
@ -349,7 +361,13 @@
{/if}
{#if $canCreateNewDraft}
<Button label={documentRes.string.CreateNewDraft} kind="regular" on:click={onCreateNewDraft} />
<Button
label={documentRes.string.CreateNewDraft}
kind="regular"
loading={creating}
disabled={creating}
on:click={onCreateNewDraft}
/>
{:else if $canCreateNewSnapshot}
<Button label={documentRes.string.EditDocument} kind="regular" on:click={onEditDocument} />
{/if}

View File

@ -50,11 +50,21 @@ export async function createNewDraftForControlledDoc (
version: { major: number, minor: number },
project: Ref<Project>,
newDraftDocId?: Ref<ControlledDocument>
): Promise<Ref<ControlledDocument>> {
): Promise<{ success: boolean, id: Ref<ControlledDocument> }> {
const hierarchy = client.getHierarchy()
newDraftDocId = newDraftDocId ?? generateId()
const ops = client.apply(document.code)
const notMatchQuery = {
...(document.template != null ? { template: document.template } : { template: { $exists: false } }),
seqNumber: document.seqNumber,
state: DocumentState.Draft
}
ops.notMatch(documents.class.Document, notMatchQuery)
const collaborativeDoc = getCollaborativeDocForDocument(
`DOC-${document.prefix}`,
document.seqNumber,
@ -76,7 +86,7 @@ export async function createNewDraftForControlledDoc (
impactedDocuments: []
}
await createChangeControl(client, newCCId, newCCSpec, document.space)
await createChangeControl(ops, newCCId, newCCSpec, document.space)
// TODO: copy labels?
const docSpec: AttachedData<ControlledDocument> = {
@ -110,7 +120,7 @@ export async function createNewDraftForControlledDoc (
})
if (meta !== undefined) {
await client.addCollection(documents.class.ProjectDocument, meta.space, meta._id, meta._class, 'documents', {
await ops.addCollection(documents.class.ProjectDocument, meta.space, meta._id, meta._class, 'documents', {
project,
initial: project,
document: newDraftDocId
@ -119,7 +129,7 @@ export async function createNewDraftForControlledDoc (
console.error('project meta not found', project)
}
await client.addCollection(
await ops.addCollection(
document._class,
space,
document.attachedTo,
@ -131,7 +141,7 @@ export async function createNewDraftForControlledDoc (
if (hierarchy.hasMixin(document, documents.mixin.DocumentTemplate)) {
const template = hierarchy.as<Document, DocumentTemplate>(document, documents.mixin.DocumentTemplate)
await client.updateMixin(newDraftDocId, documents.class.Document, space, documents.mixin.DocumentTemplate, {
await ops.updateMixin(newDraftDocId, documents.class.Document, space, documents.mixin.DocumentTemplate, {
sequence: template.sequence,
docPrefix: template.docPrefix
})
@ -143,7 +153,7 @@ export async function createNewDraftForControlledDoc (
if (newDraftDoc === undefined) {
console.error(`Document #${newDraftDocId} not found`)
} else {
await createDocumentTraining(client, newDraftDoc, {
await createDocumentTraining(ops, newDraftDoc, {
enabled: false,
roles: documentTraining.roles,
training: documentTraining.training,
@ -154,7 +164,9 @@ export async function createNewDraftForControlledDoc (
}
}
return newDraftDocId
const res = await ops.commit()
return { success: res.result, id: newDraftDocId }
}
export async function createDocumentSnapshotAndEdit (client: TxOperations, document: ControlledDocument): Promise<void> {

View File

@ -97,7 +97,12 @@ export class ApplyTxMiddleware extends BaseMiddleware implements Middleware {
return { passed: true, onEnd: () => {} }
}
// Wait for synchronized.
;(await this.scopes.get(applyIf.scope)) ?? Promise.resolve()
const scopePromise = this.scopes.get(applyIf.scope)
if (scopePromise != null) {
await scopePromise
}
let onEnd = (): void => {}
// Put sync code
this.scopes.set(