Workslot fixes (#7084)
Some checks are pending
CI / build (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions

This commit is contained in:
Denis Bykhov 2024-11-02 08:23:08 +05:00 committed by GitHub
parent 01350d870d
commit c190b1c079
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 71 additions and 28 deletions

View File

@ -21,7 +21,7 @@ import { type Resource } from '@hcengineering/platform'
import serverCore, { type TriggerControl } from '@hcengineering/server-core' import serverCore, { type TriggerControl } from '@hcengineering/server-core'
import tracker from '@hcengineering/tracker' import tracker from '@hcengineering/tracker'
import serverTime, { type ToDoFactory, type OnToDo } from '@hcengineering/server-time' import serverTime, { type ToDoFactory, type OnToDo } from '@hcengineering/server-time'
import { type ToDo, type WorkSlot } from '@hcengineering/time' import time, { type ToDo, type WorkSlot } from '@hcengineering/time'
@Mixin(serverTime.mixin.ToDoFactory, core.class.Class) @Mixin(serverTime.mixin.ToDoFactory, core.class.Class)
export class TToDoFactory extends TClass implements ToDoFactory { export class TToDoFactory extends TClass implements ToDoFactory {
@ -45,6 +45,7 @@ export function createModel (builder: Builder): void {
trigger: serverTime.trigger.OnToDoUpdate, trigger: serverTime.trigger.OnToDoUpdate,
txMatch: { txMatch: {
_class: core.class.TxCollectionCUD, _class: core.class.TxCollectionCUD,
'tx.objectClass': time.class.ToDo,
'tx._class': core.class.TxUpdateDoc 'tx._class': core.class.TxUpdateDoc
} }
}) })
@ -53,6 +54,7 @@ export function createModel (builder: Builder): void {
trigger: serverTime.trigger.OnToDoRemove, trigger: serverTime.trigger.OnToDoRemove,
txMatch: { txMatch: {
_class: core.class.TxCollectionCUD, _class: core.class.TxCollectionCUD,
'tx.objectClass': time.class.ToDo,
'tx._class': core.class.TxRemoveDoc 'tx._class': core.class.TxRemoveDoc
} }
}) })
@ -61,6 +63,7 @@ export function createModel (builder: Builder): void {
trigger: serverTime.trigger.OnToDoCreate, trigger: serverTime.trigger.OnToDoCreate,
txMatch: { txMatch: {
_class: core.class.TxCollectionCUD, _class: core.class.TxCollectionCUD,
'tx.objectClass': time.class.ToDo,
'tx._class': core.class.TxCreateDoc 'tx._class': core.class.TxCreateDoc
}, },
isAsync: true isAsync: true
@ -70,10 +73,20 @@ export function createModel (builder: Builder): void {
trigger: serverTime.trigger.OnWorkSlotCreate, trigger: serverTime.trigger.OnWorkSlotCreate,
txMatch: { txMatch: {
_class: core.class.TxCollectionCUD, _class: core.class.TxCollectionCUD,
'tx.objectClass': time.class.WorkSlot,
'tx._class': core.class.TxCreateDoc 'tx._class': core.class.TxCreateDoc
} }
}) })
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverTime.trigger.OnWorkSlotUpdate,
txMatch: {
_class: core.class.TxCollectionCUD,
'tx.objectClass': time.class.WorkSlot,
'tx._class': core.class.TxUpdateDoc
}
})
builder.mixin(tracker.class.Issue, core.class.Class, serverTime.mixin.ToDoFactory, { builder.mixin(tracker.class.Issue, core.class.Class, serverTime.mixin.ToDoFactory, {
factory: serverTime.function.IssueToDoFactory factory: serverTime.function.IssueToDoFactory
}) })

View File

