Skip to content

Commit

Permalink
Implement search by tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mbayopanda committed Aug 23, 2020
1 parent 9f31d34 commit e6f92d0
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client/src/js/components/bhTagSelect/bhTagSelect.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<span>{{$item.name}}</span>
</ui-select-match>

<ui-select-choices repeat="tag.uuid as tag in $ctrl.tags | filter: { 'name': $select.search }">
<ui-select-choices repeat="tag as tag in $ctrl.tags | filter: { 'name': $select.search }">
<span><i class="fa fa-circle" ng-style="$ctrl.getTagColor(tag)"></i> <span translate>{{ tag.name }}</span></span>
</ui-select-choices>
</ui-select>
Expand Down
10 changes: 3 additions & 7 deletions client/src/js/components/bhTagSelect/bhTagSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('bhima.components')
controller : TagSelectController,
transclude : true,
bindings : {
tagUuids : '<',
tagUuids : '<',
onSelectCallback : '&',
required : '<?',
label : '@?',
Expand Down Expand Up @@ -38,12 +38,8 @@ function TagSelectController(Tags, Notify) {
function loadTags() {
Tags.read(null)
.then(tags => {
if ($ctrl.tagUuids.length) {
const givenTags = $ctrl.tagUuids.map(e => e.uuid);
$ctrl.tags = tags.filter(e => givenTags.includes(e.uuid) === false);
} else {
$ctrl.tags = tags;
}
const identifiers = $ctrl.tagUuids.map(t => t.uuid);
$ctrl.tags = $ctrl.tagUuids.length ? tags.filter(t => identifiers.includes(t.uuid) === false) : tags;
})
.catch(Notify.handleError);
}
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/stock/StockFilterer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function StockFiltererService(Filters, AppCache, Periods, $httpParamSerializer,
{ key : 'service_uuid', label : 'STOCK.SERVICE' },
{ key : 'is_expired', label : 'STOCK.EXPIRED' },
{ key : 'tag_uuid', label : 'TAG.LABEL' },
{ key : 'tags', label : 'TAG.LABEL' },
{
key : 'dateFrom', label : 'FORM.LABELS.DATE', comparitor : '>', valueFilter : 'date',
},
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/stock/lots/modals/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<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 -->
Expand Down
7 changes: 3 additions & 4 deletions client/src/modules/stock/lots/modals/search.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ function SearchLotsModalController(data, util, Store, Instance, Periods, Stock,
});
};

vm.onSelectTags = tag => {
console.log(tag);
vm.searchQueries.tags = tag;
displayValues.tag_uuid = tag.name;
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
Expand Down
3 changes: 1 addition & 2 deletions server/controllers/stock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ function getLotFilters(parameters) {
filters.equals('tag_uuid', 'tags', 't');

// tags
filters.custom('tags',
't.uuid IN (?)');
filters.custom('tags', 't.uuid IN (?)', [params.tags]);

// NOTE(@jniles)
// is_expired is based off the server time, not off the client time.
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/stock/lots.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ async function update(req, res, next) {
// update tags
const transaction = db.transaction();
transaction.addQuery('DELETE FROM lot_tag WHERE lot_uuid = ?', [bid]);
tags.forEach(uuid => {
const binaryTagUuid = db.bid(uuid);
tags.forEach(t => {
const binaryTagUuid = db.bid(t.uuid);
transaction.addQuery('INSERT INTO lot_tag(lot_uuid, tag_uuid) VALUES (?, ?);', [bid, binaryTagUuid]);
});
await transaction.execute();
Expand Down

0 comments on commit e6f92d0

Please sign in to comment.