|
29 | 29 | import PolicyCondition from "./PolicyCondition"; |
30 | 30 | import BToggleableDisplayButton from "@/views/components/BToggleableDisplayButton"; |
31 | 31 | import SelectProjectModal from "@/views/portfolio/projects/SelectProjectModal"; |
| 32 | + import SelectTagModal from "@/views/portfolio/tags/SelectTagModal"; |
32 | 33 |
|
33 | 34 | export default { |
34 | 35 | mixins: [permissionsMixin, bootstrapTableMixin], |
|
128 | 129 | <b-form-group v-if="limitToVisible === true" id="projectLimitsList" :label="this.$t('admin.limit_to_projects')"> |
129 | 130 | <div class="list-group"> |
130 | 131 | <span v-for="project in projects"> |
131 | | - <actionable-list-group-item :value="formatProjectLabel(project.name, project.version)" :delete-icon="true" v-on:actionClicked="deleteLimiter(project.uuid)"/> |
| 132 | + <actionable-list-group-item :value="formatLabel(project.name, project.version)" :delete-icon="true" v-on:actionClicked="deleteProjectLimiter(project.uuid)"/> |
132 | 133 | </span> |
133 | 134 | <actionable-list-group-item :add-icon="true" v-on:actionClicked="$root.$emit('bv::show::modal', 'selectProjectModal')"/> |
134 | 135 | </div> |
135 | 136 | </b-form-group> |
| 137 | + <b-form-group v-if="limitToVisible === true" id="tagLimitsList" :label="this.$t('admin.limit_to_tags')"> |
| 138 | + <div class="list-group"> |
| 139 | + <span v-for="tag in tags"> |
| 140 | + <actionable-list-group-item :value="formatLabel(tag.name, tag.id)" :delete-icon="true" v-on:actionClicked="deleteTagLimiter(tag.name)"/> |
| 141 | + </span> |
| 142 | + <actionable-list-group-item :add-icon="true" v-on:actionClicked="$root.$emit('bv::show::modal', 'selectTagModal')"/> |
| 143 | + </div> |
| 144 | + </b-form-group> |
136 | 145 | <div style="text-align:right"> |
137 | 146 | <b-toggleable-display-button variant="outline-primary" :label="$t('admin.limit_to')" |
138 | 147 | v-permission="PERMISSIONS.VIEW_PORTFOLIO" v-on:toggle="limitToVisible = !limitToVisible" /> |
|
141 | 150 | </b-col> |
142 | 151 | </b-row> |
143 | 152 | <select-project-modal v-on:selection="updateProjectSelection"/> |
| 153 | + <select-tag-modal :policy="policy" v-on:selection="updateTagSelection"/> |
144 | 154 | </div> |
145 | 155 | `, |
146 | 156 | mixins: [permissionsMixin], |
|
150 | 160 | BInputGroupFormSelect, |
151 | 161 | BToggleableDisplayButton, |
152 | 162 | SelectProjectModal, |
| 163 | + SelectTagModal, |
153 | 164 | PolicyCondition |
154 | 165 | }, |
155 | 166 | data() { |
|
169 | 180 | { value: 'FAIL', text: this.$t('violation.fail') } |
170 | 181 | ], |
171 | 182 | projects: row.projects, |
172 | | - limitToVisible: false |
| 183 | + limitToVisible: false, |
| 184 | + tags: row.tags |
173 | 185 | } |
174 | 186 | }, |
175 | 187 | methods: { |
176 | | - formatProjectLabel: function(projectName, projectVersion) { |
177 | | - if (projectName && projectVersion) { |
178 | | - return projectName + " " + projectVersion; |
| 188 | + formatLabel: function(labelName, labelProperty) { |
| 189 | + if (labelName && labelProperty) { |
| 190 | + return labelName + " " + labelProperty; |
179 | 191 | } else { |
180 | | - return projectName; |
| 192 | + return labelName; |
181 | 193 | } |
182 | 194 | }, |
183 | 195 | addCondition: function() { |
|
229 | 241 | this.violationState = policy.violationState; |
230 | 242 | this.conditions = policy.policyConditions; |
231 | 243 | }, |
232 | | - deleteLimiter: function(projectUuid) { |
| 244 | + deleteProjectLimiter: function(projectUuid) { |
233 | 245 | let url = `${this.$api.BASE_URL}/${this.$api.URL_POLICY}/${this.policy.uuid}/project/${projectUuid}`; |
234 | 246 | this.axios.delete(url).then((response) => { |
235 | 247 | let p = []; |
|
244 | 256 | this.$toastr.w(this.$t('condition.unsuccessful_action')); |
245 | 257 | }); |
246 | 258 | }, |
| 259 | + deleteTagLimiter: function(tagName) { |
| 260 | + let url = `${this.$api.BASE_URL}/${this.$api.URL_POLICY}/${this.policy.uuid}/tag/${tagName}`; |
| 261 | + this.axios.delete(url).then((response) => { |
| 262 | + let p = []; |
| 263 | + for (let i=0; i<this.tags.length; i++) { |
| 264 | + if (this.tags[i].name !== tagName) { |
| 265 | + p.push(this.tags[i]); |
| 266 | + } |
| 267 | + } |
| 268 | + this.tags = p; |
| 269 | + this.$toastr.s(this.$t('message.updated')); |
| 270 | + }).catch((error) => { |
| 271 | + this.$toastr.w(this.$t('condition.unsuccessful_action')); |
| 272 | + }); |
| 273 | + }, |
247 | 274 | updateProjectSelection: function(selections) { |
248 | 275 | this.$root.$emit('bv::hide::modal', 'selectProjectModal'); |
249 | 276 | for (let i=0; i<selections.length; i++) { |
|
260 | 287 | } |
261 | 288 | }); |
262 | 289 | } |
| 290 | + }, |
| 291 | + updateTagSelection: function(selections) { |
| 292 | + this.$root.$emit('bv::hide::modal', 'selectTagModal'); |
| 293 | + for (let i=0; i<selections.length; i++) { |
| 294 | + let selection = selections[i]; |
| 295 | + let url = `${this.$api.BASE_URL}/${this.$api.URL_POLICY}/${this.policy.uuid}/tag/${selection.name}`; |
| 296 | + this.axios.post(url).then((response) => { |
| 297 | + this.tags.push(selection); |
| 298 | + this.$toastr.s(this.$t('message.updated')); |
| 299 | + }).catch((error) => { |
| 300 | + this.$toastr.w(this.$t('condition.unsuccessful_action')); |
| 301 | + }); |
| 302 | + } |
263 | 303 | } |
264 | 304 | }, |
265 | 305 | watch: { |
|
0 commit comments