Skip to content

Commit

Permalink
created new toml config file
Browse files Browse the repository at this point in the history
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
emrysr committed Sep 20, 2018
1 parent 12f69d6 commit fa16008
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ Modules/*/
Theme/*
Theme/*/
!Theme/basic/

/vendor/
9 changes: 9 additions & 0 deletions composer.json
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"
}
120 changes: 120 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions custom-config.toml
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"


30 changes: 30 additions & 0 deletions units.php
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);

0 comments on commit fa16008

Please sign in to comment.