Skip to content

Commit b6de071

Browse files
authored
Merge pull request #2135 from MetRonnie/dev
* Include cylc-flow & UIS version in sidebar. * Simplify user service.
1 parent c3cd24d commit b6de071

File tree

15 files changed

+118
-69
lines changed

15 files changed

+118
-69
lines changed

changes.d/2135.feat.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Show more Cylc version info in the sidebar.

src/components/cylc/Drawer.vue

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3333
to="/"
3434
>
3535
<template v-slot:prepend>
36-
<v-icon style="opacity: 1;">{{ $options.icons.mdiHome }}</v-icon>
36+
<v-icon style="opacity: 1;">{{ mdiHome }}</v-icon>
3737
</template>
3838
<v-list-item-title>Dashboard</v-list-item-title>
3939
</v-list-item>
@@ -49,21 +49,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4949
</div>
5050
<div class="resize-bar" ref="resizeBar"></div>
5151
<template v-slot:append>
52-
<div class="px-4 py-2 d-flex justify-center">
53-
<span class="text--secondary">
54-
<strong v-if="$options.mode !== 'production'">{{ $options.mode.toUpperCase() }}</strong> {{ $t('App.name') }} {{ $options.version }}
55-
</span>
52+
<div class="pa-2 d-flex justify-center">
53+
<v-chip
54+
id="version-chip"
55+
label
56+
class="font-weight-bold cursor-default"
57+
:prepend-icon="mdiInformationOutline"
58+
v-bind="versionChipProps"
59+
/>
60+
<v-tooltip
61+
activator="#version-chip"
62+
location="top"
63+
>
64+
<div
65+
class="d-flex flex-column align-center"
66+
style="pointer-events: visible;"
67+
data-cy="version-tooltip"
68+
>
69+
<span
70+
v-for="(value, key) in cylcVersionInfo"
71+
:key="key"
72+
>
73+
{{ key }} {{ value }}
74+
</span>
75+
<span>cylc-ui {{ UIVersion }}</span>
76+
</div>
77+
</v-tooltip>
5678
</div>
5779
</template>
5880
</v-navigation-drawer>
5981
</template>
6082

6183
<script>
62-
import { nextTick, ref } from 'vue'
84+
import { inject, nextTick, ref, computed } from 'vue'
6385
import { useDisplay } from 'vuetify'
6486
import Header from '@/components/cylc/Header.vue'
6587
import Workflows from '@/views/Workflows.vue'
66-
import { mdiHome, mdiGraphql } from '@mdi/js'
88+
import { mdiHome, mdiInformationOutline } from '@mdi/js'
6789
import pkg from '@/../package.json'
6890
import { when } from '@/utils'
6991
import { useDrawer } from '@/utils/toolbar'
@@ -122,18 +144,29 @@ export default {
122144
)
123145
})
124146
147+
const cylcVersionInfo = inject('versionInfo')
148+
const versionChipProps = computed(() => import.meta.env.MODE === 'production'
149+
? {
150+
text: `Cylc ${cylcVersionInfo.value?.['cylc-flow'] ?? ''}`,
151+
variant: 'text'
152+
}
153+
: {
154+
text: import.meta.env.MODE.toUpperCase(),
155+
variant: 'flat',
156+
color: 'indigo-darken-4',
157+
}
158+
)
159+
125160
return {
126161
drawer,
127162
drawerWidth,
128163
resizeBar,
164+
UIVersion: pkg.version,
165+
cylcVersionInfo,
166+
mdiInformationOutline,
167+
mdiHome,
168+
versionChipProps,
129169
}
130170
},
131-
132-
icons: {
133-
mdiHome,
134-
mdiGraphql,
135-
},
136-
mode: import.meta.env.MODE,
137-
version: pkg.version,
138171
}
139172
</script>

src/graphql/graphiql.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import { parse } from 'graphql'
2121
import { createGraphQLUrls } from '@/graphql/index'
22-
import { getCylcHeaders } from '@/utils/urls'
22+
import { getXSRFHeaders } from '@/utils/urls'
2323

