Skip to content

Commit

Permalink
feat: простой вывод csv
Browse files Browse the repository at this point in the history
  • Loading branch information
popstas committed Mar 2, 2020
1 parent ea6302f commit 9932603
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions components/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
@click="setPreset({name: 'none', columns: ['domain_idn']});"
v-html="'убрать все колонки'"
></button>
<button
class="column-presets__button"
@click="getCSV"
v-html="'получить CSV'"
title="Вывод будет в console.log"
></button>

<!-- one group -->
<FieldGroup
Expand Down Expand Up @@ -120,6 +126,10 @@ export default {
return this.$store.state.allFields;
},
filteredSites() {
return this.$store.state.filteredSites;
},
// раскладывает поля по группам, с дублированием
fieldGroups() {
let groups = { unnamed: { name: "", fields: [] } };
Expand Down Expand Up @@ -221,6 +231,26 @@ export default {
setTimeout(() => {
this.completionProcess = false;
}, 500);
},
getCSV() {
// console.log('this.fields: ', this.fields);
// console.log('this.filteredSites: ', this.filteredSites);
const header = this.fields.map(f => f.title);
const data = this.filteredSites.map(s => {
return this.fields.map(f => {
return s[f.name];
});
});
const csv = [...[header], ...data];
// console.log('csv: ', csv);
// console.log('data: ', data);
const raw = csv.map(row => {
return row.join(',');
}).join('\n');
console.log(raw);
}
}
};
Expand Down

0 comments on commit 9932603

Please sign in to comment.