Skip to content

Commit

Permalink
Merge pull request #34 from jekram/sania
Browse files Browse the repository at this point in the history
  • Loading branch information
saniasiddiqui authored Dec 7, 2017
2 parents 9a4a884 + 9afbbbc commit d11d37b
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 94 deletions.
11 changes: 5 additions & 6 deletions public/javascripts/slide-panel.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
$(document).ready(function(){
$('#opener').on('click', function() {
$('#opener').on('click', function() {
var panel = $('#slide-panel');
if (panel.hasClass("visible")) {
panel.removeClass('visible').animate({'margin-left':'-300px'});
$('#mycontent').css({'margin-right':'0px'});
} else {panel.addClass('visible').animate({'margin-left':'0px'});
$('#mycontent').css({'margin-right':'-300px'});
}
return false;
$('#divInformation').css({'margin-right':'0px', 'float': 'none'});
}
return false;
});
});
});
14 changes: 14 additions & 0 deletions public/js/workflows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var onEnable = function (id, isActive) {
console.log()
var data = { 'id': id, 'isActive': isActive }
$.ajax({
type: 'POST',
data: data,
url: 'http://localhost:3000/workflows/enable',
success: function (data) {
console.log(data)
var location = window.location
location.reload()
}
})
}
10 changes: 7 additions & 3 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ font-size :20px;
margin-left:-300px;
float: left;
max-width: 300px;
position: fixed;
}
#nav ul{
list-style: none;
Expand Down Expand Up @@ -189,18 +190,21 @@ font-family: "Century Gothic"
#main > h1 {
text-align: center;
}
#main > #divCredential,#divInformation {
#divInformation {
padding: 30px 25px 10px 25px;
}
#main > #successMessage {
#divCredential {
padding: 30px 25px 10px 25px;
}
#successMessage {
margin: 25px;
padding: 20px;
opacity: 1;
color: #3c763d;
background-color: #dff0d8;
border-color: #d6e9c6
}
#main > #infoMessage {
#infoMessage {
color: #31708f;
margin: 25px;
background-color: #d9edf7;
Expand Down
99 changes: 99 additions & 0 deletions routes/polls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@ router.get('/polls', function (req, res, next) {
}
request.get(options, callback)
})
router.get('/newPoll', function (req, res, next) {
console.log(req.session.kiboappid)
console.log(req.session.kiboappsecret)

var url = 'https://staging.kibopush.com/api/pages/allpages'
var options = getOptions(req, url)
function callback (error, response, body) {
if (!error && response.statusCode === 200) {
console.log('Response-Parse', JSON.parse(response.body))
var info = JSON.parse(response.body)
var pages = info.payload
var pageArray = []
for (var i = 0; i < pages.length; i++) {
var object = {id: pages[i]._id, name: pages[i].pageName}
pageArray.push(object)
}
console.log(pageArray)
res.render('newPoll', {title: 'New Poll', pages: pageArray})
} else {
error = JSON.parse(response.body)
res.send(error)
}
}
request(options, callback)
})

