diff --git a/frontend/src/components/Dashboard/DashboardDowntimes.vue b/frontend/src/components/Dashboard/DashboardDowntimes.vue
index 61edb26f..ddc982d0 100644
--- a/frontend/src/components/Dashboard/DashboardDowntimes.vue
+++ b/frontend/src/components/Dashboard/DashboardDowntimes.vue
@@ -4,6 +4,8 @@
:handle-clear-filters="handleClearFilters"
:params="params"
:handle-filter-search="handleFilterSearch"
+ :filter-errors="filterErrors"
+ :handle-filter-change="handleFilterChange"
/>
@@ -66,8 +68,8 @@ export const initialParams = {
};
const convertToSec = (val) => {
- return +new Date(val)/1000
-}
+ return +new Date(val)/1000;
+};
export default {
name: 'DashboardDowntimes',
@@ -79,7 +81,8 @@ export default {
data: function () {
return {
isLoading: false,
- params: { ...initialParams }
+ params: { ...initialParams },
+ filterErrors: {}
};
},
computed: {
@@ -90,17 +93,18 @@ export default {
},
methods: {
getDowntimes: async function (params = this.params) {
- const {start, end} = params;
+ const { start, end } = params;
- let startSec = "", endSec = "";
+ this.checkFilterErrors();
- if(start) {
- startSec = convertToSec(start);
- }
- if(end) {
- endSec = convertToSec(end);
+ if (Object.keys(this.filterErrors).length > 0) {
+ return;
}
+ const startSec = convertToSec(start);
+ const endSec = convertToSec(end) + (60 * 60 * 23 + 59 * 60 + 59); // adding end of time for that particular date.
+
+
this.isLoading = true;
await this.$store.dispatch({ type: 'getDowntimes', payload: { ...params, start: startSec, end: endSec } });
this.isLoading = false;
@@ -120,6 +124,30 @@ export default {
this.params = { ...this.params, skip: 0 };
this.getDowntimes();
+ },
+ checkFilterErrors: function () {
+ const { start, end } = this.params;
+ const errors = {};
+
+ // Converting into millisec
+ const startSec = convertToSec(start);
+ const endSec = convertToSec(end) + (60 * 60 * 23 + 59 * 60 + 59);
+
+ if (!start && end) {
+ errors.start = 'Need to enter Start Date';
+ } else if (start && !end) {
+ errors.end = 'Need to enter End Date';
+ } else if ( startSec > endSec ) {
+ errors.end = 'End Date should be greater than Start Date';
+ }
+
+ this.filterErrors = Object.assign({}, errors);
+ },
+ handleFilterChange: function (e) {
+ // reset all the errors
+ const { name } = e.target;
+
+ delete this.filterErrors[name];
}
}
};
diff --git a/frontend/src/forms/Downtime.vue b/frontend/src/forms/Downtime.vue
index 7ddbd36b..e24ea427 100644
--- a/frontend/src/forms/Downtime.vue
+++ b/frontend/src/forms/Downtime.vue
@@ -201,17 +201,17 @@ export default {
}),
},
mounted: function () {
- if(this.editDowntime) {
- const { service_id, sub_status, failures, start, end } = this.editDowntime;
+ if (this.editDowntime) {
+ const { service_id, sub_status, failures, start, end } = this.editDowntime;
- this.downtime = {
- start,
- end,
- failures,
- serviceId: service_id,
- subStatus: sub_status
- };
- }
+ this.downtime = {
+ start,
+ end,
+ failures,
+ serviceId: service_id,
+ subStatus: sub_status
+ };
+ }
},
methods: {
isCreateDowntimeBtnEnabled: function () {
diff --git a/frontend/src/forms/DowntimeFilters.vue b/frontend/src/forms/DowntimeFilters.vue
index 19a2fd53..d2aae0a1 100644
--- a/frontend/src/forms/DowntimeFilters.vue
+++ b/frontend/src/forms/DowntimeFilters.vue
@@ -6,7 +6,7 @@