From 9ff9bcbfd47eb00dbe5190d4d47e041d63c1f454 Mon Sep 17 00:00:00 2001 From: Alberto Paganelli Date: Wed, 31 Jan 2024 18:16:50 +0100 Subject: [PATCH] feat: popup added for modifications, insertions, deletions and for alarms, devices and notifications --- .../src/components/devices/DeviceBadge.vue | 11 ++++-- .../components/devices/UpdateDevicePopup.vue | 1 - .../security-rule/SecurityRuleBadge.vue | 27 ++++--------- .../security-rule/UpdateSecurityRulePopup.vue | 1 - frontend/src/scripts/Popups.ts | 5 +-- .../presentation/device/ComposeDevice.ts | 12 +++--- .../notification/ComposeNotification.ts | 38 +++++++++++-------- .../security-rule/ComposeSecurityRule.ts | 14 +++---- frontend/src/views/HomeView.vue | 2 +- frontend/src/views/NotificationView.vue | 10 ++--- frontend/src/views/SecurityRuleView.vue | 4 +- 11 files changed, 60 insertions(+), 65 deletions(-) diff --git a/frontend/src/components/devices/DeviceBadge.vue b/frontend/src/components/devices/DeviceBadge.vue index f8b114264..ade32d5d9 100644 --- a/frontend/src/components/devices/DeviceBadge.vue +++ b/frontend/src/components/devices/DeviceBadge.vue @@ -6,6 +6,8 @@ import { ref } from 'vue' import UpdateDevicePopup from '@/components/devices/UpdateDevicePopup.vue' import RequestHelper, { monitoringHost, monitoringPort } from '@/utils/RequestHelper' import { MeasureConverter } from 'domain/dist/utils' +import { popNegative, popPositive } from '@/scripts/Popups' +import { useQuasar } from 'quasar' defineProps<{ device: Device @@ -16,6 +18,7 @@ defineEmits<{ }>() const updatePopupVisible = ref(false) +const $q = useQuasar() const updateSensor = async (sensor: Sensor) => { await RequestHelper.put(`http://${monitoringHost}:${monitoringPort}/devices/sensors`, { @@ -27,10 +30,10 @@ const updateSensor = async (sensor: Sensor) => { }) }) .then(async (res: any) => { - alert('devo aggiornare i devices') - //TODO A CONFIRM POPUP + popPositive($q, 'Sensor updated successfully') }) .catch(error => { + popNegative($q, 'Error while updating sensor') console.log(error) }) } @@ -45,10 +48,10 @@ const updateCamera = async (camera: Camera) => { } }) .then(async (res: any) => { - alert('devo aggiornare i devices') - //TODO A CONFIRM POPUP + popPositive($q, 'Camera updated successfully') }) .catch(error => { + popNegative($q, 'Error while updating camera') console.log(error) }) } diff --git a/frontend/src/components/devices/UpdateDevicePopup.vue b/frontend/src/components/devices/UpdateDevicePopup.vue index 1fcf3b679..92919a264 100644 --- a/frontend/src/components/devices/UpdateDevicePopup.vue +++ b/frontend/src/components/devices/UpdateDevicePopup.vue @@ -36,7 +36,6 @@ const options = ref([ ]) const updateDevice = () => { - console.log(device) if (device.deviceId.type == DeviceType.SENSOR) { const updatedSensor: Sensor = deviceFactory.createSensor( deviceIdFactory.createSensorId(device.deviceId.code), diff --git a/frontend/src/components/security-rule/SecurityRuleBadge.vue b/frontend/src/components/security-rule/SecurityRuleBadge.vue index b6e9682aa..27fd56997 100644 --- a/frontend/src/components/security-rule/SecurityRuleBadge.vue +++ b/frontend/src/components/security-rule/SecurityRuleBadge.vue @@ -11,6 +11,8 @@ import UpdateSecurityRulePopup from './UpdateSecurityRulePopup.vue' import { ref } from 'vue' import { DeviceTypeConverter, MeasureConverter, ObjectClassConverter } from 'domain/dist/utils' import RequestHelper, { alarmHost, alarmPort } from '@/utils/RequestHelper' +import { popPositive, popNegative } from '@/scripts/Popups' +import { useQuasar } from 'quasar' defineProps<{ securityRule: SecurityRule @@ -21,24 +23,9 @@ defineEmits<{ }>() const updatePopupVisible = ref(false) +const $q = useQuasar() const updateExceedingRule = async (exceedingRule: ExceedingRule) => { - console.log(DeviceTypeConverter.convertToString(exceedingRule.deviceId.type)) - console.log(exceedingRule.deviceId.type) - console.log({ - id: exceedingRule.securityRuleId, - deviceId: { - type: DeviceTypeConverter.convertToString(exceedingRule.deviceId.type), - code: exceedingRule.deviceId.code - }, - description: exceedingRule.description, - minValue: exceedingRule.min, - maxValue: exceedingRule.max, - measure: MeasureConverter.convertToString(exceedingRule.measure), - from: exceedingRule.from.toISOString(), - to: exceedingRule.to.toISOString(), - contacts: exceedingRule.contactsToNotify - }) await RequestHelper.put(`http://${alarmHost}:${alarmPort}/security-rules/exceedings`, { id: exceedingRule.securityRuleId, deviceId: { @@ -54,10 +41,10 @@ const updateExceedingRule = async (exceedingRule: ExceedingRule) => { contacts: exceedingRule.contactsToNotify }) .then(async (res: any) => { - alert('devo aggiornare le exceeding rules') - //TODO A CONFIRM POPUP + popPositive($q, 'Exceeding rule updated successfully') }) .catch(error => { + popNegative($q, 'Error while updating exceeding rule') console.log(error) }) } @@ -76,10 +63,10 @@ const updateIntrusionRule = async (intrusionRule: IntrusionRule) => { contacts: intrusionRule.contactsToNotify }) .then(async (res: any) => { - alert('devo aggiornare le intrusion rules') - //TODO A CONFIRM POPUP + popPositive($q, 'Intrusion rule updated successfully') }) .catch(error => { + popNegative($q, 'Error while updating intrusion rule') console.log(error) }) } diff --git a/frontend/src/components/security-rule/UpdateSecurityRulePopup.vue b/frontend/src/components/security-rule/UpdateSecurityRulePopup.vue index bd9ceb984..33d2056c8 100644 --- a/frontend/src/components/security-rule/UpdateSecurityRulePopup.vue +++ b/frontend/src/components/security-rule/UpdateSecurityRulePopup.vue @@ -74,7 +74,6 @@ const measure: ref = ref(Measure.TEMPERATURE) const objectClass: ref = ref(ObjectClass.PERSON) const updateSecurityRule = () => { - console.log(securityRule) if (securityRule.deviceId.type == DeviceType.SENSOR) { const updatedExceedingRule: ExceedingRule = securityRuleFactory.createExceedingRule( (securityRule as ExceedingRule).min, diff --git a/frontend/src/scripts/Popups.ts b/frontend/src/scripts/Popups.ts index 6204659a4..1d751f135 100644 --- a/frontend/src/scripts/Popups.ts +++ b/frontend/src/scripts/Popups.ts @@ -1,5 +1,4 @@ - -import { type QVueGlobals } from "quasar"; +import { type QVueGlobals } from 'quasar' export const popPositive = (q: QVueGlobals, message: string): void => { q.notify({ type: 'positive', @@ -7,7 +6,7 @@ export const popPositive = (q: QVueGlobals, message: string): void => { }) } -export const popNegative = (q: QVueGlobals, message: string): void => { +export const popNegative = (q: QVueGlobals, message: string): void => { q.notify({ type: 'negative', message: message diff --git a/frontend/src/scripts/presentation/device/ComposeDevice.ts b/frontend/src/scripts/presentation/device/ComposeDevice.ts index 827130838..041dba9b2 100644 --- a/frontend/src/scripts/presentation/device/ComposeDevice.ts +++ b/frontend/src/scripts/presentation/device/ComposeDevice.ts @@ -1,11 +1,13 @@ -import { type Camera, Measure, type Sensor } from "domain/dist/domain/device/core"; -import { MeasureConverter } from "domain/dist/utils"; +import { type Camera, Measure, type Sensor } from 'domain/dist/domain/device/core' +import { MeasureConverter } from 'domain/dist/utils' import { type DeviceFactory, DeviceFactoryImpl, type DeviceIdFactory, - DeviceIdFactoryImpl, type ResolutionFactory, ResolutionFactoryImpl -} from "domain/dist/domain/device/factories"; + DeviceIdFactoryImpl, + type ResolutionFactory, + ResolutionFactoryImpl +} from 'domain/dist/domain/device/factories' const deviceIdFactory: DeviceIdFactory = new DeviceIdFactoryImpl() const deviceFactory: DeviceFactory = new DeviceFactoryImpl() @@ -32,4 +34,4 @@ export function composeMeasure(measures: any): Measure[] { return measures.map((measure: any) => { return MeasureConverter.convertToMeasure(measure) }) -} \ No newline at end of file +} diff --git a/frontend/src/scripts/presentation/notification/ComposeNotification.ts b/frontend/src/scripts/presentation/notification/ComposeNotification.ts index 638fe5d11..c43acb23c 100644 --- a/frontend/src/scripts/presentation/notification/ComposeNotification.ts +++ b/frontend/src/scripts/presentation/notification/ComposeNotification.ts @@ -1,26 +1,34 @@ -import RequestHelper, { alarmHost, alarmPort } from "@/utils/RequestHelper"; -import { DeviceTypeConverter, MeasureConverter, ObjectClassConverter } from "domain/dist/utils"; -import { DeviceType } from "domain/dist/domain/device/core"; -import type { Exceeding, Intrusion } from "domain/dist/domain/anomaly/core"; -import type { NotificationFactory } from "domain/dist/domain/alarm-system/factories"; -import { NotificationFactoryImpl } from "domain/dist/domain/alarm-system/factories"; -import type { AnomalyFactory } from "domain/dist/domain/anomaly/factories"; -import { AnomalyFactoryImpl } from "domain/dist/domain/anomaly/factories"; -import type { DeviceIdFactory } from "domain/dist/domain/device/factories"; -import { DeviceIdFactoryImpl } from "domain/dist/domain/device/factories"; -import type { Notification } from "domain/dist/domain/alarm-system/core"; +import RequestHelper, { alarmHost, alarmPort } from '@/utils/RequestHelper' +import { DeviceTypeConverter, MeasureConverter, ObjectClassConverter } from 'domain/dist/utils' +import { DeviceType } from 'domain/dist/domain/device/core' +import type { Exceeding, Intrusion } from 'domain/dist/domain/anomaly/core' +import type { NotificationFactory } from 'domain/dist/domain/alarm-system/factories' +import { NotificationFactoryImpl } from 'domain/dist/domain/alarm-system/factories' +import type { AnomalyFactory } from 'domain/dist/domain/anomaly/factories' +import { AnomalyFactoryImpl } from 'domain/dist/domain/anomaly/factories' +import type { DeviceIdFactory } from 'domain/dist/domain/device/factories' +import { DeviceIdFactoryImpl } from 'domain/dist/domain/device/factories' +import type { Notification } from 'domain/dist/domain/alarm-system/core' const notificationFactory: NotificationFactory = new NotificationFactoryImpl() const anomalyFactory: AnomalyFactory = new AnomalyFactoryImpl() const deviceIdFactory: DeviceIdFactory = new DeviceIdFactoryImpl() export const composeNotification = async (notification: any): Promise => { - const resAnomaly = await RequestHelper.get(`http://${alarmHost}:${alarmPort}/anomalies/` + notification.anomalyId) + const resAnomaly = await RequestHelper.get( + `http://${alarmHost}:${alarmPort}/anomalies/` + notification.anomalyId + ) switch (DeviceTypeConverter.convertToDeviceType(resAnomaly.data.deviceId.type)) { case DeviceType.CAMERA: - return notificationFactory.createIntrusionNotification(notification._id, composeIntrusion(resAnomaly.data)) + return notificationFactory.createIntrusionNotification( + notification._id, + composeIntrusion(resAnomaly.data) + ) case DeviceType.SENSOR: - return notificationFactory.createExceedingNotification(notification._id, composeExceeding(resAnomaly.data)) + return notificationFactory.createExceedingNotification( + notification._id, + composeExceeding(resAnomaly.data) + ) } } @@ -41,4 +49,4 @@ function composeExceeding(exceeding: any): Exceeding { MeasureConverter.convertToMeasure(exceeding.measure), exceeding.value ) -} \ No newline at end of file +} diff --git a/frontend/src/scripts/presentation/security-rule/ComposeSecurityRule.ts b/frontend/src/scripts/presentation/security-rule/ComposeSecurityRule.ts index eee4204cb..d50746864 100644 --- a/frontend/src/scripts/presentation/security-rule/ComposeSecurityRule.ts +++ b/frontend/src/scripts/presentation/security-rule/ComposeSecurityRule.ts @@ -1,9 +1,9 @@ -import type { ExceedingRule, IntrusionRule } from "domain/dist/domain/security-rule/core"; -import { ContactTypeConverter, MeasureConverter, ObjectClassConverter } from "domain/dist/utils"; -import type { Contact } from "domain/dist/domain/monitoring/core"; -import { type SecurityRuleFactory, SecurityRuleFactoryImpl } from "domain/dist/domain/security-rule/factories"; -import { type DeviceIdFactory, DeviceIdFactoryImpl } from "domain/dist/domain/device/factories"; -import { type ContactFactory, ContactFactoryImpl } from "domain/dist/domain/monitoring/factories"; +import type { ExceedingRule, IntrusionRule } from 'domain/dist/domain/security-rule/core' +import { ContactTypeConverter, MeasureConverter, ObjectClassConverter } from 'domain/dist/utils' +import type { Contact } from 'domain/dist/domain/monitoring/core' +import { type SecurityRuleFactory, SecurityRuleFactoryImpl } from 'domain/dist/domain/security-rule/factories' +import { type DeviceIdFactory, DeviceIdFactoryImpl } from 'domain/dist/domain/device/factories' +import { type ContactFactory, ContactFactoryImpl } from 'domain/dist/domain/monitoring/factories' const securityRuleFactory: SecurityRuleFactory = new SecurityRuleFactoryImpl() const deviceIdFactory: DeviceIdFactory = new DeviceIdFactoryImpl() @@ -44,4 +44,4 @@ function composeContacts(contacts: any): Contact[] { ContactTypeConverter.convertToContactType(contact.type) ) }) -} \ No newline at end of file +} diff --git a/frontend/src/views/HomeView.vue b/frontend/src/views/HomeView.vue index ee87e6222..0b9a28c2f 100644 --- a/frontend/src/views/HomeView.vue +++ b/frontend/src/views/HomeView.vue @@ -12,7 +12,7 @@ import { AnomalyTypeConverter, DeviceTypeConverter, MeasureConverter } from 'dom import { AnomalyType } from 'domain/dist/domain/anomaly/core' import { useTopicsStore } from '@/stores/topics' import { type AxiosResponse, HttpStatusCode } from 'axios' -import { composeSensor } from "@/scripts/presentation/device/ComposeDevice"; +import { composeSensor } from '@/scripts/presentation/device/ComposeDevice' const topicsStore = useTopicsStore() diff --git a/frontend/src/views/NotificationView.vue b/frontend/src/views/NotificationView.vue index a942de401..8b672c40f 100644 --- a/frontend/src/views/NotificationView.vue +++ b/frontend/src/views/NotificationView.vue @@ -5,16 +5,14 @@ import RequestHelper, { alarmHost, alarmPort } from '@/utils/RequestHelper' import NotificationBadge from '@/components/notification/NotificationBadge.vue' import { composeNotification } from '@/scripts/presentation/notification/ComposeNotification' -let notifications: ref = ref([]) +const notifications: ref = ref([]) async function getNotifications() { await RequestHelper.get(`http://${alarmHost}:${alarmPort}/notifications`) - .then((res: any) => { - //notifications.value = [] + .then(async (res: any) => { + notifications.value = [] for (let i = 0; i < res.data.length; i++) { - console.log("AAAA") - console.log(composeNotification(res.data[i])) - notifications.value.push(composeNotification(res.data[i])) + notifications.value.push(await composeNotification(res.data[i])) } }) .catch(error => { diff --git a/frontend/src/views/SecurityRuleView.vue b/frontend/src/views/SecurityRuleView.vue index 477c5175d..7714420aa 100644 --- a/frontend/src/views/SecurityRuleView.vue +++ b/frontend/src/views/SecurityRuleView.vue @@ -10,7 +10,7 @@ import { composeIntrusionSecurityRule } from '@/scripts/presentation/security-rule/ComposeSecurityRule' import { popNegative, popPositive } from '@/scripts/Popups.js' -import { useQuasar } from "quasar"; +import { useQuasar } from 'quasar' const exceedingsSecurityRules: ref = ref([]) const intrusionsSecurityRules: ref = ref([]) @@ -107,7 +107,7 @@ const deleteExceedingRule = async (exceedingRule: ExceedingRule) => { `http://${alarmHost}:${alarmPort}/security-rules/exceedings/` + exceedingRule.securityRuleId ) .then(async (res: any) => { - popNegative($q, 'Exceeding rule deleted successfully') + popPositive($q, 'Exceeding rule deleted successfully') await getExceedingSecurityRules() }) .catch(error => {