diff --git a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/Dockerfile b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/Dockerfile index 12dc1e6a..5876ceee 100644 --- a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/Dockerfile +++ b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/Dockerfile @@ -52,6 +52,15 @@ RUN echo "$ssh_prv_key" | sed 's/\\n/\n/g' > /root/.ssh/id_rsa && \ chmod 600 /root/.ssh/id_rsa && \ chmod 600 /root/.ssh/id_rsa.pub +# COPY id_rsa_epd /root/.ssh/id_rsa +# COPY id_rsa_epd.pub /root/.ssh/id_rsa.pub + +# RUN chmod 600 /root/.ssh/id_rsa + +# RUN chmod 600 /root/.ssh/id_rsa.pub + +# RUN mkdir -p /root/.ssh && ssh-keyscan github.com >> /root/.ssh/known_hosts + RUN mkdir -p /root/.ssh && ssh-keyscan github.com >> /root/.ssh/known_hosts RUN git clone git@github.com:AOT-Technologies/forms-flow-ai-ee.git -b epd-ff-ee-5.2.0 /tmp/forms-flow-ai/ diff --git a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/docker-compose.yml b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/docker-compose.yml index acf2acb3..6cedb74f 100644 --- a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/docker-compose.yml +++ b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/docker-compose.yml @@ -30,7 +30,7 @@ services: - REACT_APP_MT_ADMIN_BASE_URL_VERSION=${MT_ADMIN_BASE_URL_VERSION} - REACT_APP_CUSTOM_SUBMISSION_URL=${CUSTOM_SUBMISSION_URL} - REACT_APP_CUSTOM_SUBMISSION_ENABLED=${CUSTOM_SUBMISSION_ENABLED:-false} - - REACT_APP_DRAFT_ENABLED=${DRAFT_ENABLED:-false} + - REACT_APP_DRAFT_ENABLED=${DRAFT_ENABLED:-true} - REACT_APP_DRAFT_POLLING_RATE=${DRAFT_POLLING_RATE:-15000} - REACT_APP_EXPORT_PDF_ENABLED=${EXPORT_PDF_ENABLED:-false} - REACT_APP_PUBLIC_WORKFLOW_ENABLED=${PUBLIC_WORKFLOW_ENABLED:-false} @@ -45,6 +45,7 @@ services: - REACT_APP_ENABLE_APPLICATIONS_MODULE=${ENABLE_APPLICATIONS_MODULE:-true} - REACT_APP_CUSTOM_MAP_URL=${EPD_CUSTOM_MAP_URL:-http://localhost:4000/map} - REACT_APP_CUSTOM_LOGOUT_URL=${EPD_IDP_LOGOUT_URL:-https://logontest7.gov.bc.ca/clp-cgi/logoff.cgi?retnow=1&returl=https://epd-keycloak-dev.apps.silver.devops.gov.bc.ca/auth/realms/forms-flow-ai/protocol/openid-connect/logout?post_logout_redirect_uri=http://localhost:4000} + - REACT_APP_CUSTOM_FILE_UPLOAD=${EPD_APP_FILE_UPLOAD:-http://localhost:4000/fileupload} ports: - "3000:8080" tty: true diff --git a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/public/config/config.template.js b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/public/config/config.template.js index 6ee5dce7..87416e67 100644 --- a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/public/config/config.template.js +++ b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web-root-config/public/config/config.template.js @@ -55,4 +55,6 @@ window["_env_"] = { REACT_APP_ENABLE_APPLICATIONS_MODULE: "${REACT_APP_ENABLE_APPLICATIONS_MODULE}", REACT_APP_CUSTOM_MAP_URL: "${REACT_APP_CUSTOM_MAP_URL}", REACT_APP_CUSTOM_LOGOUT_URL: "${REACT_APP_CUSTOM_LOGOUT_URL}", + REACT_APP_CUSTOM_FILE_UPLOAD: "${REACT_APP_CUSTOM_FILE_UPLOAD}", + }; diff --git a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/Dockerfile b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/Dockerfile index ee3d45f9..c819c87b 100644 --- a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/Dockerfile +++ b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/Dockerfile @@ -32,6 +32,15 @@ RUN echo "$ssh_prv_key" | sed 's/\\n/\n/g' > /root/.ssh/id_rsa && \ chmod 600 /root/.ssh/id_rsa && \ chmod 600 /root/.ssh/id_rsa.pub +# COPY id_rsa_epd /root/.ssh/id_rsa +# COPY id_rsa_epd.pub /root/.ssh/id_rsa.pub + +# RUN chmod 600 /root/.ssh/id_rsa + +# RUN chmod 600 /root/.ssh/id_rsa.pub + +# RUN mkdir -p /root/.ssh && ssh-keyscan github.com >> /root/.ssh/known_hosts + RUN mkdir -p /root/.ssh && ssh-keyscan github.com >> /root/.ssh/known_hosts RUN git clone git@github.com:AOT-Technologies/forms-flow-ai-ee.git -b epd-ff-ee-5.2.0 /tmp/forms-flow-ai/ diff --git a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/Application-file-upload/AppFileUpload.js b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/Application-file-upload/AppFileUpload.js new file mode 100644 index 00000000..7dc1d1d4 --- /dev/null +++ b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/Application-file-upload/AppFileUpload.js @@ -0,0 +1,95 @@ +import React from "react"; +import ReactDOM from "react-dom"; +import { ReactComponent } from "react-formio"; +import settingsForm from "./appFileUpload.settingsForm"; + + +export default class AppFileUpload extends ReactComponent { + /** + * This function tells the form builder about your component. It's name, icon and what group it should be in. + * + * @returns {{title: string, icon: string, group: string, documentation: string, weight: number, schema: *}} + */ + static get builderInfo() { + return { + title: "Application File Upload", + icon: "map-marker", + group: "basic", + documentation: "", //TODO + weight: 120, + schema: AppFileUpload.schema(), + }; + } + + /** + * This function is the default settings for the component. At a minimum you want to set the type to the registered + * type of your component (i.e. when you call Components.setComponent('type', MyComponent) these types should match. + * + * @param sources + * @returns {*} + */ + static schema() { + return ReactComponent.schema({ + type: "AppFileUpload", + label: "File Upload", + }); + } + + /* + * Defines the settingsForm when editing a component in the builder. + */ + static editForm = settingsForm; + + static eventRegistered = false; + + /** + * This function is called when the DIV has been rendered and added to the DOM. You can now instantiate the react component. + * + * @param DOMElement + * #returns ReactInstance + * + * + */ + attachReact(element) { + let instance; + + ReactDOM.render( + { + console.log('file upload'); + var customeApplicationId = this.data.applicationId; + + + let mapURL = + process.env.REACT_APP_CUSTOM_FILE_UPLOAD || window._env_.REACT_APP_CUSTOM_FILE_UPLOAD; + + window.open( + mapURL + "?appId=" + customeApplicationId , + "_blank", + "popup=yes,width=500px,heigth=500px" + ); + + console.log("adding listner end"); + + return false; + }} + > + Upload Documents + , + element, + () => (this.reactInstance = instance) + ); + } + + /** + * Automatically detach any react components. + * + * @param element + */ + detachReact(element) { + if (element) { + ReactDOM.unmountComponentAtNode(element); + } + } +} diff --git a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/Application-file-upload/README.md b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/Application-file-upload/README.md new file mode 100644 index 00000000..e69de29b diff --git a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/Application-file-upload/appFileUpload.settingsForm.js b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/Application-file-upload/appFileUpload.settingsForm.js new file mode 100644 index 00000000..9122dee9 --- /dev/null +++ b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/Application-file-upload/appFileUpload.settingsForm.js @@ -0,0 +1,38 @@ +import baseEditForm from 'formiojs/components/_classes/component/Component.form'; + +const settingsForm = (...extend) => { + return baseEditForm([ + { + key: 'display', + components: [ + { + key: 'placeholder', + ignore: true, + }, + ] + }, + { + key: 'data', + components: [], + }, + { + key: 'validation', + components: [], + }, + { + key: 'api', + components: [], + }, + { + key: 'conditional', + components: [], + }, + { + key: 'logic', + components: [], + }, + ], ...extend); +}; + +export default settingsForm; + diff --git a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/index.js b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/index.js index 1662cd78..df26e12e 100644 --- a/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/index.js +++ b/forms-flow-ai/forms-flow-ai-ee/forms-flow-web/src/custom-components/index.js @@ -1,9 +1,11 @@ import fileUpload from "./custom-file-upload/fileUpload"; import Maps from './map-component/Mapservice'; +import AppFileUpload from "./Application-file-upload/AppFileUpload"; const components = { fileUpload: fileUpload, Maps: Maps, + AppFileUpload:AppFileUpload, }; export default components; diff --git a/frontend/src/app/features/bcbox/FileUpload.tsx b/frontend/src/app/features/bcbox/FileUpload.tsx index 29ccfc4b..13521048 100644 --- a/frontend/src/app/features/bcbox/FileUpload.tsx +++ b/frontend/src/app/features/bcbox/FileUpload.tsx @@ -1,108 +1,135 @@ // Needs to be moved to utility class later import axios from "axios"; import { useState } from "react"; - +import { getUser } from "../../helpers/utility"; +import { useEffect } from "react"; +import { builtinModules } from "module"; export const FileUpload = () => { - - - const [bucketId,setBucketId] = useState(''); - const [fileToUpload,setFileToUpload] = useState(); - - - const bcBoxBaseURL = "https://coms.api.gov.bc.ca"; - const bcBoxBucketURL = "/api/v1/bucket"; - const token = ""; - - const findUserEmail = "api/v1/user?email="; - - const setBucketPermission = "https://coms.api.gov.bc.ca/api/v1/permission/bucket/"; - - const fileUploadEndpoint= "api/v1/object?bucketId="; - - - const axiosInstance = axios.create({ - baseURL: bcBoxBaseURL, - timeout: 1000, - headers: { - 'Authorization': 'Bearer '+token, - 'Content-Type':'application/json' - } - }); - - const axiosInstanceToFileUpload = axios.create({ - baseURL: bcBoxBaseURL, - timeout: 1000, - headers: { - 'Authorization': 'Bearer '+token, - 'Content-Type':'text/plain', - 'Content-Disposition':"attachment; filename=latest2_bin.txt; filename*=UTF-8''latest2_bin.txt'" - } - }); - - const createBucket = () => { - console.log("create bucket"); - - - axiosInstance.put(bcBoxBucketURL,{ - "accessKeyId": "nr-srs-dlv", - "active": true, - "bucket": "vkophq", - "bucketName": "application/06NOV1133", - "endpoint": "https://nrs.objectstore.gov.bc.ca", - "region": "ca-central-1", - "secretAccessKey": "Ht53nIvXzmc7eGFcQwoP+0UsWWiATHeV/dW67gHO", - "key": "application/06NOV1133" - }).then((result)=>{ - console.log(result); - if(result.data!=null && result.data.bucketId != '') + useEffect(() => { + const queryString = window.location.search; + const urlParams = new URLSearchParams(queryString); + const applicationId = urlParams.get("appId"); + setAppId(applicationId as string); + }, []); + + const [bucketId, setBucketId] = useState(""); + const [fileToUpload, setFileToUpload] = useState(); + const [appId, setAppId] = useState(""); + const [fileName, setFileName] = useState(""); + + const bcBoxBaseURL = "http://localhost:4050"; + const bcBoxBucketURL = "/api/v1/bucket"; + const token = getUser()?.access_token; + + const findUserEmail = "api/v1/user?email="; + + const setBucketPermission = "http://localhost:4050/api/v1/permission/bucket/"; + + const fileUploadEndpoint = "api/v1/object?bucketId="; + + + + useEffect(() => { + if (appId !== "") { + axiosInstance + .put(bcBoxBucketURL, { + accessKeyId: "nr-srs-dlv", + active: true, + bucket: "vkophq", + bucketName: "application/" + appId, + endpoint: "https://nrs.objectstore.gov.bc.ca", + region: "ca-central-1", + secretAccessKey: "Ht53nIvXzmc7eGFcQwoP+0UsWWiATHeV/dW67gHO", + key: "application/" + appId, + }) + .then((result) => { + console.log(result); + if (result.data != null && result.data.bucketId != "") setBucketId(result.data.bucketId); - }); - + }); } - - const findUser = () => { - console.log("find user"); - axiosInstance.get(findUserEmail+"midhun.murali@aot-technologies.com").then((result)=>{ - console.log(result); - result.data.forEach((user:any)=>{ - console.log(user) - - axiosInstance.put(setBucketPermission + bucketId,[{ - "permCode": "CREATE", - "userId": user.userId - }]) - - - })} - ); - } - - const uploadFile = (event:any) =>{ - console.log("upload file", event.target.files); - setFileToUpload( event.target.files[0]); - } - - const uploadFileSubmit = (event:any) =>{ - console.log("upload file", fileToUpload); - //setFileToUpload( event.target.files[0]); - - axiosInstanceToFileUpload.put(fileUploadEndpoint+bucketId, window.URL.createObjectURL(fileToUpload)).then((result)=>{ - console.log('file upload',result); - + }, [appId]); + + useEffect(() => { + if (bucketId !== "" && bucketId !== null) { + axiosInstance + .get(findUserEmail + "midhun.murali@aot-technologies.com") + .then((result) => { + console.log(result); + result.data.forEach((user: any) => { + console.log(user); + + axiosInstance.put(setBucketPermission + bucketId, [ + { + permCode: "CREATE", + userId: user.userId, + }, + ]); }); + }); } - - return ( -
-

