Skip to content

Commit

Permalink
Merge pull request #69 from XIMDEX/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
FranEG80 authored Oct 2, 2024
2 parents d8906a7 + 26b0a2d commit c2d6835
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 133 deletions.
18 changes: 18 additions & 0 deletions src/api/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,24 @@ class AppService {
return {error: 'Error on retrying duplication'}
}
}

async checkAccessibility(id)
{
const _api = api().checkAccessibility(id)
const request = {
method: _api.method
}
try {
const res = await (await fetch(_api.url, request)).json();
if (res.error) throw Error(res.error)
return res
}
catch (e) {
console.error(e.message)
return ['base'];
}
}

}

export default function MainService()
Expand Down
5 changes: 5 additions & 0 deletions src/api/urlMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ const api = () => {
method: 'POST',
url: `${BOOK_EDITOR_URL}api/book/${bookId}/upgrade`
}),

checkAccessibility: (resource_id) => ({
method: 'GET',
url: `${BOOK_EDITOR_URL}api/book/${resource_id}/checkaccessibility`
}),
}
return mapper;
}
Expand Down
19 changes: 14 additions & 5 deletions src/features/Layout/Sidebar/AddOrEditFacetItem.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useRef, useState } from 'react'
import { Grid, IconButton, styled, TextField } from '@material-ui/core';
import { useDispatch, useSelector } from 'react-redux';
import { reloadCatalogue, setSchemas } from '../../../appSlice';
import { reloadCatalogue, selectWorkspaceCollections, selectWorkspacesData, setSchemas, setUser, setWorkspaceCollections, setWorkspacesData } from '../../../appSlice';
import PostAddRounded from '@material-ui/icons/PostAddRounded';
import Modal from '../../Resources/Modals/Modal/Modal';
import { CustomToggle } from '../../Resources/Modals/DynamicFormTemplates/CustomFields';
import MainService from '../../../api/service';
import { selectCollection, selectOrganization } from '../../../slices/organizationSlice';
import { parseWorkspace } from '../../../api/providers/workspacesProvider';

