added sample and entry count to csv import

This commit is contained in:
Timo 2021-04-07 22:58:56 +03:00
parent b9397fc81a
commit e508ce83ca
3 changed files with 43 additions and 1 deletions

View File

@ -51,7 +51,13 @@
</div>
<div class="csv-header-pill-content">
<div class="csv-header-pill" *ngFor="let field of parseResult?.meta?.fields">
{{ field }}
<div class="name">
{{ field }}
</div>
<div class="secondary">
<div class="entry-count small-label">{{ getEntries(field) }} entries</div>
<div class="sample small-label">Sample: {{ getSample(field) }}</div>
</div>
</div>
</div>
</div>

View File

@ -68,6 +68,23 @@
border-radius: 8px;
padding: 10px;
background: $white;
display: flex;
flex-direction: column;
.name {
}
.secondary {
display: flex;
justify-content: space-between;
.sample {
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
}
}

View File

@ -40,7 +40,26 @@ export class FileAttributesCsvImportDialogComponent implements OnInit {
if (!this.delimiter) {
this.delimiter = this.parseResult.meta.delimiter;
}
console.log(this.parseResult);
});
reader.readAsText(this.csvFile, this.encoding);
}
getSample(field: string) {
return this.parseResult?.data ? this.parseResult?.data[0][field] : '';
}
getEntries(field: any) {
if (this.parseResult?.data) {
let count = 0;
for (let entry of this.parseResult.data) {
if (entry[field]) {
count++;
}
}
return count;
} else {
return 0;
}
}
}