From 17a3c49265f86fc6ab5a9aca626004d7389ab46b Mon Sep 17 00:00:00 2001 From: Ben Green Date: Mon, 21 Oct 2024 17:46:04 +0100 Subject: [PATCH 1/9] UI improvement and acceptance of Sxgml units in the targets definition model, sexagesimal units can now be used directly in the definition dialogue. --- .../src/ProposalEditorView/targets/New.tsx | 97 ++++++++++++++----- .../targets/TargetTable.tsx | 12 +-- 2 files changed, 80 insertions(+), 29 deletions(-) diff --git a/src/main/webui/src/ProposalEditorView/targets/New.tsx b/src/main/webui/src/ProposalEditorView/targets/New.tsx index be02f613..6cbd2711 100644 --- a/src/main/webui/src/ProposalEditorView/targets/New.tsx +++ b/src/main/webui/src/ProposalEditorView/targets/New.tsx @@ -34,6 +34,7 @@ import {notifyError, notifySuccess} from "../../commonPanel/notifications.tsx"; import getErrorMessage from "../../errorHandling/getErrorMessage.tsx"; import {SimbadSearch} from "./simbadSearch.tsx"; import SimbadSearchHelp from "./simbadSearchHelp.tsx"; +import { AstroLib } from "@tsastro/astrolib"; export let Aladin: AladinType; @@ -88,8 +89,8 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { const form = useForm({ initialValues: { TargetName: "", - RA: 0.00, - Dec: 0.00, + RA: "0.00", + Dec: "0.00", SelectedEpoch: "J2000", sexagesimal: "00:00:00 +00:00:00" }, @@ -190,8 +191,20 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { const HandleEvent = (event: MouseEvent) => { const [ra, dec] = GetOffset(event); const [raCoords, decCoords] = Aladin.pix2world(ra, dec); - form.setFieldValue('RA', raCoords); - form.setFieldValue('Dec', decCoords); + form.setFieldValue('RA', raCoords.toString()); + form.setFieldValue('Dec', decCoords.toString()); + + //BJLG + //reset the name to something generic + random suffix + let targetProxyName = "Target_"; + let randNum = Math.random(); + //convert the number into something using chars 0-9 A-Z + let hexString = randNum.toString(36); + targetProxyName += hexString.slice(6).toUpperCase(); + form.setFieldValue('TargetName', targetProxyName); + + //allow submission in case this was previously locked + setNameUnique(true); } /** @@ -200,7 +213,7 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { */ const UpdateAladinRA = (value: number | string) => { // acquire the aladin object and set it. - Aladin.gotoRaDec(value as number, form.values.Dec); + Aladin.gotoRaDec(value as number, Number(form.values.Dec)); } /** @@ -209,7 +222,7 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { */ const UpdateAladinDec = (value: number | string) => { // acquire the aladin object and set it. - Aladin.gotoRaDec(form.values.RA, value as number); + Aladin.gotoRaDec(Number(form.values.RA), value as number); } const responsiveSpan = {base: 2, md: 1} @@ -244,37 +257,75 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { }} /> - { - UpdateAladinRA(e); if (form.getInputProps("RA").onChange) { form.getInputProps("RA").onChange(e); - }}} + } + //get the live value from the input + let raValue: string = form.getValues()["RA"]; + + //we assume + or - for sexagesimal unit - REPLACE this with appropriate regex + if(raValue.indexOf("+") >= 0 || raValue.indexOf("-") >= 0 ) + { + //convert Sexagemsimal to degrees (Sxg representation is displayed separately) + raValue = AstroLib.HmsToDeg(raValue); + //update the value to degrees + form.setFieldValue("RA", raValue); + } + //update the Aladdin viewport + UpdateAladinRA(Number(raValue)); + }} + + /> - + {AstroLib.DegToHms(form.getValues()["RA"])} + + { - UpdateAladinDec(e); if (form.getInputProps("Dec").onChange) { form.getInputProps("Dec").onChange(e); - }}} + } + //get the live value from the input + let decValue: string = form.getValues()["Dec"]; + + //we assume + or - for sexagesimal unit - REPLACE this with appropriate regex + if(decValue.indexOf("+") >= 0 || decValue.indexOf("-") >= 0 ) + { + //convert Sexagemsimal to degrees (Sxg representation is displayed separately) + decValue = AstroLib.DmsToDeg(decValue); + //update the value to degrees + form.setFieldValue("Dec", decValue); + } + //update the Aladdin viewport + UpdateAladinDec(Number(decValue)); + }} /> + + {AstroLib.DegToDms(form.getValues()["Dec"])} + Date: Tue, 22 Oct 2024 19:56:04 +0100 Subject: [PATCH 2/9] smarter naming management for target identification --- .../src/ProposalEditorView/targets/New.tsx | 52 +++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/main/webui/src/ProposalEditorView/targets/New.tsx b/src/main/webui/src/ProposalEditorView/targets/New.tsx index 6cbd2711..992a0383 100644 --- a/src/main/webui/src/ProposalEditorView/targets/New.tsx +++ b/src/main/webui/src/ProposalEditorView/targets/New.tsx @@ -118,11 +118,11 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { coordSys: {val: "ICRS"}, lat: { "@type": "ivoa:RealQuantity", - value: val.RA, unit: { value: "degrees" } + value: parseFloat(val.RA), unit: { value: "degrees" } }, lon: { "@type": "ivoa:RealQuantity", - value: val.Dec, unit: { value: "degrees" } + value: parseFloat(val.Dec), unit: { value: "degrees" } } } const Target: CelestialTarget = { @@ -194,6 +194,25 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { form.setFieldValue('RA', raCoords.toString()); form.setFieldValue('Dec', decCoords.toString()); + //we want to update the name if there is no entry OR if the entry is from the catalogue + if (form.values["TargetName"].slice(0,6) != "Target" && form.values["TargetName"].slice(0,8) != "Modified") + { + //if we have a catalogue name, modify it to show that the target has moved + if(form.values["TargetName"] != ""){ + ModifyTargetName(form.values["TargetName"]); + } + //if we have no name, add one + else{ + GenerateTargetDefaultName(); + } + + } + } + + /** + * generate new default name for a target + */ + const GenerateTargetDefaultName = () => { //BJLG //reset the name to something generic + random suffix let targetProxyName = "Target_"; @@ -206,6 +225,22 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { //allow submission in case this was previously locked setNameUnique(true); } + /** + * modify the name for a target + */ + const ModifyTargetName = (currentName :string) => { + //BJLG + //reset the name to something generic + random suffix + let targetProxyName = "Modified " + currentName + "_"; + let randNum = Math.random(); + //convert the number into something using chars 0-9 A-Z + let hexString = randNum.toString(36); + targetProxyName += hexString.slice(6).toUpperCase(); + form.setFieldValue('TargetName', targetProxyName); + + //allow submission in case this was previously locked + setNameUnique(true); + } /** * updates the aladin viewer to handle changes to RA. @@ -281,6 +316,12 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { raValue = AstroLib.HmsToDeg(raValue); //update the value to degrees form.setFieldValue("RA", raValue); + + } + //if we don't have a name for this object, generate one + if(form.values["TargetName"] == "") + { + GenerateTargetDefaultName(); } //update the Aladdin viewport UpdateAladinRA(Number(raValue)); @@ -316,7 +357,12 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { decValue = AstroLib.DmsToDeg(decValue); //update the value to degrees form.setFieldValue("Dec", decValue); - } + } + //if we don't have a name for this object, generate one + if(form.values["TargetName"] == "") + { + GenerateTargetDefaultName(); + } //update the Aladdin viewport UpdateAladinDec(Number(decValue)); }} From 82791766b020bbd3d2f167116a737d4b0311b41f Mon Sep 17 00:00:00 2001 From: Ben Green Date: Wed, 23 Oct 2024 15:30:12 +0100 Subject: [PATCH 3/9] more appropriate identification of sexagesimal units --- src/main/webui/src/ProposalEditorView/targets/New.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/webui/src/ProposalEditorView/targets/New.tsx b/src/main/webui/src/ProposalEditorView/targets/New.tsx index 992a0383..8a4b4e77 100644 --- a/src/main/webui/src/ProposalEditorView/targets/New.tsx +++ b/src/main/webui/src/ProposalEditorView/targets/New.tsx @@ -309,14 +309,14 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { //get the live value from the input let raValue: string = form.getValues()["RA"]; - //we assume + or - for sexagesimal unit - REPLACE this with appropriate regex - if(raValue.indexOf("+") >= 0 || raValue.indexOf("-") >= 0 ) + const regexp = new RegExp(/(\d{1,3})\D(\d{1,2})\D(\d{1,2}(\.\d+)[sS]*)/); + //first filter to ensure input is at least in the ball park of sensible + if(regexp.test(raValue)) { //convert Sexagemsimal to degrees (Sxg representation is displayed separately) raValue = AstroLib.HmsToDeg(raValue); //update the value to degrees form.setFieldValue("RA", raValue); - } //if we don't have a name for this object, generate one if(form.values["TargetName"] == "") @@ -350,8 +350,9 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { //get the live value from the input let decValue: string = form.getValues()["Dec"]; - //we assume + or - for sexagesimal unit - REPLACE this with appropriate regex - if(decValue.indexOf("+") >= 0 || decValue.indexOf("-") >= 0 ) + const regexp = new RegExp(/(\d{1,2})\D(\d{1,2})\D(\d{1,2}(\.\d+)[sS]*)/); + //first filter to ensure input is at least in the ball park of sensible + if(regexp.test(decValue)) { //convert Sexagemsimal to degrees (Sxg representation is displayed separately) decValue = AstroLib.DmsToDeg(decValue); From 0df54ad5b60675ee715eb08857d241a53e1b1a9c Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Thu, 24 Oct 2024 15:38:53 +0100 Subject: [PATCH 4/9] added missing @tsastro/astrolib to the dependencies --- src/main/webui/package-lock.json | 29 +++++++++++++++++++++++++++++ src/main/webui/package.json | 1 + 2 files changed, 30 insertions(+) diff --git a/src/main/webui/package-lock.json b/src/main/webui/package-lock.json index 98e00bee..d255a509 100644 --- a/src/main/webui/package-lock.json +++ b/src/main/webui/package-lock.json @@ -17,6 +17,7 @@ "@popperjs/core": "^2.11.8", "@tabler/icons-react": "^2.34.0", "@tanstack/react-query": "^5.28.8", + "@tsastro/astrolib": "^0.2.0", "@types/prismjs": "^1.26.4", "@types/react-latex": "^2.0.3", "@types/react-syntax-highlighter": "^15.5.13", @@ -527,6 +528,12 @@ "node": ">=6.9.0" } }, + "node_modules/@buge/ts-units": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@buge/ts-units/-/ts-units-1.2.3.tgz", + "integrity": "sha512-3aatF0mnIxZBMkL2EkKnOEbVAFeZR8oCUwXNTUyOv7hxeCuA8fycVWaVWBiAWdnmMTmLL5KAgzMiQ0MreuaYJg==", + "license": "Apache-2.0" + }, "node_modules/@esbuild/android-arm": { "version": "0.18.20", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", @@ -2122,6 +2129,22 @@ "@testing-library/dom": ">=7.21.4" } }, + "node_modules/@tsastro/astrolib": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@tsastro/astrolib/-/astrolib-0.2.0.tgz", + "integrity": "sha512-vzpmXWpY43a6Zmh4x4M9kkeQnZG0yBpghe73eyQ0B3SpuAFjBpGOgMiKtqq7UefrAvxVMzmnoMxTIclXaPM62Q==", + "dependencies": { + "@buge/ts-units": "^1.2.3", + "@tsastro/tsofa": "^18.1.0", + "common-js": "^0.3.8" + } + }, + "node_modules/@tsastro/tsofa": { + "version": "18.1.0", + "resolved": "https://registry.npmjs.org/@tsastro/tsofa/-/tsofa-18.1.0.tgz", + "integrity": "sha512-P9PSt8KGlA8azf+3181IewkkbcmhvbpsKXRhjqw5qoRgcTYGhfGW80xnm3FWcA0rUGdfB5sPvmE2J/kOLX5AGQ==", + "license": "MIT" + }, "node_modules/@types/aria-query": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-4.2.2.tgz", @@ -3354,6 +3377,12 @@ "node": ">= 12" } }, + "node_modules/common-js": { + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/common-js/-/common-js-0.3.8.tgz", + "integrity": "sha512-83poCK3wlRnYqWdolJiYrMYvaBFzlDO1RwQVti2ZDBR2K5ifBGksu2cw3ZKFioEqB8FVLUmuu3OXxFUlSBk5UQ==", + "license": "MIT" + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", diff --git a/src/main/webui/package.json b/src/main/webui/package.json index a61d8606..99c8c4f3 100644 --- a/src/main/webui/package.json +++ b/src/main/webui/package.json @@ -5,6 +5,7 @@ "type": "module", "homepage": "https://kilburn.jb.man.ac.uk/pst/gui/", "dependencies": { + "@tsastro/astrolib": "^0.2.0", "@mantine/core": "^7.13.1", "@mantine/dates": "^7.13.1", "@mantine/form": "^7.13.1", From 5caf9b8f2d4d6a6c11383f7c474784162ae74244 Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Thu, 24 Oct 2024 15:48:58 +0100 Subject: [PATCH 5/9] corrected the type handling --- src/main/webui/src/ProposalEditorView/targets/New.tsx | 10 +++++----- .../src/ProposalEditorView/targets/TargetTable.tsx | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/webui/src/ProposalEditorView/targets/New.tsx b/src/main/webui/src/ProposalEditorView/targets/New.tsx index 8a4b4e77..e86f63e9 100644 --- a/src/main/webui/src/ProposalEditorView/targets/New.tsx +++ b/src/main/webui/src/ProposalEditorView/targets/New.tsx @@ -1,4 +1,4 @@ -import {Modal, NumberInput, TextInput, Stack, Fieldset, Grid, rem, Text} from "@mantine/core"; +import {Modal, TextInput, Stack, Fieldset, Grid, rem, Text} from "@mantine/core"; import {useForm} from "@mantine/form"; import {useDisclosure, useMediaQuery} from "@mantine/hooks"; import { @@ -314,7 +314,7 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { if(regexp.test(raValue)) { //convert Sexagemsimal to degrees (Sxg representation is displayed separately) - raValue = AstroLib.HmsToDeg(raValue); + raValue = String(AstroLib.HmsToDeg(raValue)); //update the value to degrees form.setFieldValue("RA", raValue); } @@ -332,7 +332,7 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { - {AstroLib.DegToHms(form.getValues()["RA"])} + {AstroLib.DegToHms(Number(form.getValues()["RA"]))} void}): ReactElement => { if(regexp.test(decValue)) { //convert Sexagemsimal to degrees (Sxg representation is displayed separately) - decValue = AstroLib.DmsToDeg(decValue); + decValue = String(AstroLib.DmsToDeg(decValue)); //update the value to degrees form.setFieldValue("Dec", decValue); } @@ -371,7 +371,7 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { - {AstroLib.DegToDms(form.getValues()["Dec"])} + {AstroLib.DegToDms(Number(form.getValues()["Dec"]))} Date: Thu, 24 Oct 2024 16:07:29 +0100 Subject: [PATCH 6/9] restrict the precision to something more reasonable --- src/main/webui/src/ProposalEditorView/targets/New.tsx | 4 ++-- src/main/webui/src/ProposalEditorView/targets/TargetTable.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/webui/src/ProposalEditorView/targets/New.tsx b/src/main/webui/src/ProposalEditorView/targets/New.tsx index e86f63e9..83fb7ea8 100644 --- a/src/main/webui/src/ProposalEditorView/targets/New.tsx +++ b/src/main/webui/src/ProposalEditorView/targets/New.tsx @@ -332,7 +332,7 @@ const TargetForm = (props: {closeModal: () => void}): ReactElement => { - {AstroLib.DegToHms(Number(form.getValues()["RA"]))} + {AstroLib.DegToHms(Number(form.getValues()["RA"]),3)} void}): ReactElement => { - {AstroLib.DegToDms(Number(form.getValues()["Dec"]))} + {AstroLib.DegToDms(Number(form.getValues()["Dec"]),3)} Date: Thu, 24 Oct 2024 16:12:32 +0100 Subject: [PATCH 7/9] update node --- .github/workflows/gradle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c4707134..7029433a 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -42,7 +42,7 @@ jobs: - name: setup Node/npm uses: actions/setup-node@v4 with: - node-version: 18 + node-version: 22 cache: 'npm' cache-dependency-path: 'main/src/main/webui/package-lock.json' From ac2ecf3eee0949bba32882fe39dc32f23786899a Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Thu, 24 Oct 2024 16:27:47 +0100 Subject: [PATCH 8/9] update module type more cargo-cult as for some reason this is not finding the @tsastro stuff in CI on github --- src/main/webui/tsconfig.node.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/webui/tsconfig.node.json b/src/main/webui/tsconfig.node.json index 0118c27e..a3956db0 100644 --- a/src/main/webui/tsconfig.node.json +++ b/src/main/webui/tsconfig.node.json @@ -4,8 +4,8 @@ "jsx": "react", "composite": true, "skipLibCheck": true, - "module": "ESNext", - "moduleResolution": "node", + "module": "NodeNext", + "moduleResolution": "NodeNext", "allowSyntheticDefaultImports": true }, "include": ["vite.config.ts"] From 4cbe28940c09bb0743158258d99d3914b98d6c2d Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Thu, 24 Oct 2024 16:37:25 +0100 Subject: [PATCH 9/9] update module resolution type more cargo-cult as for some reason this is not finding the @tsastro stuff in CI on github --- src/main/webui/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webui/tsconfig.json b/src/main/webui/tsconfig.json index 6e35fee8..cffbce1c 100644 --- a/src/main/webui/tsconfig.json +++ b/src/main/webui/tsconfig.json @@ -13,7 +13,7 @@ "allowJs": true, /* Bundler mode */ - "moduleResolution": "node", + "moduleResolution": "Bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true,