router.get('/polls/:id', function (req, res, next) {
var id = req.params.id
Expand All @@ -49,6 +74,80 @@ router.get('/polls/:id', function (req, res, next) {
request.get(options, callback)
})

router.post('/polls/sendPoll', function (req, res, next) {
console.log(req.body.sendPollButton)
var id = req.body.sendPollButton
var poll = JSON.parse(req.body[id])
var body = {id: poll._id, statement: poll.statement, options: poll.options, isSegemented: poll.isSegemented, segmentationPageIds: poll.segmentationPageIds, segmentationGender: poll.segmentationGender, segmentationLocale: poll.segmentationLocale}
console.log(body)
headers = {
'app_id': req.session.kiboappid,
'app_secret': req.session.kiboappsecret,
'content-type': 'application/json'
}
var options = {
url: 'https://staging.kibopush.com/api/polls/send',
headers: headers,
rejectUnauthorized: false,
body: body,
json: true
}
console.log(options)
function callback (error, response, body) {
console.log('Response-Body', body)
if (body.status === 'success') {
console.log('Response-Parse', body)
res.redirect('/polls')
} else {
console.log('error', body)
error = body
res.send(body)
}
}
request.post(options, callback)
})

router.post('/polls/createPoll', function (req, res, next) {
var statement = req.body.reply
var response1 = req.body.responseOne
var response2 = req.body.responseTwo
var response3 = req.body.responseThree
var options = []
options.push(response1)
options.push(response2)
options.push(response3)
var segmentationPageIds = (req.body.pages).split(',')
var segmentationGender = (req.body.gender).split(',')
var segmentationLocale = (req.body.locale).split(',')
var isSegemented = false
var body = {statement: statement, options: options, isSegemented: isSegemented, segmentationPageIds: segmentationPageIds, segmentationGender: segmentationGender, segmentationLocale: segmentationLocale}
console.log(body)
headers = {
'app_id': req.session.kiboappid,
'app_secret': req.session.kiboappsecret,
'content-type': 'application/json'
}
options = {
url: 'https://staging.kibopush.com/api/polls/create',
headers: headers,
rejectUnauthorized: false,
body: body,
json: true
}
console.log(options)
function callback (error, response, body) {
console.log('Response-Body', body)
if (body.status === 'success') {
console.log('Response-Parse', body)
res.send(body.payload)
} else {
console.log('error', body)
error = body
res.send(body)
}
}
request.post(options, callback)
})
function getOptions (req, url) {
headers = {
'app_id': req.session.kiboappid,
Expand Down
76 changes: 76 additions & 0 deletions routes/workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,81 @@ router.get('/workflows', function (req, res, next) {
}
request.get(options, callback)
})
router.post('/workflows/createWorkflow', function (req, res, next) {
var rule = req.body.rule
var keywords = (req.body.keywords).split(',')
var reply = req.body.reply
var isActive = req.body.isActive
var body = {condition: rule, keywords: keywords, reply: reply, isActive: isActive}
console.log(body)
headers = {
'app_id': req.session.kiboappid,
'app_secret': req.session.kiboappsecret,
'content-type': 'application/json'
}
var options = {
url: 'https://staging.kibopush.com/api/workflows/create',
headers: headers,
rejectUnauthorized: false,
body: body,
json: true
}
console.log(options)
function callback (error, response, body) {
console.log('Response-Body', body)
if (body.status === 'success') {
console.log('Response-Parse', body)
res.redirect('/workflows')
} else {
console.log('error', body)
error = body
res.send(body)
}
}
request.post(options, callback)
})
router.get('/newWorkflow', function (req, res, next) {
res.render('createWorkflow', { title: 'Create Workflow' })
})

router.post('/workflows/enable', function (req, res, next) {
console.log(req.session.kiboappid)
console.log(req.session.kiboappsecret)
var id = req.body.id
var isActive = req.body.isActive
var url
if (isActive === 'true') {
url = 'https://staging.kibopush.com/api/workflows/disable'
} else {
url = 'https://staging.kibopush.com/api/workflows/enable'
}
console.log(url, isActive)
headers = {
'app_id': req.session.kiboappid,
'app_secret': req.session.kiboappsecret,
'content-type': 'application/json'
}

var options = {
url: url,
headers: headers,
rejectUnauthorized: false,
body: {_id: id},
json: true
}

function callback (error, response, body) {
console.log('Response-Body', body)
if (!error && response.statusCode === 200) {
console.log('Response-Parse', body)
res.send(body)
} else {
console.log('error', body)
error = body
res.send(body)
}
}
request.post(options, callback)
})

module.exports = router
14 changes: 4 additions & 10 deletions views/broadcasts.jade
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ block div#content
| Search :

input(type="search" class="light-table-filter form-control input-medium input-inline" data-table="broadcasts" placeholder="Enter search term")
div#divDatadiv.table-scrollable
div.table-scrollable
table(class = "table table-striped table-bordered table-hover broadcasts")
thead
tr
Expand All @@ -32,9 +32,6 @@ block div#content
td
span
|FileUrl
td
span
|Payload

tbody
if(broadcasts)
Expand All @@ -52,7 +49,8 @@ block div#content
td=object.text
td=object.fileurl
td=object.attachmentType
td
tr
td(colspan = 10)
ul
- each option in object.payload
li=JSON.stringify(option)
Expand All @@ -67,14 +65,11 @@ block div#content
tr
td(colspan = 8,style = "text-align:center;")="No poll record found. " + error.description

div#divDatadiv.table-scrollable
div.table-scrollable
h3= 'Broadcast Pages'
table(class = "table table-striped table-bordered table-hover broadcastpages")
thead
tr
td
span
|Id
td
span
|Page Id
Expand Down Expand Up @@ -103,7 +98,6 @@ block div#content
if (broadcastpages.lengh != 0)
- each object in broadcastpages
tr
td=object._id
td=object.pageId
td=object.userId
td=object.broadcastId
Expand Down
41 changes: 41 additions & 0 deletions views/createWorkflow.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
extends sidebar
block div#content
div#divInformation
h1
#{title}
form(action="/workflows/createWorkflow",method="post")
table(class = "table table-striped table-bordered table-hover")
tbody
tr
td
label
| Rule
td
select(name='rule' class='form-control' required)
option(value='message_is') Message Is
option(value='message_contains') Message Contains
option(value='message_begins') Message Begins With
tr
td
label
| Keywords(separated with commas)
td
input(type="text" name ="keywords" class="form-control input-medium input-inline" placeholder="hi,hello,ok " required)
tr
td
label
| Reply
td
textarea(name ="reply" class="form-control input-medium input-inline" required)
tr
td
label
| Is Active
td
select(name='isActive' class='form-control' required)
option(value='Yes') Yes
option(value='No') No
tr
td(colspan="2")
button(class = "btn btn-info" type="submit")
| Submit
Loading

0 comments on commit d11d37b

Please sign in to comment.