add support for querystring config; ref #118

This commit is contained in:
Radek Stepan 2016-06-08 12:01:55 -04:00
parent d04dad7a57
commit 52240d54f0
8 changed files with 774 additions and 240 deletions

View File

@ -27,7 +27,9 @@ $ burnchart --port 8080
##Configuration
At the moment, there is no ui exposed to change the app settings. You have to edit the `src/config.js` file.
At the moment, there is no UI exposed to change the app settings. You have to either edit the `src/config.js` file or use URL query string parameters to override these on a per-user basis.
###Config Fields
An array of days when we are not working where Monday = 1. The ideal progression line won't *drop* on these days.
@ -53,6 +55,14 @@ You can also create your own app theme. Create a LESS file following the example
"theme": "monza"
```
###URL Query String
The main config file can be overriden by passing URL query string parameters. This allows app customization on a per-user basis. We use the [qs](https://github.com/ljharb/qs) library to parse and [lodash](http://devdocs.io/lodash~3/index#merge) to merge in the new values. The following example will switch off the main theme and set off days to fall on the weekend:
```
?theme=raw&chart[off_days][0]=0&chart[off_days][1]=6
```
##Development
To run your local version of the app, install all the NPM dependencies, watch the source files in one window, and start the static file server in the other in `--dev` mode.

View File

@ -45,7 +45,7 @@ index = index.replace(/bundle\.min/gm, 'bundle');
var server = http.createServer(function(req, res) {
req.addListener('end', function() {
// Serve a custom index file in dev mode.
if (args.dev && req.url == '/') {
if (args.dev && req.url.split('?')[0] == '/') {
res.writeHead(200, {
'Content-Length': index.length,
'Content-Type': 'text/html'

View File

@ -42,6 +42,7 @@
"object-assign": "^4.0.1",
"object-path": "^0.9.2",
"proxyquire": "^1.7.3",
"qs": "^6.2.0",
"react": "^0.14.6",
"react-addons-css-transition-group": "^0.14.6",
"react-autosuggest": "^3.3.5",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,19 @@
import React from 'react';
import ReactDOM from 'react-dom';
import qs from 'qs';
import _ from 'lodash';
import App from './App.jsx';
// Get the config.
import config from '../config.js';
// Parse the query string params overriding the config.
if (location.search) {
_.merge(config, qs.parse(location.search.substring(1)));
}
//&chart[off_days][0]=0&chart[off_days][1]=6
let el = document.getElementById('app');
// Set the theme.
el.className = `theme--${config.theme}`;

View File

@ -16,7 +16,7 @@ export default {
'date': moment(created_at, moment.ISO_8601).toJSON(),
'points': total
}];
min = +Infinity , max = -Infinity;
// Generate the actual closes.
@ -31,7 +31,7 @@ export default {
issue.points = total -= size;
return issue;
});
// Now add a radius in a range (will be used for a circle).
let range = d3.scale.linear().domain([ min, max ]).range([ 5, 8 ]);
@ -51,6 +51,9 @@ export default {
// Swap if end is before the start...
if (b < a) [ b, a ] = [ a, b ];
// Make sure off days are numbers.
const off_days = _.map(config.chart.off_days, (n) => parseInt(n, 10));
a = moment(a, moment.ISO_8601);
// Do we have a due date?
b = (b != null) ? moment(b, moment.ISO_8601) : moment.utc();
@ -65,7 +68,7 @@ export default {
let day_of;
if (!(day_of = day.weekday())) day_of = 7;
if (config.chart.off_days.indexOf(day_of) != -1) {
if (off_days.indexOf(day_of) != -1) {
days.push({ 'date': day.toJSON(), 'off_day': true });
} else {
length += 1;
@ -74,11 +77,11 @@ export default {
// Go again?
if (!(day > b)) once(inc + 1);
})(0);
})(0);
// Map points on the array of days now.
let velocity = total / (length - 1);
days = _.map(days, (day, i) => {
day.points = total;
if (days[i] && !days[i].off_day) total -= velocity;

View File

@ -109,10 +109,12 @@ let request = ({ protocol, host, path, query, headers }, cb) => {
_.each(headers, (v, k) => { req.set(k, v); });
// Timeout for requests that do not finish... see #32.
let ms = config.request.timeout;
ms = (_.isString(ms)) ? parseInt(ms, 10) : ms;
let timeout = setTimeout(() => {
exited = true;
cb('Request has timed out');
}, config.request.timeout);
}, ms);
// Send.
req.end((err, data) => {