2424
// TODO: https://github.com/apollographql/GraphiQL-Subscriptions-Fetcher/issues/16
2525
// the functions hasSubscriptionOperation and graphQLFetcher are both from
@@ -115,7 +115,7 @@ function fallbackGraphQLFetcher (graphQLParams) {
115115
headers: {
116116
Accept: 'application/json',
117117
'Content-Type': 'application/json',
118-
...getCylcHeaders()
118+
...getXSRFHeaders()
119119
},
120120
body: JSON.stringify(graphQLParams),
121121
credentials: 'include'

src/graphql/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { getMainDefinition } from '@apollo/client/utilities'
2727
import { WebSocketLink } from '@apollo/client/link/ws'
2828
import { setContext } from '@apollo/client/link/context'
2929
import { store } from '@/store/index'
30-
import { createUrl, getCylcHeaders } from '@/utils/urls'
30+
import { createUrl, getXSRFHeaders } from '@/utils/urls'
3131

3232
/** @typedef {import('subscriptions-transport-ws').ClientOptions} ClientOptions */
3333

@@ -133,7 +133,7 @@ export function createApolloClient (httpUrl, subscriptionClient) {
133133
return {
134134
headers: {
135135
...headers,
136-
...getCylcHeaders()
136+
...getXSRFHeaders()
137137
}
138138
}
139139
})

src/router/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { i18n } from '@/i18n'
3030
import paths from '@/router/paths'
3131
import { store } from '@/store/index'
3232
import { Alert } from '@/model/Alert.model'
33+
import { getUserProfile } from '@/services/user.service'
3334

3435
const defaultPageTitle = i18n.global.t('App.name')
3536

@@ -72,7 +73,7 @@ const router = createRouter({
7273
router.beforeEach(async (to, from) => {
7374
NProgress.start()
7475
if (!store.state.user.user) {
75-
const user = await router.app.config.globalProperties.$userService.getUserProfile()
76+
const user = await getUserProfile()
7677
// TODO: catch error getting user profile and redirect to static error page
7778
store.commit('user/SET_USER', user)
7879
}

src/services/mock/json-server.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
const PORT = 3000
2020

2121
const userProfile = require('./json/userprofile.json')
22+
const versionInfo = require('./json/version.json')
2223
const graphql = require('./graphql.cjs')
2324
const websockets = require('./websockets.cjs')
2425

@@ -29,6 +30,7 @@ const server = jsonServer.create()
2930
require('express-ws')(server)
3031
const router = jsonServer.router({
3132
userProfile,
33+
version: versionInfo,
3234
})
3335
const middlewares = [
3436
...jsonServer.defaults({ logger: false }),
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"cylc-flow": "X.Y.Z",
3+
"cylc-uiserver": "X.Y.Z"
4+
}

src/services/plugin.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18+
import { shallowRef } from 'vue'
1819
import { createSubscriptionClient, createGraphQLUrls } from '@/graphql'
1920
import SubscriptionWorkflowService from '@/services/workflow.service'
20-
import UserService from '@/services/user.service'
21+
import { fetchData } from '@/utils/urls'
2122

2223
/**
2324
* A plugin that loads the application services.
@@ -28,7 +29,10 @@ export default {
2829
*/
2930
install (app) {
3031
this._installWorkflowService(app)
31-
this._installUserService(app)
32+
33+
const versionInfo = shallowRef(null)
34+
app.provide('versionInfo', versionInfo)
35+
fetchData('version').then((data) => { versionInfo.value = data })
3236
},
3337

3438
/**
@@ -51,16 +55,4 @@ export default {
5155
// Options API (legacy):
5256
app.config.globalProperties.$workflowService = workflowService
5357
},
54-
55-
/**
56-
* Creates a user service for the application.
57-
*
58-
* The service is available as `Vue.$userService`.
59-
*
60-
* @private
61-
* @param {Object} app - Vue application
62-
*/
63-
_installUserService (app) {
64-
app.config.globalProperties.$userService = new UserService()
65-
}
6658
}

src/services/user.service.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,13 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

18-
import axios from 'axios'
1918
import User from '@/model/User.model'
20-
import { createUrl, getCylcHeaders } from '@/utils/urls'
19+
import { fetchData } from '@/utils/urls'
2120

22-
export default class UserService {
23-
/**
24-
* Gets the user profile from the backend server.
25-
* @returns {Promise<User>} - a promise that dispatches Vuex action
26-
*/
27-
async getUserProfile () {
28-
const { data } = await axios.get(
29-
createUrl('userprofile'),
30-
{ headers: getCylcHeaders() }
31-
)
32-
return new User(data)
33-
}
21+
/**
22+
* Gets the user profile from the backend server.
23+
* @returns {Promise<User>}
24+
*/
25+
export async function getUserProfile () {
26+
return new User(await fetchData('userprofile'))
3427
}

src/store/user.module.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,8 @@ export const mutations = {
2525
}
2626
}
2727

28-
export const actions = {
29-
setUser ({ commit }, user) {
30-
commit('SET_USER', user)
31-
}
32-
}
33-
3428
export const user = {
3529
namespaced: true,
3630
state,
3731
mutations,
38-
actions
3932
}

0 commit comments

Comments
 (0)