-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified and improved uris for categories and model details
Improved vue component names Extracted model filter to separate component and integrate with router /uri changes & deep linking/
- Loading branch information
1 parent
4f35a4c
commit f864831
Showing
10 changed files
with
240 additions
and
218 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
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,123 @@ | ||
<template> | ||
<multiselect | ||
v-model="selected" | ||
:options="available_aircraft_types" | ||
group-values="models" | ||
group-label="manufacturer" | ||
:group-select="false" | ||
label="model" | ||
:placeholder="'Search ' + (aircraft_type || 'aircraft')" | ||
:max-height="500" | ||
> | ||
<template #noResult> | ||
<span v-if="aircraft_type"> | ||
{{ aircraft_type.charAt(0).toUpperCase() + aircraft_type.slice(1) }} not found. Try different phrase or | ||
category. | ||
</span> | ||
<span v-else>Aircraft model not found. Try different phrase.</span> | ||
</template> | ||
</multiselect> | ||
</template> | ||
|
||
<script> | ||
import axios from 'axios' | ||
import Multiselect from 'vue-multiselect' | ||
export default { | ||
name: 'AircraftModelFilter', | ||
components: { | ||
Multiselect | ||
}, | ||
data() { | ||
return { | ||
aircraft_type: null, | ||
all_aircraft_types: [], | ||
available_aircraft_types: [], | ||
selected: null | ||
} | ||
}, | ||
watch: { | ||
$route() { | ||
const pathSegments = this.$route.path.split('/') | ||
switch (pathSegments[1]) { | ||
case 'glider': | ||
case 'tmg': | ||
case 'ultralight': | ||
case 'airplane': | ||
this.aircraft_type = pathSegments[1] | ||
this.selected = null | ||
this.updateAircraftTypes() | ||
if (pathSegments.length == 4) { | ||
this.selected = { | ||
manufacturer: decodeURI(pathSegments[2]), | ||
model: decodeURI(pathSegments[3]) | ||
} | ||
} else { | ||
this.selected = null | ||
} | ||
break | ||
default: | ||
this.aircraft_type = null | ||
this.selected = null | ||
} | ||
}, | ||
selected(val) { | ||
if (val == null) { | ||
return | ||
} | ||
this.$router.push({ | ||
name: 'offer_details', | ||
params: { aircraftType: val.aircraft_type, manufacturer: val.manufacturer, model: val.model } | ||
}) | ||
} | ||
}, | ||
created() { | ||
this.loadAircraftTypes() | ||
}, | ||
methods: { | ||
loadAircraftTypes() { | ||
axios.get(`/models`).then((response) => { | ||
this.all_aircraft_types = response.data | ||
this.updateAircraftTypes() | ||
}) | ||
}, | ||
updateAircraftTypes() { | ||
const new_available_aircraft_types = [] | ||
for (const manufacturer in this.all_aircraft_types) { | ||
const modelsToDisplay = [] | ||
const modelsByAircraftType = this.all_aircraft_types[manufacturer].models | ||
for (const type in modelsByAircraftType) { | ||
if (this.aircraft_type == type || this.aircraft_type == null) { | ||
for (const model in modelsByAircraftType[type]) { | ||
modelsToDisplay.push({ | ||
aircraft_type: type, | ||
manufacturer: manufacturer, | ||
model: modelsByAircraftType[type][model] | ||
}) | ||
} | ||
} | ||
} | ||
new_available_aircraft_types.push({ | ||
manufacturer: manufacturer, | ||
models: modelsToDisplay | ||
}) | ||
} | ||
this.available_aircraft_types = new_available_aircraft_types | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
@import 'vue-multiselect/dist/vue-multiselect.css'; | ||
</style> |
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.