#1882 Popover::show() boilerplate code removed
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Juan Ferrer 2020-04-28 14:26:02 +02:00
parent 5826099601
commit b536c8291a
61 changed files with 556 additions and 839 deletions

View File

@ -31,6 +31,7 @@ rules:
curly: [error, multi-or-nest]
indent: [error, 4]
arrow-parens: [error, as-needed]
jasmine/no-focused-tests: 0
no-multiple-empty-lines: ["error", { "max": 1, "maxEOF": 1 }]
space-in-parens: ["error", "never"]
jasmine/no-focused-tests: 0
jasmine/prefer-toHaveBeenCalledWith: 0

View File

@ -63,10 +63,10 @@ export default class DescriptorPopover extends Popover {
this.relocate();
return this.$http.get(url, options)
.then(res => {
this.canceler = null;
this.$.$applyAsync(() => this.relocate());
return res;
});
})
.finally(() => this.canceler = null);
}
}

View File

@ -1,8 +1,9 @@
<a ng-repeat="button in $ctrl.links"
vn-tooltip="{{::button.tooltip}}"
class="vn-button colored"
ui-sref="{{::button.state}}">
<vn-icon
icon="{{::button.icon}}">
</vn-icon>
</a>
<vn-spinner
ng-if="$ctrl.canceler"
enable="true">
</vn-spinner>
<div
ng-if="$ctrl.entity"
ng-transclude="body"
class="descriptor-wrapper">
</div>

View File

@ -1,21 +1,39 @@
import ngModule from '../../module';
import Component from 'core/lib/component';
import './quick-links';
import './style.scss';
import './quick-links';
import './quick-link';
export default class Descriptor extends Component {
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
get entity() {
return this._entity;
}
set entity(value) {
this._entity = value;
}
get quicklinks() {
return this._quicklinks;
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}
}
Descriptor.$inject = ['$element', '$scope'/* , '$transclude'*/];
ngModule.vnComponent('vnDescriptor', {
template: require('./index.html'),
controller: Descriptor,
bindings: {
entity: '<?',
quicklinks: '<'
},
transclude: {
body: '?slotBody',
btnOne: '?btnOne',
btnTwo: '?btnTwo',
btnThree: '?btnThree'
}
});

View File

@ -0,0 +1,8 @@
<a
ui-sref="{{$ctrl.state}}"
vn-tooltip="{{::$ctrl.tooltip}}"
class="vn-button colored">
<vn-icon
icon="{{::$ctrl.icon}}">
</vn-icon>
</a>

View File

@ -0,0 +1,13 @@
import ngModule from '../../module';
export default class QuickLink {}
ngModule.component('vnQuickLink', {
template: require('./quick-link.html'),
controller: QuickLink,
bindings: {
state: '@?',
icon: '@?',
tooltip: '@?'
}
});

View File

