-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Daniel Pollithy
committed
Jun 5, 2017
1 parent
075bb45
commit 08e46a5
Showing
7 changed files
with
210 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"styles": { | ||
"defaultVertex": { | ||
"fontSize": "100" | ||
} | ||
}, | ||
"defaultEdgeStyle": { | ||
"edgeStyle": "orthogonalEdgeStyle", | ||
"curved": "0" | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var log = require('electron-log'); | ||
|
||
|
||
var Settings = Settings || {}; | ||
|
||
Settings._store = {}; | ||
|
||
Settings._loaded = false; | ||
|
||
Settings._file_path = path.join(__dirname, '../media/settings/settings.json'); | ||
|
||
Settings.load = function() { | ||
var json; | ||
try { | ||
json = JSON.parse(fs.readFileSync(Settings._file_path, 'utf8')); | ||
} catch (e) { | ||
log.error('Could not load settings'); | ||
log.error(e); | ||
json = {}; | ||
} | ||
Settings._store = json; | ||
Settings._loaded = true; | ||
}; | ||
|
||
Settings.save = function() { | ||
// in order to avoid a flush we assure the settings were loaded first | ||
Settings.check_loaded(); | ||
fs.writeFileSync(Settings._file_path, JSON.stringify(Settings._store, null, 4)); | ||
}; | ||
|
||
Settings.check_loaded = function() { | ||
if (!Settings._loaded) { | ||
Settings.load(); | ||
} | ||
}; | ||
|
||
Settings.set = function(key, value) { | ||
Settings.check_loaded(); | ||
Settings._store[key] = value; | ||
}; | ||
|
||
Settings.get = function(key, fallback) { | ||
Settings.check_loaded(); | ||
if (!Settings.has(key)) { | ||
return fallback; | ||
} | ||
return Settings._store[key]; | ||
}; | ||
|
||
Settings.has = function(key) { | ||
Settings.check_loaded(); | ||
return Settings._store.hasOwnProperty(key); | ||
}; | ||
|
||
Settings.get_settings_for_frontend = function() { | ||
Settings.check_loaded(); | ||
return Settings._store; | ||
}; | ||
|
||
Settings.set_settings_from_frontend = function(new_settings) { | ||
try { | ||
var fontSize = new_settings.fontSize; | ||
if (8 < fontSize && fontSize < 200) { | ||
Settings._store.styles.defaultVertex.fontSize = fontSize; | ||
} | ||
var curved = new_settings.curved; | ||
console.log(curved) | ||
if (curved === "1") { | ||
Settings._store.defaultEdgeStyle.curved = "1"; | ||
} else { | ||
Settings._store.defaultEdgeStyle.curved = "0"; | ||
} | ||
Settings.save(); | ||
} catch (e) { | ||
log.error('settings could not be applied'); | ||
} | ||
}; | ||
|
||
module.exports = Settings; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extends layout.pug | ||
|
||
block title | ||
title= 'Settings' | ||
- var selected = 'settings' | ||
|
||
block content | ||
p= message | ||
h1= 'Settings' | ||
p= 'These are general settings' | ||
form(method='post', action='/settings') | ||
div(class="form-group") | ||
label(for='1')= 'Default font size (pt)' | ||
input(id='1', class="form-control", type='number', name='fontSize', value=settings.fontSize) | ||
div(class="form-group") | ||
label(for='2')= 'Should the edges be curved' | ||
if settings.curved === "1" | ||
input(id='2', class="form-control", type='checkbox', name='curved', value="1", checked) | ||
else | ||
input(id='2', class="form-control", type='checkbox', name='curved', value="1") | ||
input(type='submit', value='save') |