Skip to content

Commit

Permalink
Add attention filter for product reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 27, 2024
1 parent b828544 commit 80186ac
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
73 changes: 43 additions & 30 deletions assets/vue/ProductReviews.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,47 @@
&nbsp;entries</label
>
</div>
<div class="form-check mb-2 mr-sm-4">
<input
v-model="params.patent"
@change="gotoPage(1)"
type="checkbox"
class="form-check form-check-inline"
id="cavil-pkg-patent"
/>
<label for="cavil-pkg-patent">Patent</label>
</div>
<div class="form-check mb-2 mr-sm-4">
<input
v-model="params.trademark"
@change="gotoPage(1)"
type="checkbox"
class="form-check form-check-inline"
id="cavil-pkg-trademark"
/>
<label for="cavil-pkg-trademark">Trademark</label>
</div>
<div class="form-check mb-2 mr-sm-4">
<input
v-model="params.exportRestricted"
@change="gotoPage(1)"
type="checkbox"
class="form-check form-check-inline"
id="cavil-pkg-export-restricted"
/>
<label for="cavil-pkg-export-restricted">Export Restricted</label>
<div class="form-group">
<div class="form-check mb-2 mr-sm-4">
<input
v-model="params.patent"
@change="gotoPage(1)"
type="checkbox"
class="form-check form-check-inline"
id="cavil-pkg-patent"
/>
<label for="cavil-pkg-patent">Patent</label>
</div>
<div class="form-check mb-2 mr-sm-4">
<input
v-model="params.trademark"
@change="gotoPage(1)"
type="checkbox"
class="form-check form-check-inline"
id="cavil-pkg-trademark"
/>
<label for="cavil-pkg-trademark">Trademark</label>
</div>
<div class="form-check mb-2 mr-sm-4">
<input
v-model="params.exportRestricted"
@change="gotoPage(1)"
type="checkbox"
class="form-check form-check-inline"
id="cavil-pkg-export-restricted"
/>
<label for="cavil-pkg-export-restricted">Export Restricted</label>
</div>
<div class="form-check mb-2 mr-sm-4">
<input
v-model="params.attention"
@change="gotoPage(1)"
type="checkbox"
class="form-check form-check-inline"
id="cavil-pkg-attention"
/>
<label for="cavil-pkg-attention">Needs Attention</label>
</div>
</div>
</form>
</div>
Expand Down Expand Up @@ -119,6 +131,7 @@ export default {
const params = getParams({
limit: 10,
offset: 0,
attention: false,
patent: false,
trademark: false,
exportRestricted: false,
Expand Down Expand Up @@ -173,7 +186,7 @@ export default {
}
},
watch: {
...genParamWatchers('limit', 'offset', 'patent', 'trademark', 'exportRestricted'),
...genParamWatchers('limit', 'offset', 'attention', 'patent', 'trademark', 'exportRestricted'),
filter: function (val) {
this.params.filter = val;
this.params.offset = 0;
Expand Down
3 changes: 3 additions & 0 deletions lib/Cavil/Controller/Pagination.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ sub product_reviews ($self) {
my $v = $self->validation;
$v->optional('limit')->num;
$v->optional('offset')->num;
$v->optional('attention');
$v->optional('patent');
$v->optional('trademark');
$v->optional('exportRestricted');
$v->optional('filter');
return $self->reply->json_validation_error if $v->has_error;
my $limit = $v->param('limit') // 10;
my $offset = $v->param('offset') // 0;
my $attention = $v->param('attention') // 'false';
my $patent = $v->param('patent') // 'false';
my $trademark = $v->param('trademark') // 'false';
my $export_restricted = $v->param('exportRestricted') // 'false';
Expand All @@ -85,6 +87,7 @@ sub product_reviews ($self) {
{
limit => $limit,
offset => $offset,
attention => $attention,
patent => $patent,
trademark => $trademark,
export_restricted => $export_restricted,
Expand Down
7 changes: 6 additions & 1 deletion lib/Cavil/Model/Packages.pm
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ sub paginate_product_reviews ($self, $name, $options) {

return paginate([], $options) unless my $product = $db->select('bot_products', 'id', {name => $name})->hash;

my $attention = '';
if ($options->{attention} eq 'true') {
$attention = "AND state IN ('unacceptable', 'new')";
}

my $search = '';
if (length($options->{search}) > 0) {
my $quoted = $db->dbh->quote("\%$options->{search}\%");
Expand Down Expand Up @@ -245,7 +250,7 @@ sub paginate_product_reviews ($self, $name, $options) {
EXTRACT(EPOCH FROM unpacked) as unpacked_epoch, EXTRACT(EPOCH FROM indexed) as indexed_epoch, state,
checksum, COUNT(*) OVER() AS total
FROM bot_package_products JOIN bot_packages ON (bot_packages.id = bot_package_products.package)
WHERE bot_package_products.product = ? $search $patent $trademark $export_restricted
WHERE bot_package_products.product = ? $search $attention $patent $trademark $export_restricted
ORDER BY bot_packages.id DESC
LIMIT ? OFFSET ?
}, $product->{id}, $options->{limit}, $options->{offset}
Expand Down

0 comments on commit 80186ac

Please sign in to comment.