2325 - Search address
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-06-12 10:53:33 +02:00
parent a66cc4a36d
commit 48034b234f
8 changed files with 45 additions and 4 deletions

View File

@ -1,7 +1,7 @@
<form ng-submit="$ctrl.onSubmit()">
<vn-textfield
class="dense standout"
placeholder="{{::'Search by' | translate: {module: $ctrl.baseState} }}"
placeholder="{{::$ctrl.placeholder | translate}}"
ng-model="$ctrl.searchString">
<prepend>
<vn-icon

View File

@ -21,6 +21,7 @@ export default class Searchbar extends Component {
constructor($element, $) {
super($element, $);
this.searchState = '.';
this.placeholder = 'Search';
this.autoState = true;
this.deregisterCallback = this.$transitions.onSuccess(
@ -35,6 +36,9 @@ export default class Searchbar extends Component {
}
this.searchState = `${this.baseState}.index`;
this.placeholder = this.$translate.instant('Search by', {
module: this.baseState
});
}
this.fetchStateFilter(this.autoLoad);
@ -293,7 +297,8 @@ ngModule.vnComponent('vnSearchbar', {
stateParams: '&?',
model: '<?',
exprBuilder: '&?',
fetchParams: '&?'
fetchParams: '&?',
placeholder: '@?'
}
});

View File

@ -6,6 +6,15 @@
data="$ctrl.addresses"
auto-load="true">
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
placeholder="Search by address"
info="You can search by address id or name"
model="model"
expr-builder="$ctrl.exprBuilder(param, value)"
auto-state="false">
</vn-searchbar>
</vn-portal>
<vn-data-viewer
model="model"
class="vn-w-md">
@ -35,7 +44,7 @@
</vn-none>
<vn-one
style="overflow: hidden; min-width: 14em;">
<div class="ellipsize"><b>{{::address.nickname}}</b></div>
<div class="ellipsize"><b>{{::address.nickname}} - #{{::address.id}}</b></div>
<div class="ellipsize" name="street">{{::address.street}}</div>
<div class="ellipsize">{{::address.city}}, {{::address.province.name}}</div>
<div class="ellipsize">

View File

@ -68,6 +68,15 @@ class Controller extends Section {
return this.isDefaultAddress(b) - this.isDefaultAddress(a);
});
}
exprBuilder(param, value) {
switch (param) {
case 'search':
return /^\d+$/.test(value)
? {id: value}
: {nickname: {like: `%${value}%`}};
}
}
}
Controller.$inject = ['$element', '$scope'];

View File

@ -67,5 +67,19 @@ describe('Client', () => {
expect(controller.addresses[0].id).toEqual(123);
});
});
describe('exprBuilder()', () => {
it('should return a filter based on a search by id', () => {
const filter = controller.exprBuilder('search', '123');
expect(filter).toEqual({id: '123'});
});
it('should return a filter based on a search by name', () => {
const filter = controller.exprBuilder('search', 'Bruce Wayne');
expect(filter).toEqual({nickname: {like: '%Bruce Wayne%'}});
});
});
});
});

View File

@ -1,6 +1,8 @@
# Index
Set as default: Establecer como predeterminado
Active first to set as default: Active primero para marcar como predeterminado
Search by address: Buscar por consignatario
You can search by address id or name: Puedes buscar por el id o nombre del consignatario
# Edit
Enabled: Activo
Is equalizated: Recargo de equivalencia

View File

@ -10,6 +10,7 @@
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar
placeholder="Search by weekly ticket"
info="Search weekly ticket by id or client id"
auto-state="false"
model="model">

View File

@ -2,4 +2,5 @@ Ticket ID: ID Ticket
Weekly tickets: Tickets programados
You are going to delete this weekly ticket: Vas a eliminar este ticket programado
This ticket will be removed from weekly tickets! Continue anyway?: Este ticket se eliminará de tickets programados! ¿Continuar de todas formas?
Search weekly ticket by id or client id: Busca tickets programados por el identificador o el identificador del cliente
Search weekly ticket by id or client id: Busca tickets programados por el identificador o el identificador del cliente
Search by weekly ticket: Buscar por tickets programados