Отображать уведомления в режиме реального времени через загрузчик-уведомление от JSON - PullRequest
0 голосов
/ 04 февраля 2019

У меня есть следующие данные (json):

{"version":"1.0","encoding":"UTF-8","feed":{"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns$gsx":"http://schemas.google.com/spreadsheets/2006/extended","id":{"$t":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values"},"updated":{"$t":"2019-02-04T08:34:17.350Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"info"},"link":[{"rel":"alternate","type":"application/atom+xml","href":"https://docs.google.com/spreadsheets/d/<ID>/pubhtml"},{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values"},{"rel":"http://schemas.google.com/g/2005#post","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values"},{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values?alt\u003djson"}],"author":[{"name":{"$t":"samantajohnny"},"email":{"$t":"samantajohnny@gmail.com"}}],"openSearch$totalResults":{"$t":"8"},"openSearch$startIndex":{"$t":"1"},"entry":[{"id":{"$t":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/cokwr"},"updated":{"$t":"2019-02-04T08:34:17.350Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"TAX INV 17-18"},"content":{"type":"text","$t":"modifiedday: Saturday, _d2mkx: 0"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/cokwr"}],"gsx$file":{"$t":"TAX INV 17-18"},"gsx$email":{"$t":""},"gsx$user":{"$t":""},"gsx$name":{"$t":""},"gsx$date":{"$t":""},"gsx$time":{"$t":""},"gsx$count":{"$t":""},"gsx$totalvalue":{"$t":""},"gsx$etc1":{"$t":""},"gsx$modifiedday":{"$t":"Saturday"},"gsx$_d2mkx":{"$t":"0"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/cpzh4"},"updated":{"$t":"2019-02-04T08:34:17.350Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"GST TAX INV 17-18"},"content":{"type":"text","$t":"user: samantajohnny, name: samantajohnny@gmail.com, date: 26-Jan-19, time: 05:22:57 PM, modifiedday: Saturday, _d2mkx: 1"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/cpzh4"}],"gsx$file":{"$t":"GST TAX INV 17-18"},"gsx$email":{"$t":""},"gsx$user":{"$t":"samantajohnny"},"gsx$name":{"$t":"samantajohnny@gmail.com"},"gsx$date":{"$t":"26-Jan-19"},"gsx$time":{"$t":"05:22:57 PM"},"gsx$count":{"$t":""},"gsx$totalvalue":{"$t":""},"gsx$etc1":{"$t":""},"gsx$modifiedday":{"$t":"Saturday"},"gsx$_d2mkx":{"$t":"1"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/cre1l"},"updated":{"$t":"2019-02-04T08:34:17.350Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Invoice Register"},"content":{"type":"text","$t":"user: arpenduhalder@gmail.com, name: Arpendu Halder, date: Feb,4, time: 02:04 PM, count: 245, totalvalue: 49627399, etc1: 9107764, modifiedday: Monday, _d180g: done, _d2mkx: 2"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/cre1l"}],"gsx$file":{"$t":"Invoice Register"},"gsx$email":{"$t":""},"gsx$user":{"$t":"arpenduhalder@gmail.com"},"gsx$name":{"$t":"Arpendu Halder"},"gsx$date":{"$t":"Feb,4"},"gsx$time":{"$t":"02:04 PM"},"gsx$count":{"$t":"245"},"gsx$totalvalue":{"$t":"49627399"},"gsx$etc1":{"$t":"9107764"},"gsx$modifiedday":{"$t":"Monday"},"gsx$_d180g":{"$t":"done"},"gsx$_d2mkx":{"$t":"2"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/chk2m"},"updated":{"$t":"2019-02-04T08:34:17.350Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Security Deposits"},"content":{"type":"text","$t":"user: soumitrachattopadhyay314@gmail.com, name: Soumitra Chattopadhyay, date: Feb,1, time: 06:15 PM, count: 30, totalvalue: 1145835, modifiedday: Friday, _d180g: done, _d2mkx: 3"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/chk2m"}],"gsx$file":{"$t":"Security Deposits"},"gsx$email":{"$t":""},"gsx$user":{"$t":"soumitrachattopadhyay314@gmail.com"},"gsx$name":{"$t":"Soumitra Chattopadhyay"},"gsx$date":{"$t":"Feb,1"},"gsx$time":{"$t":"06:15 PM"},"gsx$count":{"$t":"30"},"gsx$totalvalue":{"$t":"1145835"},"gsx$etc1":{"$t":""},"gsx$modifiedday":{"$t":"Friday"},"gsx$_d180g":{"$t":"done"},"gsx$_d2mkx":{"$t":"3"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/ciyn3"},"updated":{"$t":"2019-02-04T08:34:17.350Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Tender Details"},"content":{"type":"text","$t":"user: soumitrachattopadhyay314@gmail.com, name: Soumitra Chattopadhyay, date: Feb,1, time: 06:08 PM, count: 45, totalvalue: 45895394, modifiedday: Friday, _d180g: done, _d2mkx: 4"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/ciyn3"}],"gsx$file":{"$t":"Tender Details"},"gsx$email":{"$t":""},"gsx$user":{"$t":"soumitrachattopadhyay314@gmail.com"},"gsx$name":{"$t":"Soumitra Chattopadhyay"},"gsx$date":{"$t":"Feb,1"},"gsx$time":{"$t":"06:08 PM"},"gsx$count":{"$t":"45"},"gsx$totalvalue":{"$t":"45895394"},"gsx$etc1":{"$t":""},"gsx$modifiedday":{"$t":"Friday"},"gsx$_d180g":{"$t":"done"},"gsx$_d2mkx":{"$t":"4"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/ckd7g"},"updated":{"$t":"2019-02-04T08:34:17.350Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Employee Details"},"content":{"type":"text","$t":"user: samantajohnny@gmail.com, name: Jony S, date: Feb,1, time: 03:19 PM, modifiedday: Friday, _d2mkx: 5"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/ckd7g"}],"gsx$file":{"$t":"Employee Details"},"gsx$email":{"$t":""},"gsx$user":{"$t":"samantajohnny@gmail.com"},"gsx$name":{"$t":"Jony S"},"gsx$date":{"$t":"Feb,1"},"gsx$time":{"$t":"03:19 PM"},"gsx$count":{"$t":""},"gsx$totalvalue":{"$t":""},"gsx$etc1":{"$t":""},"gsx$modifiedday":{"$t":"Friday"},"gsx$_d2mkx":{"$t":"5"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/clrrx"},"updated":{"$t":"2019-02-04T08:34:17.350Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Vehicle Details"},"content":{"type":"text","$t":"user: samantajohnny@gmail.com, name: Jony S, date: Feb,1, time: 03:22 PM, count: 4, modifiedday: Friday, _d180g: done, _d2mkx: 6"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/clrrx"}],"gsx$file":{"$t":"Vehicle Details"},"gsx$email":{"$t":""},"gsx$user":{"$t":"samantajohnny@gmail.com"},"gsx$name":{"$t":"Jony S"},"gsx$date":{"$t":"Feb,1"},"gsx$time":{"$t":"03:22 PM"},"gsx$count":{"$t":"4"},"gsx$totalvalue":{"$t":""},"gsx$etc1":{"$t":""},"gsx$modifiedday":{"$t":"Friday"},"gsx$_d180g":{"$t":"done"},"gsx$_d2mkx":{"$t":"6"}},{"id":{"$t":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/cyevm"},"updated":{"$t":"2019-02-04T08:34:17.350Z"},"category":[{"scheme":"http://schemas.google.com/spreadsheets/2006","term":"http://schemas.google.com/spreadsheets/2006#list"}],"title":{"type":"text","$t":"Supplier Details"},"content":{"type":"text","$t":"user: samantajohnny@gmail.com, name: Jony S, date: Feb,1, time: 03:33 PM, modifiedday: Friday, _d2mkx: 7"},"link":[{"rel":"self","type":"application/atom+xml","href":"https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values/cyevm"}],"gsx$file":{"$t":"Supplier Details"},"gsx$email":{"$t":""},"gsx$user":{"$t":"samantajohnny@gmail.com"},"gsx$name":{"$t":"Jony S"},"gsx$date":{"$t":"Feb,1"},"gsx$time":{"$t":"03:33 PM"},"gsx$count":{"$t":""},"gsx$totalvalue":{"$t":""},"gsx$etc1":{"$t":""},"gsx$modifiedday":{"$t":"Friday"},"gsx$_d2mkx":{"$t":"7"}}]}}

Я пытаюсь вызвать уведомление начальной загрузки всякий раз, когда данные (json) меняются для всех строк, ниже приведен пример 3-й строки.

/* Bootstrap Notify - http://bootstrap-notify.remabledesigns.com */

$(function () {
    $( document ).ready(function() {
        $.notifyDefaults({
            type: 'minimalist',
            delay: 10000,
            placement: {
                from: "bottom",
                align: "center"
                    },
            icon_type: 'image',
            template: '<div data-notify="container" class="col-xs-11 col-sm-3 alert alert-{0}" role="alert">' +
            '<button type="button" aria-hidden="true" class="close" data-notify="dismiss">×</button>' +
            '<img data-notify="icon" class="img-circle pull-left">' +
            '<span data-notify="title">{1}</span>' +
            '<span data-notify="message">{2}</span>' +
            '<a href="{3}" data-notify="url"></a>' +
            '</div>' });

    });
});

var url = "https://spreadsheets.google.com/feeds/list/<ID>/od6/public/values?alt=json"; 

 setInterval(function(){
     $(document).ready(function () {
         $.getJSON(url, function(data) {
var rec = data.feed.entry[3];
$(rec).each(function(){

            $.notify({
            icon: 'https://randomuser.me/api/portraits/med/men/77.jpg',
            title: this.gsx$name.$t,
            message: 'Updated '+ this.gsx$file.$t +' at ' + this.gsx$time.$t,
            url: "https://twitter.com/Mouse0270" });

             });                     
         });
  });
 }, 1000);
</script>

Ожидание уведомления в реальном времени при изменении данных / строк в упомянутом json.это только показывает указанный дочерний элемент в цикле после 1 мс.

...