Skip to content

Commit

Permalink
Fixes (#8)
Browse files Browse the repository at this point in the history
* fix: replace car.png

* fix: base url

* capacity input component

* feature: send capacity

* feature: update host - set domain

* fix: minor fixes

* fix: decode route in store
  • Loading branch information
nogorka authored May 14, 2024
1 parent ea90f38 commit 589c342
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_APP_HOST="176.123.168.71"
VITE_APP_HOST="nogorka42.ru"
VITE_APP_PORT=3000

File renamed without changes
26 changes: 26 additions & 0 deletions src/components/capacity-input.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script setup>
import { ref } from 'vue'
import { useStore } from 'vuex'
const store = useStore()
const form = ref({ capacity: store.state.capacity })
const onChange = (event) => {
store.dispatch('updateCapacity', Number(event.target.value))
}
</script>

<template>
<div class="flex flex-col gap-2 ">
<label class="flex items-center gap-4">
<span class="block font-medium text-gray-700">Capacity input</span>
<input
v-model.number="form.capacity"
@change="onChange"
class="flex-1 px-4 py-2 border rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</label>
</div>
</template>
7 changes: 5 additions & 2 deletions src/http/helper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const get_base_url = () =>
`https://${import.meta.env.VITE_APP_HOST}:${import.meta.env.VITE_APP_PORT}/`
const get_base_url = () => {
if (import.meta.env.VITE_APP_HOST === 'localhost')
return `http://${import.meta.env.VITE_APP_HOST}:${import.meta.env.VITE_APP_PORT}/`
return `https://${import.meta.env.VITE_APP_HOST}:${import.meta.env.VITE_APP_PORT}/`
}


const post = async (endpoint, body) => {
Expand Down
13 changes: 11 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const store = createStore({
long: 0
},
inputPoints: [],
capacity: 1000,
optimalRoute: {
route: [],
id: null
Expand All @@ -28,6 +29,9 @@ const store = createStore({
setInputPoints(state, points) {
state.inputPoints = [...points]
},
setInputCapacity(state, value) {
state.capacity = value
},
setOptimalRoute(state, route) {
state.optimalRoute.route = [...route]
},
Expand Down Expand Up @@ -65,22 +69,27 @@ const store = createStore({
updateInputPoints({ commit }, points) {
commit('setInputPoints', points)
},
updateCapacity({ commit }, value) {
commit('setInputCapacity', value)
},


async getOptimalRoute({ dispatch }, { id }) {
const response = await api.getOptimalRoute(id)
dispatch('updateRouteData', response)
},
async optimizeRoute({ state, dispatch }) {
if (state.inputPoints.length > 0) {
const response = await api.optimizeRoute(state.inputPoints)
if (state.inputPoints.length > 0 && state.capacity) {
const body = { points: state.inputPoints, capacity: state.capacity }
const response = await api.optimizeRoute(body)
dispatch('updateRouteData', response)
return response.data?._id || null
}
},
updateRouteData({ commit, dispatch }, payload) {
if (payload.success) {
const { _id, route, date } = payload.data

const decodedRoute = JSON.parse(route)
// const decodedRoute = route.map(r =>
// r.map(point => JSON.parse(point))
Expand Down
2 changes: 1 addition & 1 deletion src/utils/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const config = {
defaultLatLong: [59.9342802, 30.3350986],
key: import.meta.env.VITE_GRAPH_HOPPER_KEY,
car: {
iconUrl: 'car.png',
iconUrl: '/img/car.png',
iconSize: [30, 30],
iconAnchor: [30, 30]
}
Expand Down
40 changes: 24 additions & 16 deletions src/views/FileImport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import GoBack from '@/components/go-back.vue'
import { processCsv, processJson } from '@/utils/process-file-formats.js'
import OptimizeRouteButton from '@/components/optimize-route-button.vue'
import CapacityInput from '@/components/capacity-input.vue'
const onChange = (e) => {
const file = e.target.files[0]
Expand Down Expand Up @@ -31,22 +32,29 @@ const onChange = (e) => {
<template>
<div class="container mx-auto p-4">
<go-back />
<div class="max-w-lg mx-auto">
<h1 class="text-center text-2xl font-bold my-4">File Import</h1>
<input
class="block w-full text-center p-2 mx-auto my-4 border-2 border-gray-300 rounded-lg cursor-pointer hover:border-blue-500 focus:border-blue-500"
type="file"
accept=".json, .csv"
@change="onChange"
/>
<span>Example:</span>
<a href="/example.json" download="ex" class="text-blue-600 visited:text-purple-600">
example.json
</a>
<span>, </span>
<a href="/example.csv" download="ex" class="text-blue-600 visited:text-purple-600">
example.csv
</a>
<div class="max-w-lg mx-auto gap-6">
<div>
<h1 class="text-center text-2xl font-bold my-4">File Import</h1>
<input
class="block w-full text-center p-2 mx-auto my-4 border-2 border-gray-300 rounded-lg cursor-pointer hover:border-blue-500 focus:border-blue-500"
type="file"
accept=".json, .csv"
@change="onChange"
/>
<span class="font-medium text-gray-700">Example:</span>
<a href="/example.json" download="ex" class="text-blue-600 visited:text-purple-600">
example.json
</a>
<span>, </span>
<a href="/example.csv" download="ex" class="text-blue-600 visited:text-purple-600">
example.csv
</a>
</div>

<div>
<h1 class="text-center text-2xl font-bold my-4">Input vehicles capacity</h1>
<capacity-input />
</div>

<optimize-route-button />
</div>
Expand Down

0 comments on commit 589c342

Please sign in to comment.