diff --git a/routes/broadcasts.js b/routes/broadcasts.js index 8106adf..b5eb76c 100644 --- a/routes/broadcasts.js +++ b/routes/broadcasts.js @@ -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 diff --git a/views/broadcastDetail.jade b/views/broadcastDetail.jade new file mode 100644 index 0000000..d006c6b --- /dev/null +++ b/views/broadcastDetail.jade @@ -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 \ No newline at end of file