Upload Files To Your Applications

- {uploadFile(e)}}> + }, [bucketId]); + + const axiosInstance = axios.create({ + baseURL: bcBoxBaseURL, + timeout: 1000, + headers: { + Authorization: "Bearer " + token, + "Content-Type": "application/json", + }, + }); + + const axiosInstanceToFileUpload = axios.create({ + baseURL: bcBoxBaseURL, + timeout: 1000, + headers: { + Authorization: "Bearer " + token, + "Content-Type": "text/plain", + "Content-Disposition": + "attachment; filename=\""+fileName+"\"", + }, + }); + + const uploadFile = (event: any) => { + console.log("upload file", event.target.files); + setFileToUpload(event.target.files[0]); + setFileName(event.target.files[0].name) + }; + + const uploadFileSubmit = (event: any) => { + if (bucketId !== null && bucketId !== "") + axiosInstanceToFileUpload + .put( + fileUploadEndpoint + bucketId, + window.URL.createObjectURL(fileToUpload) + ) + .then((result) => { + console.log("file upload", result); + alert('File successfully upload.') + }); + else alert("Unable to find application upload location"); + //setFileToUpload( event.target.files[0]); + }; + + return ( +
+

Please Upload File To Your Application # {appId}

+ { + uploadFile(e); + }} + >
- {createBucket()}}/> -
- {findUser()}} /> -
- {uploadFileSubmit(e)}} /> + { + uploadFileSubmit(e); + }} + />
); diff --git a/frontend/src/app/helpers/utility.ts b/frontend/src/app/helpers/utility.ts index 26edbbe5..f55ca5fd 100644 --- a/frontend/src/app/helpers/utility.ts +++ b/frontend/src/app/helpers/utility.ts @@ -4,7 +4,7 @@ import axios from "axios"; import { User } from "oidc-client-ts" import { getClientSettings } from '../auth/UserManagerSetting'; -function getUser() { +export function getUser() { const oidcStorage = sessionStorage.getItem(`oidc.user:`+getClientSettings().authority+`:`+getClientSettings().client_id) if (!oidcStorage) { return null; @@ -44,3 +44,5 @@ export const getAxiosInstance = () => { return instance; } + + diff --git a/frontend/src/app/routes/Routes.tsx b/frontend/src/app/routes/Routes.tsx index f2e3efba..b43c7100 100644 --- a/frontend/src/app/routes/Routes.tsx +++ b/frontend/src/app/routes/Routes.tsx @@ -19,7 +19,7 @@ const AppRoutes = () => { }/>}/> }/> }/> - }/> + }/>}/> }> }> Page not found}>