Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: logic to parse csv file and display in console(#22c8vdr) #4

Merged
merged 4 commits into from
Feb 23, 2022
Merged
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
6 changes: 6 additions & 0 deletions changelogs/unreleased/-22c8vdr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: 'Implemented: logic to parse csv file and display in console'
ticket_id: "#22c8vdr"
merge_request: 4
author: Disha Talreja
type: added
6 changes: 3 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -58,16 +58,16 @@ const showToast = async (message: string) => {
// ['Jake', '33', 'c'],
// ['Jill', '30', 'd']]

const parseCsv = async (file: File, options: any) => {
const parseCsv = async (file: File, options?: any) => {
return new Promise ((resolve, reject) => {
Papa.parse(file, {
header: false,
header: true,
skipEmptyLines: true,
complete: function (results: any) {
if (results.errors.length) {
reject(results.error)
} else {
resolve(results)
resolve(results.data)
}
},
...options
36 changes: 28 additions & 8 deletions src/views/PurchaseOrder.vue
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@
<div class="header">
<div class="fileInput">
<ion-item>
<ion-label for="inputFile">{{ $t("Purchase order") }}</ion-label>
<ion-input class="ion-hide" :placeholder="$t('Select CSV')" type="file" id="inputFile"/>
<ion-button slot="end" fill="outline">{{ $t("Upload") }}</ion-button>
<ion-label>{{ $t("Purchase order") }}</ion-label>
<input @change="getFile" ref="file" class="ion-hide" type="file" id="inputFile"/>
<label for="inputFile">{{ $t("Upload") }}</label>
</ion-item>
</div>
<div class="info">
@@ -44,9 +44,10 @@
</ion-content>
</ion-page>
</template>
<script lang="ts">
import { IonPage, IonHeader, IonToolbar, IonBackButton, IonTitle, IonContent, IonItem, IonLabel, IonNote, IonInput, IonButton, IonSelect } from "@ionic/vue";
import { defineComponent } from "vue";
<script>
import { IonPage, IonHeader, IonToolbar, IonBackButton, IonTitle, IonContent, IonItem, IonLabel, IonNote, IonButton, IonSelect } from "@ionic/vue";
import { defineComponent, ref } from "vue";
import { parseCsv } from '@/utils'
export default defineComponent({
name: " purchase orders",
components: {
@@ -58,11 +59,30 @@ export default defineComponent({
IonContent,
IonItem,
IonLabel,
IonInput,
IonButton,
IonSelect,
IonNote
}
},
data() {
return {
file: "",
content:[]
}
},
methods: {
getFile(event) {
const file = ref(null);
this.file = event.target.files[0];
this.parseFile();
},
async parseFile(){
await parseCsv(this.file).then(res => {
this.content = res;
console.log(res);
})
},
},

})
</script>
<style scoped>