Skip to content

Commit

Permalink
readme more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
bleucitron committed Jan 20, 2016
2 parents eccf633 + 45e93a6 commit 62ea84b
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 297 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.2
5 changes: 4 additions & 1 deletion PRIVATE.json.template
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"secret": "fake"
"secret": "fake",
"pg_user": "postgres",
"pg_pwd": "toto",
"db_name": "element"
}
35 changes: 10 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,41 @@
### Dependencies

Install:
* Docker
* Node.js
* Postgresql

the use `npm install` to install all the dependencies.
Create a `Tokens.json` following the [example](Tokens.example.json)
Create a `PRIVATE.json` following the [example](PRIVATE.example.json)



### Initialize the database

There are two way of loading the places in the db.

#### Load with files

Put your datafiles in `data`, then do:
In the psql console (just type `psql` to access it), you can init your db with:

```
npm run serve-dev
# then in another window
docker exec 6elementdev_api_1 tools/init-database.js
docker exec 6elementdev_api_1 tools/loadFiles.js
alter user postgres password 'toto';
CREATE DATABASE element OWNER postgres;
```

in production you can use `npm run prod` and change the names of the containers in the exec commands.

#### Load from a backup

In dev, `./backups` is linked to `/backups` and in prod, `/data/6element/backups` is linked to `/backups` where automatic backups (at 3AM) are persisted.
At anytime you can backup the db using
In your regular console:

```
docker exec 6elementdev_api_1 tools/backup.js > backups/test.sql
node tools/init-database.js
```

to load it back **you must put it in your backups folder and give the path inside the container**:
you can always use `psql` separately to load and dump data:

```
docker exec 6elementdev_api_1 tools/restore.js /backups/test.sql
psql -p5432 -U postgres -d element < Desktop/latest.sql
```

you can also use a gziped file (comming from the automated backup for example).


### Running the app

#### Daily routine in dev

```
npm run start-dev
npm run dev
```


Expand Down
1 change: 1 addition & 0 deletions client/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ article{

.border-open { border: solid #7fdc2b 2px; font-size: 15px; }
.border-closed { border: solid #ff3b6c 2px; font-size: 15px; text-decoration : line-through;}
.border-grey { border: solid #616161 2px; font-size: 15px;}

.chart {
width: 100%;
Expand Down
19 changes: 8 additions & 11 deletions client/decheteries.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
<script defer src="./js/panels.js"></script>
<script defer src="./js/favorite.js"></script>
<script defer src="./js/charts.js"></script>
<!--<script src="./js/map.js"></script>-->
<!--<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
<script defer src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script>-->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-71148240-1', 'auto');
ga('send', 'pageview', location.pathname);
</script>
</head>
<body>
<header>
Expand All @@ -31,13 +36,5 @@
<div id="sheet" />
</div>
</article>
<!--<nav>
<div class="adapt-width">
<div id="navigation">
<button class="btn-recycling-center">Déchèteries</button>
<button class="btn-container">Containeurs</button>
</div>
</div>
</nav>-->
</body>
</html>
8 changes: 8 additions & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
</script>
<script defer src="./js/location.js"></script>
<script defer src="./js/favorite.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-71148240-1', 'auto');
ga('send', 'pageview', location.pathname);
</script>
</head>
<body>
<header>
Expand Down
12 changes: 6 additions & 6 deletions client/js/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ function formatDate (date) {
showlegend: false,
x: xSignals,
y: ySignals,
marker: {
symbol: 'x',
color: '#E400B9'
line: {
shape: 'spline',
color: '#E400B9',
connectgaps: false
},
line: {shape: 'spline'},
mode: 'lines',
hoverinfo: 'none'
},
Expand Down Expand Up @@ -134,9 +134,9 @@ function draw(node, data){
ticksX.push(strDate);
}

if(value >= 0 && isAffluence){
if(isAffluence){
xSignals.push(strDate);
ySignals.push(value);
ySignals.push(value >= 0 ? value : {undefined});
}

// Color
Expand Down
11 changes: 9 additions & 2 deletions client/js/favorite.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ function getCookie(sName) {


function changeFavorite(e){
var button = e.srcElement.parentNode;
var button = e.currentTarget;
var isFavorite = button.class === 'place-favorite';
button.class = isFavorite ? 'place-no-favorite' : 'place-favorite';
e.srcElement.src = isFavorite ? '../img/no-favorite.svg' : '../img/favorite.svg';
e.currentTarget.firstChild.src = isFavorite ? '../img/no-favorite.svg' : '../img/favorite.svg';
var id = button.id.replace('register-','');
var cookie_places = getCookie('6element-places') || '';
if(isFavorite) setCookie('6element-places', cookie_places.replace(id + ';',''));// remove place in cookie
else setCookie('6element-places', cookie_places + id + ';');// add place in cookie

ga('send', {
hitType: 'event',
eventCategory: 'Favorites',
eventAction: 'changeFavorite',
eventLabel: id + ':' + (isFavorite ? 'false' : 'true')
});
}

function initializeAllFavorites(){
Expand Down
26 changes: 24 additions & 2 deletions client/views/placeView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var React = require('react');
var getColor = require('../js/getColor');
var Calendar = require('./calendar');
var opening_hours = require('opening_hours');
var moment = require('moment');
var momentTZ = require('moment-timezone');

var NotEmpty = function(field){
if(field === undefined) return false;
Expand All @@ -13,6 +15,22 @@ var NotEmpty = function(field){
return true;
}

function fromUTC(str){

var tmp = str.split('T');
var vDate = tmp[0].split('-');
var vTime = tmp[1].split(':');

var yyyy = parseInt(vDate[0]);
var MM = parseInt(vDate[1]);
var dd = parseInt(vDate[2]);
var hh = parseInt(vTime[0]);
var mm = parseInt(vTime[1]);
var ss = parseInt(vTime[2]);

return new Date(Date.UTC(yyyy,MM-1,dd,hh,mm,ss));
}

module.exports = React.createClass({
render: function() {

Expand All @@ -22,7 +40,11 @@ module.exports = React.createClass({
// OPENING HOURS
var oh = place.opening_hours === null ? undefined :
new opening_hours(place.opening_hours);
var isOpen = oh ? oh.getState() : true;
var now = momentTZ().tz('Europe/Paris').toDate();
//console.log(now);
//var now = fromUTC(momentTZ().tz('Europe/Paris').format());

var isOpen = oh ? oh.getState(now) : true;
var calendarJSX = NotEmpty(place.opening_hours) ?
(<Calendar opening_hours={place.opening_hours} />) : "";

Expand Down Expand Up @@ -78,7 +100,7 @@ module.exports = React.createClass({
{
binsJSX = place.bins
.map(function(bin, num){
return (<li key={'bin'+id+num} className={bin.a?"border-open":"border-closed"}>{bin.t}</li>);
return (<li key={'bin'+id+num} className={!isOpen ? 'border-grey' : bin.a ? "border-open":"border-closed"}>{bin.t}</li>);
});
}

Expand Down
3 changes: 0 additions & 3 deletions client/views/placesView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ module.exports = React.createClass({
return (<PlaceView key={'place'+place.id} place={place} date={self.props.date} mode={self.props.mode} />);
});

/*<button id="btn-map">Afficher la carte</button>
<div id="map" className="hide-map"/>*/

return (
<div id="places">
{placesJSX}
Expand Down
27 changes: 0 additions & 27 deletions compose-alpha.yml

This file was deleted.

28 changes: 0 additions & 28 deletions compose-dev.yml

This file was deleted.

27 changes: 0 additions & 27 deletions compose-prod.yml

This file was deleted.

17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
"lint": "eslint .",
"watch": "babel client/views/*.jsx --out-dir . --watch",
"build": "babel client/views/*.jsx --out-dir .",
"stop-dev": "docker-compose -p dev6element -f compose-dev.yml stop",
"stop-alpha": "docker-compose -p alpha6element -f compose-alpha.yml stop",
"stop-prod": "docker-compose -f compose-prod.yml stop",
"prod": "docker-compose -f compose-prod.yml up -d --force-recreate",
"prod": "node server/index.js",
"preprod": "npm run build",
"alpha": "docker-compose -p alpha6element -f compose-alpha.yml up -d --force-recreate",
"prealpha": "npm run build",
"serve-dev": "docker-compose -p dev6element -f compose-dev.yml up --force-recreate",
"dev": "npm-run-all --parallel serve-dev watch",
"monitor": "nodemon -L --watch server --watch client/*.js server/index.js",
"dev": "npm-run-all --parallel serve-dev watch monitor",
"validate": "npm ls"
},
"babel": {
Expand Down Expand Up @@ -49,12 +44,11 @@
"es6-shim": "^0.31.3",
"express": "^4.12.4",
"jsdom": "^7.0.2",
"node-schedule": "^0.6.0",
"moment": "^2.11.1",
"moment-timezone": "^0.5.0",
"opening_hours": "^3.3.0",
"pg": "^4.4.2",
"pg-hstore": "^2.3.2",
"geolib": "^2.0.18",
"proj4": "^2.3.10",
"query-string": "^3.0.0",
"react": "0.14.5",
"react-dom": "0.14.5",
Expand All @@ -70,6 +64,7 @@
"babel-preset-react": "^6.1.18",
"eslint": "^1.3.1",
"eslint-plugin-react": "^3.15.0",
"nodemon": "^1.8.1",
"npm-run-all": "^1.3.4",
"reactify": "^1.1.1",
"watchify": "^3.2.1"
Expand Down
Loading

0 comments on commit 62ea84b

Please sign in to comment.