diff --git a/front/core/components/searchbar/searchbar.js b/front/core/components/searchbar/searchbar.js
index f8099caf1..b9c761874 100644
--- a/front/core/components/searchbar/searchbar.js
+++ b/front/core/components/searchbar/searchbar.js
@@ -21,17 +21,23 @@ export default class Searchbar extends Component {
constructor($element, $) {
super($element, $);
this.searchState = '.';
+ this.autoState = true;
- let criteria = {};
this.deregisterCallback = this.$transitions.onSuccess(
- criteria, () => this.onStateChange());
+ {}, transition => this.onStateChange(transition));
}
$postLink() {
- this.onStateChange();
+ if (this.autoState) {
+ if (!this.baseState) {
+ let stateParts = this.$state.current.name.split('.');
+ this.baseState = stateParts[0];
+ }
- if (this.$state.is(this.searchState) && this.filter !== null)
- this.doSearch();
+ this.searchState = `${this.baseState}.index`;
+ }
+
+ this.fetchStateFilter(this.autoLoad);
}
$onDestroy() {
@@ -62,11 +68,18 @@ export default class Searchbar extends Component {
if (value == null) this.params = [];
}
- onStateChange() {
- let filter = null;
- let isIndex = this.$state.is(this.searchState);
+ onStateChange(transition) {
+ if (!this.element.parentNode
+ || transition == this.transition)
+ return;
+
+ this.fetchStateFilter();
+ }
+
+ fetchStateFilter(autoLoad) {
+ if (this.$state.is(this.searchState)) {
+ let filter = null;
- if (isIndex) {
if (this.$params.q) {
try {
filter = JSON.parse(this.$params.q);
@@ -75,15 +88,12 @@ export default class Searchbar extends Component {
}
}
- focus(this.element.querySelector('vn-textfield input'));
- }
+ if (!filter && autoLoad)
+ filter = {};
- this.filter = filter;
-
- if (isIndex)
- this.doSearch();
- else if (this.model)
- this.model.clear();
+ this.doSearch(filter, 'state');
+ } else
+ this.clearSearch();
}
openPanel(event) {
@@ -112,21 +122,16 @@ export default class Searchbar extends Component {
this.$.popover.hide();
filter = compact(filter);
filter = filter != null ? filter : {};
- this.goSearch(filter);
+ this.doSearch(filter, 'panel');
}
onSubmit() {
- this.goSearch(this.fromBar());
+ this.doSearch(this.fromBar(), 'bar');
}
removeParam(index) {
this.params.splice(index, 1);
- this.goSearch(this.fromBar());
- }
-
- goSearch(filter) {
- this.filter = filter;
- this.doSearch();
+ this.doSearch(this.fromBar(), 'bar');
}
fromBar() {
@@ -180,75 +185,94 @@ export default class Searchbar extends Component {
});
}
- doSearch() {
- let filter = this.filter;
- if (filter == null && this.autoload)
- filter = {};
-
- if (this.onSearch)
- this.onSearch({$params: filter});
-
- if (this.model) {
- if (filter !== null) {
- let where = buildFilter(filter,
- (param, value) => this.exprBuilder({param, value}));
-
- let userParams = {};
- let hasParams = false;
-
- if (this.paramBuilder) {
- for (let param in filter) {
- let value = filter[param];
- if (value == null) continue;
- let expr = this.paramBuilder({param, value});
- if (expr) {
- Object.assign(userParams, expr);
- hasParams = true;
- }
- }
- }
- this.model.applyFilter(
- where ? {where} : null,
- hasParams ? userParams : null
- ).then(() => this.onModelFilter());
- } else
- this.model.clear();
- }
+ clearSearch() {
+ if (!this.filter) return;
+ if (this.model) this.model.clear();
+ this.filter = null;
}
- onModelFilter() {
+ doSearch(filter, source) {
+ let promise;
+
+ if (this.model)
+ promise = this.modelSearch(filter);
+ else if (this.onSearch)
+ promise = this.onSearch({$params: filter});
+
+ promise = promise || this.$q.resolve();
+ promise.then(data => this.onFilter(filter, source, data));
+ }
+
+ modelSearch(filter) {
+ if (filter === null) {
+ this.model.clear();
+ return this.$q.resolve();
+ }
+
+ let where = null;
+ let params = null;
+
+ if (this.exprBuilder) {
+ where = buildFilter(filter,
+ (param, value) => this.exprBuilder({param, value}));
+ } else {
+ params = Object.assign({}, filter);
+
+ if (this.fetchParams)
+ params = this.fetchParams({$params: params});
+ }
+
+ return this.model.applyFilter(where ? {where} : null, params)
+ .then(() => this.model.data);
+ }
+
+ onFilter(filter, source, data) {
+ let state;
let params;
let opts;
- let data = this.model.data;
- let currentState = this.$state.current.name;
- let stateParts = currentState.split('.');
- let baseState = stateParts[0];
- let subState = stateParts[1];
- if (this.goState && data && data.length == 1) {
+ if (data && data.length == 1 && this.autoState && source != 'state') {
+ let baseDepth = this.baseState.split('.').length;
+ let stateParts = this.$state.current.name
+ .split('.')
+ .slice(baseDepth);
+
+ let subState = stateParts[0];
+
switch (subState) {
- case 'index':
- subState = 'card.summary';
- break;
case 'card':
- subState += `.${stateParts[2]}`;
+ subState += `.${stateParts[1]}`;
+ if (stateParts.length >= 3)
+ subState += '.index';
break;
+ default:
+ subState = 'card.summary';
}
- if (this.goStateParams)
- params = this.goStateParams({$row: data[0]});
+ if (this.singleParams)
+ params = this.singleParams({$row: data[0]});
+
+ state = `${this.baseState}.${subState}`;
+ filter = null;
} else {
- if (subState == 'index')
+ state = this.searchState;
+
+ if (filter)
+ params = {q: JSON.stringify(filter)};
+ if (this.$state.is(state))
opts = {location: 'replace'};
- subState = `index`;
- params = {q: JSON.stringify(this.filter)};
}
- this.$state.go(`${baseState}.${subState}`, params, opts);
+ this.filter = filter;
+
+ if (source != 'state')
+ this.transition = this.$state.go(state, params, opts).transition;
+ if (source != 'bar')
+ focus(this.element.querySelector('vn-textfield input'));
}
- exprBuilder(param, value) {
- return {[param]: value};
+ singleParams(params) {
+ return {id: params.$row.id};
}
}
@@ -256,27 +280,29 @@ ngModule.vnComponent('vnSearchbar', {
controller: Searchbar,
template: require('./searchbar.html'),
bindings: {
- searchState: '@?',
filter: '',
suggestedFilter: '',
panel: '@',
info: '@?',
- model: '',
onSearch: '&?',
+ model: '',
exprBuilder: '&?',
- paramBuilder: '&?',
- goState: '@?',
- goStateParams: '&?'
+ baseState: '@?',
+ autoState: '',
+ singleParams: '&?',
+ fetchParams: '&?'
}
});
class AutoSearch {
constructor(vnSlotService) {
- let searchbar = vnSlotService.getContent('topbar');
- if (searchbar && searchbar.$ctrl instanceof Searchbar) {
+ this.vnSlotService = vnSlotService;
+ }
+
+ $postLink() {
+ let searchbar = this.vnSlotService.getContent('topbar');
+ if (searchbar && searchbar.$ctrl instanceof Searchbar)
this.model = searchbar.$ctrl.model;
- console.log(this.model.data);
- }
}
}
AutoSearch.$inject = ['vnSlotService'];
diff --git a/front/salix/module.js b/front/salix/module.js
index 7324ee922..34e53b8bd 100644
--- a/front/salix/module.js
+++ b/front/salix/module.js
@@ -67,7 +67,7 @@ export function config($translatePartialLoaderProvider, $httpProvider, $compileP
.cssClassDirectivesEnabled(false);
let env = process.env.NODE_ENV;
- if (!env || env == 'development')
+ if (env && env !== 'development')
$compileProvider.debugInfoEnabled(false);
}
ngModule.config(config);
diff --git a/modules/claim/front/index/index.html b/modules/claim/front/index/index.html
index 383e55a9d..0f74e4a6c 100644
--- a/modules/claim/front/index/index.html
+++ b/modules/claim/front/index/index.html
@@ -1,13 +1,5 @@
-
-
+ model="model">
{{::claim.id}}
diff --git a/modules/claim/front/index/index.js b/modules/claim/front/index/index.js
index 21464fea9..1e9724987 100644
--- a/modules/claim/front/index/index.js
+++ b/modules/claim/front/index/index.js
@@ -43,13 +43,6 @@ export default class Controller {
onDescriptorLoad() {
this.$.popover.relocate();
}
-
- onSearch(params) {
- if (params)
- this.$.model.applyFilter(null, params);
- else
- this.$.model.clear();
- }
}
Controller.$inject = ['$scope'];
diff --git a/modules/claim/front/main/index.html b/modules/claim/front/main/index.html
index e733162b1..c66c02f14 100644
--- a/modules/claim/front/main/index.html
+++ b/modules/claim/front/main/index.html
@@ -1,8 +1,15 @@
+
+
+ info="Search claim by id or client name"
+ model="model">
diff --git a/modules/client/front/index/index.html b/modules/client/front/index/index.html
index f3c3fb728..a501b68cf 100644
--- a/modules/client/front/index/index.html
+++ b/modules/client/front/index/index.html
@@ -1,13 +1,6 @@
-
-
+
+ model="model">
diff --git a/modules/client/front/index/index.js b/modules/client/front/index/index.js
index 51dd41dea..054944f9d 100644
--- a/modules/client/front/index/index.js
+++ b/modules/client/front/index/index.js
@@ -7,33 +7,6 @@ export default class Controller {
this.clientSelected = null;
}
- exprBuilder(param, value) {
- switch (param) {
- case 'search':
- return /^\d+$/.test(value)
- ? {id: value}
- : {name: {like: `%${value}%`}};
- case 'phone':
- return {
- or: [
- {phone: value},
- {mobile: value}
- ]
- };
- case 'name':
- case 'socialName':
- case 'city':
- return {[param]: {like: `%${value}%`}};
- case 'email':
- return {[param]: {like: `%${value}%`}};
- case 'id':
- case 'fi':
- case 'postcode':
- case 'salesPersonFk':
- return {[param]: value};
- }
- }
-
openSummary(client, event) {
if (event.defaultPrevented) return;
event.preventDefault();
diff --git a/modules/client/front/main/index.html b/modules/client/front/main/index.html
index 1ae1d211b..cab796c1f 100644
--- a/modules/client/front/main/index.html
+++ b/modules/client/front/main/index.html
@@ -1,8 +1,16 @@
+
+
+ info="Search client by id or name"
+ model="model"
+ expr-builder="$ctrl.exprBuilder(param, value)">
diff --git a/modules/client/front/main/index.js b/modules/client/front/main/index.js
index 890165a19..cae95c1dd 100644
--- a/modules/client/front/main/index.js
+++ b/modules/client/front/main/index.js
@@ -1,7 +1,33 @@
import ngModule from '../module';
import ModuleMain from 'salix/components/module-main';
-export default class Client extends ModuleMain {}
+export default class Client extends ModuleMain {
+ exprBuilder(param, value) {
+ switch (param) {
+ case 'search':
+ return /^\d+$/.test(value)
+ ? {id: value}
+ : {name: {like: `%${value}%`}};
+ case 'phone':
+ return {
+ or: [
+ {phone: value},
+ {mobile: value}
+ ]
+ };
+ case 'name':
+ case 'socialName':
+ case 'city':
+ case 'email':
+ return {[param]: {like: `%${value}%`}};
+ case 'id':
+ case 'fi':
+ case 'postcode':
+ case 'salesPersonFk':
+ return {[param]: value};
+ }
+ }
+}
ngModule.vnComponent('vnClient', {
controller: Client,
diff --git a/modules/entry/front/index/index.html b/modules/entry/front/index/index.html
index 60bbe46d5..9dfaa7e34 100644
--- a/modules/entry/front/index/index.html
+++ b/modules/entry/front/index/index.html
@@ -1,13 +1,5 @@
-
-
+ model="model">
-
diff --git a/modules/entry/front/index/index.js b/modules/entry/front/index/index.js
index 53d2f45e0..7368cc05e 100644
--- a/modules/entry/front/index/index.js
+++ b/modules/entry/front/index/index.js
@@ -5,13 +5,6 @@ export default class Controller {
this.$ = $scope;
}
- onSearch(params) {
- if (params)
- this.$.model.applyFilter(null, params);
- else
- this.$.model.clear();
- }
-
showTravelDescriptor(event, travelFk) {
if (event.defaultPrevented) return;
event.preventDefault();
diff --git a/modules/entry/front/main/index.html b/modules/entry/front/main/index.html
index 44b1b2b4e..07009b7b0 100644
--- a/modules/entry/front/main/index.html
+++ b/modules/entry/front/main/index.html
@@ -1,8 +1,14 @@
+
+
+ info="Search entrys by id"
+ model="model">
diff --git a/modules/invoiceOut/front/index/index.html b/modules/invoiceOut/front/index/index.html
index c798b8bc6..ad7c363ce 100644
--- a/modules/invoiceOut/front/index/index.html
+++ b/modules/invoiceOut/front/index/index.html
@@ -1,16 +1,9 @@
-
-
+ model="model">
+ class="vn-w-md">
@@ -27,7 +20,7 @@
-
{{::invoiceOut.ref | dashIfEmpty}}
diff --git a/modules/invoiceOut/front/index/index.js b/modules/invoiceOut/front/index/index.js
index dd8219fae..46ad6bc3f 100644
--- a/modules/invoiceOut/front/index/index.js
+++ b/modules/invoiceOut/front/index/index.js
@@ -32,13 +32,6 @@ export default class Controller {
event.preventDefault();
event.stopImmediatePropagation();
}
-
- onSearch(params) {
- if (params)
- this.$.model.applyFilter(null, params);
- else
- this.$.model.clear();
- }
}
Controller.$inject = ['$scope', 'vnToken'];
diff --git a/modules/invoiceOut/front/main/index.html b/modules/invoiceOut/front/main/index.html
index 18e72ed5e..df65fd217 100644
--- a/modules/invoiceOut/front/main/index.html
+++ b/modules/invoiceOut/front/main/index.html
@@ -1,8 +1,14 @@
+
+
+ info="Search invoices by reference"
+ model="model">
diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html
index c83ce5ed1..154c64bb1 100644
--- a/modules/item/front/index/index.html
+++ b/modules/item/front/index/index.html
@@ -1,12 +1,5 @@
-
-
+ model="model">
-
diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js
index 087021577..968c7b027 100644
--- a/modules/item/front/index/index.js
+++ b/modules/item/front/index/index.js
@@ -21,13 +21,6 @@ class Controller {
event.stopImmediatePropagation();
}
- onSearch(params) {
- if (params)
- this.$.model.applyFilter(null, params);
- else
- this.$.model.clear();
- }
-
showItemDescriptor(event, itemFk) {
if (event.defaultPrevented) return;
@@ -39,7 +32,6 @@ class Controller {
this.$.itemDescriptor.show();
}
-
showWorkerDescriptor(event, workerFk) {
if (event.defaultPrevented) return;
diff --git a/modules/item/front/main/index.html b/modules/item/front/main/index.html
index 758bfd55e..55ef00b75 100644
--- a/modules/item/front/main/index.html
+++ b/modules/item/front/main/index.html
@@ -1,9 +1,16 @@
+
+
+ suggested-filter="{isActive: true}"
+ model="model">
diff --git a/modules/order/front/index/index.html b/modules/order/front/index/index.html
index 20dd4a231..b16a1b25d 100644
--- a/modules/order/front/index/index.html
+++ b/modules/order/front/index/index.html
@@ -1,12 +1,6 @@
-
-
+
+ model="model">
-
+
{{::order.id}}
diff --git a/modules/order/front/index/index.js b/modules/order/front/index/index.js
index 8cf289796..10940eb27 100644
--- a/modules/order/front/index/index.js
+++ b/modules/order/front/index/index.js
@@ -8,13 +8,6 @@ export default class Controller {
this.ticketSelected = null;
}
- onSearch(params) {
- if (params)
- this.$.model.applyFilter(null, params);
- else
- this.$.model.clear();
- }
-
showClientDescriptor(event, clientFk) {
this.$.clientDescriptor.clientFk = clientFk;
this.$.clientDescriptor.parent = event.target;
diff --git a/modules/order/front/main/index.html b/modules/order/front/main/index.html
index 09d498599..1aca6a48d 100644
--- a/modules/order/front/main/index.html
+++ b/modules/order/front/main/index.html
@@ -1,8 +1,15 @@
+
+
+ info="Search orders by id"
+ model="model">
diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html
index c01112928..ab8b1364b 100644
--- a/modules/route/front/index/index.html
+++ b/modules/route/front/index/index.html
@@ -1,13 +1,5 @@
-
-
+ model="model">
-
{{::route.id | dashIfEmpty}}
diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js
index 8fdde810c..735581265 100644
--- a/modules/route/front/index/index.js
+++ b/modules/route/front/index/index.js
@@ -24,13 +24,6 @@ export default class Controller {
this.routeSelected = route;
this.$.summary.show();
}
-
- onSearch(params) {
- if (params)
- this.$.model.applyFilter(null, params);
- else
- this.$.model.clear();
- }
}
Controller.$inject = ['$scope', 'vnToken'];
diff --git a/modules/route/front/main/index.html b/modules/route/front/main/index.html
index f6e097b24..2be8ab467 100644
--- a/modules/route/front/main/index.html
+++ b/modules/route/front/main/index.html
@@ -1,9 +1,16 @@
+
+
+ filter="$ctrl.filter"
+ model="model">
diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html
index b303c3ae7..a0efea467 100644
--- a/modules/ticket/front/index/index.html
+++ b/modules/ticket/front/index/index.html
@@ -1,13 +1,5 @@
-
-
+ model="model">
-
diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js
index 05dc23c08..a4606bb72 100644
--- a/modules/ticket/front/index/index.js
+++ b/modules/ticket/front/index/index.js
@@ -38,30 +38,6 @@ export default class Controller {
this.$.balanceCreateDialog.description += description.join(', ');
}
- getScopeDates(days) {
- const today = new Date();
- today.setHours(0, 0, 0, 0);
-
- const daysOnward = new Date(today);
- daysOnward.setDate(today.getDate() + days);
- daysOnward.setHours(23, 59, 59, 999);
-
- return {from: today, to: daysOnward};
- }
-
- onSearch(params) {
- if (params) {
- if (typeof(params.scopeDays) === 'number')
- Object.assign(params, this.getScopeDates(params.scopeDays));
- // Set default params to 1 scope days
- else if (Object.entries(params).length == 0)
- params = this.getScopeDates(1);
-
- this.$.model.applyFilter(null, params);
- } else
- this.$.model.clear();
- }
-
goToLines(event, ticketFk) {
this.preventDefault(event);
let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true});
diff --git a/modules/ticket/front/main/index.html b/modules/ticket/front/main/index.html
index 7e058f45d..bcb77cca5 100644
--- a/modules/ticket/front/main/index.html
+++ b/modules/ticket/front/main/index.html
@@ -1,8 +1,15 @@
+
+
+ info="Search ticket by id or alias"
+ model="model"
+ fetch-params="$ctrl.fetchParams($params)">
diff --git a/modules/ticket/front/main/index.js b/modules/ticket/front/main/index.js
index d6100daa3..bd4718176 100644
--- a/modules/ticket/front/main/index.js
+++ b/modules/ticket/front/main/index.js
@@ -1,7 +1,25 @@
import ngModule from '../module';
import ModuleMain from 'salix/components/module-main';
-export default class Ticket extends ModuleMain {}
+export default class Ticket extends ModuleMain {
+ fetchParams($params) {
+ if (!Object.entries($params).length)
+ $params.scopeDays = 1;
+
+ if (typeof $params.scopeDays === 'number') {
+ const from = new Date();
+ from.setHours(0, 0, 0, 0);
+
+ const to = new Date(from.getTime());
+ to.setDate(to.getDate() + $params.scopeDays);
+ to.setHours(23, 59, 59, 999);
+
+ Object.assign($params, {from, to});
+ }
+
+ return $params;
+ }
+}
ngModule.vnComponent('vnTicket', {
controller: Ticket,
diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html
index 3af99eb6b..ba0272d3f 100644
--- a/modules/travel/front/index/index.html
+++ b/modules/travel/front/index/index.html
@@ -1,13 +1,6 @@
-
-
+
+ model="model">
+
+ info="Search travels by id"
+ model="model"
+ fetch-params="$ctrl.fetchParams($params)">
diff --git a/modules/travel/front/main/index.js b/modules/travel/front/main/index.js
index 3be713973..f04cc750d 100644
--- a/modules/travel/front/main/index.js
+++ b/modules/travel/front/main/index.js
@@ -1,7 +1,25 @@
import ngModule from '../module';
import ModuleMain from 'salix/components/module-main';
-export default class Travel extends ModuleMain {}
+export default class Travel extends ModuleMain {
+ fetchParams($params) {
+ if (!Object.entries($params).length)
+ $params.scopeDays = 1;
+
+ if (typeof $params.scopeDays === 'number') {
+ const shippedFrom = new Date();
+ shippedFrom.setHours(0, 0, 0, 0);
+
+ const shippedTo = new Date(shippedFrom.getTime());
+ shippedTo.setDate(shippedTo.getDate() + $params.scopeDays);
+ shippedTo.setHours(23, 59, 59, 999);
+
+ Object.assign($params, {shippedFrom, shippedTo});
+ }
+
+ return $params;
+ }
+}
ngModule.vnComponent('vnTravel', {
controller: Travel,
diff --git a/modules/worker/front/index/index.html b/modules/worker/front/index/index.html
index 56dde4609..dfab7f16a 100644
--- a/modules/worker/front/index/index.html
+++ b/modules/worker/front/index/index.html
@@ -1,12 +1,5 @@
-
-
+ model="model">
diff --git a/modules/worker/front/index/index.js b/modules/worker/front/index/index.js
index 1cc9a8f92..1b585f013 100644
--- a/modules/worker/front/index/index.js
+++ b/modules/worker/front/index/index.js
@@ -9,13 +9,6 @@ export default class Controller {
});
}
- onSearch(params) {
- if (params)
- this.$.model.applyFilter(null, params);
- else
- this.$.model.clear();
- }
-
preview(event, worker) {
if (event.defaultPrevented) return;
@@ -26,7 +19,6 @@ export default class Controller {
this.$.preview.show();
}
-
goToTimeControl(event, workerId) {
if (event.defaultPrevented) return;
@@ -34,6 +26,7 @@ export default class Controller {
event.stopPropagation();
this.$state.go('worker.card.timeControl', {id: workerId}, {absolute: true});
}
+
onMoreChange(callback) {
callback.call(this);
}
diff --git a/modules/worker/front/main/index.html b/modules/worker/front/main/index.html
index 826a7905f..51948fedf 100644
--- a/modules/worker/front/main/index.html
+++ b/modules/worker/front/main/index.html
@@ -1,8 +1,14 @@
+
+
+ info="Search workers by id, firstName, lastName or user name"
+ model="model">
diff --git a/modules/zone/front/location/index.html b/modules/zone/front/location/index.html
index 4b3523a1f..20755f916 100644
--- a/modules/zone/front/location/index.html
+++ b/modules/zone/front/location/index.html
@@ -4,25 +4,25 @@
filter="::$ctrl.filter">
-
+
+
-
-
-
-
-
-
-
+
+
+
+
+
diff --git a/modules/zone/front/main/index.html b/modules/zone/front/main/index.html
index d6e63a1a6..d5a2b2b38 100644
--- a/modules/zone/front/main/index.html
+++ b/modules/zone/front/main/index.html
@@ -6,13 +6,10 @@
+ expr-builder="$ctrl.exprBuilder(param, value)">