Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/bulma/EnsoTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export default {
fetch() {
return this.ready && this.$refs.table.fetch();
},
fetchRow(dtRowId) {
return this.ready && this.$refs.table.fetchRow(dtRowId);
},
highlight(dtRowId) {
return this.ready && this.$refs.table.highlight(dtRowId);
},
Expand Down
3 changes: 3 additions & 0 deletions src/bulma/VueTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export default {
fetch() {
return this.ready && this.$refs.table.fetch();
},
fetchRow(dtRowId) {
return this.ready && this.$refs.table.fetchRow(dtRowId);
},
highlight(dtRowId) {
return this.ready && this.$refs.table.highlight(dtRowId);
},
Expand Down
2 changes: 1 addition & 1 deletion src/bulma/parts/TableBody.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<template v-for="column in state.template.columns">
<td :key="column.name"
:class="[
{ 'is-number' : column.money || column.number },
{ 'is-number' : column.number },
columnAlignment(column), column.class
]" v-if="visibleColumn(column)">
<table-cell v-bind="cellBindings(row, column)"
Expand Down
8 changes: 4 additions & 4 deletions src/bulma/parts/TableFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
</td>
<template v-for="i in columns.length - 1">
<td class="is-bold"
:class="[{ 'is-number' : columns[i].money || columns[i].number },
:class="[{ 'is-number' : columns[i].number },
columnAlignment(columns[i])]"
:key="i"
v-if="visibleColumn(columns[i])">
<span v-if="
columns[i].meta.total || columns[i].meta.rawTotal
|| columns[i].meta.average
">{{
columns[i].money || columns[i].number
columns[i].number
? state.body.total[columns[i].name]
: totalFormat(state.body.total[columns[i].name])
}}</span>
Expand All @@ -42,12 +42,12 @@
<ul>
<li v-for="cell in hiddenTotals"
class="is-bold"
:class="[{ 'is-money' : cell.money || cell.number },
:class="[{ 'is-number' : cell.number },
columnAlignment(cell)]"
:key="cell.name">
<span>{{ i18n(cell.label) }}:</span>
<span v-if="cell.meta.total || cell.meta.rawTotal ">{{
cell.money || cell.number
cell.number
? state.body.total[cell.name]
: totalFormat(state.body.total[cell.name])
}}</span>
Expand Down
7 changes: 1 addition & 6 deletions src/bulma/parts/top/Filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import { Dropdown, DropdownItem } from '@enso-ui/dropdown/bulma';
import Boolean from './filters/Boolean.vue';
import String from './filters/String.vue';
import Enum from './filters/Enum.vue';
import Money from './filters/Money.vue';
import Number from './filters/Number.vue';
import Date from './filters/Date.vue';
import CustomSelect from './filters/CustomSelect.vue';
Expand All @@ -69,7 +68,7 @@ export default {
name: 'Filters',

components: {
Dropdown, DropdownItem, Boolean, String, Enum, Money, Number, Date, CustomSelect,
Dropdown, DropdownItem, Boolean, String, Enum, Number, Date, CustomSelect,
},

inject: ['activeScenario', 'i18n', 'state'],
Expand Down Expand Up @@ -112,10 +111,6 @@ export default {
return 'enum';
}

if (column.money) {
return 'money';
}

if (column.number) {
return 'number';
}
Expand Down
1 change: 0 additions & 1 deletion src/bulma/parts/top/filters/FilterLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const Types = {
string: String,
enum: Enum,
select: Select,
money: Range,
number: Range,
date: Date,
};
Expand Down
3 changes: 1 addition & 2 deletions src/bulma/parts/top/filters/Labels.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { clickOutside } from '@enso-ui/directives';
import Boolean from './Boolean.vue';
import String from './String.vue';
import Enum from './Enum.vue';
import Money from './Money.vue';
import Number from './Number.vue';
import Date from './Date.vue';
import FilterLabel from './FilterLabel.vue';
Expand All @@ -39,7 +38,7 @@ export default {
directives: { clickOutside },

components: {
Boolean, String, Enum, Money, Number, Date, CustomSelect, FilterLabel,
Boolean, String, Enum, Number, Date, CustomSelect, FilterLabel,
},

inject: ['activeScenario', 'i18n', 'state'],
Expand Down
102 changes: 0 additions & 102 deletions src/bulma/parts/top/filters/Money.vue

This file was deleted.

2 changes: 1 addition & 1 deletion src/bulma/parts/top/filters/Number.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import { focus } from '@enso-ui/directives';

export default {
name: 'Money',
name: 'Number',

directives: { focus },

Expand Down
98 changes: 60 additions & 38 deletions src/renderless/CoreTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default {
doButtonAction: this.doButtonAction,
exportData: this.exportData,
fetch: this.fetch,
fetchRow: this.fetchRow,
hasContent: this.hasContent,
hasEntries: this.hasEntries,
hasFooter: this.hasFooter,
Expand Down Expand Up @@ -265,7 +266,7 @@ export default {

this.init();
},
request() {
request(dtRowId = null) {
if (this.ongoingRequest) {
this.ongoingRequest.cancel();
}
Expand All @@ -275,13 +276,13 @@ export default {
return this.template.method === 'GET'
? axios[this.template.method.toLowerCase()](
this.template.readPath, {
...this.readRequest(this.template.method),
...this.readRequest(this.template.method, false, false, dtRowId),
cancelToken: this.ongoingRequest.token,
},
)
: axios[this.template.method.toLowerCase()](
this.template.readPath,
this.readRequest(this.template.method),
this.readRequest(this.template.method, false, false, dtRowId),
{ cancelToken: this.ongoingRequest.token },
);
},
Expand All @@ -301,9 +302,7 @@ export default {
return;
}

this.state.body = this.meta.money
? this.processMoney(body)
: body;
this.state.body = body;

if (this.meta.number) {
this.processNumber();
Expand All @@ -320,14 +319,63 @@ export default {
}
});
},
readRequest(method, exportMode = false, selection = false) {
fetchRow(dtRowId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we reuse most part of fetch()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do it but the final code was a bit dirtier. because fetchRow() has something in the middle of the method and for refactoring this we should refactor methods to many tiny methods but it makes our class a little complicated(because it isn't SRP!)

const index = this.state.body.data
.findIndex((item) => item[this.template.dtRowId] === dtRowId);

if (index === -1) {
throw new Error(`${dtRowId} is not exist`);
}

const selectedRow = { ...this.state.body.data[index] };
this.meta.loading = true;
this.$emit('fetching');

return this.request(dtRowId).then(({ data }) => {
const body = data;
this.meta.loading = false;

if (body.data.length === 0) {
this.fetch();

return;
}

this.state.body.data[index] = body.data[0];

if (this.meta.number) {
this.processNumber(index);
}

const changedTotal = Object.keys(this.state.body.total)
.filter((key) => selectedRow[key] !== this.state.body.data[index][key])
.length > 0;

if (changedTotal) {
this.fetch();

return;
}

this.$emit('fetched');
this.$nextTick(this.refreshPageSelected);
}).catch(error => {
this.meta.loading = false;

if (!axios.isCancel(error)) {
this.errorHandler(error);
}
});
},
readRequest(method, exportMode = false, selection = false, dtRowId = null) {
const params = selection
? { selection: this.state.selected }
: {
withMeta: !dtRowId,
internalFilters: this.internalFilters,
filters: this.filters,
intervals: this.intervals,
params: this.params,
filters: dtRowId ? { [`${this.template.table}`]: { [`${this.template.dtRowId}`]: dtRowId } } : this.filters,
intervals: dtRowId ? {} : this.intervals,
params: dtRowId ? this.params : {},
columns: this.requestColumns(exportMode),
meta: {
start: this.meta.start,
Expand Down Expand Up @@ -362,36 +410,10 @@ export default {
return columns;
}, []);
},
processMoney(body) {
this.template.columns
.filter(column => !!column.money)
.forEach(column => {
const total = this.meta.total
&& Object.keys(body.total).includes(column.name);

let money = body.data.map(row => Number.parseFloat(row[column.name]) || 0);

if (total) {
money.push(Number.parseFloat(body.total[column.name]) || 0);
}

money = accounting.formatColumn(money, column.money);

body.data = body.data.map((row, index) => {
row[column.name] = money[index];
return row;
});

if (total) {
body.total[column.name] = money.pop();
}
});
return body;
},
processNumber() {
processNumber(index = null) {
this.template.columns
.filter(column => !!column.number)
.forEach(column => (new NumberFormatter(this, column)).handle());
.forEach(column => (new NumberFormatter(this, column, index)).handle());
},
isEmpty() {
return this.body && this.body.count === 0;
Expand Down
Loading