Départ
@@ -65,7 +38,7 @@ export default {
.locations {
position: relative;
margin-bottom: 1em;
- svg {
+ img {
position: absolute;
left: 0;
bottom: .5em;
diff --git a/helpers/date-helpers.js b/helpers/date-helpers.js
index 86e82a6..5338330 100644
--- a/helpers/date-helpers.js
+++ b/helpers/date-helpers.js
@@ -1,12 +1,8 @@
-import { DateTime } from 'luxon';
-
export const sortByDate = (array) => array.sort((a, b) => {
- const startA = DateTime.fromISO(a.start);
- const startB = DateTime.fromISO(b.start);
- if (startA < startB) {
+ if (a.date < b.date) {
return -1;
}
- if (startA > startB) {
+ if (a.date > b.date) {
return 1;
}
return 0;
diff --git a/helpers/mutate-step.js b/helpers/mutate-step.js
new file mode 100644
index 0000000..d7eed94
--- /dev/null
+++ b/helpers/mutate-step.js
@@ -0,0 +1,27 @@
+import {
+ IN_PROGRESS, STARTED, VALIDATED, WAITING,
+} from '@fabnumdef/e-chauffeur_lib-vue/api/status/states';
+import {
+ DELIVER, PROGRESS, START, WAIT,
+} from '@fabnumdef/e-chauffeur_lib-vue/api/status/transitions';
+
+export default (s) => {
+ let status;
+ switch (s) {
+ case VALIDATED:
+ status = START;
+ break;
+ case WAITING:
+ status = PROGRESS;
+ break;
+ case STARTED:
+ status = WAIT;
+ break;
+ case IN_PROGRESS:
+ status = DELIVER;
+ break;
+ default:
+ break;
+ }
+ return status;
+};
diff --git a/helpers/steps-converter.js b/helpers/steps-converter.js
deleted file mode 100644
index 67f4b2e..0000000
--- a/helpers/steps-converter.js
+++ /dev/null
@@ -1,99 +0,0 @@
-import { DateTime } from 'luxon';
-import {
- IN_PROGRESS, STARTED, VALIDATED, WAITING,
-} from '@fabnumdef/e-chauffeur_lib-vue/api/status/states';
-import {
- DELIVER, PROGRESS, START, WAIT,
-} from '@fabnumdef/e-chauffeur_lib-vue/api/status/transitions';
-import { sortByDate, isToday } from '~/helpers/date-helpers';
-
-const statesToTrack = [
- VALIDATED,
- STARTED,
- IN_PROGRESS,
- WAITING,
-];
-
-const generateDetails = ({ passengersCount, comments, luggage }, type) => {
- const details = [];
- if (passengersCount) {
- let key;
- if (type === 'arrival') {
- key = `Dépôt de passager${passengersCount > 1 ? 's' : ''}`;
- } else {
- key = `Prise en charge de passager${passengersCount > 1 ? 's' : ''}`;
- }
- details.push({
- key,
- value: passengersCount,
- });
- }
- if (comments) {
- details.push({
- key: 'Commentaire',
- value: comments,
- });
- }
- if (luggage) {
- details.push({
- key: 'Présence de bagages',
- value: 'Oui',
- });
- }
- return details;
-};
-
-export const generateStep = (ride) => {
- const steps = [];
- if (
- isToday(DateTime.fromISO(ride.start).toJSDate())
- && statesToTrack.filter((state) => state === ride.status).length > 0
- ) {
- if ((ride.status === VALIDATED || ride.status === STARTED)) {
- steps.push({
- destination: ride.departure.label,
- date: ride.start,
- id: ride.id,
- type: 'departure',
- details: generateDetails(ride, 'departure'),
- phone: ride.phone,
- });
- }
- steps.push({
- destination: ride.arrival.label,
- date: ride.end,
- id: ride.id,
- type: 'arrival',
- details: generateDetails(ride, 'arrival'),
- phone: ride.phone,
- });
- }
- return steps;
-};
-
-export const mutateStep = (rides, rideId) => {
- const [ride] = rides.filter((r) => r.id === rideId);
- let status;
- switch (ride.status) {
- case VALIDATED:
- status = START;
- break;
- case WAITING:
- status = PROGRESS;
- break;
- case STARTED:
- status = WAIT;
- break;
- case IN_PROGRESS:
- status = DELIVER;
- break;
- default:
- break;
- }
- return { ride, status };
-};
-
-export default (rides) => sortByDate(rides.reduce((acc, ride) => [
- ...acc,
- ...generateStep(ride),
-], []));
diff --git a/middleware/menu.js b/middleware/menu.js
deleted file mode 100644
index e75479c..0000000
--- a/middleware/menu.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export default function ({ store: { commit } }) {
- commit('toggleMenu', false);
-}
diff --git a/middleware/status.js b/middleware/status.js
deleted file mode 100644
index b23f96b..0000000
--- a/middleware/status.js
+++ /dev/null
@@ -1,11 +0,0 @@
-export default ({ store, redirect }) => {
- const hasRides = store.getters('rides/rides').length > 0;
- const isActive = store.getter('context/isActive');
- if (hasRides && isActive) {
- return redirect('_campus/active');
- } else if (hasRides) {
- return redirect('_campus/inactive');
- } else if (!hasRides) {
- return redirect('_campus/break');
- }
-};
diff --git a/nuxt.config.js b/nuxt.config.js
index 527d10b..ef7ce7c 100644
--- a/nuxt.config.js
+++ b/nuxt.config.js
@@ -24,7 +24,7 @@ module.exports = {
},
router: {
- middleware: ['auth', 'menu'],
+ middleware: ['auth'],
},
css: [
diff --git a/pages/_campus.vue b/pages/_campus.vue
index ef6b290..3c13416 100644
--- a/pages/_campus.vue
+++ b/pages/_campus.vue
@@ -2,23 +2,20 @@
diff --git a/pages/_campus/active.vue b/pages/_campus/active.vue
index 7e0d75a..413f6c4 100644
--- a/pages/_campus/active.vue
+++ b/pages/_campus/active.vue
@@ -1,9 +1,11 @@
-
+
Etape en cours
- {{ currentStep.date }}
+ {{ stepDate }}
- Détails :
+ Action :
+ - {{ currentStep.passengersCount.key }} : {{ currentStep.passengersCount.value }}
+
+
+ Téléphone :
+ -
+ {{ phone }}
+
+
+
+
+ Détails :
+
-
@@ -35,6 +56,7 @@
diff --git a/pages/history.vue b/pages/history.vue
index b3be597..1747c4a 100644
--- a/pages/history.vue
+++ b/pages/history.vue
@@ -57,7 +57,7 @@ export default {
const { data } = await this.$api.rides(
this.campus.id,
'id,start,end,departure(label),arrival(label)',
- ).getDriverRides(this.$auth.user.id, DELIVERED);
+ ).getDriverRides(this.$auth.user.id, null, DELIVERED);
this.rides = data.filter((ride) => (
isToday(DateTime.fromISO(ride.start).toJSDate())
&& DateTime.fromISO(ride.end).toJSDate() < new Date()
diff --git a/pages/index.vue b/pages/index.vue
index 9533553..a195d77 100644
--- a/pages/index.vue
+++ b/pages/index.vue
@@ -34,7 +34,7 @@ export default {
computed: {
...mapGetters({
campuses: 'context/accessibleCampuses',
- driverStatus: 'status/current',
+ driverStatus: 'status/workStatus',
}),
},
mounted() {
diff --git a/plugins/socket.js b/plugins/socket.js
index 16fd2ee..d7ec750 100644
--- a/plugins/socket.js
+++ b/plugins/socket.js
@@ -10,6 +10,9 @@ export default function ({ app, store }) {
ioInstance.on('reconnecting', () => {
store.dispatch('reconnecting', true);
});
+ ioInstance.on('deleteStep', (rideId) => {
+ store.dispatch('socket_deleteStep', rideId);
+ });
const autoConnect = (isLogged) => {
if (isLogged) {
diff --git a/static/icon-break.svg b/static/icon-break.svg
new file mode 100644
index 0000000..54d9991
--- /dev/null
+++ b/static/icon-break.svg
@@ -0,0 +1,21 @@
+
diff --git a/static/icon-inactive.svg b/static/icon-inactive.svg
new file mode 100644
index 0000000..241d457
--- /dev/null
+++ b/static/icon-inactive.svg
@@ -0,0 +1,17 @@
+
diff --git a/static/locations-icon.svg b/static/locations-icon.svg
new file mode 100644
index 0000000..9c9195d
--- /dev/null
+++ b/static/locations-icon.svg
@@ -0,0 +1,31 @@
+
diff --git a/static/step-list-icon.svg b/static/step-list-icon.svg
new file mode 100644
index 0000000..bbb19b6
--- /dev/null
+++ b/static/step-list-icon.svg
@@ -0,0 +1,25 @@
+
diff --git a/store/index.js b/store/index.js
index cbb0ec5..8e11dca 100644
--- a/store/index.js
+++ b/store/index.js
@@ -22,11 +22,11 @@ export const getters = {
export const actions = {
// eslint-disable-next-line no-shadow
- socket_rideUpdate({ commit, state }, payload) {
- commit('rides/pushRide', { ride: payload, loggedUser: state.auth.user });
- if (Object.keys(state.rides.selectedRide).length === 0) {
- commit('rides/selectRide', 0);
- }
+ socket_rideUpdate({ dispatch }, payload) {
+ dispatch('rides/pushStep', payload);
+ },
+ socket_deleteStep({ dispatch }, rideId) {
+ dispatch('rides/deleteStep', rideId);
},
reconnecting({ commit }, reconnecting = true) {
commit('reconnecting', reconnecting);
diff --git a/store/rides.js b/store/rides.js
index d3e15a5..58609eb 100644
--- a/store/rides.js
+++ b/store/rides.js
@@ -3,10 +3,15 @@
import {
VALIDATED, STARTED, IN_PROGRESS, WAITING, DELIVERED,
} from '@fabnumdef/e-chauffeur_lib-vue/api/status/states';
-import { DateTime } from 'luxon';
-import generateSteps, { generateStep, mutateStep } from '../helpers/steps-converter';
+import getAction from '../helpers/mutate-step';
import { sortByDate } from '../helpers/date-helpers';
+export const state = () => ({
+ steps: [],
+ previous: 'Position actuelle',
+ alert: false,
+});
+
const statesToTrack = [
VALIDATED,
STARTED,
@@ -14,93 +19,82 @@ const statesToTrack = [
WAITING,
];
-export const state = () => ({
- rides: [],
- steps: [],
- previous: 'Position actuelle',
-});
-
export const mutations = {
- setRides: (s, rides = null) => {
- s.rides = rides
+ setSteps: (s, steps = []) => {
+ s.steps = steps
.filter(({ id }) => !!id);
},
- setSteps: (s, rides = []) => {
- s.steps = generateSteps(rides);
+ toggleAlert: (s) => {
+ s.alert = !s.alert;
},
- pushRide: (s, { ride, loggedUser }) => {
- if (!ride.id) {
- throw new Error('Id is required');
- }
- const i = s.rides.findIndex(({ id }) => id === ride.id);
- const isToTrack = statesToTrack.includes(ride.status) && loggedUser.id === ride.driver.id;
- if (i === -1) {
- if (isToTrack) {
- const steps = generateStep(ride);
- s.rides.push(ride);
- s.steps.push(...steps);
- sortByDate(s.rides);
- sortByDate(s.steps);
- }
- } else {
- Object.assign(s.rides[i], ride);
- if (ride.status === WAITING || ride.status === IN_PROGRESS) {
- s.steps = s.steps.filter((step) => {
- const toKeep = step.id !== ride.id || step.type !== 'departure';
- if (!toKeep) {
- s.previous = step.destination;
- }
- return toKeep;
- });
- } else if (ride.status === DELIVERED) {
- s.steps = s.steps.filter((step) => {
- const toKeep = step.id !== ride.id;
- if (!toKeep && step.type === 'arrival') {
- s.previous = step.destination;
- }
- return toKeep;
- });
- } else if (ride.status !== STARTED) {
- s.steps = s.steps.filter((step) => step.id !== ride.id);
- }
- }
+ setPrevious: (s, previous) => {
+ s.previous = previous;
},
};
export const getters = {
- rides: ({ rides }) => rides,
+ rawSteps: (s) => s.steps,
steps: (s) => s.steps.map((step) => ({
...step,
- date: DateTime.fromISO(step.date).toFormat("HH 'h' mm"),
previous: s.previous,
})),
+ alert: (s) => s.alert,
};
export const actions = {
- async fetchRides({ dispatch }, campus) {
+ async fetchRides({ commit }, campus) {
try {
const { data } = await this.$api.rides(
campus,
- 'id,start,end,phone,departure(label),arrival(label),'
- + 'passengersCount,car(id,label,model(label)),status,comments,luggage',
- ).getDriverRides(this.$auth.user.id, ...statesToTrack);
- dispatch('setState', data);
+ 'id,destination,phone,details(*),type,date,status,rideId,passengersCount',
+ ).getDriverRides(this.$auth.user.id, 'steps', ...statesToTrack);
+ commit('setSteps', data);
} catch (e) {
throw new Error('Rides fetching failed');
}
},
- setState({ commit }, rides) {
- commit('setRides', rides);
- commit('setSteps', rides);
- },
- async updateSteps({ commit, getters: g }, { rideId, driverId, campusId }) {
- commit('status/toggleDriving', null, { root: true });
-
+ async updateSteps({ commit, getters: g }, { step, campusId }) {
try {
- const { ride, status } = mutateStep(g.rides, rideId);
- return this.$api.rides(campusId, driverId, 'id').mutateRide(ride, status);
+ await this.$api.rides(campusId, 'id').mutateRide(step, getAction(step.status), 'step');
+ commit('status/setRideStatus', null, { root: true });
+ if (g.alert) {
+ commit('toggleAlert');
+ }
} catch (e) {
throw new Error('Ride mutation failed');
}
},
+ deleteStep: ({ commit, getters: g }, rideId) => {
+ const updatedSteps = JSON.parse(JSON.stringify(g.rawSteps))
+ .filter((step) => {
+ const updatedRideId = step.rideId.filter((id) => rideId !== id);
+ return updatedRideId.length > 0 ? { ...step, rideId: updatedRideId } : false;
+ });
+ commit('setSteps', updatedSteps);
+ },
+ pushStep: ({ commit, getters: g }, payload) => {
+ payload.forEach((step) => {
+ const steps = JSON.parse(JSON.stringify(g.rawSteps));
+ const { status, id } = step;
+ if (!id) {
+ throw new Error('Id is required');
+ }
+ const index = steps.findIndex((st) => st.id === id);
+ if (index === -1) {
+ if (status === VALIDATED || status === WAITING) {
+ steps.push(step);
+ if (steps.length > 0 && step.date < steps[0].date) {
+ commit('toggleAlert');
+ }
+ }
+ } else if (status === DELIVERED || status === WAITING) {
+ steps.splice(index, 1);
+ commit('setPrevious', step.destination);
+ } else {
+ steps[index].status = status;
+ }
+ sortByDate(steps);
+ commit('setSteps', steps);
+ });
+ },
};
diff --git a/store/status.js b/store/status.js
index 8cf714c..72f382b 100644
--- a/store/status.js
+++ b/store/status.js
@@ -1,26 +1,28 @@
// We've to disable param reassign, because it's the common behavior of vuex
/* eslint-disable no-param-reassign */
+export const statuses = {
+ ACTIVE: 'active',
+ INACTIVE: 'inactive',
+ BREAK: 'break',
+};
+
export const state = () => ({
- current: 'inactive',
- statusList: {
- ACTIVE: 'active',
- INACTIVE: 'inactive',
- BREAK: 'break',
- },
- driving: false,
+ workStatus: statuses.INACTIVE,
+ statusList: statuses,
+ rideStatus: false,
});
export const mutations = {
- setStatus: (s, status = s.statusList.INACTIVE) => {
- s.current = status;
+ setWorkStatus: (s, status) => {
+ s.workStatus = status;
},
- toggleDriving: (s) => {
- s.driving = !s.driving;
+ setRideStatus: (s) => {
+ s.rideStatus = !s.rideStatus;
},
};
export const getters = {
- current: (s) => s.current,
+ workStatus: (s) => s.workStatus,
list: (s) => s.statusList,
- driving: (s) => s.driving,
+ rideStatus: (s) => s.rideStatus,
};