Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(Invetory): adding loading indicator into the inventory list #1991

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions client/src/modules/inventory/list/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<li role="separator" class="divider"></li>
<li role="menuitem">
<a ng-href="/reports/inventory/items/?params={{ InventoryCtrl.parameters }}&lang={{ InventoryCtrl.lang }}"
<a ng-href="/reports/inventory/items/?params={{ InventoryCtrl.parameters }}&lang={{ InventoryCtrl.lang }}"
download="{{ 'INVENTORY.PRICE_LIST_REPORT' | translate }}">
<span class="fa fa-file-pdf-o"></span> <span translate>DOWNLOADS.PDF</span>
</a>
Expand All @@ -57,7 +57,7 @@
data-method="filter">
<i class="fa fa-filter"></i>
</button>

<a
class="btn btn-default text-capitalize"
ui-sref="inventory.create"
Expand All @@ -72,7 +72,7 @@
id="research">
<i class="fa fa-search"></i> <span translate>FORM.BUTTONS.SEARCH</span>
</button>
</div>
</div>
</div>

</div>
Expand All @@ -99,6 +99,13 @@
ui-grid-exporter
ui-grid-auto-resize
ui-grid-resize-columns>

<bh-grid-loading-indicator
loading-state="InventoryCtrl.loading"
empty-state="InventoryCtrl.gridOptions.data.length === 0"
error-state="InventoryCtrl.hasError">
</bh-grid-loading-indicator>

</div>
</div>
</div>
14 changes: 13 additions & 1 deletion client/src/modules/inventory/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function InventoryListController($translate, Inventory, Notify, uiGridConstants,
vm.filterEnabled = false;
vm.gridOptions = {};
vm.gridApi = {};
vm.loading = false;


// grid default options
columnDefs = [
Expand Down Expand Up @@ -138,20 +140,30 @@ function InventoryListController($translate, Inventory, Notify, uiGridConstants,
}

function runResearch(params) {

if (params) {
search.assignFilters(params);
vm.latestViewFilters = search.latestViewFilters();
vm.hasCustomFilters = search.hasCustomFilters();
vm.parameters = JSON.stringify(params);
}

vm.loading = true;
vm.hasError = false;

Inventory.read(null, params)
.then(function (rows) {
vm.gridOptions.data = rows;
})
.catch(Notify.handleError);
.catch(Error);

vm.loading = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the loading indicator work? It seems like this will not wait for the data to download.

The correct way to wait for the data to download is to use the .finally() Promise method. Like this:

.catch(Notify.handleError)
.finally(function () {
  vm.loading = false; // this will execute after the data is downloaded.
});

}

function Error() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error is a reserved word in JavaScript. Could you name this function something else?

vm.hasError = true;
Notify.handleError();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notify.handleError() takes in a parameter - the error sent from the server. It should be passed to thus function.

}
// research and filter data in Inventory List
function research() {
Inventory.openSearchModal()
Expand Down