2020-04-22 19:07:51 +05:30
|
|
|
import Vue from 'vue';
|
2020-07-28 23:09:34 +05:30
|
|
|
import { createStore } from './store';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
2020-05-24 23:13:21 +05:30
|
|
|
import IntegrationForm from './components/integration_form.vue';
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
function parseBooleanInData(data) {
|
|
|
|
const result = {};
|
|
|
|
Object.entries(data).forEach(([key, value]) => {
|
|
|
|
result[key] = parseBoolean(value);
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
function parseDatasetToProps(data) {
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
type,
|
|
|
|
commentDetail,
|
|
|
|
projectKey,
|
|
|
|
upgradePlanPath,
|
|
|
|
editProjectPath,
|
|
|
|
triggerEvents,
|
|
|
|
fields,
|
|
|
|
inheritFromId,
|
|
|
|
...booleanAttributes
|
|
|
|
} = data;
|
2020-05-24 23:13:21 +05:30
|
|
|
const {
|
|
|
|
showActive,
|
|
|
|
activated,
|
|
|
|
commitEvents,
|
|
|
|
mergeRequestEvents,
|
|
|
|
enableComments,
|
2020-07-28 23:09:34 +05:30
|
|
|
showJiraIssuesIntegration,
|
|
|
|
enableJiraIssues,
|
2020-05-24 23:13:21 +05:30
|
|
|
} = parseBooleanInData(booleanAttributes);
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
return {
|
|
|
|
activeToggleProps: {
|
|
|
|
initialActivated: activated,
|
|
|
|
},
|
|
|
|
showActive,
|
|
|
|
type,
|
|
|
|
triggerFieldsProps: {
|
|
|
|
initialTriggerCommit: commitEvents,
|
|
|
|
initialTriggerMergeRequest: mergeRequestEvents,
|
|
|
|
initialEnableComments: enableComments,
|
|
|
|
initialCommentDetail: commentDetail,
|
|
|
|
},
|
|
|
|
jiraIssuesProps: {
|
|
|
|
showJiraIssuesIntegration,
|
|
|
|
initialEnableJiraIssues: enableJiraIssues,
|
|
|
|
initialProjectKey: projectKey,
|
|
|
|
upgradePlanPath,
|
|
|
|
editProjectPath,
|
|
|
|
},
|
|
|
|
triggerEvents: JSON.parse(triggerEvents),
|
|
|
|
fields: JSON.parse(fields),
|
|
|
|
inheritFromId: parseInt(inheritFromId, 10),
|
|
|
|
id: parseInt(id, 10),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default (el, adminEl) => {
|
|
|
|
if (!el) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const props = parseDatasetToProps(el.dataset);
|
|
|
|
|
|
|
|
const initialState = {
|
|
|
|
adminState: null,
|
|
|
|
customState: props,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (adminEl) {
|
|
|
|
initialState.adminState = Object.freeze(parseDatasetToProps(adminEl.dataset));
|
|
|
|
}
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
return new Vue({
|
|
|
|
el,
|
2020-07-28 23:09:34 +05:30
|
|
|
store: createStore(initialState),
|
2020-04-22 19:07:51 +05:30
|
|
|
render(createElement) {
|
2020-07-28 23:09:34 +05:30
|
|
|
return createElement(IntegrationForm);
|
2020-04-22 19:07:51 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|