Merge, errores en spinner solucionados

This commit is contained in:
Juan Ferrer Toribio 2017-11-16 13:46:56 +01:00
commit 519a55fac7
225 changed files with 73324 additions and 1182 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.DS_Store
node_modules
build
npm-debug.log

54
Jenkinsfile vendored
View File

@ -1,58 +1,54 @@
#!/usr/bin/env groovy
def branchName = "${env.BRANCH_NAME}";
def buildNumber = "${env.BUILD_NUMBER}";
def branchProduction = "master"
def branchTest = "test";
def dockerHost = "${env.DOCKER_HOST}";
env.BRANCH_NAME = branchName;
env.TAG = "${env.BUILD_NUMBER}";
if (branchName == branchProduction)
dockerHost = "tcp://172.16.255.29:2375";
switch (branchName){
case branchTest:
env.NODE_ENV = "development";
break;
case branchProduction:
env.DOCKER_HOST = "tcp://172.16.255.29:2375";
env.NODE_ENV = "production"
break;
}
node
{
stage ('Print environment variables'){
echo "Branch ${branchName}, Build ${env.TAG}, NODE_ENV ${env.NODE_ENV} en docker Host ${env.DOCKER_HOST}"
}
stage ('Checkout') {
checkout scm
}
stage ('install modules'){
sh "npm install"
}
stage ('build Project Salix'){
stage ('build Project'){
sh "gulp build"
}
stage ("docker ${element}")
stage ("docker")
{
stage ("Stopping ${prefixDocker}-${element} actual")
stage ("install modules loopback service")
{
try
{
def returnDocker = sh (script: "docker stop ${prefixDocker}-${element}", returnStdout: true).trim();
echo "${returnDocker}";
returnDocker = sh (script: "docker rm ${prefixDocker}-${element}", returnStdout: false).trim();
//echo "${returnDocker}";
returnDocker = sh (script: "docker rmi ${prefixDocker}-${element}:${buildNumber-3}", returnStdout: true).trim();
echo "borran ${prefixDocker}-${element}:${buildNumber-3}";
//echo "${returnDocker}";
}catch(Exception _){
echo "Error Stage Stopping"
}
sh "cd ./services/loopback && npm install"
}
stage ("Stopping/Removing Docker")
{
sh "docker-compose down --rmi 'all'"
}
stage ("Generar dockers")
{
stage ("build dockers")
{
sh "docker-compose build "
}
stage ("up dockers")
{
sh "docker-compose up -d"
}
sh "docker-compose up -d --build"
}
}
}

View File

@ -43,6 +43,10 @@ npm run testWatch or test for single run
on root run:
gulp docker
wait 10 secs for db to be ready
npm run e2e
## Built With

View File

@ -1,18 +1,18 @@
<div>
<div class="box-wrapper">
<div class="box">
<img src="./logo.svg"/>
<form name="form" ng-submit="$ctrl.submit()">
<vn-textfield vn-id="userField" label="User" model="$ctrl.user" vn-focus></vn-textfield>
<vn-textfield label="Password" model="$ctrl.password" type="password"></vn-textfield>
<div class="footer">
<vn-submit label="Enter"></vn-submit>
<div class="spinner-wrapper">
<vn-spinner enable="$ctrl.loading"></vn-spinner>
<div class="box">
<img src="./logo.svg"/>
<form name="form" ng-submit="$ctrl.submit()">
<vn-textfield vn-id="userField" label="User" model="$ctrl.user" vn-focus></vn-textfield>
<vn-textfield label="Password" model="$ctrl.password" type="password"></vn-textfield>
<div class="footer">
<vn-submit label="Enter"></vn-submit>
<div class="spinner-wrapper">
<vn-spinner enable="$ctrl.loading"></vn-spinner>
</div>
</div>
</div>
</form>
</div>
</form>
</div>
</div>
<vn-snackbar vn-id="snackbar"></vn-snackbar>
</div>

View File

@ -16,6 +16,7 @@ vn-login > div {
margin: auto;
height: inherit;
}
.box {
box-sizing: border-box;
position: absolute;
@ -27,15 +28,18 @@ vn-login > div {
box-shadow: 0 0 1em 0 rgba(1,1,1,.6);
border-radius: .5em;
}
img {
width: 100%;
padding-bottom: 1em;
}
.footer {
margin-top: 1em;
text-align: center;
position: relative;
}
.spinner-wrapper {
position: absolute;
width: 0;

View File

@ -7,7 +7,8 @@
{
"url": "/clients",
"state": "clients",
"component": "vn-client-index"
"component": "vn-client-index",
"acl": ["employee"]
}, {
"url": "/create",
"state": "create",
@ -47,7 +48,7 @@
"client": "$ctrl.client"
},
"menu": {
"description": "Datos facturación",
"description": "Pay method",
"icon": "assignment"
}
}, {

View File

@ -30,7 +30,7 @@
<vn-horizontal>
<vn-autocomplete vn-one
field="$ctrl.address.agencyFk"
url="/client/api/AgencyServices"
url="/client/api/AgencyModes"
show-field="name"
value-field="id"
label="Agency">

View File

@ -2,6 +2,7 @@ import './address-create.js';
describe('Client', () => {
describe('Component vnAddressCreate', () => {
let controller;
let $componentController;
let $state;
@ -13,11 +14,10 @@ describe('Client', () => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.id = '1234';
controller = $componentController('vnAddressCreate', {$state});
}));
it('should define and set address property', () => {
let controller = $componentController('vnAddressCreate', {$state});
expect(controller.address.clientFk).toBe(1234);
expect(controller.address.isEnabled).toBe(true);
});

View File

@ -11,8 +11,12 @@
<vn-vertical pad-large>
<vn-title>Address</vn-title>
<vn-horizontal>
<vn-check vn-one label="enabled" field="$ctrl.address.isEnabled"></vn-check>
<vn-check vn-one label="Is equalizated" field="$ctrl.address.isEqualizated"></vn-check>
<vn-one>
<vn-check label="enabled" field="$ctrl.address.isEnabled"></vn-check>
</vn-one>
<vn-one>
<vn-check label="Is equalizated" field="$ctrl.address.isEqualizated"></vn-check>
</vn-one>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Consignee" field="$ctrl.address.consignee" vn-focus></vn-textfield>
@ -32,8 +36,9 @@
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-one
initial-data="$ctrl.address.defaultAgency"
field="$ctrl.address.defaultAgencyFk"
url="/client/api/AgencyServices"
url="/client/api/AgencyModes"
show-field="name"
value-field="id"
label="Agency">

View File

@ -4,6 +4,7 @@ describe('Client', () => {
describe('Component vnAddressEdit', () => {
let $componentController;
let $state;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -13,11 +14,10 @@ describe('Client', () => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.addressId = '1234';
controller = $componentController('vnAddressEdit', {$state: $state});
}));
it('should define and set address property', () => {
let controller = $componentController('vnAddressEdit', {$state: $state});
expect(controller.address.id).toBe(1234);
});
});

View File

@ -10,17 +10,20 @@
<vn-vertical pad-large>
<vn-title>Basic data</vn-title>
<vn-horizontal>
<vn-textfield vn-one label="Name" field="$ctrl.client.name" vn-focus></vn-textfield>
<vn-textfield vn-one label="Tax number" field="$ctrl.client.fi"></vn-textfield>
<vn-textfield autofocus vn-one label="Social name" field="$ctrl.client.socialName"></vn-textfield>
<vn-textfield vn-one label="Comercial Name" field="$ctrl.client.name" vn-focus></vn-textfield>
<vn-textfield vn-one label="Contact" field="$ctrl.client.contact"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Phone" field="$ctrl.client.phone"></vn-textfield>
<vn-textfield vn-one label="Mobile" field="$ctrl.client.mobile"></vn-textfield>
<vn-textfield vn-one label="Fax" field="$ctrl.client.fax"></vn-textfield>
<vn-textfield vn-one
label="Email"
field="$ctrl.client.email"
info="You can save multiple emails by chaining them using comma without spaces, example: user@domain.com,user2@domain.com the first email will be considered as the main"
>
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Email" field="$ctrl.client.email" info="You can save multiple emails by chaining them using comma without spaces, example: user@domain.com,user2@domain.com the first email will be considered as the main"></vn-textfield>
<vn-autocomplete vn-one
initial-data="$ctrl.client.salesPerson"
field="$ctrl.client.salesPersonFk"
@ -28,7 +31,9 @@
show-field="name"
value-field="id"
select-fields="surname"
label="Salesperson">
label="Salesperson"
filter-search="{where: {or: [{name: {regexp: 'search'}}, {surname: {regexp: 'search'}}]}}"
>
</vn-autocomplete>
<vn-autocomplete vn-one
initial-data="$ctrl.client.contactChannel"

View File

@ -1,6 +1,6 @@
{
"Basic data": "Datos básicos",
"Name": "Nombre",
"Comercial Name": "Nombre comercial",
"Tax number": "NIF/CIF",
"Social name": "Razón social",
"Phone": "Teléfono",
@ -9,5 +9,6 @@
"Email": "Correo electrónico",
"Salesperson": "Comercial",
"Channel": "Canal",
"You can save multiple emails by chaining them using comma without spaces, example: user@domain.com,user2@domain.com the first email will be considered as the main": "Puede guardar varios correos electrónicos encadenándolos mediante comas sin espacios, ejemplo: user@dominio.com,user2@dominio.com siendo el primer correo electrónico el principal"
"You can save multiple emails by chaining them using comma without spaces, example: user@domain.com,user2@domain.com the first email will be considered as the main": "Puede guardar varios correos electrónicos encadenándolos mediante comas sin espacios, ejemplo: user@dominio.com,user2@dominio.com siendo el primer correo electrónico el principal",
"Contact": "Contacto"
}

View File

@ -8,7 +8,7 @@
<form name="form" ng-submit="$ctrl.submit()" pad-medium>
<vn-card margin-small-bottom>
<vn-vertical pad-large>
<vn-title>Billing information</vn-title>
<vn-title>Pay method</vn-title>
<vn-horizontal>
<vn-autocomplete vn-two
vn-acl="administrative"
@ -16,32 +16,29 @@
url="/client/api/PayMethods"
select-fields="ibanRequired"
initial-data="$ctrl.client.payMethod"
label="Forma de pago">
label="Pay method">
</vn-autocomplete>
<vn-textfield vn-two label="IBAN" field="$ctrl.client.iban" vn-acl="administrative"></vn-textfield>
<vn-textfield vn-one label="Vencimiento" field="$ctrl.client.dueDay" vn-acl="administrative"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Descuento" field="$ctrl.client.discount" vn-acl="administrative"></vn-textfield>
<vn-textfield vn-one label="Crédito" field="$ctrl.client.credit" vn-acl="administrative"></vn-textfield>
<vn-textfield vn-one label="Crédito asegurado" field="$ctrl.client.creditInsurance" vn-acl="administrative"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-check vn-one label="Recargo de equivalencia" field="$ctrl.client.equalizationTax" vn-acl="administrative"></vn-check>
<vn-check vn-one label="Vies" field="$ctrl.client.vies" vn-acl="administrative"></vn-check>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-card margin-small-bottom>
<vn-vertical pad-large>
<vn-title>Documentación</vn-title>
<vn-horizontal>
<vn-check vn-one label="Recibido core VNH" field="$ctrl.client.coreVnh" vn-acl="administrative"></vn-check>
<vn-check vn-one label="Recibido core VNL" field="$ctrl.client.coreVnl" vn-acl="administrative"></vn-check>
<vn-check vn-one label="Recibido B2B VNL" field="$ctrl.client.sepaVnl" vn-acl="administrative"></vn-check>
<vn-horizontal margin-medium-bottom>
<vn-one>
<vn-check label="Recibido core VNH" field="$ctrl.client.coreVnh" vn-acl="administrative"></vn-check>
</vn-one>
<vn-one>
<vn-check label="Recibido core VNL" field="$ctrl.client.coreVnl" vn-acl="administrative"></vn-check>
</vn-one>
<vn-one>
<vn-check label="Recibido B2B VNL" field="$ctrl.client.sepaVnl" vn-acl="administrative"></vn-check>
</vn-one>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Guardar" vn-acl="administrative"></vn-submit>
</vn-button-bar>
@ -60,17 +57,3 @@
<button response="ACCEPT" translate>Yes, notify</button>
</tpl-buttons>
</vn-dialog>
<vn-dialog
vn-id="propagate-equalizationTax"
on-response="$ctrl.returnDialogRE(response)">
<tpl-body>
<vn-vertical>
<vn-one text-center translate>You changes the equivalent tax</vn-one>
<vn-one text-center translate>Do you want to spread the change to their consignees?</vn-one>
</vn-vertical>
</tpl-body>
<tpl-buttons>
<button response="CANCEL" translate>No</button>
<button response="ACCEPT" translate>Yes, propagate</button>
</tpl-buttons>
</vn-dialog>

View File

@ -20,7 +20,6 @@ export default class Controller {
this.billData.discount = this.client.discount;
this.billData.credit = this.client.credit;
this.billData.creditInsurance = this.client.creditInsurance;
this.equalizationTax = this.client.equalizationTax;
}
}
submit() {
@ -38,9 +37,7 @@ export default class Controller {
}
);
if (equals) {
this.checkREChanges();
} else {
if (!equals) {
this.$.sendMail.show();
}
}
@ -49,28 +46,6 @@ export default class Controller {
this.$http.post(`/mailer/manuscript/payment-update/${this.client.id}`).then(
() => {
this.vnApp.showMessage(this.translate.instant('Notification sent!'));
this.checkREChanges();
}
);
} else {
this.checkREChanges();
}
}
checkREChanges() {
let equals = this.equalizationTax == this.client.equalizationTax;
this.equalizationTax = this.client.equalizationTax;
if (!equals)
this.$.propagateEqualizationTax.show();
}
returnDialogRE(response) {
if (response === 'ACCEPT') {
this.$http.patch(`/client/api/Clients/${this.client.id}/addressesPropagateRe`, {isEqualizated: this.client.equalizationTax}).then(
res => {
if (res.data)
this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded'));
}
);
}

View File

@ -5,6 +5,7 @@ describe('Client', () => {
let $componentController;
let $httpBackend;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -18,11 +19,11 @@ describe('Client', () => {
$scope.watcher = {submit};
let show = jasmine.createSpy('show');
$scope.sendMail = {show};
controller = $componentController('vnClientBillingData', {$scope: $scope});
}));
describe('copyData()', () => {
it(`should define billData using client's data`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {
credit: 1000000000000,
creditInsurance: null,
@ -40,7 +41,6 @@ describe('Client', () => {
describe('submit()', () => {
it(`should call submit() on the watcher then receive a callback`, done => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
spyOn(controller, 'checkPaymentChanges');
controller.submit()
.then(() => {
@ -53,7 +53,6 @@ describe('Client', () => {
describe('checkPaymentChanges()', () => {
it(`should not call sendMail.show() if there are no changes on billing data`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Silver Surfer'};
controller.checkPaymentChanges();
@ -62,7 +61,6 @@ describe('Client', () => {
});
it(`should call sendMail.show() if there are changes on billing data object`, () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.billData = {marvelHero: 'Silver Surfer'};
controller.client = {marvelHero: 'Spider-Man'};
controller.checkPaymentChanges();
@ -73,7 +71,6 @@ describe('Client', () => {
describe('returnDialog()', () => {
it('should request to send notification email', () => {
let controller = $componentController('vnClientBillingData', {$scope: $scope});
controller.client = {id: '123'};
$httpBackend.when('POST', `/mailer/manuscript/payment-update/${controller.client.id}`).respond('done');
$httpBackend.expectPOST(`/mailer/manuscript/payment-update/${controller.client.id}`);

View File

@ -8,5 +8,7 @@
"You changes the equivalent tax": "Has cambiado el recargo de equivalencia",
"Do you want to spread the change to their consignees?" : "¿Deseas propagar el cambio a sus consignatarios?",
"Yes, propagate": "Si, propagar",
"Equivalent tax spreaded": "Recargo de equivalencia propagado"
"Equivalent tax spreaded": "Recargo de equivalencia propagado",
"Invoice by address": "Facturar por consignatario",
"Equalization tax": "Recargo de equivalencia"
}

View File

@ -4,6 +4,7 @@ describe('Client', () => {
describe('Component vnClientCard', () => {
let $componentController;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -12,11 +13,10 @@ describe('Client', () => {
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope;
controller = $componentController('vnClientCard', {$scope: $scope});
}));
it('should define and set client property to null in the module instance', () => {
let controller = $componentController('vnClientCard', {$scope: $scope});
expect(controller.client).toBeDefined();
expect(controller.client).toBe(null);
});

View File

@ -1,3 +1,3 @@
vn-descriptor{
vn-descriptor {
font-family: raleway-bold;
}

View File

@ -5,6 +5,7 @@ describe('Client', () => {
let $componentController;
let $scope;
let $state;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -23,11 +24,10 @@ describe('Client', () => {
};
}
};
controller = $componentController('vnClientCreate', {$scope: $scope});
}));
it('should define and set scope, state and client properties', () => {
let controller = $componentController('vnClientCreate', {$scope: $scope});
expect(controller.$).toBe($scope);
expect(controller.$state).toBe($state);
expect(controller.client.active).toBe(true);
@ -35,7 +35,6 @@ describe('Client', () => {
describe('onSubmit()', () => {
it(`should call submit() on the watcher then expect a callback`, () => {
let controller = $componentController('vnClientCreate', {$scope: $scope});
spyOn($state, 'go');
controller.onSubmit();

View File

@ -1,9 +1,9 @@
<vn-card>
<vn-vertical class="margin-medium" pad-medium-top pad-medium-bottom>
<vn-horizontal>
<vn-one>
<a vn-one ui-sref="clients">
<i class="material-icons descriptor-icon">person</i>
</vn-one>
</a>
<vn-vertical vn-two>
<div class="margin-none">{{::$ctrl.client.id}}</div>
<div class="margin-none">{{$ctrl.client.name}}</div>

View File

@ -1,5 +1,4 @@
import ngModule from '../module';
import './style.css';
export default class Controller {
constructor($scope, $http) {

View File

@ -4,6 +4,7 @@ describe('Client', () => {
describe('Component vnDescriptor', () => {
let $componentController;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -12,11 +13,11 @@ describe('Client', () => {
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
controller = $componentController('vnDescriptor', {$scope: $scope});
}));
describe('set active', () => {
it('should check if active is defined and diferent from the new value', () => {
let controller = $componentController('vnDescriptor', {$scope: $scope});
controller.client = {id: 1};
expect(controller._active).toBe(undefined);

View File

@ -1,3 +0,0 @@
.descriptor-icon{
font-size:60px;
}

View File

@ -5,27 +5,29 @@
form="form"
save="patch">
</vn-watcher>
<form name="form" ng-submit="watcher.submit()" pad-medium>
<form name="form" ng-submit="$ctrl.submit()" pad-medium>
<vn-card margin-small-bottom>
<vn-vertical pad-large>
<vn-title>Fiscal data</vn-title>
<vn-horizontal>
<vn-check vn-one label="Facturar" field="$ctrl.client.hasToInvoice"></vn-check>
<vn-check vn-one label="Factura impresa" field="$ctrl.client.invoiceByEmail"></vn-check>
<vn-textfield autofocus vn-two label="Social name" field="$ctrl.client.socialName" vn-acl="administrative"></vn-textfield>
<vn-textfield vn-one label="Tax number" field="$ctrl.client.fi" vn-acl="administrative"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-two label="Domicilio fiscal" field="$ctrl.client.street" vn-focus></vn-textfield>
<vn-textfield vn-one label="Municipio" field="$ctrl.client.city"></vn-textfield>
<vn-textfield vn-two label="Street" field="$ctrl.client.street" vn-focus vn-acl="administrative"></vn-textfield>
<vn-textfield vn-one label="City" field="$ctrl.client.city" vn-acl="administrative"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Código postal" field="$ctrl.client.postcode"></vn-textfield>
<vn-textfield vn-one label="Postcode" field="$ctrl.client.postcode" vn-acl="administrative"></vn-textfield>
<vn-autocomplete vn-one
initial-data="$ctrl.client.province"
field="$ctrl.client.provinceFk"
url="/client/api/Provinces"
show-field="name"
value-field="id"
label="Provincia">
label="Province"
vn-acl="administrative"
>
</vn-autocomplete>
<vn-autocomplete vn-one
initial-data="$ctrl.client.country"
@ -33,13 +35,52 @@
url="/client/api/Countries"
show-field="name"
value-field="id"
label="País">
label="Country"
vn-acl="administrative"
>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal margin-small-bottom>
<vn-one>
<vn-check label="Equalization tax" field="$ctrl.client.equalizationTax" vn-acl="administrative" vn-acl="administrative"></vn-check>
</vn-one>
<vn-one>
<vn-check label="Invoice by address" field="$ctrl.client.hasToInvoiceByAddress" vn-acl="administrative" vn-acl="administrative"></vn-check>
</vn-one>
<vn-one></vn-one>
</vn-horizontal>
<vn-horizontal>
<vn-one>
<vn-check label="Has to invoice" field="$ctrl.client.hasToInvoice" vn-acl="administrative"></vn-check>
</vn-one>
<vn-one>
<vn-check label="Invoice by mail" field="$ctrl.client.invoiceByEmail" vn-acl="administrative"></vn-check>
</vn-one>
<vn-one>
<vn-check label="Vies" field="$ctrl.client.vies" vn-acl="administrative" vn-acl="administrative"></vn-check>
</vn-one>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Guardar"></vn-submit>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>
<vn-dialog
vn-id="propagate-equalizationTax"
on-response="$ctrl.returnDialogEt(response)"
>
<tpl-body>
<vn-vertical>
<vn-one text-center translate>You changes the equivalent tax</vn-one>
<vn-one text-center translate>Do you want to spread the change to their consignees?</vn-one>
</vn-vertical>
</tpl-body>
<tpl-buttons>
<button response="CANCEL" translate>No</button>
<button response="ACCEPT" translate>Yes, propagate</button>
</tpl-buttons>
</vn-dialog>

View File

@ -1,7 +1,54 @@
import ngModule from '../module';
export default class ClientFiscalData {
constructor($scope, $http, vnApp, $translate) {
this.$ = $scope;
this.$http = $http;
this.vnApp = vnApp;
this.translate = $translate;
this.equalizationTax = undefined;
this.copyData();
}
$onChanges() {
this.copyData();
}
copyData() {
if (this.client) {
this.equalizationTax = this.client.equalizationTax;
}
}
submit() {
return this.$.watcher.submit().then(
() => this.checkEtChanges());
}
checkEtChanges() {
let equals = this.equalizationTax == this.client.equalizationTax;
this.equalizationTax = this.client.equalizationTax;
if (!equals)
this.$.propagateEqualizationTax.show();
}
returnDialogEt(response) {
if (response === 'ACCEPT') {
this.$http.patch(`/client/api/Clients/${this.client.id}/addressesPropagateRe`, {isEqualizated: this.client.equalizationTax}).then(
res => {
if (res.data)
this.vnApp.showMessage(this.translate.instant('Equivalent tax spreaded'));
}
);
}
}
}
ClientFiscalData.$inject = ['$scope', '$http', 'vnApp', '$translate'];
ngModule.component('vnClientFiscalData', {
template: require('./fiscal-data.html'),
controller: ClientFiscalData,
bindings: {
client: '<'
}

View File

@ -3,6 +3,7 @@ import './index.js';
describe('Client', () => {
describe('Component vnClientIndex', () => {
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -10,17 +11,15 @@ describe('Client', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnClientIndex');
}));
it('should define and set model property as an empty object', () => {
let controller = $componentController('vnClientIndex');
expect(controller.model).toEqual({});
});
describe('search()', () => {
it(`should set model's search to the search input`, () => {
let controller = $componentController('vnClientIndex');
controller.model.search = 'batman';
let index = {
filter: {},

View File

@ -11,6 +11,6 @@ vn-item-client a:hover {
background-color: #424242;
}
.vn-item-client-name{
.vn-item-client-name {
font-family: raleway-bold;
}

View File

@ -1,5 +1,14 @@
{
"Client": "Cliente",
"Clients": "Clientes",
"Fiscal data": "Datos Fiscales"
"Fiscal data": "Datos Fiscales",
"Has to invoice": "Factura",
"Invoice by mail": "Factura impresa",
"Country": "País",
"Street": "Domicilio fiscal",
"City": "Municipio",
"Postcode": "Código postal",
"Province": "Provincia",
"Save": "Guardar",
"Pay method" : "Forma de pago"
}

View File

@ -4,6 +4,7 @@ describe('Client', () => {
describe('Component vnNoteCreate', () => {
let $componentController;
let $state;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -13,11 +14,10 @@ describe('Client', () => {
$componentController = _$componentController_;
$state = _$state_;
$state.params.id = '1234';
controller = $componentController('vnNoteCreate', {$state: $state});
}));
it('should define clientFk using $state.params.id', () => {
let controller = $componentController('vnNoteCreate', {$state: $state});
expect(controller.note.clientFk).toBe(1234);
expect(controller.note.client).toBe(undefined);
});

View File

@ -6,11 +6,13 @@ export default class Controller {
this.$http = $http;
this.$state = $state;
}
$onChanges() {
if (this.client) {
this.getObservation(this.client.id);
}
}
getObservation(clientId) {
let json = JSON.stringify({where: {clientFk: this.client.id}, order: 'created DESC'});
this.$http.get(`/client/api/clientObservations?filter=${json}`).then(
@ -19,6 +21,7 @@ export default class Controller {
}
);
}
newObservation() {
this.$state.go("clientCard.notes.create", {id: this.client.id});
}

View File

@ -5,6 +5,7 @@ describe('Client', () => {
let $componentController;
let $state;
let $httpBackend;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -14,11 +15,11 @@ describe('Client', () => {
$componentController = _$componentController_;
$state = _$state_;
$httpBackend = _$httpBackend_;
controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
}));
describe('$onChanges()', () => {
it(`should call getObservation() with the client id`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {
id: 1234
};
@ -31,19 +32,20 @@ describe('Client', () => {
describe('$getObservation()', () => {
it(`should request to GET the client notes`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {id: '1234'};
let json = JSON.stringify({where: {clientFk: '1234'}, order: 'created DESC'});
$httpBackend.when('GET', `/client/api/clientObservations?filter=${json}`).respond('ok');
$httpBackend.expectGET(`/client/api/clientObservations?filter=${json}`, {Accept: 'application/json, text/plain, */*'});
let jsonString = JSON.stringify({where: {clientFk: '1234'}, order: 'created DESC'});
let json = {data: 'some data'};
$httpBackend.when('GET', `/client/api/clientObservations?filter=${jsonString}`).respond(json);
$httpBackend.expectGET(`/client/api/clientObservations?filter=${jsonString}`, {Accept: 'application/json, text/plain, */*'});
controller.getObservation();
$httpBackend.flush();
expect(controller.observations).toEqual(json);
});
});
describe('$newObservation()', () => {
it(`should redirect the user to the newObservation view`, () => {
let controller = $componentController('vnClientNotes', {$httpBackend: $httpBackend, $state: $state});
controller.client = {id: '1234'};
spyOn(controller.$state, 'go');
controller.newObservation();

View File

@ -1,3 +1,3 @@
.notes-date{
.notes-date {
font-family: raleway-bold;
}

View File

@ -1,25 +1,28 @@
import ngModule from '../module';
export default class Controller {
constructor($window) {
this.$window = $window;
constructor(sessionStorage) {
this.sessionStorage = sessionStorage;
// onSubmit() is defined by @vnSearchbar
this.onSubmit = () => {};
}
onSearch() {
this.setStorageValue();
this.onSubmit(this.filter);
}
$onChanges() {
var value = JSON.parse(this.$window.sessionStorage.getItem('filter'));
var value = this.sessionStorage.get('filter');
if (value !== undefined)
this.filter = value;
}
setStorageValue() {
this.$window.sessionStorage.setItem('filter', JSON.stringify(this.filter));
this.sessionStorage.set('filter', this.filter);
}
}
Controller.$inject = ['$window'];
Controller.$inject = ['sessionStorage'];
ngModule.component('vnClientSearchPanel', {
template: require('./search-panel.html'),

View File

@ -3,20 +3,21 @@ import './search-panel.js';
describe('Client', () => {
describe('Component vnClientSearchPanel', () => {
let $componentController;
let $window;
let sessionStorage;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, _$window_) => {
beforeEach(angular.mock.inject((_$componentController_, _sessionStorage_) => {
$componentController = _$componentController_;
$window = _$window_;
sessionStorage = _sessionStorage_;
controller = $componentController('vnClientSearchPanel', {sessionStorage: sessionStorage});
}));
describe('onSearch()', () => {
it(`should call setStorageValue() and onSubmit()`, () => {
let controller = $componentController('vnClientSearchPanel', {$window: $window});
it('should call setStorageValue() and onSubmit()', () => {
spyOn(controller, 'setStorageValue');
spyOn(controller, 'onSubmit');
controller.setStorageValue();
@ -28,14 +29,12 @@ describe('Client', () => {
});
describe('$onChanges()', () => {
it(`should set filter properties using the search values`, () => {
let controller = $componentController('vnClientSearchPanel', {$window: $window});
it('should set filter properties using the search values', () => {
expect(controller.filter).not.toBeDefined();
spyOn(JSON, 'parse').and.returnValue({data: 'data'});
spyOn(sessionStorage, 'get').and.returnValue({data: 'data'});
controller.$onChanges();
expect(controller.filter).toBe(JSON.parse({data: 'data'}));
expect(controller.filter).toBe(sessionStorage.get({data: 'data'}));
});
});
});

View File

@ -8,9 +8,15 @@
<form name="form" ng-submit="watcher.submit()" pad-medium>
<vn-card>
<vn-vertical pad-large>
<vn-title>Web access</vn-title>
<vn-check label="Enable web access" field="$ctrl.account.active"></vn-check>
<vn-textfield label="User" class="margin-medium-top" field="$ctrl.account.name" vn-focus></vn-textfield>
<vn-one>
<vn-title>Web access</vn-title>
</vn-one>
<vn-one>
<vn-check label="Enable web access" field="$ctrl.account.active"></vn-check>
</vn-one>
<vn-one>
<vn-textfield label="User" class="margin-medium-top" field="$ctrl.account.name" vn-focus></vn-textfield>
</vn-one>
</vn-vertical>
</vn-card>
<vn-button-bar>

View File

@ -29,6 +29,7 @@ export default class Controller {
this.repeatPassword = '';
this.$.$apply();
}
onPassChange(response) {
if (response == 'ACCEPT' && this.canChangePassword)
try {

View File

@ -5,6 +5,7 @@ describe('Component VnClientWebAccess', () => {
let $httpBackend;
let $scope;
let vnApp;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -16,11 +17,11 @@ describe('Component VnClientWebAccess', () => {
$httpBackend = _$httpBackend_;
vnApp = _vnApp_;
spyOn(vnApp, 'showError');
controller = $componentController('vnClientWebAccess', {$scope: $scope});
}));
describe('$onChanges()', () => {
it(`should pass client's account data to account then call isCustomer function`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
spyOn(controller, 'isCustomer');
controller.client = {client: 'Bruce Wayne', account: 'Wayne Industries'};
controller.account = {};
@ -33,7 +34,6 @@ describe('Component VnClientWebAccess', () => {
describe('isCustomer()', () => {
it(`should perform a query if client is defined with an ID`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'};
controller.isCustomer();
@ -45,7 +45,6 @@ describe('Component VnClientWebAccess', () => {
describe('onPassOpen()', () => {
it('should set passwords to empty values', () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.newPassword = 'm24x8';
controller.repeatPassword = 'm24x8';
controller.onPassOpen();
@ -57,7 +56,6 @@ describe('Component VnClientWebAccess', () => {
describe('onPassChange()', () => {
it('should request to update the password', () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'};
controller.newPassword = 'm24x8';
controller.repeatPassword = 'm24x8';
@ -70,7 +68,6 @@ describe('Component VnClientWebAccess', () => {
describe(`when password is empty`, () => {
it(`should throw Passwords can't be empty error`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'};
controller.newPassword = '';
controller.canChangePassword = true;
@ -82,7 +79,6 @@ describe('Component VnClientWebAccess', () => {
describe(`when passwords don't match`, () => {
it(`should throw Passwords don't match error`, () => {
let controller = $componentController('vnClientWebAccess', {$scope: $scope});
controller.client = {id: '1234'};
controller.newPassword = 'm24x8';
controller.canChangePassword = true;

View File

@ -1,14 +1,16 @@
import {module} from '../module';
import Component from '../lib/component';
import copyObject from '../lib/copy';
import './style.scss';
class Autocomplete extends Component {
constructor($element, $scope, $http, $timeout) {
constructor($element, $scope, $http, $timeout, $filter) {
super($element);
this.$element = $element;
this.$scope = $scope;
this.$http = $http;
this.$timeout = $timeout;
this.$filter = $filter;
this._showDropDown = false;
this.finding = false;
@ -20,7 +22,7 @@ class Autocomplete extends Component {
this.showField = this.showField || 'name';
this.valueField = this.valueField || 'id';
this.order = this.order || 'name ASC';
this.items = this.data || [];
this.items = copyObject(this.data) || [];
this.displayValueMultiCheck = [];
this._multiField = [];
this.readonly = true;
@ -30,6 +32,7 @@ class Autocomplete extends Component {
get showDropDown() {
return this._showDropDown;
}
set showDropDown(value) {
if (value && this.url && !this._preLoad) {
this._preLoad = true;
@ -75,6 +78,7 @@ class Autocomplete extends Component {
get field() {
return this.multiple ? this._multiField : this._field;
}
set field(value) {
if (!angular.equals(value, this.field)) {
this.finding = true;
@ -101,7 +105,7 @@ class Autocomplete extends Component {
if (value && value.hasOwnProperty(this.valueField)) {
this._field = value[this.valueField];
if (this.multiple) {
this._multiField = [value[this.valueField]]
this._multiField = [value[this.valueField]];
}
if (value.hasOwnProperty(this.showField)) {
this.displayValue = value[this.showField];
@ -162,6 +166,7 @@ class Autocomplete extends Component {
json => this.onItemRequest(null)
);
}
onItemRequest(data) {
if (data && data.length > 0)
this.showItem(data[0]);
@ -187,12 +192,19 @@ class Autocomplete extends Component {
}
findItems(search) {
if (!this.url)
return this.items ? this.items : [];
if (search && !this.finding) {
if (this.url && search && !this.finding) {
this.maxRow = false;
let filter = {where: {name: {regexp: search}}};
let filter = {};
if (this.filterSearch) {
let toSearch = this.filterSearch.replace(/search/g, search);
filter = this.$scope.$eval(toSearch);
} else {
filter = {where: {name: {regexp: search}}};
if (this.filter && this.filter.where) {
Object.assign(filter.where, this.filter.where);
}
}
filter.order = this.order;
let json = JSON.stringify(filter);
this.finding = true;
this.$http.get(`${this.url}?filter=${json}`).then(
@ -212,54 +224,67 @@ class Autocomplete extends Component {
this.finding = false;
}
);
} else if (search && !this.url && this.data) {
this.items = this.$filter('filter')(this.data, search);
} else if (!search && !this.finding) {
this.maxRow = 10;
this.items = [];
this.getItems();
}
}
getItems() {
let filter = {};
if (!this.finding) {
this.finding = true;
if (this.url === undefined) {
this.items = copyObject(this.data);
this.maxRow = false;
this.removeLoadMore = true;
} else {
let filter = {};
if (!this.finding) {
this.finding = true;
if (this.maxRow) {
if (this.items) {
filter.skip = this.items.length;
}
filter.limit = this.maxRow;
filter.order = this.order;
}
let json = JSON.stringify(filter);
this.removeLoadMore = false;
this.$http.get(`${this.url}?filter=${json}`).then(
json => {
if (json.data.length) {
json.data.forEach(
el => {
if (this.multiple) {
el.checked = this.field.indexOf(el[this.valueField]) !== -1;
}
this.items.push(el);
}
);
if (filter.skip === 0 && this.maxRow && json.data.length < this.maxRow) {
this.removeLoadMore = true;
}
} else {
this.maxRow = false;
if (this.maxRow) {
if (this.items) {
filter.skip = this.items.length;
}
this.finding = false;
},
() => {
this.finding = false;
filter.limit = this.maxRow;
filter.order = this.order;
}
);
if (this.filter) {
Object.assign(filter, this.filter);
}
let json = JSON.stringify(filter);
this.removeLoadMore = false;
this.$http.get(`${this.url}?filter=${json}`).then(
json => {
if (json.data.length) {
json.data.forEach(
el => {
if (this.multiple) {
el.checked = this.field.indexOf(el[this.valueField]) !== -1;
}
this.items.push(el);
}
);
if (filter.skip === 0 && this.maxRow && json.data.length < this.maxRow) {
this.removeLoadMore = true;
}
} else {
this.maxRow = false;
}
this.finding = false;
},
() => {
this.finding = false;
}
);
}
}
}
$onInit() {
this.findMore = this.url && this.maxRow;
this.mouseFocus = false;
@ -299,9 +324,16 @@ class Autocomplete extends Component {
this.$element.unbind('focusout');
}
}
$onChanges(objectChange) {
if (objectChange.data && objectChange.data.currentValue && objectChange.data.currentValue.length) {
this.items = copyObject(objectChange.data.currentValue);
this.maxRow = false;
this.removeLoadMore = true;
}
}
Autocomplete.$inject = ['$element', '$scope', '$http', '$timeout'];
}
Autocomplete.$inject = ['$element', '$scope', '$http', '$timeout', '$filter'];
module.component('vnAutocomplete', {
template: require('./autocomplete.html'),
@ -317,7 +349,9 @@ module.component('vnAutocomplete', {
field: '=',
label: '@',
multiple: '@?',
order: '@?'
order: '@?',
filter: '<?',
filterSearch: '@?'
},
transclude: {
tplItem: '?tplItem'

View File

@ -6,6 +6,7 @@ describe('Component vnAutocomplete', () => {
let $httpBackend;
let $timeout;
let $element;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -17,11 +18,11 @@ describe('Component vnAutocomplete', () => {
$httpBackend = _$httpBackend_;
$timeout = _$timeout_;
$element = angular.element('<div></div>');
controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
}));
describe('showDropDown() setter', () => {
it(`should set _showDropDown value`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller._showDropDown = '';
controller.showDropDown = 'some value';
@ -29,7 +30,6 @@ describe('Component vnAutocomplete', () => {
});
it(`should set _showDropDown value`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller._showDropDown = '';
controller.showDropDown = 'some value';
@ -39,7 +39,6 @@ describe('Component vnAutocomplete', () => {
describe('displayValue() setter', () => {
it(`should display value in a formated way`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
let value = 'some value';
controller.displayValue = value;
@ -48,7 +47,6 @@ describe('Component vnAutocomplete', () => {
describe('when the autocomeplete is multiple', () => {
it(`should display values separated with commas`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.multiple = true;
controller.displayValue = 'some value';
controller.displayValue = 'another value';
@ -61,14 +59,12 @@ describe('Component vnAutocomplete', () => {
describe('field() setter', () => {
describe('when value is an object', () => {
it(`should set _field controllers property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.field = {id: 1, name: 'Bruce Wayne'};
expect(controller._field).toEqual(1);
});
it(`should set _multifield controllers property `, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.multiple = true;
controller.field = {id: 1, name: 'Bruce Wayne'};
@ -82,7 +78,6 @@ describe('Component vnAutocomplete', () => {
});
it(`should set _multifield value and remove it if called a second type with same value`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.multiple = true;
controller.field = {id: 1, name: 'Bruce Wayne'};
@ -96,7 +91,6 @@ describe('Component vnAutocomplete', () => {
});
it(`should set displayValue finding an existing item in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = {id: 2, name: 'Bruce Wayne'};
@ -106,7 +100,6 @@ describe('Component vnAutocomplete', () => {
describe('when value is a number', () => {
it(`should set _field controller property finding an existing item in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = 2;
@ -114,7 +107,6 @@ describe('Component vnAutocomplete', () => {
});
it(`should set _multifield value and remove it if called a second type with same value finding an existing item in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}];
controller.multiple = true;
controller.field = 2;
@ -127,16 +119,15 @@ describe('Component vnAutocomplete', () => {
});
it(`should perform a query if the item id isn't present in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
$httpBackend.whenGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}').respond();
$httpBackend.expectGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}');
controller.url = 'test.com';
$httpBackend.whenGET(`${controller.url}?filter={"fields":{"id":true,"name":true},"where":{"id":3}}`).respond();
$httpBackend.expectGET(`${controller.url}?filter={"fields":{"id":true,"name":true},"where":{"id":3}}`);
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = 3;
$httpBackend.flush();
});
it(`should set displayValue finding an existing item in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = 2;
@ -144,9 +135,9 @@ describe('Component vnAutocomplete', () => {
});
it(`should set field performing a query as the item id isn't present in the controller.items property`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
$httpBackend.whenGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}').respond();
$httpBackend.expectGET('test.com?filter={"fields":{"id":true,"name":true},"where":{"id":3}}');
controller.url = 'test.com';
$httpBackend.whenGET(`${controller.url}?filter={"fields":{"id":true,"name":true},"where":{"id":3}}`).respond();
$httpBackend.expectGET(`${controller.url}?filter={"fields":{"id":true,"name":true},"where":{"id":3}}`);
controller.items = [{id: 1, name: 'test1'}, {id: 2, name: 'Bruce Wayne'}];
controller.field = 3;
$httpBackend.flush();
@ -154,28 +145,28 @@ describe('Component vnAutocomplete', () => {
});
});
describe('findItem()', () => {
it(`should return items empty array if the controller does not provide a url and have no items defined`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout});
controller.findItems('some search value');
expect(controller.items).not.toBeDefined();
});
it(`should return items array if the controller does not provide a url`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout});
controller.items = ['Batman', 'Bruce Wayne'];
controller.findItems('some search value');
expect(controller.items.length).toEqual(2);
});
describe('findItems()', () => {
it(`should perform a search and store the result in controller items`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.url = 'test.com';
let search = 'The Joker';
let json = JSON.stringify({where: {name: {regexp: search}}});
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
$httpBackend.expectGET(`test.com?filter=${json}`);
let json = JSON.stringify({where: {name: {regexp: search}}, order: controller.order});
$httpBackend.whenGET(`${controller.url}?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
$httpBackend.expectGET(`${controller.url}?filter=${json}`);
controller.findItems(search);
$httpBackend.flush();
expect(controller.items[0]).toEqual({id: 3, name: 'The Joker'});
});
it(`should perform a search and store the result in controller items with filterSearch`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout});
controller.url = 'test.com';
let search = 'The Joker';
controller.filterSearch = "{where: {surname: {regexp: 'search'}}}";
let json = JSON.stringify({where: {surname: {regexp: search}}, order: controller.order});
$httpBackend.whenGET(`${controller.url}?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
$httpBackend.expectGET(`${controller.url}?filter=${json}`);
controller.findItems(search);
$httpBackend.flush();
@ -183,12 +174,12 @@ describe('Component vnAutocomplete', () => {
});
it(`should perform a search with multiple true and store the result in controller items with the checked property defined`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
controller.url = 'test.com';
let search = 'Joker';
controller.multiple = true;
let json = JSON.stringify({where: {name: {regexp: search}}});
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}, {id: 4, name: 'Joker'}]);
$httpBackend.expectGET(`test.com?filter=${json}`);
let json = JSON.stringify({where: {name: {regexp: search}}, order: controller.order});
$httpBackend.whenGET(`${controller.url}?filter=${json}`).respond([{id: 3, name: 'The Joker'}, {id: 4, name: 'Joker'}]);
$httpBackend.expectGET(`${controller.url}?filter=${json}`);
controller.findItems(search);
$httpBackend.flush();
@ -196,7 +187,7 @@ describe('Component vnAutocomplete', () => {
});
it(`should call getItems function if there's no search value`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
controller.url = 'test.com';
spyOn(controller, 'getItems');
controller.findItems();
@ -206,9 +197,9 @@ describe('Component vnAutocomplete', () => {
describe('getItems()', () => {
it(`should perfom a query to fill the items without filter`, () => {
let controller = $componentController('vnAutocomplete', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
$httpBackend.whenGET(`test.com?filter={"skip":0,"limit":10,"order":"name ASC"}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
$httpBackend.expectGET(`test.com?filter={"skip":0,"limit":10,"order":"name ASC"}`);
controller.url = 'test.com';
$httpBackend.whenGET(`${controller.url}?filter={"skip":0,"limit":10,"order":"name ASC"}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
$httpBackend.expectGET(`${controller.url}?filter={"skip":0,"limit":10,"order":"name ASC"}`);
controller.getItems();
$httpBackend.flush();

View File

@ -2,6 +2,7 @@ import {module as _module} from '../module';
import * as resolveFactory from '../lib/resolveDefaultComponents';
import * as normalizerFactory from '../lib/inputAttrsNormalizer';
import * as util from '../lib/util';
import './style.css';
const _NAME = 'check';
export const NAME = util.getName(_NAME);

View File

@ -0,0 +1,3 @@
vn-check {
float: left;
}

View File

@ -21,6 +21,12 @@ export default class ColumnHeader {
}
return showArrow;
}
$onInit() {
if (this.defaultOrder) {
this.order = this.defaultOrder;
this.onClick();
}
}
}
ColumnHeader.$inject = [];
@ -29,7 +35,8 @@ module.component('vnColumnHeader', {
bindings: {
field: '@?',
text: '@?',
className: '@?'
className: '@?',
defaultOrder: '@?'
},
require: {
gridHeader: '^^vnGridHeader'

View File

@ -2,6 +2,7 @@ import './column-header.js';
describe('Component vnColumnHeader', () => {
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -9,11 +10,12 @@ describe('Component vnColumnHeader', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnColumnHeader', {});
}));
describe('onClick()', () => {
it(`should change the ordenation to DESC (descendant) if it was ASC (ascendant)`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}});
controller.gridHeader = {selectColum: () => {}};
controller.order = 'ASC';
controller.onClick();
@ -21,7 +23,7 @@ describe('Component vnColumnHeader', () => {
});
it(`should change the ordenation to ASC (ascendant) if it wasnt ASC`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}});
controller.gridHeader = {selectColum: () => {}};
controller.order = 'DESC or any other value that might occur';
controller.onClick();
@ -29,7 +31,7 @@ describe('Component vnColumnHeader', () => {
});
it(`should call the selectColum() function after changing a value`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}});
controller.gridHeader = {selectColum: () => {}};
controller.order = 'Change me!';
spyOn(controller.gridHeader, 'selectColum');
controller.onClick();
@ -40,7 +42,7 @@ describe('Component vnColumnHeader', () => {
describe('showArrow()', () => {
it(`should return true when the type is DESC and MouseIsOver`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {selectColum: () => {}}});
controller.gridHeader = {selectColum: () => {}};
controller.mouseIsOver = true;
let result = controller.showArrow('DESC');
@ -48,7 +50,7 @@ describe('Component vnColumnHeader', () => {
});
it(`should return true if many conditions are true`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {currentColumn: {field: 'fields should be identical'}}});
controller.gridHeader = {currentColumn: {field: 'fields should be identical'}};
controller.field = 'fields should be identical';
controller.order = 'ASC';
let result = controller.showArrow('ASC');
@ -57,7 +59,7 @@ describe('Component vnColumnHeader', () => {
});
it(`should return false without type being DESC or any other values being true`, () => {
let controller = $componentController('vnColumnHeader', {}, {gridHeader: {currentColumn: {field: 'this field isnt the same as controllers field'}}});
controller.gridHeader = {currentColumn: {field: 'fields should be identical'}};
controller.field = 'I am the controllers field';
controller.order = 'ASC';
let result = controller.showArrow('ASC');
@ -65,4 +67,22 @@ describe('Component vnColumnHeader', () => {
expect(result).toEqual(false);
});
});
describe('onInit()', () => {
it(`should never call onClick()`, () => {
spyOn(controller, 'onClick');
controller.$onInit();
expect(controller.onClick).not.toHaveBeenCalledWith();
});
it(`should define controllers order as per defaultOrder then call onClick()`, () => {
controller.defaultOrder = 'ASC';
spyOn(controller, 'onClick');
controller.$onInit();
expect(controller.order).toEqual('ASC');
expect(controller.onClick).toHaveBeenCalledWith();
});
});
});

View File

@ -1,19 +1,21 @@
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<div
class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"
tabindex="1"
ng-focus="$ctrl.hasFocus = true"
ng-blur="$ctrl.hasFocus = false"
ng-mouseenter="$ctrl.hasMouseIn = true"
ng-mouseleave="$ctrl.hasMouseIn = false"
>
<input type="text"
class="mdl-textfield__input"
name="{{::$ctrl.name}}"
ng-model="$ctrl.modelView"
ng-disabled="{{!$ctrl.enabled}}"
rule="{{::$ctrl.rule}}"/>
<button
type="button"
class="mdl-chip__action ng-hide"
tabindex="-1"
translate-attr="{title: 'Clear'}"
ng-show="$ctrl.modelView"
ng-click="$ctrl.onClear()"
>
<i class="material-icons">clear</i>
</button>
<label class="mdl-textfield__label">{{::$ctrl.label | translate}}</label>
rule="{{::$ctrl.rule}}"/>
<div class="mdl-chip__action">
<i class="material-icons" ng-if="$ctrl.isTimePicker" ng-click="$ctrl.vp.open()">query_builder</i>
<i class="material-icons pointer" ng-show="$ctrl.modelView&&($ctrl.hasFocus||$ctrl.hasMouseIn)" ng-click="$ctrl.onClear()">clear</i>
</div>
<label class="mdl-textfield__label" translate>{{$ctrl.label}}</label>
</div>

View File

@ -27,7 +27,9 @@ class DatePicker extends Component {
this.enabled = true;
this._modelView = null;
this._model = undefined;
this._optionsChecked = false;
this.hasFocus = false;
this.hasMouseIn = false;
componentHandler.upgradeElement($element[0].firstChild);
}
@ -37,7 +39,8 @@ class DatePicker extends Component {
set model(value) {
this._model = value;
if (value && !this.modelView) {
let initialDateFormat = (this.iniOptions && this.iniOptions.dateFormat) ? this.iniOptions.dateFormat : 'Y-m-d';
let options = this._getOptions();
let initialDateFormat = (options && options.dateFormat) ? options.dateFormat : 'Y-m-d';
let format = this._formatFlat2Angular(initialDateFormat);
this.modelView = this.$filter('date')(value, format);
}
@ -135,9 +138,12 @@ class DatePicker extends Component {
}
}
$onInit() {
if (!this.iniOptions)
_getOptions() {
if (this.iniOptions && this._optionsChecked) {
return this.iniOptions;
} else if (!this.iniOptions) {
this.iniOptions = {};
}
if (!this.iniOptions.locale)
this.iniOptions.locale = this.$translate.use();
@ -157,9 +163,14 @@ class DatePicker extends Component {
}
);
}
this._optionsChecked = true;
return this.iniOptions;
}
if (this.input)
this.vp = new Flatpickr(this.input, this.iniOptions);
$onInit() {
this.iniOptions = this._getOptions();
this.isTimePicker = (this.iniOptions && this.iniOptions.enableTime && this.iniOptions.noCalendar);
this.vp = new Flatpickr(this.input, this.iniOptions);
}
$onDestroy() {
if (this.vp)

View File

@ -6,36 +6,35 @@ describe('Component vnDatePicker', () => {
let $timeout;
let $element;
let $translate;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$timeout_) => {
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$timeout_, _$translate_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$timeout = _$timeout_;
$element = angular.element(`<div><input></div>`);
$translate = {};
$translate = _$translate_;
controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout});
}));
describe('_formatFlat2Angular()', () => {
it(`should format date from Y-m-d to yyyy-MM-dd`, () => {
let controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout});
let formatedDate = controller._formatFlat2Angular(`Y-m-d`);
expect(formatedDate).toBe('yyyy-MM-dd');
});
it(`should format date from d-m-Y to dd-MM-yyyy`, () => {
let controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout});
let formatedDate = controller._formatFlat2Angular(`d-m-Y`);
expect(formatedDate).toBe('dd-MM-yyyy');
});
it(`should split the given string into parts`, () => {
let controller = $componentController('vnDatePicker', {$scope, $element, $translate, $timeout});
controller.iniOptions = {dateFormat: 'd/m/Y'};
controller.model = '2017-12-23';

View File

@ -1,6 +1,10 @@
vn-date-picker {
div {
outline: none; //remove chrome outline
}
.mdl-chip__action {
position: absolute;
width: auto;
top: 0px;
right: -6px;
margin: 22px 0px;
@ -8,5 +12,7 @@ vn-date-picker {
}
.material-icons {
font-size: 18px;
float: right;
margin-right: 5px;
}
}

View File

@ -1,8 +1,7 @@
import './dialog.js';
describe('Component vnDialog', () => {
let $componentController;
let $element;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -11,13 +10,15 @@ describe('Component vnDialog', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
$element = angular.element('<div></div>');
controller = $componentController('vnDialog', {$element});
}));
describe('show()', () => {
it(`should define keypressHandler function, call addEventListener function and define element.style.display to block then call onOpen function`, () => {
window.innerHeight = 600;
window.innerWidth = 800;
let controller = $componentController('vnDialog', {$element}, {onOpen: () => {}, dialog: {style: {}, offsetWidth: 780, offsetHeight: 581}});
controller.onOpen = () => {};
controller.dialog = {style: {}, offsetWidth: 780, offsetHeight: 581};
spyOn(controller.document, 'addEventListener');
spyOn(controller, 'onOpen');
controller.show();
@ -31,7 +32,7 @@ describe('Component vnDialog', () => {
it(`should define keypressHandler function, call addEventListener function and define element.style.display to block and never call onOpen function`, () => {
window.innerHeight = 600;
window.innerWidth = 800;
let controller = $componentController('vnDialog', {$element}, {dialog: {style: {}, offsetWidth: 781, offsetHeight: 581}});
controller.dialog = {style: {}, offsetWidth: 781, offsetHeight: 581};
spyOn(controller.document, 'addEventListener');
controller.show();
@ -44,7 +45,6 @@ describe('Component vnDialog', () => {
describe('hide()', () => {
it(`should call fireResponse() and realHide()`, () => {
let controller = $componentController('vnDialog', {$element});
spyOn(controller, 'fireResponse');
spyOn(controller, 'realHide');
controller.hide();
@ -56,7 +56,6 @@ describe('Component vnDialog', () => {
describe('fireResponse()', () => {
it(`should return cancel as false`, () => {
let controller = $componentController('vnDialog', {$element});
let result = controller.fireResponse('I am the answer!');
expect(controller.onResponse).not.toBeDefined();
@ -65,9 +64,9 @@ describe('Component vnDialog', () => {
it(`should return onResponse()`, () => {
let text = 'I am the answer!';
let controller = $componentController('vnDialog', {$element}, {onResponse: () => {
controller.onResponse = () => {
return {response: text};
}});
};
let result = controller.fireResponse(text);
expect(result.response).toEqual(text);
@ -76,7 +75,6 @@ describe('Component vnDialog', () => {
describe('realHide()', () => {
it(`should set element.style.display and lastEvent properties and call removeEvenListener()`, () => {
let controller = $componentController('vnDialog', {$element});
spyOn(controller.document, 'removeEventListener');
expect(controller.element.style.display).not.toEqual('none');
@ -91,7 +89,6 @@ describe('Component vnDialog', () => {
describe('onButtonClick()', () => {
it(`should call realHide if cancel isn't false`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
controller.element.className = 'tpl-buttons';
let childElement = document.createElement('div');
@ -106,7 +103,6 @@ describe('Component vnDialog', () => {
});
it(`should call fireResponse with the value of response`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
controller.element.className = 'tpl-buttons';
let childElement = document.createElement('div');
@ -125,7 +121,6 @@ describe('Component vnDialog', () => {
describe('onDialogMouseDown()', () => {
it(`should set controller's lastEvent property`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
controller.onDialogMouseDown(event);
@ -136,7 +131,6 @@ describe('Component vnDialog', () => {
describe('onBackgroundMouseDown()', () => {
it(`shouldn't call hide() function as event equals lastEvent`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
controller.lastEvent = event;
@ -147,7 +141,6 @@ describe('Component vnDialog', () => {
});
it(`should call hide() function as event doesn't equal lastEvent`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
controller.lastEvent = event;
@ -161,7 +154,6 @@ describe('Component vnDialog', () => {
describe('onKeypress()', () => {
it(`should call hide() if the key pressed equal the code 27`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
event.keyCode = 27;
@ -172,7 +164,6 @@ describe('Component vnDialog', () => {
});
it(`should't call hide() as the key pressed equal the code 999`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
event.keyCode = 999;

View File

@ -19,8 +19,8 @@ function vnAcl(aclService, $timeout) {
$timeout(() => {
input.setAttribute("disabled", "true");
});
$element[0].querySelectorAll('i, vn-drop-down').forEach(i => {
i.parentNode.removeChild(i);
$element[0].querySelectorAll('i, vn-drop-down').forEach(element => {
element.parentNode.removeChild(element);
});
}
} else {

View File

@ -11,7 +11,8 @@ export function directive() {
restrict: 'A',
link: function($scope, $element, $attrs) {
$element.on('click', function(event) {
let dialog = $scope[kebabToCamel($attrs.vnDialog)];
let dialogKey = kebabToCamel($attrs.vnDialog);
let dialog = $scope[dialogKey];
if (dialog instanceof Dialog)
dialog.show();
event.preventDefault();

View File

@ -2,6 +2,8 @@ import {module} from '../module';
/**
* Sets the focus and selects the text on the input.
*
* @return {Object} The directive
*/
export function directive() {
return {

View File

@ -1,16 +0,0 @@
import {module} from '../module';
directive.$inject = ['$compile'];
function directive($compile) {
return {
restrict: 'A',
priority: 9999,
link: function(scope, element, attrs) {
element.removeAttr('vn-repeat');
element.attr('ng-repeat', attrs.vnRepeat);
$compile(element)(scope);
}
};
}
module.directive('vnRepeat', directive);

View File

@ -0,0 +1,54 @@
describe('Directive acl', () => {
let scope;
let element;
let compile;
let $timeout;
beforeEach(() => {
angular.mock.module('client');
});
compile = (hasPermissions, _element) => {
inject(($compile, $rootScope, aclService, _$timeout_) => {
spyOn(aclService, 'aclPermission').and.returnValue(hasPermissions);
scope = $rootScope.$new();
$timeout = _$timeout_;
element = angular.element(_element);
$compile(element)(scope);
scope.$digest();
});
};
it('should not disable the input element as the user has permision', () => {
let html = `<div vn-acl="administrative,client" vn-acl-action="disabled"><input/></div>`;
compile(true, html);
let input = element.find('input');
expect(input).toBeDefined();
expect(input.attr('disabled')).toBeFalsy();
});
it('should delete the element as the user does not have permission and there is no action', () => {
let html = `<container><div vn-acl="administrative,client" vn-acl-action="anything but disabled"><input/></div></container>`;
compile(false, html);
expect(element.children().length).toEqual(0);
});
it('should disable the element as the action is to disable it but the user has no permission but present', () => {
let html = `<div vn-acl="administrative,client" vn-acl-action="disabled"><input/></div>`;
compile(false, html);
let input = element.find('input');
$timeout.flush();
expect(input).toBeDefined();
expect(input.attr('disabled')).toBeTruthy();
});
it('should delete any element with the tag i and vn-drop-down', () => {
let html = `<div vn-acl="administrative,client" vn-acl-action="disabled"><label><i/></label><input/></div>`;
compile(false, html);
expect(element.find('i').length).toBe(0);
});
});

View File

@ -0,0 +1,37 @@
describe('Directive dialog', () => {
let $scope;
let $element;
let element;
let compile;
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
compile = _element => {
inject(($compile, $rootScope) => {
$scope = $rootScope.$new();
$scope.myDialog = controller;
element = angular.element(_element);
$compile(element)($scope);
$scope.$digest();
});
};
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
$element = angular.element('<div></div>');
controller = $componentController('vnDialog', {$element});
}));
it('should call show() function if dialog is a instance of vnDialog', () => {
let html = `<div vn-dialog="myDialog"></div>`;
spyOn(controller, 'show');
compile(html);
element[0].click();
expect(controller.show).toHaveBeenCalledWith();
});
});

View File

@ -0,0 +1,55 @@
describe('Directive focus', () => {
let $scope;
let $element;
let compile;
beforeEach(() => {
angular.mock.module('client');
});
compile = (_element, _childElement) => {
inject(($compile, $rootScope) => {
$scope = $rootScope.$new();
$element = angular.element(_element);
if (_childElement) {
let childElement = angular.element(_childElement);
$element[0] < childElement;
$element[0].firstChild.focus = jasmine.createSpy(focus);
}
$element[0].focus = jasmine.createSpy('focus');
$element[0].select = jasmine.createSpy('select');
$compile($element)($scope);
$scope.$digest();
});
};
it('should call the querySelector function upon the input to redefine it with the expected selector then call focus', () => {
let html = `<div vn-focus><input></input></div>`;
let childHtml = '<input></input>';
compile(html, childHtml);
expect($element[0].firstChild.focus).toHaveBeenCalled();
});
it('should print a warning message on console', () => {
let html = `<potato vn-focus></potato>`;
console.warn = jasmine.createSpy('warn');
compile(html);
expect(console.warn).toHaveBeenCalledWith(`vnFocus: Can't find a focusable element`);
});
it('should call focus function on the element', () => {
let html = `<input vn-focus></input>`;
compile(html);
expect($element[0].focus).toHaveBeenCalledWith();
});
it('should call select function on the element', () => {
let html = `<input vn-focus></input>`;
compile(html);
expect($element[0].select).toHaveBeenCalledWith();
});
});

View File

@ -0,0 +1,43 @@
describe('Directive vnId', () => {
let $scope;
let $element;
let compile;
beforeEach(() => {
angular.mock.module('client');
});
compile = _element => {
inject(($compile, $rootScope) => {
$scope = $rootScope.$new();
$element = angular.element(_element);
$compile($element)($scope);
$scope.$digest();
});
};
it(`should throw an error when there's no id defined`, () => {
let html = `<form vn-id=""></form>`;
expect(() => {
compile(html);
}).toThrow(new Error(`vnId: Attribute can't be null`));
});
it(`should throw an error when these's no controller defined in $element[0]`, () => {
let html = `<div vn-id="1"></div>`;
expect(() => {
compile(html);
}).toThrow(new Error(`vnId: Can't find controller for element '1'`));
});
it(`should set the controller into the $scope as there are no errors being thrown`, () => {
let html = `<form vn-id="1"></form>`;
expect($scope['1']).not.toBeDefined();
compile(html);
expect($scope['1']).toBeDefined();
});
});

View File

@ -5,6 +5,7 @@ describe('Component vnDropDown', () => {
let $timeout;
let $element;
let $filter;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -15,11 +16,11 @@ describe('Component vnDropDown', () => {
$element = angular.element('<div><ul><li></li></ul></div>');
$timeout = _$timeout_;
$filter = _$filter_;
controller = $componentController('vnDropDown', {$element, $timeout, $filter});
}));
describe('show() setter', () => {
it(`should define controllers _show using the value received as argument`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller._show = 'old value';
controller.show = 'new value';
@ -29,21 +30,18 @@ describe('Component vnDropDown', () => {
describe('search()', () => {
it(`should set controllers _search property with the value received`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.search = 'some filter valiue';
expect(controller._search).toEqual('some filter valiue');
});
it(`should set controllers _search property to null as the value received is an empty string`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.search = '';
expect(controller._search).toEqual(null);
});
it(`should call onFilterRest() if controllers filterAction is defined`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.filterAction = true;
spyOn(controller, 'onFilterRest');
controller.search = 'some filter valiue';
@ -52,7 +50,6 @@ describe('Component vnDropDown', () => {
});
it(`should call filterItems() if controllers filterAction is undefined`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.filterAction = undefined;
spyOn(controller, 'filterItems');
controller.search = 'some filter valiue';
@ -63,7 +60,6 @@ describe('Component vnDropDown', () => {
describe('activeOption() setter', () => {
it(`should set _activeOption as items.length if showLoadMore is defined if activeOption is bigger than items.length then call loadItems()`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'loadItems');
controller.showLoadMore = true;
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
@ -75,7 +71,6 @@ describe('Component vnDropDown', () => {
});
it(`should set _activeOption as activeOption if showLoadMore is defined if activeOption is smaller than items.length then call loadItems()`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'loadItems');
controller.showLoadMore = true;
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
@ -87,7 +82,6 @@ describe('Component vnDropDown', () => {
});
it(`should set _activeOption as items.length -1 if showLoadMore is not defined then call loadItems()`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'loadItems');
controller.showLoadMore = undefined;
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
@ -99,7 +93,6 @@ describe('Component vnDropDown', () => {
});
it(`should define _activeOption as activeOption and never call loadItems()`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'loadItems');
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}, {id: 5, name: 'Doctor X'}];
controller.activeOption = 1;
@ -112,7 +105,6 @@ describe('Component vnDropDown', () => {
describe('filterItems() setter', () => {
it(`should set _itemsFiltered using the value of items`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}];
controller.filterItems();
@ -120,7 +112,6 @@ describe('Component vnDropDown', () => {
});
it(`should set _itemsFiltered with the filtered value of items`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller.search = 'Batman';
controller.filterItems();
@ -129,7 +120,6 @@ describe('Component vnDropDown', () => {
});
it(`should set _itemsFiltered an empty array`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller.search = 'the Joker';
@ -139,7 +129,7 @@ describe('Component vnDropDown', () => {
describe('onFilterRest()', () => {
it(`should call the filterAction() with a constructed object as argument`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter}, {filterAction: () => {}});
controller.filterAction = () => {};
controller.search = 'Batman';
spyOn(controller, 'filterAction');
controller.onFilterRest();
@ -150,7 +140,6 @@ describe('Component vnDropDown', () => {
describe('$onChanges()', () => {
it(`should set the top css of the $element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let argumentObject = {show: true, top: {currentValue: 100}};
spyOn(controller.$element, 'css');
controller.$onChanges(argumentObject);
@ -159,7 +148,6 @@ describe('Component vnDropDown', () => {
});
it(`should set the width css of the $element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let argumentObject = {show: true, itemWidth: {currentValue: 100}};
spyOn(controller.$element, 'css');
controller.$onChanges(argumentObject);
@ -168,7 +156,6 @@ describe('Component vnDropDown', () => {
});
it(`should set the width css of the $element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let argumentObject = {items: {id: 1, name: 'Batman'}};
spyOn(controller, 'filterItems');
controller.$onChanges(argumentObject);
@ -179,7 +166,6 @@ describe('Component vnDropDown', () => {
describe('clearSearch()', () => {
it(`should set the controllers search property to null`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.search = true;
controller.clearSearch();
@ -189,7 +175,6 @@ describe('Component vnDropDown', () => {
describe('selectOption()', () => {
it(`should set controllers selected and show properties then call clearSearch() as _activeOption is smaller than items.length`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'clearSearch');
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller._activeOption = 0;
@ -201,7 +186,6 @@ describe('Component vnDropDown', () => {
});
it(`should not set controllers selected, show and never call clearSearch() as _activeOption is bigger than items.length`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'clearSearch');
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller._activeOption = 100;
@ -213,7 +197,7 @@ describe('Component vnDropDown', () => {
});
it(`should call loadMore() if the activeValue equals items.length`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter}, {loadMore: () => {}});
controller.loadMore = () => {};
spyOn(controller, 'loadMore');
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
controller._activeOption = 4;
@ -226,7 +210,6 @@ describe('Component vnDropDown', () => {
describe('onKeydown()', () => {
it(`should call selectOption() and preventDefault() if Enter key is pressed`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'selectOption');
controller._show = true;
controller.element = document.createElement('div');
@ -241,7 +224,6 @@ describe('Component vnDropDown', () => {
});
it(`should call clearSearch() Esc key is pressed`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller, 'clearSearch');
controller._show = true;
controller.element = document.createElement('div');
@ -253,7 +235,6 @@ describe('Component vnDropDown', () => {
});
it(`should call clearSearch() Esc key is pressed and take off 1 from _activeOption`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
spyOn(controller, 'setScrollPosition');
controller._show = true;
@ -269,7 +250,6 @@ describe('Component vnDropDown', () => {
});
it(`should call clearSearch() Esc key is pressed and add up 1 to _activeOption`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.items = [{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce'}, {id: 3, name: 'Logan'}, {id: 4, name: 'Wolverine'}];
spyOn(controller, 'setScrollPosition');
controller._show = true;
@ -291,7 +271,6 @@ describe('Component vnDropDown', () => {
let child = $element[0].firstChild.firstChild;
child.scrollIntoView = () => {};
spyOn(child, 'scrollIntoView');
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller._activeOption = 0;
controller.setScrollPosition();
@ -301,7 +280,6 @@ describe('Component vnDropDown', () => {
describe('selectItem()', () => {
it(`should pass item to selected and set controller._show to false`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let item = {id: 1, name: 'Batman'};
controller.selectItem(item);
@ -310,7 +288,6 @@ describe('Component vnDropDown', () => {
});
it(`should pass item to selected and set controller._show to true if the controller.multiple is defined`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
let item = {id: 1, name: 'Batman'};
controller.multiple = true;
controller.selectItem(item);
@ -322,14 +299,14 @@ describe('Component vnDropDown', () => {
describe('loadItems()', () => {
it(`should set controller._show to true`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
controller.loadItems();
expect(controller._show).toEqual(true);
});
it(`should call loadMore() and then set controller._show to true`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter}, {showLoadMore: () => {}, loadMore: () => {}});
controller.showLoadMore = () => {};
controller.loadMore = () => {};
spyOn(controller, 'loadMore');
controller.loadItems();
@ -340,7 +317,6 @@ describe('Component vnDropDown', () => {
describe('$onInit()', () => {
it(`should add an event listener to the parent element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller.parent, 'addEventListener');
controller.$onInit();
@ -350,7 +326,6 @@ describe('Component vnDropDown', () => {
describe('$onDestroy()', () => {
it(`should remove an event listener from the parent element`, () => {
let controller = $componentController('vnDropDown', {$element, $timeout, $filter});
spyOn(controller.parent, 'removeEventListener');
controller.$onDestroy();

View File

@ -2,6 +2,7 @@ import './grid-header.js';
describe('Component vnGridHeader', () => {
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -9,11 +10,11 @@ describe('Component vnGridHeader', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnGridHeader', {});
}));
describe('selectColum()', () => {
it(`should set controller currentColumn to equal the argument received`, () => {
let controller = $componentController('vnGridHeader', {});
let col = {columnStuff: 'some stuff'};
controller.selectColum(col);
@ -21,7 +22,6 @@ describe('Component vnGridHeader', () => {
});
it(`should set controller currentColumn.order to undefined then set currentColumn to equal the argument received`, () => {
let controller = $componentController('vnGridHeader', {});
controller.currentColumn = {field: 'some field', order: 'ordered'};
let col = {columnStuff: 'some stuff'};
controller.selectColum(col);
@ -31,7 +31,6 @@ describe('Component vnGridHeader', () => {
});
it(`should set controller currentColumn.order to undefined then call onOrder passing currentColumn as argument`, () => {
let controller = $componentController('vnGridHeader', {});
controller.onOrder = () => {};
spyOn(controller, 'onOrder');
let col = {columnStuff: 'some stuff'};

View File

@ -1,5 +1,8 @@
<div class="icon-menu">
<vn-icon-button icon="{{::$ctrl.icon}}"></vn-icon-button>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored icon-square icon-menu__button">
<vn-icon vn-none icon="{{::$ctrl.icon}}"></vn-icon>
<vn-icon vn-none class="icon-menu__arrow_down" icon="keyboard_arrow_down" ng-click="$ctrl.showDropDown = true"></vn-icon>
</button>
<div ng-if="!$ctrl.findMore">
<vn-drop-down
items="$ctrl.items"

View File

@ -6,6 +6,7 @@ describe('Component vnIconMenu', () => {
let $httpBackend;
let $timeout;
let $scope;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -17,19 +18,21 @@ describe('Component vnIconMenu', () => {
$timeout = _$timeout_;
$scope = $rootScope.$new();
$element = angular.element('<div></div>');
controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
}));
describe('component vnIconMenu', () => {
describe('findItem()', () => {
it(`should return items empty array if the controller does not provide a url and have no items defined`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout});
controller.findItems('some search value');
controller.url = undefined;
controller.items = undefined;
let result = controller.findItems('some search value');
expect(controller.items).not.toBeDefined();
expect(result).toEqual([]);
});
it(`should return items array if the controller does not provide a url`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout});
controller.url = undefined;
controller.items = ['Batman', 'Bruce Wayne'];
controller.findItems('some search value');
@ -37,11 +40,10 @@ describe('Component vnIconMenu', () => {
});
it(`should perform a search and store the result in controller items`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
let search = 'The Joker';
let json = JSON.stringify({where: {name: {regexp: search}}});
$httpBackend.whenGET(`test.com?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
$httpBackend.expectGET(`test.com?filter=${json}`);
$httpBackend.whenGET(`${controller.url}?filter=${json}`).respond([{id: 3, name: 'The Joker'}]);
$httpBackend.expectGET(`${controller.url}?filter=${json}`);
controller.findItems(search);
$httpBackend.flush();
@ -49,7 +51,6 @@ describe('Component vnIconMenu', () => {
});
it(`should call getItems function if there's no search value`, () => {
let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
spyOn(controller, 'getItems');
controller.findItems();
@ -57,18 +58,27 @@ describe('Component vnIconMenu', () => {
});
});
// implementation pending.
describe('getItems()', () => {
it(`should perform a query and then push elements found into controller.items`, () => {
controller.items = [];
$httpBackend.whenGET(`${controller.url}?filter={}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
$httpBackend.expectGET(`${controller.url}?filter={}`);
controller.getItems();
$httpBackend.flush();
// describe('getItems()', () => {
// it(`should perfom a query to fill the items without filter`, () => {
// let controller = $componentController('vnIconMenu', {$scope, $element, $httpBackend, $timeout}, {url: 'test.com'});
// $httpBackend.whenGET(`test.com?filter={}`).respond([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
// $httpBackend.expectGET(`test.com?filter={}`);
// controller.getItems();
// $httpBackend.flush();
expect(controller.items).toEqual([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
});
// expect(controller.items).toEqual([{id: 1, name: 'Batman'}, {id: 2, name: 'Bruce Wayne'}]);
// });
// });
it(`should perform a query and then set controller.maxRow to false if there are no items in the controller`, () => {
controller.items = [];
controller.maxRow = true;
$httpBackend.whenGET(`${controller.url}?filter={"skip":0,"limit":true,"order":"name ASC"}`).respond(controller.items);
$httpBackend.expectGET(`${controller.url}?filter={"skip":0,"limit":true,"order":"name ASC"}`);
controller.getItems();
$httpBackend.flush();
expect(controller.maxRow).toBeFalsy();
});
});
});
});

View File

@ -1,3 +1,12 @@
vn-icon-menu{
position: relative;
.icon-menu__button {
padding: 0 10px;
}
vn-icon{
float: left;
}
vn-icon.icon-menu__arrow_down{
margin:2px 0 0 5px;
}
}

View File

@ -1,4 +1,7 @@
import ngModule from './module';
import {module} from '../module';
var acl = window.salix ? window.salix.acl : {};
module.constant('aclConstant', acl);
aclService.$inject = ['aclConstant'];
function aclService(aclConstant) {
@ -29,4 +32,4 @@ function aclService(aclConstant) {
};
}
ngModule.service('aclService', aclService);
module.service('aclService', aclService);

View File

@ -4,6 +4,8 @@ import './template';
import './getTemplate';
import './app';
import './interceptor';
import './aclService';
import './storageServices';
export * from './util';
export {default as splitingRegister} from './splitingRegister';

View File

@ -0,0 +1,66 @@
import {module} from '../module';
class VnStorage {
constructor() {
this._type = '';
this.prefix = 'vn';
}
set type(value) {
this._type = value;
this.checkSupport();
}
get type() {
return this._type;
}
get webStorage() {
return window[this.type];
}
checkSupport() {
try {
let supported = (this.type in window && window[this.type] !== null);
if (supported) {
let key = '__' + Math.round(Math.random() * 1e7);
let webStorage = window[this.type];
webStorage.setItem(key, '');
webStorage.removeItem(key);
}
} catch (e) {
console.error('VnStorage.notification.error', e.message);
return false;
}
}
get(param) {
let toRead = this.webStorage.getItem(`${this.prefix}.${param}`);
if (toRead && toRead.startsWith('jsonObject:')) {
toRead = JSON.parse(toRead.replace('jsonObject:', ''));
}
return toRead;
}
set(param, data) {
let toStorage = typeof data === 'object' ? `jsonObject:${JSON.stringify(data)}` : data;
this.webStorage.setItem(`${this.prefix}.${param}`, toStorage);
}
remove(param) {
this.webStorage.removeItem(`${this.prefix}.${param}`);
}
clear() {
this.webStorage.clear();
}
}
class SessionStorage extends VnStorage {
constructor() {
super();
this.type = 'sessionStorage';
}
}
class LocalStorage extends VnStorage {
constructor() {
super();
this.type = 'localStorage';
}
}
module.service('sessionStorage', SessionStorage);
module.service('localStorage', LocalStorage);

View File

@ -1,4 +1,4 @@
<vn-vertical class="multi-check" vn-none class="multi-check {{$ctrl.className}}" tabindex="-1" ng-blur="$ctrl.showDropDown = false">
<vn-vertical class="multi-check" vn-none class="multi-check {{$ctrl.className}}" tabindex="1" ng-blur="$ctrl.onBlur()">
<vn-one>
<vn-horizontal>
<vn-none class="primaryCheckbox" ng-if="$ctrl.checkAll===0">

View File

@ -2,15 +2,40 @@ import {module} from '../module';
import './multi-check.scss';
/**
* Draw checkbox with a drop-down and multi options
* @param {SmallInt} checkAll Primary input-check state: 0 -> uncheck, 1 -> checked, 2 -> indeterminate checked
* @param {Array} options List of options shown in drop-down
* @param {Array} models Elements to check / unCheck
* @param {String} className Optional css class name
*/
export default class MultiCheck {
constructor() {
constructor($timeout) {
this.$timeout = $timeout;
this._checkAll = 0;
this._models = [];
this.type = {};
this._type = {};
this.showDropDown = false;
}
get type() {
return this._type;
}
set type(value) {
if (value && value.id) {
this._type = value;
switch (value.id) {
case 'all':
this.checkAll = 1;
break;
case 'any':
this.checkAll = 0;
break;
default:
this.checkAll = 2;
break;
}
}
this._type = {};
this.showDropDown = false;
}
@ -39,12 +64,12 @@ export default class MultiCheck {
if (this.type.id && this.type.id !== 'all' && this.type.id !== 'any') {
if (this.type.id.length > 3 && this.type.id.substr(0, 3) === 'no-') {
let label = this.type.id.replace('no-', '');
checked = el[label] == null;
checked = Boolean(el[label]) === false;
} else if (this.type.id.length > 6 && this.type.id.substr(0, 6) === 'equal-') {
let label = this.type.id.replace('equal-', '');
checked = (el[label] && el[label] === this.type.name);
} else {
checked = el[this.type.id] != null;
checked = Boolean(el[this.type.id]) === true;
}
} else {
checked = this.checkAll === 1;
@ -59,25 +84,14 @@ export default class MultiCheck {
this.checkAll = 0;
}
$doCheck() {
if (this.type && this.type.id) {
switch (this.type.id) {
case 'all':
this.checkAll = 1;
break;
case 'any':
this.checkAll = 0;
break;
default:
this.checkAll = 2;
break;
}
this.type = {};
}
onBlur() {
this.$timeout(() => {
this.showDropDown = false;
}, 200);
}
}
MultiCheck.$inject = [];
MultiCheck.$inject = ['$timeout'];
module.component('vnMultiCheck', {
template: require('./multi-check.html'),
@ -85,7 +99,7 @@ module.component('vnMultiCheck', {
bindings: {
checkAll: '=',
options: '<',
models: '=',
models: '<',
className: '@?'
}
});

View File

@ -2,6 +2,7 @@ import './multi-check.js';
describe('Component vnMultiCheck', () => {
let $componentController;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -9,11 +10,11 @@ describe('Component vnMultiCheck', () => {
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
controller = $componentController('vnMultiCheck', {});
}));
describe('models()', () => {
it(`should set controller _models property with the argument received`, () => {
let controller = $componentController('vnMultiCheck', {});
let argument = 'I am the model';
controller.models = argument;
@ -23,7 +24,6 @@ describe('Component vnMultiCheck', () => {
describe('checkAll()', () => {
it(`should set controller _checkAll property with the argument received then call switchChecks()`, () => {
let controller = $componentController('vnMultiCheck', {});
let argument = 'I am the model';
spyOn(controller, 'switchChecks');
controller.checkAll = argument;
@ -34,8 +34,7 @@ describe('Component vnMultiCheck', () => {
});
describe('switchChecks()', () => {
it(`should set checked property inside each existing elemenet when begings with no-`, () => {
let controller = $componentController('vnMultiCheck', {});
it(`should set checked property inside each existing elemenet when id begings with no-`, () => {
controller.type = {id: 'no-name'};
controller.models = [
{name: 'name'},
@ -47,12 +46,11 @@ describe('Component vnMultiCheck', () => {
controller._checkAll = 1;
controller.switchChecks();
expect(controller._models[0].checked).toBeFalsy();
expect(controller._models[0].checked).toBeTruthy();
expect(controller._models[1].checked).toBeTruthy();
});
it(`should set checked property inside each existing elemenet when begings with equal-`, () => {
let controller = $componentController('vnMultiCheck', {});
it(`should set checked property inside each existing elemenet when id begings with equal-`, () => {
controller.type = {id: 'equal-name', name: 'name'};
controller.models = [
{name: null},
@ -64,12 +62,11 @@ describe('Component vnMultiCheck', () => {
controller._checkAll = 1;
controller.switchChecks();
expect(controller._models[0].checked).toBeFalsy();
expect(controller._models[0].checked).toBeTruthy();
expect(controller._models[1].checked).toBeTruthy();
});
it(`should set checked property inside each existing elemenet when begings with anything but any, all, no- or equal-`, () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'name'};
controller.models = [
{name: null},
@ -81,13 +78,12 @@ describe('Component vnMultiCheck', () => {
controller._checkAll = 1;
controller.switchChecks();
expect(controller._models[0].checked).toBeFalsy();
expect(controller._models[0].checked).toBeTruthy();
expect(controller._models[1].checked).toBeTruthy();
});
describe('when id is any', () => {
it('should set element checked property based on controller._checkAll', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'any'};
controller.models = [
{name: 'name'}
@ -111,7 +107,6 @@ describe('Component vnMultiCheck', () => {
describe('when id is all', () => {
it('should set element checked property based on controller._checkAll property', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'all'};
controller.models = [
{name: 'name'}
@ -136,7 +131,6 @@ describe('Component vnMultiCheck', () => {
describe('$onChanges()', () => {
it('should set controller.type to empty object and checkAll to zero', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'all'};
controller._checkAll = 1;
controller.$onChanges();
@ -146,22 +140,21 @@ describe('Component vnMultiCheck', () => {
});
});
describe('$doCheck()', () => {
describe('type setter', () => {
it('should set controller.type to empty object and checkAll based on controller.type.id', () => {
let controller = $componentController('vnMultiCheck', {});
controller.type = {id: 'all'};
let value = {id: 'all'};
controller._checkAll = 0;
controller.$doCheck();
controller.type = value;
expect(controller.type).toEqual({});
expect(controller._checkAll).toEqual(1);
controller.type = {id: 'any'};
controller.$doCheck();
value = {id: 'any'};
controller.type = value;
expect(controller.type).toEqual({});
expect(controller._checkAll).toEqual(0);
controller.type = {id: 'any other id name'};
controller.$doCheck();
value = {id: 'any other id name'};
controller.type = value;
expect(controller.type).toEqual({});
expect(controller._checkAll).toEqual(2);

View File

@ -1,6 +1,7 @@
<paging
page="$ctrl.currentPage"
page-size="$ctrl.numPerPage"
ng-if="$ctrl.numPages>1"
total="$ctrl.numItems"
show-prev-next="true"
show-first-last="false"

View File

@ -39,6 +39,11 @@ export default class Paging {
this.pageChange();
}
}
$doCheck() {
if (this.index && this.index.filter && this.index.filter.page && this.index.filter.page != this.currentPage) {
this.currentPage = this.index.filter.page;
}
}
}
Paging.$inject = ['$http', '$scope'];

View File

@ -4,6 +4,7 @@ describe('Component vnPaging', () => {
let $componentController;
let $scope;
let $httpBackend;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -13,11 +14,11 @@ describe('Component vnPaging', () => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
controller = $componentController('vnPaging', {$scope, $httpBackend});
}));
describe('$onChanges()', () => {
it(`should define numberPage and currentPage based on index.filter properties`, () => {
let controller = $componentController('vnPaging', {$scope, $httpBackend});
controller.index = {filter: {size: 'something', page: 'something else'}};
controller.$onChanges({index: 'simpleChange', currentValue: 'current value', previousValue: 'previous value'});
@ -26,7 +27,6 @@ describe('Component vnPaging', () => {
});
it(`should define numItems based on changes.total.currentValue`, () => {
let controller = $componentController('vnPaging', {$scope, $httpBackend});
controller.index = {filter: {size: 'something', page: 'something else'}};
controller.$onChanges({total: {currentValue: 'current value'}});
@ -36,7 +36,6 @@ describe('Component vnPaging', () => {
describe('onModelUpdated()', () => {
it(`should define controllers numItems as the result of page times size plus one`, () => {
let controller = $componentController('vnPaging', {$scope, $httpBackend});
controller.numPerPage = 2;
controller.index = {
filter: {size: 10, page: 10},
@ -50,8 +49,7 @@ describe('Component vnPaging', () => {
describe('onPageChange()', () => {
it(`should call accept() since pageChange property is undefined`, () => {
let myIndex = {accept: () => {}, filter: {page: 0}};
let controller = $componentController('vnPaging', {$scope, $httpBackend}, {index: myIndex});
controller.index = {accept: () => {}, filter: {page: 0}};
spyOn(controller.index, 'accept');
controller.onPageChange(100);
@ -59,8 +57,7 @@ describe('Component vnPaging', () => {
});
it(`should call pageChange() since pageChange property isn't undefined`, () => {
let myIndex = {accept: () => {}, filter: {page: 0}};
let controller = $componentController('vnPaging', {$scope, $httpBackend}, {index: myIndex});
controller.index = {accept: () => {}, filter: {page: 0}};
controller.pageChange = true;
spyOn(controller, 'pageChange');
controller.onPageChange(100);

View File

@ -0,0 +1,63 @@
import './spinner.js';
describe('Component vnSpinner', () => {
let $componentController;
let $scope;
let $element;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$element = angular.element('<div><div></div></div>');
controller = $componentController('vnSpinner', {$scope, $element});
}));
describe('enable()', () => {
it(`should call start() based on a boolean value passed as argument`, () => {
spyOn(controller, 'start');
spyOn(controller, 'stop');
controller.enable = true;
expect(controller.start).toHaveBeenCalledWith();
expect(controller.stop).not.toHaveBeenCalledWith();
});
it(`should call stop() based on a boolean value passed as argument`, () => {
spyOn(controller, 'start');
spyOn(controller, 'stop');
controller.enable = false;
expect(controller.start).not.toHaveBeenCalledWith();
expect(controller.stop).toHaveBeenCalledWith();
});
});
describe('start()', () => {
it(`should call start() on the controller.materialSpinner then set controllers._enable to be truthy`, () => {
controller.spinner = {MaterialSpinner: {start: () => {}}};
spyOn(controller.spinner.MaterialSpinner, 'start');
controller._enable = false;
controller.start();
expect(controller.spinner.MaterialSpinner.start).toHaveBeenCalledWith();
expect(controller._enable).toBeTruthy();
});
});
describe('stop()', () => {
it(`should call stop() on the controller.materialSpinner then set controllers._enable to be truthy`, () => {
controller.spinner = {MaterialSpinner: {stop: () => {}}};
spyOn(controller.spinner.MaterialSpinner, 'stop');
controller._enable = true;
controller.stop();
expect(controller.spinner.MaterialSpinner.stop).toHaveBeenCalledWith();
expect(controller._enable).toBeFalsy();
});
});
});

View File

@ -6,6 +6,7 @@ describe('Component vnTextfield', () => {
let $attrs;
let $timeout;
let $element;
let controller;
beforeEach(() => {
angular.mock.module('client');
@ -17,11 +18,11 @@ describe('Component vnTextfield', () => {
$attrs = {};
$timeout = _$timeout_;
$element = angular.element('<div><input></div>');
controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
}));
describe('value() setter', () => {
it(`should set _value, input.value and hasValue properties to null, '' and false then call mdlUpdate()`, () => {
let controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
spyOn(controller, 'mdlUpdate');
let testValue = '';
controller.value = testValue;
@ -33,7 +34,6 @@ describe('Component vnTextfield', () => {
});
it(`should set _value, input.value and hasValue propertiest to test, test and true then call mdlUpdate()`, () => {
let controller = $componentController('vnTextfield', {$scope, $element, $attrs, $timeout});
spyOn(controller, 'mdlUpdate');
let testValue = 'test';
controller.value = testValue;

View File

@ -59,7 +59,7 @@ export default class Watcher extends Component {
* Submits the data and goes back in the history.
*/
submitBack() {
this.submit().then(
return this.submit().then(
() => this.window.history.back()
);
}
@ -69,7 +69,7 @@ export default class Watcher extends Component {
* @param {String} state The state name
*/
submitGo(state) {
this.submit().then(
return this.submit().then(
() => this.$state.go(state)
);
}

View File

@ -0,0 +1,293 @@
import './watcher.js';
import getModifiedData from '../lib/modified';
describe('Component vnWatcher', () => {
let $componentController;
let $scope;
let $element;
let $state;
let $transitions;
let $httpBackend;
let vnApp;
let $translate;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$state_, _$transitions_, _$httpBackend_, _vnApp_, _$translate_) => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$element = angular.element('<div></div>');
$state = _$state_;
vnApp = _vnApp_;
$transitions = _$transitions_;
$httpBackend = _$httpBackend_;
$translate = _$translate_;
controller = $componentController('vnWatcher', {$scope, $element, $state, vnApp, $transitions, $httpBackend, $translate});
}));
describe('$onInit()', () => {
it(`should call fetchData() if controllers get and url properties are defined`, () => {
controller.get = () => {};
controller.url = 'test.com';
spyOn(controller, 'fetchData');
controller.$onInit();
expect(controller.fetchData).toHaveBeenCalledWith();
});
it(`should throw an error if $onInit is called without url defined`, () => {
controller.get = () => {};
expect(function() {
controller.$onInit();
}).toThrow(new Error('Error: Parameter url ommitted'));
});
});
describe('$onChanges()', () => {
it(`should call updateOriginalData() if controllers data is defined`, () => {
controller.data = [];
spyOn(controller, 'updateOriginalData');
controller.$onChanges();
expect(controller.updateOriginalData).toHaveBeenCalledWith();
});
});
describe('$onDestroy()', () => {
it(`should call deregisterCallback()`, () => {
spyOn(controller, 'deregisterCallback');
controller.$onDestroy();
expect(controller.deregisterCallback).toHaveBeenCalledWith();
});
});
describe('fetchData()', () => {
it(`should perform a query then store the received data into controller.data and call updateOriginalData()`, () => {
spyOn(controller, 'updateOriginalData');
let json = {data: 'some data'};
controller.data = [1];
controller.idField = 0;
controller.url = 'test.com';
$httpBackend.whenGET('test.com/1').respond(json);
$httpBackend.expectGET('test.com/1');
controller.fetchData();
$httpBackend.flush();
expect(controller.data).toEqual({data: 'some data'});
expect(controller.updateOriginalData).toHaveBeenCalledWith();
});
});
describe('submitBack()', () => {
it(`should call controller.window.history.back() function after calling controllers submit() function`, done => {
spyOn(controller, 'submit').and.returnValue(Promise.resolve());
spyOn(controller.window.history, 'back');
controller.submitBack()
.then(() => {
expect(controller.submit).toHaveBeenCalledWith();
expect(controller.window.history.back).toHaveBeenCalledWith();
done();
});
});
});
describe('submitGo()', () => {
it(`should call controller.$state.go() function after calling controllers submit() function`, done => {
spyOn(controller, 'submit').and.returnValue(Promise.resolve());
spyOn(controller.$state, 'go');
let state = 'the state';
controller.submitGo(state)
.then(() => {
expect(controller.submit).toHaveBeenCalledWith();
expect(controller.$state.go).toHaveBeenCalledWith(state);
done();
});
});
});
describe('submit()', () => {
describe('when controller.form', () => {
it(`should call controller.form.setSubminted if controller.form is defined`, () => {
controller.form = {$setSubmitted: () => {}};
spyOn(controller.form, '$setSubmitted');
controller.submit();
expect(controller.form.$setSubmitted).toHaveBeenCalledWith();
});
it(`should call controller.invalidForm if controller.form.$valid is not defined`, () => {
controller.form = {$setSubmitted: () => {}};
spyOn(controller, 'invalidForm');
controller.submit();
expect(controller.invalidForm).toHaveBeenCalledWith(jasmine.any(Function));
});
});
describe('when !controller.dataChanged()', () => {
it(`should call controller.noChanges()`, () => {
spyOn(controller, 'noChanges');
controller.submit();
expect(controller.noChanges).toHaveBeenCalledWith(jasmine.any(Function));
});
});
describe('when controller.save()', () => {
it(`should set controller.save.model property`, () => {
controller.save = {};
controller.data = {originalInfo: 'original data', info: 'new data'};
controller.orgData = {originalInfo: 'original data'};
controller.submit();
expect(controller.save.model).toEqual({info: 'new data'});
});
it(`should call controller.save.accept() then controller.writeData`, done => {
controller.save = {accept: () => {}};
controller.data = {originalInfo: 'original data', info: 'new data'};
controller.orgData = {originalInfo: 'original data'};
spyOn(controller.save, 'accept').and.returnValue(Promise.resolve());
spyOn(controller, 'writeData').and.callThrough();
controller.submit()
.then(() => {
expect(controller.save.accept).toHaveBeenCalledWith();
expect(controller.writeData).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Function));
done();
});
});
});
describe('when id is defined', () => {
it(`should perform a query then call controller.writeData()`, () => {
controller.dataChanged = () => {
return true;
};
controller.data = {id: 2};
controller.orgData = {id: 1};
let changedData = getModifiedData(controller.data, controller.orgData);
controller.idField = 'id';
controller.url = 'test.com';
let json = {data: 'some data'};
spyOn(controller, 'writeData').and.callThrough();
$httpBackend.whenPATCH(`${controller.url}/1`, changedData).respond(json);
$httpBackend.expectPATCH(`${controller.url}/1`);
controller.submit()
.then(() => {
expect(controller.writeData).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Function));
done();
});
$httpBackend.flush();
});
});
it(`should perform a POST query then call controller.writeData()`, () => {
controller.dataChanged = () => {
return true;
};
controller.data = {id: 2};
controller.orgData = {id: 1};
controller.url = 'test.com';
let json = {data: 'some data'};
spyOn(controller, 'writeData').and.callThrough();
$httpBackend.whenPOST(`${controller.url}`, controller.data).respond(json);
$httpBackend.expectPOST(`${controller.url}`, controller.data);
controller.submit()
.then(() => {
expect(controller.writeData).toHaveBeenCalledWith(jasmine.any(Object), jasmine.any(Function));
done();
});
$httpBackend.flush();
});
});
describe('writeData()', () => {
it(`should call Object.asssign() function over controllers.data with json.data, then call updateOriginalData function and finally call resolve() function`, () => {
spyOn(controller, 'updateOriginalData');
controller.data = {};
let json = {data: 'some data'};
let resolve = jasmine.createSpy('resolve');
controller.writeData(json, resolve);
expect(controller.updateOriginalData).toHaveBeenCalledWith();
expect(resolve).toHaveBeenCalledWith(json);
});
});
describe('copyInNewObject()', () => {
it(`should return newCopy object if data was an object`, () => {
let data = {id: 1, Heroname: 'Batman', name: 'Bruce Wayne'};
let result = controller.copyInNewObject(data);
expect(result).toEqual(data);
});
});
describe('callback()', () => {
describe(`when dataChanged() returns true and there's no state in the controller`, () => {
it(`should define controller.state, call controller.$scope.confirm.show() and return false`, () => {
$scope.confirm = {show: jasmine.createSpy('show')};
controller.dataChanged = () => {
return true;
};
controller.state = undefined;
let transition = {to: () => {
return {name: 'Batman'};
}};
let result = controller.callback(transition);
expect(controller.state).toEqual('Batman');
expect(controller.$scope.confirm.show).toHaveBeenCalledWith();
expect(result).toBeFalsy();
});
});
describe(`when dataChanged() returns false and/or there's a state in the controller`, () => {
it(`should return true`, () => {
$scope.confirm = {show: jasmine.createSpy('show')};
controller.dataChanged = () => {
return false;
};
controller.state = 'the state';
let transition = {to: () => {
return {name: 'Batman'};
}};
let result = controller.callback(transition);
expect(result).toBeTruthy();
});
});
});
describe(`onConfirmResponse()`, () => {
describe(`when response is ACCEPT`, () => {
it(`should call Object.assing on controlle.data with controller.orgData then call go() on state`, () => {
let response = 'ACCEPT';
controller.data = {};
controller.orgData = {name: 'Batman'};
controller.$state = {go: jasmine.createSpy('go')};
controller.state = 'Batman';
controller.onConfirmResponse(response);
expect(controller.data).toEqual(controller.orgData);
expect(controller.$state.go).toHaveBeenCalledWith(controller.state);
});
});
describe(`when response is not ACCEPT`, () => {
it(`should set controller.state to null`, () => {
let response = 'anything but ACCEPT';
controller.state = 'Batman';
controller.onConfirmResponse(response);
expect(controller.state).toBeFalsy();
});
});
});
});
// 309

1
client/locator/index.js Normal file
View File

@ -0,0 +1 @@
export * from './src/locator';

View File

@ -0,0 +1,14 @@
{
"module": "locator",
"name": "Locator",
"icon": "add_location",
"validations" : false,
"routes": [
{
"url": "/locator",
"state": "locator",
"component": "vn-locator-index",
"acl": ["developer"]
}
]
}

View File

@ -0,0 +1,39 @@
<vn-card margin-large>
<vn-vertical pad-medium>
<vn-horizontal vn-one margin-large-bottom class="locator-header">
<vn-title vn-one>Routes locator</vn-title>
<form vn-two vn-horizontal class="filterPanel" ng-submit="$ctrl.searchRoutes()">
<vn-textfield vn-one label="Filter" model="$ctrl.search"></vn-textfield>
<vn-icon
vn-none
margin-medium-right
pad-medium-top
icon="keyboard_arrow_down"
ng-click="$ctrl.moreFilters($event)">
</vn-icon>
<vn-button vn-none pad-small-top label="Filtrar" ng-click="$ctrl.searchRoutes()"></vn-button>
</form>
<vn-one vn-horizontal>
<vn-one></vn-one>
<vn-autocomplete vn-two
initial-value="$ctrl.filter.warehouseFk"
show-field="name"
value-field="id"
field="$ctrl.filter.warehouseFk"
url="/production/api/Warehouses/production"
on-change = "$ctrl.onChangeWareHouse(item)"
label="Store">
</vn-autocomplete>
<vn-icon-button vn-none pad-ten-top margin-medium-left icon="refresh" ng-click="$ctrl.refreshRoutes()"></vn-icon-button>
</vn-one>
</vn-horizontal>
<vn-horizontal vn-one margin-large-bottom>
<vn-one>
<vn-locator-actions routes="$ctrl.routes" states="$ctrl.states" hour-items="$ctrl.hourItems"></vn-locator-actions>
</vn-one>
<vn-two></vn-two>
</vn-horizontal>
<vn-locator-table check-all="$ctrl.checkAll" routes="$ctrl.routes" footer="$ctrl.footer"></vn-locator-table>
</vn-vertical>
</vn-card>

View File

@ -0,0 +1,33 @@
import ngModule from '../module';
class LocatorIndex {
constructor($state) {
this.$state = $state;
this.routes = [];
for (let i = 1; i < 100; i++) {
let route = {
id: i,
zoneFk: Math.floor(Math.random() * 6) + 1,
postalcode: 46006,
order: Math.floor(Math.random() * 3) + 1,
preparado: '25/08',
entrada: '26/08',
ticket: 1547890 + i,
routeFk: Math.floor(Math.random() * 9999) + 1000,
alias: `Flores X${Math.floor(Math.random() * 3) + 1}`,
bultos: Math.floor(Math.random() * 20) + 10,
m3: (Math.random()).toFixed(2),
error: (Math.floor(Math.random() * 3) + 1) === 1
};
route.success = (!route.error && (Math.floor(Math.random() * 3) + 1) === 1);
this.routes.push(route);
}
}
}
LocatorIndex.$inject = ['$state'];
ngModule.component('vnLocatorIndex', {
template: require('./index.html'),
controller: LocatorIndex
});

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,6 @@
{
"Routes locator": "Localizador de rutas",
"Filter": "Filtro",
"Store": "Almacén",
"Address": "Dirección"
}

View File

@ -0,0 +1,14 @@
<vn-horizontal class="actionPanel">
<vn-none margin-medium-right>
<vn-icon-button icon="local_shipping"></vn-icon-button>
</vn-none>
<vn-none margin-medium-right>
<vn-icon-menu icon="local_shipping" selected="$ctrl.actionRoute" items="[{id:1,name:'test_01'},{id:2,name:'test_02'}]"></vn-icon-menu>
</vn-none>
<vn-none margin-medium-right>
</vn-none>
<vn-none margin-medium-right>
</vn-none>
</vn-horizontal>

View File

@ -0,0 +1,13 @@
import ngModule from '../module';
class LocatorActions {
constructor($state) {
this.$state = $state;
}
}
LocatorActions.$inject = ['$state'];
ngModule.component('vnLocatorActions', {
template: require('./locator-actions.html'),
controller: LocatorActions
});

View File

@ -0,0 +1,60 @@
<vn-vertical>
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
<vn-column-header vn-one pad-medium-h>
<vn-multi-check
check-all="$ctrl.checkAll"
models="$ctrl.routes"
options="[{id:'all',name:'Todos'},{id:'any',name:'Ninguno'}, {id:'error', name:'Con problema'}, {id:'no-error', name:'Sin problema'}]"
></vn-multi-check>
</vn-column-header>
<vn-column-header vn-two pad-medium-h field="zoneFk" text="Zona"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="postalcode" text="Postal Code"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="order" text="Order" default-order="DESC"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="preparado" text="Preparado"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="entrada" text="Entrada"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="ticket" text="Ticket"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="routeFk" text="ID de ruta"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="alias" text="Alias"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="bultos" text="Bultos"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="m3" text="m3"></vn-column-header>
</vn-grid-header>
<vn-one class="list list-content">
<vn-vertical
class="list list-element text-center"
ng-repeat="route in $ctrl.pageTable.model track by route.id"
ng-class="{warning: route.error, success: route.success}"
>
<vn-horizontal>
<vn-one pad-medium-h></vn-one>
<vn-two pad-medium-h>{{::route.zoneFk}}</vn-two>
<vn-two pad-medium-h>{{::route.postalcode}}</vn-two>
<vn-two pad-medium-h>{{::route.order}}</vn-two>
<vn-two pad-medium-h>{{::route.preparado}}</vn-two>
<vn-two pad-medium-h>{{::route.entrada}}</vn-two>
<vn-two pad-medium-h>{{::route.ticket}}</vn-two>
<vn-two pad-medium-h>{{::route.routeFk}}</vn-two>
<vn-two pad-medium-h>{{::route.alias}}</vn-two>
<vn-two pad-medium-h>{{::route.bultos}}</vn-two>
<vn-two pad-medium-h>{{::route.m3}}</vn-two>
</vn-horizontal>
<vn-horizontal margin-small-top>
<vn-none pad-medium-h margin--small-top>
<vn-check model="route.checked"></vn-check>
</vn-none>
<vn-none pad-medium-h></vn-none>
<vn-one text-left pad-small border-solid>
<strong translate>Address</strong>: {{::route.address}}
</vn-one>
<vn-none pad-medium-h>
<vn-icon icon="more" vn-tooltip tooltip-template="/static/templates/tooltip.routes.tpl.html" tooltip-position="left"></vn-icon>
</vn-none>
</vn-horizontal>
</vn-vertical>
</vn-one>
<vn-horizontal vn-one class="list list-footer">
</vn-horizontal>
<vn-one>
<vn-paging page-change="$ctrl.paginate()" index="$ctrl.pageTable" total="$ctrl.totalFilter"></vn-paging>
</vn-one>
</vn-vertical>

View File

@ -0,0 +1,46 @@
import ngModule from '../module';
class LocatorTable {
constructor($filter) {
this.$filter = $filter;
this.itemsDisplayedInList = 7;
this.pageTable = {
filter: {
page: 1,
size: this.itemsDisplayedInList
},
model: []
};
this._routes = [];
}
set routes(value) {
this._routes = value;
this.totalFilter = this._routes.length;
this.pageTable.filter.page = 1;
this.paginate();
}
get routes() {
return this._routes;
}
onOrder(field, order) {
let reverse = order === 'DESC';
this.routes = this.$filter('orderBy')(this.routes, field, reverse);
this.paginate();
}
paginate() {
let init = (this.pageTable.filter.page - 1) * this.itemsDisplayedInList;
let fin = this.pageTable.filter.page * this.itemsDisplayedInList;
this.pageTable.model = this.routes.slice(init, fin);
}
}
LocatorTable.$inject = ['$filter'];
ngModule.component('vnLocatorTable', {
template: require('./locator-table.html'),
bindings: {
routes: '<'
},
controller: LocatorTable
});

View File

@ -0,0 +1,5 @@
export * from './module';
import './index/index';
import './locator-actions/locator-actions';
import './locator-table/locator-table';

View File

@ -0,0 +1,5 @@
import {ng} from 'vendor';
import 'core';
const ngModule = ng.module('locator', []);
export default ngModule;

View File

@ -4,5 +4,6 @@
"core": [],
"client": [],
"production": [],
"route": []
"route": [],
"locator": []
}

View File

@ -7,7 +7,8 @@
{
"url": "/production",
"state": "production",
"component": "vn-production-index"
"component": "vn-production-index",
"acl": ["developer"]
}
]
}

View File

@ -83,7 +83,15 @@ export default class ProductionIndex {
event.preventDefault();
}
onChildSubmit(filter) {
this.searchTickets(filter);
let newFilter = {};
Object.keys(filter).forEach(
field => {
if (filter[field] !== null) {
newFilter[field] = filter[field];
}
}
);
this.searchTickets(newFilter);
this.onChildCancel();
}
onChildCancel() {
@ -93,7 +101,6 @@ export default class ProductionIndex {
}
searchTickets(filter) {
this.filter = Object.assign({}, this.filter, filter || {});
let filters = Object.assign({}, {
where: this.filter
}, {
@ -112,13 +119,13 @@ export default class ProductionIndex {
}
refreshTickets() {
this.filter = {};
this.filter.warehouseFk = this.userProfile.warehouseId;
this.filter.warehouseFk = this.$.displayValue = this.userProfile.warehouseId;
this.search = null;
}
onChangeWareHouse(item) {
if (item && item.id && item.id != this.filter.warehouseFk) {
this.filter.warehouseFk = item.id;
this.searchTickets();
onChangeWareHouse(warehouse) {
if (warehouse && warehouse != this.filter.warehouseFk) {
this.filter.warehouseFk = warehouse;
this.searchTickets(this.filter);
}
}
$onInit() {
@ -130,9 +137,10 @@ export default class ProductionIndex {
hour += ':00';
this.hourItems.push({id: i, name: hour});
}
this.searchTickets();
this.filter.warehouseFk = this.$.displayValue = this.userProfile.warehouseId;
}
}
ProductionIndex.$inject = ['$element', '$scope', '$http', 'vnPopover', 'aclConstant'];
ngModule.component('vnProductionIndex', {

View File

@ -32,7 +32,6 @@ export class ProductionTable {
onOrder(field, order) {
let reverse = order === 'DESC';
this.tickets = this.$filter('orderBy')(this.tickets, field, reverse);
this.pageTickets();
}
pageTickets() {
let init = (this.pageTable.filter.page - 1) * this.itemsDisplayedInList;
@ -46,9 +45,9 @@ ProductionTable.$inject = ['$filter'];
ngModule.component('vnProductionTable', {
template: require('./production-table.html'),
bindings: {
tickets: '=',
tickets: '<',
footer: '<',
checkAll: '='
checkAll: '<'
},
controller: ProductionTable
});

View File

@ -13,7 +13,8 @@
{
"url": "/list",
"state": "routes.index",
"component": "vn-route-index"
"component": "vn-route-index",
"acl": ["developer"]
},
{
"url": "/create",
@ -34,7 +35,7 @@
"route": "$ctrl.route"
},
"menu": {
"description": "Datos básicos",
"description": "Basic data",
"icon": "person"
}
},
@ -42,11 +43,12 @@
"url": "/logisticData",
"state": "routes.card.logisticData",
"component": "vn-route-logistic-data",
"acl": ["employee"],
"params": {
"route": "$ctrl.route"
},
"menu": {
"description": "Datos logísticos",
"description": "Logistic data",
"icon": "local_shipping"
}
},
@ -58,7 +60,7 @@
"route": "$ctrl.route"
},
"menu": {
"description": "Tickets asignados",
"description": "Assigned tickets",
"icon": "assignment"
}
}

View File

@ -0,0 +1,37 @@
<vn-watcher
vn-id="watcher"
data="$ctrl.route"
form="form"
>
</vn-watcher>
<form name="form" pad-medium>
<vn-card>
<vn-vertical pad-large>
<vn-title>Basic data</vn-title>
<vn-horizontal>
<vn-date-picker vn-one label="Date" model="$ctrl.route.date"></vn-date-picker>
<vn-autocomplete vn-one
label="Agency"
url="/route/api/Agencies"
field="$ctrl.route.agency"
>
</vn-autocomplete>
<vn-autocomplete vn-one
field="$ctrl.route.driver"
url="/route/api/Vehicles/activeDrivers"
label="Driver"></vn-autocomplete>
<vn-autocomplete vn-one
field="$ctrl.route.vehicle"
url="/route/api/Vehicles/comboVehicles"
label="Vehicle"
order="tradeMark ASC"
filter="{where: {isActive:1, warehouseFk:1}}"
></vn-autocomplete>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -0,0 +1,8 @@
import ngModule from '../module';
ngModule.component('vnRouteBasicData', {
template: require('./basic-data.html'),
bindings: {
route: '<'
}
});

View File

@ -8,11 +8,11 @@
<vn-card>
<vn-vertical class="margin-medium" pad-medium-top pad-medium-bottom>
<vn-horizontal>
<vn-one>
<a vn-one ui-sref="routes.index">
<i class="material-icons descriptor-icon">local_shipping</i>
</vn-one>
</a>
<vn-vertical vn-two>
<div class="margin-none"><span translate>Ruta</span> {{::$ctrl.route.id}}</div>
<div class="margin-none"><span translate>Route</span> {{::$ctrl.route.id}}</div>
<div class="margin-none">{{$ctrl.route.date | date:'dd/MM/yyyy'}}</div>
</vn-vertical>
</vn-horizontal>

View File

View File

@ -20,8 +20,19 @@
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Driver" field="$ctrl.delivery.driver"></vn-textfield>
<vn-textfield vn-one label="Vehicle" field="$ctrl.delivery.vehicle"></vn-textfield>
<vn-autocomplete vn-one
field="$ctrl.delivery.driver"
url="/route/api/Vehicles/activeDrivers"
label="Driver"></vn-autocomplete>
<vn-autocomplete vn-one
field="$ctrl.delivery.vehicle"
url="/route/api/Vehicles/comboVehicles"
label="Vehicle"
order="tradeMark ASC"
filter="{where: {isActive:1, warehouseFk:1}}"
></vn-autocomplete>
</vn-horizontal>
</vn-vertical>

View File

@ -0,0 +1,12 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 48 48" version="1.1" width="528" height="528">
<g id="surface1">
<path style=" fill:#1C9957;" d="M 42 39 L 42 9 C 42 7.34375 40.65625 6 39 6 L 9 6 C 7.34375 6 6 7.34375 6 9 L 6 39 C 6 40.65625 7.34375 42 9 42 L 39 42 C 40.65625 42 42 40.65625 42 39 Z "/>
<path style=" fill:#3E7BF1;" d="M 9 42 L 39 42 C 40.65625 42 24 26 24 26 C 24 26 7.34375 42 9 42 Z "/>
<path style=" fill:#CBCCC9;" d="M 42 39 L 42 9 C 42 7.34375 26 24 26 24 C 26 24 42 40.65625 42 39 Z "/>
<path style=" fill:#EFEFEF;" d="M 39 42 C 40.65625 42 42 40.65625 42 39 L 42 38.753906 L 26.246094 23 L 23 26.246094 L 38.753906 42 Z "/>
<path style=" fill:#FFD73D;" d="M 42 9 C 42 7.34375 40.65625 6 39 6 L 38.753906 6 L 6 38.753906 L 6 39 C 6 40.65625 7.34375 42 9 42 L 9.246094 42 L 42 9.246094 Z "/>
<path style=" fill:#D73F35;" d="M 36 2 C 30.476563 2 26 6.476563 26 12 C 26 18.8125 33.664063 21.296875 35.332031 31.851563 C 35.441406 32.53125 35.449219 33 36 33 C 36.550781 33 36.558594 32.53125 36.667969 31.851563 C 38.335938 21.296875 46 18.8125 46 12 C 46 6.476563 41.523438 2 36 2 Z "/>
<path style=" fill:#752622;" d="M 39.5 12 C 39.5 13.933594 37.933594 15.5 36 15.5 C 34.066406 15.5 32.5 13.933594 32.5 12 C 32.5 10.066406 34.066406 8.5 36 8.5 C 37.933594 8.5 39.5 10.066406 39.5 12 Z "/>
<path style=" fill:#FFFFFF;" d="M 14.492188 12.53125 L 14.492188 14.632813 L 17.488281 14.632813 C 17.09375 15.90625 16.03125 16.816406 14.492188 16.816406 C 12.660156 16.816406 11.175781 15.332031 11.175781 13.5 C 11.175781 11.664063 12.660156 10.179688 14.492188 10.179688 C 15.316406 10.179688 16.070313 10.484375 16.648438 10.980469 L 18.195313 9.433594 C 17.21875 8.542969 15.921875 8 14.492188 8 C 11.453125 8 8.992188 10.464844 8.992188 13.5 C 8.992188 16.535156 11.453125 19 14.492188 19 C 19.304688 19 20.128906 14.683594 19.675781 12.539063 Z "/>
</g>
</svg>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 30.3 26.6" style="enable-background:new 0 0 30.3 26.6;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
.st1{fill:#F7931E;}
</style>
<rect width="30.3" height="26.6"/>
<g>
<path class="st0" d="M24.9,9.7h-3.7v-5H4c-1.4,0-2.5,1.1-2.5,2.5v13.5H4c0,2,1.6,3.7,3.7,3.7s3.7-1.6,3.7-3.7h7.4
c0,2,1.6,3.7,3.7,3.7s3.7-1.6,3.7-3.7h2.5v-6.1L24.9,9.7z M7.7,22.5c-1,0-1.8-0.8-1.8-1.8s0.8-1.8,1.8-1.8s1.8,0.8,1.8,1.8
S8.7,22.5,7.7,22.5z M24.2,11.5l2.4,3.1h-5.5v-3.1H24.2z M22.4,22.5c-1,0-1.8-0.8-1.8-1.8s0.8-1.8,1.8-1.8s1.8,0.8,1.8,1.8
C24.2,21.7,23.4,22.5,22.4,22.5z"/>
<path class="st1" d="M12,7.2c-3,0-5.5,2.5-5.5,5.5S9,18.2,12,18.2s5.5-2.5,5.5-5.5S15,7.2,12,7.2z M14.8,13.3h-2.2v2.2h-1.1v-2.2
H9.3v-1.1h2.2V9.9h1.1v2.2h2.2V13.3z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

Some files were not shown because too many files have changed in this diff Show More