diff --git a/src/components/forms/formGenerator.js b/src/components/forms/formGenerator.js index 300da2d..7f906c5 100644 --- a/src/components/forms/formGenerator.js +++ b/src/components/forms/formGenerator.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useState } from 'react' /** * @@ -13,15 +13,20 @@ export const FormGenerator = ({ const handler = async (event) => { event.preventDefault() - for (let i = 0; i < refList.length; i++) { - if (refList[i].current.value === '' - && inputList[0].action !== 'Update' - || i === 0 - && refList.length !== 1 - ) { - refList[i].current.focus() - } else if (i === refList.length - 1) { - await action(refList) + + if ( inputList[0].action === 'Download' ) { + await action() + } else { + for (let i = 0; i < refList.length; i++) { + if (refList[i].current.value === '' + && inputList[0].action !== 'Update' + || i === 0 + && refList.length !== 1 + ) { + refList[i].current.focus() + } else if (i === refList.length - 1) { + await action(refList) + } } } } @@ -51,6 +56,14 @@ export const FormGenerator = ({ key={key} /> ) + } else if (input.type === 'drop-box') { + return ( + + ) } else if (input.type === 'file') { return ( - { info.button_value } - + { + info.button_value === '' + ? <> + : + } + ) } @@ -130,6 +150,52 @@ const PasswordInputGenerator = ({ ) } +/** + * Text input generator, example: + * @param { + * { + * type: 'drop-box', + * name: 'name', + * values: list, + * link: link to the file + * } } input - basic text input + * @param { + * { + * type: 'info', + * action: 'Update' + * endpoint: 'Album' + * } } info - information about form + */ +const DownloadFilesListInputGenerator = ({ + input, info +}) => { + + return ( +
+ {input.name + ':'} + { + input.values.map( (item, index) => { + + return ( +
+ + { item } + +
+ ) + } + ) + } +
+ ) +} + /** * Upload file input generator, example: * @param { @@ -196,4 +262,6 @@ const UploadInputGenerator = ({ ) } + + export default FormGenerator \ No newline at end of file diff --git a/src/components/forms/model_crud/modelShowModelsAndDownload.js b/src/components/forms/model_crud/modelShowModelsAndDownload.js index e69de29..a0fc798 100644 --- a/src/components/forms/model_crud/modelShowModelsAndDownload.js +++ b/src/components/forms/model_crud/modelShowModelsAndDownload.js @@ -0,0 +1,65 @@ +import React, { useEffect } from 'react' + +import { useSelector, useDispatch } from 'react-redux' + +import { userAuthSelector } from '../../../redux/slices/userAuthSlice' +import { modelCrudSelector } from '../../../redux/slices/modelCrudSlice' +import modelCrudAsyncThunk from '../../../redux/asyncThunks/modelCrudAsyncThunk' + +import { GeneralAddress } from '../../../redux/asyncThunks/abstracts/abstractAddress' + +import FormGenerator from '../formGenerator' + + +const ModelShowAndDownloadForm = () => { + + const dispatch = useDispatch() + + const { models_list } = useSelector( modelCrudSelector ) + const { user, token } = useSelector( userAuthSelector ) + + let blocker = false + + useEffect( + () => { + if ( models_list.length === 0 && user.id > 0 && token !== '' && !blocker ) { + dispatch( modelCrudAsyncThunk.fetchGetAllModels(token) ) + if ( models_list.length === 0 ) { + blocker = true + } + } + } + ) + + let inputList = [ + { + type: 'info', + action: 'Download', + endpint: 'model/download', + button_value: 'Refresh Models List' + }, + { + type: 'drop-box', + name: 'Models', + values: models_list, + link: GeneralAddress + '/model/', + } + ] + + const handleRefresh = () => { + dispatch( modelCrudAsyncThunk.fetchGetAllModels(token) ) + } + + return ( + <> + + + ) + +} + +export default ModelShowAndDownloadForm \ No newline at end of file diff --git a/src/components/forms/model_crud/modelUpload.js b/src/components/forms/model_crud/modelUpload.js index e69de29..de69c65 100644 --- a/src/components/forms/model_crud/modelUpload.js +++ b/src/components/forms/model_crud/modelUpload.js @@ -0,0 +1,10 @@ +import React from 'react' + +const ModelUploadForm = () => { + return ( + <> + + ) +} + +export default ModelUploadForm \ No newline at end of file diff --git a/src/pages/func_group/model_crud/modelCrudIndex.js b/src/pages/func_group/model_crud/modelCrudIndex.js index 2a88dc9..3161005 100644 --- a/src/pages/func_group/model_crud/modelCrudIndex.js +++ b/src/pages/func_group/model_crud/modelCrudIndex.js @@ -1,10 +1,41 @@ import React, { useState, useEffect } from 'react' -const ModelCrudIndex = () => { +import ModelShowAndDownloadForm from '../../../components/forms/model_crud/modelShowModelsAndDownload' +import ModelUpload from '../../../components/forms/model_crud/modelUpload' + + +const __handleSwap = (name, movement) => { + + let display = { + display: 'block' + } + + let hide = { + display: 'none' + } + + if ( Object.keys(movement['movement']).includes(name) ) { + if (movement['movement'][name]) + return display + else + return hide + } else { + return hide + } + +} + +const ModelCrudIndex = ( movement ) => { return ( -
-
+ <> +
+ +
+
+ +
+ ) } diff --git a/src/pages/func_group/navigationBar.js b/src/pages/func_group/navigationBar.js index 215f20f..857350c 100644 --- a/src/pages/func_group/navigationBar.js +++ b/src/pages/func_group/navigationBar.js @@ -10,32 +10,26 @@ import userAuthAsyncThunk from '../../redux/asyncThunks/userAuthAsyncThunk' const __setShowGeneral = ( view, key, movements ) => { - movements.user_view.setUserCrudView( - { - update_user: false, - delete_user: false - } - ) + movements.user_view.userCrudView = { + update_user: false, + delete_user: false + } - movements.model_view.setModelCrudView( - { - show_models_and_dwonload: false, - upload_model: false - } - ) + movements.model_view.modelCrudView = { + show_models_and_dwonload: false, + upload_model: false + } - movements.render_view.setRenderView( - { - show_ready_renders_and_download: false, - render_functionality: { - render_single_image: false, - render_single_set: false, - render_all: false, - render_image_by_vector: false, - render_set_by_vector: false - } + movements.render_view.renderView = { + show_ready_renders_and_download: false, + render_functionality: { + render_single_image: false, + render_single_set: false, + render_all: false, + render_image_by_vector: false, + render_set_by_vector: false } - ) + } if (view === 'user_view') { let new_move = movements.user_view.userCrudView @@ -44,6 +38,7 @@ const __setShowGeneral = ( view, key, movements ) => { new_move ) } else if (view === 'model_view') { + let new_move = movements.model_view.modelCrudView new_move[key] = true movements.model_view.setModelCrudView( @@ -144,7 +139,7 @@ const NavigationBar = ({ movements }) => { ├── Models
-
__setShowGeneral( 'model_view', 'show_models_and_dwonload', movements )}> +
__setShowGeneral( 'model_view', 'show_models_and_download', movements )}> │ ├── Show Models & Download
__setShowGeneral( 'model_view', 'upload_model', movements ) }> diff --git a/src/pages/func_group/rootUtils.js b/src/pages/func_group/rootUtils.js index 7786566..07fdfdd 100644 --- a/src/pages/func_group/rootUtils.js +++ b/src/pages/func_group/rootUtils.js @@ -22,7 +22,7 @@ const GeneralView = () => { ) const [modelCrudView, setModelCrudView] = useState( { - show_models_and_dwonload: false, + show_models_and_download: false, upload_model: false } ) @@ -60,16 +60,16 @@ const GeneralView = () => { movements={ movements } /> ) diff --git a/src/redux/asyncThunks/abstracts/abstractAddress.js b/src/redux/asyncThunks/abstracts/abstractAddress.js index 0353f78..164c1a8 100644 --- a/src/redux/asyncThunks/abstracts/abstractAddress.js +++ b/src/redux/asyncThunks/abstracts/abstractAddress.js @@ -1 +1 @@ -export const GeneralAddress = 'localhost:9090' \ No newline at end of file +export const GeneralAddress = 'http://localhost:9090' \ No newline at end of file diff --git a/src/redux/asyncThunks/abstracts/abstractService.js b/src/redux/asyncThunks/abstracts/abstractService.js index e175e1c..dc58850 100644 --- a/src/redux/asyncThunks/abstracts/abstractService.js +++ b/src/redux/asyncThunks/abstracts/abstractService.js @@ -1,7 +1,7 @@ import axios from 'axios' import { GeneralAddress } from './abstractAddress' -const APIAddress = 'http://' + GeneralAddress +const APIAddress = GeneralAddress let defaultBody = {} diff --git a/src/redux/slices/modelCrudSlice.js b/src/redux/slices/modelCrudSlice.js index 1f76bbc..f537fc8 100644 --- a/src/redux/slices/modelCrudSlice.js +++ b/src/redux/slices/modelCrudSlice.js @@ -8,7 +8,6 @@ const modelCrudSlice = createSlice( models_list: [], download_blend_file: '', upload_blend_file_status: '' - }, reducers: {}, extraReducers: {