-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide a document-based component capable of displaying CSV co…
…ntent. (close #1012)
- Loading branch information
Showing
4 changed files
with
78 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<template> | ||
<q-scroll-area class="fit"> | ||
<table v-if="data"> | ||
<template v-for="(row, index) in data" :key="index"> | ||
<tr> | ||
<template v-for="cell in row" :key="cell"> | ||
<td>{{ cell }}</td> | ||
</template> | ||
</tr> | ||
</template> | ||
</table> | ||
</q-scroll-area> | ||
</template> | ||
|
||
<script setup> | ||
import { ref, watch } from 'vue' | ||
import Papa from 'papaparse' | ||
import { Document } from '../../document.js' | ||
// Props | ||
const props = defineProps({ | ||
url: { | ||
type: String, | ||
default: null | ||
}, | ||
localize: { | ||
type: Boolean, | ||
default: true | ||
}, | ||
options: { | ||
type: Object, | ||
default: () => null | ||
} | ||
}) | ||
// Data | ||
const data = ref(null) | ||
// Watch | ||
watch(() => props.url, async (value) => { | ||
const response = await Document.fetchUrl(value, props.localize) | ||
if (response?.ok) { | ||
const csv = await response.text() | ||
data.value = Papa.parse(csv, props.options).data | ||
} | ||
else data.value = null | ||
}, { immediate: true }) | ||
</script> | ||
<style lang="scss"> | ||
td { | ||
padding-left: 4px; | ||
padding-right: 4px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters