mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-29 04:55:03 +02:00
UBERF-4786 (#4285)
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { Attribute, Class, IdMap, Ref, Status, generateId } from '@hcengineering/core'
|
||||
import { Class, IdMap, Ref, Status, generateId } from '@hcengineering/core'
|
||||
import { IntlString } from '@hcengineering/platform'
|
||||
import { DocPopup, createQuery, getClient } from '@hcengineering/presentation'
|
||||
import { Project, ProjectType, Task, getStates } from '@hcengineering/task'
|
||||
import { DocPopup, getClient } from '@hcengineering/presentation'
|
||||
import { Task, TaskType } from '@hcengineering/task'
|
||||
import { ObjectPresenter, statusStore } from '@hcengineering/view-resources'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import { typeStore } from '..'
|
||||
import task from '../plugin'
|
||||
import { taskTypeStore } from '..'
|
||||
|
||||
export let value: Task | Task[]
|
||||
export let width: 'medium' | 'large' | 'full' = 'medium'
|
||||
export let placeholder: IntlString
|
||||
export let ofAttribute: Ref<Attribute<Status>>
|
||||
export let _class: Ref<Class<Status>>
|
||||
export let embedded: boolean = false
|
||||
|
||||
@@ -43,35 +41,26 @@
|
||||
: undefined
|
||||
: value.status
|
||||
|
||||
$: _space = Array.isArray(value)
|
||||
? value.every((v) => v.space === (value as Array<Task>)[0].space)
|
||||
? value[0].space
|
||||
$: kind = Array.isArray(value)
|
||||
? value.every((v) => v.kind === (value as Array<Task>)[0].kind)
|
||||
? value[0].kind
|
||||
: undefined
|
||||
: value.space
|
||||
: value.kind
|
||||
|
||||
let project: Project | undefined
|
||||
|
||||
const query = createQuery()
|
||||
$: _space
|
||||
? query.query(task.class.Project, { _id: _space as Ref<Project> }, (res) => {
|
||||
project = res[0]
|
||||
})
|
||||
: (project = undefined)
|
||||
|
||||
function updateStatuses (
|
||||
space: Project | undefined,
|
||||
types: IdMap<ProjectType>,
|
||||
store: IdMap<Status>,
|
||||
allStatuses: Status[]
|
||||
): void {
|
||||
if (space === undefined) {
|
||||
statuses = allStatuses.filter((p) => p.ofAttribute === ofAttribute)
|
||||
function updateStatuses (taskTypes: IdMap<TaskType>, store: IdMap<Status>, kind: Ref<TaskType> | undefined): void {
|
||||
if (kind === undefined) {
|
||||
statuses = []
|
||||
} else {
|
||||
statuses = getStates(space, types, store)
|
||||
if (kind !== undefined) {
|
||||
const type = taskTypes.get(kind)
|
||||
if (type !== undefined) {
|
||||
statuses = type.statuses.map((p) => store.get(p)).filter((p) => p !== undefined) as Status[]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$: updateStatuses(project, $typeStore, $statusStore.byId, $statusStore.array)
|
||||
$: updateStatuses($taskTypeStore, $statusStore.byId, kind)
|
||||
|
||||
let statuses: Status[] = []
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<!--
|
||||
// Copyright © 2023 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 { Ref, generateId } from '@hcengineering/core'
|
||||
import { Card, getClient } from '@hcengineering/presentation'
|
||||
import { ProjectTypeDescriptor, createProjectType } from '@hcengineering/task'
|
||||
import { DropdownLabelsIntl, EditBox, ToggleWithLabel } from '@hcengineering/ui'
|
||||
import { createEventDispatcher } from 'svelte'
|
||||
import task from '../../plugin'
|
||||
|
||||
const client = getClient()
|
||||
|
||||
let name: string = ''
|
||||
let classic: boolean = true
|
||||
|
||||
let descriptor: ProjectTypeDescriptor | undefined = undefined
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
async function createType (): Promise<void> {
|
||||
if (descriptor === undefined) {
|
||||
return
|
||||
}
|
||||
await createProjectType(
|
||||
client,
|
||||
{
|
||||
name,
|
||||
descriptor: descriptor._id,
|
||||
description: '',
|
||||
tasks: [],
|
||||
classic
|
||||
},
|
||||
[],
|
||||
generateId()
|
||||
)
|
||||
dispatch('close')
|
||||
}
|
||||
|
||||
const descriptors = client.getModel().findAllSync(task.class.ProjectTypeDescriptor, {})
|
||||
const items = descriptors.map((it) => ({
|
||||
label: it.name,
|
||||
id: it._id
|
||||
}))
|
||||
|
||||
function selectType (evt: CustomEvent<Ref<ProjectTypeDescriptor>>): void {
|
||||
descriptor = descriptors.find((it) => it._id === evt.detail)
|
||||
}
|
||||
</script>
|
||||
|
||||
<Card
|
||||
label={task.string.CreateProjectType}
|
||||
canSave={name.trim().length > 0 && descriptor !== undefined}
|
||||
okAction={createType}
|
||||
on:close={() => {
|
||||
dispatch('close')
|
||||
}}
|
||||
on:changeContent
|
||||
>
|
||||
<div class="flex-col flex-gap-2">
|
||||
<EditBox bind:value={name} placeholder={task.string.ProjectType} />
|
||||
<DropdownLabelsIntl {items} on:selected={selectType} />
|
||||
<ToggleWithLabel label={task.string.ClassicProject} bind:on={classic} />
|
||||
</div>
|
||||
</Card>
|
||||
@@ -14,46 +14,12 @@
|
||||
// limitations under the License.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { generateId } from '@hcengineering/core'
|
||||
import { Button, IconAdd, Menu, getEventPopupPositionElement, showPopup } from '@hcengineering/ui'
|
||||
import { Button, IconAdd, showPopup } from '@hcengineering/ui'
|
||||
import CreateProjectType from './CreateProjectType.svelte'
|
||||
|
||||
import { translate } from '@hcengineering/platform'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import task, { ProjectTypeDescriptor, createProjectType } from '@hcengineering/task'
|
||||
|
||||
const client = getClient()
|
||||
|
||||
async function createType (descriptor: ProjectTypeDescriptor): Promise<void> {
|
||||
const descriptorName = await translate(descriptor.name, {})
|
||||
|
||||
await createProjectType(
|
||||
client,
|
||||
{
|
||||
name: `New ${descriptorName} project type`,
|
||||
descriptor: descriptor._id,
|
||||
description: '',
|
||||
tasks: []
|
||||
},
|
||||
[],
|
||||
generateId()
|
||||
)
|
||||
}
|
||||
|
||||
async function chooseProjectType (evt: MouseEvent): Promise<void> {
|
||||
const descriptors = client.getModel().findAllSync(task.class.ProjectTypeDescriptor, {})
|
||||
showPopup(
|
||||
Menu,
|
||||
{
|
||||
actions: descriptors.map((it) => ({
|
||||
label: it.name,
|
||||
action: () => {
|
||||
void createType(it)
|
||||
}
|
||||
}))
|
||||
},
|
||||
getEventPopupPositionElement(evt)
|
||||
)
|
||||
function open () {
|
||||
showPopup(CreateProjectType, {}, 'top')
|
||||
}
|
||||
</script>
|
||||
|
||||
<Button id="new-project-type" icon={IconAdd} kind={'link'} size="small" on:click={chooseProjectType} />
|
||||
<Button id="new-project-type" icon={IconAdd} kind={'link'} size="small" on:click={open} />
|
||||
|
||||
Reference in New Issue
Block a user