|
| 1 | +<!-- Copyright by the Spark Development Network; Licensed under the Rock Community License --> |
| 2 | +<template> |
| 3 | + <div v-if="isProgramPickerVisible" class="row"> |
| 4 | + <div class="col-md-6"> |
| 5 | + <StepProgramPicker v-model="internalProgram" |
| 6 | + label="Step Program" /> |
| 7 | + </div> |
| 8 | + </div> |
| 9 | + |
| 10 | + <div class="row"> |
| 11 | + <div class="col-md-6"> |
| 12 | + <StepTypePicker v-model="internalType" |
| 13 | + label="Step Type" |
| 14 | + rules="required" |
| 15 | + :disabled="isTypePickerDisabled" |
| 16 | + :stepProgramGuid="stepProgramGuid ?? null" /> |
| 17 | + </div> |
| 18 | + <div :class="stepTypeConfiguration?.hasEndDate ? 'col-md-3 col-sm-6' : 'col-md-6'"> |
| 19 | + <DatePicker v-model="internalStartDate" |
| 20 | + :label="stepTypeConfiguration?.startDateLabel ?? 'Date'" |
| 21 | + :rules="stepTypeConfiguration?.isDateRequired ? 'required' : ''" /> |
| 22 | + </div> |
| 23 | + <div v-if="stepTypeConfiguration?.hasEndDate" class="col-md-3 col-sm-6"> |
| 24 | + <DatePicker v-model="internalEndDate" |
| 25 | + label="End Date" /> |
| 26 | + </div> |
| 27 | + </div> |
| 28 | + |
| 29 | + <div class="row"> |
| 30 | + <div class="col-md-6"> |
| 31 | + <StepStatusPicker v-model="internalStatus" |
| 32 | + label="Status" |
| 33 | + rules="required" |
| 34 | + :showBlankItem="true" |
| 35 | + :stepProgramGuid="stepProgramGuid ?? null" /> |
| 36 | + </div> |
| 37 | + <div class="col-md-6"> |
| 38 | + <CampusPicker v-model="internalCampus" |
| 39 | + label="Campus" |
| 40 | + forceVisible |
| 41 | + showBlankItem /> |
| 42 | + </div> |
| 43 | + </div> |
| 44 | + |
| 45 | + <AttributeValuesContainer v-if="stepTypeConfiguration?.stepAttributes && Object.keys(stepTypeConfiguration.stepAttributes).length > 0" |
| 46 | + v-model="internalAttributeValues" |
| 47 | + :attributes="stepTypeConfiguration.stepAttributes" |
| 48 | + isEditMode |
| 49 | + :numberOfColumns="2" /> |
| 50 | +</template> |
| 51 | + |
| 52 | +<script setup lang="ts"> |
| 53 | + import { computed, PropType, ref, watch } from "vue"; |
| 54 | + import AttributeValuesContainer from "@Obsidian/Controls/attributeValuesContainer.obs"; |
| 55 | + import CampusPicker from "@Obsidian/Controls/campusPicker.obs"; |
| 56 | + import DatePicker from "@Obsidian/Controls/datePicker.obs"; |
| 57 | + import StepProgramPicker from "@Obsidian/Controls/stepProgramPicker.obs"; |
| 58 | + import StepStatusPicker from "@Obsidian/Controls/stepStatusPicker.obs"; |
| 59 | + import StepTypePicker from "@Obsidian/Controls/stepTypePicker.obs"; |
| 60 | + import { Guid } from "@Obsidian/Types"; |
| 61 | + import { ListItemBag } from "@Obsidian/ViewModels/Utility/listItemBag"; |
| 62 | + import { StepBulkEntryStepTypeConfigurationBag } from "@Obsidian/ViewModels/Blocks/Engagement/StepBulkEntry/stepBulkEntryStepTypeConfigurationBag"; |
| 63 | + |
| 64 | + const props = defineProps({ |
| 65 | + /** The current step type configuration, null until a step type is selected. */ |
| 66 | + stepTypeConfiguration: { |
| 67 | + type: Object as PropType<StepBulkEntryStepTypeConfigurationBag | null>, |
| 68 | + default: null |
| 69 | + }, |
| 70 | + |
| 71 | + /** Whether the program picker should be shown. */ |
| 72 | + isProgramPickerVisible: { |
| 73 | + type: Boolean as PropType<boolean>, |
| 74 | + default: true |
| 75 | + }, |
| 76 | + |
| 77 | + /** Whether the step type picker should be disabled (pre-selected via settings or URL). */ |
| 78 | + isTypePickerDisabled: { |
| 79 | + type: Boolean as PropType<boolean>, |
| 80 | + default: false |
| 81 | + }, |
| 82 | + |
| 83 | + /** The initial step program from block settings or page parameters. */ |
| 84 | + initialProgram: { |
| 85 | + type: Object as PropType<ListItemBag | null>, |
| 86 | + default: null |
| 87 | + }, |
| 88 | + |
| 89 | + /** The initial step type from block settings or page parameters. */ |
| 90 | + initialType: { |
| 91 | + type: Object as PropType<ListItemBag | null>, |
| 92 | + default: null |
| 93 | + }, |
| 94 | + |
| 95 | + /** The start date value. */ |
| 96 | + startDate: { |
| 97 | + type: String as PropType<string>, |
| 98 | + default: "" |
| 99 | + }, |
| 100 | + |
| 101 | + /** The end date value. */ |
| 102 | + endDate: { |
| 103 | + type: String as PropType<string>, |
| 104 | + default: "" |
| 105 | + }, |
| 106 | + |
| 107 | + /** The campus value. */ |
| 108 | + campus: { |
| 109 | + type: Object as PropType<ListItemBag | null>, |
| 110 | + default: null |
| 111 | + }, |
| 112 | + |
| 113 | + /** The step status value. */ |
| 114 | + stepStatus: { |
| 115 | + type: Object as PropType<ListItemBag | null>, |
| 116 | + default: null |
| 117 | + }, |
| 118 | + |
| 119 | + /** The attribute values. */ |
| 120 | + attributeValues: { |
| 121 | + type: Object as PropType<Record<string, string>>, |
| 122 | + default: () => ({}) |
| 123 | + } |
| 124 | + }); |
| 125 | + |
| 126 | + const emit = defineEmits<{ |
| 127 | + (e: "update:startDate", value: string): void; |
| 128 | + (e: "update:endDate", value: string): void; |
| 129 | + (e: "update:campus", value: ListItemBag | null): void; |
| 130 | + (e: "update:stepStatus", value: ListItemBag | null): void; |
| 131 | + (e: "update:attributeValues", value: Record<string, string>): void; |
| 132 | + (e: "stepTypeChanged", value: Guid | null): void; |
| 133 | + (e: "programChanged", value: Guid | null): void; |
| 134 | + }>(); |
| 135 | + |
| 136 | + // #region Values |
| 137 | + |
| 138 | + // Program and type use internal refs because they have one-time initialization |
| 139 | + // and emit custom events (not v-model pass-through). |
| 140 | + const internalProgram = ref<ListItemBag | null>(props.initialProgram ?? null); |
| 141 | + const internalType = ref<ListItemBag | null>(props.initialType ?? null); |
| 142 | + |
| 143 | + // v-model pass-through fields use computed get/set instead of |
| 144 | + // bilateral watchers (ref → emit + prop → ref). |
| 145 | + const internalStartDate = computed({ |
| 146 | + get: () => props.startDate, |
| 147 | + set: (val) => emit("update:startDate", val) |
| 148 | + }); |
| 149 | + |
| 150 | + const internalEndDate = computed({ |
| 151 | + get: () => props.endDate, |
| 152 | + set: (val) => emit("update:endDate", val) |
| 153 | + }); |
| 154 | + |
| 155 | + const internalCampus = computed({ |
| 156 | + get: () => props.campus, |
| 157 | + set: (val) => emit("update:campus", val) |
| 158 | + }); |
| 159 | + |
| 160 | + const internalStatus = computed({ |
| 161 | + get: () => props.stepStatus, |
| 162 | + set: (val) => emit("update:stepStatus", val) |
| 163 | + }); |
| 164 | + |
| 165 | + const internalAttributeValues = computed({ |
| 166 | + get: () => props.attributeValues, |
| 167 | + set: (val) => emit("update:attributeValues", val) |
| 168 | + }); |
| 169 | + |
| 170 | + // #endregion |
| 171 | + |
| 172 | + // #region Computed Values |
| 173 | + |
| 174 | + /** The current step program Guid, derived from the configuration or the picker. */ |
| 175 | + const stepProgramGuid = computed<Guid | null>(() => { |
| 176 | + return props.stepTypeConfiguration?.stepProgramGuid |
| 177 | + ?? internalProgram.value?.value |
| 178 | + ?? props.initialProgram?.value |
| 179 | + ?? null; |
| 180 | + }); |
| 181 | + |
| 182 | + // #endregion |
| 183 | + |
| 184 | + // #region Watchers |
| 185 | + |
| 186 | + // Notify parent when the step type or program picker changes. |
| 187 | + watch(() => internalType.value?.value ?? null, (newGuid) => { |
| 188 | + emit("stepTypeChanged", newGuid); |
| 189 | + }); |
| 190 | + |
| 191 | + watch(() => internalProgram.value?.value ?? null, (newGuid) => { |
| 192 | + // Clear the step type since it may belong to a different program. |
| 193 | + internalType.value = null; |
| 194 | + emit("programChanged", newGuid); |
| 195 | + }); |
| 196 | + |
| 197 | + // #endregion |
| 198 | +</script> |
0 commit comments