-
Notifications
You must be signed in to change notification settings - Fork 1
π Import & Export (FileHandler)
File: Meesterproef-SNSimulation/js/FileHandler.js
-
export(nodes): Exports the network nodes to a JSON file. Prompts the user for a filename and creates a downloadable file with the network setup.-
Parameters:
-
nodes(Map): The map of nodes to export.
-
-
Explanation
Because there is no way to export a file with JavaScript, the function creates an
aelement with the JSON file as blob in thehrefand adownloadattribute with the filename. After which, it programmatically clicks the link to download the file and then removes the link.
-
-
import(nodes, links): Imports network nodes and links from a JSON file. Prompts the user to select a file and updates the nodes and links based on the file content.-
Parameters:
-
nodes(Map): The map of nodes to update with imported data. -
links(Map): The map of links to update with imported data.
-
-
Returns: Promise - Resolves when the import is complete.
-
Explanation
Because there is no way to prompt for a file in JavaScript, this function does a similar trick to the export function. It creates an HTML
<input type="file">and then clicks it. Thereafter, it reads the file with a newFileReader()object. It then rebuilds the nodes map from the imported JSON file.
-
-
mapToArray(map): Converts a map to an array of objects. Each object represents an item from the map, including nested maps and ignoring HTML elements.-
Parameters:
-
map(Map): The map to convert to an array.
-
-
Returns: Array - The array representation of the map.
-
-
π Debrief
-
β οΈ Problem definition -
π§βπ¨ Design
-
π§βπ» Solution & Code
- ποΈ App (main file)
- π€ Simulation
- π΅ Node
- π Person
- π° Post
- γ°οΈ Edge
βοΈ Cursor- π½ userData
- π WebData
- π Import & Export (FileHandler)
- Onboarding
-
π€ Recommendations