diff --git a/Dockerfile b/Dockerfile index e1a66cd..f29698b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,48 +1,11 @@ -# -# example Dockerfile for https://docs.docker.com/engine/examples/postgresql_service/ -# +FROM postgres:11.3 -FROM ubuntu:16.04 +ENV POSTGIS_MAJOR 2.4 -# Add the PostgreSQL PGP key to verify their Debian packages. -# It should be the same key as https://www.postgresql.org/media/keys/ACCC4CF8.asc -RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 +RUN apt-get update \ + && apt-get --assume-yes install software-properties-common postgis\ + && rm -rf /var/lib/apt/lists/ -# Add PostgreSQL's repository. It contains the most recent stable release -# of PostgreSQL, ``9.3``. -RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list +RUN mkdir -p /docker-entrypoint-initdb.d -# Install ``python-software-properties``, ``software-properties-common`` and PostgreSQL 9.3 -# There are some warnings (in red) that show up during the build. You can hide -# them by prefixing each apt-get statement with DEBIAN_FRONTEND=noninteractive -RUN apt-get update && apt-get install -y python-software-properties software-properties-common postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3 - -# Note: The official Debian and Ubuntu images automatically ``apt-get clean`` -# after each ``apt-get`` - -# Run the rest of the commands as the ``postgres`` user created by the ``postgres-9.3`` package when it was ``apt-get installed`` -USER postgres - -# Create a PostgreSQL role named ``docker`` with ``docker`` as the password and -# then create a database `docker` owned by the ``docker`` role. -# Note: here we use ``&&\`` to run commands one after the other - the ``\`` -# allows the RUN command to span multiple lines. -RUN /etc/init.d/postgresql start &&\ - psql --command "CREATE USER docker WITH SUPERUSER PASSWORD 'docker';" &&\ - createdb -O docker marketalerts - -# Adjust PostgreSQL configuration so that remote connections to the -# database are possible. -RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.3/main/pg_hba.conf - -# And add ``listen_addresses`` to ``/etc/postgresql/9.3/main/postgresql.conf`` -RUN echo "listen_addresses='*'" >> /etc/postgresql/9.3/main/postgresql.conf - -# Expose the PostgreSQL port -EXPOSE 5432 - -# Add VOLUMEs to allow backup of config, logs and databases -VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"] - -# Set the default command to run when starting the container -CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"] +CMD ["postgres"] diff --git a/README.md b/README.md index 5baaa51..6f2d0f4 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ The purpose of this project is to build a web application that enables subscribi ### Setup with npm commands -1. Run setup script +1. Install packages +`npm install` + +2. Run setup script `npm run setup` this will create and run postgres image and then execute migrations -2. Install packages -`npm install` - 3. Run app `npm start` to run app without restart on changes or `npm run start-mon` to run app with automatic restart on code change diff --git a/app/controllers/municipalities.js b/app/controllers/municipalities.js index c347d95..f64b185 100644 --- a/app/controllers/municipalities.js +++ b/app/controllers/municipalities.js @@ -1,7 +1,7 @@ const { currentRERequest } = require('../helpers/url'); -const { getMunicipalitiesForRegion } = require('../helpers/codes'); +const { getMunicipalitiesForRegion, getMunicipalityName } = require('../helpers/codes'); -const getMunicipality = async (req,res) => { +const getMunicipality = async (req, res) => { let request = await currentRERequest(req); const municipalities = getMunicipalitiesForRegion(request.region); @@ -10,9 +10,8 @@ const getMunicipality = async (req,res) => { const postMunicipality = async (req, res) => { const request = await currentRERequest(req); - - const nextStepPage = req.query.nextStep || 'povrsina'; - const nextStepUrl = `/${nextStepPage}/${request.uniqueId}`; + const nextStepPage = req.query.nextStep || 'naselje'; + const nextStepUrl = `/${nextStepPage}/${request.uniqueId}/${getMunicipalityName(request.region, req.body.municipality)}`; request.municipality = req.body.municipality; await request.save(); diff --git a/app/controllers/neighborhoodMap.js b/app/controllers/neighborhoodMap.js new file mode 100644 index 0000000..3874459 --- /dev/null +++ b/app/controllers/neighborhoodMap.js @@ -0,0 +1,35 @@ +const { currentRERequest } = require('../helpers/url'); + +const getNeighborhood = async (req, res) => { + const municipality = req.params.municipality + const nextStep = req.query.nextStep || '/'; + + res.render('neighborhoodMap', { + nextStep, + municipality + }); + +}; + +const postNeighborhood = async (req, res) => { + let request = await currentRERequest(req); + const northWest = [req.body.west, req.body.north]; + const northEast = [req.body.east, req.body.north]; + const southEast = [req.body.east, req.body.south]; + const southWest = [req.body.west, req.body.south]; + + request.bounding_box = { + type: 'Polygon', coordinates: [ + [northWest, northEast, southEast, + southWest, northWest] + ] + }; + await request.save(); + const nextStep = req.query.nextStep || `/povrsina/${request.uniqueId}`; + res.redirect(nextStep); +}; + +module.exports = { + getNeighborhood, + postNeighborhood +}; \ No newline at end of file diff --git a/app/migrations/20190523144812-activate-postgis.js b/app/migrations/20190523144812-activate-postgis.js new file mode 100644 index 0000000..8b944e3 --- /dev/null +++ b/app/migrations/20190523144812-activate-postgis.js @@ -0,0 +1,15 @@ +'use strict'; + +module.exports = { + up: (queryInterface, Sequelize) => { + return queryInterface.sequelize.query("CREATE EXTENSION postgis").then(([results, metadata]) => { + /// No result + }) + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.sequelize.query("DROP EXTENSION IF EXISTS postgis").then(([results, metadata]) => { + /// No result + }) + } +}; diff --git a/app/migrations/20190523151420-add-bounding-box-column.js b/app/migrations/20190523151420-add-bounding-box-column.js new file mode 100644 index 0000000..e319421 --- /dev/null +++ b/app/migrations/20190523151420-add-bounding-box-column.js @@ -0,0 +1,17 @@ +'use strict'; + +module.exports = { + + up: (queryInterface, Sequelize) => { + + return queryInterface.sequelize.query("ALTER TABLE \"RealEstateRequests\" ADD COLUMN bounding_box geometry(Polygon);").then(([results, metadata]) => { + /// No result + }) + }, + + down: (queryInterface, Sequelize) => { + return queryInterface.sequelize.query("ALTER TABLE \"RealEstateRequests\" DROP COLUMN bounding_box").then(([results, metadata]) => { + /// No result + }) + } +}; \ No newline at end of file diff --git a/app/models/realestaterequest.js b/app/models/realestaterequest.js index 4f48367..37997c6 100644 --- a/app/models/realestaterequest.js +++ b/app/models/realestaterequest.js @@ -15,6 +15,7 @@ module.exports = (sequelize, DataTypes) => { size: DataTypes.STRING, gardenSize: DataTypes.STRING, price: DataTypes.STRING, + bounding_box: DataTypes.GEOMETRY('POINT', 4326) }, {}); RealEstateRequest.associate = function(models) { // associations can be defined here diff --git a/app/public/main.css b/app/public/main.css index 5653fe5..046958b 100644 --- a/app/public/main.css +++ b/app/public/main.css @@ -9,3 +9,28 @@ background-repeat: no-repeat; color: rgba(0, 0, 0, 0); } + + +#map { + height: 50%; +} + +html, +body { + height: 100%; + margin: 0; + padding: 0; +} + +#floating-panel { + top: 10px; + left: 25%; + z-index: 5; + background-color: #fff; + padding: 5px; + border: 1px solid #999; + text-align: center; + font-family: 'Roboto', 'sans-serif'; + line-height: 30px; + padding-left: 10px; +} diff --git a/app/views/municipality.ejs b/app/views/municipality.ejs index 84cda22..e151451 100644 --- a/app/views/municipality.ejs +++ b/app/views/municipality.ejs @@ -8,7 +8,7 @@