mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 03:14:40 +03:00
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:
parent
655cf13229
commit
f87b0e264e
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@ -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",
|
||||
|
@ -48,6 +48,10 @@
|
||||
afterUpdate(adjustHeight)
|
||||
|
||||
function adjustHeight (): void {
|
||||
if (input == null) {
|
||||
return
|
||||
}
|
||||
|
||||
input.style.height = 'auto'
|
||||
input.style.height = `${input.scrollHeight + 2}px`
|
||||
}
|
||||
|
@ -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,6 +213,12 @@
|
||||
}
|
||||
|
||||
async function onCreateNewDraft (): Promise<void> {
|
||||
if (creating) {
|
||||
return
|
||||
}
|
||||
|
||||
creating = true
|
||||
try {
|
||||
if ($controlledDocument != null && $canCreateNewDraft && $documentLatestVersion != null) {
|
||||
const latest = $documentLatestVersion
|
||||
const version = { major: latest.major, minor: latest.minor + 1 }
|
||||
@ -219,15 +226,17 @@
|
||||
|
||||
if (project !== undefined) {
|
||||
try {
|
||||
const id = await createNewDraftForControlledDoc(
|
||||
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))
|
||||
}
|
||||
@ -237,6 +246,9 @@
|
||||
} else {
|
||||
console.warn('Unexpected document state', $documentState)
|
||||
}
|
||||
} finally {
|
||||
creating = false
|
||||
}
|
||||
}
|
||||
|
||||
async function onEditDocument (): Promise<void> {
|
||||
@ -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}
|
||||
|
@ -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> {
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user