diff --git a/app/Http/Controllers/Api/Application/Nodes/NodeConfigurationController.php b/app/Http/Controllers/Api/Application/Nodes/NodeConfigurationController.php index 95ae70f3b..8d542f7fb 100644 --- a/app/Http/Controllers/Api/Application/Nodes/NodeConfigurationController.php +++ b/app/Http/Controllers/Api/Application/Nodes/NodeConfigurationController.php @@ -14,10 +14,15 @@ class NodeConfigurationController extends ApplicationApiController * to remote machines so long as an API key is provided to the machine to make the request * with, and the node is known. * - * @return \Illuminate\Http\JsonResponse + * @return string + * @throws \Illuminate\Contracts\Container\BindingResolutionException */ public function __invoke(GetNodeRequest $request, Node $node) { + if ($request->query('format') === 'yaml') { + return $node->getYamlConfiguration(); + } + return new JsonResponse($node->getConfiguration()); } } diff --git a/resources/scripts/api/admin/nodes/getNodeConfiguration.ts b/resources/scripts/api/admin/nodes/getNodeConfiguration.ts new file mode 100644 index 000000000..f439b1e7e --- /dev/null +++ b/resources/scripts/api/admin/nodes/getNodeConfiguration.ts @@ -0,0 +1,9 @@ +import http from '@/api/http'; + +export default (id: number): Promise => { + return new Promise((resolve, reject) => { + http.get(`/api/application/nodes/${id}/configuration?format=yaml`) + .then(({ data }) => resolve(data)) + .catch(reject); + }); +}; diff --git a/resources/scripts/components/admin/nodes/NodeConfigurationContainer.tsx b/resources/scripts/components/admin/nodes/NodeConfigurationContainer.tsx new file mode 100644 index 000000000..77ebc1238 --- /dev/null +++ b/resources/scripts/components/admin/nodes/NodeConfigurationContainer.tsx @@ -0,0 +1,48 @@ +import getNodeConfiguration from '@/api/admin/nodes/getNodeConfiguration'; +import { Context } from '@/components/admin/nodes/NodeEditContainer'; +import { ApplicationStore } from '@/state'; +import { Actions, useStoreActions } from 'easy-peasy'; +import React, { useEffect, useState } from 'react'; +import AdminBox from '@/components/admin/AdminBox'; +import tw from 'twin.macro'; +import { faCode, faDragon } from '@fortawesome/free-solid-svg-icons'; + +export default () => { + const { clearAndAddHttpError } = useStoreActions((actions: Actions) => actions.flashes); + + const [ configuration, setConfiguration ] = useState(''); + + const node = Context.useStoreState(state => state.node); + + if (node === undefined) { + return ( + <> + ); + } + + useEffect(() => { + getNodeConfiguration(node.id) + .then((configuration) => { + console.log(configuration); + setConfiguration(configuration); + }) + .catch(error => { + console.error(error); + clearAndAddHttpError({ key: 'node', error }); + }); + }, []); + + return ( +
+ +
+                    {configuration}
+                
+
+ + + Never™ + +
+ ); +}; diff --git a/resources/scripts/components/admin/nodes/NodeEditContainer.tsx b/resources/scripts/components/admin/nodes/NodeEditContainer.tsx index b2a2857a6..0937be13a 100644 --- a/resources/scripts/components/admin/nodes/NodeEditContainer.tsx +++ b/resources/scripts/components/admin/nodes/NodeEditContainer.tsx @@ -1,3 +1,4 @@ +import NodeConfigurationContainer from '@/components/admin/nodes/NodeConfigurationContainer'; import React, { useEffect, useState } from 'react'; import { useLocation } from 'react-router'; import tw from 'twin.macro'; @@ -132,7 +133,7 @@ const NodeEditContainer = () => { -

Configuration

+