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"], "args": ["src/__start.ts"],
"env": { "env": {
"ELASTIC_URL": "http://localhost:9200", "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", "APM_SERVER_URL2": "http://localhost:8200",
"METRICS_CONSOLE": "false", "METRICS_CONSOLE": "false",
"METRICS_FILE": "${workspaceRoot}/metrics.txt", // Show metrics in console evert 30 seconds., "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", "SERVER_SECRET": "secret",
"ENABLE_CONSOLE": "true", "ENABLE_CONSOLE": "true",
"COLLABORATOR_URL": "ws://localhost:3078", "COLLABORATOR_URL": "ws://localhost:3078",

View File

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

View File

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

View File

@ -50,11 +50,21 @@ export async function createNewDraftForControlledDoc (
version: { major: number, minor: number }, version: { major: number, minor: number },
project: Ref<Project>, project: Ref<Project>,
newDraftDocId?: Ref<ControlledDocument> newDraftDocId?: Ref<ControlledDocument>
): Promise<Ref<ControlledDocument>> { ): Promise<{ success: boolean, id: Ref<ControlledDocument> }> {
const hierarchy = client.getHierarchy() const hierarchy = client.getHierarchy()
newDraftDocId = newDraftDocId ?? generateId() 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( const collaborativeDoc = getCollaborativeDocForDocument(
`DOC-${document.prefix}`, `DOC-${document.prefix}`,
document.seqNumber, document.seqNumber,
@ -76,7 +86,7 @@ export async function createNewDraftForControlledDoc (
impactedDocuments: [] impactedDocuments: []
} }
await createChangeControl(client, newCCId, newCCSpec, document.space) await createChangeControl(ops, newCCId, newCCSpec, document.space)
// TODO: copy labels? // TODO: copy labels?
const docSpec: AttachedData<ControlledDocument> = { const docSpec: AttachedData<ControlledDocument> = {
@ -110,7 +120,7 @@ export async function createNewDraftForControlledDoc (
}) })
if (meta !== undefined) { 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, project,
initial: project, initial: project,
document: newDraftDocId document: newDraftDocId
@ -119,7 +129,7 @@ export async function createNewDraftForControlledDoc (
console.error('project meta not found', project) console.error('project meta not found', project)
} }
await client.addCollection( await ops.addCollection(
document._class, document._class,
space, space,
document.attachedTo, document.attachedTo,
@ -131,7 +141,7 @@ export async function createNewDraftForControlledDoc (
if (hierarchy.hasMixin(document, documents.mixin.DocumentTemplate)) { if (hierarchy.hasMixin(document, documents.mixin.DocumentTemplate)) {
const template = hierarchy.as<Document, DocumentTemplate>(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, sequence: template.sequence,
docPrefix: template.docPrefix docPrefix: template.docPrefix
}) })
@ -143,7 +153,7 @@ export async function createNewDraftForControlledDoc (
if (newDraftDoc === undefined) { if (newDraftDoc === undefined) {
console.error(`Document #${newDraftDocId} not found`) console.error(`Document #${newDraftDocId} not found`)
} else { } else {
await createDocumentTraining(client, newDraftDoc, { await createDocumentTraining(ops, newDraftDoc, {
enabled: false, enabled: false,
roles: documentTraining.roles, roles: documentTraining.roles,
training: documentTraining.training, 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> { 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: () => {} } return { passed: true, onEnd: () => {} }
} }
// Wait for synchronized. // 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 => {} let onEnd = (): void => {}
// Put sync code // Put sync code
this.scopes.set( this.scopes.set(