Skip to content

Commit

Permalink
Merge pull request #59 from constantine2nd/develop
Browse files Browse the repository at this point in the history
A few features
  • Loading branch information
simonredfern authored Oct 14, 2024
2 parents e3ce2d9 + 054279f commit 0c1c996
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api-explorer",
"version": "1.0.18",
"version": "1.0.20",
"private": true,
"scripts": {
"dev": "vite & ts-node server/app.ts",
Expand Down
25 changes: 22 additions & 3 deletions server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,36 @@ import path from 'path'
const port = 8085
const app: Application = express()

// Initialize client.
// Initialize Redis client.
console.log(`--- Redis setup -------------------------------------------------`)
process.env.VITE_OBP_REDIS_URL
? console.log(`VITE_OBP_REDIS_URL: ${process.env.VITE_OBP_REDIS_URL}`)
: console.log(`VITE_OBP_REDIS_URL: undefined connects to localhost on port 6379`)

const redisPassword = process.env.VITE_OBP_REDIS_PASSWORD
? process.env.VITE_OBP_REDIS_PASSWORD // Redis instance is protected with a password
: '' // Specify an empty password (i.e., no password) when connecting to Redis
if(!redisPassword) {
console.warn(`VITE_OBP_REDIS_PASSWORD is not provided.`)
}
console.log(`-----------------------------------------------------------------`)
let redisClient = process.env.VITE_OBP_REDIS_URL
? createClient({ url: process.env.VITE_OBP_REDIS_URL })
const redisClient = process.env.VITE_OBP_REDIS_URL
? createClient({ url: process.env.VITE_OBP_REDIS_URL, password: redisPassword })
: createClient()
redisClient.connect().catch(console.error)

const redisUrl = process.env.VITE_OBP_REDIS_URL
? process.env.VITE_OBP_REDIS_URL
: 'localhost on port 6379'

// Provide feedback in case of successful connection to Redis
redisClient.on('connect', () => {
console.log(`Connected to Redis instance: ${redisUrl}`)
})
// Provide feedback in case of unsuccessful connection to Redis
redisClient.on('error', (err) => {
console.error(`Error connecting to Redis instance: ${redisUrl}`, err)
})

// Initialize store.
let redisStore = new RedisStore({
Expand Down
28 changes: 18 additions & 10 deletions src/components/Menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import { ArrowDown } from '@element-plus/icons-vue'
import { SEARCH_LINKS_COLOR as searchLinksColorSetting } from '../obp/style-setting'
import { inject, ref } from 'vue'
import { updateServerStatus } from '@/obp/common-functions';
import { updateServerStatus, clearCacheByName } from '@/obp/common-functions';
import { obpApiHostKey } from '@/obp/keys';
const APP_VERSION = ref(__APP_VERSION__)
Expand All @@ -42,6 +42,10 @@ const handleLocale = (command: string) => {
const updateStatus = (event: any) => {
updateServerStatus()
}
const clearCacheStorage = (event: any) => {
clearCacheByName('obp-message-docs-cache')
clearCacheByName('obp-resource-docs-cache')
}
</script>

<template>
Expand All @@ -51,10 +55,9 @@ const updateStatus = (event: any) => {
<span id="selected-api-version" class="host">OBPv5.1.0</span>
</el-col>
<el-col :span="14" class="menu-right">
<span class="host">App Version: {{ APP_VERSION }}</span>
<span class="host" id="cache-storage-status" @click="clearCacheStorage">App Version: {{ APP_VERSION }}</span>
&nbsp;&nbsp;
<span class="host"
><span id="backend-status" @click="updateStatus" >API Host: </span>
<span class="host"><span id="backend-status" @click="updateStatus">API Host: </span>
<a :href="OBP_API_HOST">
{{ OBP_API_HOST }}
</a>
Expand All @@ -69,12 +72,8 @@ const updateStatus = (event: any) => {
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-for="locale in $i18n.availableLocales"
:key="`locale-${locale}`"
:command="locale"
>{{ locale }}</el-dropdown-item
>
<el-dropdown-item v-for="locale in $i18n.availableLocales" :key="`locale-${locale}`" :command="locale">{{
locale }}</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
Expand All @@ -89,22 +88,31 @@ a {
color: #7787a6;
text-decoration: none;
}
a:hover {
color: v-bind(searchLinksColor);
}
.host {
font-size: 14px;
font-family: 'Roboto';
}
.menu-left,
.menu-right,
.el-dropdown-menu {
color: #7787a6;
}
.server-is-online {
color: v-bind(searchLinksColor);
}
.server-is-offline {
color: red;
}
.text-is-red {
color: red;
}
</style>
4 changes: 3 additions & 1 deletion src/language/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@

import en from './en.json'
import es from './es.json'
import ro from './ro.json'

export const defaultLocale = 'EN'

export const languages = {
EN: en,
ES: es
ES: es,
RO: ro
}
19 changes: 19 additions & 0 deletions src/language/ro.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"header": {
"portal_home": "Portal Acasă",
"api_explorer": "Explorator API",
"api_manager": "Administrator API",
"glossary": "Glosar",
"more": "Mai mult",
"spaces": "Spații",
"login": "Autentificare",
"logoff": "Deconectare"
},
"preview": {
"required_roles": "ROLURI NECESARE",
"validations": "VALIDĂRI",
"possible_errors": "POSIBILE ERORI",
"connector_methods": "METODE DE CONECTOR"
}
}

22 changes: 22 additions & 0 deletions src/obp/common-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,26 @@ export async function getOpeyJWT() {
})
const token = String(response?.data?.token)
return token
}

export function clearCacheByName(cacheName: string) {
if ('caches' in window) {
caches.delete(cacheName).then(function(success) {
if (success) {
console.log(`Cache ${cacheName} deleted successfully`);
} else {
console.log(`Failed to delete cache ${cacheName}`);
}
});
caches.keys().then(function(keys) {
if (keys.length === 0) {
console.log('Cache exists but is empty');
const oElem = document.getElementById('cache-storage-status')
if (oElem) {
oElem.className = 'host text-is-red'
}
}
});
}

}

0 comments on commit 0c1c996

Please sign in to comment.