-
Notifications
You must be signed in to change notification settings - Fork 0
Ability to download metadata related to searched/filtered results. #39
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,116 @@ | ||
| <template> | ||
| <v-btn block @click="downloadMapData">Download Map Data</v-btn> | ||
| </template> | ||
|
|
||
| <script setup> | ||
| import { useMapStore } from '@/stores/map'; | ||
| import Papa from 'papaparse'; | ||
|
|
||
| const mapStore = useMapStore(); | ||
| const renameColumnInCSV = { | ||
| "figure num": "Figure Number", | ||
| "figure caption": "Figure Caption", | ||
| "figure url": "Figure Url", | ||
| "textmodel section number": "Textmodel Section Number", | ||
| "textmodel section name": "Textmodel Section Name", | ||
| "textmodel page number": "Textmodel Page Number", | ||
| "textmodel snipped": "Textmodel Snippet", | ||
| "citation citation": "Citation", | ||
| "citation url": "Citation Url", | ||
| "citation attribution": "Citation Attribution", | ||
| "citation attribution url": "Citation Attribution Url", | ||
| "location long name": "Location Name", | ||
| "location country": "Location Country", | ||
| "location area km2": "Location Area [km^2]", | ||
| "process taxonomies process": "Taxonomy Processes", | ||
| "vegetation info": "Vegetation Info", | ||
| "soil info": "Soil Info", | ||
| "geol info": "Geological Info", | ||
| "topo info": "Topographic Info", | ||
| "uncertainty info": "Uncertainty Info", | ||
| "other info": "Other Info", | ||
| "num spatial zones": "Number of Spatial Zones", | ||
| "spatial zone type spatial property": "Spatial Zone Type", | ||
| "num temporal zones": "Number of Temporal Zones", | ||
| "temporal zone type temporal property": "Temporal Zone Type", | ||
| "model type name": "Model Type" | ||
| } | ||
| const csvColumns = Object.values(renameColumnInCSV); | ||
|
|
||
| function flattenItem(obj, parentKey = '', result = {}) { | ||
| for (const key in obj) { | ||
| if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
| let newKey = parentKey ? `${parentKey} ${key}` : key; | ||
|
|
||
| // Convert column names as per requirement | ||
| newKey = renamecsvColumn(newKey); | ||
|
|
||
| if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) { | ||
| // Recursive call for nested objects | ||
| flattenItem(obj[key], newKey, result); | ||
| } else if (Array.isArray(obj[key])) { | ||
| if (obj[key].every(item => typeof item === 'string' || typeof item === 'number')) { | ||
| result[newKey] = obj[key].join(', '); | ||
| } else { | ||
| const arrayValues = {}; | ||
| obj[key].forEach(item => { | ||
| for (const subKey in item) { | ||
| if (Object.prototype.hasOwnProperty.call(item, subKey)) { | ||
| if (!arrayValues[subKey]) { | ||
| arrayValues[subKey] = []; | ||
| } | ||
| arrayValues[subKey].push(item[subKey]); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| for (const arrayKey in arrayValues) { | ||
| const renamedValue = renamecsvColumn(`${newKey} ${arrayKey}`); | ||
| if (csvColumns.includes(renamedValue)) | ||
| result[renamedValue] = arrayValues[arrayKey].join(', '); | ||
| } | ||
| } | ||
| } else { | ||
| if (csvColumns.includes(newKey)) | ||
| result[newKey] = obj[key]; | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| function flattenMapDataJSON(data) { | ||
| const result = []; | ||
| data.forEach(item => { | ||
| // As per requirement only include properties, no need of geometry info | ||
| result.push(flattenItem(item.properties)); | ||
| }); | ||
| return result; | ||
| } | ||
|
|
||
| function downloadMapData() { | ||
| const mapData = mapStore.currentFilteredData; | ||
| const flattenedMapData = flattenMapDataJSON(mapData); | ||
|
|
||
| const csv = Papa.unparse(flattenedMapData, { | ||
| columns: csvColumns | ||
| }); | ||
|
|
||
| const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); | ||
|
|
||
| const link = document.createElement('a'); | ||
| link.href = URL.createObjectURL(blob); | ||
| link.setAttribute('download', 'data.csv'); | ||
| document.body.appendChild(link); | ||
| link.click(); | ||
| document.body.removeChild(link); | ||
| } | ||
| function renamecsvColumn(name) { | ||
| let newName = name.replaceAll("_", " "); | ||
| newName = newName.replace(/\b\w/g, char => char.toLowerCase()); | ||
| if (renameColumnInCSV[newName]) { | ||
| newName = renameColumnInCSV[newName]; | ||
| } | ||
| return newName; | ||
| } | ||
| </script> |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.