Descriptor/card/quicklinks fix #656

This commit is contained in:
Joan Sanchez 2018-10-03 08:00:19 +02:00
parent 1ea93211dc
commit 374d845d4b
20 changed files with 109 additions and 149 deletions

View File

@ -87,6 +87,9 @@
</vn-table>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Regularizar" vn-acl="administrative, salesAssistant"></vn-submit>
</vn-button-bar>
<!-- WIP
<a ng-click="$ctrl.openAddSalesDialog()" vn-tooltip="New item" vn-bind="+" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>

View File

@ -22,7 +22,11 @@ class Controller {
};
}
getClaim() {
$onInit() {
this.getCard();
}
getCard() {
let json = encodeURIComponent(JSON.stringify(this.filter));
let query = `/claim/api/Claims/${this.$state.params.id}?filter=${json}`;
this.$http.get(query).then(res => {
@ -31,11 +35,9 @@ class Controller {
}
});
}
$onInit() {
this.getClaim();
}
reload() {
this.getClaim();
this.getCard();
}
}

View File

@ -21,11 +21,11 @@ describe('Claim', () => {
controller = $componentController('vnClaimCard', {$scope: $scope, $state: $state});
}));
describe('getClaim()', () => {
describe('getCard()', () => {
it(`should make a query and save the data in claim`, () => {
let json = encodeURIComponent(JSON.stringify(controller.filter));
$httpBackend.expectGET(`/claim/api/Claims/${controller.$state.params.id}?filter=${json}`).respond({id: 1});
controller.getClaim();
controller.getCard();
$httpBackend.flush();
expect(controller.claim).toEqual({id: 1});

View File

@ -30,22 +30,29 @@
</vn-auto>
</vn-vertical>
<vn-horizontal pad-small class="quicklinks">
<vn-button ng-if="$ctrl.quicklinks.btnOne" pad-small-right
<a ng-if="$ctrl.quicklinks.btnOne" pad-small-right
vn-tooltip="{{::$ctrl.quicklinks.btnOne.tooltip}}"
icon="{{::$ctrl.quicklinks.btnOne.icon}}"
ng-click="$ctrl.quicklinkGo($ctrl.quicklinks.btnOne.state, $ctrl.quicklinks.btnOne.params)">
</vn-button>
<vn-button ng-if="$ctrl.quicklinks.btnTwo" pad-small-right
ui-sref="{{::$ctrl.quicklinks.btnOne.state}}" target="_blank">
<vn-icon
class="mdl-button mdl-js-button mdl-button--colored"
icon="{{::$ctrl.quicklinks.btnOne.icon}}">
</vn-icon>
</a>
<a ng-if="$ctrl.quicklinks.btnTwo" pad-small-right
vn-tooltip="{{::$ctrl.quicklinks.btnTwo.tooltip}}"
icon="{{::$ctrl.quicklinks.btnTwo.icon}}"
ng-click="$ctrl.quicklinkGo($ctrl.quicklinks.btnTwo.state, $ctrl.quicklinks.btnTwo.params)">
</vn-button>
<vn-button ng-if="$ctrl.quicklinks.btnThree" pad-small-right
ui-sref="{{::$ctrl.quicklinks.btnTwo.state}}" target="_blank">
<vn-icon
class="mdl-button mdl-js-button mdl-button--colored"
icon="{{::$ctrl.quicklinks.btnTwo.icon}}">
</vn-icon>
</a>
<a ng-if="$ctrl.quicklinks.btnThree" pad-small-right
vn-tooltip="{{::$ctrl.quicklinks.btnThree.tooltip}}"
icon="{{::$ctrl.quicklinks.btnThree.icon}}"
ng-click="$ctrl.quicklinkGo($ctrl.quicklinks.btnThree.state, $ctrl.quicklinks.btnThree.params)">
</vn-button>
ui-sref="{{::$ctrl.quicklinks.btnThree.state}}" target="_blank">
<vn-icon
class="mdl-button mdl-js-button mdl-button--colored"
icon="{{::$ctrl.quicklinks.btnThree.icon}}">
</vn-icon>
</a>
</vn-horizontal>
</vn-card>

View File

@ -3,7 +3,24 @@ import ngModule from '../module';
class Controller {
constructor($state) {
this.$state = $state;
this._quicklinks = {};
}
get claim() {
return this._claim;
}
set claim(value) {
this._claim = value;
if (!value) return;
this._quicklinks = {
btnOne: {
icon: 'person',
state: `client.card.summary({id: ${value.clientFk}})`,
tooltip: 'Client card'
}
};
}
set quicklinks(value = {}) {
@ -13,10 +30,6 @@ class Controller {
get quicklinks() {
return this._quicklinks;
}
quicklinkGo(state, params) {
this.$state.go(state, params);
}
}
Controller.$inject = ['$state'];

View File

@ -8,8 +8,6 @@ class Controller extends Component {
this.$http = $http;
this.$timeout = $timeout;
this.isTooltip = true;
this.client = {};
this._quicklinks = {};
}
set clientFk(value) {
@ -38,10 +36,6 @@ class Controller extends Component {
});
}
goToClientTickets() {
this.$state.go('ticket.index', {q: `{"clientFk": ${this.client.id}}`});
}
show() {
this.$.popover.parent = this.parent;
setTimeout(() => {

View File

@ -6,12 +6,6 @@ class Controller {
this.$http = $http;
}
set clientFk(value) {
if (!value) return;
this.getCard(value);
}
set client(value) {
this._client = value;
@ -37,21 +31,6 @@ class Controller {
get quicklinks() {
return this._quicklinks;
}
getCard(clientFk) {
this.$http.get(`/client/api/Clients/${clientFk}/getCard`)
.then(response => {
Object.assign(this.client, response.data);
});
}
goToClientTickets() {
this.$state.go('ticket.index', {q: `{"clientFk": ${this.client.id}}`});
}
quicklinkGo(state, params) {
this.$state.go(state, params);
}
}
Controller.$inject = ['$http', '$state'];
@ -60,7 +39,6 @@ ngModule.component('vnClientDescriptor', {
template: require('./index.html'),
bindings: {
client: '<',
clientFk: '<?',
quicklinks: '<'
},
controller: Controller

View File

@ -1,34 +0,0 @@
import './index';
describe('Descriptor', () => {
describe('Component vnClientDescriptor', () => {
let $componentController;
let $httpBackend;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnClientDescriptor');
}));
describe('getCard()', () => {
it(`should perform a query and store the client into the controller`, () => {
controller.client = {};
let clientFk = 101;
let response = {id: 101, name: 'Batman', debt: 100};
$httpBackend.when('GET', `/client/api/Clients/${clientFk}/getCard`).respond(response);
$httpBackend.expect('GET', `/client/api/Clients/${clientFk}/getCard`);
controller.getCard(clientFk);
$httpBackend.flush();
expect(controller.client).toEqual(response);
});
});
});
});

View File

@ -6,7 +6,6 @@ class Controller extends Component {
constructor($element, $scope, $http) {
super($element, $scope);
this.$http = $http;
this._quicklinks = {};
this.isTooltip = true;
this.clear();
}

View File

@ -4,7 +4,6 @@ import './style.scss';
class Controller {
constructor($state) {
this.$state = $state;
this._quicklinks = {};
}
set quicklinks(value = {}) {
@ -14,10 +13,6 @@ class Controller {
get quicklinks() {
return this._quicklinks;
}
quicklinkGo(state, params) {
this.$state.go(state, params);
}
}
Controller.$inject = ['$state'];

View File

@ -1,27 +0,0 @@
import './index.js';
describe('Item', () => {
describe('Component vnItemDescriptor', () => {
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('item');
});
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnItemDescriptor');
controller.$state.go = () => {};
}));
describe('quicklinkGo()', () => {
it(`shoud set _itemFk to a given value and call _getItem if the given value is not null`, () => {
spyOn(controller.$state, 'go');
controller.quicklinkGo('state', 'params');
expect(controller.$state.go).toHaveBeenCalledWith('state', 'params');
});
});
});
});

View File

@ -38,6 +38,7 @@ Tag: Etiqueta
Worker: Trabajador
Available: Disponible
Create: Crear
Client card: Ficha del cliente
#Sections
Items: Artículos

View File

@ -6,7 +6,6 @@ class Controller extends Component {
constructor($element, $scope, $http) {
super($element, $scope);
this.$http = $http;
this._quicklinks = {};
this.isTooltip = true;
this.clear();
}

View File

@ -31,10 +31,6 @@ class Controller {
get quicklinks() {
return this._quicklinks;
}
quicklinkGo(state, params) {
this.$state.go(state, params);
}
}
Controller.$inject = ['$state', '$scope'];

View File

@ -24,7 +24,11 @@ class Controller {
};
}
getOrder() {
$onInit() {
this.getCard();
}
getCard() {
let json = encodeURIComponent(JSON.stringify(this.filter));
let query = `/order/api/Orders/${this.$state.params.id}?filter=${json}`;
this.$http.get(query).then(res => {
@ -35,6 +39,10 @@ class Controller {
});
}
reload() {
this.getCard();
}
getTotal() {
let query = `/order/api/Orders/${this.$state.params.id}/getTotal`;
this.$http.get(query).then(res => {
@ -43,13 +51,6 @@ class Controller {
}
});
}
$onInit() {
this.getOrder();
}
reload() {
this.getOrder();
}
}
Controller.$inject = ['$http', '$state'];

View File

@ -22,12 +22,12 @@ describe('Order', () => {
controller = $componentController('vnOrderCard', {$scope: $scope, $state: $state});
}));
describe('getOrder()', () => {
describe('getCard()', () => {
it(`should make a query, save the data in order and call get order if the response has data`, () => {
spyOn(controller, 'getTotal');
let json = encodeURIComponent(JSON.stringify(controller.filter));
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}?filter=${json}`).respond({id: 1});
controller.getOrder();
controller.getCard();
$httpBackend.flush();
expect(controller.order).toEqual({id: 1});
@ -38,7 +38,7 @@ describe('Order', () => {
spyOn(controller, 'getTotal');
let json = encodeURIComponent(JSON.stringify(controller.filter));
$httpBackend.expectGET(`/order/api/Orders/${controller.$state.params.id}?filter=${json}`).respond(undefined);
controller.getOrder();
controller.getCard();
$httpBackend.flush();
expect(controller.order).toEqual({});

View File

@ -37,4 +37,30 @@
value="{{$ctrl.order.total | currency: ' €': 2}}">
</vn-label-value>
</div>
<vn-horizontal pad-small class="quicklinks">
<a ng-if="$ctrl.quicklinks.btnOne" pad-small-right
vn-tooltip="{{::$ctrl.quicklinks.btnOne.tooltip}}"
ui-sref="{{::$ctrl.quicklinks.btnOne.state}}" target="_blank">
<vn-icon
class="mdl-button mdl-js-button mdl-button--colored"
icon="{{::$ctrl.quicklinks.btnOne.icon}}">
</vn-icon>
</a>
<a ng-if="$ctrl.quicklinks.btnTwo" pad-small-right
vn-tooltip="{{::$ctrl.quicklinks.btnTwo.tooltip}}"
ui-sref="{{::$ctrl.quicklinks.btnTwo.state}}" target="_blank">
<vn-icon
class="mdl-button mdl-js-button mdl-button--colored"
icon="{{::$ctrl.quicklinks.btnTwo.icon}}">
</vn-icon>
</a>
<a ng-if="$ctrl.quicklinks.btnThree" pad-small-right
vn-tooltip="{{::$ctrl.quicklinks.btnThree.tooltip}}"
ui-sref="{{::$ctrl.quicklinks.btnThree.state}}" target="_blank">
<vn-icon
class="mdl-button mdl-js-button mdl-button--colored"
icon="{{::$ctrl.quicklinks.btnThree.icon}}">
</vn-icon>
</a>
</vn-horizontal>
</vn-card>

View File

@ -5,6 +5,14 @@ class Controller {
constructor($translate) {
this.translate = $translate;
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
get quicklinks() {
return this._quicklinks;
}
}
Controller.$inject = ['$translate'];

View File

@ -4,10 +4,7 @@ class Controller {
constructor($http, $state) {
this.$http = $http;
this.$state = $state;
}
getTicket() {
let filter = {
this.filter = {
include: [
{relation: 'warehouse', scope: {fields: ['name']}},
{relation: 'agencyMode', scope: {fields: ['name']}},
@ -33,8 +30,14 @@ class Controller {
}
]
};
}
let json = encodeURIComponent(JSON.stringify(filter));
$onInit() {
this.getCard();
}
getCard() {
let json = encodeURIComponent(JSON.stringify(this.filter));
let query = `/ticket/api/Tickets/${this.$state.params.id}?filter=${json}`;
this.$http.get(query).then(res => {
if (res.data)
@ -42,12 +45,8 @@ class Controller {
});
}
$onInit() {
this.getTicket();
}
reload() {
this.getTicket();
this.getCard();
}
}

View File

@ -20,7 +20,7 @@ describe('Ticket', () => {
controller = $componentController('vnTicketCard', {$state: $state});
}));
describe('getTicket()', () => {
describe('getCard()', () => {
it('should perform a GET query and define the ticket property on controller', () => {
let filter = {
include: [
@ -53,7 +53,7 @@ describe('Ticket', () => {
$httpBackend.when('GET', `/ticket/api/Tickets/1?filter=${filter}`).respond({id: 1});
$httpBackend.expect('GET', `/ticket/api/Tickets/1?filter=${filter}`);
controller.getTicket();
controller.getCard();
$httpBackend.flush();
expect(controller.ticket).toBeDefined();