Skip to content

Commit

Permalink
Merge pull request #513 from Duke-MatSci/jhyang
Browse files Browse the repository at this point in the history
yaml converter all done
  • Loading branch information
tholulomo authored Oct 9, 2024
2 parents 7fce17a + bd4e0e9 commit f7ec7da
Show file tree
Hide file tree
Showing 16 changed files with 463 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/src/assets/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
@import './modules/_vega.scss';
@import './modules/_visualize.scss';
@import './modules/_tools.scss';
@import './modules/_nuplot.scss';
@import './modules/_nuplot.scss';
14 changes: 7 additions & 7 deletions app/src/components/explorer/XmlView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<div>
<pre class="language-xml grid">
<code class="inlinecode language-xml keepMarkUp">
{{ xml }}
</code>
</pre>
</div>
<div>
<pre class="language-xml grid">
<code class="inlinecode language-xml keepMarkUp">
{{ xml }}
</code>
</pre>
</div>
</template>

<script>
Expand Down
45 changes: 40 additions & 5 deletions app/src/pages/explorer/xml/XmlLoader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,27 @@
<h2 class="visualize_header-h1 u_margin-top-med u_centralize_text">
{{ optionalChaining(() => xmlViewer.title) }}
</h2>
<div class="u_centralize_text viz-u-mgbottom-sm">
<a
href="#"
class="viz-tab__button"
:class="[!loadYaml && 'active u--color-primary']"
>XML View</a
>
||
<a
class="viz-tab__button"
:class="[loadYaml && 'active u--color-primary']"
@click.prevent="openYaml(true)"
>YAML View</a
>
</div>
</div>
<!-- xml viewer -->
<div class="wrapper">
<XmlView :xml="optionalChaining(() => xmlViewer.xmlString)" />
<div class="wrapper" style="min-width: 90%">
<pre>
<code class="language-xml" >{{ optionalChaining(() => xmlViewer.xmlString) }}</code>
</pre>
</div>
</md-content>

