Skip to content

Commit

Permalink
Merge pull request #32 from jekram/baqar
Browse files Browse the repository at this point in the history
added /broadcasts/:id
  • Loading branch information
saniasiddiqui authored Dec 7, 2017
2 parents 4bc4a53 + bd23ec9 commit 9a4a884
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
61 changes: 61 additions & 0 deletions routes/broadcasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,65 @@ router.get('/broadcasts', function (req, res, next) {
request.get(options, callback)
})




router.get('/broadcasts/download', function (req, res, next) {
let url = `https://staging.kibopush.com/api/broadcasts/download`
console.log('download', url)
let options = getOptions(req, url)
function callback (error, response, body) {
console.log('Response-Body', response.body)
if (!error && response.statusCode === 200) {
console.log('Response-Parse', JSON.parse(response.body))
var info = JSON.parse(response.body)
// var broadcast = info.payload
// res.render('broadcastDetail', { title: 'Broadcast Details', broadcast: broadcast })
} else {
error = JSON.parse(response.body)
console.log(error)
//res.render('broadcastDetail', { title: 'Broadcast Details', broadcasts: broadcasts, error: error })
}
}
request.get(options, callback)
})




router.get('/broadcasts/:id', function (req, res, next) {
let id = req.params.id
let url = `https://staging.kibopush.com/api/broadcasts/${id}`
console.log(url)
let options = getOptions(req, url)
function callback (error, response, body) {
console.log('Response-Body', response.body)
if (!error && response.statusCode === 200) {
console.log('Response-Parse', JSON.parse(response.body))
var info = JSON.parse(response.body)
var broadcast = info.payload
res.render('broadcastDetail', { title: 'Broadcast Details', broadcast: broadcast })
} else {
error = JSON.parse(response.body)
console.log(error)
res.render('broadcastDetail', { title: 'Broadcast Details', broadcasts: broadcasts, error: error })
}
}
request.get(options, callback)
})

function getOptions (req, url) {
headers = {
'app_id': req.session.kiboappid,
'app_secret': req.session.kiboappsecret,
'content-type': 'application/json'
}
var options = {
url: url,
headers: headers,
rejectUnauthorized: false
}
return options
}

module.exports = router
50 changes: 50 additions & 0 deletions views/broadcastDetail.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
extends sidebar
block div#content
div#divInformation
h1= title
div(class = "control-group span6")
label
| 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
table(class = "table table-striped table-bordered table-hover broadcasts")
thead
tr
td
span
|Id
td
span
|Platform
td
span
|Title
td
span
|Date
td
span
|Payload

tbody
if(broadcast)
form(action="/downloadcsv",method="post")
- var dd=JSON.stringify(broadcast)
input(type="hidden" name ="dd" value = dd)
tr
td=broadcast._id
td=broadcast.platform
td=broadcast.title
td=broadcast.datetime
td
ul
- each option in broadcast.payload
li=JSON.stringify(option)
tr
td(colspan = 10,style = "text-align:right;")
button(class = "downloadcsv btn btn-info" type="submit")
|Export Record in CSV
else
tr
td(colspan = 8,style = "text-align:center;")="No broadcast record found. " + error.description

0 comments on commit 9a4a884

Please sign in to comment.