Skip to content

Commit

Permalink
feat(admin-ui): post agama locally #806
Browse files Browse the repository at this point in the history
  • Loading branch information
mjatin-dev committed Mar 22, 2023
1 parent 8e43fad commit 70baf8f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 52 deletions.
3 changes: 2 additions & 1 deletion admin-ui/app/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@
"access_token": "Access token",
"userinfo": "Userinfo",
"JARM": "JARM",
"request_object": "Request Object"
"request_object": "Request Object",
"agama":"Agama"
},
"links": {
"support": "https://support.gluu.org/"
Expand Down
43 changes: 31 additions & 12 deletions admin-ui/plugins/auth-server/components/Agama/AgamaListPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useEffect, useContext, useCallback } from 'react'
import { useNavigate, useLocation } from 'react-router-dom'
import { useSelector, useDispatch } from 'react-redux'
import { Card, CardBody, Badge, Input } from 'Components'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
Expand All @@ -8,17 +7,20 @@ import SetTitle from 'Utils/SetTitle'
import { ThemeContext } from 'Context/theme/themeContext'
import getThemeColor from 'Context/theme/config'
import { Paper, TablePagination } from '@material-ui/core'
import { getAgama , postAgama} from '../../redux/actions/AgamaActions'
import { getAgama } from '../../redux/actions/AgamaActions'
import {
hasPermission,
AGAMA_READ,
AGAMA_WRITE
} from 'Utils/PermChecker'
import axios from 'axios'
import GluuViewWrapper from '../../../../app/routes/Apps/Gluu/GluuViewWrapper'
import MaterialTable from '@material-table/core'
import { Button, Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap'
import { useDropzone } from 'react-dropzone'
import JSZip from 'jszip'
const JansConfigApi = require('jans_config_api')
import { getClient } from '../../../../app/redux/api/base'

function AgamaListPage() {
const { t } = useTranslation()
Expand All @@ -35,11 +37,16 @@ function AgamaListPage() {
const [projectName, setProjectName] = useState('')
const [getProjectName, setGetProjectName] = useState(false)


const token = useSelector((state) => state.authReducer.token.access_token)
const issuer = useSelector((state) => state.authReducer.issuer)

const BASE_PATH = getClient(JansConfigApi, token, issuer)

const theme = useContext(ThemeContext)
const selectedTheme = theme.state.theme
const themeColors = getThemeColor(selectedTheme)
const bgThemeColor = { background: themeColors.background }

function convertFileToByteArray(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader()
Expand All @@ -54,11 +61,27 @@ function AgamaListPage() {
})
}


const submitData = async () => {
let file = await convertFileToByteArray(selectedFile);
let obj = {file, name:projectName}
dispatch(postAgama(obj))
var config = {
method: 'post',
url: BASE_PATH.basePath+'/api/v1/agama-deployment?name='+projectName,
headers: {
'Authorization': 'Bearer '+token,
'Content-Type': 'application/zip'
},
data : file
}
axios(config)
.then(function (response) {
dispatch(getAgama())
setProjectName('')
setShowAddModal(false)
})
.catch(function (error) {
console.log(error);
});
// dispatch(postAgama(obj))
}
const onDrop = useCallback((acceptedFiles) => {
// Do something with the files
Expand All @@ -71,11 +94,9 @@ function AgamaListPage() {
zip.forEach(function (relativePath, zipEntry) {
if (zipEntry.name.endsWith('.json')) {
foundJson = true
console.log(zipEntry.name)
if (!foundProjectName) {
zipEntry.async('string').then(function (jsonStr) {
const jsonData = JSON.parse(jsonStr) // Parse the JSON data
console.log(jsonData) // Do something with the JSON data
if (jsonData?.projectName) {
foundProjectName = true
setGetProjectName(false)
Expand All @@ -96,13 +117,12 @@ function AgamaListPage() {
setGetProjectName(true)
}
})
// console.log(acceptedFiles[0]);
}, [])
const { acceptedFiles, getRootProps, getInputProps } = useDropzone({
onDrop,
multiple: false,
accept: {
'application/*': ['.zip'],
'application/x-zip-compressed': ['.zip'],
},
})

Expand All @@ -111,11 +131,10 @@ function AgamaListPage() {
)
const agamaList = useSelector((state) => state.agamaReducer.agamaList)
const permissions = useSelector((state) => state.authReducer.permissions)
SetTitle(t('titles.oidc_clients'))
SetTitle(t('titles.agama'))

let memoLimit = limit
useEffect(() => {
console.log('GET AGAMA')
dispatch(getAgama())
}, [])

Expand Down
6 changes: 1 addition & 5 deletions admin-ui/plugins/auth-server/redux/actions/AgamaActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ import {
type: GET_AGAMA_RESPONSE,
payload: data
})

export const postAgama = (data) => ({
type:POST_AGAMA,
payload:data
})

2 changes: 0 additions & 2 deletions admin-ui/plugins/auth-server/redux/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,3 @@ export const REVOKE_SESSION_RESPONSE = 'REVOKE_SESSION_RESPONSE'

export const GET_AGAMA = "GET_AGAMA"
export const GET_AGAMA_RESPONSE = "GET_AGAMA_RESPONSE"
export const POST_AGAMA = "POST_AGAMA"
export const POST_AGAMA_RESPONSE = "POST_AGAMA_RESPONSE"
12 changes: 0 additions & 12 deletions admin-ui/plugins/auth-server/redux/api/AgamaApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,4 @@ export default class AgamaApi {
})
})
}
// Post Agama
postAgama = ({payload}) => {
console.log('abcd',payload)
let opts = {}
opts['requestBody'] = payload.file
opts['name'] = payload.name
return new Promise((resolve, reject) => {
this.api.postAgamaDevStudioPrj(payload, (error, data) => {
handleResponse(error, reject, resolve, data)
})
})
}
}
22 changes: 2 additions & 20 deletions admin-ui/plugins/auth-server/redux/sagas/AgamaSaga.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { call, all, put, fork, takeLatest, select } from 'redux-saga/effects'
import { isFourZeroOneError } from 'Utils/TokenController'
import { getAcrsResponse, editAcrsResponse } from '../actions/AcrsActions'
import { getAPIAccessToken } from 'Redux/actions/AuthActions'
import { GET_AGAMA, POST_AGAMA } from '../actions/types'
import { GET_AGAMA } from '../actions/types'
import AgamaApi from '../api/AgamaApi'
import { getClient } from 'Redux/api/base'
import { getAgamaResponse } from '../actions/AgamaActions'
Expand All @@ -29,32 +28,15 @@ export function* getAgamas() {
}
}
}
export function* postAgamaSaga(payload) {
console.log("POST AGAMA")
try {
const api = yield* newFunction()
const data = yield call(api.postAgama, payload)
console.log(data);
// yield put(getAgamaResponse(data))
} catch (e) {
if (isFourZeroOneError(e)) {
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
yield put(getAPIAccessToken(jwt))
}
}
}




export function* watchGetAgama() {
yield takeLatest(GET_AGAMA, getAgamas)
}
export function* watchPostAgama() {
yield takeLatest(POST_AGAMA, postAgamaSaga)
}


export default function* rootSaga() {
yield all([fork(watchGetAgama), fork(watchPostAgama)])
yield all([fork(watchGetAgama)])
}

0 comments on commit 70baf8f

Please sign in to comment.