@ -16,8 +16,8 @@
import { createQuery } from '@hcengineering/presentation' import { createQuery } from '@hcengineering/presentation'
import { Label } from '@hcengineering/ui' import { Label } from '@hcengineering/ui'
import { ToDo, WorkSlot } from '@hcengineering/time' import { ToDo, WorkSlot } from '@hcengineering/time'
import time from '../plugin'
import ToDoPresenter from './ToDoPresenter.svelte' import ToDoPresenter from './ToDoPresenter.svelte'
import calendar from '@hcengineering/calendar'
export let event: WorkSlot export let event: WorkSlot
export let oneRow: boolean = false export let oneRow: boolean = false
@ -26,13 +26,15 @@
let todo: ToDo let todo: ToDo
const query = createQuery() const query = createQuery()
$: query.query(event.attachedToClass, { _id: event.attachedTo }, (res) => { $: !hideDetails
? query.query(event.attachedToClass, { _id: event.attachedTo }, (res) => {
todo = res[0] todo = res[0]
}) })
: query.unsubscribe()
</script> </script>
{#if hideDetails} {#if hideDetails}
<Label label={time.string.WorkSlot} /> <Label label={calendar.string.Busy} />
{:else if todo} {:else if todo}
<ToDoPresenter value={todo} withoutSpace={oneRow} /> <ToDoPresenter value={todo} withoutSpace={oneRow} />
{/if} {/if}

View File

@ -85,20 +85,19 @@ export async function applicationTextPresenter (doc: Doc, control: TriggerContro
* @public * @public
*/ */
export async function OnRecruitUpdate (tx: Tx, control: TriggerControl): Promise<Tx[]> { export async function OnRecruitUpdate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
const actualTx = TxProcessor.extractTx(tx) const actualTx = TxProcessor.extractTx(tx) as TxCUD<Doc>
const cud = actualTx as TxCUD<Doc> if (!control.hierarchy.isDerived(actualTx.objectClass, recruit.class.Vacancy)) {
if (!control.hierarchy.isDerived(cud.objectClass, recruit.class.Vacancy)) {
return [] return []
} }
const res: Tx[] = [] const res: Tx[] = []
if (actualTx._class === core.class.TxCreateDoc) { if (actualTx._class === core.class.TxCreateDoc) {
handleVacancyCreate(control, cud, actualTx, res) handleVacancyCreate(control, actualTx, res)
} else if (actualTx._class === core.class.TxUpdateDoc) { } else if (actualTx._class === core.class.TxUpdateDoc) {
await handleVacancyUpdate(control, cud, res) await handleVacancyUpdate(control, actualTx, res)
} else if (actualTx._class === core.class.TxRemoveDoc) { } else if (actualTx._class === core.class.TxRemoveDoc) {
await handleVacancyRemove(control, cud, actualTx) handleVacancyRemove(control, actualTx, res)
} }
return res return res
} }
@ -156,16 +155,13 @@ async function handleVacancyUpdate (control: TriggerControl, cud: TxCUD<Doc>, re
} }
} }
async function handleVacancyRemove (control: TriggerControl, cud: TxCUD<Doc>, actualTx: Tx): Promise<void> { function handleVacancyRemove (control: TriggerControl, cud: TxCUD<Doc>, res: Tx[]): void {
const removeTx = actualTx as TxRemoveDoc<Vacancy> const removeTx = cud as TxRemoveDoc<Vacancy>
// It could be null or new value // It could be null or new value
const txes = ( const vacancy = control.removedMap.get(removeTx.objectId) as Vacancy
await control.findAll(control.ctx, core.class.TxCUD, { if (vacancy === undefined) {
objectId: removeTx.objectId return
}) }
).filter((it) => it._id !== removeTx._id)
const vacancy = TxProcessor.buildDoc2Doc(txes) as Vacancy
const res: Tx[] = []
if (vacancy.company != null) { if (vacancy.company != null) {
// We have old value // We have old value
res.push( res.push(
@ -182,8 +178,8 @@ async function handleVacancyRemove (control: TriggerControl, cud: TxCUD<Doc>, ac
} }
} }
function handleVacancyCreate (control: TriggerControl, cud: TxCUD<Doc>, actualTx: Tx, res: Tx[]): void { function handleVacancyCreate (control: TriggerControl, cud: TxCUD<Doc>, res: Tx[]): void {
const createTx = actualTx as TxCreateDoc<Vacancy> const createTx = cud as TxCreateDoc<Vacancy>
const vacancy = TxProcessor.createDoc2Doc(createTx) const vacancy = TxProcessor.createDoc2Doc(createTx)
if (vacancy.company !== undefined) { if (vacancy.company !== undefined) {
res.push( res.push(

View File

@ -69,6 +69,21 @@ export async function OnTask (tx: Tx, control: TriggerControl): Promise<Tx[]> {
return [] return []
} }
export async function OnWorkSlotUpdate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
const actualTx = TxProcessor.extractTx(tx) as TxCUD<WorkSlot>
if (!control.hierarchy.isDerived(actualTx.objectClass, time.class.WorkSlot)) return []
if (!control.hierarchy.isDerived(actualTx._class, core.class.TxUpdateDoc)) return []
const updTx = actualTx as TxUpdateDoc<WorkSlot>
const visibility = updTx.operations.visibility
if (visibility !== undefined) {
const workslot = (await control.findAll(control.ctx, time.class.WorkSlot, { _id: updTx.objectId }, { limit: 1 }))[0]
if (workslot === undefined) return []
const todo = (await control.findAll(control.ctx, time.class.ToDo, { _id: workslot.attachedTo }))[0]
return [control.txFactory.createTxUpdateDoc(todo._class, todo.space, todo._id, { visibility })]
}
return []
}
export async function OnWorkSlotCreate (tx: Tx, control: TriggerControl): Promise<Tx[]> { export async function OnWorkSlotCreate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
const actualTx = TxProcessor.extractTx(tx) as TxCUD<WorkSlot> const actualTx = TxProcessor.extractTx(tx) as TxCUD<WorkSlot>
if (!control.hierarchy.isDerived(actualTx.objectClass, time.class.WorkSlot)) return [] if (!control.hierarchy.isDerived(actualTx.objectClass, time.class.WorkSlot)) return []
@ -578,6 +593,22 @@ async function changeIssueStatusHandler (
} }
} }
} }
} else if (status.category === task.statusCategory.Won || status.category === task.statusCategory.Lost) {
const issue = (await control.findAll(control.ctx, tracker.class.Issue, { _id: issueId }))[0]
if (issue !== undefined) {
const todos = await control.findAll(control.ctx, time.class.ToDo, {
attachedTo: issue._id,
doneOn: null
})
const res: Tx[] = []
const now = Date.now()
for (const todo of todos) {
if (todo.doneOn == null) {
res.push(control.txFactory.createTxUpdateDoc(todo._class, todo.space, todo._id, { doneOn: now }))
}
}
return res
}
} }
return [] return []
} }
@ -648,6 +679,7 @@ export default async () => ({
OnToDoUpdate, OnToDoUpdate,
OnToDoRemove, OnToDoRemove,
OnToDoCreate, OnToDoCreate,
OnWorkSlotCreate OnWorkSlotCreate,
OnWorkSlotUpdate
} }
}) })

