SAPUI5/Javascript Interval 30 sec, Display MessageBox as a Popup when new changes occur on the DB











up vote
0
down vote

favorite












I want to display an error messageBox for every "102" status.



onInit: function () {
var counter = {};
var sUrl = "/api/equipmentReport/getMachineOverview.xsjs";

var oModel = new JSONModel();
this.modelRefresh = setInterval(this.refreshModel.bind(this), 30000, sUrl, oModel);
oModel.attachRequestCompleted(function (oEvent) {
this.buildComboBox(oEvent.getSource().getData());
if (oEvent.getParameter("success") === true) {
var oModelData = oEvent.getSource().getData();
oModelData.equipments.forEach(function(o){
// o.iotTimestampDate = o.iotTimestamp !== null ? new Date(o.iotTimestamp) : "";
counter[o.registeredProductId] = o.telemetryStatus;
})
}
this.getPopupMessageForOfflineMachines(counter);
oEvent.getSource().updateBindings(true);
this.getView().setModel(oModel, "rootModel");

}.bind(this));

oModel.attachEventOnce('requestCompleted', {
oModel: oModel
}, this.restoreApplicationState.bind(this));
oModel.loadData(sUrl, false);



oModel.setSizeLimit(1000000);
sap.ui.getCore().setModel(oModel);
this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
this.oRouter.attachRouteMatched(this.handleRouteMatched, this);
var oHashChanger = sap.ui.core.routing.HashChanger.getInstance();
var sHash = oHashChanger.getHash();
if (sHash) {
var sAppStateKey = /(?:sap-iapp-state=)([^&=]+)/.exec(sHash)[1];
if (sAppStateKey) {
sap.ushell.Container
.getService("CrossApplicationNavigation")
.getAppState(this.getOwnerComponent(), sAppStateKey)
.done(this.restoreAppState.bind(this));
}
}
this.getView().setModel(oModel);


so firstly I am creating an object(registeredProductId -> status)



40000000.H: "102"
40000001.H: "113"
40000002.H: "113"
40000003.H: "113"
40000004.H: "113"
40000005.H: "113"
40000006.H: "113"
40000007.H: "113"
40000008.H: "113"
40000009.H: "113"
40000010.H: "101"
40000011.H: "113"
40000012.H: "113"
40000015.H: "103"
40000023.H: "103"
40000026.H: "103"
40000027.H: "113"
40000028.H: "102"
40000029.H: "103"


after that in my function I get status 102, and I need to check somehow the object. If the registeredProductId is already there and if it has status !== 102, it is warning-relevant, so that the Popup appears only once per Status and only when the service data changes.



getPopupMessageForOfflineMachines: function(counter) {
console.log(counter);
for (var key in counter) {
if(counter[key] == "102"){
MessageBox.warning(key);
}
}

},


if so, it is warning-relevant



The problem is that the model/service refreshes every 30 seconds and my Popup comes out every 30 seconds.



I would really appreciate any pointers on this issue.










share|improve this question




























    up vote
    0
    down vote

    favorite












    I want to display an error messageBox for every "102" status.



    onInit: function () {
    var counter = {};
    var sUrl = "/api/equipmentReport/getMachineOverview.xsjs";

    var oModel = new JSONModel();
    this.modelRefresh = setInterval(this.refreshModel.bind(this), 30000, sUrl, oModel);
    oModel.attachRequestCompleted(function (oEvent) {
    this.buildComboBox(oEvent.getSource().getData());
    if (oEvent.getParameter("success") === true) {
    var oModelData = oEvent.getSource().getData();
    oModelData.equipments.forEach(function(o){
    // o.iotTimestampDate = o.iotTimestamp !== null ? new Date(o.iotTimestamp) : "";
    counter[o.registeredProductId] = o.telemetryStatus;
    })
    }
    this.getPopupMessageForOfflineMachines(counter);
    oEvent.getSource().updateBindings(true);
    this.getView().setModel(oModel, "rootModel");

    }.bind(this));

    oModel.attachEventOnce('requestCompleted', {
    oModel: oModel
    }, this.restoreApplicationState.bind(this));
    oModel.loadData(sUrl, false);



    oModel.setSizeLimit(1000000);
    sap.ui.getCore().setModel(oModel);
    this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
    this.oRouter.attachRouteMatched(this.handleRouteMatched, this);
    var oHashChanger = sap.ui.core.routing.HashChanger.getInstance();
    var sHash = oHashChanger.getHash();
    if (sHash) {
    var sAppStateKey = /(?:sap-iapp-state=)([^&=]+)/.exec(sHash)[1];
    if (sAppStateKey) {
    sap.ushell.Container
    .getService("CrossApplicationNavigation")
    .getAppState(this.getOwnerComponent(), sAppStateKey)
    .done(this.restoreAppState.bind(this));
    }
    }
    this.getView().setModel(oModel);


    so firstly I am creating an object(registeredProductId -> status)



    40000000.H: "102"
    40000001.H: "113"
    40000002.H: "113"
    40000003.H: "113"
    40000004.H: "113"
    40000005.H: "113"
    40000006.H: "113"
    40000007.H: "113"
    40000008.H: "113"
    40000009.H: "113"
    40000010.H: "101"
    40000011.H: "113"
    40000012.H: "113"
    40000015.H: "103"
    40000023.H: "103"
    40000026.H: "103"
    40000027.H: "113"
    40000028.H: "102"
    40000029.H: "103"


    after that in my function I get status 102, and I need to check somehow the object. If the registeredProductId is already there and if it has status !== 102, it is warning-relevant, so that the Popup appears only once per Status and only when the service data changes.



    getPopupMessageForOfflineMachines: function(counter) {
    console.log(counter);
    for (var key in counter) {
    if(counter[key] == "102"){
    MessageBox.warning(key);
    }
    }

    },


    if so, it is warning-relevant



    The problem is that the model/service refreshes every 30 seconds and my Popup comes out every 30 seconds.



    I would really appreciate any pointers on this issue.










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I want to display an error messageBox for every "102" status.



      onInit: function () {
      var counter = {};
      var sUrl = "/api/equipmentReport/getMachineOverview.xsjs";

      var oModel = new JSONModel();
      this.modelRefresh = setInterval(this.refreshModel.bind(this), 30000, sUrl, oModel);
      oModel.attachRequestCompleted(function (oEvent) {
      this.buildComboBox(oEvent.getSource().getData());
      if (oEvent.getParameter("success") === true) {
      var oModelData = oEvent.getSource().getData();
      oModelData.equipments.forEach(function(o){
      // o.iotTimestampDate = o.iotTimestamp !== null ? new Date(o.iotTimestamp) : "";
      counter[o.registeredProductId] = o.telemetryStatus;
      })
      }
      this.getPopupMessageForOfflineMachines(counter);
      oEvent.getSource().updateBindings(true);
      this.getView().setModel(oModel, "rootModel");

      }.bind(this));

      oModel.attachEventOnce('requestCompleted', {
      oModel: oModel
      }, this.restoreApplicationState.bind(this));
      oModel.loadData(sUrl, false);



      oModel.setSizeLimit(1000000);
      sap.ui.getCore().setModel(oModel);
      this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
      this.oRouter.attachRouteMatched(this.handleRouteMatched, this);
      var oHashChanger = sap.ui.core.routing.HashChanger.getInstance();
      var sHash = oHashChanger.getHash();
      if (sHash) {
      var sAppStateKey = /(?:sap-iapp-state=)([^&=]+)/.exec(sHash)[1];
      if (sAppStateKey) {
      sap.ushell.Container
      .getService("CrossApplicationNavigation")
      .getAppState(this.getOwnerComponent(), sAppStateKey)
      .done(this.restoreAppState.bind(this));
      }
      }
      this.getView().setModel(oModel);


      so firstly I am creating an object(registeredProductId -> status)



      40000000.H: "102"
      40000001.H: "113"
      40000002.H: "113"
      40000003.H: "113"
      40000004.H: "113"
      40000005.H: "113"
      40000006.H: "113"
      40000007.H: "113"
      40000008.H: "113"
      40000009.H: "113"
      40000010.H: "101"
      40000011.H: "113"
      40000012.H: "113"
      40000015.H: "103"
      40000023.H: "103"
      40000026.H: "103"
      40000027.H: "113"
      40000028.H: "102"
      40000029.H: "103"


      after that in my function I get status 102, and I need to check somehow the object. If the registeredProductId is already there and if it has status !== 102, it is warning-relevant, so that the Popup appears only once per Status and only when the service data changes.



      getPopupMessageForOfflineMachines: function(counter) {
      console.log(counter);
      for (var key in counter) {
      if(counter[key] == "102"){
      MessageBox.warning(key);
      }
      }

      },


      if so, it is warning-relevant



      The problem is that the model/service refreshes every 30 seconds and my Popup comes out every 30 seconds.



      I would really appreciate any pointers on this issue.










      share|improve this question















      I want to display an error messageBox for every "102" status.



      onInit: function () {
      var counter = {};
      var sUrl = "/api/equipmentReport/getMachineOverview.xsjs";

      var oModel = new JSONModel();
      this.modelRefresh = setInterval(this.refreshModel.bind(this), 30000, sUrl, oModel);
      oModel.attachRequestCompleted(function (oEvent) {
      this.buildComboBox(oEvent.getSource().getData());
      if (oEvent.getParameter("success") === true) {
      var oModelData = oEvent.getSource().getData();
      oModelData.equipments.forEach(function(o){
      // o.iotTimestampDate = o.iotTimestamp !== null ? new Date(o.iotTimestamp) : "";
      counter[o.registeredProductId] = o.telemetryStatus;
      })
      }
      this.getPopupMessageForOfflineMachines(counter);
      oEvent.getSource().updateBindings(true);
      this.getView().setModel(oModel, "rootModel");

      }.bind(this));

      oModel.attachEventOnce('requestCompleted', {
      oModel: oModel
      }, this.restoreApplicationState.bind(this));
      oModel.loadData(sUrl, false);



      oModel.setSizeLimit(1000000);
      sap.ui.getCore().setModel(oModel);
      this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
      this.oRouter.attachRouteMatched(this.handleRouteMatched, this);
      var oHashChanger = sap.ui.core.routing.HashChanger.getInstance();
      var sHash = oHashChanger.getHash();
      if (sHash) {
      var sAppStateKey = /(?:sap-iapp-state=)([^&=]+)/.exec(sHash)[1];
      if (sAppStateKey) {
      sap.ushell.Container
      .getService("CrossApplicationNavigation")
      .getAppState(this.getOwnerComponent(), sAppStateKey)
      .done(this.restoreAppState.bind(this));
      }
      }
      this.getView().setModel(oModel);


      so firstly I am creating an object(registeredProductId -> status)



      40000000.H: "102"
      40000001.H: "113"
      40000002.H: "113"
      40000003.H: "113"
      40000004.H: "113"
      40000005.H: "113"
      40000006.H: "113"
      40000007.H: "113"
      40000008.H: "113"
      40000009.H: "113"
      40000010.H: "101"
      40000011.H: "113"
      40000012.H: "113"
      40000015.H: "103"
      40000023.H: "103"
      40000026.H: "103"
      40000027.H: "113"
      40000028.H: "102"
      40000029.H: "103"


      after that in my function I get status 102, and I need to check somehow the object. If the registeredProductId is already there and if it has status !== 102, it is warning-relevant, so that the Popup appears only once per Status and only when the service data changes.



      getPopupMessageForOfflineMachines: function(counter) {
      console.log(counter);
      for (var key in counter) {
      if(counter[key] == "102"){
      MessageBox.warning(key);
      }
      }

      },


      if so, it is warning-relevant



      The problem is that the model/service refreshes every 30 seconds and my Popup comes out every 30 seconds.



      I would really appreciate any pointers on this issue.







      javascript sapui5






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 11 at 12:19









      Vega

      11.7k113251




      11.7k113251










      asked Nov 11 at 12:10









      Fiodor Smirnov

      11




      11
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You can keep track of and compare with the previous values. Concretely, add a variable e.g. previousCounter, and then in your getPopupMessageForOfflineMachines function, use



          if(counter[key] == "102" && counter[key] !== previousCounter[key]){
          MessageBox.warning(key);
          }





          share|improve this answer





















          • thank you for the answer, but it didnt help :(
            – Fiodor Smirnov
            Nov 11 at 13:17










          • Can you please elaborate?
            – rikusv
            Nov 11 at 13:50











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248601%2fsapui5-javascript-interval-30-sec-display-messagebox-as-a-popup-when-new-change%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          You can keep track of and compare with the previous values. Concretely, add a variable e.g. previousCounter, and then in your getPopupMessageForOfflineMachines function, use



          if(counter[key] == "102" && counter[key] !== previousCounter[key]){
          MessageBox.warning(key);
          }





          share|improve this answer





















          • thank you for the answer, but it didnt help :(
            – Fiodor Smirnov
            Nov 11 at 13:17










          • Can you please elaborate?
            – rikusv
            Nov 11 at 13:50















          up vote
          0
          down vote













          You can keep track of and compare with the previous values. Concretely, add a variable e.g. previousCounter, and then in your getPopupMessageForOfflineMachines function, use



          if(counter[key] == "102" && counter[key] !== previousCounter[key]){
          MessageBox.warning(key);
          }





          share|improve this answer





















          • thank you for the answer, but it didnt help :(
            – Fiodor Smirnov
            Nov 11 at 13:17










          • Can you please elaborate?
            – rikusv
            Nov 11 at 13:50













          up vote
          0
          down vote










          up vote
          0
          down vote









          You can keep track of and compare with the previous values. Concretely, add a variable e.g. previousCounter, and then in your getPopupMessageForOfflineMachines function, use



          if(counter[key] == "102" && counter[key] !== previousCounter[key]){
          MessageBox.warning(key);
          }





          share|improve this answer












          You can keep track of and compare with the previous values. Concretely, add a variable e.g. previousCounter, and then in your getPopupMessageForOfflineMachines function, use



          if(counter[key] == "102" && counter[key] !== previousCounter[key]){
          MessageBox.warning(key);
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 12:46









          rikusv

          27515




          27515












          • thank you for the answer, but it didnt help :(
            – Fiodor Smirnov
            Nov 11 at 13:17










          • Can you please elaborate?
            – rikusv
            Nov 11 at 13:50


















          • thank you for the answer, but it didnt help :(
            – Fiodor Smirnov
            Nov 11 at 13:17










          • Can you please elaborate?
            – rikusv
            Nov 11 at 13:50
















          thank you for the answer, but it didnt help :(
          – Fiodor Smirnov
          Nov 11 at 13:17




          thank you for the answer, but it didnt help :(
          – Fiodor Smirnov
          Nov 11 at 13:17












          Can you please elaborate?
          – rikusv
          Nov 11 at 13:50




          Can you please elaborate?
          – rikusv
          Nov 11 at 13:50


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248601%2fsapui5-javascript-interval-30-sec-display-messagebox-as-a-popup-when-new-change%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation