This commit is contained in:
Bernat 2019-09-06 09:35:27 +02:00
commit 751c945575
21 changed files with 120 additions and 20 deletions

View File

@ -45,4 +45,4 @@ import './input-file';
import './treeview';
import './treeview/child';
import './calendar';
import './scroll-up/scroll-up';

View File

@ -3,7 +3,7 @@ import Input from '../../lib/input';
import './style.scss';
/**
* Draw checkbox with a drop-down and multi options
* Multicheck component for checking all form instances at once
* @param {SmallInt} checkAll Primary input-check state: 0 -> uncheck, 1 -> checked
* @param {Array} data List of options shown in drop-down
* @param {Array} models Elements to check / unCheck

View File

@ -0,0 +1,5 @@
<button class="mdl-button mdl-js-button mdl-button--fab mdl-button--mini-fab mdl-js-ripple-effect mdl-button--colored"
ng-click="$ctrl.goUp()"
vn-tooltip="Go up">
<vn-icon icon="keyboard_arrow_up"></vn-icon>
</button>

View File

@ -0,0 +1,35 @@
import ngModule from '../../module';
import Component from '../../lib/component';
import './style.scss';
export default class Controller extends Component {
constructor($element, $scope, $window) {
super($element, $scope);
this.$window = $window;
$window.addEventListener('scroll', () => {
console.log($element[0]);
if ($window.scrollY > 0)
$element[0].style.display = 'block';
else
$element[0].style.display = 'none';
});
}
goUp() {
this.$window.scrollTo(0, 0);
}
}
Controller.$inject = ['$element', '$scope', '$window'];
ngModule.component('vnScrollUp', {
template: require('./scroll-up.html'),
controller: Controller,
bindings: {
field: '=?',
options: '<?',
disabled: '<?',
checked: '<?'
}
});

View File

@ -0,0 +1,6 @@
vn-scroll-up {
top: 5em;
right: 2.5em;
display: none;
position: fixed;
}

View File

@ -51,3 +51,4 @@ Create new one: Crear nuevo
Toggle: Desplegar/Plegar
Check all: Seleccionar todo
Select a file: Selecciona un fichero
Go up: Ir arriba

View File

@ -82,3 +82,4 @@
vn-acl-action="remove">
</vn-float-button>
</a>
<vn-scroll-up></vn-scroll-up>

View File

@ -76,3 +76,4 @@
<vn-claim-summary claim="$ctrl.claimSelected"></vn-claim-summary>
</tpl-body>
</vn-dialog>
<vn-scroll-up></vn-scroll-up>

View File

@ -67,3 +67,4 @@
<vn-client-summary client="$ctrl.clientSelected"></vn-client-summary>
</tpl-body>
</vn-dialog>
<vn-scroll-up></vn-scroll-up>

View File

@ -78,3 +78,4 @@
</tpl-body>
</vn-dialog>
<vn-client-descriptor-popover vn-id="clientDescriptor"></vn-client-descriptor-popover>
<vn-scroll-up></vn-scroll-up>

View File

@ -82,3 +82,5 @@
<vn-client-descriptor-popover
vn-id="clientDescriptor">
</vn-client-descriptor-popover>
<vn-scroll-up></vn-scroll-up>

View File

@ -146,3 +146,4 @@
vn-id="workerDescriptor"
worker-fk="$ctrl.selectedWorker">
</vn-worker-descriptor-popover>
<vn-scroll-up></vn-scroll-up>

View File

@ -91,3 +91,4 @@
<vn-order-summary order="$ctrl.selectedOrder"></vn-order-summary>
</tpl-body>
</vn-dialog>
<vn-scroll-up></vn-scroll-up>

View File

@ -75,3 +75,4 @@
<a ui-sref="route.create" vn-tooltip="New route" vn-bind="+" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>
<vn-scroll-up></vn-scroll-up>

View File

@ -161,3 +161,4 @@
<vn-client-balance-create
vn-id="balanceCreateDialog">
</vn-client-balance-create>
<vn-scroll-up></vn-scroll-up>

View File

@ -3,6 +3,10 @@
url="/api/Tickets/{{$ctrl.$stateParams.id}}/getSales"
data="$ctrl.sales">
</vn-crud-model>
<vn-watcher
vn-id="watcher"
data="$ctrl.sales">
</vn-watcher>
<vn-vertical>
<vn-card pad-large>
<vn-vertical>
@ -269,17 +273,17 @@
<vn-thead>
<vn-tr>
<vn-th number shrink>Id</vn-th>
<vn-th shrink>Item</vn-th>
<vn-th>Item</vn-th>
<vn-th number shrink>Quantity</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="sale in $ctrl.transfer.sales">
<vn-td number shrink>{{::sale.itemFk | zeroFill:6}}</vn-td>
<vn-td shrink>
<vn-td>
<span title="{{::sale.concept}}">{{::sale.concept}}</span>
</vn-td>
<vn-td-editable number>
<vn-td-editable number shrink>
<text>{{sale.quantity}}</text>
<field>
<vn-input-number vn-focus

View File

@ -116,6 +116,18 @@ class Controller {
});
}
/**
* Returns new instances
*
* @return {Array} New instances
*/
newInstances() {
if (!this.sales) return;
return this.sales.filter(sale => {
return !sale.id;
});
}
/**
* Returns an array of indexes
@ -151,6 +163,7 @@ class Controller {
return checkedLines.length;
}
removeCheckedLines() {
const sales = this.checkedLines();
@ -159,6 +172,9 @@ class Controller {
this.sales.splice(index, 1);
});
if (this.newInstances().length === 0)
this.$scope.watcher.updateOriginalData();
this.refreshTotal();
}
@ -295,8 +311,8 @@ class Controller {
updatePrice() {
if (this.editedPrice != this.sale.price) {
this.$http.post(`/api/Sales/${this.edit.id}/updatePrice`, {newPrice: this.editedPrice}).then(res => {
if (res.data)
this.sale.price = res.data.price;
this.sale.price = res.data.price;
this.$scope.watcher.updateOriginalData();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
@ -434,6 +450,8 @@ class Controller {
const data = {quantity: parseInt(sale.quantity)};
const query = `/api/Sales/${sale.id}/updateQuantity`;
this.$http.post(query, data).then(() => {
this.$scope.watcher.updateOriginalData();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
}).catch(e => {
this.$scope.model.refresh();
@ -448,6 +466,8 @@ class Controller {
const data = {concept: sale.concept};
const query = `/api/Sales/${sale.id}`;
this.$http.patch(query, data).then(() => {
this.$scope.watcher.updateOriginalData();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
}).catch(e => {
this.$scope.model.refresh();
@ -478,6 +498,9 @@ class Controller {
sale.price = newSale.price;
sale.item = newSale.item;
if (this.newInstances().length === 0)
this.$scope.watcher.updateOriginalData();
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}

View File

@ -1,4 +1,5 @@
import '../index.js';
import watcher from 'core/mocks/watcher';
describe('Ticket', () => {
describe('Component vnTicketSale', () => {
@ -42,6 +43,7 @@ describe('Ticket', () => {
$scope = $rootScope.$new();
$scope.ticket = ticket;
$scope.watcher = watcher;
$httpBackend = _$httpBackend_;
$httpBackend.whenGET(/api\/Tickets\/1\/getSales.*/).respond(sales);
@ -188,6 +190,7 @@ describe('Ticket', () => {
describe('updateQuantity()', () => {
it('should make a POST query saving sale quantity', () => {
spyOn(controller.$scope.watcher, 'updateOriginalData');
const data = {quantity: 10};
const sale = sales[0];
sale.quantity = 10;
@ -196,11 +199,14 @@ describe('Ticket', () => {
$httpBackend.expect('POST', `/api/Sales/1/updateQuantity`, data).respond();
controller.updateQuantity(sale);
$httpBackend.flush();
expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith();
});
});
describe('updateConcept()', () => {
it('should make a POST query saving sale concept', () => {
spyOn(controller.$scope.watcher, 'updateOriginalData');
const data = {concept: 'My new weapon'};
const sale = sales[0];
sale.concept = 'My new weapon';
@ -209,11 +215,14 @@ describe('Ticket', () => {
$httpBackend.expect('PATCH', `/api/Sales/1`, data).respond();
controller.updateConcept(sale);
$httpBackend.flush();
expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith();
});
});
describe('addSale()', () => {
it('should make a POST query adding a new sale', () => {
spyOn(controller.$scope.watcher, 'updateOriginalData');
const newSale = {itemFk: 4, quantity: 10};
const params = {itemId: 4, quantity: 10};
@ -233,6 +242,8 @@ describe('Ticket', () => {
$httpBackend.expect('POST', `/api/tickets/1/addSale`, params).respond(expectedResult);
controller.addSale(newSale);
$httpBackend.flush();
expect(controller.$scope.watcher.updateOriginalData).toHaveBeenCalledWith();
});
});

View File

@ -76,11 +76,14 @@ vn-ticket-sale {
}
}
vn-table, table {
margin-bottom: 10px;
margin-bottom: 10px
}
vn-table {
width: 20em
overflow-x: hidden;
overflow-y: auto;
max-height: 25em;
width: 30em;
}
table {

View File

@ -52,3 +52,4 @@
</vn-card>
<vn-pagination model="model"></vn-pagination>
</div>
<vn-scroll-up></vn-scroll-up>

View File

@ -73,3 +73,4 @@
<vn-worker-summary worker="$ctrl.selectedWorker"></vn-worker-summary>
</tpl-body>
</vn-dialog>
<vn-scroll-up></vn-scroll-up>