Skip to content

Commit

Permalink
Merge #1789
Browse files Browse the repository at this point in the history
1789: refactor(inventory registry): use filter, export and save grid state r=jniles

This PR refactor the inventory registry accoriding the new standard for search filters, data exportation, saving grid state and update the UI.

Closes #1747
  • Loading branch information
bors[bot] committed Jul 17, 2017
2 parents e46831f + 72eeb50 commit 3a9974a
Show file tree
Hide file tree
Showing 19 changed files with 388 additions and 179 deletions.
4 changes: 3 additions & 1 deletion client/src/i18n/en/inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
"EDIT_TYPE":"Edit inventory type",
"EDIT_UNIT":"Edit inventory unit form",
"ELEMENT":"Element",
"PRICE_LIST_REPORT":"Inventory Prices Report",
"PRICES":"Inventory Prices",
"LIST":"Inventory Data List",
"LIST_METADATA":"Inventory",
"LIST_GROUP":"Inventory Groups",
"LIST_TYPE":"Inventory Types",
"LIST_UNIT":"Inventory Unit form",
"DEFAULT_QUANTITY_DEFINITION":"The default quantity allows you to customize the default quantity invoiced for. The invoicing module can change this quantity at invoice time."}}
"DEFAULT_QUANTITY_DEFINITION":"The default quantity allows you to customize the default quantity invoiced for. The invoicing module can change this quantity at invoice time.",
"REGISTRY": "Inventories Registry"}}
4 changes: 3 additions & 1 deletion client/src/i18n/fr/inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
"EDIT_TYPE":"Modifier Types d'inventaires",
"EDIT_UNIT":"Modifier Forme d'inventaires",
"ELEMENT":"Élément",
"PRICE_LIST_REPORT":"Rapport des prix des articles et services",
"PRICES":"Tarification",
"LIST":"Liste des données d'inventaire",
"LIST_METADATA":"Inventaires",
"LIST_GROUP":"Groupes d'inventaires",
"LIST_TYPE":"Types d'inventaires",
"LIST_UNIT":"Formes d'inventaires"}}
"LIST_UNIT":"Formes d'inventaires",
"REGISTRY": "Registre des inventaires"}}
4 changes: 2 additions & 2 deletions client/src/js/components/bhFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function bhFiltersController($filter) {

var filters = changes.filters.currentValue;

if (!filters) { return; }

filters.defaultFilters.forEach(mapDisplayValues);
filters.customFilters.forEach(mapDisplayValues);
};
Expand All @@ -30,5 +32,3 @@ function bhFiltersController($filter) {
}
}
}


10 changes: 4 additions & 6 deletions client/src/js/services/FilterService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ angular.module('bhima.services')
FilterService.$inject = ['Store'];

function FilterService(Store) {

function FilterList() {
// initialise internal state
this._defaultFilters = [];
this._customFilters = [];

this._filterIndex = {};
}

FilterList.prototype.resetFilterState = function resetFilterState(key) {
this._filterIndex[key].setValue(null, null);
}
};

FilterList.prototype._resetCustomFilters = function resetCustomFilters() {
this._filterActiveFilters().forEach(function (filter) {
Expand All @@ -24,7 +22,7 @@ function FilterService(Store) {
this.resetFilterState(filter._key);
}
}.bind(this));
}
};

