From 20829a5cb565a5f70b31a4b727dc944585cabce2 Mon Sep 17 00:00:00 2001 From: Carolina Capetillo Date: Tue, 19 Nov 2024 14:31:03 -0800 Subject: [PATCH 1/4] adds shuffle button and load more targets button --- .../Scheduling/BeginnerScheduling.vue | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/components/Scheduling/BeginnerScheduling.vue b/src/components/Scheduling/BeginnerScheduling.vue index 12d963b..fb12bdd 100644 --- a/src/components/Scheduling/BeginnerScheduling.vue +++ b/src/components/Scheduling/BeginnerScheduling.vue @@ -21,6 +21,8 @@ const selectedTargets = ref([]) const startDate = ref('') const endDate = ref('') const selectedProposal = ref() +const displayedTargets = ref([]) +const totalLoaded = ref(3) const categories = ref([ { @@ -75,6 +77,23 @@ const handleObjectSelection = (option) => { ra: target.ra, dec: target.dec })) + displayedTargets.value = objectSelection.value.targets.slice(0, 3) + totalLoaded.value = 3 +} + +const shuffleTargets = () => { + const allTargets = selectedTargets.value + // Shuffles the full list of targets and take the first 3 + const shuffled = allTargets.sort(() => Math.random() - 0.5).slice(0, 3) + displayedTargets.value = shuffled +} + +const loadMoreTargets = () => { + const allTargets = selectedTargets.value + // Calculates the new total of targets to load and stops at 15 or the total number of targets, whichever is smaller + const newTotalLoaded = Math.min(totalLoaded.value + 3, allTargets.length, 15) + displayedTargets.value = allTargets.slice(0, newTotalLoaded) + totalLoaded.value = newTotalLoaded } const emitSelections = () => { @@ -213,7 +232,7 @@ const handleExposuresUpdate = (exposures) => {

Requesting an Observation of a {{ objectSelection.object }}

-
+

{{ target.name }}

@@ -227,6 +246,8 @@ const handleExposuresUpdate = (exposures) => {
+ +

From 40e2016143d09a119397c32e0319696dd7056e39 Mon Sep 17 00:00:00 2001 From: Carolina Capetillo Date: Tue, 19 Nov 2024 15:47:54 -0800 Subject: [PATCH 2/4] deletes commented out code --- src/components/Scheduling/BeginnerScheduling.vue | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/Scheduling/BeginnerScheduling.vue b/src/components/Scheduling/BeginnerScheduling.vue index fb12bdd..ffd369a 100644 --- a/src/components/Scheduling/BeginnerScheduling.vue +++ b/src/components/Scheduling/BeginnerScheduling.vue @@ -97,7 +97,6 @@ const loadMoreTargets = () => { } const emitSelections = () => { - // if (targetSelection.value && exposureSettings.value.length > 0) { emits('selectionsComplete', { target: targetSelection.value, settings: exposureSettings.value, @@ -105,7 +104,6 @@ const emitSelections = () => { endDate: endDate.value, proposal: selectedProposal.value }) - // } } const handleTargetSelection = (target) => { From b5b69bae1e8c76399fa5fda63015dae881fac4cf Mon Sep 17 00:00:00 2001 From: Carolina Capetillo Date: Wed, 20 Nov 2024 10:43:21 -0800 Subject: [PATCH 3/4] fixes shuffling -- now it shuffles only within the same category --- .../Scheduling/BeginnerScheduling.vue | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/components/Scheduling/BeginnerScheduling.vue b/src/components/Scheduling/BeginnerScheduling.vue index ffd369a..f5a59d9 100644 --- a/src/components/Scheduling/BeginnerScheduling.vue +++ b/src/components/Scheduling/BeginnerScheduling.vue @@ -23,6 +23,7 @@ const endDate = ref('') const selectedProposal = ref() const displayedTargets = ref([]) const totalLoaded = ref(3) +const allCategoryTargets = ref({}) const categories = ref([ { @@ -67,7 +68,10 @@ const handleObjectSelection = (option) => { const filteredTargets = selectedTargets.value.filter( target => target.avmdesc.match(categoryRegex) - ).slice(0, 3) + ) + + // Store all targets for this category in allCategoryTargets + allCategoryTargets.value[option.object] = filteredTargets // Populate the targets for the selected object objectSelection.value.targets = filteredTargets.map(target => ({ @@ -82,17 +86,33 @@ const handleObjectSelection = (option) => { } const shuffleTargets = () => { - const allTargets = selectedTargets.value - // Shuffles the full list of targets and take the first 3 - const shuffled = allTargets.sort(() => Math.random() - 0.5).slice(0, 3) - displayedTargets.value = shuffled + const currentCategoryTargets = allCategoryTargets.value[objectSelection.value.object] || [] + if (currentCategoryTargets.length === 0) return + + // Shuffle the full list of targets for this category and take the first 3 + const shuffled = [...currentCategoryTargets].sort(() => Math.random() - 0.5).slice(0, 3) + displayedTargets.value = shuffled.map(target => ({ + name: target.name, + desc: target.desc, + filters: target.filters, + ra: target.ra, + dec: target.dec + })) } const loadMoreTargets = () => { - const allTargets = selectedTargets.value - // Calculates the new total of targets to load and stops at 15 or the total number of targets, whichever is smaller - const newTotalLoaded = Math.min(totalLoaded.value + 3, allTargets.length, 15) - displayedTargets.value = allTargets.slice(0, newTotalLoaded) + const currentCategoryTargets = allCategoryTargets.value[objectSelection.value.object] || [] + if (currentCategoryTargets.length === 0) return + + // Calculate the new total to load, up to a maximum of 15 or the total number of targets + const newTotalLoaded = Math.min(totalLoaded.value + 3, currentCategoryTargets.length, 15) + displayedTargets.value = currentCategoryTargets.slice(0, newTotalLoaded).map(target => ({ + name: target.name, + desc: target.desc, + filters: target.filters, + ra: target.ra, + dec: target.dec + })) totalLoaded.value = newTotalLoaded } From 5369fb9dd30d6bde4a41fb0552cac500fc4b9dd7 Mon Sep 17 00:00:00 2001 From: Carolina Capetillo Date: Wed, 20 Nov 2024 11:18:13 -0800 Subject: [PATCH 4/4] adds magic number --- src/components/Scheduling/BeginnerScheduling.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Scheduling/BeginnerScheduling.vue b/src/components/Scheduling/BeginnerScheduling.vue index f5a59d9..249e34e 100644 --- a/src/components/Scheduling/BeginnerScheduling.vue +++ b/src/components/Scheduling/BeginnerScheduling.vue @@ -105,7 +105,8 @@ const loadMoreTargets = () => { if (currentCategoryTargets.length === 0) return // Calculate the new total to load, up to a maximum of 15 or the total number of targets - const newTotalLoaded = Math.min(totalLoaded.value + 3, currentCategoryTargets.length, 15) + const maxNumberOfTargets = 15 + const newTotalLoaded = Math.min(totalLoaded.value + 3, currentCategoryTargets.length, maxNumberOfTargets) displayedTargets.value = currentCategoryTargets.slice(0, newTotalLoaded).map(target => ({ name: target.name, desc: target.desc,