Skip to content

Commit

Permalink
Merge pull request #2094 from Inist-CNRS/feat/theme/config-autocomplete
Browse files Browse the repository at this point in the history
Theme config autocomplete
  • Loading branch information
parmentf authored Jul 18, 2024
2 parents a5c57c6 + 068760c commit 830ad21
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/api/models/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const getAvailableThemes = () => {
value,
name: theme.name,
description: theme.description,
defaultVariables: theme.customTemplateVariables,
});
});
return toReturn;
Expand Down
72 changes: 36 additions & 36 deletions src/app/custom/themes/voscouleurs/lodex-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@
"version": "6",
"licence": "CeCILL",
"name": {
"fr": "voscouleurs",
"en": "yourcolors"
"fr": "Voscouleurs",
"en": "Voscouleurs"
},
"description": {
"fr": "Theme personnalisable",
"en": "customizable Theme"
"fr": "Thème personnalisable",
"en": "Customizable theme"
},
"configuration": {
"files": {
"index": "index.ejs",
"palette": ""
}
},
"variables": {
"siteTitle": "titre du site",
"summary": "promesse du site",
"logo": {
"file": "path vers le fichier du logo",
"alt": "nom de l'organisme",
"url": "url de l'organisme",
"size": "100"
},
"font": {
"family": "",
"title": ""
},
"color": {
"themePrimary": "",
"themeSecondary": "",
"themeRGBA": "",
"bgBody": "#fff",
"bgHeader": "",
"headerTitle": "",
"bgContent": "",
"bgFacet": "",
"titles": "",
"titleGraph": "",
"text": "",
"icon": "",
"iconHover": "",
"button": "",
"buttonHover": "",
"textContrast": "",
"bgContrast": ""
"variables": {
"siteTitle": "titre du site",
"summary": "promesse du site",
"logo": {
"file": "path vers le fichier du logo",
"alt": "nom de l'organisme",
"url": "url de l'organisme",
"size": "100"
},
"font": {
"family": "",
"title": ""
},
"color": {
"themePrimary": "",
"themeSecondary": "",
"themeRGBA": "",
"bgBody": "#fff",
"bgHeader": "",
"headerTitle": "",
"bgContent": "",
"bgFacet": "",
"titles": "",
"titleGraph": "",
"text": "",
"icon": "",
"iconHover": "",
"button": "",
"buttonHover": "",
"textContrast": "",
"bgContrast": ""
}
}
}
}
41 changes: 37 additions & 4 deletions src/app/js/admin/configTenant/ConfigTenantForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const ConfigTenantForm = ({
history,
onLoadConfigTenant,
}) => {
const [initialConfig, setInitialConfig] = useState('');
const [configTenant, setConfigTenant] = useState('');
const [enableAutoPublication, setEnableAutoPublication] = useState(false);
const [userAuth, setUserAuth] = useState({});
Expand All @@ -61,6 +62,7 @@ export const ConfigTenantForm = ({
const [theme, setTheme] = useState('default');
const [themes, setThemes] = useState([
{
defaultVariables: {},
name: {
fr: 'Classique',
en: 'Classic',
Expand Down Expand Up @@ -88,6 +90,7 @@ export const ConfigTenantForm = ({
delete response.theme;

const stringified = JSON.stringify(response, null, 2);
setInitialConfig(stringified);
setConfigTenant(stringified);

const themesResponse = await getConfigTenantAvailableTheme();
Expand Down Expand Up @@ -132,6 +135,39 @@ export const ConfigTenantForm = ({
setConfigTenant(newConfigTenant);
};

const handleThemeChange = (event) => {
setIsFormModified(true);
setTheme(event.target.value);

try {
const themeValue = themes.find(
(value) => value.value === event.target.value,
);

try {
const parsedConfig = JSON.parse(configTenant);

if (parsedConfig.front) {
parsedConfig.front.theme = themeValue.defaultVariables;
}

setConfigTenant(JSON.stringify(parsedConfig, null, 2));
} catch (_) {
// If we can't parse the actual config fallback to the initial

const parsedConfig = JSON.parse(initialConfig);

if (parsedConfig.front) {
parsedConfig.front.theme = themeValue.defaultVariables;
}

setConfigTenant(JSON.stringify(parsedConfig, null, 2));
}
} catch (_) {
/* empty */
}
};

return (
<Box className="container">
<h1>{polyglot.t('config_tenant')}</h1>
Expand Down Expand Up @@ -213,10 +249,7 @@ export const ConfigTenantForm = ({
width: 'min(505px, 100%)',
}}
sx={{ mb: 2 }}
onChange={(event) => {
setIsFormModified(true);
setTheme(event.target.value);
}}
onChange={handleThemeChange}
>
{themes.map((t) => (
<MenuItem key={t.value} value={t.value}>
Expand Down

0 comments on commit 830ad21

Please sign in to comment.