Skip to content

Commit

Permalink
feature(core): clean code (ergonode#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
derpdead committed Jul 29, 2020
1 parent ca7438d commit ff728e9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
DEFAULT_FORMAT,
} from '@Core/models/calendar/calendar';
import {
format as formatDate,
parse as parseDate,
} from 'date-fns';
Expand Down Expand Up @@ -54,35 +53,14 @@ export default {
const valueTo = this.value[FILTER_OPERATOR.SMALLER_OR_EQUAL];
return {
from: valueFrom
? parseDate(valueFrom, this.dateFormat, new Date())
: null,
to: valueTo
? parseDate(valueTo, this.dateFormat, new Date())
: null,
from: valueFrom,
to: valueTo,
};
},
},
methods: {
onValueChange({
from, to,
}) {
const dateFrom = from ? formatDate(from, this.dateFormat) : null;
const dateTo = to ? formatDate(to, this.dateFormat) : null;
if (this.value[FILTER_OPERATOR.GREATER_OR_EQUAL] !== dateFrom
&& dateFrom) {
this.$emit('input', {
key: FILTER_OPERATOR.GREATER_OR_EQUAL,
value: dateFrom,
});
} else if (this.value[FILTER_OPERATOR.SMALLER_OR_EQUAL] !== dateTo
&& dateTo) {
this.$emit('input', {
key: FILTER_OPERATOR.SMALLER_OR_EQUAL,
value: dateTo,
});
}
onValueChange(payload) {
this.$emit('input', payload);
},
onEmptyRecordChange(value) {
this.$emit('input', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
:value="filterValue"
:hint="hint"
:title="title"
:parameters="parameters"
:filter-id="filter.id"
@remove="onRemove"
@swap="onSwap"
Expand All @@ -34,9 +33,15 @@ import SelectDropdownApplyFooter from '@Core/components/Inputs/Select/DropDown/F
import {
FILTER_OPERATOR,
} from '@Core/defaults/operators';
import {
DEFAULT_FORMAT,
} from '@Core/models/calendar/calendar';
import {
getParsedFilter,
} from '@Core/models/mappers/gridDataMapper';
import {
format as formatDate,
} from 'date-fns';
export default {
name: 'GridDateTypeAdvancedFilter',
Expand All @@ -59,8 +64,8 @@ export default {
return {
value: {
isEmptyRecord: false,
[FILTER_OPERATOR.GREATER_OR_EQUAL]: '',
[FILTER_OPERATOR.SMALLER_OR_EQUAL]: '',
[FILTER_OPERATOR.GREATER_OR_EQUAL]: null,
[FILTER_OPERATOR.SMALLER_OR_EQUAL]: null,
},
};
},
Expand Down Expand Up @@ -91,15 +96,32 @@ export default {
return [
this.value[FILTER_OPERATOR.GREATER_OR_EQUAL],
this.value[FILTER_OPERATOR.SMALLER_OR_EQUAL],
].filter(value => value !== '')
].filter(value => value)
.map(value => formatDate(value, this.parameters))
.join(' - ');
},
},
methods: {
onValueChange({
key, value,
from, to,
}) {
this.value[key] = value;
const value = {
[FILTER_OPERATOR.GREATER_OR_EQUAL]: null,
[FILTER_OPERATOR.SMALLER_OR_EQUAL]: null,
};
if (from) {
value[FILTER_OPERATOR.GREATER_OR_EQUAL] = from;
}
if (to) {
value[FILTER_OPERATOR.SMALLER_OR_EQUAL] = to;
}
this.value = {
...this.value,
...value,
};
},
onRemove(index) {
this.$emit('remove', index);
Expand All @@ -110,16 +132,30 @@ export default {
onClear() {
this.value = {
isEmptyRecord: false,
[FILTER_OPERATOR.GREATER_OR_EQUAL]: '',
[FILTER_OPERATOR.SMALLER_OR_EQUAL]: '',
[FILTER_OPERATOR.GREATER_OR_EQUAL]: null,
[FILTER_OPERATOR.SMALLER_OR_EQUAL]: null,
};
},
onApplyValue() {
const filterValue = {
...this.value,
};
if (filterValue[FILTER_OPERATOR.GREATER_OR_EQUAL]) {
const fromValue = formatDate(filterValue[FILTER_OPERATOR.GREATER_OR_EQUAL], DEFAULT_FORMAT);
filterValue[FILTER_OPERATOR.GREATER_OR_EQUAL] = fromValue;
}
if (filterValue[FILTER_OPERATOR.SMALLER_OR_EQUAL]) {
const toValue = formatDate(filterValue[FILTER_OPERATOR.SMALLER_OR_EQUAL], DEFAULT_FORMAT);
filterValue[FILTER_OPERATOR.SMALLER_OR_EQUAL] = toValue;
}
this.$emit('apply', {
key: this.filter.id,
value: getParsedFilter({
id: this.filter.id,
filter: this.value,
filter: filterValue,
}),
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ import {
import {
THEME,
} from '@Core/defaults/theme';
import calendar, {
CALENDAR_MONTHS,
import {
DEFAULT_FORMAT,
getNextMonth,
getPreviousMonth,
WEEK_DAYS,
} from '@Core/models/calendar/calendar';
import {
Expand Down Expand Up @@ -106,6 +103,7 @@ export default {
return Object.values(WEEK_DAYS);
},
fromHeader() {
console.log(this.value.from);
if (this.value.from) {
return `From ${formatDate(this.value.from, this.format)}`;
}
Expand Down

0 comments on commit ff728e9

Please sign in to comment.