EZQMS-1268: Doc ID changes editable phases (#7834)

* EZQMS-1268: Doc ID changes editable phases

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>

* fixed edit condition & added category edit handler

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>

* fixed import

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>

---------

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
Victor Ilyushchenko 2025-01-30 12:29:01 +03:00 committed by GitHub
parent 9c3a1cc641
commit 78d69ed272
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 94 additions and 7 deletions

View File

@ -0,0 +1,48 @@
<!--
// Copyright © 2025 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
-->
<script lang="ts">
import documents, { DocumentCategory, DocumentTemplate } from '@hcengineering/controlled-documents'
import { createQuery, getClient } from '@hcengineering/presentation'
import { createEventDispatcher } from 'svelte'
import { Ref } from '@hcengineering/core'
import { DropdownLabelsPopup } from '@hcengineering/ui'
export let object: DocumentTemplate
const client = getClient()
const dispatch = createEventDispatcher()
let categories: DocumentCategory[] = []
const query = createQuery()
query.query(documents.class.DocumentCategory, {}, (res) => {
categories = res
})
async function handleSubmit (category: Ref<DocumentCategory>): Promise<void> {
await client.update(object, { category })
dispatch('close')
}
</script>
{#if object}
<DropdownLabelsPopup
items={categories.map((cat) => ({ id: cat._id, label: cat.title }))}
selected={object.category}
on:close={(e) => handleSubmit(e.detail)}
/>
{/if}

View File

@ -5,21 +5,41 @@
import { getClient } from '@hcengineering/presentation'
import { Label } from '@hcengineering/ui'
import view from '@hcengineering/view'
import { createEventDispatcher } from 'svelte'
export let value: Ref<DocumentCategory> | undefined
export let editable: boolean = false
let category: DocumentCategory | undefined = undefined
const client = getClient()
const dispatch = createEventDispatcher()
$: if (value) {
client.findOne(documents.class.DocumentCategory, { _id: value }).then((result) => {
category = result
})
}
function handleClick (event: MouseEvent): void {
if (!editable) {
return
}
dispatch('edit', event)
}
</script>
{#if category}
{category.title}
<a
class="flex-presenter inline-presenter noBold"
class:no-underline={!editable}
class:cursor-inherit={!editable}
href={undefined}
on:click={handleClick}
>
{category.title}
</a>
{:else}
<Label label={view.string.LabelNA} />
{/if}

View File

@ -22,6 +22,7 @@
import documentsRes from '../../../plugin'
import {
$documentAllVersionsDescSorted as documentAllVersions,
$controlledDocument as controlledDocument,
$isEditable as isEditable,
$projectRef as projectRef
@ -41,6 +42,7 @@
import AbstractEditor from '../editors/AbstractEditor.svelte'
import DocumentFlatHierarchy from './info/DocumentFlatHierarchy.svelte'
import DocumentPrefixPresenter from '../presenters/DocumentPrefixPresenter.svelte'
import ChangeCategoryPopup from '../popups/ChangeCategoryPopup.svelte'
const client = getClient()
const hierarchy = client.getHierarchy()
@ -58,9 +60,20 @@
)
}
$: isDocCodeEditable =
$isEditable && $controlledDocument != null && $controlledDocument.major === 0 && $controlledDocument.minor === 0
$: isDocPrefixEditable = isDocCodeEditable
function handleCategoryEdit (event: MouseEvent): void {
event?.preventDefault()
event?.stopPropagation()
showPopup(
ChangeCategoryPopup,
{
object: $controlledDocument
},
eventToHTMLElement(event)
)
}
$: isEditableDraft = $isEditable && $controlledDocument != null && $documentAllVersions.length === 1
$: isTemplate =
$controlledDocument != null && hierarchy.hasMixin($controlledDocument, documents.mixin.DocumentTemplate)
@ -81,7 +94,7 @@
value={$controlledDocument}
isRegular
disableLink
editable={isDocCodeEditable}
editable={isEditableDraft}
on:edit={(e) => {
handleCodeEdit(e.detail)
}}
@ -89,7 +102,13 @@
</DocumentInfo>
<DocumentInfo label={documentsRes.string.Category}>
<CategoryPresenter value={$controlledDocument.category} />
<CategoryPresenter
value={$controlledDocument.category}
editable={isEditableDraft}
on:edit={(e) => {
handleCategoryEdit(e.detail)
}}
/>
</DocumentInfo>
{#if !isTemplate}
@ -100,7 +119,7 @@
{#if isTemplate}
<DocumentInfo label={documentsRes.string.DocumentPrefix}>
<DocumentPrefixPresenter value={asTemplate} editable={isDocPrefixEditable} />
<DocumentPrefixPresenter value={asTemplate} editable={isEditableDraft} />
</DocumentInfo>
{/if}