// @TODO registerDefaultFilter and registerCustomFilter could use the same underlying function
// with a toggle between the array to populate and the default value
Expand Down Expand Up @@ -84,9 +82,9 @@ function FilterService(Store) {
// return filters for the view - this method will always be compatible with the bhFilter component
FilterList.prototype.formatView = function formatView() {
var activeFilters = this._filterActiveFilters();
var activeKeys = activeFilters.map(function (filter) { return filter._key });
var activeKeys = activeFilters.map(function (filter) { return filter._key; });

function keysInActive(filter) { return activeKeys.indexOf(filter._key) !== -1 }
function keysInActive(filter) { return activeKeys.indexOf(filter._key) !== -1; }

// parse into two lists
return {
Expand Down
96 changes: 96 additions & 0 deletions client/src/js/services/SearchFilterService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
angular.module('bhima.services')
.service('SearchFilterService', SearchFilterService);

SearchFilterService.$inject = [
'FilterService', 'appcache',
];

function SearchFilterService(Filters, AppCache) {
function SearchFilter(cacheKey) {
this._filters = new Filters();
this._cache = new AppCache(cacheKey);

// available filters
this._availableFilters = [
{ key : 'period', label : 'TABLE.COLUMNS.PERIOD', valueFilter : 'translate' },
{ key : 'custom_period_start', label : 'PERIODS.START', valueFilter : 'date', comparitor : '>' },
{ key : 'custom_period_end', label : 'PERIODS.END', valueFilter : 'date', comparitor : '<' },
{ key : 'limit', label : 'FORM.LABELS.LIMIT' },
{ key : 'is_caution', label : 'FORM.LABELS.CAUTION' },
{ key : 'cashbox_id', label : 'FORM.LABELS.CASHBOX' },
{ key : 'debtor_uuid', label : 'FORM.LABELS.CLIENT' },
{ key : 'user_id', label : 'FORM.LABELS.USER' },
{ key : 'reference', label : 'FORM.LABELS.REFERENCE' },
{ key : 'dateFrom', label : 'FORM.LABELS.DATE_FROM', comparitor : '>', valueFilter : 'date' },
{ key : 'dateTo', label : 'FORM.LABELS.DATE_TO', comparitor : '<', valueFilter : 'date' },
{ key : 'currency_id', label : 'FORM.LABELS.CURRENCY' },
{ key : 'reversed', label : 'CASH.REGISTRY.REVERSED_RECORDS' },
{ key : 'patientReference', label : 'FORM.LABELS.REFERENCE_PATIENT' },
{ key : 'defaultPeriod', label : 'TABLE.COLUMNS.PERIOD', valueFilter : 'translate' },
{ key : 'invoiceReference', label : 'FORM.LABELS.INVOICE' },
{ key : 'patientReference', label : 'FORM.LABELS.REFERENCE_PATIENT' },
{ key : 'debtor_group_uuid', label : 'FORM.LABELS.DEBTOR_GROUP' },
{ key : 'invoice_uuid', label : 'FORM.LABELS.INVOICE' },
{ key : 'group_uuid', label : 'FORM.LABELS.GROUP' },
{ key : 'text', label : 'FORM.LABELS.LABEL' },
];

this._filters.registerCustomFilters(this._availableFilters);
this._filters.registerDefaultFilters([]);
}

/**
* @method formatParameters
*
* @description
* format parameters given according the FilterService standard
*
* @param {object} parameters - { key: value }
* @param {object} ctx - the context (this of object)
* @returns {object}
*/
function formatParameters(parameters, ctx) {
var params = parameters || {};
return ctx._filters._customFilters.filter(function (column) {
var value = params[column._key];
if (angular.isDefined(value)) {
column._value = value;
return true;
}
return false;
});
}

SearchFilter.prototype.assignFilters = function assignFilters(parameters) {
var filters = formatParameters(parameters, this);
this._cache.parameters = parameters;
this._cache.filters = filters;
};

SearchFilter.prototype.latestViewFilters = function latestViewFilters() {
return {
defaultFilters : [],
customFilters : this._cache.filters || [],
};
};

SearchFilter.prototype.hasCustomFilters = function hasCustomFilters() {
if (!this._cache.filters) { return false; }
return this._cache.filters.length;
};

SearchFilter.prototype.getParameters = function getParameters() {
return this._cache.parameters;
};

SearchFilter.prototype.removeFilter = function removeFilter(key) {
delete this._cache.parameters[key];
};

SearchFilter.prototype.clearFilters = function clearFilters() {
delete this._cache.parameters;
delete this._cache.filters;
};

return SearchFilter;
}
2 changes: 1 addition & 1 deletion client/src/modules/cash/cash.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ angular.module('bhima.services')

CashService.$inject = [
'$uibModal', 'PrototypeApiService', 'ExchangeRateService', 'SessionService', 'moment', '$translate',
'FilterService', 'appcache', 'PeriodService', 'LanguageService', '$httpParamSerializer'
'FilterService', 'appcache', 'PeriodService', 'LanguageService', '$httpParamSerializer',
];

/**
Expand Down
5 changes: 2 additions & 3 deletions client/src/modules/cash/payments/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ angular.module('bhima.controllers')
CashPaymentRegistryController.$inject = [
'CashService', 'bhConstants', 'NotifyService', 'SessionService', 'uiGridConstants',
'ReceiptModal', 'ModalService', 'GridSortingService', '$state', 'FilterService',
'GridColumnService', 'GridStateService'
'GridColumnService', 'GridStateService',
];

/**
Expand All @@ -25,7 +25,6 @@ function CashPaymentRegistryController(
var reversedBackgroundColor = { 'background-color' : '#ffb3b3' };
var regularBackgroundColor = { 'background-color' : 'none' };
var cacheKey = 'payment-grid';


var gridColumns;
var columnDefs;
Expand Down Expand Up @@ -201,7 +200,7 @@ function CashPaymentRegistryController(
// the visibility of the cash registry's columns.
function openColumnConfigModal() {
gridColumns.openConfigurationModal();
};
}

startup();
}
3 changes: 1 addition & 2 deletions client/src/modules/inventory/configuration/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function InventoryConfigurationController() {
/** paths in the headercrumb */
vm.bcPaths = [
{ label : 'TREE.INVENTORY' },
{ label : 'TREE.INVENTORY_CONFIGURATION' }
{ label : 'TREE.INVENTORY_CONFIGURATION' },
];

}
34 changes: 17 additions & 17 deletions client/src/modules/inventory/inventory.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,49 @@ angular.module('bhima.routes')
views : {
'' : {
templateUrl : 'modules/inventory/configuration/configuration.html',
controller : 'InventoryConfigurationController as InventoryCtrl'
controller : 'InventoryConfigurationController as InventoryCtrl',
},
'groups@inventoryConfiguration' : {
templateUrl : 'modules/inventory/configuration/groups/groups.html',
controller : 'InventoryGroupsController as GroupsCtrl'
controller : 'InventoryGroupsController as GroupsCtrl',
},
'types@inventoryConfiguration' : {
templateUrl : 'modules/inventory/configuration/types/types.html',
controller : 'InventoryTypesController as TypesCtrl'
controller : 'InventoryTypesController as TypesCtrl',
},
'units@inventoryConfiguration' : {
templateUrl : 'modules/inventory/configuration/units/units.html',
controller : 'InventoryUnitsController as UnitsCtrl'
}
}
})
controller : 'InventoryUnitsController as UnitsCtrl',
},
},
})
.state('inventory', {
abstract : true,
url : '/inventory',
controller : 'InventoryListController as InventoryCtrl',
templateUrl : 'modules/inventory/list/list.html'
templateUrl : 'modules/inventory/list/list.html',
})
.state('inventory.create', {
url : '/create',
params : {
creating : { value : true }
},
onEnter :['$state', 'ModalService', onEnterFactory('create')],
onExit : ['$uibModalStack', closeModal]
creating : { value : true },
},
onEnter : ['$state', 'ModalService', onEnterFactory('create')],
onExit : ['$uibModalStack', closeModal],
})
.state('inventory.update', {
url : '/:uuid/update',
onEnter :['$state', 'ModalService', onEnterFactory('update')],
onExit : ['$uibModalStack', closeModal]
onEnter : ['$state', 'ModalService', onEnterFactory('update')],
onExit : ['$uibModalStack', closeModal],
})
.state('inventory.list', {
url: '/:uuid',
url : '/:uuid',
params : {
uuid : { squash : true, value : null },
created : false, // default for transitioning from child states
updated : false, // default for transitioning from child states
filters : null
}
filters : null,
},
});
// @TODO IMPLEMENT THEM
// .state('/inventory/types', {
Expand Down
27 changes: 12 additions & 15 deletions client/src/modules/inventory/inventory.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function InventoryService(Api, Groups, Units, Types, $uibModal) {
service.Groups = Groups;
service.Units = Units;
service.Types = Types;
service.openSearchModal = openSearchModal;
service.formatFilterParameters = formatFilterParameters;
service.openSearchModal = openSearchModal;
service.formatFilterParameters = formatFilterParameters;

/**
* @method openSearchModal
Expand All @@ -24,15 +24,15 @@ function InventoryService(Api, Groups, Units, Types, $uibModal) {
*/
function openSearchModal(params) {
return $uibModal.open({
templateUrl: 'modules/inventory/list/modals/search.modal.html',
size: 'md',
keyboard: false,
animation: false,
backdrop: 'static',
controller: 'InventoryServiceModalController as ModalCtrl',
templateUrl : 'modules/inventory/list/modals/search.modal.html',
size : 'md',
keyboard : false,
animation : false,
backdrop : 'static',
controller : 'InventoryServiceModalController as ModalCtrl',
resolve : {
params : function paramsProvider() { return params; }
}
},
}).result;
}

Expand All @@ -43,21 +43,18 @@ function InventoryService(Api, Groups, Units, Types, $uibModal) {
*/
function formatFilterParameters(params) {
var columns = [
{ field: 'group_uuid', displayName: 'FORM.LABELS.GROUP' },
{ field: 'text', displayName: 'FORM.LABELS.LABEL' }
{ field : 'group_uuid', displayName : 'FORM.LABELS.GROUP' },
{ field : 'text', displayName : 'FORM.LABELS.LABEL' },
];
// returns columns from filters
return columns.filter(function (column) {
var LIMIT_UUID_LENGTH = 6;
var value = params[column.field];

if (angular.isDefined(value)) {
column.value = value;

return true;
} else {
return false;
}
return false;
});
}

Expand Down
Loading

0 comments on commit 3a9974a

Please sign in to comment.