View File

@ -56,6 +56,7 @@ export default plugin(serverTimeId, {
OnToDoUpdate: '' as Resource<TriggerFunc>, OnToDoUpdate: '' as Resource<TriggerFunc>,
OnToDoRemove: '' as Resource<TriggerFunc>, OnToDoRemove: '' as Resource<TriggerFunc>,
OnToDoCreate: '' as Resource<TriggerFunc>, OnToDoCreate: '' as Resource<TriggerFunc>,
OnWorkSlotCreate: '' as Resource<TriggerFunc> OnWorkSlotCreate: '' as Resource<TriggerFunc>,
OnWorkSlotUpdate: '' as Resource<TriggerFunc>
} }
}) })

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
// //
import core, { AnyAttribute, Hierarchy, Tx, TxCUD, TxProcessor, TxRemoveDoc } from '@hcengineering/core' import core, { AnyAttribute, Hierarchy, Tx, TxRemoveDoc } from '@hcengineering/core'
import type { TriggerControl } from '@hcengineering/server-core' import type { TriggerControl } from '@hcengineering/server-core'
import view from '@hcengineering/view' import view from '@hcengineering/view'
@ -24,8 +24,7 @@ export async function OnCustomAttributeRemove (tx: Tx, control: TriggerControl):
const hierarchy = control.hierarchy const hierarchy = control.hierarchy
const ptx = tx as TxRemoveDoc<AnyAttribute> const ptx = tx as TxRemoveDoc<AnyAttribute>
if (!checkTx(ptx, hierarchy)) return [] if (!checkTx(ptx, hierarchy)) return []
const txes = await control.findAll<TxCUD<AnyAttribute>>(control.ctx, core.class.TxCUD, { objectId: ptx.objectId }) const attribute = control.removedMap.get(ptx.objectId) as AnyAttribute
const attribute = TxProcessor.buildDoc2Doc<AnyAttribute>(txes)
if (attribute === undefined) return [] if (attribute === undefined) return []
const preferences = await control.findAll(control.ctx, view.class.ViewletPreference, { const preferences = await control.findAll(control.ctx, view.class.ViewletPreference, {
config: attribute.name, config: attribute.name,