mirror of https://github.com/statping/statping
fixed the date range filter error
parent
a118ecbef1
commit
d0f427f436
|
@ -4,6 +4,8 @@
|
||||||
:handle-clear-filters="handleClearFilters"
|
:handle-clear-filters="handleClearFilters"
|
||||||
:params="params"
|
:params="params"
|
||||||
:handle-filter-search="handleFilterSearch"
|
:handle-filter-search="handleFilterSearch"
|
||||||
|
:filter-errors="filterErrors"
|
||||||
|
:handle-filter-change="handleFilterChange"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="card contain-card mb-4">
|
<div class="card contain-card mb-4">
|
||||||
|
@ -66,8 +68,8 @@ export const initialParams = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const convertToSec = (val) => {
|
const convertToSec = (val) => {
|
||||||
return +new Date(val)/1000
|
return +new Date(val)/1000;
|
||||||
}
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'DashboardDowntimes',
|
name: 'DashboardDowntimes',
|
||||||
|
@ -79,7 +81,8 @@ export default {
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
params: { ...initialParams }
|
params: { ...initialParams },
|
||||||
|
filterErrors: {}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
@ -92,15 +95,16 @@ export default {
|
||||||
getDowntimes: async function (params = this.params) {
|
getDowntimes: async function (params = this.params) {
|
||||||
const { start, end } = params;
|
const { start, end } = params;
|
||||||
|
|
||||||
let startSec = "", endSec = "";
|
this.checkFilterErrors();
|
||||||
|
|
||||||
if(start) {
|
if (Object.keys(this.filterErrors).length > 0) {
|
||||||
startSec = convertToSec(start);
|
return;
|
||||||
}
|
|
||||||
if(end) {
|
|
||||||
endSec = convertToSec(end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
this.isLoading = true;
|
||||||
await this.$store.dispatch({ type: 'getDowntimes', payload: { ...params, start: startSec, end: endSec } });
|
await this.$store.dispatch({ type: 'getDowntimes', payload: { ...params, start: startSec, end: endSec } });
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
@ -120,6 +124,30 @@ export default {
|
||||||
this.params = { ...this.params, skip: 0 };
|
this.params = { ...this.params, skip: 0 };
|
||||||
|
|
||||||
this.getDowntimes();
|
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form>
|
<form>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<div class="form-group col-md-3">
|
<div class="form-group col-md-2">
|
||||||
<label class="col-form-label">
|
<label class="col-form-label">
|
||||||
{{ $t('service') }}
|
{{ $t('service') }}
|
||||||
</label>
|
</label>
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group col-md-4">
|
<div class="form-group col-md-5">
|
||||||
<label class="col-form-label">
|
<label class="col-form-label">
|
||||||
{{ $t('downtime_date_range') }}
|
{{ $t('downtime_date_range') }}
|
||||||
</label>
|
</label>
|
||||||
|
@ -42,7 +42,14 @@
|
||||||
value=""
|
value=""
|
||||||
:config="config"
|
:config="config"
|
||||||
placeholder="Select Start Date"
|
placeholder="Select Start Date"
|
||||||
|
@on-change="handleFilterChange({target: {name: 'start'}})"
|
||||||
/>
|
/>
|
||||||
|
<small
|
||||||
|
v-if="filterErrors.start"
|
||||||
|
class="form-text text-danger"
|
||||||
|
>
|
||||||
|
{{ filterErrors.start }}
|
||||||
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<FlatPickr
|
<FlatPickr
|
||||||
|
@ -52,9 +59,16 @@
|
||||||
name="end"
|
name="end"
|
||||||
class="form-control form-control-plaintext"
|
class="form-control form-control-plaintext"
|
||||||
value=""
|
value=""
|
||||||
:config="config"
|
:config="{...config, ...endConfig}"
|
||||||
placeholder="Select End Date"
|
placeholder="Select End Date"
|
||||||
|
@on-change="handleFilterChange({target: {name: 'end'}})"
|
||||||
/>
|
/>
|
||||||
|
<small
|
||||||
|
v-if="filterErrors.end"
|
||||||
|
class="form-text text-danger"
|
||||||
|
>
|
||||||
|
{{ filterErrors.end }}
|
||||||
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -79,9 +93,12 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group col-md-3 d-flex align-items-end">
|
<div class="form-group col-md-3">
|
||||||
|
<label class="col-form-label invisible">
|
||||||
|
{{ $t('actions') }}
|
||||||
|
</label>
|
||||||
<div
|
<div
|
||||||
class="ml-auto"
|
class="d-flex justify-content-end"
|
||||||
role="group"
|
role="group"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
|
@ -129,6 +146,14 @@ export default {
|
||||||
handleFilterSearch: {
|
handleFilterSearch: {
|
||||||
type: Function,
|
type: Function,
|
||||||
default: function () {}
|
default: function () {}
|
||||||
|
},
|
||||||
|
filterErrors: {
|
||||||
|
type: Object,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
handleFilterChange: {
|
||||||
|
type: Function,
|
||||||
|
default: function () {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data: function () {
|
data: function () {
|
||||||
|
@ -137,12 +162,14 @@ export default {
|
||||||
altFormat: 'D, J M Y',
|
altFormat: 'D, J M Y',
|
||||||
altInput: true,
|
altInput: true,
|
||||||
dateFormat: 'Z',
|
dateFormat: 'Z',
|
||||||
maxDate: new Date()
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState([ 'services' ])
|
...mapState([ 'services' ]),
|
||||||
|
endConfig: function (){
|
||||||
|
return { ...(this.params.start && { minDate: this.params.start }) };
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue