-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtask.object.ts
More file actions
237 lines (204 loc) · 6.57 KB
/
Copy pathtask.object.ts
File metadata and controls
237 lines (204 loc) · 6.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import { P, cel } from '@objectstack/spec';
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { ObjectSchema, Field } from '@objectstack/spec/data';
export const Task = ObjectSchema.create({
name: 'crm_task',
label: 'Task',
pluralLabel: 'Tasks',
icon: 'check-square',
description: 'Activities and to-do items',
fields: {
// Task Information
subject: Field.text({
label: 'Subject',
required: true,
searchable: true,
maxLength: 255,
}),
description: Field.markdown({
label: 'Description',
}),
// Task Management
status: Field.select({
label: 'Status',
required: true,
options: [
{ label: 'Not Started', value: 'not_started', color: '#808080', default: true },
{ label: 'In Progress', value: 'in_progress', color: '#FFA500' },
{ label: 'Waiting', value: 'waiting', color: '#FFD700' },
{ label: 'Completed', value: 'completed', color: '#00AA00' },
{ label: 'Deferred', value: 'deferred', color: '#999999' },
]
}),
priority: Field.select({
label: 'Priority',
required: true,
options: [
{ label: 'Low', value: 'low', color: '#4169E1', default: true },
{ label: 'Normal', value: 'normal', color: '#00AA00' },
{ label: 'High', value: 'high', color: '#FFA500' },
{ label: 'Urgent', value: 'urgent', color: '#FF0000' },
]
}),
type: Field.select({
label: 'Task Type',
options: [
{ label: 'Call', value: 'call' },
{ label: 'Email', value: 'email' },
{ label: 'Meeting', value: 'meeting' },
{ label: 'Follow-up', value: 'follow_up' },
{ label: 'Demo', value: 'demo' },
{ label: 'Other', value: 'other' },
]
}),
// Dates
due_date: Field.date({
label: 'Due Date',
}),
reminder_date: Field.datetime({
label: 'Reminder Date/Time',
}),
completed_date: Field.datetime({
label: 'Completed Date',
readonly: true,
}),
// Assignment
owner: Field.lookup('user', {
defaultValue: cel`os.user.id`,
label: 'Assigned To',
}),
// Related To (Polymorphic relationship - can link to multiple object types)
related_to_type: Field.select({
label: 'Related To Type',
options: [
{ label: 'Account', value: 'crm_account' },
{ label: 'Contact', value: 'crm_contact' },
{ label: 'Opportunity', value: 'crm_opportunity' },
{ label: 'Lead', value: 'crm_lead' },
{ label: 'Case', value: 'crm_case' },
]
}),
related_to_account: Field.lookup('crm_account', {
label: 'Related Account',
}),
related_to_contact: Field.lookup('crm_contact', {
label: 'Related Contact',
}),
related_to_opportunity: Field.lookup('crm_opportunity', {
label: 'Related Opportunity',
}),
related_to_lead: Field.lookup('crm_lead', {
label: 'Related Lead',
}),
related_to_case: Field.lookup('crm_case', {
label: 'Related Case',
}),
// Recurrence (for recurring tasks)
is_recurring: Field.boolean({
label: 'Recurring Task',
defaultValue: false,
}),
recurrence_type: Field.select({
label: 'Recurrence Type',
options: [
{ label: 'Daily', value: 'daily' },
{ label: 'Weekly', value: 'weekly' },
{ label: 'Monthly', value: 'monthly' },
{ label: 'Yearly', value: 'yearly' },
]
}),
recurrence_interval: Field.number({
label: 'Recurrence Interval',
defaultValue: 1,
min: 1,
}),
recurrence_end_date: Field.date({
label: 'Recurrence End Date',
}),
// Flags
is_completed: Field.boolean({
label: 'Is Completed',
defaultValue: false,
readonly: true,
}),
is_overdue: Field.boolean({
label: 'Is Overdue',
defaultValue: false,
readonly: true,
}),
// Set by the `task_due_reminder` schedule flow once a reminder has fired,
// so the hourly sweep never re-alerts the same task. Reset to false if you
// push `reminder_date` into the future.
reminder_sent: Field.boolean({
label: 'Reminder Sent',
defaultValue: false,
readonly: true,
}),
// Progress
progress_percent: Field.percent({
label: 'Progress (%)',
min: 0,
max: 100,
defaultValue: 0,
}),
// Time tracking
estimated_hours: Field.number({
label: 'Estimated Hours',
scale: 2,
min: 0,
}),
actual_hours: Field.number({
label: 'Actual Hours',
scale: 2,
min: 0,
}),
},
enable: {
trackHistory: true,
searchable: true,
apiEnabled: true,
files: true,
feeds: true, // Enable social feed, comments, and mentions
activities: true, // Enable tasks and events tracking
trash: true,
mru: true, // Track Most Recently Used
},
// Database indexes for performance
indexes: [
{ fields: ['status'] },
{ fields: ['priority'] },
{ fields: ['owner'] },
{ fields: ['due_date'] },
],
// ADR-0079: render-only `titleFormat` retired in favor of `nameField`,
// which names the real field holding the record title (here: `subject`).
nameField: 'subject',
compactLayout: ['subject', 'status', 'priority', 'due_date', 'owner'],
// Removed: list_views and form_views belong in UI configuration, not object definition
validations: [
{
name: 'completed_date_required',
type: 'script',
severity: 'error',
message: 'Completed date is required when status is Completed',
condition: P`record.status == "completed" && isBlank(record.completed_date)`,
},
{
name: 'recurrence_fields_required',
type: 'script',
severity: 'error',
message: 'Recurrence type is required for recurring tasks',
condition: P`record.is_recurring == true && isBlank(record.recurrence_type)`,
},
{
name: 'related_to_required',
type: 'script',
severity: 'warning',
message: 'At least one related record should be selected',
condition: P`isBlank(record.related_to_account) && isBlank(record.related_to_contact) && isBlank(record.related_to_opportunity) && isBlank(record.related_to_lead) && isBlank(record.related_to_case)`,
},
],
// NOTE: object `workflows[]` were removed in @objectstack 7.7. Field-updates
// moved to this object's *.hook.ts; scheduled status-flips & notifications
// moved to src/flows/*.flow.ts (see flows/index.ts).
});