Skip to content

Commit

Permalink
Merge pull request #73 from ymaheshwari1/fix/unused-code
Browse files Browse the repository at this point in the history
Removed: RouteMenu component, util functions and package those are not used
  • Loading branch information
ymaheshwari1 authored Feb 2, 2024
2 parents a22cb78 + 35f05f5 commit 1f49840
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 254 deletions.
32 changes: 3 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
"@ionic/core": "^7.6.0",
"@ionic/vue": "^7.6.0",
"@ionic/vue-router": "^7.6.0",
"@types/file-saver": "^2.0.4",
"@types/papaparse": "^5.3.1",
"axios": "^0.21.1",
"axios-cache-adapter": "^2.7.3",
"core-js": "^3.6.5",
"file-saver": "^2.0.5",
"http-status-codes": "^2.1.4",
"luxon": "^2.3.0",
"mitt": "^2.1.0",
Expand Down Expand Up @@ -53,7 +50,6 @@
"cypress": "^8.3.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"papaparse": "^5.3.1",
"typescript": "~4.7.4",
"vue-cli-plugin-i18n": "^1.0.1"
}
Expand Down
120 changes: 0 additions & 120 deletions src/components/RouteMenu.vue

This file was deleted.

102 changes: 1 addition & 101 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import saveAs from "file-saver";
import { toastController } from "@ionic/vue";
import Papa from "papaparse"
import { Group, Route, Rule } from "@/types";
import { DateTime } from "luxon";

Expand All @@ -21,104 +19,6 @@ const showToast = async (message: string) => {
return toast.present();
}

// Utility for parsing CSV file
// Package Used : PapaParse (Link to Documentation : https://www.papaparse.com/docs#config)

// In this we will be receiving the file and options in the function
// and we are returning a promise with results in it

// We have used the parse method of the papaparse library which will take a config object with File.
// In the config object we have passed various keys:
// - header : It tells papaparse that there will be a header in the CSV.
// - skipEmptyLines : It will ignore any empty lines in the CSV.
// - complete : A parse result always contains three objects: data, errors, and meta.
// data and errors are arrays, and meta is an object. In the step callback, the data
// array will only contain one element.

// Also, we have passed options, as if user wants to add some more properties to the method
// or if he want to modify some pre-build keys then he can do so.

// Types of Responses

// CSV FILE :
// columnA,columnB,columnC
// "Susan",41,a
// "Mike",5,b
// "Jake",33,c
// "Jill",30,d

// For (header:true) we get
// [{columnA: "Susan", columnB: "41", columnC: "a"},
// {columnA: "Mike", columnB: "5", columnC: "b"},
// {columnA: "Jake", columnB: "33", columnC: "c"},
// {columnA: "Jill", columnB: "30", columnC: "d"}]

// // For (header:false) we get
// [["columnA", "columnB", "columnC"],
// ["Susan", "41", "a"],
// ["Mike", "5", "b"],
// ["Jake", "33", "c"],
// ["Jill", "30", "d"]]

const parseCsv = async (file: File, options: any) => {
return new Promise ((resolve, reject) => {
Papa.parse(file, {
header: false,
skipEmptyLines: true,
complete: function (results: any) {
if (results.errors.length) {
reject(results.error)
} else {
resolve(results)
}
},
...options
});
})
}

// Here we have created a JsonToCsvOption which contains the properties which we can pass to jsonToCsv function

interface JsonToCsvOption {
parse?: object | null;
encode?: object | null;
name?: string;
download?: boolean;
}

// Utility for converting Javascript Object into blob and download it as Csv
// Package Used : PapaParse (Link to Documentation : https://www.papaparse.com/docs#config)
// file-saver (Link to Documentation : https://www.npmjs.com/package/file-saver)

// In this we will be receiving a Javascript object and options in the function and we will be
// returning a blob object

// We have used a unparse method of papaparse library for converting javascript object into csv file,
// and in addition to this we are using saveAs method to download our blob file
// In the options we will be passing various keys:
// parse: In this we will be passing a object which contains various properties (headers,skipEmptyLines) to be passed in unparse method
// encode: In this we will be passing a object which contains various properties related to the encoding like { type }
// name: In this we will provide a name by which we want to download the csv File, and it is necessary to provide the .csv in the name
// download: In this we will provide a value which will decide whether we want to download the file or not

const jsonToCsv = (file: any, options: JsonToCsvOption = {}) => {
const csv = Papa.unparse(file, {
...options.parse
});
const encoding = {
type: String,
default: "utf-8",
...options.encode
};
const blob = new Blob([csv], {
type: "application/csvcharset=" + encoding
});
if (options.download) {
saveAs(blob, options.name ? options.name : "default.csv");
}
return blob;
}

const sortSequence = (sequence: Array<Group | Route | Rule>) => {
// Currently, sorting is only performed on sequenceNum, so if two seqence have same seqNum then they will be arranged in FCFS basis
// TODO: Need to check that if for the above case we need to define the sorting on name as well, when seqNum is same
Expand All @@ -133,4 +33,4 @@ const getTimeFromSeconds = (time: any) => {
return time ? DateTime.fromSeconds(time).toLocaleString(DateTime.DATETIME_MED) : "-";
}

export { getTime, getTimeFromSeconds, showToast, hasError , parseCsv , jsonToCsv, JsonToCsvOption, sortSequence }
export { getTime, getTimeFromSeconds, showToast, hasError, sortSequence }

0 comments on commit 1f49840

Please sign in to comment.