Skip to content

Commit

Permalink
Enable caching of entry date, expiration date, and tags in lots search
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcameron committed Jan 8, 2021
1 parent fcdf5d5 commit 6b78180
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 16 deletions.
21 changes: 11 additions & 10 deletions client/src/modules/stock/lots/modals/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<bh-clear on-clear="$ctrl.clear('depot_uuid')"></bh-clear>
</bh-depot-select>

<!-- Inventaire -->
<!-- Inventory -->
<bh-inventory-select
inventory-uuid="$ctrl.searchQueries.inventory_uuid"
on-select-callback="$ctrl.onSelectInventory(inventory)"
Expand All @@ -51,20 +51,13 @@
</div>
</div>

<!-- tags -->
<bh-tag-select
tag-uuids="$ctrl.searchQueries.tags"
on-select-callback="$ctrl.onSelectTags(tags)">
<bh-clear on-clear="$ctrl.clear('tags')"></bh-clear>
</bh-tag-select>

<!--entry date -->
<bh-date-interval
label="STOCK.ENTRY_DATE"
date-id="entry-date"
date-from="$ctrl.searchQueries.entry_date_from"
date-to="$ctrl.searchQueries.entry_date_to"
mode="clean">
on-change="$ctrl.onEntryDate(dateFrom, dateTo)">
</bh-date-interval>

<!-- expiration date -->
Expand All @@ -73,7 +66,7 @@
date-id="expiration-date"
date-from="$ctrl.searchQueries.expiration_date_from"
date-to="$ctrl.searchQueries.expiration_date_to"
mode="clean">
on-change="$ctrl.onExpirationDate(dateFrom, dateTo)">
</bh-date-interval>

<bh-yes-no-radios
Expand All @@ -94,6 +87,14 @@
on-change-callback="$ctrl.onToggleExpiryRisk(value)">
<bh-clear on-clear="$ctrl.clear('is_expiry_risk')"></bh-clear>
</bh-yes-no-radios>

<!-- tags -->
<bh-tag-select
tag-uuids="$ctrl.searchQueries.tags"
on-select-callback="$ctrl.onSelectTags(tags)">
<bh-clear on-clear="$ctrl.clear('tags')"></bh-clear>
</bh-tag-select>

</div>
</uib-tab>

Expand Down
63 changes: 57 additions & 6 deletions client/src/modules/stock/lots/modals/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function SearchLotsModalController(data, util, Store, Instance, Periods, Stock,
const searchQueryOptions = [
'depot_uuid', 'inventory_uuid', 'group_uuid', 'label', 'entry_date_from',
'entry_date_to', 'expiration_date_from', 'expiration_date_to',
'is_expired', 'is_expiry_risk',
'is_expired', 'is_expiry_risk', 'tags',
];

// displayValues will be an id:displayValue pair
Expand All @@ -37,11 +37,6 @@ function SearchLotsModalController(data, util, Store, Instance, Periods, Stock,
});
};

vm.onSelectTags = tags => {
vm.searchQueries.tags = tags;
displayValues.tags = tags.map(t => t.name).join(',');
};

// custom filter depot_uuid - assign the value to the params object
vm.onSelectDepot = function onSelectDepot(depot) {
vm.searchQueries.depot_uuid = depot.uuid;
Expand Down Expand Up @@ -86,6 +81,28 @@ function SearchLotsModalController(data, util, Store, Instance, Periods, Stock,
displayValues.group_uuid = group.name;
};

// Save the entry dates
vm.onEntryDate = (dateFrom, dateTo) => {
vm.searchQueries.entry_date_from = dateFrom;
displayValues.entry_date_from = dateFrom;
vm.searchQueries.entry_date_to = dateTo;
displayValues.entry_date_to = dateTo;
};

// Save the expiration dates
vm.onExpirationDate = (dateFrom, dateTo) => {
vm.searchQueries.expiration_date_from = dateFrom;
displayValues.expiration_date_from = dateFrom;
vm.searchQueries.expiration_date_to = dateTo;
displayValues.expiration_date_to = dateTo;
};

// Save the Tags
vm.onSelectTags = tags => {
vm.searchQueries.tags = tags;
displayValues.tags = tags.map(t => t.name).join(',');
};

// deletes a filter from the custom filter object,
// this key will no longer be written to changes on exit
vm.clear = function clear(key) {
Expand All @@ -102,10 +119,44 @@ function SearchLotsModalController(data, util, Store, Instance, Periods, Stock,
vm.defaultQueries.limit = data.limit;
}

if (data.entry_date_from) {
vm.defaultQueries.entry_date_from = data.entry_date_from;
}
if (data.entry_date_to) {
vm.defaultQueries.entry_date_to = data.entry_date_to;
}

if (data.expiration_date_from) {
vm.defaultQueries.expiration_date_from = data.expiration_date_from;
}
if (data.expiration_date_to) {
vm.defaultQueries.expiration_date_to = data.expiration_date_to;
}

if (data.tags) {
vm.defaultQueries.tags = data.tags.map(t => t.name).join(',');
}

vm.cancel = () => Instance.dismiss();

vm.submit = () => {
const loggedChanges = SearchModal.getChanges(vm.searchQueries, changes, displayValues, lastDisplayValues);

// The following work-around is necessary to deal with the case where you
// select a tag but then delete it before clicking [Submit]; the element
// has an empty array so it needs to be deleted. There probably is a
// cleaner way to do this.
// There may be a bug in bhTagSelect that is causing this problem.
// @jmcameron 2021-01-08
loggedChanges.some((elt, i) => {
if (elt.key === 'tags') {
if (elt.value.length === 0) {
delete loggedChanges[i];
}
}
return elt.key === 'tags';
});

return Instance.close(loggedChanges);
};
}

0 comments on commit 6b78180

Please sign in to comment.