Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Althome #652

Merged
merged 5 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions frontend/components/Admin/Theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import { useState } from 'react';
import Loader from 'react-loader-spinner';
import { useEffect } from 'react';
import { useSelector } from 'react-redux';
import { isValidURI } from '../Viewing/Shell';
const { publicRuntimeConfig } = getConfig();

export default function Theme() {
const dispatch = useDispatch();
const { theme, loading } = useTheme(dispatch);
const [instanceName, setInstanceName] = useState(''); // default to empty
const [frontPageText, setFrontPageText] = useState(''); // default to empty
const [altHome, setAltHome] = useState('');
const [baseColor, setBaseColor] = useState('');
const [logoFile, setLogoFile] = useState(null);
const [showModuleInteractions, setShowModuleInteractions] = useState(true);
Expand All @@ -27,6 +29,7 @@ export default function Theme() {
if (theme) {
setInstanceName(theme.instanceName);
setFrontPageText(theme.frontPageText);
setAltHome(theme.altHome);
}
}, [theme]);

Expand Down Expand Up @@ -57,16 +60,20 @@ export default function Theme() {
'X-authorization': token
};

if (altHome !== '' && !isValidURI(altHome)) {
alert('Alternate Home Page must be empty or contain a valid URL.');
return; // Prevent form submission
}

const formData = new FormData();
formData.append('instanceName', instanceName);
formData.append('frontPageText', frontPageText);
formData.append('altHome', altHome);
formData.append('baseColor', baseColor);
if (logoFile) {
formData.append('logo', logoFile);
}

console.log('this is a test');

try {
const response = await fetch(url, { method: 'POST', headers: headers, body: formData });
const data = await response.text();
Expand Down Expand Up @@ -116,6 +123,13 @@ export default function Theme() {
rows={10} // Number of rows
cols={100} // Number of columns
/>
<div>Alternate Home Page</div>
<input
type="text"
value={altHome}
onChange={(e) => setAltHome(e.target.value)}
style={{ width: '600px' }}
/>

<div>Color Settings</div>
<table className={styles.table}>
Expand Down
8 changes: 7 additions & 1 deletion frontend/components/Navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ export default function Navbar() {
);
}, [loggedIn]);

console.log(theme);
let linkHref = "/";
if (theme && theme.altHome && theme.altHome.length > 0) {
linkHref = theme.altHome;
}

return (
<header className={styles.container}
style={{ backgroundColor: theme?.themeParameters?.[0]?.value || '#465775' }}
>

<div className={styles.logoAndInstanceContainer}> {/* This is your new div container */}
<Link href="/">
<Link href={linkHref}>
<a className={styles.logo}>
<Image alt="logo" width={80} height={80} src="/images/logo.svg" />
{/* <Image alt="logo" width={80} height={80} src="/images/widevibe.gif" /> */}
Expand Down
7 changes: 6 additions & 1 deletion frontend/components/Search/NavbarSearch/NavbarSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ export default function NavbarSearch(properties) {
const pageVisited = useSelector(state => state.tracking.pageVisited);
const { theme, loading } = useTheme();

let linkHref = "/";
if (theme && theme.altHome && theme.altHome.length > 0) {
linkHref = theme.altHome;
}

return (
<header className={styles.container}
style={{ backgroundColor: theme?.themeParameters?.[0]?.value || '#465775' }}
>
<Link href="/">
<Link href={linkHref}>
<a className={styles.logo}>
<Image alt="logo" width={86} height={86} src="/images/logo.svg" />
</a>
Expand Down
2 changes: 1 addition & 1 deletion frontend/public/commitHash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f6f9da07901a90dad77c15690464facfc1fa8e67
50e52732439c53176be416e5f359560e01e328bd
16 changes: 11 additions & 5 deletions frontend/specialAccess/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SubmitLabel from '../components/Submit/ReusableComponents/SubmitLabel';
import getConfig from 'next/config';
import { useDispatch } from 'react-redux';
import { addError } from '../redux/actions';
import { isValidURI } from '../components/Viewing/Shell';
import axios from 'axios';
const { publicRuntimeConfig } = getConfig();

Expand Down Expand Up @@ -139,13 +140,14 @@ export default function Setup({ setInSetupMode }) {
/>

<InputField
labelText="Alternate Home Page: If you would like to set your own version of the home page, set the uri here. For example, typing https://mysynbiohub.org, would make this the default page, while mysynbiohub, would make https://synbiohub.org/mysynbiohub the default page."
labelText="Alternate Home Page: If you would like to set your own version of the home page, set the uri here. For example, typing https://mysynbiohub.org would make this the default page, while mysynbiohub would make https://synbiohub.org/mysynbiohub the default page."
placeholder="Alternate Home Page"
value={altHome}
onChange={event => setAltHome(event.target.value)}
inputName="Alternate Home Page"
containerStyling={styles.inputcontainer}
/>

</div>
}
/>
Expand Down Expand Up @@ -221,6 +223,10 @@ export default function Setup({ setInSetupMode }) {
'Content-Type': 'application/json',
Accept: 'text/plain'
};
if (altHome !== '' && !isValidURI(altHome)) {
setErrors(['Alternate Home Page must either be empty or contain a valid URL.']);
return; // Prevent the submission
}
try {
await axios.post(
`${publicRuntimeConfig.backend}/setup`,
Expand All @@ -240,18 +246,18 @@ export default function Setup({ setInSetupMode }) {
virtuosoINI: '/etc/virtuoso-opensource-7/virtuoso.ini',
virtuosoDB: '/var/lib/virtuoso-opensource-7/db',
allowPublicSignup,
altHome
altHome, // This can now be either a valid URL or an empty string
},
{
headers
headers,
}
);
setErrors([]);
setInSetupMode(false);
} catch (error) {
if (error.response.status === 400) {
if (error.response?.status === 400) {
const errorMessages = error.response.data.details.map(
error => error.message
(err) => err.message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? Seems like it should be error?

);
setErrors(errorMessages);
return;
Expand Down
Loading