new section thermograph
gitea/salix/1981-travel_thermograph This commit looks good Details

This commit is contained in:
Bernat Exposito Domenech 2020-01-13 11:53:10 +01:00
parent 456845dbd6
commit f4e3649d9e
11 changed files with 196 additions and 11 deletions

View File

@ -1,6 +1,9 @@
{
"name": "TravelThermograph",
"base": "VnModel",
"base": "Loggable",
"log": {
"model":"TravelLog"
},
"options": {
"mysql": {
"table": "travelThermograph"

View File

@ -9,3 +9,5 @@ import './summary';
import './basic-data';
import './log';
import './create';
import './thermograph';

View File

@ -16,3 +16,4 @@ New travel: Nuevo envío
# Sections
Travels: Envíos
Log: Historial
Thermographs: Termómetros

View File

@ -10,7 +10,8 @@
],
"card": [
{"state": "travel.card.basicData", "icon": "settings"},
{"state": "travel.card.log", "icon": "history"}
{"state": "travel.card.log", "icon": "history"},
{"state": "travel.card.thermograph", "icon": "icon-thermometer"}
]
},
"routes": [
@ -57,6 +58,15 @@
"state": "travel.create",
"component": "vn-travel-create",
"description": "New travel"
}, {
"url" : "/thermograph",
"state": "travel.card.thermograph",
"component": "vn-travel-thermograph",
"description": "Thermographs",
"params": {
"travel": "$ctrl.travel"
},
"acl": ["buyer"]
}
]
}

View File

