Skip to content

Commit b25e8ac

Browse files
Implemented SNMP alerts in Vue3 (#413)
* Implemented SNMP alerts in Vue3 - Implemented SNMP alerts page in Vue3. - JIRA: https://jsw.ibm.com/browse/PFEBMC-2405 Signed-off-by: Nikhil Ashoka <[email protected]> * Resolved code conflicts with 1060-vue3 - Resolved code conflicts at routes.js * Implemented ModalAddDestination - Implemented ModalAddDestination section in SNMP alerts page. * Implemented Delete SNMP address - Implemented Delete functionality in SNMP alerts page. * Enabled Modal Add and styling fixes - Enabled Modal to add the IP address and the Port. - Replaced Bootstrap v4 breaking changes with Bootstrap v5 change. --------- Signed-off-by: Nikhil Ashoka <[email protected]>
1 parent d6fc6d4 commit b25e8ac

File tree

6 files changed

+319
-285
lines changed

6 files changed

+319
-285
lines changed

src/components/Composables/useTableSelectableComposable.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ const useTableSelectableComposable = () => {
103103
}
104104
};
105105

106+
const toggleSelectRowByIpAddress = (tableRef, rowIndex, rowSelected, row) => {
107+
if (tableRef && rowIndex !== undefined) {
108+
if (!rowSelected) {
109+
// Find the index of the object to remove
110+
const indexToRemove = selectedRowsList.value.findIndex(
111+
(item) => item.ip === row.ip,
112+
);
113+
114+
// Check if the object exists in the array
115+
if (indexToRemove !== -1) {
116+
tableRef.unselectRow(rowIndex);
117+
// Remove the object from the array
118+
selectedRowsList.value.splice(indexToRemove, 1);
119+
}
120+
} else {
121+
tableRef.selectRow(rowIndex);
122+
}
123+
}
124+
};
125+
106126
const onRowSelected = (selectedRows, totalRowsCount) => {
107127
if (selectedRows && totalRowsCount !== undefined) {
108128
if (selectedRowsList.value.indexOf(selectedRows) === -1) {
@@ -138,6 +158,7 @@ const useTableSelectableComposable = () => {
138158
toggleSelectRowById,
139159
toggleSelectRowByGroupName,
140160
toggleSelectRowByUsername,
161+
toggleSelectRowByIpAddress,
141162
onRowSelected,
142163
onChangeHeaderCheckbox,
143164
selectedRowsList,

src/router/routes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import Network from '@/views/Settings/Network';
4545
import Dumps from '@/views/Logs/Dumps';
4646
import DateTime from '@/views/Settings/DateTime/DateTime.vue';
4747
import ChangePassword from '@/views/ChangePassword';
48+
import SnmpAlerts from '@/views/Settings/SnmpAlerts';
4849

4950
const roles = {
5051
administrator: 'Administrator',
@@ -294,6 +295,14 @@ export const routes = [
294295
title: i18n.global.t('appPageTitle.powerRestorePolicy'),
295296
},
296297
},
298+
{
299+
path: '/settings/snmp-alerts',
300+
name: 'snmp-alerts',
301+
component: SnmpAlerts,
302+
meta: {
303+
title: i18n.global.t('appPageTitle.snmpAlerts'),
304+
},
305+
},
297306
{
298307
path: '/settings/date-time',
299308
name: 'date-time',

src/store/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import DumpsStore from './modules/Logs/DumpsStore.js';
3737
import FieldCoreOverrideStore from './modules/ResourceManagement/FieldCoreOverrideStore.js';
3838
import PostCodeLogsStore from './modules/Logs/PostCodeLogsStore.js';
3939
import DateTimeStore from './modules/Settings/DateTimeStore';
40+
import SnmpAlertsStore from './modules/Settings/SnmpAlertsStore.js';
4041
// ... (export use other stores)
4142
export {
4243
EventLogStore,
@@ -77,4 +78,5 @@ export {
7778
DumpsStore,
7879
FieldCoreOverrideStore,
7980
DateTimeStore,
81+
SnmpAlertsStore,
8082
};
Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import api, { getResponseCount } from '@/store/api';
22
import i18n from '@/i18n';
3-
const SnmpAlertsStore = {
4-
namespaced: true,
5-
state: {
3+
import { defineStore } from 'pinia';
4+
5+
export const SnmpAlertsStore = defineStore('snmpAlerts', {
6+
state: () => ({
67
allSnmpDetails: [],
7-
},
8+
}),
89
getters: {
9-
allSnmpDetails(state) {
10-
return state.allSnmpDetails;
11-
},
12-
},
13-
mutations: {
14-
setSnmpDetails(state, allSnmpDetails) {
15-
state.allSnmpDetails = allSnmpDetails;
16-
},
10+
allSnmpDetailsGetter: (state) => state.allSnmpDetails,
1711
},
1812
actions: {
1913
async getSnmpAlertUrl() {
@@ -24,8 +18,8 @@ const SnmpAlertsStore = {
2418
.then((response) => response.data['@odata.id'])
2519
.catch((error) => console.log('Error', error));
2620
},
27-
async getSnmpDetails({ commit, dispatch }) {
28-
const snmpAlertUrl = await dispatch('getSnmpAlertUrl');
21+
async getSnmpDetails() {
22+
const snmpAlertUrl = await this.getSnmpAlertUrl();
2923
return await api
3024
.get(snmpAlertUrl)
3125
.then((response) =>
@@ -37,27 +31,31 @@ const SnmpAlertsStore = {
3731
const snmpDetailsDataFiltered = snmpDetailsData.filter(
3832
(item) => item.SubscriptionType === 'SNMPTrap',
3933
);
40-
commit('setSnmpDetails', snmpDetailsDataFiltered);
34+
const finalSNmpData = snmpDetailsDataFiltered.map((singleData) => {
35+
singleData.isSelected = false;
36+
return singleData;
37+
})
38+
this.allSnmpDetails = finalSNmpData;
4139
})
4240
.catch((error) => {
4341
console.log(error);
44-
const message = i18n.t('pageSnmpAlerts.toast.errorLoadSnmpDetails');
42+
const message = i18n.global.t('pageSnmpAlerts.toast.errorLoadSnmpDetails');
4543
throw new Error(message);
4644
});
4745
},
48-
async deleteDestination({ dispatch }, id) {
49-
const snmpAlertUrl = await dispatch('getSnmpAlertUrl');
46+
async deleteDestination(id) {
47+
const snmpAlertUrl = await this.getSnmpAlertUrl();
5048
return await api
5149
.delete(`${snmpAlertUrl}/${id}`)
52-
.then(() => dispatch('getSnmpDetails'))
50+
.then(() => this.getSnmpDetails())
5351
.then(() =>
54-
i18n.t('pageSnmpAlerts.toast.successDeleteDestination', {
52+
i18n.global.t('pageSnmpAlerts.toast.successDeleteDestination', {
5553
id,
5654
}),
5755
)
5856
.catch((error) => {
5957
console.log(error);
60-
const message = i18n.t(
58+
const message = i18n.global.t(
6159
'pageSnmpAlerts.toast.errorDeleteDestination',
6260
{
6361
id,
@@ -66,8 +64,8 @@ const SnmpAlertsStore = {
6664
throw new Error(message);
6765
});
6866
},
69-
async deleteMultipleDestinations({ dispatch }, destination) {
70-
const snmpAlertUrl = await dispatch('getSnmpAlertUrl');
67+
async deleteMultipleDestinations(destination) {
68+
const snmpAlertUrl = await this.getSnmpAlertUrl();
7169
const promises = destination.map(({ id }) => {
7270
return api.delete(`${snmpAlertUrl}/${id}`).catch((error) => {
7371
console.log(error);
@@ -77,22 +75,22 @@ const SnmpAlertsStore = {
7775
return await api
7876
.all(promises)
7977
.then((response) => {
80-
dispatch('getSnmpDetails');
78+
this.getSnmpDetails();
8179
return response;
8280
})
8381
.then(
8482
api.spread((...responses) => {
8583
const { successCount, errorCount } = getResponseCount(responses);
8684
let toastMessages = [];
8785
if (successCount) {
88-
const message = i18n.tc(
86+
const message = i18n.global.t(
8987
'pageSnmpAlerts.toast.successBatchDelete',
9088
successCount,
9189
);
9290
toastMessages.push({ type: 'success', message });
9391
}
9492
if (errorCount) {
95-
const message = i18n.tc(
93+
const message = i18n.global.t(
9694
'pageSnmpAlerts.toast.errorBatchDelete',
9795
errorCount,
9896
);
@@ -102,18 +100,18 @@ const SnmpAlertsStore = {
102100
}),
103101
);
104102
},
105-
async addDestination({ dispatch }, { data }) {
106-
const snmpAlertUrl = await dispatch('getSnmpAlertUrl');
103+
async addDestination({ data }) {
104+
const snmpAlertUrl = await this.getSnmpAlertUrl();
107105
return await api
108106
.post(snmpAlertUrl, data)
109-
.then(() => dispatch('getSnmpDetails'))
110-
.then(() => i18n.t('pageSnmpAlerts.toast.successAddDestination'))
107+
.then(() => this.getSnmpDetails())
108+
.then(() => i18n.global.t('pageSnmpAlerts.toast.successAddDestination'))
111109
.catch((error) => {
112110
console.log(error);
113-
const message = i18n.t('pageSnmpAlerts.toast.errorAddDestination');
111+
const message = i18n.global.t('pageSnmpAlerts.toast.errorAddDestination');
114112
throw new Error(message);
115113
});
116114
},
117115
},
118-
};
116+
});
119117
export default SnmpAlertsStore;

0 commit comments

Comments
 (0)