add panel-search
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-03-16 13:02:48 +01:00
parent 2d4f182fe6
commit 26f77ca07e
5 changed files with 136 additions and 2 deletions

View File

@ -1,4 +1,6 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
const buildFilter = require('vn-loopback/util/filter').buildFilter;
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
module.exports = Self => {
Self.remoteMethodCtx('filter', {
@ -9,7 +11,31 @@ module.exports = Self => {
arg: 'filter',
type: 'object',
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
http: {source: 'query'}
},
{
arg: 'search',
type: 'string',
description: `If it's and integer searchs by invoiceInFk, otherwise it searchs by the supplierName`,
},
{
arg: 'agencyFk',
type: 'integer',
description: 'The agency route name',
},
{
arg: 'agencyAgreement',
type: 'integer',
description: 'The agencyMode id',
},
{
arg: 'from',
type: 'date',
description: 'The to date filter',
},
{
arg: 'to',
type: 'date',
description: 'The to date filter',
}
],
returns: {
@ -29,6 +55,25 @@ module.exports = Self => {
if (typeof options == 'object')
Object.assign(myOptions, options);
const where = buildFilter(ctx.args, (param, value) => {
switch (param) {
case 'search':
return /^\d+$/.test(value)
? {'fp.itemFk': {inq: value}}
: {'it.code': {like: `%${value}%`}};
case 'agencyFk':
return {'it.categoryFk': value};
case 'agencyAgreement':
return {'it.workerFk': value};
case 'from':
case 'to':
param = `fp.${param}`;
return {[param]: value};
}
});
filter = mergeFilters(filter, {where});
const stmts = [];
const stmt = new ParameterizedSQL(
`SELECT *
@ -61,7 +106,8 @@ module.exports = Self => {
) a`
);
stmt.merge(conn.makeSuffix(filter));
stmt.merge(conn.makeWhere(filter.where));
stmt.merge(conn.makePagination(filter));
const agencyTerm = stmts.push(stmt) - 1;
const sql = ParameterizedSQL.join(stmts, ';');

View File

@ -0,0 +1,51 @@
<div class="search-panel">
<form class="vn-pa-lg" ng-submit="$ctrl.onSearch()">
<vn-horizontal>
<vn-textfield
vn-one
label="General search"
ng-model="filter.search"
vn-focus>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-one
url="AgencyModes"
label="Agency route"
show-field="name"
value-field="name"
ng-model="filter.agencyFk">
</vn-autocomplete>
<vn-autocomplete vn-one
url="Agencies"
label="Agency Agreement"
show-field="name"
value-field="name"
ng-model="filter.agencyAgreement">
</vn-autocomplete>
</vn-horizontal>
<section class="vn-px-md">
<vn-horizontal class="manifold-panel vn-pa-md">
<vn-date-picker
vn-one
label="From"
ng-model="filter.from"
on-change="$ctrl.from = value">
</vn-date-picker>
<vn-date-picker
vn-one
label="To"
ng-model="filter.to"
on-change="$ctrl.to = value">
</vn-date-picker>
<vn-icon color-marginal
icon="info"
vn-tooltip="Cannot choose a range of dates and days onward at the same time">
</vn-icon>
</vn-horizontal>
</section>
<vn-horizontal class="vn-px-lg vn-pb-lg vn-mt-lg">
<vn-submit label="Search"></vn-submit>
</vn-horizontal>
</form>
</div>

View File

@ -0,0 +1,27 @@
import ngModule from '../module';
import SearchPanel from 'core/components/searchbar/search-panel';
class Controller extends SearchPanel {
get from() {
return this._from;
}
set from(value) {
this._from = value;
this.filter.scopeDays = null;
}
get to() {
return this._to;
}
set to(value) {
this._to = value;
this.filter.scopeDays = null;
}
}
ngModule.vnComponent('vnAgencyTermSearchPanel', {
template: require('./index.html'),
controller: Controller
});

View File

@ -5,6 +5,16 @@
data="agencyTerms"
auto-load="true">
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
auto-state="false"
panel="vn-agency-term-search-panel"
info="Search prices by invoiceIn or autonomous"
placeholder="Search autonomous"
filter="{}"
model="model">
</vn-searchbar>
</vn-portal>
<vn-card>
<smart-table
model="model"