forked from emoncms/emoncms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
installed composer created new file to load part of config file and return as json added user editable units in config file
- Loading branch information
Showing
5 changed files
with
224 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ Modules/*/ | |
Theme/* | ||
Theme/*/ | ||
!Theme/basic/ | ||
|
||
/vendor/ |
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,9 @@ | ||
{ | ||
"name": "emoncms/emoncms", | ||
"description": "Web-app for processing, logging and visualising energy, temperature and other environmental data https://emoncms.org", | ||
"type": "project", | ||
"require": { | ||
"yosymfony/toml": "^1.0" | ||
}, | ||
"license": "GNU AFFERO GENERAL PUBLIC LICENSE" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,63 @@ | ||
# This is a config file for saving user editable editable settings. | ||
# Written in TOML to standardize the config file format | ||
# https://github.com/toml-lang/toml | ||
|
||
[version] | ||
title = "Emoncms Settings" | ||
date = 2018-09-20T20:43:11Z | ||
|
||
# common engeneering units - add [[units]] before the "short" and "long" names | ||
# this list will appear whenever you select units within the system | ||
|
||
[[units]] | ||
short = "W" | ||
long = "Watt" | ||
[[units]] | ||
short = "kWh" | ||
long = "Kilowatt Hour" | ||
|
||
[[units]] | ||
short = "Wh" | ||
long = "Watt-Hour" | ||
|
||
[[units]] | ||
short = "V" | ||
long = "Volt" | ||
|
||
[[units]] | ||
short = "VA" | ||
long = "Volt-Ampere" | ||
|
||
[[units]] | ||
short = "A" | ||
long = "Ampere" | ||
|
||
[[units]] | ||
short = "°C" | ||
long = "Celsius" | ||
|
||
[[units]] | ||
short = "K" | ||
long = "Kelvin" | ||
|
||
[[units]] | ||
short = "°F" | ||
long = "Fahrenheit" | ||
|
||
[[units]] | ||
short = "%" | ||
long = "Percent" | ||
|
||
[[units]] | ||
short = "Hz" | ||
long = "Hertz" | ||
|
||
[[units]] | ||
short = "pulses" | ||
long = "Pulses" | ||
|
||
[[units]] | ||
short = "dB" | ||
long = "Decibel" | ||
|
||
|
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,30 @@ | ||
<?php | ||
/** | ||
* load a config file and return units it as json | ||
*/ | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
use Yosymfony\Toml\Toml; | ||
// https://github.com/yosymfony/toml | ||
|
||
$filename = 'custom-config.toml'; | ||
try { | ||
$config = Toml::ParseFile($filename); | ||
} catch (Exception $e) { | ||
$config = array("success"=>false,"message"=>$e->getMessage()); | ||
} | ||
header('Content-Type: application/json'); | ||
echo json_encode($config['units'],JSON_UNESCAPED_UNICODE); | ||
|
||
|
||
/** | ||
* @ todo: create api endpoint to add to the config file?? | ||
* you can use the TomlBuilder class to build toml data from PHP | ||
*/ | ||
// use Yosymfony\Toml\TomlBuilder; | ||
// $tb = new TomlBuilder(); | ||
// $values = $tb->addComment('edited by [user] on [date]') | ||
// ->addTable('widget') | ||
// ->addValue('height', "120px") | ||
// ->getTomlString(); | ||
// file_put_contents ($filename , $values, FILE_APPEND); |