This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
template_fields.js
150 lines (147 loc) · 4.35 KB
/
template_fields.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// This JS is used only when create / edit template. (Using Vue.js)
'use strict'
const vm = new Vue({
el: '#json_generator',
data: {
items: [],
customFields: {},
newItemTitle: '',
newItemValue: '',
api_builtin_fields: {},
api_custom_fields: {},
customFieldUrl: ''
},
methods: {
addField: function (newFieldName, newFieldValue) {
if (newFieldName === '' || newFieldValue === '') {
return
}
this.items.push({
title: newFieldName,
value: newFieldValue
})
this.newFieldName = ''
this.newFieldValue = ''
},
deleteField: function (target) {
this.items = this.items.filter(function (item) {
return item !== target
})
},
loadField: function () {
this.api_builtin_fields = base_builtin_fields
this.api_custom_fields = base_custom_fields
this.items = []
if (this.api_builtin_fields) {
for (const [key, value] of Object.entries(this.api_builtin_fields)) {
this.items.push({
title: key,
value: value
})
}
}
// { "issue_priority_id":"Priority", "issue_start_date":"Start date" }
if (this.api_custom_fields) {
for (const [key, value] of Object.entries(this.api_custom_fields)) {
this.customFields[key] = value
}
}
},
updateSelectableField: function () {
let tmpFields = {}
if (this.api_custom_fields) {
for (const [key, value] of Object.entries(this.api_custom_fields)) {
tmpFields[key] = value
}
}
this.customFields = tmpFields
},
fieldFormat: function () {
const fields = this.customFields
const title = this.newItemTitle
if (fields[title] && fields[title].field_format) {
const format = fields[title].field_format
if (format === 'int' || format === 'date' || format === 'ratio' ||
format === 'list' || format === 'bool' || format === 'string') {
return fields[title].field_format
}
}
return 'text'
},
possibleValues: function () {
const fields = this.customFields
const title = this.newItemTitle
return fields[title].possible_values
}
},
mounted: function () {
const trackerPulldown = document.getElementById(trackerPulldownId)
if (trackerPulldown) {
if (trackerPulldown.value === '') {
this.$el.style.display = 'none'
}
trackerPulldown.addEventListener('change', event => {
if (event.target.value === '') {
this.$el.style.display = 'none'
return
}
this.$el.style.display = 'block'
const trackerId = event.target.value
let url = baseUrl + '?tracker_id=' + trackerId + '&template_id=' + templateId
if (typeof projectId !== 'undefined') {
url += '&project_id=' + projectId
}
window.fetch(url)
.then((response) => {
return response.text()
})
.then((data) => {
let obj = JSON.parse(data)
this.api_custom_fields = obj.custom_fields
this.updateSelectableField()
})
})
}
this.loadField()
},
computed: {
// not yet
},
watch: {
newItemTitle: function (val) {
if (typeof relativeUrlRoot === 'undefined') {
this.customFieldUrl = ''
return
}
let field = this.customFields[val]
if (field == null || field.type != 'IssueCustomField') {
this.customFieldUrl = ''
return
}
this.customFieldUrl = relativeUrlRoot + '/custom_fields/' + field.id + '/edit'
}
}
})
// Apply post data.
const copyJson = document.getElementById('paste-json')
if (copyJson) {
copyJson.addEventListener('click', (event) => {
const data = document.getElementById('builtin_fields_data_via_vue')
if (data) {
const text = data.innerText
let jsonObj = JSON.parse(text)
let convertObj = {}
jsonObj.forEach(item => {
let value = item.value
if (item.title === 'issue_watcher_user_ids') {
value = item.value.map(user => {
let idx = user.lastIndexOf(':')
return user.substring(idx + 1)
})
}
convertObj[item.title] = value
})
document.getElementById(templateType + '_builtin_fields').value = JSON.stringify(convertObj)
}
})
}