|
27 | 27 | import bootstrapTableMixin from "../../mixins/bootstrapTableMixin"; |
28 | 28 | import BInputGroupFormSelect from "../../forms/BInputGroupFormSelect"; |
29 | 29 | import PolicyCondition from "./PolicyCondition"; |
| 30 | + import BToggleableDisplayButton from "@/views/components/BToggleableDisplayButton"; |
| 31 | + import SelectProjectModal from "@/views/portfolio/projects/SelectProjectModal"; |
30 | 32 |
|
31 | 33 | export default { |
32 | 34 | mixins: [permissionsMixin, bootstrapTableMixin], |
|
124 | 126 | </div> |
125 | 127 | </b-form-group> |
126 | 128 | <div style="text-align:right"> |
| 129 | + <b-toggleable-display-button variant="outline-primary" :label="$t('admin.limit_to')" |
| 130 | + v-permission="PERMISSIONS.VIEW_PORTFOLIO" v-on:toggle="limitToVisible = !limitToVisible" /> |
127 | 131 | <b-button variant="outline-danger" @click="deletePolicy">{{ $t('message.delete_policy') }}</b-button> |
128 | 132 | </div> |
129 | 133 | </b-col> |
130 | 134 | </b-row> |
131 | | - </div> |
| 135 | + <b-row> |
| 136 | + <b-col md="6"> |
| 137 | + <b-form-group v-if="limitToVisible === true" id="projectLimitsList" :label="this.$t('admin.limit_to_projects')"> |
| 138 | + <div class="list-group"> |
| 139 | + <span v-for="project in projects"> |
| 140 | + <actionable-list-group-item :value="formatProjectLabel(project.name, project.version)" delete-icon="true" v-on:actionClicked="deleteLimiter(project.uuid)"/> |
| 141 | + </span> |
| 142 | + <actionable-list-group-item add-icon="true" v-on:actionClicked="$root.$emit('bv::show::modal', 'selectProjectModal')"/> |
| 143 | + </div> |
| 144 | + </b-form-group> |
| 145 | + </b-col> |
| 146 | + </b-row> |
| 147 | + <select-project-modal v-on:selection="updateProjectSelection"/> |
| 148 | + </div> |
132 | 149 | `, |
133 | 150 | mixins: [permissionsMixin], |
134 | 151 | components: { |
135 | 152 | ActionableListGroupItem, |
136 | 153 | BInputGroupFormInput, |
137 | 154 | BInputGroupFormSelect, |
| 155 | + BToggleableDisplayButton, |
| 156 | + SelectProjectModal, |
138 | 157 | PolicyCondition |
139 | 158 | }, |
140 | 159 | data() { |
|
152 | 171 | { value: 'INFO', text: this.$t('violation.info') }, |
153 | 172 | { value: 'WARN', text: this.$t('violation.warn') }, |
154 | 173 | { value: 'FAIL', text: this.$t('violation.fail') } |
155 | | - ] |
| 174 | + ], |
| 175 | + projects: row.projects, |
| 176 | + limitToVisible: false |
156 | 177 | } |
157 | 178 | }, |
158 | 179 | methods: { |
| 180 | + formatProjectLabel: function(projectName, projectVersion) { |
| 181 | + if (projectName && projectVersion) { |
| 182 | + return projectName + " " + projectVersion; |
| 183 | + } else { |
| 184 | + return projectName; |
| 185 | + } |
| 186 | + }, |
159 | 187 | addCondition: function() { |
160 | 188 | if (! this.conditions) { |
161 | 189 | this.conditions = []; |
|
204 | 232 | this.operator = policy.operator; |
205 | 233 | this.violationState = policy.violationState; |
206 | 234 | this.conditions = policy.policyConditions; |
| 235 | + }, |
| 236 | + deleteLimiter: function(projectUuid) { |
| 237 | + let url = `${this.$api.BASE_URL}/${this.$api.URL_POLICY}/${this.policy.uuid}/project/${projectUuid}`; |
| 238 | + this.axios.delete(url).then((response) => { |
| 239 | + let p = []; |
| 240 | + for (let i=0; i<this.projects.length; i++) { |
| 241 | + if (this.projects[i].uuid !== projectUuid) { |
| 242 | + p.push(this.projects[i]); |
| 243 | + } |
| 244 | + } |
| 245 | + this.projects = p; |
| 246 | + this.$toastr.s(this.$t('message.updated')); |
| 247 | + }).catch((error) => { |
| 248 | + this.$toastr.w(this.$t('condition.unsuccessful_action')); |
| 249 | + }); |
| 250 | + }, |
| 251 | + updateProjectSelection: function(selections) { |
| 252 | + this.$root.$emit('bv::hide::modal', 'selectProjectModal'); |
| 253 | + for (let i=0; i<selections.length; i++) { |
| 254 | + let selection = selections[i]; |
| 255 | + let url = `${this.$api.BASE_URL}/${this.$api.URL_POLICY}/${this.policy.uuid}/project/${selection.uuid}`; |
| 256 | + this.axios.post(url).then((response) => { |
| 257 | + this.projects.push(selection); |
| 258 | + this.$toastr.s(this.$t('message.updated')); |
| 259 | + }).catch((error) => { |
| 260 | + if (error.response.status === 304) { |
| 261 | + //this.$toastr.w(this.$t('condition.unsuccessful_action')); |
| 262 | + } else { |
| 263 | + this.$toastr.w(this.$t('condition.unsuccessful_action')); |
| 264 | + } |
| 265 | + }); |
| 266 | + } |
207 | 267 | } |
208 | 268 | }, |
209 | 269 | watch: { |
|
0 commit comments