Added links click count stats to campaign view

This commit is contained in:
Andris Reinman 2016-05-05 14:34:54 +03:00
parent 84869dafa7
commit 09de6e4576
5 changed files with 396 additions and 245 deletions

View file

@ -177,6 +177,8 @@ module.exports.get = (id, withSegment, callback) => {
let campaign = tools.convertKeys(rows[0]);
let handleSegment = () => {
if (!campaign.segment || !withSegment) {
return callback(null, campaign);
} else {
@ -196,8 +198,66 @@ module.exports.get = (id, withSegment, callback) => {
});
});
}
};
if (!campaign.parent) {
return handleSegment();
}
db.getConnection((err, connection) => {
if (err) {
return callback(err);
}
connection.query('SELECT `id`, `cid`, `name` FROM campaigns WHERE id=?', [campaign.parent], (err, rows) => {
connection.release();
if (err) {
return callback(err);
}
if (!rows || !rows.length) {
return handleSegment();
}
campaign.parent = tools.convertKeys(rows[0]);
return handleSegment();
});
});
});
});
};
module.exports.getLinks = (id, callback) => {
id = Number(id) || 0;
if (id < 1) {
return callback(new Error('Missing Campaign ID'));
}
db.getConnection((err, connection) => {
if (err) {
return callback(err);
}
let query = 'SELECT `id`, `url`, `clicks` FROM links WHERE `campaign`=? LIMIT 1000';
connection.query(query, [id], (err, rows) => {
connection.release();
if (err) {
return callback(err);
}
if (!rows || !rows.length) {
return callback(null, []);
}
let links = rows.map(
row => tools.convertKeys(row)
).sort((a, b) => (
a.url.replace(/^https?:\/\/(www.)?/, '').toLowerCase()).localeCompare(b.url.replace(/^https?:\/\/(www.)?/, '').toLowerCase()));
return callback(null, links);
});
});
};
module.exports.create = (campaign, opts, callback) => {

View file

@ -271,8 +271,20 @@ router.get('/view/:id', passport.csrfProtection, (req, res) => {
campaign.openRate = campaign.delivered ? Math.round((campaign.opened / campaign.delivered) * 100) : 0;
campaign.clicksRate = campaign.delivered ? Math.round((campaign.clicks / campaign.delivered) * 100) : 0;
campaigns.getLinks(campaign.id, (err, links) => {
if (err) {
// ignore
}
let index = 0;
campaign.links = (links || []).map(link => {
link.index = ++index;
return link;
});
campaign.showOverview = true;
res.render('campaigns/view', campaign);
});
});
});
});

View file

@ -1,6 +1,9 @@
<ol class="breadcrumb">
<li><a href="/">Home</a></li>
<li><a href="/campaigns">Campaigns</a></li>
{{#if parent}}
<li><a href="/campaigns/view/{{parent.id}}">{{parent.name}}</a></li>
{{/if}}
<li><a href="/campaigns/view/{{id}}">{{name}}</a></li>
<li class="active">Edit RSS Campaign</li>
</ol>

View file

@ -1,6 +1,9 @@
<ol class="breadcrumb">
<li><a href="/">Home</a></li>
<li><a href="/campaigns">Campaigns</a></li>
{{#if parent}}
<li><a href="/campaigns/view/{{parent.id}}">{{parent.name}}</a></li>
{{/if}}
<li><a href="/campaigns/view/{{id}}">{{name}}</a></li>
<li class="active">Edit Campaign</li>
</ol>

View file

@ -1,6 +1,9 @@
<ol class="breadcrumb">
<li><a href="/">Home</a></li>
<li><a href="/campaigns">Campaigns</a></li>
{{#if parent}}
<li><a href="/campaigns/view/{{parent.id}}">{{parent.name}}</a></li>
{{/if}}
<li class="active">{{name}}</li>
</ol>
@ -16,7 +19,20 @@
<div class="well well-sm">{{{description}}}</div>
{{/if}}
<dl class="dl-horizontal">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="{{#if showOverview}}active{{/if}}"><a href="#overview" aria-controls="overview" role="tab" data-toggle="tab">Overview</a></li>
{{#if links}}
<li role="presentation" class="{{#if showLinks}}active{{/if}}"><a href="#links" aria-controls="links" role="tab" data-toggle="tab">Links</a></li>
{{/if}}
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane {{#if showOverview}}active{{/if}}" id="overview">
<p></p>
<dl class="dl-horizontal">
<dt>List</dt>
<dd>
{{#if segment}}
@ -46,7 +62,7 @@
<dd>
{{#if lastCheck}}<span class="datestring" data-date="{{lastCheck}}" title="{{lastCheck}}">{{lastCheck}}</span>{{else}}
Not yet checked{{/if}}
{{#unless isActive}}<span class="text-muted">(feed is only checked if RSS campaign is active)</span>{{/unless}}
{{#unless isActive}}<span class="text-muted">(activate campaign to start checking feed for new messages)</span>{{/unless}}
</dd>
{{#if checkStatus}}
<dt>RSS status</dt>
@ -54,14 +70,20 @@
{{/if}}
{{/if}}
{{#if from}}
<dt>Email "from name"</dt>
<dd>{{from}}</dd>
{{/if}}
{{#if address}}
<dt>Email "from" address</dt>
<dd>{{address}}</dd>
{{/if}}
{{#if subject}}
<dt>Email "subject line"</dt>
<dd>{{subject}}</dd>
{{/if}}
{{#if isNormal}}
@ -98,9 +120,9 @@
{{/unless}}
{{/if}}
</dl>
</dl>
{{#if isNormal}}
{{#if isNormal}}
<div class="panel panel-default">
<div class="panel-body">
@ -201,9 +223,9 @@
</div>
</div>
{{/if}}
{{/if}}
{{#if isRss}}
{{#if isRss}}
<div class="panel panel-default">
<div class="panel-body">
@ -234,7 +256,58 @@
{{/if}}
</div>
</div>
{{/if}}
</div>
{{#if links}}
<div role="tabpanel" class="tab-pane {{#if showLinks}}active{{/if}}" id="links">
<p></p>
<div class="table-responsive">
<table class="table table-bordered table-hover">
<thead>
<th class="col-md-1">
#
</th>
<th>
URL
</th>
<th class="col-md-2">
Clicked
</th>
</thead>
<tbody>
{{#if links}}
{{#each links}}
<tr>
<td>
{{index}}
</td>
<td>
<a href="{{url}}">{{url}}</a>
</td>
<td>
{{clicks}}
</td>
</tr>
{{/each}}
{{else}}
<tr>
<td colspan="3">
No data available in table
</td>
</tr>
{{/if}}
</tbody>
</table>
</div>
</div>
{{/if}}
{{#if isRss}}
<div class="table-responsive">
<div class="well text-info">
If a new entry is found from campaign feed a new subcampaign is created of that entry and it will be listed here
@ -262,4 +335,4 @@
</thead>
</table>
</div>
{{/if}}
{{/if}}