diff --git a/front/core/components/calendar/index.html b/front/core/components/calendar/index.html index 0efff24927..eb6d196bad 100644 --- a/front/core/components/calendar/index.html +++ b/front/core/components/calendar/index.html @@ -23,7 +23,7 @@
+ ng-click="$ctrl.selectWeekDay($event, day.index)"> {{::day.localeChar}}
@@ -38,7 +38,7 @@ on-last="$ctrl.repeatLast()">
+ ng-click="$ctrl.select($event, day)"> {{::day | date: 'd'}}
diff --git a/front/core/components/calendar/index.js b/front/core/components/calendar/index.js index 4afec0a9a9..96bc435dbb 100644 --- a/front/core/components/calendar/index.js +++ b/front/core/components/calendar/index.js @@ -127,10 +127,11 @@ export default class Calendar extends FormInput { /* * Day selection event */ - select(day) { + select($event, day) { if (!this.editable) return; this.change(day); this.emit('selection', { + $event: $event, $days: [day], $type: 'day' }); @@ -140,7 +141,7 @@ export default class Calendar extends FormInput { /* * WeekDay selection event */ - selectWeekDay(weekday) { + selectWeekDay($event, weekday) { if (!this.editable) return; let days = []; for (let day of this.days) { @@ -149,6 +150,7 @@ export default class Calendar extends FormInput { } this.field = days[0]; this.emit('selection', { + $event: $event, $days: days, $type: 'weekday', $weekday: weekday diff --git a/front/core/components/popover/index.js b/front/core/components/popover/index.js index 413f4d85fc..e209034a37 100644 --- a/front/core/components/popover/index.js +++ b/front/core/components/popover/index.js @@ -37,6 +37,21 @@ export default class Popover extends Popup { super.hide(); } + get parent() { + return this.__parent; + } + + set parent(value) { + this.__parent = value; + + if (!value) return; + + const parentRect = value.getBoundingClientRect(); + this.parentRect = {}; + for (let prop in parentRect) + this.parentRect[prop] = parentRect[prop]; + } + /** * Repositions the popover to a correct location relative to the parent. */ @@ -55,7 +70,7 @@ export default class Popover extends Popup { arrowStyle.top = ''; arrowStyle.bottom = ''; - let parentRect = this.parent.getBoundingClientRect(); + let parentRect = this.parentRect; let popoverRect = this.windowEl.getBoundingClientRect(); let arrowRect = arrow.getBoundingClientRect(); let clamp = (value, min, max) => Math.min(Math.max(value, min), max); diff --git a/front/core/mocks/popover.js b/front/core/mocks/popover.js new file mode 100644 index 0000000000..037e0963a8 --- /dev/null +++ b/front/core/mocks/popover.js @@ -0,0 +1,25 @@ +const popover = { + show: () => { + return { + then: callback => { + callback(); + } + }; + }, + hide: () => { + return { + then: callback => { + callback(); + } + }; + }, + relocate: () => { + return { + then: callback => { + callback(); + } + }; + } +}; + +module.exports = popover; diff --git a/modules/zone/front/calendar/index.html b/modules/zone/front/calendar/index.html index b1277cbe58..cfcebf3593 100644 --- a/modules/zone/front/calendar/index.html +++ b/modules/zone/front/calendar/index.html @@ -25,7 +25,7 @@ hide-contiguous="true" has-events="$ctrl.hasEvents($day)" get-class="$ctrl.getClass($day)" - on-selection="$ctrl.onSelection($days, $type, $weekday)" + on-selection="$ctrl.onSelection($event, $days, $type, $weekday)" class="vn-pa-md" style="min-width: 250px; flex: 1;"> diff --git a/modules/zone/front/calendar/index.js b/modules/zone/front/calendar/index.js index 88f16d3349..702a0a0d99 100644 --- a/modules/zone/front/calendar/index.js +++ b/modules/zone/front/calendar/index.js @@ -130,7 +130,7 @@ class Controller extends Component { } } - onSelection($days, $type, $weekday) { + onSelection($event, $days, $type, $weekday) { let $events = []; let $exclusions = []; @@ -141,6 +141,7 @@ class Controller extends Component { } this.emit('selection', { + $event, $days, $type, $weekday, diff --git a/modules/zone/front/card/index.spec.js b/modules/zone/front/card/index.spec.js index 48970ce6ba..9d0911de24 100644 --- a/modules/zone/front/card/index.spec.js +++ b/modules/zone/front/card/index.spec.js @@ -1,6 +1,6 @@ import './index.js'; -describe('Agency Component vnZoneCard', () => { +describe('Zone Component vnZoneCard', () => { let controller; let $httpBackend; let data = {id: 1, name: 'fooName'}; diff --git a/modules/zone/front/create/index.spec.js b/modules/zone/front/create/index.spec.js index 5041e50950..b97c9c3cf2 100644 --- a/modules/zone/front/create/index.spec.js +++ b/modules/zone/front/create/index.spec.js @@ -1,7 +1,7 @@ import './index'; import watcher from 'core/mocks/watcher'; -describe('Agency Component vnZoneCreate', () => { +describe('Zone Component vnZoneCreate', () => { let $scope; let $state; let controller; diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 2b8a0e4233..589208caff 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -1,6 +1,7 @@
+ data="data" + on-selection="$ctrl.onSelection($event, $events)">
@@ -31,3 +32,11 @@ + + + +
+
Zones
+ +
+
\ No newline at end of file diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index 0d7baeb605..006252a691 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -17,6 +17,27 @@ class Controller extends Section { this.vnApp.showMessage(this.$t('No service for the specified zone')); }); } + + onSelection($event, $events) { + if (!$events.length) return; + + const zones = []; + for (let event of $events) + zones.push(event.zoneFk); + + this.$.zoneEvents.show($event.target); + const zoneIndex = this.$.zoneIndex; + const zoneModel = zoneIndex.$scope.model; + zoneModel.applyFilter({ + include: { + relation: 'agencyMode', + scope: {fields: ['name']} + }, + where: { + id: {inq: zones} + } + }); + } } ngModule.component('vnZoneDeliveryDays', { diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js new file mode 100644 index 0000000000..e6019b025a --- /dev/null +++ b/modules/zone/front/delivery-days/index.spec.js @@ -0,0 +1,41 @@ +import './index.js'; +import popover from 'core/mocks/popover'; +import crudModel from 'core/mocks/crud-model'; + +fdescribe('Zone Component vnZoneDeliveryDays', () => { + let $componentController; + let controller; + let $element; + + beforeEach(ngModule('zone')); + + beforeEach(angular.mock.inject(_$componentController_ => { + $componentController = _$componentController_; + $element = angular.element(' { + it('should return', () => { + jest.spyOn(controller.$.zoneEvents, 'show'); + + const $event = new Event('click'); + const target = angular.element('
My target
'); // crear con DOM? + target.dispatchEvent($event); + const $events = [ + {zoneFk: 1}, + {zoneFk: 2}, + {zoneFk: 8} + ]; + controller.onSelection($event, $events); + + expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(); + }); + }); +}); diff --git a/modules/zone/front/delivery-days/style.scss b/modules/zone/front/delivery-days/style.scss index 79f95a3dc1..531b517954 100644 --- a/modules/zone/front/delivery-days/style.scss +++ b/modules/zone/front/delivery-days/style.scss @@ -1,3 +1,4 @@ +@import "variables"; vn-zone-delivery-days { vn-zone-calendar { @@ -13,4 +14,27 @@ vn-zone-delivery-days { display: flex; flex-direction: column; } +} + +.zoneEvents { + width: 700px; + max-height: 450px; + + vn-float-button { + display: none + } + + vn-data-viewer { + margin-bottom: 0; + vn-pagination { + padding: 0 + } + } + + & > .header { + background-color: $color-main; + color: white; + font-weight: bold; + text-align: center + } } \ No newline at end of file diff --git a/modules/zone/front/index/index.html b/modules/zone/front/index/index.html index cb820b66a7..b057896158 100644 --- a/modules/zone/front/index/index.html +++ b/modules/zone/front/index/index.html @@ -4,7 +4,7 @@ filter="::$ctrl.filter" limit="20" data="zones" - auto-load="true"> + auto-load="false"> { +describe('Zone Component vnZoneIndex', () => { let $componentController; let controller;