|
17 | 17 | v-model="project.classifier" :options="availableClassifiers" |
18 | 18 | :label="$t('message.classifier')" :tooltip="$t('message.component_classifier_desc')" |
19 | 19 | :readonly="this.isNotPermitted(PERMISSIONS.PORTFOLIO_MANAGEMENT)" /> |
| 20 | + <b-input-group-form-select id="project-parent-input" required="false" |
| 21 | + v-model="selectedParent" :options="availableParents" |
| 22 | + :label="$t('message.parent')" :readonly="this.isNotPermitted(PERMISSIONS.PORTFOLIO_MANAGEMENT)" /> |
20 | 23 | <b-form-group |
21 | 24 | id="project-description-form-group" |
22 | 25 | :label="this.$t('message.description')" |
|
33 | 36 | style="max-width:none; background-color:transparent;" |
34 | 37 | :readonly="this.isNotPermitted(PERMISSIONS.PORTFOLIO_MANAGEMENT)" /> |
35 | 38 | </b-form-group> |
36 | | - <c-switch id="input-5" class="mx-1" color="primary" v-model="project.active" label :disabled="this.isNotPermitted(PERMISSIONS.PORTFOLIO_MANAGEMENT)" v-bind="labelIcon" /> {{$t('message.active')}} |
| 39 | + <c-switch id="input-5" class="mx-1" color="primary" v-model="project.active" label |
| 40 | + :disabled="this.isNotPermitted(PERMISSIONS.PORTFOLIO_MANAGEMENT) || (project.active && this.hasActiveChild(project))" v-bind="labelIcon" |
| 41 | + v-b-tooltip.hover :title="$t('message.inactive_active_children')"/> {{$t('message.active')}} |
37 | 42 | <p></p> |
38 | 43 | <b-input-group-form-input id="project-uuid" input-group-size="mb-3" type="text" v-model="project.uuid" |
39 | 44 | lazy="false" required="false" feedback="false" autofocus="false" disabled="true" |
|
99 | 104 | cSwitch |
100 | 105 | }, |
101 | 106 | props: { |
102 | | - project: Object |
| 107 | + project: Object, |
| 108 | + uuid: String |
103 | 109 | }, |
104 | 110 | data() { |
105 | 111 | return { |
|
115 | 121 | { value: 'FIRMWARE', text: this.$i18n.t('message.component_firmware') }, |
116 | 122 | { value: 'FILE', text: this.$i18n.t('message.component_file') } |
117 | 123 | ], |
| 124 | + selectedParent: null, |
| 125 | + availableParents: [ |
| 126 | + { value: null, text: ''} |
| 127 | + ], |
118 | 128 | tag: '', // The contents of a tag as its being typed into the vue-tag-input |
119 | 129 | tags: [], // An array of tags bound to the vue-tag-input |
120 | 130 | addOnKeys: [9, 13, 32, ':', ';', ','], // Separators used when typing tags into the vue-tag-input |
|
128 | 138 | this.readOnlyProjectName = this.project.name; |
129 | 139 | this.readOnlyProjectVersion = this.project.version; |
130 | 140 | }, |
| 141 | + mounted() { |
| 142 | + this.retrieveParents(); |
| 143 | + }, |
131 | 144 | methods: { |
132 | 145 | initializeTags: function() { |
133 | 146 | this.tags = (this.project.tags || []).map(tag => ({ text: tag.name })); |
|
151 | 164 | version: this.project.version, |
152 | 165 | description: this.project.description, |
153 | 166 | classifier: this.project.classifier, |
| 167 | + parent: {uuid: this.selectedParent}, |
154 | 168 | cpe: this.project.cpe, |
155 | 169 | purl: this.project.purl, |
156 | 170 | swidTagId: this.project.swidTagId, |
|
174 | 188 | }).catch((error) => { |
175 | 189 | this.$toastr.w(this.$t('condition.unsuccessful_action')); |
176 | 190 | }); |
| 191 | + }, |
| 192 | + retrieveParents: function() { |
| 193 | + let url = `${this.$api.BASE_URL}/${this.$api.URL_PROJECT}/withoutDescendantsOf/${this.$props.uuid}`; |
| 194 | + this.axios.get(url).then((response) => { |
| 195 | + for (let i = 0; i < response.data.length; i++) { |
| 196 | + let project = response.data[i]; |
| 197 | + if (project.uuid !== this.project.uuid){ |
| 198 | + if (project.version){ |
| 199 | + this.availableParents.push({value: project.uuid, text: project.name + ' : ' + project.version}); |
| 200 | + } else { |
| 201 | + this.availableParents.push({value: project.uuid, text: project.name}); |
| 202 | + } |
| 203 | + } |
| 204 | + if (this.project.parent && this.project.parent.uuid === project.uuid ) { |
| 205 | + this.selectedParent = project.uuid; |
| 206 | + } |
| 207 | + } |
| 208 | + }).catch((error) => { |
| 209 | + this.$toastr.w(this.$t('condition.unsuccessful_action')); |
| 210 | + }); |
| 211 | + }, |
| 212 | + hasActiveChild: function (project) { |
| 213 | + let bool = false; |
| 214 | + if (project.children){ |
| 215 | + for (const child of project.children){ |
| 216 | + if (child.active || bool){ |
| 217 | + return true; |
| 218 | + } else { |
| 219 | + bool = this.hasActiveChild(child); |
| 220 | + } |
| 221 | + } |
| 222 | + } |
| 223 | + return bool; |
177 | 224 | } |
178 | 225 | } |
179 | 226 | } |
|
0 commit comments