Expand Down Expand Up @@ -141,7 +158,6 @@ import 'prismjs/themes/prism-coy.min.css'
import optionalChainingUtil from '@/mixins/optional-chaining-util'
import Comment from '@/components/explorer/Comment'
import spinner from '@/components/Spinner'
import XmlView from '@/components/explorer/XmlView'
import { XML_VIEWER } from '@/modules/gql/xml-gql'
import { mapGetters, mapActions, mapMutations } from 'vuex'
import dialogBox from '@/components/Dialog.vue'
Expand All @@ -152,7 +168,6 @@ export default {
components: {
Comment,
spinner,
XmlView,
dialogBox
},
data () {
Expand All @@ -174,6 +189,9 @@ export default {
},
isLargeTabView () {
return screen.width < 1024
},
loadYaml () {
return !!this.$route.query.isYaml
}
},
methods: {
Expand All @@ -197,12 +215,29 @@ export default {
},
async reloadXml () {
return await this.$apollo.queries.xmlFinder.refetch()
},
openYaml () {
const query = {
title: this.xmlViewer.title?.split('.')[0],
isNewCuration: this.$route.query?.isNewCuration,
isYaml: true
}
const params = {
id: this.$route.params.id
}
return this.$router.push({ name: 'YamlVisualizer', params, query })
}
},
mounted () {
window.Prism = window.Prism || {}
window.Prism.manual = true
Prism.highlightAll()
},
updated () {
const vm = this
setTimeout(() => {
Prism.highlightAll(vm.$refs.codeBlock)
}, 200)
},
apollo: {
xmlViewer: {
Expand Down
210 changes: 210 additions & 0 deletions app/src/pages/explorer/xml/YamlLoader.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<template>
<div class="xmlLoader">
<section
class="u_width--max viz-u-postion__rel utility-roverflow"
v-if="!yamlLoading"
>
<md-drawer
class="md-right"
:class="{ ' md-fixed': showSidepanel }"
:md-active.sync="showSidepanel"
>
<comment :type="type" :identifier="xmlId"></comment>
<md-button
@click="showSidepanel = false"
class="md-fab md-fixed md-dense md-fab-top-right md-primary btn--primary"
>
<md-icon>close</md-icon>
</md-button>
</md-drawer>

<div class="u_width--max viz-u-postion__rel utility-roverflow">
<md-content
class="u_width--max md-app-side-drawer md-app-container md-scrollbar u_margin-none"
>
<div :class="[isSmallTabView ? 'u_myprofile--container' : '']">
<h2 class="visualize_header-h1 u_margin-top-med u_centralize_text">
{{ `${optionalChaining(() => controlID)}.yaml` }}
</h2>
<div class="u_centralize_text viz-u-mgbottom-sm">
<a
@click.prevent="openYaml(true)"
class="viz-tab__button"
:class="[!loadYaml && 'active u--color-primary']"
>XML View</a
>
||
<a
class="viz-tab__button"
:class="[loadYaml && 'active u--color-primary']"
href="#"
>YAML View</a
>
</div>
</div>
<!-- xml viewer -->
<div class="wrapper" style="min-width: 90%" ref="codeBlock">
<!-- <XmlView ref="codeBlock" :content="dataFeed" :isYaml="loadYaml" /> -->
<pre>
<code class="language-yml keepMarkUp" >{{ optionalChaining(() => yamlString) }}</code>
</pre>
</div>
</md-content>

<md-content class="u_margin-bottom-small">
<md-button
class="md-primary md-raised btn--primary"
:class="[
isLargeTabView
? 'viz-u-display__show u--margin-centered'
: 'viz-u-postion__abs utility-absolute-input visualize--link-bottom'
]"
@click="
requestApproval({
curationId: xmlViewer.id,
isNew: xmlViewer.isNewCuration
})
"
v-if="
isAuth &&
!isAdmin &&
xmlViewer.status === 'Not Approved' &&
xmlViewer.curationState === 'Editing'
"
>
Request Approval
</md-button>
</md-content>
</div>
<div
:class="[
isSmallTabView
? 'u_margin-top-small u_adjust-banner-text'
: 'u--margin-neg',
'md-fab md-fab-top-right u_width--max u--shadow-none u--layout-flex u--layout-flex-justify-end u--b-rad'
]"
>
<md-button
class="md-fab md-dense md-primary btn--primary"
@click.native.prevent="navBack"
>
<md-tooltip> Go Back </md-tooltip>
<md-icon>arrow_back</md-icon>
</md-button>

<md-button
@click="showSidepanel = true"
class="md-fab md-dense md-primary btn--primary"
>
<md-tooltip md-direction="top">Comment</md-tooltip>
<md-icon>comment</md-icon>
</md-button>
</div>
</section>

<section class="section_loader u--margin-toplg" v-else>
<spinner :loading="yamlLoading" text="Loading Yaml" />
</section>
</div>
</template>

<script>
import Prism from 'prismjs'
import 'prismjs/themes/prism-coy.min.css'
import 'prismjs/themes/prism-dark.css'
import 'prismjs/themes/prism.css'
import 'prismjs/components/prism-yaml'
import optionalChainingUtil from '@/mixins/optional-chaining-util'
import Comment from '@/components/explorer/Comment'
import spinner from '@/components/Spinner'
import { mapGetters } from 'vuex'
export default {
name: 'YamlVisualizer',
mixins: [optionalChainingUtil],
components: {
Comment,
spinner
},
data () {
return {
showSidepanel: false,
type: 'xml',
yamlString: '',
yamlLoading: false
}
},
computed: {
...mapGetters({
isAuth: 'auth/isAuthenticated',
isAdmin: 'auth/isAdmin',
userId: 'auth/userId'
}),
isSmallTabView () {
return screen.width < 760
},
isLargeTabView () {
return screen.width < 1024
},
loadYaml () {
return !!this.$route.query.isYaml
},
xmlId () {
return this.$route.params.id
},
controlID () {
return this.$route.query?.title?.split('.')[0]
}
},
methods: {
navBack () {
this.$router.back()
},
async openAsYaml () {
this.yamlLoading = true
if (!this.controlID) {
this.yamlLoading = false
return this.$router.push({ name: 'XmlGallery' })
}
try {
const res = await fetch(`/api/mn/yaml-loader/${this.controlID}`)
if (!res.ok) {
throw new Error('Failed to convert to YAML')
}
const yamlText = await res.text()
this.yamlString = yamlText
this.yamlLoading = false
} catch (error) {
this.yamlLoading = false
this.$store.commit('setSnackbar', {
message:
error.message ??
'An error occurred while trying to convert to YAML',
action: () => this.openAsYaml()
})
}
},
openYaml () {
const query = {
isNewCuration: this.$route.query?.isNewCuration
}
const params = {
id: this.$route.params.id
}
return this.$router.push({ name: 'XmlVisualizer', params, query })
}
},
async mounted () {
await this.openAsYaml()
window.Prism = window.Prism || {}
window.Prism.manual = true
},
updated () {
const vm = this
setTimeout(() => {
Prism.highlightAll(vm.$refs.codeBlock)
}, 200)
}
}
</script>
6 changes: 6 additions & 0 deletions app/src/router/module/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ const explorerRoutes = [
component: () => import('@/pages/explorer/xml/XmlLoader.vue'),
meta: { requiresAuth: false }
},
{
path: 'yamlvisualizer/:id',
name: 'YamlVisualizer',
component: () => import('@/pages/explorer/xml/YamlLoader.vue'),
meta: { requiresAuth: false }
},
{
path: 'dataset',
component: ChartBase,
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ services:
- ./app:/app
managedservices:
container_name: managedservices
depends_on:
- mongo
# depends_on:
# - mongo
restart: always
build:
dockerfile: Dockerfile
Expand Down
3 changes: 2 additions & 1 deletion resfulservice/config/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ module.exports = {
ManagedServiceRegister: {
dynamfit: '/dynamfit/extract/',
chemprops: '/chemprops/call/',
ontology: '/ontology/extract/'
ontology: '/ontology/extract/',
'yaml-loader': '/yaml_converter/'
},
MGD_SVC_ERR_CODE: {
default: {
Expand Down
14 changes: 8 additions & 6 deletions resfulservice/src/controllers/managedServiceController.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ const { validateIsAdmin } = require('../middlewares/validations');
* @returns {*} response
*/
exports.manageServiceRequest = async (req, res, next) => {
const {
logger,
params: { appName },
body
} = req;
const { logger, params, body } = req;
const [appName, controlId] = params.appName?.split('/');
logger.info(':::manageServiceRequest Function Entry');
const reqId = uuidv4();
logger.info(`${appName}::${JSON.stringify({ ...body, reqId })}`);
Expand All @@ -41,7 +38,7 @@ exports.manageServiceRequest = async (req, res, next) => {
}

req.reqId = reqId;
req.url = `${req.env?.MANAGED_SERVICE_ADDRESS}${ManagedServiceRegister[appName]}`;
if (!controlId) { req.url = `${req.env?.MANAGED_SERVICE_ADDRESS}${ManagedServiceRegister[appName]}`; } else { req.url = `${req.env?.MANAGED_SERVICE_ADDRESS}${ManagedServiceRegister[appName]}${controlId}`; }
return await _managedServiceCall(req, res);
} catch (error) {
const statusCode = error?.response?.status ?? 500;
Expand Down Expand Up @@ -129,6 +126,11 @@ const _managedServiceCall = async (req, res) => {
`mgdsvc.${appName} = (${reqId}) => response.status(${response.status})`
);
if (response.status === 200) {
if (response.headers['content-type'] === 'text/yaml; charset=utf-8') {
res.setHeader('Content-Type', response.headers['content-type']);
return res.send(response.data);
// return res.status(200).json({ yamlString: YAML.stringify(yamlString) });
}
const errorObj = {};
if (response.headers.responseid !== reqId) {
errorObj.error = {
Expand Down
Loading

0 comments on commit f7ec7da

Please sign in to comment.