details:   https://code.openbravo.com/erp/devel/pi/rev/d51b35c667bc
changeset: 32878:d51b35c667bc
user:      Inigo Sanchez <inigo.sanchez <at> openbravo.com>
date:      Tue Oct 24 10:25:47 2017 +0200
summary:   Fixed issue 36605: unneeded datasource requests opening alert 
management window

The problem was when Alert Management window was opened, 10 requests to 
datasource were performed.
In order to improve this situation, several actions have been done. Firts, the 
4 calls of the datasource
definition are removed. Now, the datasource is defined statically. Thisthat 
Alert Management window is
not working good. Also, two of the duplicate request are removed.

Besides, when the Alert Management window is closed and the four grids are 
removed, now the datasources
are destroyed too in order to avoid having several instances for the same 
datasources every time that
Alerts windowd is reopened. Now, every grid removes their own datasource.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js
            |  28 +---
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-management-view.js
 |  65 +++++++++-
 2 files changed, 70 insertions(+), 23 deletions(-)

diffs (169 lines):

diff -r 68b79a76a32d -r d51b35c667bc 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js
        Tue Oct 24 09:12:56 2017 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-grid.js
        Tue Oct 24 10:25:47 2017 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2011-2015 Openbravo SLU
+ * All portions are Copyright (C) 2011-2017 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -126,8 +126,6 @@
       items: []
     });
 
-    OB.Datasource.get('DB9F062472294F12A0291A7BD203F922', this, null, true);
-
     this.Super('initWidget', arguments);
   },
 
@@ -136,6 +134,10 @@
       this.contextMenu.destroy();
       this.contextMenu = null;
     }
+    if (this.dataSource) {
+      this.dataSource.destroy();
+      this.dataSource = null;
+    }
     this.Super('destroy', arguments);
   },
 
@@ -177,25 +179,7 @@
   },
 
   getGridTotalRows: function () {
-    var criteria = this.getCriteria() || {},
-        requestProperties = {};
-
-    if (!OB.AlertManagement.sections[this.alertStatus].expanded) {
-      // fetch to the datasource with an empty criteria to get all the rows
-      requestProperties.params = requestProperties.params || {};
-      requestProperties.params._alertStatus = this.alertStatus;
-      requestProperties.params._startRow = 0;
-      requestProperties.params._endRow = this.dataPageSize;
-      requestProperties.clientContext = {
-        alertStatus: this.alertStatus
-      };
-      this.dataSource.fetchData(criteria, function (dsResponse, data, 
dsRequest) {
-        OB.AlertManagement.setTotalRows(dsResponse.totalRows, 
dsResponse.clientContext.alertStatus);
-      }, requestProperties);
-
-    } else {
-      OB.AlertManagement.setTotalRows(this.getTotalRows(), this.alertStatus);
-    }
+    OB.AlertManagement.setTotalRows(this.getTotalRows(), this.alertStatus);
   },
 
   getFetchRequestParams: function (params) {
diff -r 68b79a76a32d -r d51b35c667bc 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-management-view.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-management-view.js
     Tue Oct 24 09:12:56 2017 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/alert-management/ob-alert-management-view.js
     Tue Oct 24 10:25:47 2017 +0200
@@ -11,7 +11,7 @@
  * under the License.
  * The Original Code is Openbravo ERP.
  * The Initial Developer of the Original Code is Openbravo SLU
- * All portions are Copyright (C) 2011-2015 Openbravo SLU
+ * All portions are Copyright (C) 2011-2017 Openbravo SLU
  * All Rights Reserved.
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -29,6 +29,45 @@
     return result;
   },
 
+  createAlertDataSource: function () {
+    return OB.Datasource.create({
+      createClassName: '',
+      ID: 'DB9F062472294F12A0291A7BD203F922' + '_' + new Date().getTime(),
+      potentiallyShared: true,
+      dataURL: 
OB.Utilities.applicationUrl('org.openbravo.service.datasource/DB9F062472294F12A0291A7BD203F922'),
+      requestProperties: {
+        params: {
+          _contextUrl: OB.Utilities.getLocationUrlWithoutFragment(),
+          _skinVersion: 'Default',
+          Constants_IDENTIFIER: OB.Constants.IDENTIFIER,
+          Constants_FIELDSEPARATOR: OB.Constants.FIELDSEPARATOR,
+          _new: 'true',
+          _create: 'true'
+        }
+      },
+      fields: [{
+        name: 'id',
+        type: '_id_13',
+        primaryKey: true
+      }, {
+        name: 'creationDate',
+        type: '_id_16'
+      }, {
+        name: 'description',
+        type: '_id_14'
+      }, {
+        name: 'alertRule',
+        type: '_id_19'
+      }, {
+        name: 'comments',
+        type: '_id_14'
+      }, {
+        name: 'recordID',
+        type: '_id_10'
+      }]
+    });
+  },
+
   translatedStatus: {
     New: '',
     Acknowledged: '',
@@ -110,6 +149,7 @@
     this.grids.New = isc.OBAlertGrid.create({
       alertStatus: 'New'
     });
+
     this.NewAcknowledged = isc.OBAlertSectionStackControl.create({
       currentStatus: 'New',
       newStatus: 'Acknowledged',
@@ -183,6 +223,11 @@
       items: [this.grids.Solved]
     };
     this.sectionStack.addSection(this.sections.Solved);
+
+    this.grids.New.setDataSource(this.createAlertDataSource());
+    this.grids.Acknowledged.setDataSource(this.createAlertDataSource());
+    this.grids.Suppressed.setDataSource(this.createAlertDataSource());
+    this.grids.Solved.setDataSource(this.createAlertDataSource());
   },
 
   destroy: function () {
@@ -268,6 +313,7 @@
     for (i = 0; i < 4; i++) {
       OB.AlertManagement.grids[alertStatus[i]].invalidateCache();
       if (!OB.AlertManagement.sections[alertStatus[i]].expanded) {
+        OB.AlertManagement.getTotalRowsForAlert();
         OB.AlertManagement.grids[alertStatus[i]].getGridTotalRows();
       }
       if (OB.AlertManagement.grids[alertStatus[i]].isDrawn()) {
@@ -276,6 +322,23 @@
     }
   },
 
+  getTotalRowsForAlert: function () {
+    var criteria = this.getCriteria() || {},
+        requestProperties = {};
+
+    // fetch to the datasource with an empty criteria to get all the rows
+    requestProperties.params = requestProperties.params || {};
+    requestProperties.params._alertStatus = this.alertStatus;
+    requestProperties.params._startRow = 0;
+    requestProperties.params._endRow = this.dataPageSize;
+    requestProperties.clientContext = {
+      alertStatus: this.alertStatus
+    };
+    this.dataSource.fetchData(criteria, function (dsResponse, data, dsRequest) 
{
+      OB.AlertManagement.setTotalRows(dsResponse.totalRows, 
dsResponse.clientContext.alertStatus);
+    }, requestProperties);
+  },
+
   notifyRefreshEnd: function () {
     var i, alertStatus = ['New', 'Acknowledged', 'Suppressed', 'Solved'];
     for (i = 0; i < 4; i++) {

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to