Skip to content

Commit

Permalink
Merge pull request #143 from Geoportail-Luxembourg/GSLUX-709-msg
Browse files Browse the repository at this point in the history
GSLUX-709: Notification messages on draw
  • Loading branch information
AlitaBernachot authored Aug 29, 2024
2 parents 700c9ff + 69ad4a4 commit 7b91cab
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 48 deletions.
24 changes: 12 additions & 12 deletions cypress/e2e/draw/draw-bar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Map controls', () => {

describe('When drawing the point on the map', () => {
beforeEach(() => {
cy.get('div.ol-viewport').click(100, 100)
cy.get('div.ol-viewport').click(100, 100, { force: true })
})

it('displays the draw Panel', () => {
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('Map controls', () => {

describe('When drawing the label on the map', () => {
beforeEach(() => {
cy.get('div.ol-viewport').click(100, 100)
cy.get('div.ol-viewport').click(100, 100, { force: true })
})

it('displays the draw Panel', () => {
Expand Down Expand Up @@ -86,16 +86,16 @@ describe('Map controls', () => {
})

it('displays a tooltip when clicking on the map and hides it on draw end (second point double click)', () => {
cy.get('div.ol-viewport').click(100, 100)
cy.get('div.ol-viewport').click(100, 100, { force: true })
cy.get('div.lux-tooltip').should('exist')
cy.get('div.ol-viewport').dblclick(200, 200)
cy.get('div.ol-viewport').dblclick(200, 200, { force: true })
cy.get('div.lux-tooltip').should('not.exist')
})

describe('When drawing the line on the map', () => {
beforeEach(() => {
cy.get('div.ol-viewport').click(100, 100)
cy.get('div.ol-viewport').dblclick(200, 200)
cy.get('div.ol-viewport').click(100, 100, { force: true })
cy.get('div.ol-viewport').dblclick(200, 200, { force: true })
})

it('displays the draw Panel', () => {
Expand All @@ -120,18 +120,18 @@ describe('Map controls', () => {
})

it('displays a tooltip when clicking on the map and hides it on draw end (third point double click)', () => {
cy.get('div.ol-viewport').click(100, 100)
cy.get('div.ol-viewport').click(100, 100, { force: true })
cy.get('div.lux-tooltip').should('exist')
cy.get('div.ol-viewport').click(100, 200)
cy.get('div.ol-viewport').dblclick(200, 200)
cy.get('div.ol-viewport').click(100, 200, { force: true })
cy.get('div.ol-viewport').dblclick(200, 200, { force: true })
cy.get('div.lux-tooltip').should('not.exist')
})

describe('When drawing the polygon on the map', () => {
beforeEach(() => {
cy.get('div.ol-viewport').click(100, 100)
cy.get('div.ol-viewport').click(100, 200)
cy.get('div.ol-viewport').dblclick(200, 200)
cy.get('div.ol-viewport').click(100, 100, { force: true })
cy.get('div.ol-viewport').click(100, 200, { force: true })
cy.get('div.ol-viewport').dblclick(200, 200, { force: true })
})

it('displays the draw Panel', () => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/draw/draw-feat-line.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ describe('Draw "Line"', () => {
cy.visit('/')
cy.get('button[data-cy="drawButton"]').click()
cy.get('button[data-cy="drawLineButton"]').click()
cy.get('div.ol-viewport').click(100, 100)
cy.get('div.ol-viewport').dblclick(200, 200)
cy.get('div.ol-viewport').click(100, 100, { force: true })
cy.get('div.ol-viewport').dblclick(200, 200, { force: true })
})

describe('When clicking button to draw Line', () => {
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/draw/draw-feat-polygon.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ describe('Draw "Polygon"', () => {
cy.visit('/')
cy.get('button[data-cy="drawButton"]').click()
cy.get('button[data-cy="drawPolygonButton"]').click()
cy.get('div.ol-viewport').click(100, 100)
cy.get('div.ol-viewport').click(100, 200)
cy.get('div.ol-viewport').dblclick(200, 200)
cy.get('div.ol-viewport').click(100, 100, { force: true })
cy.get('div.ol-viewport').click(100, 200, { force: true })
cy.get('div.ol-viewport').dblclick(200, 200, { force: true })
})

describe('When clicking button to draw Polygon', () => {
Expand Down
66 changes: 66 additions & 0 deletions cypress/e2e/draw/draw-notifications.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
describe('Draw notifications', () => {
beforeEach(() => {
cy.visit('/')
cy.get('button[data-cy="drawButton"]').click()
})

describe('When clicking button to draw point', () => {
it('show a helper message', () => {
cy.get('[data-cy="notification"]').should('not.exist')
cy.get('button[data-cy="drawPointButton"]').click()
cy.get('[data-cy="notification"]').should('have.length', 1)
cy.get('[data-cy="notification"]').should(
'have.text',
'Cliquez pour placer le point'
)
})
})

describe('When clicking button to draw label', () => {
it('show a helper message', () => {
cy.get('[data-cy="notification"]').should('not.exist')
cy.get('button[data-cy="drawLabelButton"]').click()
cy.get('[data-cy="notification"]').should('have.length', 1)
cy.get('[data-cy="notification"]').should(
'have.text',
"Cliquez pour placer l'étiquette"
)
})
})

describe('When clicking button to draw line', () => {
it('show a helper message', () => {
cy.get('[data-cy="notification"]').should('not.exist')
cy.get('button[data-cy="drawLineButton"]').click()
cy.get('[data-cy="notification"]').should('have.length', 1)
cy.get('[data-cy="notification"]').should(
'have.text',
'Cliquez pour commencer à dessiner la ligneFaites un double-clic ou ESC pour terminer. Tapez ⌫ pour enlever le dernier point dessinéActivez la coche "suivre les routes" pour faire coller votre ligne au réseau routier existant'
)
})
})

describe('When clicking button to draw polygon', () => {
it('show a helper message', () => {
cy.get('[data-cy="notification"]').should('not.exist')
cy.get('button[data-cy="drawPolygonButton"]').click()
cy.get('[data-cy="notification"]').should('have.length', 1)
cy.get('[data-cy="notification"]').should(
'have.text',
'Cliquez pour commencer à dessiner le polygoneFaites un double-clic, typez ESC ou cliquez sur le dernier point pour terminerTapez ⌫ pour enlever le dernier point dessiné'
)
})
})

describe('When clicking button to draw circle', () => {
it('show a helper message', () => {
cy.get('[data-cy="notification"]').should('not.exist')
cy.get('button[data-cy="drawCircleButton"]').click()
cy.get('[data-cy="notification"]').should('have.length', 1)
cy.get('[data-cy="notification"]').should(
'have.text',
'Cliquez pour commencer à dessiner un cercle'
)
})
})
})
37 changes: 33 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"pinia": "^2.0.26",
"sortablejs": "^1.15.2",
"tailwindcss": "^3.4.4",
"uuid": "^10.0.0",
"vue": "^3.2.45",
"vue-dompurify-html": "^3.1.2"
},
Expand All @@ -68,6 +69,7 @@
"@types/node": "^18.11.9",
"@types/proj4": "^2.5.2",
"@types/sortablejs": "^1.15.2",
"@types/uuid": "^10.0.0",
"@vitejs/plugin-vue": "^3.2.0",
"@vitest/coverage-c8": "^0.26.2",
"@vue/eslint-config-prettier": "^7.0.0",
Expand Down
9 changes: 5 additions & 4 deletions src/components/alert-notifications/alert-notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
import { storeToRefs } from 'pinia'
import { useAlertNotificationsStore } from '@/stores/alert-notifications.store'
import { AlertNotification } from '@/stores/alert-notifications.store.model'
import Notification from './notification-item.vue'
const alertNotificationsStore = useAlertNotificationsStore()
const { notifications } = storeToRefs(alertNotificationsStore)
function onClose(index: number) {
alertNotificationsStore.removeNotification(index)
function onClose(uuid: string) {
alertNotificationsStore.removeNotification(uuid)
}
</script>

Expand All @@ -22,8 +23,8 @@ function onClose(index: number) {
<Notification
v-for="(notification, index) in notifications"
:key="index"
:notification="notification"
@close="() => onClose(index)"
:notification="<AlertNotification>notification"
@close="() => onClose(notification.uuid)"
/>
</div>
</Teleport>
Expand Down
5 changes: 3 additions & 2 deletions src/components/alert-notifications/notification-item.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
import { ShallowRef, shallowRef } from 'vue'
import { AlertNotificationModel } from '@/stores/alert-notifications.store.model'
import { AlertNotification } from '@/stores/alert-notifications.store.model'
defineEmits<{
(e: 'close'): void
}>()
const props = defineProps<{
notification: AlertNotificationModel
notification: AlertNotification
}>()
const show: ShallowRef<boolean> = shallowRef(true)
Expand All @@ -31,6 +31,7 @@ function onEnter(el: Element, done: () => void) {
@after-leave="$emit('close')"
>
<div
data-cy="notification"
v-if="show"
v-dompurify-html="props.notification.message"
class="lux-alert"
Expand Down
47 changes: 47 additions & 0 deletions src/composables/draw/draw-notifications.composable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { watch } from 'vue'
import { storeToRefs } from 'pinia'
import { useTranslation } from 'i18next-vue'

import { useAlertNotificationsStore } from '@/stores/alert-notifications.store'
import { useDrawStore } from '@/stores/draw.store'
import { DrawStateActive } from '@/stores/draw.store.model'

export default function useDrawNotifications() {
const { t } = useTranslation()
const { addNotification } = useAlertNotificationsStore()
const { drawStateActive } = storeToRefs(useDrawStore())

watch(drawStateActive, notify)

function notify(drawStateActive: DrawStateActive) {
let notification: string | undefined

switch (drawStateActive) {
case 'drawPoint':
notification = t('Click to draw the point')
break
case 'drawLine':
notification = t(
'Click to start drawing line<br>Double-click to finish'
)
break
case 'drawPolygon':
notification = t(
'Click to start drawing polygon<br>Double-click or click last point to finish'
)
break
case 'drawCircle':
notification = t('Click to start drawing circle')
break
case 'drawLabel':
notification = t('Click to place the label')
break
}

if (notification) {
addNotification(notification)
}
}

return {}
}
8 changes: 5 additions & 3 deletions src/composables/draw/draw.composable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Draw from 'ol/interaction/Draw'

import { useDrawStore } from '@/stores/draw.store'
import useDrawInteraction from './draw-interaction.composable'
import useDrawNotifications from './draw-notifications.composable'

type DrawInteractions = {
drawPoint: Draw
Expand All @@ -23,15 +24,16 @@ export default function useDraw() {
drawPolygon: useDrawInteraction({ type: 'Polygon' }).drawInteraction,
} as DrawInteractions

watch(drawStateActive, () => {
useDrawNotifications()

watch(drawStateActive, drawStateActive => {
Object.keys(drawInteractions).forEach(key => {
if (`${[key as keyof DrawInteractions]}` === `${drawStateActive.value}`) {
if (`${[key as keyof DrawInteractions]}` === `${drawStateActive}`) {
drawInteractions[key as keyof DrawInteractions].setActive(true)
} else {
drawInteractions[key as keyof DrawInteractions].setActive(false)
}
})
// todo: set messages from DrawController.onChangeActive_ here and implement modal to display them
})

return {}
Expand Down
Loading

0 comments on commit 7b91cab

Please sign in to comment.