diff --git a/src/components/Interactive.js b/src/components/Interactive.js index 9ba219db463f3dc15c3ff14fea76442992a3a822..b3508f3beaf43e391098e289588ba751960d6a54 100644 --- a/src/components/Interactive.js +++ b/src/components/Interactive.js @@ -2,5 +2,16 @@ import React from "react"; import { Alert } from "react-bootstrap"; export default function Interactive() { - return <Alert variant="info">This service is under development!</Alert>; + return ( + <Alert variant="warning"> + <p>You will leave ESAP GUI and be redirected to</p> + <a + target="_blank" + rel="noopener noreferrer" + href="http://130.246.212.44/escape/" + > + Interactive analysis platform hosted by SKAO + </a> + </Alert> + ); } diff --git a/src/components/query/ASTRONVOResults.js b/src/components/query/ASTRONVOResults.js index 7bd41157f72f5448803752f9e445745b833a4314..1a5735b385b6690444b403f2acf21d0739a5773a 100644 --- a/src/components/query/ASTRONVOResults.js +++ b/src/components/query/ASTRONVOResults.js @@ -8,9 +8,9 @@ export default function ASTRONVOResults({ catalog }) { const { queryMap } = useContext(QueryContext); if (!queryMap) return null; if (queryMap.get(catalog).status === "fetched") { - if (queryMap.get(catalog).results.query_results.length === 0) + if (queryMap.get(catalog).results.results.length === 0) return <Alert variant="warning">No matching results found!</Alert>; - console.log(queryMap.get(catalog).results.query_results); + console.log(queryMap.get(catalog).results.results); return ( <> <Table className="mt-3" responsive> @@ -32,7 +32,7 @@ export default function ASTRONVOResults({ catalog }) { </tr> </thead> <tbody> - {queryMap.get(catalog).results.query_results.map((result) => { + {queryMap.get(catalog).results.results.map((result) => { return ( <tr key={result.result}> {/* <th> diff --git a/src/components/query/ApertifResults.js b/src/components/query/ApertifResults.js index 358b874ea05ff21ff46b5787d572ecac4c37ce1d..b360f12e6653e6da0080e96407dcd16fbfc4f24f 100644 --- a/src/components/query/ApertifResults.js +++ b/src/components/query/ApertifResults.js @@ -8,12 +8,9 @@ export default function ApertifResults({ catalog }) { const { queryMap } = useContext(QueryContext); if (!queryMap) return null; if (queryMap.get(catalog).status === "fetched") { - if (queryMap.get(catalog).results.query_results.length === 0) + if (queryMap.get(catalog).results.results.length === 0) return <Alert variant="warning">No matching results found!</Alert>; - console.log( - "Query results:", - queryMap.get(catalog).results.query_results["query_results"] - ); + console.log("Query results:", queryMap.get(catalog).results.results); return ( <> <Table className="mt-3" responsive> @@ -35,7 +32,7 @@ export default function ApertifResults({ catalog }) { </tr> </thead> <tbody> - {queryMap.get(catalog).results.query_results.map((result) => { + {queryMap.get(catalog).results.results.map((result) => { return ( <tr key={result.PID}> {/* <th> diff --git a/src/components/query/QueryIVOARegistry.js b/src/components/query/QueryIVOARegistry.js index 52d664cfde2a43c1d96926aea7b79e83546379a6..cf1101a5d9266a9e42c8ac3a5eb7ca5e00351250 100644 --- a/src/components/query/QueryIVOARegistry.js +++ b/src/components/query/QueryIVOARegistry.js @@ -157,7 +157,11 @@ export default function QueryIVOARegistry() { {selectedRegistry.map((registry) => { const details = queryMap.get(registry); console.log("Details:", details); - return <VOServiceResults catalog={registry} />; + return ( + <div className="mt-3"> + <VOServiceResults catalog={registry} /> + </div> + ); })} </Container> ); @@ -207,7 +211,9 @@ export default function QueryIVOARegistry() { )} </Col> </Row> - <QueryResults catalog={catalog} /> + <div className="mt-3"> + <QueryResults catalog={catalog} /> + </div> </div> ); })} diff --git a/src/components/query/VOServiceResults.js b/src/components/query/VOServiceResults.js index af5fec62fd8b37b04d8c3f5112ae9e8fc35c09fb..0f9ee8c79bc649c1c5e2b91202a8dcea1c09145d 100644 --- a/src/components/query/VOServiceResults.js +++ b/src/components/query/VOServiceResults.js @@ -8,7 +8,7 @@ export default function VORegistryResults({ catalog }) { if (!queryMap.get(catalog)) return null; console.log("VO service queryMap:", queryMap.get(catalog)); if (queryMap.get(catalog).status === "fetched") { - if (queryMap.get(catalog).results.length === 0) + if (queryMap.get(catalog).results.results.length === 0) return <Alert variant="warning">No matching results found!</Alert>; return ( <div> @@ -20,7 +20,7 @@ export default function VORegistryResults({ catalog }) { </tr> </thead> <tbody> - {queryMap.get(catalog).results.query_results.map((result) => { + {queryMap.get(catalog).results.results.map((result) => { return ( <tr key={result.result}> <td> diff --git a/src/components/query/ZooniverseResults.js b/src/components/query/ZooniverseResults.js index f8814e4c5c3ab1cbc3c802750534604d9aa26591..69ff383d90af05b207d7549bfd45f6db2558ed42 100644 --- a/src/components/query/ZooniverseResults.js +++ b/src/components/query/ZooniverseResults.js @@ -1,25 +1,25 @@ -import React, { useContext, useState} from "react"; +import React, { useContext, useState } from "react"; import { Table, Alert } from "react-bootstrap"; import { QueryContext } from "../../contexts/QueryContext"; import LoadingSpinner from "../LoadingSpinner"; import Paginate, { pagination_fields } from "../Paginate"; const DATETIME_OPTIONS = { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: 'numeric', - minute: 'numeric', - second: 'numeric', + year: "numeric", + month: "long", + day: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", hour12: false, - timeZoneName: 'short' + timeZoneName: "short", }; -Object.isObject = function(obj) { - return (obj && obj.constructor === this) || false; +Object.isObject = function (obj) { + return (obj && obj.constructor === this) || false; }; -function renderArray(array, currentReactKey=""){ +function renderArray(array, currentReactKey = "") { return array.map((element, index) => { const updatedReactKey = `${currentReactKey}_${index}`; const separator = index < array.length - 1 ? ", " : ""; @@ -27,97 +27,132 @@ function renderArray(array, currentReactKey=""){ }); } -function renderObject(object, currentReactKey=""){ +function renderObject(object, currentReactKey = "") { return ( <Table key={currentReactKey + "_objTable"}> - <tbody> - {Object.entries(object).map(([key, value]) =>{ - const updatedReactKey=`${currentReactKey}_${key}`; - return( - <tr key={updatedReactKey}><td className="b">{key}</td><td>{renderIfCompound(value, updatedReactKey)}</td></tr> - ) - })} - </tbody> + <tbody> + {Object.entries(object).map(([key, value]) => { + const updatedReactKey = `${currentReactKey}_${key}`; + return ( + <tr key={updatedReactKey}> + <td className="b">{key}</td> + <td>{renderIfCompound(value, updatedReactKey)}</td> + </tr> + ); + })} + </tbody> </Table> - ) + ); } -function renderIfCompound(element, currentReactKey="", separatorForPod="", floatPrecision=3) { +function renderIfCompound( + element, + currentReactKey = "", + separatorForPod = "", + floatPrecision = 3 +) { if (Array.isArray(element)) { return renderArray(element, currentReactKey, separatorForPod); } else if (Object.isObject(element)) { return renderObject(element, currentReactKey, separatorForPod); } else if (typeof element === "boolean") { - return JSON.stringify(element) + separatorForPod - } else if (Number.isInteger(element)){ + return JSON.stringify(element) + separatorForPod; + } else if (Number.isInteger(element)) { return element.toString() + separatorForPod; } else { - try{ + try { return element.toFixed(floatPrecision) + separatorForPod; - } - catch(err){ - return `${element}` + separatorForPod + } catch (err) { + return `${element}` + separatorForPod; } } } function titleCase(string) { - var sentence = string.toLowerCase().split(" "); - for(var i = 0; i< sentence.length; i++){ - sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1); - } - return sentence.join(" "); - } + var sentence = string.toLowerCase().split(" "); + for (var i = 0; i < sentence.length; i++) { + sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1); + } + return sentence.join(" "); +} -function newPageCallback(setPage){ +function newPageCallback(setPage) { return (args) => { - if(args.target){ - setPage(parseFloat(args.target.text)); - } + if (args.target) { + setPage(parseFloat(args.target.text)); + } }; } -function ZooniverseProjectResults(context){ - const { queryMap, page, setPage } = context; - const date_formatter=new Intl.DateTimeFormat("default", DATETIME_OPTIONS); +function ZooniverseProjectResults(context) { + const { queryMap, page, setPage } = context; + const date_formatter = new Intl.DateTimeFormat("default", DATETIME_OPTIONS); const result = queryMap.get("zooniverse_projects").results.query_results[0]; const numPages = result.pages; - const mandatory_fields = ["launch_date", "created_at", "live", "updated_at", "project_id", "display_name", "slug"]; - const remaining_fields = Object.keys(result).filter(key => !(mandatory_fields.includes(key) || pagination_fields.includes(key))); + const mandatory_fields = [ + "launch_date", + "created_at", + "live", + "updated_at", + "project_id", + "display_name", + "slug", + ]; + const remaining_fields = Object.keys(result).filter( + (key) => + !(mandatory_fields.includes(key) || pagination_fields.includes(key)) + ); const remaining_headers = remaining_fields.map((field) => { - const title=titleCase(field.replace("_", " ")); - return (<th key={`project_header_${field}`}>{title}</th>); + const title = titleCase(field.replace("_", " ")); + return <th key={`project_header_${field}`}>{title}</th>; }); - return ( - <> - <Paginate getNewPage={newPageCallback(setPage)} currentPage={page} numAdjacent={3} numPages={numPages}/> - <Table className="mt-3" responsive> - <thead> - <tr className="bg-light"> - {/* <th> + return ( + <> + <Paginate + getNewPage={newPageCallback(setPage)} + currentPage={page} + numAdjacent={3} + numPages={numPages} + /> + <Table className="mt-3" responsive> + <thead> + <tr className="bg-light"> + {/* <th> <InputGroup> <InputGroup.Checkbox /> </InputGroup> </th> */} - <th>ID</th> - <th>Display Name</th> - <th>Created</th> - <th>Updated</th> - <th>Launched</th> - <th>Live</th> - <th>View</th> - {remaining_headers} - </tr> - </thead> - <tbody> - {queryMap.get("zooniverse_projects").results.query_results.map((result) => { - const launch_date = result.launch_date ? date_formatter.format(new Date(result.launch_date)) : "Not Launched"; - const created_at = date_formatter.format(new Date(result.created_at)); - const updated_at = date_formatter.format(new Date(result.updated_at)); - const live = result.live ? "Yes" : "No" + <th>ID</th> + <th>Display Name</th> + <th>Created</th> + <th>Updated</th> + <th>Launched</th> + <th>Live</th> + <th>View</th> + {remaining_headers} + </tr> + </thead> + <tbody> + {queryMap + .get("zooniverse_projects") + .results.query_results.map((result) => { + const launch_date = result.launch_date + ? date_formatter.format(new Date(result.launch_date)) + : "Not Launched"; + const created_at = date_formatter.format( + new Date(result.created_at) + ); + const updated_at = date_formatter.format( + new Date(result.updated_at) + ); + const live = result.live ? "Yes" : "No"; const remaining_cells = remaining_fields.map((field) => { const reactKey = `project_${result.project_id}_${field}`; - return (<td key={reactKey}>{renderIfCompound(result[field], reactKey)}</td>); + return ( + <td key={reactKey}> + {renderIfCompound(result[field], reactKey)} + </td> + ); }); return ( <tr key={`project_${result.project_id}`}> @@ -132,84 +167,122 @@ function ZooniverseProjectResults(context){ <td>{updated_at}</td> <td>{launch_date}</td> <td>{live}</td> - <td><a href={`https://zooniverse.org/projects/${result.slug}`}>Link</a></td> + <td> + <a href={`https://zooniverse.org/projects/${result.slug}`}> + Link + </a> + </td> {remaining_cells} </tr> ); })} - </tbody> - </Table> - <Paginate getNewPage={newPageCallback(setPage)} currentPage={page} numAdjacent={3} numPages={numPages}/> - </> - ); - + </tbody> + </Table> + <Paginate + getNewPage={newPageCallback(setPage)} + currentPage={page} + numAdjacent={3} + numPages={numPages} + /> + </> + ); } -function ZooniverseWorkflowResults(context){ - const { queryMap, page, setPage } = context; - let date_formatter=new Intl.DateTimeFormat("default", DATETIME_OPTIONS); +function ZooniverseWorkflowResults(context) { + const { queryMap, page, setPage } = context; + let date_formatter = new Intl.DateTimeFormat("default", DATETIME_OPTIONS); let result = queryMap.get("zooniverse_workflows").results.query_results[0]; let result_workflow = result.workflows[0]; const numPages = result.pages; - let mandatory_fields = ["created_at", "updated_at", "workflow_id", "display_name"]; - let remaining_fields = Object.keys(result_workflow).filter(key => !(mandatory_fields.includes(key) || pagination_fields.includes(key))); + let mandatory_fields = [ + "created_at", + "updated_at", + "workflow_id", + "display_name", + ]; + let remaining_fields = Object.keys(result_workflow).filter( + (key) => + !(mandatory_fields.includes(key) || pagination_fields.includes(key)) + ); let remaining_headers = remaining_fields.map((field) => { - let title=titleCase(field.replace("_", " ")); - return (<th key={`project_header_${field}`}>{title}</th>); + let title = titleCase(field.replace("_", " ")); + return <th key={`project_header_${field}`}>{title}</th>; }); - return ( - <> - <Paginate getNewPage={newPageCallback(setPage)} currentPage={page} numAdjacent={3} numPages={numPages}/> - {queryMap.get("zooniverse_workflows").results.query_results.map((project) => { - return (<div key={project.project_id}> - <h4>{project.display_name}</h4> - <Table className="mt-3" responsive> - <thead> - <tr className="bg-light"> - {/* <th> + return ( + <> + <Paginate + getNewPage={newPageCallback(setPage)} + currentPage={page} + numAdjacent={3} + numPages={numPages} + /> + {queryMap + .get("zooniverse_workflows") + .results.query_results.map((project) => { + return ( + <div key={project.project_id}> + <h4>{project.display_name}</h4> + <Table className="mt-3" responsive> + <thead> + <tr className="bg-light"> + {/* <th> <InputGroup> <InputGroup.Checkbox /> </InputGroup> </th> */} - <th>ID</th> - <th>Display Name</th> - <th>Created</th> - <th>Updated</th> - {remaining_headers} - {/* <th>View</th> */} - </tr> - </thead> - <tbody> - {project.workflows.map((workflow) => { - let created_at = date_formatter.format(new Date(workflow.created_at)); - let updated_at = date_formatter.format(new Date(workflow.updated_at)); - let remaining_cells = remaining_fields.map((field) => { - let reactKey = `workflow_${workflow.workflow_id}_${field}`; - return (<td key={reactKey}>{renderIfCompound(workflow[field], reactKey)}</td>); - }); - return ( - <tr key={`workflow_${workflow.workflow_id}`}> - {/* <th> + <th>ID</th> + <th>Display Name</th> + <th>Created</th> + <th>Updated</th> + {remaining_headers} + {/* <th>View</th> */} + </tr> + </thead> + <tbody> + {project.workflows.map((workflow) => { + let created_at = date_formatter.format( + new Date(workflow.created_at) + ); + let updated_at = date_formatter.format( + new Date(workflow.updated_at) + ); + let remaining_cells = remaining_fields.map((field) => { + let reactKey = `workflow_${workflow.workflow_id}_${field}`; + return ( + <td key={reactKey}> + {renderIfCompound(workflow[field], reactKey)} + </td> + ); + }); + return ( + <tr key={`workflow_${workflow.workflow_id}`}> + {/* <th> <InputGroup> <InputGroup.Checkbox /> </InputGroup> </th> */} - <td>{workflow.workflow_id}</td> - <td>{workflow.display_name}</td> - <td>{created_at}</td> - <td>{updated_at}</td> - {remaining_cells} - {/* <td><a href={`https://zooniverse.org/workflows/${workflow.slug}`}>Link</a></td> */} - </tr> - ); - })} - </tbody> - </Table> - </div>); + <td>{workflow.workflow_id}</td> + <td>{workflow.display_name}</td> + <td>{created_at}</td> + <td>{updated_at}</td> + {remaining_cells} + {/* <td><a href={`https://zooniverse.org/workflows/${workflow.slug}`}>Link</a></td> */} + </tr> + ); + })} + </tbody> + </Table> + </div> + ); })} - <Paginate getNewPage={newPageCallback(setPage)} currentPage={page} numAdjacent={3} numPages={numPages}/> - </> - ); + <Paginate + getNewPage={newPageCallback(setPage)} + currentPage={page} + numAdjacent={3} + numPages={numPages} + /> + </> + ); } export default function ZooniverseResults({ catalog }) { @@ -218,13 +291,11 @@ export default function ZooniverseResults({ catalog }) { if (context.queryMap.get(catalog).status === "fetched") { if (context.queryMap.get(catalog).results.query_results.length === 0) return <Alert variant="warning">No matching results found!</Alert>; - else if (catalog === "zooniverse_projects"){ + else if (catalog === "zooniverse_projects") { return ZooniverseProjectResults(context); - } - else if (catalog === "zooniverse_workflows"){ + } else if (catalog === "zooniverse_workflows") { return ZooniverseWorkflowResults(context); - } - else { + } else { return <Alert variant="warning">Unrecognised Zooniverse Catalog!</Alert>; } } else { diff --git a/src/contexts/GlobalContext.js b/src/contexts/GlobalContext.js index 61b79c52071c3c5bcbf21721ac0e2e6d4984340a..d8c42dcfbba472643df6364b482f3c14dfd3a148 100644 --- a/src/contexts/GlobalContext.js +++ b/src/contexts/GlobalContext.js @@ -5,7 +5,7 @@ import getCookie from "../utils/getCookie"; export const GlobalContext = createContext(); export function GlobalContextProvider({ children }) { - console.log("ASTRON ESAP version 14 aug 2020"); + console.log("ASTRON ESAP version ", Date()); const api_host = process.env.NODE_ENV === "development" ? "http://sdc.astron.nl:5555/esap-api/" diff --git a/src/utils/form/parseADEXForm.js b/src/utils/form/parseADEXForm.js index d2f9460dc23fc6ea74995f1f051a881a8590194f..351fabef237b4d6f60208855092efa1e64e4060b 100644 --- a/src/utils/form/parseADEXForm.js +++ b/src/utils/form/parseADEXForm.js @@ -6,7 +6,7 @@ export default function ParseADEXForm(formData) { // "esapquery": "querystring"} let query = ""; let formInput = Object.entries(formData); - console.log(formInput); + console.log("formInput:", formInput); for (let [key, value] of formInput) { console.log(`${key}: ${value}`); diff --git a/src/utils/form/parseASTRONVOForm.js b/src/utils/form/parseASTRONVOForm.js index 8724fc5aabc2c2c9d2a6cda65687d5f6d5b78b1d..9162c828a9635cabe750e5dbbcccfd933dc8ea4c 100644 --- a/src/utils/form/parseASTRONVOForm.js +++ b/src/utils/form/parseASTRONVOForm.js @@ -5,7 +5,7 @@ export default function ParseASTRONVOForm(formData) { // "esapquery": "querystring"} let query = ""; let formInput = Object.entries(formData); - console.log(formInput); + console.log("formInput:", formInput); for (let [key, value] of formInput) { console.log(`${key}: ${value}`); diff --git a/src/utils/form/parseVOServiceForm.js b/src/utils/form/parseVOServiceForm.js index eba08e89669973ab4b34f26102346630503ad5ca..c42aec9a71378c01d5b44ba9d9e675ff0b09abf9 100644 --- a/src/utils/form/parseVOServiceForm.js +++ b/src/utils/form/parseVOServiceForm.js @@ -12,14 +12,16 @@ export default function ParseVOServiceForm(formData, access_url) { for (let [key, value] of formInput) { console.log(`${key}: ${value}`); - if (value && value !== "all" && key !== "catalog") { + // Ignore value of keyword from get-services query, in this step keyword will not be used. + if (value && value !== "all" && key !== "catalog" && key !== "keyword") { query += `${`${query}` ? "&" : ""}` + key + "=" + value; } } query += `${`${query}` ? "&" : ""}` + "access_url=" + access_url; console.log("Query:", query); - // If catalog is set to "all", query for each catalog needs to be generated {"catalog": "catalogname", + // If catalog is set to "all", query for each catalog needs to be generated + // {"catalog": "catalogname", // "catalogquery": "querystring", // "status": "null|fetching|fetched", // "results": null} @@ -27,7 +29,7 @@ export default function ParseVOServiceForm(formData, access_url) { let service_type = formInput.find(([key]) => key === "service_type")[1]; let esapquery = - "run-query/?" + query + `${`${query}` ? "&" : ""}dataset_uri=` + catalog; + "query/?" + query + `${`${query}` ? "&" : ""}dataset_uri=` + catalog; queries.push({ catalog: access_url,