Skip to content

Commit c190b1c

Browse files
authored
Workslot fixes (#7084)
1 parent 01350d8 commit c190b1c

File tree

6 files changed

+71
-28
lines changed

6 files changed

+71
-28
lines changed

models/server-time/src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { type Resource } from '@hcengineering/platform'
2121
import serverCore, { type TriggerControl } from '@hcengineering/server-core'
2222
import tracker from '@hcengineering/tracker'
2323
import serverTime, { type ToDoFactory, type OnToDo } from '@hcengineering/server-time'
24-
import { type ToDo, type WorkSlot } from '@hcengineering/time'
24+
import time, { type ToDo, type WorkSlot } from '@hcengineering/time'
2525

2626
@Mixin(serverTime.mixin.ToDoFactory, core.class.Class)
2727
export class TToDoFactory extends TClass implements ToDoFactory {
@@ -45,6 +45,7 @@ export function createModel (builder: Builder): void {
4545
trigger: serverTime.trigger.OnToDoUpdate,
4646
txMatch: {
4747
_class: core.class.TxCollectionCUD,
48+
'tx.objectClass': time.class.ToDo,
4849
'tx._class': core.class.TxUpdateDoc
4950
}
5051
})
@@ -53,6 +54,7 @@ export function createModel (builder: Builder): void {
5354
trigger: serverTime.trigger.OnToDoRemove,
5455
txMatch: {
5556
_class: core.class.TxCollectionCUD,
57+
'tx.objectClass': time.class.ToDo,
5658
'tx._class': core.class.TxRemoveDoc
5759
}
5860
})
@@ -61,6 +63,7 @@ export function createModel (builder: Builder): void {
6163
trigger: serverTime.trigger.OnToDoCreate,
6264
txMatch: {
6365
_class: core.class.TxCollectionCUD,
66+
'tx.objectClass': time.class.ToDo,
6467
'tx._class': core.class.TxCreateDoc
6568
},
6669
isAsync: true
@@ -70,10 +73,20 @@ export function createModel (builder: Builder): void {
7073
trigger: serverTime.trigger.OnWorkSlotCreate,
7174
txMatch: {
7275
_class: core.class.TxCollectionCUD,
76+
'tx.objectClass': time.class.WorkSlot,
7377
'tx._class': core.class.TxCreateDoc
7478
}
7579
})
7680

81+
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
82+
trigger: serverTime.trigger.OnWorkSlotUpdate,
83+
txMatch: {
84+
_class: core.class.TxCollectionCUD,
85+
'tx.objectClass': time.class.WorkSlot,
86+
'tx._class': core.class.TxUpdateDoc
87+
}
88+
})
89+
7790
builder.mixin(tracker.class.Issue, core.class.Class, serverTime.mixin.ToDoFactory, {
7891
factory: serverTime.function.IssueToDoFactory
7992
})

plugins/time-resources/src/components/WorkSlotElement.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import { createQuery } from '@hcengineering/presentation'
1717
import { Label } from '@hcengineering/ui'
1818
import { ToDo, WorkSlot } from '@hcengineering/time'
19-
import time from '../plugin'
2019
import ToDoPresenter from './ToDoPresenter.svelte'
20+
import calendar from '@hcengineering/calendar'
2121
2222
export let event: WorkSlot
2323
export let oneRow: boolean = false
@@ -26,13 +26,15 @@
2626
let todo: ToDo
2727
2828
const query = createQuery()
29-
$: query.query(event.attachedToClass, { _id: event.attachedTo }, (res) => {
30-
todo = res[0]
31-
})
29+
$: !hideDetails
30+
? query.query(event.attachedToClass, { _id: event.attachedTo }, (res) => {
31+
todo = res[0]
32+
})
33+
: query.unsubscribe()
3234
</script>
3335

