Last active
December 17, 2015 16:59
-
-
Save madgaoh/5643009 to your computer and use it in GitHub Desktop.
Neo4j (<= 1.9) web tool can't share data browser view profiles.
This script can export current selected profile to textbox (auto-generated in header-menu area).
You can copy it, and use another script for import. Please execute in neo4j web tool page, by browser's dev-tools or bookmarklet.
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
/* ====== for export ====== */ | |
function exportCurrentProfile() { | |
var profiles = JSON.parse(localStorage.getItem("databrowser.visualization.profiles")); | |
if (!profiles) { | |
return {"err":"profile data not initialized."}; | |
} | |
var currentProfileId = localStorage.getItem("databrowser.visualization.currentProfile"); | |
var currentProfile = ""; | |
for (i = 0; i < profiles.length; i++) { | |
if (profiles[i].id == currentProfileId) { | |
currentProfile = profiles[i]; | |
break; | |
} | |
} | |
if (currentProfile == null) { | |
return {"err":"profile data not found."}; | |
} else if (currentProfile.builtin) { | |
return {"err":"buildtn profile is selected."}; | |
} else { | |
delete currentProfile.id; | |
return {"profile":currentProfile}; | |
} | |
} | |
function showExportedProfile(profile) { | |
var text = document.getElementById("exported-profile-text"); | |
if (!text) { | |
var li = document.createElement("li"); | |
li.className = "title-button"; | |
var span = document.createElement("span"); | |
span.innerText = "style export"; | |
span.className = "subtitle"; | |
text = document.createElement("input"); | |
text.id = "exported-profile-text"; | |
text.type = "text"; | |
li.appendChild(span); | |
li.appendChild(text); | |
document.getElementById("mainmenu").firstChild.appendChild(li); | |
text.onclick=text.select; | |
} | |
text.value = JSON.stringify(profile); | |
text.focus(); | |
text.onclick(); | |
} | |
var result = exportCurrentProfile(); | |
if (result.err) { | |
alert(result.err); | |
} else { | |
showExportedProfile(result.profile); | |
} |
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
/* ====== for import ====== */ | |
function importProfile(newProfile) { | |
if (!(newProfile.name && newProfile.styleRules)) { | |
return {"err":"invalid data."}; | |
} | |
var profiles = JSON.parse(localStorage.getItem("databrowser.visualization.profiles")); | |
if (!profiles) { | |
profiles = [{"id":0,"name":"Default profile","builtin":true,"styleRules":[]}]; | |
} | |
newProfile.id = profiles[profiles.length-1].id + 1; | |
var newProfiles = profiles.concat([newProfile]); | |
localStorage.setItem("databrowser.visualization.profiles", JSON.stringify(newProfiles)); | |
localStorage.setItem("databrowser.visualization.currentProfile", newProfile.id); | |
return {}; | |
} | |
var result = importProfile(JSON.parse(prompt("please paste text", ""))); | |
if (result.err) { | |
alert(result.err); | |
} else { | |
alert("import success, please reload page."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment