Web User Interface
The Web User Interface is built on NodeJS using the framework SailsJS on the server side and AngularJS on the client side. It is connected to PostgreSQL for managing the data and to Redis for managing sessions.
The versions are:
- NodeJS: 4.4.1
- PostgreSQL: 9.5
- Redis: 2.8.4
- For the frameworks and other libraries, check the files
package.jsonandbower.json
Structure
The folder is called web and its structure is the following:
web
|___ .tmp
| ...
|___ api
|___ controllers
| FeedbackController.js
| PointsController.js
| RatingsController.js
| TranslationsController.js
|___ models
| Points.js
| Ratings.js
| SentimentFeedback.js
| TranslationKeys.js
| Translations.js
|___ policies
| ...
|___ responses
| ...
|___ services
| PointsService.js
| RatingsService.js
| SentimentFeedbackService.js
| TranslationsService.js
|___ assets
|___ bower
| ...
|___ images
| ...
|___ js
|___ controllers
| HomeController.js
| PointController.js
|___ dependencies
| sails.io.js
|___ services
| ChartFactory.js
| GoogleMapsFactory.js
| PointsService.js
| RatingFactory.js
| app.js
| directives.js
| removeDiacritics.js
|___ styles
| styles.less
| ...
|___ templates
| home.html
| infowindow.html
| menubar.html
| point.html
| typeahead.html
| favicon.ico
| robots.txt
|___ config
|___ env
| development.js
| production.js
| autoreaload.js
| bootstrap.js
| connections.js
| models.js
| ...
|___ tasks
| pipeline.js
| ...
|___ tests
| ...
|___ views
| homepage.ejs
| layout.ejs
| ...
| .bowerrc
| bower.json
| package.json
| README.md
| ...
Some comments about the structure:
- The
.tmpfolder contains the public files, which are automatically generated from a Grunt task of Sails. - The
apifolder is the server side logic, which contains the controllers, models and services. - The
assetsfolder is the client side logic.- The
bowerfolder contains the third-party libraries, which are automatically copied frombower_sourcesusing a Grunt task. - Mainly Angular code resides inside the
jsfolder- The
app.jsfile contains the definition of the angular module and some configurations. At the end of the file, there are some parameters that can be modified, for example, the initial latitude and longitude, the original language, the available languages, the options for the markers clusters, etc. - The directives are in the file
directives.js, the controllers are inside the foldercontrollersand the services inside the folderservices.
- The
- The templates are unified into a single file, as well as the js and css scripts (only in production)
- The
- About the
configfolder, here are listed the files that were modified - In the
tasksfolder there are the Grunt tasks. Some of them were modified to customize the development. - The
testsfolder contains the tests for the application, but they are still under develpment.
Deployment
Install PostgreSQL
Follow any guide, for example the official one for Ubuntu, or follow these steps:
- Create the file
/etc/apt/sources.list.d/pgdg.list, and add a line for the repositorydeb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main - Import the repository running
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \ sudo apt-key add -sudo apt-get update
- Install postgresql
sudo apt-get install postgresql-9.5
Now, make the database accesible:
- Change to postgres user
sudo su - postgres - Change these config files using
vior any other editorvi /etc/postgresql/9.5/main/postgresql.confChange this linelisten_addresses = '*'vi /etc/postgresql/9.5/main/pg_hba.confChange this linehost all all 0.0.0.0/0 md5
- Reload configuration and restart
psqlSELECT pg_reload_conf();\qservice postgresql restart
Create a user and the database:
psqlcreate user dmkm with password '<password>';create database smart with owner dmkm encoding 'UTF8';
Install the extension Unaccent (used for searching):
sudo su - postgrespsql -d smartCREATE EXTENSION unaccent;SELECT unaccent('Hôtel');
Install Redis
Install Redis and start the service.
-
On Centos, follow this guide
yum install wgetwget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/e/rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-*.rpmyum install redissystemctl start redis.servicesystemctl enable redis.service
-
On Ubuntu
sudo apt-get install redis-serversudo service redis-server
Install NodeJS
Install NodeJS downloading from its site or:
- On Ubuntu
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -sudo apt-get install -y nodejs
- On Centos (as root)
curl --silent --location https://rpm.nodesource.com/setup_4.x | bash -yum -y install nodejs
Install SailsJS
sudo npm -g install sails
Install Bower
sudo npm -g install bower
Install PM2
sudo npm -g install pm2
Initialize the application
- Clone the github repository https://github.com/DMKM1517/SmartCity.git
- On this directory create the file
login.jsonwith the content:
{
"dbname": "smart",
"host" : "<host>",
"port" : 5432,
"user" : "dmkm",
"password" : "<password>"
}
- If using Redis, create a file
web/config/local.jswith the content:
module.exports = {
session: {
adapter: 'redis'
},
sockets: {
adapter: 'socket.io-redis'
}
};
- Install the dependencies for the web
cd webnpm install --prodbower install
- Run the server using PM2
pm2 start app.js --name web -x -- --prod
- Save the process to startup
pm2 startup- (copy and execute the output line)
pm2 save
- The default port is
1337. To change it, modify the fileconfig/env/production.jsand uncomment or update the propertyport: 80
Update the application
- On the github directory
git pull- (make any modifications if needed)
- Restart the server
pm2 restart web- Check the logs
pm2 logs web
- Check the logs