3436
{#if hideDetails}
35-
<Label label={time.string.WorkSlot} />
37+
<Label label={calendar.string.Busy} />
3638
{:else if todo}
3739
<ToDoPresenter value={todo} withoutSpace={oneRow} />
3840
{/if}

server-plugins/recruit-resources/src/index.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,19 @@ export async function applicationTextPresenter (doc: Doc, control: TriggerContro
8585
* @public
8686
*/
8787
export async function OnRecruitUpdate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
88-
const actualTx = TxProcessor.extractTx(tx)
89-
const cud = actualTx as TxCUD<Doc>
90-
if (!control.hierarchy.isDerived(cud.objectClass, recruit.class.Vacancy)) {
88+
const actualTx = TxProcessor.extractTx(tx) as TxCUD<Doc>
89+
if (!control.hierarchy.isDerived(actualTx.objectClass, recruit.class.Vacancy)) {
9190
return []
9291
}
9392

9493
const res: Tx[] = []
9594

9695
if (actualTx._class === core.class.TxCreateDoc) {
97-
handleVacancyCreate(control, cud, actualTx, res)
96+
handleVacancyCreate(control, actualTx, res)
9897
} else if (actualTx._class === core.class.TxUpdateDoc) {
99-
await handleVacancyUpdate(control, cud, res)
98+
await handleVacancyUpdate(control, actualTx, res)
10099
} else if (actualTx._class === core.class.TxRemoveDoc) {
101-
await handleVacancyRemove(control, cud, actualTx)
100+
handleVacancyRemove(control, actualTx, res)
102101
}
103102
return res
104103
}
@@ -156,16 +155,13 @@ async function handleVacancyUpdate (control: TriggerControl, cud: TxCUD<Doc>, re
156155
}
157156
}
158157

159-
async function handleVacancyRemove (control: TriggerControl, cud: TxCUD<Doc>, actualTx: Tx): Promise<void> {
160-
const removeTx = actualTx as TxRemoveDoc<Vacancy>
158+
function handleVacancyRemove (control: TriggerControl, cud: TxCUD<Doc>, res: Tx[]): void {
159+
const removeTx = cud as TxRemoveDoc<Vacancy>
161160
// It could be null or new value
162-
const txes = (
163-
await control.findAll(control.ctx, core.class.TxCUD, {
164-
objectId: removeTx.objectId
165-
})
166-
).filter((it) => it._id !== removeTx._id)
167-
const vacancy = TxProcessor.buildDoc2Doc(txes) as Vacancy
168-
const res: Tx[] = []
161+
const vacancy = control.removedMap.get(removeTx.objectId) as Vacancy
162+
if (vacancy === undefined) {
163+
return
164+
}
169165
if (vacancy.company != null) {
170166
// We have old value
171167
res.push(
@@ -182,8 +178,8 @@ async function handleVacancyRemove (control: TriggerControl, cud: TxCUD<Doc>, ac
182178
}
183179
}
184180

185-
function handleVacancyCreate (control: TriggerControl, cud: TxCUD<Doc>, actualTx: Tx, res: Tx[]): void {
186-
const createTx = actualTx as TxCreateDoc<Vacancy>
181+
function handleVacancyCreate (control: TriggerControl, cud: TxCUD<Doc>, res: Tx[]): void {
182+
const createTx = cud as TxCreateDoc<Vacancy>
187183
const vacancy = TxProcessor.createDoc2Doc(createTx)
188184
if (vacancy.company !== undefined) {
189185
res.push(

server-plugins/time-resources/src/index.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ export async function OnTask (tx: Tx, control: TriggerControl): Promise<Tx[]> {
6969
return []
7070
}
7171

72+
export async function OnWorkSlotUpdate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
73+
const actualTx = TxProcessor.extractTx(tx) as TxCUD<WorkSlot>
74+
if (!control.hierarchy.isDerived(actualTx.objectClass, time.class.WorkSlot)) return []
75+
if (!control.hierarchy.isDerived(actualTx._class, core.class.TxUpdateDoc)) return []
76+
const updTx = actualTx as TxUpdateDoc<WorkSlot>
77+
const visibility = updTx.operations.visibility
78+
if (visibility !== undefined) {
79+
const workslot = (await control.findAll(control.ctx, time.class.WorkSlot, { _id: updTx.objectId }, { limit: 1 }))[0]
80+
if (workslot === undefined) return []
81+
const todo = (await control.findAll(control.ctx, time.class.ToDo, { _id: workslot.attachedTo }))[0]
82+
return [control.txFactory.createTxUpdateDoc(todo._class, todo.space, todo._id, { visibility })]
83+
}
84+
return []
85+
}
86+
7287
export async function OnWorkSlotCreate (tx: Tx, control: TriggerControl): Promise<Tx[]> {
7388
const actualTx = TxProcessor.extractTx(tx) as TxCUD<WorkSlot>
7489
if (!control.hierarchy.isDerived(actualTx.objectClass, time.class.WorkSlot)) return []
@@ -578,6 +593,22 @@ async function changeIssueStatusHandler (
578593
}
579594
}
580595
}
596+
} else if (status.category === task.statusCategory.Won || status.category === task.statusCategory.Lost) {
597+
const issue = (await control.findAll(control.ctx, tracker.class.Issue, { _id: issueId }))[0]
598+
if (issue !== undefined) {
599+
const todos = await control.findAll(control.ctx, time.class.ToDo, {
600+
attachedTo: issue._id,
601+
doneOn: null
602+
})
603+
const res: Tx[] = []
604+
const now = Date.now()
605+
for (const todo of todos) {
606+
if (todo.doneOn == null) {
607+
res.push(control.txFactory.createTxUpdateDoc(todo._class, todo.space, todo._id, { doneOn: now }))
608+
}
609+
}
610+
return res
611+
}
581612
}
582613
return []
583614
}
@@ -648,6 +679,7 @@ export default async () => ({
648679
OnToDoUpdate,
649680
OnToDoRemove,
650681
OnToDoCreate,
651-
OnWorkSlotCreate
682+
OnWorkSlotCreate,
683+
OnWorkSlotUpdate
652684
}
653685
})

server-plugins/time/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default plugin(serverTimeId, {
5656
OnToDoUpdate: '' as Resource<TriggerFunc>,
5757
OnToDoRemove: '' as Resource<TriggerFunc>,
5858
OnToDoCreate: '' as Resource<TriggerFunc>,
59-
OnWorkSlotCreate: '' as Resource<TriggerFunc>
59+
OnWorkSlotCreate: '' as Resource<TriggerFunc>,
60+
OnWorkSlotUpdate: '' as Resource<TriggerFunc>
6061
}
6162
})

server-plugins/view-resources/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414
//
1515

16-
import core, { AnyAttribute, Hierarchy, Tx, TxCUD, TxProcessor, TxRemoveDoc } from '@hcengineering/core'
16+
import core, { AnyAttribute, Hierarchy, Tx, TxRemoveDoc } from '@hcengineering/core'
1717
import type { TriggerControl } from '@hcengineering/server-core'
1818
import view from '@hcengineering/view'
1919

@@ -24,8 +24,7 @@ export async function OnCustomAttributeRemove (tx: Tx, control: TriggerControl):
2424
const hierarchy = control.hierarchy
2525
const ptx = tx as TxRemoveDoc<AnyAttribute>
2626
if (!checkTx(ptx, hierarchy)) return []
27-
const txes = await control.findAll<TxCUD<AnyAttribute>>(control.ctx, core.class.TxCUD, { objectId: ptx.objectId })
28-
const attribute = TxProcessor.buildDoc2Doc<AnyAttribute>(txes)
27+
const attribute = control.removedMap.get(ptx.objectId) as AnyAttribute
2928
if (attribute === undefined) return []
3029
const preferences = await control.findAll(control.ctx, view.class.ViewletPreference, {
3130
config: attribute.name,

0 commit comments

Comments
 (0)