2020-04-22 19:07:51 +05:30
|
|
|
import Vue from 'vue';
|
2023-03-04 22:38:38 +05:30
|
|
|
import VueApollo from 'vue-apollo';
|
2023-03-17 16:20:25 +05:30
|
|
|
import VueRouter from 'vue-router';
|
2021-10-27 15:23:28 +05:30
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
|
|
|
import EnvironmentsDetailHeader from './components/environments_detail_header.vue';
|
2023-03-04 22:38:38 +05:30
|
|
|
import { apolloProvider } from './graphql/client';
|
2020-04-22 19:07:51 +05:30
|
|
|
import environmentsMixin from './mixins/environments_mixin';
|
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
export const initHeader = () => {
|
|
|
|
const el = document.getElementById('environments-detail-view-header');
|
2020-04-22 19:07:51 +05:30
|
|
|
const container = document.getElementById('environments-detail-view');
|
2021-10-27 15:23:28 +05:30
|
|
|
const dataset = convertObjectPropsToCamelCase(JSON.parse(container.dataset.details));
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
mixins: [environmentsMixin],
|
|
|
|
data() {
|
2021-10-27 15:23:28 +05:30
|
|
|
const environment = {
|
|
|
|
name: dataset.name,
|
|
|
|
id: Number(dataset.id),
|
|
|
|
externalUrl: dataset.externalUrl,
|
|
|
|
isAvailable: dataset.isEnvironmentAvailable,
|
|
|
|
hasTerminals: dataset.hasTerminals,
|
|
|
|
autoStopAt: dataset.autoStopAt,
|
|
|
|
onSingleEnvironmentPage: true,
|
|
|
|
// TODO: These two props are snake_case because the environments_mixin file uses
|
|
|
|
// them and the mixin is imported in several files. It would be nice to conver them to camelCase.
|
|
|
|
stop_path: dataset.environmentStopPath,
|
|
|
|
delete_path: dataset.environmentDeletePath,
|
|
|
|
};
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
return {
|
|
|
|
environment,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render(createElement) {
|
2021-10-27 15:23:28 +05:30
|
|
|
return createElement(EnvironmentsDetailHeader, {
|
2020-04-22 19:07:51 +05:30
|
|
|
props: {
|
|
|
|
environment: this.environment,
|
2021-10-27 15:23:28 +05:30
|
|
|
canDestroyEnvironment: dataset.canDestroyEnvironment,
|
|
|
|
canUpdateEnvironment: dataset.canUpdateEnvironment,
|
|
|
|
canStopEnvironment: dataset.canStopEnvironment,
|
|
|
|
canAdminEnvironment: dataset.canAdminEnvironment,
|
|
|
|
cancelAutoStopPath: dataset.environmentCancelAutoStopPath,
|
|
|
|
terminalPath: dataset.environmentTerminalPath,
|
|
|
|
metricsPath: dataset.environmentMetricsPath,
|
2023-03-17 16:20:25 +05:30
|
|
|
updatePath: dataset.environmentEditPath,
|
2023-03-04 22:38:38 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export const initPage = async () => {
|
|
|
|
if (!gon.features.environmentDetailsVue) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
const EnvironmentsDetailPageModule = await import('./environment_details/index.vue');
|
|
|
|
const EnvironmentsDetailPage = EnvironmentsDetailPageModule.default;
|
|
|
|
const dataElement = document.getElementById('environments-detail-view');
|
|
|
|
const dataSet = convertObjectPropsToCamelCase(JSON.parse(dataElement.dataset.details));
|
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
2023-03-17 16:20:25 +05:30
|
|
|
Vue.use(VueRouter);
|
2023-03-04 22:38:38 +05:30
|
|
|
const el = document.getElementById('environment_details_page');
|
2023-03-17 16:20:25 +05:30
|
|
|
|
|
|
|
const router = new VueRouter({
|
|
|
|
mode: 'history',
|
|
|
|
base: window.location.pathname,
|
|
|
|
routes: [
|
|
|
|
{
|
|
|
|
path: '/',
|
|
|
|
name: 'environment_details',
|
|
|
|
component: EnvironmentsDetailPage,
|
|
|
|
props: (route) => ({
|
|
|
|
after: route.query.after,
|
|
|
|
before: route.query.before,
|
|
|
|
projectFullPath: dataSet.projectFullPath,
|
|
|
|
environmentName: dataSet.name,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
scrollBehavior(to, from, savedPosition) {
|
|
|
|
if (savedPosition) {
|
|
|
|
return savedPosition;
|
|
|
|
}
|
|
|
|
return { top: 0 };
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
apolloProvider: apolloProvider(),
|
2023-03-17 16:20:25 +05:30
|
|
|
router,
|
2023-03-04 22:38:38 +05:30
|
|
|
provide: {},
|
|
|
|
render(createElement) {
|
2023-03-17 16:20:25 +05:30
|
|
|
return createElement('router-view');
|
2020-04-22 19:07:51 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|