mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-29 19:56:18 +00:00
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:
parent
9c3a1cc641
commit
78d69ed272
@ -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}
|
@ -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}
|
||||
|
@ -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}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user