-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add technologies to advisories (#205)
- Loading branch information
Showing
24 changed files
with
319 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 30 additions & 35 deletions
65
frontend/src/components/elements/forms/AdvisoryLabelSelectField.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,39 @@ | ||
<script> | ||
export default { | ||
name: "AdvisoryLabelSelectField", | ||
props: ["modelValue"], | ||
emits: ["update:modelValue"], | ||
mounted() { | ||
this.loadData() | ||
}, | ||
methods: { | ||
change() { | ||
this.$emit('update:modelValue', this.items) | ||
name: 'AdvisoryLabelSelectField', | ||
props: ['modelValue'], | ||
emits: ['update:modelValue'], | ||
mounted() { | ||
this.loadData(); | ||
}, | ||
loadData() { | ||
let url = "/advisory-management/labels/" | ||
this.$api.get(url).then((response) => { | ||
this.choices = response.data.results | ||
this.items = [] | ||
this.modelValue.forEach((item) => { | ||
// prefill with already selected items | ||
this.items.push(item.pk) | ||
}) | ||
}) | ||
} | ||
}, | ||
data() { | ||
return { | ||
items: this.modelValue, | ||
choices: [] | ||
methods: { | ||
change() { | ||
this.$emit('update:modelValue', this.items); | ||
}, | ||
loadData() { | ||
let url = '/advisory-management/labels/'; | ||
this.$api.get(url).then((response) => { | ||
this.choices = response.data.results; | ||
this.items = []; | ||
this.modelValue.forEach((item) => { | ||
// prefill with already selected items | ||
this.items.push(item.pk); | ||
}); | ||
}); | ||
} | ||
}, | ||
data() { | ||
return { | ||
items: this.modelValue, | ||
choices: [] | ||
}; | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<label for="labels">Labels</label> | ||
<MultiSelect @change="change" id="labels" v-model="items" | ||
:options="choices" optionLabel="name" | ||
optionValue="pk"> | ||
</MultiSelect> | ||
<label for="labels">Labels</label> | ||
<MultiSelect @change="change" id="labels" v-model="items" :options="choices" optionLabel="name" optionValue="pk"> </MultiSelect> | ||
</template> | ||
|
||
<style scoped> | ||
</style> | ||
<style scoped></style> |
75 changes: 75 additions & 0 deletions
75
frontend/src/components/elements/forms/TechnologySelectField.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<script> | ||
import TechnologyService from '@/service/TechnologyService'; | ||
export default { | ||
name: 'TechnologySelectField', | ||
props: ['modelValue'], | ||
emits: ['update:modelValue', 'change'], | ||
data() { | ||
let model = this.modelValue; | ||
if (this.modelValue && this.modelValue.pk) { | ||
model = this.modelValue.pk; | ||
} | ||
return { | ||
model: model, | ||
choices: [], | ||
loading: false, | ||
loaded: false, | ||
service: new TechnologyService() | ||
}; | ||
}, | ||
methods: { | ||
change() { | ||
this.$emit('update:modelValue', this.model); | ||
for (let i = 0; i < this.choices.length; i++) { | ||
if (this.choices[i].pk === this.model) { | ||
this.$emit('change', this.choices[i]); | ||
break; | ||
} | ||
} | ||
}, | ||
onFocus() { | ||
if (this.loaded === false) { | ||
this.loadData(); | ||
} | ||
}, | ||
loadData() { | ||
this.loading = true; | ||
this.service | ||
.getTechnologies(this.$api) | ||
.then((response) => { | ||
this.choices = response.data.results; | ||
this.loaded = true; | ||
}) | ||
.finally(() => { | ||
this.loading = false; | ||
}); | ||
}, | ||
onFilter(event) { | ||
let params = { | ||
search: event.value | ||
}; | ||
this.service.getTechnologies(this.$api, params).then((response) => { | ||
this.choices = response.data.results; | ||
}); | ||
} | ||
}, | ||
watch: { | ||
modelValue: { | ||
immediate: true, | ||
deep: true, | ||
handler(value) { | ||
if (this.choices.length === 0) { | ||
if (value && value.pk) { | ||
this.choices = [value]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<Dropdown v-model="model" :options="choices" @focus="onFocus" optionLabel="name" optionValue="pk" @change="change" :loading="loading" :filter="true" @filter="onFilter"></Dropdown> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.