@ -107,6 +107,29 @@
</vn-tfoot>
</vn-table>
</vn-auto>
<vn-auto>
<h4 translate>Thermographs</h4>
<vn-table>
<vn-thead>
<vn-tr>
<vn-th>Code</vn-th>
<vn-th>Temperature</vn-th>
<vn-th expand>State</vn-th>
<vn-th>Destination</vn-th>
<vn-th>Created</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="thermograph in $ctrl.travelThermographs">
<vn-td>{{thermograph.thermographFk}} </vn-td>
<vn-td>{{thermograph.temperature}}</vn-td>
<vn-td>{{thermograph.result}}</vn-td>
<vn-td>{{thermograph.warehouse.name}}</vn-td>
<vn-td>{{thermograph.created | date: 'dd/MM/yyyy'}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-auto>
</vn-horizontal>
</vn-card>
<vn-ticket-descriptor-popover

View File

@ -1,11 +1,12 @@
import ngModule from '../module';
import './style.scss';
import Component from 'core/lib/component';
class Controller {
constructor($scope, $http) {
this.$ = $scope;
this.$http = $http;
class Controller extends Component {
constructor($element, $, $httpParamSerializer) {
super($element, $);
this.entries = [];
this.$httpParamSerializer = $httpParamSerializer;
}
get travel() {
@ -18,6 +19,7 @@ class Controller {
if (value && value.id) {
this.getTravel();
this.getEntries();
this.getThermographs();
}
}
@ -33,6 +35,27 @@ class Controller {
});
}
getThermographs() {
const params = {
filter: {
include: {
relation: 'warehouse',
scope: {
fields: ['id', 'name']
}
},
where: {
travelFk: this.travel.id
}
}
};
const serializedParams = this.$httpParamSerializer(params);
return this.$http.get(`TravelThermographs?${serializedParams}`).then(res => {
this.travelThermographs = res.data;
});
}
total(field) {
let total = 0;
@ -43,7 +66,7 @@ class Controller {
}
}
Controller.$inject = ['$scope', '$http'];
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
ngModule.component('vnTravelSummary', {
template: require('./index.html'),

View File

@ -3,15 +3,20 @@ import './index';
describe('component vnTravelSummary', () => {
let controller;
let $httpBackend;
let $scope;
let $element;
let $httpParamSerializer;
beforeEach(angular.mock.module('travel', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnTravelSummary');
$httpParamSerializer = _$httpParamSerializer_;
$scope = $rootScope.$new();
$element = angular.element(`<vn-travel-summary></vn-travel-summary>`);
controller = $componentController('vnTravelSummary', {$element, $scope});
}));
describe('travel setter/getter', () => {
@ -24,12 +29,14 @@ describe('component vnTravelSummary', () => {
it('should return the travel and then call both getTravel() and getEntries()', () => {
spyOn(controller, 'getTravel');
spyOn(controller, 'getEntries');
spyOn(controller, 'getThermographs');
controller.travel = {id: 99};
expect(controller._travel.id).toEqual(99);
expect(controller.getTravel).toHaveBeenCalledWith();
expect(controller.getEntries).toHaveBeenCalledWith();
expect(controller.getThermographs).toHaveBeenCalledWith();
});
});
@ -59,6 +66,32 @@ describe('component vnTravelSummary', () => {
});
});
describe('getThermographs()', () => {
it('should call the getThermographs method to get the thermographs', () => {
controller._travel = {id: 2};
const params = {
filter: {
include: {
relation: 'warehouse',
scope: {
fields: ['id', 'name']
}
},
where: {
travelFk: controller._travel.id
}
}
};
const serializedParams = $httpParamSerializer(params);
const query = `TravelThermographs?${serializedParams}`;
$httpBackend.expectGET(query).respond('I am the thermographs');
controller.getThermographs();
$httpBackend.flush();
expect(controller.travelThermographs).toEqual('I am the thermographs');
});
});
describe('total()', () => {
it('should calculate the total amount of a given property for every row', () => {
controller.entries = [

View File

@ -0,0 +1,50 @@
<vn-crud-model
vn-id="model"
url="TravelThermographs"
data="$ctrl.travelThermographs"
order="created"
link="{travelFk: $ctrl.$params.id}"
filter="$ctrl.filter"
auto-load="true">
</vn-crud-model>
<vn-data-viewer model="model">
<form name="form">
<vn-card class="vn-mt-md">
<vn-table model="model" auto-load="false">
<vn-thead>
<vn-tr>
<vn-th>Code</vn-th>
<vn-th>Temperature</vn-th>
<vn-th expand>State</vn-th>
<vn-th>Destination</vn-th>
<vn-th>Created</vn-th>
<vn-th shrink></vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="thermograph in $ctrl.travelThermographs">
<vn-td>{{thermograph.thermographFk}} </vn-td>
<vn-td>{{thermograph.temperature}} </vn-td>
<vn-td expand>{{thermograph.result}}</vn-td>
<vn-td>{{thermograph.warehouse.name}}</vn-td>
<vn-td>{{thermograph.created | date: 'dd/MM/yyyy'}}</vn-td>
<vn-td shrink>
<vn-icon-button
icon="delete"
ng-click="$ctrl.showDeleteConfirm($index)"
title="{{'Remove thermograph' | translate}}"
tabindex="-1">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
</form>
</vn-data-viewer>
<vn-confirm
vn-id="confirm"
question="Delete thermograph from travel?"
on-response="$ctrl.removeThermographFromTravel($response)">
</vn-confirm>

View File

@ -0,0 +1,28 @@
import ngModule from '../module';
import './style.scss';
import Component from 'core/lib/component';
class Controller extends Component {
constructor($element, $) {
super($element, $);
this.filter = {
include:
{relation: 'warehouse',
scope: {
fields: ['id', 'name']
}
}
};
}
}
ngModule.component('vnTravelThermograph', {
template: require('./index.html'),
controller: Controller,
require: {
card: '^vnTravelCard'
},
bindings: {
travel: '<'
}
});

View File

@ -0,0 +1,6 @@
Code: Código
Temperature: Temperatura
State: Estado
Destination: Destino
Created: Creado
Remove thermograph: Eliminar termómetro

View File

@ -0,0 +1,6 @@
@import "variables";
vn-route-tickets form{
margin: 0 auto;
max-width: $width-lg;
}