Navigation Menu

Skip to content

Commit

Permalink
ATLAS-168: Notify users when their marker is fading
Browse files Browse the repository at this point in the history
  • Loading branch information
HelioStrike committed Jul 20, 2019
1 parent a378be6 commit d77bfb2
Show file tree
Hide file tree
Showing 14 changed files with 428 additions and 29 deletions.
11 changes: 11 additions & 0 deletions conf.example.js
Expand Up @@ -18,4 +18,15 @@ module.exports = {
"rdn": "cn",
}
},
"smtp": {
"host": process.env.MAIL_HOST || "localhost",
"port": process.env.MAIL_PORT || 1025,
"use_authentication": Boolean(process.env.MAIL_AUTH),
"auth": {
"user": process.env.MAIL_USER || "postfix_user",
"pass": process.env.MAIL_PASS || "secret",
},
"logger": Boolean(process.env.MAIL_LOGGING), // log to console
"debug": Boolean(process.env.LOG_SMTP_TRAFFIC) // include SMTP traffic in the logs
},
};
34 changes: 34 additions & 0 deletions db/01_database.sql
Expand Up @@ -184,6 +184,40 @@ CREATE TABLE `rss` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `notifications`
--

DROP TABLE IF EXISTS `notifications`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `notifications` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`marker_id` varchar(38) COLLATE utf8_unicode_ci NOT NULL,
`principal` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`notified_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`marker_id`) REFERENCES `atlas`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `unsubscribed`
--

DROP TABLE IF EXISTS `unsubscribed`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unsubscribed` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`marker_id` varchar(38) COLLATE utf8_unicode_ci NOT NULL,
`principal` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `marker_principal_unique` (`marker_id`,`principal`),
CONSTRAINT `unsubscribed_marker_id_foreign` FOREIGN KEY (`marker_id`) REFERENCES `atlas`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
Expand Down
34 changes: 34 additions & 0 deletions db/02_updates.sql
Expand Up @@ -148,6 +148,40 @@ CREATE TABLE `rss` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `notifications`
--

