Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/dev This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2019-10-01 14:01:18 +02:00
commit f65e0cd5bf
25 changed files with 198 additions and 140 deletions

View File

@ -262,10 +262,12 @@ export default class Calendar extends Component {
*/ */
select(index) { select(index) {
if (this.disabled) return; if (this.disabled) return;
let day = this.days[index]; let day = this.days[index].dated;
day.index = index;
this.emit('selection', {values: [day]}); this.emit('selection', {
$days: [day],
$type: 'day'
});
} }
/** /**
@ -276,15 +278,17 @@ export default class Calendar extends Component {
selectAll(weekday) { selectAll(weekday) {
if (this.disabled) return; if (this.disabled) return;
let selected = []; let days = [];
for (let i in this.days) { for (let i in this.days) {
const day = this.days[i]; const day = this.days[i].dated;
const date = day.dated; if (day.getDay() === weekday && day.getMonth() == this.defaultDate.getMonth())
day.index = i; days.push(day);
if (date.getDay() === weekday && date.getMonth() == this.defaultDate.getMonth())
selected.push(day);
} }
this.emit('selection', {values: selected}); this.emit('selection', {
$days: days,
$type: 'weekday',
$weekday: weekday
});
} }
renderStyle(style) { renderStyle(style) {

View File

@ -60,12 +60,17 @@ describe('Component vnCalendar', () => {
describe('select()', () => { describe('select()', () => {
it(`should return the selected element, then emit a 'selection' event`, () => { it(`should return the selected element, then emit a 'selection' event`, () => {
spyOn(controller, 'emit'); spyOn(controller, 'emit');
const days = [{dated: new Date()}]; const dated = new Date();
const days = [{dated}];
controller.days = days; controller.days = days;
controller.select(0); controller.select(0);
expect(controller.emit).toHaveBeenCalledWith('selection', {values: days}); let res = {
$days: [dated],
$type: 'day'
};
expect(controller.emit).toHaveBeenCalledWith('selection', res);
}); });
}); });

34
front/core/lib/section.js Normal file
View File

@ -0,0 +1,34 @@
import Component from './component';
/**
* Class with commonly injected services assigned as properties. It also has
* abbreviations for commonly used methods like tranlation.
*
* @property {Object} $translate Angular tranlation service
* @property {Object} $http Angular HTTP service
* @property {Object} $state Router state service
* @property {Object} $stateParams Router state parameters
*/
export default class Section extends Component {
constructor($element, $scope, $translate, $http, $state) {
super($element, $scope);
Object.assign(this, {
$translate,
$http,
$state,
$stateParams: $state.params
});
}
/**
* Translates an string.
*
* @param {String} string String to translate
* @param {Array} params Translate parameters
* @return {String} The translated string
*/
_(string, params) {
return this.$translate.instant(string, params, );
}
}
Section.$inject = ['$element', '$scope', '$translate', '$http', '$state'];

View File

@ -15,3 +15,4 @@ import './descriptor.scss';
import './list.scss'; import './list.scss';
import './modal-form.scss'; import './modal-form.scss';
import './photo-list.scss'; import './photo-list.scss';
import './width.scss';

View File

@ -99,11 +99,6 @@ html [pointer], .pointer{
html [noDrop], .noDrop{ html [noDrop], .noDrop{
cursor: no-drop; cursor: no-drop;
} }
html [compact], .compact{
max-width: $width-compact;
margin-left: auto;
margin-right: auto;
}
button { button {
@extend %clickable; @extend %clickable;
} }
@ -147,6 +142,12 @@ fieldset[disabled] .mdl-textfield .mdl-textfield__label,
font-size: 0.7em font-size: 0.7em
} }
} }
[compact], .compact {
margin-left: auto;
margin-right: auto;
max-width: $width-md;
}
.vn-grid { .vn-grid {
border-collapse: collapse; border-collapse: collapse;
width: 100%; width: 100%;

View File

@ -5,9 +5,11 @@ $mobile-width: 800px;
// Width // Width
$width-small: 36em; $width-xs: 25em;
$width-compact: 60em; $width-sm: 32em;
$width-large: 80em; $width-md: 60em;
$width-lg: 80em;
$width-xl: 100em;
// Padding // Padding

View File

@ -0,0 +1,26 @@
@import "./variables";
%margin-auto {
margin-left: auto;
margin-right: auto;
}
.vn-w-xs {
@extend %margin-auto;
max-width: $width-xs;
}
.vn-w-sm {
@extend %margin-auto;
max-width: $width-sm;
}
.vn-w-md {
@extend %margin-auto;
max-width: $width-md;
}
.vn-w-lg {
@extend %margin-auto;
max-width: $width-lg;
}
.vn-w-xl {
@extend %margin-auto;
max-width: $width-xl;
}

View File

@ -3,6 +3,7 @@
skip="2" skip="2"
has-events="$ctrl.hasEvents($day)" has-events="$ctrl.hasEvents($day)"
get-class="$ctrl.getClass($day)" get-class="$ctrl.getClass($day)"
on-selection="$ctrl.onSelection($days, $type, $weekday)"
on-move-next="ndMonth.moveNext(2)" on-move-next="ndMonth.moveNext(2)"
on-move-previous="ndMonth.movePrevious(2)" on-move-previous="ndMonth.movePrevious(2)"
vn-acl="deliveryBoss" vn-acl="deliveryBoss"
@ -13,6 +14,7 @@
skip="2" skip="2"
has-events="$ctrl.hasEvents($day)" has-events="$ctrl.hasEvents($day)"
get-class="$ctrl.getClass($day)" get-class="$ctrl.getClass($day)"
on-selection="$ctrl.onSelection($days, $type, $weekday)"
default-date="$ctrl.ndMonthDate" default-date="$ctrl.ndMonthDate"
vn-acl="deliveryBoss" vn-acl="deliveryBoss"
display-controls="false" display-controls="false"

View File

@ -1,12 +1,10 @@
import ngModule from '../module'; import ngModule from '../module';
import Section from 'core/lib/section';
import './style.scss'; import './style.scss';
class Controller { class Controller extends Section {
constructor($, $stateParams) { constructor($el, $, $t, $http, $state) {
Object.assign(this, { super($el, $, $t, $http, $state);
$,
$stateParams
});
this.excls = {}; this.excls = {};
this.resetEvents(); this.resetEvents();
@ -14,6 +12,10 @@ class Controller {
this.ndMonthDate.setMonth(this.ndMonthDate.getMonth() + 1); this.ndMonthDate.setMonth(this.ndMonthDate.getMonth() + 1);
} }
onSelection($days, $type, $weekday) {
this.emit('selection', {$days, $type, $weekday});
}
resetEvents() { resetEvents() {
this.wdays = []; this.wdays = [];
this.days = {}; this.days = {};
@ -96,8 +98,6 @@ class Controller {
} }
} }
Controller.$inject = ['$scope', '$stateParams'];
ngModule.component('vnZoneCalendar', { ngModule.component('vnZoneCalendar', {
template: require('./index.html'), template: require('./index.html'),
controller: Controller, controller: Controller,

View File

@ -2,4 +2,4 @@
<vn-zone-descriptor zone="$ctrl.zone"></vn-zone-descriptor> <vn-zone-descriptor zone="$ctrl.zone"></vn-zone-descriptor>
<vn-left-menu></vn-left-menu> <vn-left-menu></vn-left-menu>
</vn-side-menu> </vn-side-menu>
<div class="content-block" ui-view></div> <div ui-view></div>

View File

@ -1,5 +1,5 @@
<div class="main-with-right-menu"> <div class="main-with-right-menu">
<div class="vn-list" style="max-width: 30em;"> <div class="vn-list vn-w-sm">
<vn-card ng-if="data.length"> <vn-card ng-if="data.length">
<a <a
ng-repeat="row in data" ng-repeat="row in data"
@ -64,23 +64,16 @@
<vn-side-menu side="right"> <vn-side-menu side="right">
<vn-zone-calendar <vn-zone-calendar
events="data" events="data"
exclusions="exclusions"> exclusions="exclusions"
on-selection="$ctrl.onCreate($days, $type, $weekday)">
</vn-zone-calendar> </vn-zone-calendar>
</vn-side-menu> </vn-side-menu>
<vn-float-button
icon="add"
translate-attr="{title: 'Add'}"
vn-bind="+"
ng-click="$ctrl.onCreate()"
fixed-bottom-right
style="z-index: 10;">
</vn-float-button>
<vn-dialog <vn-dialog
vn-id="dialog" vn-id="dialog"
on-response="$ctrl.onSave(response)"> on-response="$ctrl.onSave(response)">
<tpl-body> <tpl-body>
<vn-vertical> <vn-vertical>
<vn-vertical> <vn-vertical pad-medium-bottom>
<vn-radio <vn-radio
field="$ctrl.eventType" field="$ctrl.eventType"
label="One day" label="One day"
@ -88,13 +81,13 @@
</vn-radio> </vn-radio>
<vn-radio <vn-radio
field="$ctrl.eventType" field="$ctrl.eventType"
label="Range of dates" label="Indefinitely"
val="range"> val="indefinitely">
</vn-radio> </vn-radio>
<vn-radio <vn-radio
field="$ctrl.eventType" field="$ctrl.eventType"
label="Indefinitely" label="Range of dates"
val="indefinitely"> val="range">
</vn-radio> </vn-radio>
</vn-vertical> </vn-vertical>
<div <div

View File

@ -1,13 +1,10 @@
import ngModule from '../module'; import ngModule from '../module';
import Section from 'core/lib/section';
import './style.scss'; import './style.scss';
class Controller { class Controller extends Section {
constructor($, _, $http, $stateParams) { constructor($el, $, $t, $http, $state) {
Object.assign(this, { super($el, $, $t, $http, $state);
$,
_,
$http
});
this.wdays = [ this.wdays = [
{ {
@ -36,15 +33,15 @@ class Controller {
this.abrWdays = {}; this.abrWdays = {};
for (let wday of this.wdays) { for (let wday of this.wdays) {
let locale = _.instant(wday.name); let locale = this._(wday.name);
this.abrWdays[wday.code] = locale.substr(0, 3); this.abrWdays[wday.code] = locale.substr(0, 3);
wday.abr = locale.substr(0, 1); wday.abr = locale.substr(0, 1);
} }
this.$http.get(`/api/Zones/${$stateParams.id}/exclusions`) this.$http.get(`/api/Zones/${this.$stateParams.id}/exclusions`)
.then(res => this.$.exclusions = res.data); .then(res => this.$.exclusions = res.data);
this.path = `/api/Zones/${$stateParams.id}/events`; this.path = `/api/Zones/${this.$stateParams.id}/events`;
this.refresh(); this.refresh();
} }
@ -89,10 +86,19 @@ class Controller {
this.$.dialog.show(); this.$.dialog.show();
} }
onCreate() { onCreate($day, $type, $weekday) {
this.isNew = true; this.isNew = true;
this.eventType = 'day'; this.eventType = $type == 'day' ? 'day' : 'indefinitely';
this.selected = {};
if ($type == 'weekday') {
let wdays = [];
let index = $weekday - 1;
if (index < 0) index = 7 - index;
wdays[this.wdays[index].code] = true;
this.selected = {wdays};
} else
this.selected = {from: $day[0]};
this.$.dialog.show(); this.$.dialog.show();
} }
@ -153,7 +159,6 @@ class Controller {
}); });
} }
} }
Controller.$inject = ['$scope', '$translate', '$http', '$stateParams'];
ngModule.component('vnZoneEvents', { ngModule.component('vnZoneEvents', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -1,6 +1,5 @@
<vn-card <div class="main-with-right-menu">
ng-if="data.length" <vn-card ng-if="data.length" class="vn-w-xs">
style="max-width: 25em; margin: 0 auto;">
<vn-table> <vn-table>
<vn-tbody> <vn-tbody>
<vn-tr ng-repeat="row in data | orderBy:'day'"> <vn-tr ng-repeat="row in data | orderBy:'day'">
@ -9,26 +8,27 @@
<vn-icon-button <vn-icon-button
icon="delete" icon="delete"
translate-attr="{title: 'Delete'}" translate-attr="{title: 'Delete'}"
ng-click="$ctrl.onDelete($index)"> ng-click="$ctrl.onDelete(row.id)">
</vn-icon-button> </vn-icon-button>
</vn-td> </vn-td>
</vn-tr> </vn-tr>
</vn-tbody> </vn-tbody>
</vn-table> </vn-table>
</vn-card> </vn-card>
<vn-bg-title ng-if="!data"> <vn-bg-title ng-if="!data">
<vn-spinner enable="true"></vn-spinner> <vn-spinner enable="true"></vn-spinner>
</vn-bg-title> </vn-bg-title>
<vn-bg-title ng-if="data.length == 0" translate> <vn-bg-title ng-if="data.length == 0" translate>
No records found No records found
</vn-bg-title> </vn-bg-title>
<vn-float-button </div>
icon="add" <vn-side-menu side="right">
translate-attr="{title: 'Add'}" <vn-zone-calendar
vn-bind="+" events="events"
ng-click="$ctrl.onCreate()" exclusions="data"
fixed-bottom-right> on-selection="$ctrl.onCreate($days)">
</vn-float-button> </vn-zone-calendar>
</vn-side-menu>
<vn-dialog <vn-dialog
vn-id="dialog" vn-id="dialog"
on-response="$ctrl.onSave(response)"> on-response="$ctrl.onSave(response)">

View File

@ -1,13 +1,14 @@
import ngModule from '../module'; import ngModule from '../module';
import Section from 'core/lib/section';
class Controller { class Controller extends Section {
constructor($, $http, $stateParams) { constructor($el, $, $t, $http, $state) {
Object.assign(this, { super($el, $, $t, $http, $state);
$,
$http
});
this.path = `/api/Zones/${$stateParams.id}/exclusions`; this.$http.get(`/api/Zones/${this.$stateParams.id}/events`)
.then(res => this.$.events = res.data);
this.path = `/api/Zones/${this.$stateParams.id}/exclusions`;
this.refresh(); this.refresh();
} }
@ -16,9 +17,9 @@ class Controller {
.then(res => this.$.data = res.data); .then(res => this.$.data = res.data);
} }
onCreate() { onCreate($days) {
this.isNew = true; this.isNew = true;
this.selected = {}; this.selected = {day: $days[0]};
this.$.dialog.show(); this.$.dialog.show();
} }
@ -36,23 +37,21 @@ class Controller {
return false; return false;
} }
onDelete(index) { onDelete(id) {
this.$.confirm.show(); this.$.confirm.show();
this.deleteIndex = index; this.deleteId = id;
} }
delete(response) { delete(response) {
if (response != 'ACCEPT') return; if (response != 'ACCEPT') return;
let id = this.$.data[this.deleteIndex].id; if (!this.deleteId) return;
if (!id) return; this.$http.delete(`${this.path}/${this.deleteId}`)
this.$http.delete(`${this.path}/${id}`)
.then(() => { .then(() => {
this.$.data.splice(this.deleteIndex, 1); this.refresh();
this.deleteIndex = null; this.deleteId = null;
}); });
} }
} }
Controller.$inject = ['$scope', '$http', '$stateParams'];
ngModule.component('vnZoneExclusions', { ngModule.component('vnZoneExclusions', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -1,12 +1,7 @@
import ngModule from '../module'; import ngModule from '../module';
import Section from 'core/lib/section';
class Controller { class Controller extends Section {
constructor($, $http, $stateParams) {
this.$ = $;
this.$http = $http;
this.$stateParams = $stateParams;
}
onSearch(params) { onSearch(params) {
this.$.model.applyFilter(null, params); this.$.model.applyFilter(null, params);
this.$.$applyAsync(() => this.$.treeview.refresh()); this.$.$applyAsync(() => this.$.treeview.refresh());
@ -30,8 +25,6 @@ class Controller {
} }
} }
Controller.$inject = ['$scope', '$http', '$stateParams'];
ngModule.component('vnZoneLocation', { ngModule.component('vnZoneLocation', {
template: require('./index.html'), template: require('./index.html'),
controller: Controller, controller: Controller,

View File

@ -1,6 +1,4 @@
<vn-card <vn-card ng-if="data.length" class="vn-w-xs">
ng-if="data.length"
style="max-width: 25em; margin: 0 auto;">
<vn-table> <vn-table>
<vn-tbody> <vn-tbody>
<vn-tr ng-repeat="row in data | orderBy:'warehouse.name'"> <vn-tr ng-repeat="row in data | orderBy:'warehouse.name'">

View File

@ -1,13 +1,11 @@
import ngModule from '../module'; import ngModule from '../module';
import Section from 'core/lib/section';
class Controller { class Controller extends Section {
constructor($, _, $http, $stateParams) { constructor($el, $, $t, $http, $state) {
Object.assign(this, { super($el, $, $t, $http, $state);
$,
$http
});
this.path = `/api/Zones/${$stateParams.id}/warehouses`; this.path = `/api/Zones/${this.$stateParams.id}/warehouses`;
this.refresh(); this.refresh();
} }
@ -52,7 +50,6 @@ class Controller {
}); });
} }
} }
Controller.$inject = ['$scope', '$translate', '$http', '$stateParams'];
ngModule.component('vnZoneWarehouses', { ngModule.component('vnZoneWarehouses', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -2,7 +2,7 @@
vn-invoice-out-summary .summary { vn-invoice-out-summary .summary {
max-width: $width-large; max-width: $width-lg;
vn-icon[icon=insert_drive_file]{ vn-icon[icon=insert_drive_file]{
color: $color-font-secondary; color: $color-font-secondary;

View File

@ -1,7 +1,8 @@
@import "./variables"; @import "./variables";
vn-order-summary .summary{ vn-order-summary .summary{
max-width: $width-large; max-width: $width-lg;
& > div > vn-horizontal > vn-one { & > div > vn-horizontal > vn-one {
min-width: 10em !important; min-width: 10em !important;

View File

@ -1,5 +1,5 @@
@import "./variables"; @import "./variables";
vn-route-index .index { vn-route-index .index {
max-width: $width-large; max-width: $width-lg;
} }

View File

@ -2,7 +2,7 @@
vn-route-summary .summary { vn-route-summary .summary {
max-width: $width-large; max-width: $width-lg;
vn-icon[icon=insert_drive_file]{ vn-icon[icon=insert_drive_file]{
color: $color-font-secondary; color: $color-font-secondary;

View File

@ -2,5 +2,5 @@
vn-route-tickets form{ vn-route-tickets form{
margin: 0 auto; margin: 0 auto;
max-width: $width-large; max-width: $width-lg;
} }

View File

@ -1,7 +1,7 @@
@import "./variables"; @import "./variables";
vn-ticket-summary .summary { vn-ticket-summary .summary {
max-width: $width-large; max-width: $width-lg;
vn-button { vn-button {
max-height: 27px; max-height: 27px;

View File

@ -63,7 +63,7 @@
<vn-calendar pad-small <vn-calendar pad-small
data="$ctrl.currentWeek" data="$ctrl.currentWeek"
default-date="$ctrl.defaultDate" default-date="$ctrl.defaultDate"
on-selection="$ctrl.onSelection(values)" on-selection="$ctrl.onSelection($days)"
on-move-next="$ctrl.onMoveNext()" on-move-next="$ctrl.onMoveNext()"
on-move-previous="$ctrl.onMovePrevious()"> on-move-previous="$ctrl.onMovePrevious()">
</vn-calendar> </vn-calendar>

View File

@ -208,12 +208,9 @@ class Controller {
this.refresh(); this.refresh();
} }
onSelection(value) { onSelection($days) {
const selected = value[0].dated; this.defaultDate.setMonth($days[0].getMonth());
this.defaultDate.setDate($days[0].getDate());
this.defaultDate.setMonth(selected.getMonth());
this.defaultDate.setDate(selected.getDate());
this.refresh(); this.refresh();
} }