Started adding timezone support
This commit is contained in:
parent
33e075ecdc
commit
478237e60f
14 changed files with 191 additions and 9 deletions
|
@ -21,10 +21,10 @@ let db = mysql.createPool(mysqlConfig);
|
|||
function listTables(callback) {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
if(err.code === 'ER_ACCESS_DENIED_ERROR'){
|
||||
if (err.code === 'ER_ACCESS_DENIED_ERROR') {
|
||||
err = new Error('Could not access the database. Check MySQL config and authentication credentials');
|
||||
}
|
||||
if(err.code === 'ECONNREFUSED' || err.code === 'PROTOCOL_SEQUENCE_TIMEOUT'){
|
||||
if (err.code === 'ECONNREFUSED' || err.code === 'PROTOCOL_SEQUENCE_TIMEOUT') {
|
||||
err = new Error('Could not connect to the database. Check MySQL host and port configuration');
|
||||
}
|
||||
return callback(err);
|
||||
|
|
|
@ -230,7 +230,7 @@ module.exports.insert = (listId, meta, subscription, callback) => {
|
|||
let keys = [];
|
||||
let values = [];
|
||||
|
||||
let allowedKeys = ['first_name', 'last_name'];
|
||||
let allowedKeys = ['first_name', 'last_name', 'tz'];
|
||||
Object.keys(subscription).forEach(key => {
|
||||
let value = subscription[key];
|
||||
key = tools.toDbKey(key);
|
||||
|
@ -392,7 +392,8 @@ module.exports.getWithMergeTags = (listId, cid, callback) => {
|
|||
EMAIL: subscription.email,
|
||||
FIRST_NAME: subscription.firstName,
|
||||
LAST_NAME: subscription.lastName,
|
||||
FULL_NAME: [].concat(subscription.firstName || []).concat(subscription.lastName || []).join(' ')
|
||||
FULL_NAME: [].concat(subscription.firstName || []).concat(subscription.lastName || []).join(' '),
|
||||
TIMEZONE: subscription.tz || ''
|
||||
};
|
||||
|
||||
fields.getRow(fieldList, subscription, true, true).forEach(field => {
|
||||
|
@ -433,7 +434,7 @@ module.exports.update = (listId, cid, updates, allowEmail, callback) => {
|
|||
return callback(err);
|
||||
}
|
||||
|
||||
let allowedKeys = ['first_name', 'last_name'];
|
||||
let allowedKeys = ['first_name', 'last_name', 'tz'];
|
||||
|
||||
if (allowEmail) {
|
||||
allowedKeys.unshift('email');
|
||||
|
|
147
lib/tz.js
Normal file
147
lib/tz.js
Normal file
|
@ -0,0 +1,147 @@
|
|||
'use strict';
|
||||
|
||||
module.exports.list = [
|
||||
'Pacific/Midway',
|
||||
'Pacific/Samoa',
|
||||
'Pacific/Honolulu',
|
||||
'US/Alaska',
|
||||
'America/Los_Angeles',
|
||||
'America/Tijuana',
|
||||
'US/Arizona',
|
||||
'America/Chihuahua',
|
||||
'America/Chihuahua',
|
||||
'America/Mazatlan',
|
||||
'US/Mountain',
|
||||
'America/Managua',
|
||||
'US/Central',
|
||||
'America/Mexico_City',
|
||||
'America/Mexico_City',
|
||||
'America/Monterrey',
|
||||
'Canada/Saskatchewan',
|
||||
'America/Bogota',
|
||||
'US/Eastern',
|
||||
'US/East-Indiana',
|
||||
'America/Lima',
|
||||
'America/Bogota',
|
||||
'Canada/Atlantic',
|
||||
'America/Caracas',
|
||||
'America/La_Paz',
|
||||
'America/Santiago',
|
||||
'Canada/Newfoundland',
|
||||
'America/Sao_Paulo',
|
||||
'America/Argentina/Buenos_Aires',
|
||||
'America/Argentina/Buenos_Aires',
|
||||
'America/Godthab',
|
||||
'America/Noronha',
|
||||
'Atlantic/Azores',
|
||||
'Atlantic/Cape_Verde',
|
||||
'Africa/Casablanca',
|
||||
'Europe/London',
|
||||
'Etc/Greenwich',
|
||||
'Europe/Lisbon',
|
||||
'Europe/London',
|
||||
'Africa/Monrovia',
|
||||
'UTC',
|
||||
'Europe/Amsterdam',
|
||||
'Europe/Belgrade',
|
||||
'Europe/Berlin',
|
||||
'Europe/Berlin',
|
||||
'Europe/Bratislava',
|
||||
'Europe/Brussels',
|
||||
'Europe/Budapest',
|
||||
'Europe/Copenhagen',
|
||||
'Europe/Ljubljana',
|
||||
'Europe/Madrid',
|
||||
'Europe/Paris',
|
||||
'Europe/Prague',
|
||||
'Europe/Rome',
|
||||
'Europe/Sarajevo',
|
||||
'Europe/Skopje',
|
||||
'Europe/Stockholm',
|
||||
'Europe/Vienna',
|
||||
'Europe/Warsaw',
|
||||
'Africa/Lagos',
|
||||
'Europe/Zagreb',
|
||||
'Europe/Athens',
|
||||
'Europe/Bucharest',
|
||||
'Africa/Cairo',
|
||||
'Africa/Harare',
|
||||
'Europe/Helsinki',
|
||||
'Europe/Istanbul',
|
||||
'Asia/Jerusalem',
|
||||
'Europe/Helsinki',
|
||||
'Africa/Johannesburg',
|
||||
'Europe/Riga',
|
||||
'Europe/Sofia',
|
||||
'Europe/Tallinn',
|
||||
'Europe/Vilnius',
|
||||
'Asia/Baghdad',
|
||||
'Asia/Kuwait',
|
||||
'Europe/Minsk',
|
||||
'Africa/Nairobi',
|
||||
'Asia/Riyadh',
|
||||
'Europe/Volgograd',
|
||||
'Asia/Tehran',
|
||||
'Asia/Muscat',
|
||||
'Asia/Baku',
|
||||
'Europe/Moscow',
|
||||
'Asia/Muscat',
|
||||
'Europe/Moscow',
|
||||
'Asia/Tbilisi',
|
||||
'Asia/Yerevan',
|
||||
'Asia/Kabul',
|
||||
'Asia/Karachi',
|
||||
'Asia/Karachi',
|
||||
'Asia/Tashkent',
|
||||
'Asia/Calcutta',
|
||||
'Asia/Kolkata',
|
||||
'Asia/Calcutta',
|
||||
'Asia/Calcutta',
|
||||
'Asia/Calcutta',
|
||||
'Asia/Katmandu',
|
||||
'Asia/Almaty',
|
||||
'Asia/Dhaka',
|
||||
'Asia/Dhaka',
|
||||
'Asia/Yekaterinburg',
|
||||
'Asia/Rangoon',
|
||||
'Asia/Bangkok',
|
||||
'Asia/Bangkok',
|
||||
'Asia/Jakarta',
|
||||
'Asia/Novosibirsk',
|
||||
'Asia/Hong_Kong',
|
||||
'Asia/Chongqing',
|
||||
'Asia/Hong_Kong',
|
||||
'Asia/Krasnoyarsk',
|
||||
'Asia/Kuala_Lumpur',
|
||||
'Australia/Perth',
|
||||
'Asia/Singapore',
|
||||
'Asia/Taipei',
|
||||
'Asia/Ulan_Bator',
|
||||
'Asia/Urumqi',
|
||||
'Asia/Irkutsk',
|
||||
'Asia/Tokyo',
|
||||
'Asia/Tokyo',
|
||||
'Asia/Seoul',
|
||||
'Asia/Tokyo',
|
||||
'Australia/Adelaide',
|
||||
'Australia/Darwin',
|
||||
'Australia/Brisbane',
|
||||
'Australia/Canberra',
|
||||
'Pacific/Guam',
|
||||
'Australia/Hobart',
|
||||
'Australia/Melbourne',
|
||||
'Pacific/Port_Moresby',
|
||||
'Australia/Sydney',
|
||||
'Asia/Yakutsk',
|
||||
'Asia/Vladivostok',
|
||||
'Pacific/Auckland',
|
||||
'Pacific/Fiji',
|
||||
'Pacific/Kwajalein',
|
||||
'Asia/Kamchatka',
|
||||
'Asia/Magadan',
|
||||
'Pacific/Fiji',
|
||||
'Asia/Magadan',
|
||||
'Asia/Magadan',
|
||||
'Pacific/Auckland',
|
||||
'Pacific/Tongatapu'
|
||||
];
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"schemaVersion": 4
|
||||
"schemaVersion": 5
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* eslint-env browser */
|
||||
/* eslint prefer-arrow-callback: 0, object-shorthand: 0, new-cap: 0, no-invalid-this: 0, no-var: 0*/
|
||||
/* globals $: false, moment: false */
|
||||
/* globals $: false, moment: false, jstz: false */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -125,3 +125,13 @@ $('.page-refresh').each(function () {
|
|||
window.location.reload();
|
||||
}, interval * 1000);
|
||||
});
|
||||
|
||||
if (typeof jstz !== 'undefined') {
|
||||
(function () {
|
||||
var tz = jstz.determine();
|
||||
var tzname = tz && tz.name() || false;
|
||||
if (tzname) {
|
||||
$('.tz-detect').val(tzname);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
|
2
public/jstimezonedetect/jstz.min.js
vendored
Normal file
2
public/jstimezonedetect/jstz.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -548,7 +548,7 @@ router.post('/subscription/import-confirm', passport.parseForm, passport.csrfPro
|
|||
fieldList = [];
|
||||
}
|
||||
|
||||
let allowedColumns = ['email', 'first_name', 'last_name'];
|
||||
let allowedColumns = ['email', 'first_name', 'last_name', 'tz'];
|
||||
fieldList.forEach(field => {
|
||||
if (field.column) {
|
||||
allowedColumns.push(field.column);
|
||||
|
|
|
@ -13,6 +13,7 @@ let fields = require('../lib/models/fields');
|
|||
let subscriptions = require('../lib/models/subscriptions');
|
||||
let settings = require('../lib/models/settings');
|
||||
let openpgp = require('openpgp');
|
||||
let tzlist = require('../lib/tz').list;
|
||||
|
||||
router.get('/subscribe/:cid', (req, res, next) => {
|
||||
subscriptions.subscribe(req.params.cid, req.ip, (err, subscription) => {
|
||||
|
|
17
setup/sql/upgrade-00005.sql
Normal file
17
setup/sql/upgrade-00005.sql
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Header section
|
||||
# Define incrementing schema version number
|
||||
SET @schema_version = '5';
|
||||
|
||||
-- {{#each tables.subscription}}
|
||||
|
||||
# Adds new column 'tz' to subscriptions table
|
||||
# Indicates subscriber time zone, use UTC as default
|
||||
ALTER TABLE `{{this}}` ADD COLUMN `tz` varchar(100) CHARACTER SET ascii DEFAULT NULL AFTER `opt_in_country`;
|
||||
CREATE INDEX subscriber_tz ON `{{this}}` (`tz`);
|
||||
|
||||
-- {{/each}}
|
||||
|
||||
# Footer section
|
||||
LOCK TABLES `settings` WRITE;
|
||||
INSERT INTO `settings` (`key`, `value`) VALUES('db_schema_version', @schema_version) ON DUPLICATE KEY UPDATE `value`=@schema_version;
|
||||
UNLOCK TABLES;
|
|
@ -1,6 +1,6 @@
|
|||
# This file is a handlebars template
|
||||
# To modify several similar tables at once use (replace [] with {}):
|
||||
# [[#each tablename]] ALTER TABLE `[[this]]` ... [[/each]]
|
||||
# [[#each tables.tablename]] ALTER TABLE `[[this]]` ... [[/each]]
|
||||
# NB! as this is a handlebars file, then remember to escape any template sequences
|
||||
|
||||
# Header section
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<option value="email">Email address</option>
|
||||
<option value="first_name">First Name</option>
|
||||
<option value="last_name">Last Name</option>
|
||||
<option value="tz">Timezone</option>
|
||||
{{#each ../customFields}}
|
||||
{{#if column}}
|
||||
<option value="{{column}}">{{name}}</option>
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
<script src="/datepicker/js/bootstrap-datepicker.min.js"></script>
|
||||
<script src="/datatables/datatables.min.js"></script>
|
||||
<script src="/moment/moment.min.js"></script>
|
||||
<script src="/jstimezonedetect/jstz.min.js"></script>
|
||||
<script src="/javascript/tables.js"></script>
|
||||
|
||||
{{#if useEditor}}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
<input type="hidden" name="_csrf" value="{{csrfToken}}">
|
||||
<input type="hidden" name="cid" value="{{cid}}">
|
||||
<input type="hidden" class="tz-detect" name="tz" id="tz" value="{{tz}}">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email address</label>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<form method="post" action="/subscription/{{cid}}/subscribe">
|
||||
|
||||
<input type="hidden" name="_csrf" value="{{csrfToken}}">
|
||||
<input type="hidden" class="tz-detect" name="tz" id="tz" value="{{tz}}">
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email address</label>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue