|
24 | 24 | import { workspacePermissions } from '../../stores'; |
25 | 25 | import { t } from '../../stores/i18n.svelte.js'; |
26 | 26 | import { formatDateShort, formatCustomFieldDate } from '../../utils/dateFormatter.js'; |
| 27 | + import { resolveOptionLabel, resolveOptionLabels } from '../../utils/optionUtils.js'; |
27 | 28 | import StatusBadge from '../../components/StatusBadge.svelte'; |
28 | 29 | import Badge from '../../components/Badge.svelte'; |
29 | 30 | import ApprovalsTimeline from './ApprovalsTimeline.svelte'; |
|
214 | 215 | ? localStorage.getItem(SCHEDULING_COLLAPSED_KEY) === 'true' |
215 | 216 | : false |
216 | 217 | ); |
| 218 | + let hasDateCustomFields = $derived( |
| 219 | + !!(workspaceScreenFields && workspaceScreenFields.some(f => f.field_type === 'custom' && getCustomFieldDefinition(f.field_identifier)?.field_type === 'date')) |
| 220 | + ); |
217 | 221 | let schedulingExpanded = $derived( |
218 | | - (item?.due_date || item?.end_date) ? true : schedulingUserPref |
| 222 | + (item?.due_date || item?.end_date || hasDateCustomFields) ? true : schedulingUserPref |
219 | 223 | ); |
220 | | - let schedulingForcedOpen = $derived(!!(item?.due_date || item?.end_date)); |
| 224 | + let schedulingForcedOpen = $derived(!!(item?.due_date || item?.end_date || hasDateCustomFields)); |
221 | 225 |
|
222 | 226 | function toggleScheduling() { |
223 | 227 | if (schedulingForcedOpen) return; |
|
278 | 282 | return customFieldDefinitions.find(field => field.id === parseInt(fieldId)); |
279 | 283 | } |
280 | 284 |
|
| 285 | + function coerceCheckboxValue(raw) { |
| 286 | + if (typeof raw === 'boolean') return raw; |
| 287 | + if (typeof raw === 'number') return raw !== 0; |
| 288 | + if (typeof raw === 'string') { |
| 289 | + const normalized = raw.trim().toLowerCase(); |
| 290 | + if (['false', '0', 'no', 'off'].includes(normalized)) return false; |
| 291 | + if (['true', '1', 'yes', 'on'].includes(normalized)) return true; |
| 292 | + } |
| 293 | + return Boolean(raw); |
| 294 | + } |
| 295 | + |
| 296 | + function formatCustomFieldValue(fieldDef, value) { |
| 297 | + if (fieldDef.field_type === 'checkbox') { |
| 298 | + return coerceCheckboxValue(value) ? t('common.yes') : t('common.no'); |
| 299 | + } |
| 300 | + if (fieldDef.field_type === 'select') { |
| 301 | + return resolveOptionLabel(fieldDef.options, value); |
| 302 | + } |
| 303 | + if (fieldDef.field_type === 'multiselect') { |
| 304 | + return resolveOptionLabels(fieldDef.options, Array.isArray(value) ? value : []).join(', '); |
| 305 | + } |
| 306 | + if (fieldDef.field_type === 'date') { |
| 307 | + return formatCustomFieldDate(value); |
| 308 | + } |
| 309 | + if (fieldDef.field_type === 'user' && typeof value === 'object') { |
| 310 | + return value.name || t('common.selected'); |
| 311 | + } |
| 312 | + if (Array.isArray(value)) { |
| 313 | + return value.map(v => typeof v === 'object' ? v.title || v.name || v.label || v.value : v).join(', '); |
| 314 | + } |
| 315 | + if (typeof value === 'object') { |
| 316 | + return value.title || value.name || value.label || value.value || JSON.stringify(value); |
| 317 | + } |
| 318 | + return value; |
| 319 | + } |
| 320 | + |
281 | 321 | function formatVirtualFieldValue(field, value) { |
282 | 322 | if (field.virtual_field_type === 'checkbox') { |
283 | 323 | return value ? t('common.yes') : t('common.no'); |
|
969 | 1009 | {/if} |
970 | 1010 |
|
971 | 1011 | <!-- Scheduling Section (collapsible) --> |
972 | | - {#if shouldShowSystemField('due_date') || shouldShowSystemField('start_date') || shouldShowSystemField('end_date')} |
| 1012 | + {#if shouldShowSystemField('due_date') || shouldShowSystemField('start_date') || shouldShowSystemField('end_date') || hasDateCustomFields} |
973 | 1013 | <div class="border-t my-4" style="border-color: var(--ds-border);"></div> |
974 | 1014 |
|
975 | 1015 | <!-- Scheduling Header --> |
|
1233 | 1273 | <Text variant="subtle" size="sm">{fieldDef.name}</Text> |
1234 | 1274 | <span style="color: {currentValue ? 'var(--ds-text)' : 'var(--ds-text-subtle)'};"> |
1235 | 1275 | {#if currentValue !== null && currentValue !== undefined && currentValue !== ''} |
1236 | | - {#if fieldDef.field_type === 'checkbox'} |
1237 | | - {currentValue ? t('common.yes') : t('common.no')} |
1238 | | - {:else if fieldDef.field_type === 'date'} |
1239 | | - {formatCustomFieldDate(currentValue)} |
1240 | | - {:else if fieldDef.field_type === 'user' && typeof currentValue === 'object'} |
1241 | | - {currentValue.name || t('common.selected')} |
1242 | | - {:else if Array.isArray(currentValue)} |
1243 | | - {currentValue.map(v => typeof v === 'object' ? v.title || v.name || v.label || v.value : v).join(', ')} |
1244 | | - {:else if typeof currentValue === 'object'} |
1245 | | - {currentValue.title || currentValue.name || currentValue.label || currentValue.value || JSON.stringify(currentValue)} |
1246 | | - {:else} |
1247 | | - {currentValue} |
1248 | | - {/if} |
| 1276 | + {formatCustomFieldValue(fieldDef, currentValue)} |
1249 | 1277 | {:else} |
1250 | 1278 | {t('common.none')} |
1251 | 1279 | {/if} |
|
0 commit comments