DROP TABLE IF EXISTS `notifications`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `notifications` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`marker_id` varchar(38) COLLATE utf8_unicode_ci NOT NULL,
`principal` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`notified_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`marker_id`) REFERENCES `atlas`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `unsubscribed`
--

DROP TABLE IF EXISTS `unsubscribed`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `unsubscribed` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`marker_id` varchar(38) COLLATE utf8_unicode_ci NOT NULL,
`principal` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `marker_principal_unique` (`marker_id`,`principal`),
CONSTRAINT `unsubscribed_marker_id_foreign` FOREIGN KEY (`marker_id`) REFERENCES `atlas`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
Expand Down
30 changes: 30 additions & 0 deletions db/notificationstable.sql
@@ -0,0 +1,30 @@
-- MySQL dump 10.13 Distrib 5.6.39, for Linux (x86_64)
--
-- Host: localhost Database: atlasdb
-- ------------------------------------------------------
-- Server version 5.6.39

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;



/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2018-04-08 7:53:27
66 changes: 64 additions & 2 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -24,6 +24,8 @@
"morgan": "^1.9.1",
"mysql": "^2.17.1",
"negotiator": "^0.6.2",
"node-schedule": "^1.3.2",
"nodemailer": "^6.2.1",
"request": "^2.72.0",
"rss": "^1.2.2",
"serve-favicon": "^2.5.0",
Expand Down
26 changes: 24 additions & 2 deletions public/js/atlas.js
Expand Up @@ -240,15 +240,37 @@ function fetchMarkerSites() {
.always(function (authrules, textStatus) {
loadSites(data, authrules);
var marker_id = document.getElementById('marker-id').value;
if(marker_id != "" && sites[marker_id]) {
var update_marker = document.getElementById('update-marker').value;
var delete_marker = document.getElementById('delete-marker').value;
var subscribe_marker = document.getElementById('subscribe-marker').value;
var unsubscribe_marker = document.getElementById('unsubscribe-marker').value;

if(isValidMarkerId(marker_id) && sites[marker_id]) {
sites[marker_id].infowindow.open(map, sites[marker_id].marker);
google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
google.maps.event.addListenerOnce(map, 'tilesloaded', function(){
map.setZoom(8);
map.setCenter(sites[marker_id].marker.getPosition());
});
});
}
}

if(isValidMarkerId(update_marker) && sites[update_marker]) {
updateMarker(update_marker);
}

if(isValidMarkerId(delete_marker) && sites[delete_marker]) {
deleteMarker(delete_marker);
}

if(isValidMarkerId(subscribe_marker) && sites[subscribe_marker]) {
subscribeMarker(subscribe_marker);
}

if(isValidMarkerId(unsubscribe_marker) && sites[unsubscribe_marker]) {
unsubscribeMarker(unsubscribe_marker);
}

});
})
}
Expand Down
41 changes: 35 additions & 6 deletions public/js/user.js
Expand Up @@ -110,7 +110,7 @@ function createSite() {
closeBubbles();
myPosition = map.getCenter();
var image = {
url: "https://maps.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png",
url: "http://maps.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png",
scaledSize: new google.maps.Size(32, 32)
};
var marker = new google.maps.Marker({
Expand Down Expand Up @@ -147,9 +147,6 @@ function newSite(myPosition) {
contact: userName,
created_by: currentUser,
name: userName + " Site",
patients: 0,
encounters: 0,
observations: 0,
email: userEmail,
show_counts: 1,
notes: "",
Expand Down Expand Up @@ -208,7 +205,7 @@ function deleteMarker(site) {
}
if (auth_site.length === 0)
$("#editSite").attr("hidden", true);
}
}

function createEditInfoWindow(site, marker) {
var html = contentEditwindow(site);
Expand Down Expand Up @@ -339,7 +336,7 @@ function saveMarker(e) {
sites[nid].siteData.date_changed = response.date_changed;
sites[nid].siteData.image_url = response.image_url;
delete sites[nid].siteData.image;
sites[nid].fadeGroup = 0;
console.log(sites[nid].siteData);

sites[nid].infowindow.setContent(contentInfowindow(sites[nid].siteData));
sites[nid].editwindow.setContent(contentEditwindow(sites[nid].siteData));
Expand Down Expand Up @@ -402,6 +399,38 @@ function updateMarker(id) {
});
}

function subscribeMarker(id) {
var json = JSON.stringify({ marker_id: id });
$.ajax({
url: "/subscriptions",
type: "POST",
data: json,
dataType: "json",
processData: false,
contentType: "application/json",
})
.done(function(response) {
bootbox.alert({ message: "Subscribed for marker updates!", backdrop: true });
})
.fail(function(jqXHR, textStatus, errorThrown) {
bootbox.alert({ message: "Error subscribing for marker updates - Please try again ! - " + jqXHR.statusText, backdrop: true });
});
}

function unsubscribeMarker(id) {
$.ajax({
url: "/subscriptions/"+id,
type: "DELETE",
dataType: "json",
})
.done(function(response) {
bootbox.alert({ message: "Unsubscribed for marker updates!", backdrop: true });
})
.fail(function(jqXHR, textStatus, errorThrown) {
bootbox.alert({ message: "Error Unsubscribing for marker updates - Please try again ! - " + jqXHR.statusText, backdrop: true });
});
}

function addCoOwner(e) {
e.preventDefault();
var atlas_id = $("#site").val();
Expand Down
10 changes: 9 additions & 1 deletion routes/default.js
Expand Up @@ -6,13 +6,21 @@ module.exports = function(){
router.get('/', function(req, res, next) {

var marker_id = req.query['marker'];
var update_marker = req.query['update'];
var delete_marker = req.query['delete'];
var subscribe_marker = req.query['subscribe'];
var unsubscribe_marker = req.query['unsubscribe'];

var options = {
title: 'OpenMRS Atlas',
isAuth: req.session,
user: req.session.user,
google_maps_api_key: process.env.GOOGLE_MAPS_JS_API_KEY || 'NO_API',
marker_id: marker_id
marker_id: marker_id,
update_marker: update_marker,
delete_marker: delete_marker,
subscribe_marker: subscribe_marker,
unsubscribe_marker: unsubscribe_marker
};
res.render('index', options);

Expand Down

0 comments on commit d77bfb2

Please sign in to comment.