@ -2,7 +2,9 @@
@import "./effects";
@import "./variables";
.vn-descriptor {
.vn-descriptor,
.vn-descriptor slot-body {
display: block;
box-shadow: 0 1px 3px $color-shadow;
& > .header {
@ -65,7 +67,11 @@
align-items: center;
justify-content: center;
& > a {
& > a,
vn-quick-link > a {
display: flex;
align-items: center;
justify-content: center;
padding: 0 $spacing-md;
margin: 0 $spacing-sm;

View File

@ -1,4 +1,6 @@
<vn-crud-model vn-id="model" auto-load="true"
<vn-crud-model
vn-id="model"
auto-load="true"
url="ClaimDms"
link="{claimFk: $ctrl.$params.id}"
limit="20"
@ -17,7 +19,7 @@
<section class="actions">
<vn-button
class="round"
ng-click="$ctrl.showDeleteConfirm($index)"
ng-click="confirm.show($index)"
title="{{'Remove file' | translate}}"
tabindex="-1"
icon="delete">
@ -25,19 +27,16 @@
</section>
</section>
</vn-horizontal>
<vn-worker-descriptor-popover
vn-id="workerDescriptor">
</vn-worker-descriptor-popover>
<vn-confirm
vn-id="confirm"
message="This file will be deleted"
question="Are you sure you want to continue?"
on-response="$ctrl.deleteDms($response)">
on-accept="$ctrl.deleteDms($data)">
</vn-confirm>
<vn-float-button fixed-bottom-right
<vn-float-button
icon="add"
vn-tooltip="Select photo"
vn-bind="+"
ng-click="$ctrl.openUploadDialog()">
ng-click="$ctrl.openUploadDialog()"
fixed-bottom-right>
</vn-float-button>

View File

@ -3,29 +3,14 @@ import Section from 'salix/components/section';
import './style.scss';
class Controller extends Section {
showWorkerDescriptor(event, workerFk) {
event.preventDefault();
event.stopImmediatePropagation();
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.workerFk = workerFk;
this.$.workerDescriptor.show();
}
showDeleteConfirm(index) {
this.dmsIndex = index;
this.$.confirm.show();
}
deleteDms(response) {
if (response === 'accept') {
const dmsFk = this.photos[this.dmsIndex].dmsFk;
const query = `claimDms/${dmsFk}/removeFile`;
this.$http.post(query).then(() => {
this.$.model.remove(this.dmsIndex);
this.vnApp.showSuccess(this.$translate.instant('Photo deleted'));
deleteDms(index) {
const dmsFk = this.photos[index].dmsFk;
return this.$http.post(`ClaimDms/${dmsFk}/removeFile`)
.then(() => {
this.$.model.remove(index);
this.vnApp.showSuccess(this.$t('Photo deleted'));
});
}
}
onDrop($event) {
const files = $event.dataTransfer.files;
@ -36,10 +21,10 @@ class Controller extends Section {
}
setDefaultParams() {
const params = {filter: {
const filter = {
where: {code: 'claim'}
}};
return this.$http.get('DmsTypes/findOne', {params}).then(res => {
};
return this.$http.get('DmsTypes/findOne', {filter}).then(res => {
const dmsTypeId = res.data && res.data.id;
const companyId = this.vnConfig.companyFk;
const warehouseId = this.vnConfig.warehouseFk;
@ -50,7 +35,7 @@ class Controller extends Section {
warehouseId: warehouseId,
companyId: companyId,
dmsTypeId: dmsTypeId,
description: this.$translate.instant('FileDescription', {
description: this.$t('FileDescription', {
claimId: this.claim.id,
clientId: this.claim.client.id,
clientName: this.claim.client.name
@ -91,7 +76,7 @@ class Controller extends Section {
data: this.dms.files
};
this.$http(options).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Photo uploaded!'));
this.vnApp.showSuccess(this.$t('Photo uploaded!'));
this.$.model.refresh();
});
}

View File

@ -6,16 +6,13 @@ describe('Claim', () => {
let $scope;
let $httpBackend;
let controller;
let $httpParamSerializer;
beforeEach(ngModule('claim'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
$httpParamSerializer = _$httpParamSerializer_;
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-claim-photos></vn-claim-photos>');
controller = $componentController('vnClaimPhotos', {$element, $scope});
controller = $componentController('vnClaimPhotos', {$element: null, $scope});
controller.$.model = crudModel;
controller.claim = {
id: 1,
@ -25,31 +22,25 @@ describe('Claim', () => {
describe('deleteDms()', () => {
it('should make an HTTP Post query', () => {
const dmsId = 1;
const dmsIndex = 0;
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$.model, 'remove');
controller.photos = [{dmsFk: 1}];
controller.dmsIndex = dmsIndex;
$httpBackend.when('POST', `claimDms/${dmsId}/removeFile`).respond({});
$httpBackend.expect('POST', `claimDms/${dmsId}/removeFile`);
controller.deleteDms('accept');
const dmsId = 1;
const dmsIndex = 0;
controller.photos = [{dmsFk: 1}];
$httpBackend.expectPOST(`ClaimDms/${dmsId}/removeFile`).respond();
controller.deleteDms(dmsIndex);
$httpBackend.flush();
expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex);
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Photo deleted');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
describe('setDefaultParams()', () => {
it('should make an HTTP GET query, then set all dms properties', () => {
const params = {filter: {
where: {code: 'claim'}
}};
let serializedParams = $httpParamSerializer(params);
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({});
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
$httpBackend.expectRoute('GET', `DmsTypes/findOne`).respond({});
controller.setDefaultParams();
$httpBackend.flush();
@ -67,13 +58,12 @@ describe('Claim', () => {
controller.dmsIndex = dmsIndex;
controller.dms = {files: []};
$httpBackend.when('POST', `claims/${claimId}/uploadFile`).respond({});
$httpBackend.expect('POST', `claims/${claimId}/uploadFile`);
$httpBackend.expectPOST(`claims/${claimId}/uploadFile`).respond({});
controller.create();
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Photo uploaded!');
expect(controller.$.model.refresh).toHaveBeenCalled();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
});

View File

@ -1,9 +1,13 @@
<div class="vn-descriptor">
<slot-body>
<div class="header">
<a translate-attr="{title: 'Return to module index'}" ui-sref="client.index">
<a
translate-attr="{title: 'Return to module index'}"
ui-sref="client.index">
<vn-icon icon="chevron_left"></vn-icon>
</a>
<a translate-attr="{title: 'Preview'}" ui-sref="client.card.summary({id: $ctrl.client.id})">
<a
translate-attr="{title: 'Preview'}"
ui-sref="client.card.summary({id: $ctrl.client.id})">
<vn-icon icon="desktop_windows"></vn-icon>
</a>
<vn-icon-button
@ -63,16 +67,22 @@
</vn-icon>
</div>
<div class="quicklinks" >
<a class="vn-button colored"
vn-tooltip="Client ticket list"
ui-sref="ticket.index({q: $ctrl.filter})">
<vn-icon icon="icon-ticket"></vn-icon>
</a>
<a class="vn-button colored"
vn-tooltip="New order"
ui-sref="order.create({clientFk: $ctrl.client.id})">
<vn-icon icon="icon-basketadd"></vn-icon>
</a>
<div ng-transclude="btnOne">
<vn-quick-link
tooltip="Client ticket list"
state="ticket.index({ q: '{{ {clientFk: $ctrl.client.id} }}' })"
icon="icon-ticket">
</vn-quick-link>
</div>
<div ng-transclude="btnTwo">
<vn-quick-link
tooltip="New order"
state="order.create({ clientFk: {{ $ctrl.client.id }} })"
icon="icon-basketadd">
</vn-quick-link>
</div>
<div ng-transclude="btnThree">
</div>
</div>
<!--
<vn-quick-links
@ -80,7 +90,6 @@
</vn-quick-links>
-->
</div>
</div>
<vn-menu vn-id="menu">
<ul class="vn-list">
<li>
@ -138,3 +147,4 @@
<button response="accept" translate>Accept</button>
</tpl-buttons>
</vn-dialog>
</slot-body>

View File

@ -2,17 +2,17 @@ import ngModule from '../module';
import Descriptor from 'salix/components/descriptor';
class Controller extends Descriptor {
constructor($element, $, $httpParamSerializer) {
super($element, $);
constructor($element, $, $transclude, $httpParamSerializer) {
super($element, $, $transclude);
this.$httpParamSerializer = $httpParamSerializer;
}
get client() {
return this._client;
return this.entity;
}
set client(value) {
this._client = value;
this.entity = value;
if (!value) return;
if (this.$params.sendSMS)
@ -33,7 +33,7 @@ class Controller extends Descriptor {
}
get filter() {
return this.client ? JSON.stringify({clientFk: this.client.id}) : null;
return JSON.stringify({clientFk: this.client.id});
}
showSMSDialog() {
@ -56,11 +56,10 @@ class Controller extends Descriptor {
window.open(`api/report/campaign-metrics?${params}`);
}
}
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
Controller.$inject = ['$element', '$scope', '$transclude', '$httpParamSerializer'];
ngModule.vnComponent('vnClientDescriptor', {
template: require('./index.html'),
slotTemplate: require('./index.html'),
bindings: {
client: '<'
},

View File

@ -62,7 +62,7 @@
</vn-td>
<vn-td shrink>
<span class="link"
ng-click="$ctrl.showWorkerDescriptor($event, document.dms.workerFk)">
ng-click="workerDescriptor.show($event, document.dms.workerFk)">
{{::document.dms.worker.user.nickname | dashIfEmpty}}
</span></vn-td>
<vn-td>
@ -86,7 +86,7 @@
<vn-td shrink>
<vn-icon-button
icon="delete"
ng-click="$ctrl.showDeleteConfirm($index)"
ng-click="confirm.show($index)"
title="{{'Remove file' | translate}}"
tabindex="-1">
</vn-icon-button>
@ -109,5 +109,5 @@
vn-id="confirm"
message="This file will be deleted"
question="Are you sure you want to continue?"
on-response="$ctrl.deleteDms($response)">
on-accept="$ctrl.deleteDms($data)">
</vn-confirm>

View File

@ -24,8 +24,7 @@ class Controller extends Section {
scope: {
fields: ['name']
}
},
{
}, {
relation: 'worker',
scope: {
fields: ['userFk'],
@ -42,30 +41,15 @@ class Controller extends Section {
};
}
showWorkerDescriptor(event, workerFk) {
event.preventDefault();
event.stopImmediatePropagation();
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.workerFk = workerFk;
this.$.workerDescriptor.show();
}
showDeleteConfirm(index) {
this.dmsIndex = index;
this.$.confirm.show();
}
deleteDms(response) {
if (response === 'accept') {
const dmsFk = this.clientDms[this.dmsIndex].dmsFk;
const query = `clientDms/${dmsFk}/removeFile`;
this.$http.post(query).then(() => {
this.$.model.remove(this.dmsIndex);
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
deleteDms(index) {
const dmsFk = this.clientDms[index].dmsFk;
return this.$http.post(`ClientDms/${dmsFk}/removeFile`)
.then(() => {
this.$.model.remove(index);
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
}
}
Controller.$inject = ['$element', '$scope'];

View File

@ -12,27 +12,25 @@ describe('Client', () => {
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
const $element = angular.element('<vn-client-dms-index></vn-client-dms-index>');
controller = $componentController('vnClientDmsIndex', {$element, $scope});
controller = $componentController('vnClientDmsIndex', {$element: null, $scope});
controller.$.model = crudModel;
}));
describe('deleteDms()', () => {
it('should make an HTTP Post query', () => {
const dmsId = 1;
const dmsIndex = 0;
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$.model, 'remove');
controller.clientDms = [{dmsFk: 1}];
controller.dmsIndex = dmsIndex;
$httpBackend.when('POST', `clientDms/${dmsId}/removeFile`).respond({});
$httpBackend.expect('POST', `clientDms/${dmsId}/removeFile`);
controller.deleteDms('accept');
const dmsId = 1;
const dmsIndex = 0;
controller.clientDms = [{dmsFk: 1}];
$httpBackend.expectPOST(`ClientDms/${dmsId}/removeFile`).respond();
controller.deleteDms(dmsIndex);
$httpBackend.flush();
expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex);
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
});

View File

@ -29,8 +29,9 @@
{{::sample.type.description}}
</vn-td>
<vn-td>
<span class="link"
ng-click="$ctrl.showWorkerDescriptor($event, sample.worker.id)">
<span
ng-click="workerDescriptor.show($event, sample.worker.id)"
class="link">
{{::sample.worker.user.nickname}}
</span>
</vn-td>

View File

@ -11,8 +11,7 @@ class Controller extends Section {
scope: {
fields: ['code', 'description']
}
},
{
}, {
relation: 'worker',
scope: {
fields: ['userFk'],
@ -23,8 +22,7 @@ class Controller extends Section {
}
}
}
},
{
}, {
relation: 'company',
scope: {
fields: ['code']
@ -33,19 +31,7 @@ class Controller extends Section {
]
};
}
showWorkerDescriptor(event, workerFk) {
if (event.defaultPrevented) return;
event.preventDefault();
event.stopImmediatePropagation();
this.selectedWorker = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
}
Controller.$inject = ['$element', '$scope'];
ngModule.component('vnClientSampleIndex', {
template: require('./index.html'),

View File

@ -43,7 +43,7 @@
<vn-td center>
<span
class="link"
ng-click="$ctrl.showTravelDescriptor($event, entry.travelFk)">
vn-click-stop="travelDescriptor.show($event, entry.travelFk)">
{{::entry.landed | date:'dd/MM/yyyy'}}
</span>
</vn-td>
@ -64,15 +64,8 @@
</a>
</vn-tbody>
</vn-table>
</vn-data-viewer>
</vn-card>
</vn-data-viewer>
<vn-travel-descriptor-popover
vn-id="travelDescriptor"
travel-id="$ctrl.selectedTravel">
vn-id="travelDescriptor">
</vn-travel-descriptor-popover>
<vn-popup vn-id="summary">
<vn-entry-summary
entry="$ctrl.entrySelected">
</vn-entry-summary>
</vn-popup>
<vn-scroll-up></vn-scroll-up>

View File

@ -1,17 +1,8 @@
import ngModule from '../module';
import Section from 'salix/components/section';
import './style.scss';
export default class Controller extends Section {
showTravelDescriptor(event, travelFk) {
if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
this.selectedTravel = travelFk;
this.$.travelDescriptor.parent = event.target;
this.$.travelDescriptor.show();
}
}
export default class Controller extends Section {}
ngModule.component('vnEntryIndex', {
template: require('./index.html'),

View File

@ -3,18 +3,18 @@
url="TicketRequests/filter"
limit="20"
data="requests"
order="shipped DESC, isOk ASC">
order="shipped DESC, isOk ASC"
auto-load="true">
</vn-crud-model>
<vn-portal slot="topbar">
<vn-searchbar vn-focus
<vn-searchbar
panel="vn-request-search-panel"
suggested-filter="$ctrl.filter.where"
info="Search request by id or alias">
info="Search request by id or alias"
model="model"
auto-state="false">
</vn-searchbar>
</vn-portal>
<vn-auto-search
on-search="$ctrl.onSearch($params)">
</vn-auto-search>
<vn-data-viewer model="model">
<vn-card>
<vn-table model="model">
@ -36,7 +36,7 @@
<vn-tr ng-repeat="request in requests">
<vn-td number>
<span class="link"
ng-click="$ctrl.showTicketDescriptor($event, request.ticketFk)">
ng-click="ticketDescriptor.show($event, request.ticketFk)">
{{request.ticketFk}}
</span>
</vn-td>
@ -52,7 +52,7 @@
<vn-td>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, request.attenderFk)">
ng-click="workerDescriptor.show($event, request.attenderFk)">
{{::request.atenderNickname}}
</span>
</vn-td>
@ -76,7 +76,7 @@
<vn-td expand>
<span
class="link"
ng-click="$ctrl.showItemDescriptor($event, request.itemFk)"
ng-click="itemDescriptor.show($event, request.itemFk)"
title="{{request.itemDescription}}">
{{request.itemDescription}}
</span>
@ -111,16 +111,17 @@
vn-id="itemDescriptor">
</vn-item-descriptor-popover>
<vn-dialog
vn-id="deny-dialog"
vn-id="denyDialog"
on-accept="$ctrl.onDenyAccept($data)"
on-close="$ctrl.onDenyClose()">
on-close="$ctrl.denyObservation = null">
<tpl-title translate>
Specify the reasons to deny this request
</tpl-title>
<tpl-body>
<h5 class="vn-pa-md" translate>Specify the reasons to deny this request</h5>
<vn-horizontal class="vn-pa-md">
<vn-textarea vn-focus
ng-model="$ctrl.denyObservation">
<vn-textarea
ng-model="$ctrl.denyObservation"
vn-focus>
</vn-textarea>
</vn-horizontal>
</tpl-body>
<tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>

View File

@ -25,11 +25,6 @@ export default class Controller extends Section {
}
}
$postLink() {
if (this.filter)
this.onSearch(this.filter);
}
getState(isOk) {
if (isOk === null)
return 'Nueva';
@ -62,11 +57,11 @@ export default class Controller extends Section {
quantity: request.saleQuantity
};
let endpoint = `Sales/${request.saleFk}/`;
let endpoint = `Sales/${request.saleFk}`;
this.$http.patch(endpoint, params).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
}).then(() => this.confirmRequest(request));
this.$http.patch(endpoint, params)
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
.then(() => this.confirmRequest(request));
} else
this.confirmRequest(request);
}
@ -85,30 +80,13 @@ export default class Controller extends Section {
return 'success';
}
onSearch(params) {
if (params)
this.$.model.applyFilter(null, params);
else
this.$.model.clear();
}
showDenyReason(event, requestId) {
this.selectedRequest = requestId;
this.$.denyReason.parent = event.target;
this.$.denyReason.show();
}
clear() {
delete this.denyRequestId;
}
onDenyAccept(request) {
let params = {
observation: this.denyObservation
};
let query = `TicketRequests/${request.id}/deny`;
return this.$http.post(query, params).then(res => {
return this.$http.post(`TicketRequests/${request.id}/deny`, params)
.then(res => {
const newRequest = res.data;
request.isOk = newRequest.isOk;
request.attenderFk = newRequest.attenderFk;
@ -117,38 +95,6 @@ export default class Controller extends Section {
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
onDenyClose() {
this.denyObservation = null;
}
showTicketDescriptor(event, ticketFk) {
this.$.ticketDescriptor.ticketFk = ticketFk;
this.$.ticketDescriptor.parent = event.target;
this.$.ticketDescriptor.show();
event.preventDefault();
event.stopImmediatePropagation();
}
showItemDescriptor(event, itemFk) {
this.$.itemDescriptor.itemFk = itemFk;
this.$.itemDescriptor.parent = event.target;
this.$.itemDescriptor.show();
}
showWorkerDescriptor(event, workerFk) {
this.$.workerDescriptor.workerFk = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
preventNavigation(event) {
event.preventDefault();
}
}
ngModule.component('vnItemRequest', {

View File

@ -1,5 +1,4 @@
import './index.js';
import crudModel from 'core/mocks/crud-model';
describe('Item', () => {
describe('Component vnItemRequest', () => {
@ -12,10 +11,7 @@ describe('Item', () => {
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
$scope.model = crudModel;
$scope.denyReason = {hide: () => {}};
const $element = angular.element('<vn-item-request></vn-item-request>');
controller = $componentController('vnItemRequest', {$element, $scope});
controller = $componentController('vnItemRequest', {$element: null, $scope});
}));
afterAll(() => {
@ -49,23 +45,20 @@ describe('Item', () => {
controller.confirmRequest(request);
expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith();
expect(controller.vnApp.showSuccess).not.toHaveBeenCalled();
});
it('should perform a query and call vnApp.showSuccess() and refresh if the conditions are met', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
let model = controller.$.model;
jest.spyOn(model, 'refresh');
const expectedResult = {concept: 'Melee Weapon'};
let request = {itemFk: 1, saleQuantity: 1, id: 1};
$httpBackend.when('POST', `TicketRequests/${request.id}/confirm`).respond(expectedResult);
$httpBackend.expect('POST', `TicketRequests/${request.id}/confirm`).respond(expectedResult);
$httpBackend.expectPOST(`TicketRequests/${request.id}/confirm`).respond(expectedResult);
controller.confirmRequest(request);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
@ -83,19 +76,17 @@ describe('Item', () => {
let request = {saleFk: 1, saleQuantity: 1};
jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.when('PATCH', `Sales/${request.saleFk}/`).respond();
$httpBackend.expect('PATCH', `Sales/${request.saleFk}/`).respond();
$httpBackend.expectPATCH(`Sales/${request.saleFk}`).respond();
controller.changeQuantity(request);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
describe('compareDate()', () => {
it(`should return "success" if receives a future date`, () => {
let date = '3019-02-18T11:00:00.000Z';
let result = controller.compareDate(date);
expect(result).toEqual('success');
@ -103,7 +94,6 @@ describe('Item', () => {
it(`should return "warning" if date is today`, () => {
let date = new Date();
let result = controller.compareDate(date);
expect(result).toEqual('warning');
@ -117,9 +107,8 @@ describe('Item', () => {
response: 'new'
};
const url = `TicketRequests/:id/deny`;
$httpBackend.expectRoute('POST', url).respond({response: 'denied'});
$httpBackend.expectPOST(`TicketRequests/${request.id}/deny`)
.respond({response: 'denied'});
controller.onDenyAccept(request);
$httpBackend.flush();

View File

@ -37,7 +37,7 @@
on-error-src/>
</vn-td>
<vn-td number>
<span ng-click="$ctrl.showDescriptor($event, row.itemFk)"
<span ng-click="descriptor.show($event, row.itemFk)"
class="link">
{{::row.itemFk | zeroFill:6}}
</span>

View File

@ -48,13 +48,6 @@ class Controller extends Section {
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')));
}
showDescriptor(event, itemFk) {
let descriptor = this.$.descriptor;
descriptor.itemFk = itemFk;
descriptor.parent = event.target;
descriptor.show();
}
save() {
this.$http.post(`Orders/${this.$params.id}/confirm`).then(() => {
this.vnApp.showSuccess(this.$t('Order confirmed'));

View File

@ -6,7 +6,8 @@ describe('Order', () => {
let controller;
let $httpBackend;
let rows = [
const vat = 10.5;
const rows = [
{
quantity: 4,
price: 10.5
@ -23,11 +24,10 @@ describe('Order', () => {
$httpBackend = _$httpBackend_;
$state.params.id = 1;
$httpBackend.whenRoute('GET', `OrderRows`).respond(rows);
$httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, 10.5);
$httpBackend.whenGET(`OrderRows`).respond(rows);
$httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, vat);
let $element = angular.element('<div></div>');
controller = $componentController('vnOrderLine', {$element});
controller = $componentController('vnOrderLine', {$element: null});
}));
describe('getRows()', () => {
@ -35,7 +35,7 @@ describe('Order', () => {
controller.getRows();
$httpBackend.flush();
expect(controller.rows).toBeDefined();
expect(controller.rows).toEqual(rows);
});
});
@ -44,7 +44,7 @@ describe('Order', () => {
controller.getVAT();
$httpBackend.flush();
expect(controller.VAT).toBeDefined();
expect(controller.VAT).toBe(vat);
});
});
@ -59,7 +59,7 @@ describe('Order', () => {
$httpBackend.flush();
expect(controller.rows.length).toBe(1);
expect(controller.card.reload).toHaveBeenCalledWith();
expect(controller.card.reload).toHaveBeenCalled();
});
});
});

View File

@ -63,7 +63,7 @@
</vn-td>
<vn-td shrink>
<span
ng-click="$ctrl.showDescriptor($event, row.itemFk)"
ng-click="descriptor.show($event, row.itemFk)"
class="link">
{{::row.itemFk | zeroFill:6}}
</span>

View File

@ -4,10 +4,8 @@ import './style.scss';
class Controller extends Section {
setSummary() {
this.$http.get(`Orders/${this.order.id}/summary`).then(res => {
if (res && res.data)
this.summary = res.data;
});
this.$http.get(`Orders/${this.order.id}/summary`)
.then(res => this.summary = res.data);
}
get formattedAddress() {
@ -23,16 +21,6 @@ class Controller extends Section {
if (this.order && this.order.id)
this.setSummary();
}
showDescriptor(event, itemFk) {
this.$.descriptor.itemFk = itemFk;
this.$.descriptor.parent = event.target;
this.$.descriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
}
ngModule.component('vnOrderSummary', {

View File

@ -16,14 +16,15 @@ describe('Order', () => {
describe('getSummary()', () => {
it('should now perform a GET query and define the summary property', () => {
let res = {id: 1, nickname: 'Batman'};
$httpBackend.when('GET', `Orders/1/summary`).respond(200, res);
$httpBackend.expect('GET', `Orders/1/summary`);
let res = {
id: 1,
nickname: 'Batman'
};
$httpBackend.expectGET(`Orders/1/summary`).respond(res);
controller.setSummary();
$httpBackend.flush();
expect(controller.summary).toBeDefined();
expect(controller.summary.nickname).toEqual('Batman');
expect(controller.summary).toEqual(res);
});
});

View File

@ -34,7 +34,7 @@
<vn-tr ng-repeat="row in rows">
<vn-td number>
<span
ng-click="$ctrl.showDescriptor($event, row.itemFk)"
ng-click="descriptor.show($event, row.itemFk)"
class="link">
{{::row.itemFk}}
</span>

View File

@ -16,27 +16,15 @@ class Controller extends Section {
onDataChange() {
this.$http.get(`Orders/${this.$params.id}/getVolumes`)
.then(response => {
if (response.data) {
.then(res => {
this.$.model.data.forEach(order => {
response.data.volumes.forEach(volume => {
res.data.volumes.forEach(volume => {
if (order.itemFk === volume.itemFk)
order.volume = volume.volume;
});
});
}
});
}
showDescriptor(event, itemFk) {
this.$.descriptor.itemFk = itemFk;
this.$.descriptor.parent = event.target;
this.$.descriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
}
ngModule.component('vnOrderVolume', {

View File

@ -4,58 +4,39 @@ describe('Order', () => {
describe('Component vnOrderVolume', () => {
let controller;
let $httpBackend;
let $state;
let $scope;
beforeEach(ngModule('order'));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, $rootScope) => {
beforeEach(angular.mock.inject(($componentController, $state, _$httpBackend_, $rootScope) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
$scope.model = {data: [{itemFk: 1}, {itemFk: 2}], accept: () => {
return {
then: () => {}
$scope.model = {
data: [
{itemFk: 1},
{itemFk: 2}
]
};
}};
$scope.descriptor = {show: () => {}};
$scope.popover = {relocate: () => {}};
$state = _$state_;
$state.params.id = 1;
const $element = angular.element('<vn-order-volume></vn-order-volume>');
controller = $componentController('vnOrderVolume', {$element, $scope});
}));
it('should join the sale volumes to its respective sale', () => {
let response = {volumes: [{itemFk: 1, volume: 0.008}, {itemFk: 2, volume: 0.003}]};
$httpBackend.whenGET(`Orders/1/getVolumes`).respond(response);
$httpBackend.expectGET(`Orders/1/getVolumes`);
let response = {
volumes: [
{itemFk: 1, volume: 0.008},
{itemFk: 2, volume: 0.003}
]
};
$httpBackend.expectGET(`Orders/1/getVolumes`).respond(response);
controller.onDataChange();
$httpBackend.flush();
expect(controller.$.model.data[0].volume).toBe(0.008);
expect(controller.$.model.data[1].volume).toBe(0.003);
});
describe('showDescriptor()', () => {
it('should set $scope.descriptor.itemFk, $scope.descriptor.parent and call $scope.descriptor.show()', () => {
let event = {target: 1};
let itemFk = 1;
jest.spyOn(controller.$.descriptor, 'show');
controller.showDescriptor(event, itemFk);
expect(controller.$.descriptor.itemFk).toBe(1);
expect(controller.$.descriptor.parent).toBe(1);
expect(controller.$.descriptor.show).toHaveBeenCalledWith();
});
});
describe('onDescriptorLoad()', () => {
it('should call $scope.popover.relocate()', () => {
jest.spyOn(controller.$.popover, 'relocate');
controller.onDescriptorLoad();
expect(controller.$.popover.relocate).toHaveBeenCalledWith();
});
});
});
});

View File

@ -26,7 +26,7 @@
<vn-td expand>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, route.workerFk)">
vn-click-stop="workerDescriptor.show($event, route.workerFk)">
{{::route.workerNickname}}
</span>
</vn-td>
@ -37,7 +37,7 @@
<vn-td>{{::route.description | dashIfEmpty}}</vn-td>
<vn-td>
<vn-icon-button
ng-click="$ctrl.preview($event, route)"
vn-click-stop="$ctrl.preview(route)"
vn-tooltip="Preview"
icon="desktop_windows">
</vn-icon-button>
@ -61,4 +61,3 @@
fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>
<vn-scroll-up></vn-scroll-up>

View File

@ -2,21 +2,7 @@ import ngModule from '../module';
import Section from 'salix/components/section';
export default class Controller extends Section {
showWorkerDescriptor(event, workerFk) {
if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
this.selectedWorker = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
preview(event, route) {
if (event.defaultPrevented) return;
event.preventDefault();
event.stopPropagation();
preview(route) {
this.routeSelected = route;
this.$.summary.show();
}

View File

@ -9,8 +9,7 @@ class Controller extends Section {
order: 'concept ASC',
include: [{
relation: 'item',
},
{
}, {
relation: 'components',
scope: {
fields: ['componentFk', 'value'],

View File

@ -60,7 +60,7 @@
</vn-td>
<vn-td shrink>
<span class="link"
ng-click="$ctrl.showWorkerDescriptor($event, document.dms.workerFk)">
ng-click="workerDescriptor.show($event, document.dms.workerFk)">
{{::document.dms.worker.user.nickname | dashIfEmpty}}
</span></vn-td>
<vn-td>
@ -83,7 +83,7 @@
</vn-td>
<vn-td shrink>
<vn-icon-button icon="delete"
ng-click="$ctrl.showDeleteConfirm($index)"
ng-click="confirm.show($index)"
title="{{'Remove file' | translate}}"
tabindex="-1">
</vn-icon-button>
@ -106,5 +106,5 @@
vn-id="confirm"
message="This file will be deleted"
question="Are you sure you want to continue?"
on-response="$ctrl.deleteDms($response)">
on-accept="$ctrl.deleteDms($data)">
</vn-confirm>

View File

@ -42,30 +42,15 @@ class Controller extends Section {
};
}
showWorkerDescriptor(event, workerFk) {
event.preventDefault();
event.stopImmediatePropagation();
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.workerFk = workerFk;
this.$.workerDescriptor.show();
}
showDeleteConfirm(index) {
this.dmsIndex = index;
this.$.confirm.show();
}
deleteDms(response) {
if (response === 'accept') {
const dmsFk = this.ticketDms[this.dmsIndex].dmsFk;
const query = `ticketDms/${dmsFk}/removeFile`;
this.$http.post(query).then(() => {
this.$.model.remove(this.dmsIndex);
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
deleteDms(index) {
const dmsFk = this.ticketDms[index].dmsFk;
this.$http.post(`ticketDms/${dmsFk}/removeFile`)
.then(() => {
this.$.model.remove(index);
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
}
}
ngModule.component('vnTicketDmsIndex', {
template: require('./index.html'),

View File

@ -10,27 +10,25 @@ describe('Ticket', () => {
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
const $element = angular.element('<vn-ticket-dms-index></vn-ticket-dms-index>');
controller = $componentController('vnTicketDmsIndex', {$element});
controller = $componentController('vnTicketDmsIndex', {$element: null});
controller.$.model = crudModel;
}));
describe('deleteDms()', () => {
it('should make an HTTP Post query', () => {
const dmsId = 1;
const dmsIndex = 0;
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$.model, 'remove');
controller.ticketDms = [{dmsFk: 1}];
controller.dmsIndex = dmsIndex;
$httpBackend.when('POST', `ticketDms/${dmsId}/removeFile`).respond({});
$httpBackend.expect('POST', `ticketDms/${dmsId}/removeFile`);
controller.deleteDms('accept');
const dmsId = 1;
const dmsIndex = 0;
controller.ticketDms = [{dmsFk: 1}];
$httpBackend.expectPOST(`ticketDms/${dmsId}/removeFile`).respond({});
controller.deleteDms(dmsIndex);
$httpBackend.flush();
expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex);
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
});

View File

@ -28,7 +28,7 @@
<vn-tr ng-repeat="expedition in expeditions">
<vn-td class="vn-px-md" style="width:30px; color:#FFA410;">
<vn-icon-button icon="delete"
ng-click="$ctrl.deleteExpedition(expedition)"
ng-click="deleteExpedition.show(expedition.id)"
vn-tooltip="Delete expedition">
</vn-icon-button>
</vn-td>
@ -48,7 +48,7 @@
<vn-td expand>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, expedition.workerFk)">
ng-click="workerDescriptor.show($event, expedition.workerFk)">
{{::expedition.userNickname | dashIfEmpty}}
</span>
</vn-td>
@ -66,8 +66,8 @@
vn-id="workerDescriptor">
</vn-worker-descriptor-popover>
<vn-confirm
vn-id="delete-expedition"
on-response="$ctrl.returnDialog($response)"
vn-id="deleteExpedition"
on-accept="$ctrl.onDialogAccept($data)"
question="Delete expedition"
message="Are you sure you want to delete this expedition?">
</vn-confirm>

View File

@ -2,17 +2,9 @@ import ngModule from '../module';
import Section from 'salix/components/section';
class Controller extends Section {
deleteExpedition(expedition) {
this.expeditionId = expedition.id;
this.$.deleteExpedition.show();
}
returnDialog(response) {
if (response === 'accept') {
this.$http.delete(`Expeditions/${this.expeditionId}`).then(
() => this.$.model.refresh()
);
}
onDialogAccept(id) {
return this.$http.delete(`Expeditions/${id}`)
.then(() => this.$.model.refresh());
}
showItemDescriptor(event, itemFk) {
@ -32,18 +24,6 @@ class Controller extends Section {
this.$.itemDescriptor.parent = event.target;
this.$.itemDescriptor.show();
}
showWorkerDescriptor(event, workerFk) {
event.preventDefault();
event.stopImmediatePropagation();
this.selectedWorker = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
}
ngModule.component('vnTicketExpedition', {

View File

@ -14,20 +14,17 @@ describe('Ticket', () => {
$scope.model = {
refresh: () => {}
};
const $element = angular.element('<vn-ticket-expedition></vn-ticket-expedition>');
controller = $componentController('vnTicketExpedition', {$element, $scope});
controller = $componentController('vnTicketExpedition', {$element: null, $scope});
}));
describe('returnDialog()', () => {
describe('onDialogAccept()', () => {
it('should perform a DELETE query', () => {
jest.spyOn($scope.model, 'refresh');
let response = 'accept';
controller.expeditionId = 1;
const id = 1;
$httpBackend.when('DELETE', `Expeditions/1`).respond(200);
$httpBackend.expect('DELETE', `Expeditions/1`);
controller.returnDialog(response);
$httpBackend.expectDELETE(`Expeditions/${id}`).respond(200);
controller.onDialogAccept(id);
$httpBackend.flush();
expect($scope.model.refresh).toHaveBeenCalledWith();

View File

@ -25,7 +25,7 @@
</div>
<div class="description">
<h3>
<span class="link" ng-click="$ctrl.showDescriptor($event, sale.item.id)">
<span class="link" ng-click="descriptor.show($event, sale.item.id)">
{{::sale.item.name}}
</span>
</h3>

View File

@ -13,16 +13,6 @@ class Controller extends Section {
}
};
}
showDescriptor(event, itemFk) {
this.$.descriptor.itemFk = itemFk;
this.$.descriptor.parent = event.target;
this.$.descriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
}
ngModule.component('vnTicketPicture', {

View File

@ -43,14 +43,14 @@
<vn-td>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, request.requesterFk)">
ng-click="workerDescriptor.show($event, request.requesterFk)">
{{::request.requester.user.nickname | dashIfEmpty}}
</span>
</vn-td>
<vn-td>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, request.attenderFk)">
ng-click="workerDescriptor.show($event, request.attenderFk)">
{{::request.atender.user.nickname | dashIfEmpty}}
</span>
</vn-td>

View File

@ -16,8 +16,7 @@ class Controller extends Section {
}
}
}
},
{
}, {
relation: 'requester',
scope: {
include: {
@ -27,8 +26,7 @@ class Controller extends Section {
}
}
}
},
{
}, {
relation: 'sale'
}
]
@ -60,14 +58,6 @@ class Controller extends Section {
this.$.itemDescriptor.show();
}
showWorkerDescriptor(event, workerFk) {
event.preventDefault();
event.stopImmediatePropagation();
this.selectedWorker = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
getRequestState(state) {
switch (state) {
case null:

View File

@ -6,9 +6,8 @@ describe('Ticket', () => {
beforeEach(ngModule('ticket'));
beforeEach(angular.mock.inject($componentController => {
const $element = angular.element('<vn-ticket-request-index></vn-ticket-request-index>');
controller = $componentController('vnTicketRequestIndex', {$element});
beforeEach(inject($componentController => {
controller = $componentController('vnTicketRequestIndex', {$element: null});
}));
describe('getRequestState()', () => {

View File

@ -33,10 +33,6 @@ class Controller extends Section {
this.$.descriptor.parent = event.target;
this.$.descriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
}
ngModule.component('vnTicketSaleChecked', {

View File

@ -52,7 +52,7 @@
<vn-td expand>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, sale.workerFk)">
ng-click="workerDescriptor.show($event, sale.workerFk)">
{{::sale.userNickname | dashIfEmpty}}
</span>
</vn-td>

View File

@ -18,18 +18,6 @@ class Controller extends Section {
this.$.itemDescriptor.parent = event.target;
this.$.itemDescriptor.show();
}
showWorkerDescriptor(event, workerFk) {
event.preventDefault();
event.stopImmediatePropagation();
this.selectedWorker = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
}
ngModule.component('vnTicketSaleTracking', {

View File

@ -9,7 +9,6 @@
</vn-watcher>
<vn-vertical class="vn-w-xl">
<vn-card class="vn-pa-lg">
<vn-vertical>
<vn-horizontal class="header">
<vn-tool-bar class="vn-mb-md">
<vn-button
@ -37,13 +36,13 @@
</vn-button-menu>
<vn-button
disabled="!$ctrl.isChecked || !$ctrl.isEditable"
ng-click="$ctrl.showRemoveLinesDialog()"
ng-click="deleteLines.show()"
vn-tooltip="Remove lines"
icon="delete">
</vn-button>
<vn-button
disabled="!$ctrl.isChecked || !$ctrl.isEditable"
ng-click="$ctrl.showTransferPopover($event);"
ng-click="transfer.show()"
vn-tooltip="Transfer lines"
icon="call_split">
</vn-button>
@ -200,7 +199,6 @@
vn-bind="+"
fixed-bottom-right>
</vn-float-button>
<vn-item-descriptor-popover
vn-id="descriptor"
quicklinks="$ctrl.quicklinks">

View File

@ -228,16 +228,6 @@ class Controller extends Section {
}
}
showRemoveLinesDialog() {
this.$.deleteLines.show();
}
showTransferPopover(event) {
this.setTransferParams();
this.$.transfer.parent = event.target;
this.$.transfer.show();
}
setTransferParams() {
const checkedSales = JSON.stringify(this.checkedLines());
const sales = JSON.parse(checkedSales);
@ -312,10 +302,6 @@ class Controller extends Section {
this.$.descriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
showEditPricePopover(event, sale) {
if (!this.isEditable) return;
this.sale = sale;

View File

@ -61,10 +61,6 @@ class Controller extends Section {
this.$.descriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
get isEditable() {
try {
return !this.ticket.state.state.alertLevel;

View File

@ -24,7 +24,7 @@
<vn-td expand>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, tracking.worker.user.id)">
ng-click="workerDescriptor.show($event, tracking.worker.user.id)">
{{::tracking.worker.user.nickname | dashIfEmpty}}
</span>
</vn-td>

View File

@ -17,8 +17,7 @@ class Controller extends Section {
}
}
}
},
{
}, {
relation: 'state',
scope: {
fields: ['name']
@ -27,14 +26,6 @@ class Controller extends Section {
]
};
}
showWorkerDescriptor(event, workerFk) {
event.preventDefault();
event.stopImmediatePropagation();
this.selectedWorker = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
}
ngModule.component('vnTicketTrackingIndex', {

View File

@ -60,10 +60,6 @@ class Controller extends Section {
this.$.descriptor.parent = event.target;
this.$.descriptor.show();
}
onDescriptorLoad() {
this.$.popover.relocate();
}
}
ngModule.component('vnTicketVolume', {

View File

@ -66,16 +66,21 @@ describe('ticket', () => {
});
});
/* it('should join the sale volumes to its respective sale', () => {
/*
it('should join the sale volumes to its respective sale', () => {
controller.ticket = {id: 1};
let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]};
$httpBackend.whenGET(`tickets/1/getVolume`).respond(response);
$httpBackend.expectGET(`tickets/1/getVolume`);
let response = {volumes: [
{saleFk: 1, m3: 0.008},
{saleFk: 2, m3: 0.003}
]};
$httpBackend.expectGET(`tickets/1/getVolume`).respond(response);
controller.onDataChange();
$httpBackend.flush();
expect($scope.model.data[0].volume.m3).toBe(0.008);
expect($scope.model.data[1].volume.m3).toBe(0.003);
}); */
});
*/
});
});

View File

@ -64,7 +64,7 @@
<vn-td shrink>
<vn-icon-button
icon="delete"
ng-click="$ctrl.showDeleteConfirm($index)"
ng-click="confirm.show($index)"
title="{{'Remove file' | translate}}"
tabindex="-1">
</vn-icon-button>
@ -74,10 +74,7 @@
</vn-table>
</vn-card>
</vn-data-viewer>
<vn-worker-descriptor-popover
vn-id="workerDescriptor">
</vn-worker-descriptor-popover>
<a ui-sref="worker.card.create"
<a ui-sref="worker.card.dms.create"
vn-tooltip="Upload file"
vn-bind="+"
fixed-bottom-right>
@ -87,5 +84,5 @@
vn-id="confirm"
message="This file will be deleted"
question="Are you sure you want to continue?"
on-response="$ctrl.deleteDms($response)">
on-accept="$ctrl.deleteDms($data)">
</vn-confirm>

View File

@ -19,13 +19,13 @@ class Controller extends Component {
'file',
'created',
],
include: [{
include: [
{
relation: 'dmsType',
scope: {
fields: ['name']
}
},
{
}, {
relation: 'worker',
scope: {
fields: ['userFk'],
@ -36,36 +36,22 @@ class Controller extends Component {
}
},
}
}]
}
]
},
}
};
}
showWorkerDescriptor(event, workerFk) {
event.preventDefault();
event.stopImmediatePropagation();
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.workerFk = workerFk;
this.$.workerDescriptor.show();
}
showDeleteConfirm(index) {
this.dmsIndex = index;
this.$.confirm.show();
}
deleteDms(response) {
if (response === 'accept') {
const workerDmsId = this.workerDms[this.dmsIndex].id;
const query = `WorkerDms/${workerDmsId}/removeFile`;
this.$http.post(query).then(() => {
this.$.model.remove(this.dmsIndex);
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
deleteDms(index) {
const workerDmsId = this.workerDms[index].dmsFk;
return this.$http.post(`WorkerDms/${workerDmsId}/removeFile`)
.then(() => {
this.$.model.remove(index);
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
}
}
ngModule.component('vnWorkerDmsIndex', {
template: require('./index.html'),

View File

@ -4,36 +4,33 @@ import crudModel from 'core/mocks/crud-model';
describe('Worker', () => {
describe('Component vnWorkerDmsIndex', () => {
let $scope;
let $element;
let $httpBackend;
let controller;
beforeEach(ngModule('worker'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
$element = angular.element(`<vn-worker-dms-index></vn-worker-dms-index`);
controller = $componentController('vnWorkerDmsIndex', {$element, $scope});
controller = $componentController('vnWorkerDmsIndex', {$element: null, $scope});
controller.$.model = crudModel;
}));
describe('deleteDms()', () => {
it('should make an HTTP Post query', () => {
const workerDmsId = 1;
const dmsIndex = 0;
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$.model, 'remove');
controller.workerDms = [{id: 1, dmsFk: 4}];
controller.dmsIndex = dmsIndex;
$httpBackend.when('POST', `WorkerDms/${workerDmsId}/removeFile`).respond({});
$httpBackend.expect('POST', `WorkerDms/${workerDmsId}/removeFile`);
controller.deleteDms('accept');
const workerDmsId = 4;
const dmsIndex = 0;
controller.workerDms = [{id: 1, dmsFk: 4}];
$httpBackend.expectPOST(`WorkerDms/${workerDmsId}/removeFile`).respond();
controller.deleteDms(dmsIndex);
$httpBackend.flush();
expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex);
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
});

View File

@ -32,7 +32,7 @@
<span translate class="label">Changed by</span><span class="label">: </span>
<span
ng-class="{'link': log.user.worker.id, 'value': !log.user.worker.id}"
ng-click="$ctrl.showWorkerDescriptor($event, log.user.worker.id)"
ng-click="workerDescriptor.show($event, log.user.id)"
translate>{{::log.user.name | dashIfEmpty}}
</span>
</div>
@ -53,7 +53,7 @@
<vn-td class="expendable">
<span
ng-class="{'link': log.user.worker.id, 'value': !log.user.worker.id}"
ng-click="$ctrl.showWorkerDescriptor($event, log.user.worker.id)"
ng-click="workerDescriptor.show($event, log.user.id)"
translate>{{::log.user.name | dashIfEmpty}}
</span>
</vn-td>

View File

@ -42,18 +42,6 @@ export default class Controller extends Section {
}
}
showWorkerDescriptor(event, workerFk) {
if (event.defaultPrevented) return;
if (!workerFk) return;
event.preventDefault();
event.stopPropagation();
this.selectedWorker = workerFk;
this.$.workerDescriptor.parent = event.target;
this.$.workerDescriptor.show();
}
getInstance(instance) {
const properties = [];
let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/;