const StyledTextField = styled(TextField)({
'& label.Mui-focused': {
Expand All @@ -30,7 +31,6 @@ const AddOrEditItemFacet = ({facet, requestOpts, values = {}, ...props}) => {
const [disableSuccess, setDisableSuccess] = useState(true)
const [disableCancel, setDisableCancel] = useState(false)
const organization_id = useSelector(selectOrganization)
const collection_id = useSelector(selectCollection)
const [open, setOpen] = useState(false)
const [form, setForm] = useState({});
const formRef = useRef(null);
Expand Down Expand Up @@ -65,8 +65,15 @@ const AddOrEditItemFacet = ({facet, requestOpts, values = {}, ...props}) => {

if (facet.key === 'workspaces' && res.ok) {
alert('Workspace created successfully')
let fetchedUser = await MainService().getUser();
if (fetchedUser?.error) {
return alert(
"Error loading user: " + fetchedUser.error
);
}
dispatch(setWorkspaceCollections(fetchedUser.data.workspaces));
}

const schemas = await MainService().getSchemas();
dispatch(reloadCatalogue())
dispatch(setSchemas(schemas));
Expand All @@ -82,11 +89,13 @@ const AddOrEditItemFacet = ({facet, requestOpts, values = {}, ...props}) => {
}

const handleChange = (key, value) => {
let newForm = {...form, [key]: value}
let newForm = {...values, ...form, [key]: value}
if (value === '') {
delete newForm[key]
}
setDisableSuccess(Object.keys(newForm).length !== facet.fields.filter(obj => obj.type === "string").length)

setDisableSuccess(Object.keys(newForm).length === 0)
// setDisableSuccess(Object.keys(newForm).length !== facet.fields.filter(obj => obj.type === "string").length)
setForm(newForm)
}

Expand Down
1 change: 0 additions & 1 deletion src/features/Layout/Sidebar/FacetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export function FacetCard({ facet, fixed, resources, collection, organization, f
const handleFilterSelected = (value, isChecked) => {
let newValues = {...facetValues}
newValues[value] = {...newValues[value], selected: isChecked}
console.log("FILTER SELECTED", newValues);
setFacetValues(newValues)
if (isChecked && !selectedWS.includes(value)) {
setSelectedWS([...selectedWS,value ])
Expand Down
41 changes: 37 additions & 4 deletions src/features/Resources/Modals/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { selectCollection } from '../../../slices/organizationSlice';
import SemanticForm from "@rjsf/semantic-ui";
import { JSONSchema7 } from 'json-schema';
import { render } from '../../../utils/render';
import { Tab, Label, Icon, Dropdown } from 'semantic-ui-react'
import { Tab, Label, Icon, Dropdown, Radio} from 'semantic-ui-react'
import { Button as Btn } from 'semantic-ui-react';
import { Message } from 'semantic-ui-react';
import RelatedFiles from './RelatedFiles';
Expand Down Expand Up @@ -126,6 +126,9 @@ export default function DynamicForm({ resourceType, action, schema, dataForUpdat
}
});

const [loadingAccessibiliy, setLoadingAccessibility] = useState(true)
const [accessibility, setAccessibility] = useState(false);

const resources = useSelector(selectResources)

const handleWorkspaceSelected = (data) => {
Expand Down Expand Up @@ -277,8 +280,6 @@ export default function DynamicForm({ resourceType, action, schema, dataForUpdat
//end cdn functions

useEffect(() => {


const getThemes = async () => {
const themes_scorm = await MainService().getBookThemes()
const newThemes = themes_scorm.map(th => ({key: th, value: th, text: th === 'v1' ? `${th} (deprecated)` : th}))
Expand All @@ -291,6 +292,20 @@ export default function DynamicForm({ resourceType, action, schema, dataForUpdat

}, [])


useEffect(() => {
const getAccessibility = async () => {
const {accessibility} = await MainService().checkAccessibility(resourceData.id)
setAccessibility(accessibility)
setLoadingAccessibility(false)
}

if (resourceData?.id && action === 'edit' && resourceType === 'book') {
getAccessibility()
}

}, [resourceData])

useEffect(() => {

if(action === 'create') {
Expand Down Expand Up @@ -477,6 +492,11 @@ export default function DynamicForm({ resourceType, action, schema, dataForUpdat
theFormData.append(e, body[e]);
})

if (wksSelected?.wsp?.length !== 0) {
const valuesWsp: number[] = wksSelected?.wsp?.map(e => e.id)
theFormData.append('toWorkspaceId', valuesWsp.join(',') )
}

if (formFiles) {
for (var i = 0; i < formFiles.length; i++) {
theFormData.append('File[]', formFiles[i]);
Expand Down Expand Up @@ -683,6 +703,10 @@ export default function DynamicForm({ resourceType, action, schema, dataForUpdat
setResourceData({...resourceData, theme: value})
}

const handleResourceAccessibility = (_, {checked}) => {
setAccessibility(checked)
}

const handleDuplicate = async () => {
if(canDuplicate){
setProcessingDuplicate(true);
Expand Down Expand Up @@ -776,6 +800,15 @@ export default function DynamicForm({ resourceType, action, schema, dataForUpdat
/>
</div>
)}
{resourceType === 'book' && action !== 'create' && (
<div className='form-theme' style={{display: 'flex', flexDirection: 'row', justifyContent: 'space-between', paddingInline: 20}}>
<label style={{fontWeight: 'bold', fontSize: 16}}><span style={{ color: 'tomato', fontSize: '1rem'}}>Test</span> Enable Accessibility: </label>
{loadingAccessibiliy
? (<Icon loading name='spinner' />)
: (<Radio toggle defaultChecked={accessibility} onClick={handleResourceAccessibility}/>)
}
</div>
)}
<SemanticForm
id='sfu'
className={fillAlert ? 'fill-alert' : ''}
Expand Down Expand Up @@ -835,7 +868,7 @@ export default function DynamicForm({ resourceType, action, schema, dataForUpdat

<Grid item sm={12} className={classes.divider}>
{dataForUpdate ? (
<ResourceActionButtons resource={dataForUpdate} themeBook={resourceData?.theme ?? DEFAULT_THEME_BOOK} />
<ResourceActionButtons resource={dataForUpdate} themeBook={resourceData?.theme ?? DEFAULT_THEME_BOOK} accessibility={accessibility}/>
) : null}
</Grid>

Expand Down
Loading

0 comments on commit c2d6835

Please sign in to comment.