MDL-68612 core_table: Pending checks for dyanmic updates
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 4 Jun 2020 02:43:04 +0000 (10:43 +0800)
committerJun Pataleta <jun@moodle.com>
Thu, 4 Jun 2020 02:47:27 +0000 (10:47 +0800)
lib/table/amd/build/dynamic.min.js
lib/table/amd/build/dynamic.min.js.map
lib/table/amd/src/dynamic.js

index da081b3..3bf3339 100644 (file)
Binary files a/lib/table/amd/build/dynamic.min.js and b/lib/table/amd/build/dynamic.min.js differ
index 1609714..f1e7466 100644 (file)
Binary files a/lib/table/amd/build/dynamic.min.js.map and b/lib/table/amd/build/dynamic.min.js.map differ
index 10abe96..1448991 100644 (file)
  * @copyright  2020 Simey Lameze <simey@moodle.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
  * @copyright  2020 Simey Lameze <simey@moodle.com>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-import {fetch as fetchTableData} from 'core_table/local/dynamic/repository';
 import * as Selectors from 'core_table/local/dynamic/selectors';
 import Events from './local/dynamic/events';
 import * as Selectors from 'core_table/local/dynamic/selectors';
 import Events from './local/dynamic/events';
+import Pending from 'core/pending';
 import {addIconToContainer} from 'core/loadingicon';
 import {addIconToContainer} from 'core/loadingicon';
+import {fetch as fetchTableData} from 'core_table/local/dynamic/repository';
 
 let watching = false;
 
 
 let watching = false;
 
@@ -69,6 +70,8 @@ export const refreshTableContent = (tableRoot, resetContent = false) => {
     const filterset = getFiltersetFromTable(tableRoot);
     addIconToContainer(tableRoot);
 
     const filterset = getFiltersetFromTable(tableRoot);
     addIconToContainer(tableRoot);
 
+    const pendingPromise = new Pending('core_table/dynamic:refreshTableContent');
+
     return fetchTableData(
         tableRoot.dataset.tableComponent,
         tableRoot.dataset.tableHandler,
     return fetchTableData(
         tableRoot.dataset.tableComponent,
         tableRoot.dataset.tableHandler,
@@ -97,6 +100,11 @@ export const refreshTableContent = (tableRoot, resetContent = false) => {
             bubbles: true,
         }));
 
             bubbles: true,
         }));
 
+        return tableRoot;
+    })
+    .then(tableRoot => {
+        pendingPromise.resolve();
+
         return tableRoot;
     });
 };
         return tableRoot;
     });
 };
@@ -113,6 +121,8 @@ export const updateTable = (tableRoot, {
 } = {}, refreshContent = true) => {
     checkTableIsDynamic(tableRoot);
 
 } = {}, refreshContent = true) => {
     checkTableIsDynamic(tableRoot);
 
+    const pendingPromise = new Pending('core_table/dynamic:updateTable');
+
     // Update sort fields.
     if (sortBy && sortOrder) {
         const sortData = JSON.parse(tableRoot.dataset.tableSortData);
     // Update sort fields.
     if (sortBy && sortOrder) {
         const sortData = JSON.parse(tableRoot.dataset.tableSortData);
@@ -152,8 +162,13 @@ export const updateTable = (tableRoot, {
 
     // Refresh.
     if (refreshContent) {
 
     // Refresh.
     if (refreshContent) {
-        return refreshTableContent(tableRoot);
+        return refreshTableContent(tableRoot)
+        .then(tableRoot => {
+            pendingPromise.resolve();
+            return tableRoot;
+        });
     } else {
     } else {
+        pendingPromise.resolve();
         return Promise.resolve(tableRoot);
     }
 };
         return Promise.resolve(tableRoot);
     }
 };