Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
gerard 2018-06-19 09:06:22 +02:00
commit 8448d76ebe
30 changed files with 172 additions and 115 deletions

View File

@ -1,4 +1,8 @@
<div ng-click="$ctrl.onSnackbarClick($event)">
<div id="shapes"></div>
<!-- <div ng-click="$ctrl.onSnackbarClick($event)">
<button ng-click="$ctrl.onButtonClick()"></button>
<div class="text"></div>
</div>
-->

View File

@ -9,11 +9,50 @@ export default class Controller extends Component {
constructor($element, $translate) {
super($element);
this.$translate = $translate;
this.shown = false;
this.snackbar = $element[0].firstChild;
this.$snackbar = angular.element(this.snackbar);
this.button = $element[0].querySelector('button');
this.textNode = this.snackbar.querySelector('.text');
}
/**
* It creates a new snackbar notification
* @param {Object} data Snackbar data
* @return {Object} Created snackbar shape
*/
createShape(data) {
let shape = document.createElement('div');
shape.className = 'shape';
let button = document.createElement('button');
let buttonText = data.actionText || this.$translate.instant('Hide');
buttonText = document.createTextNode(buttonText);
button.appendChild(buttonText);
button.addEventListener('click', () => {
this.onButtonClick(shape);
});
shape.appendChild(button);
let shapeText = document.createElement('div');
shapeText.setAttribute('class', 'text');
shape.appendChild(shapeText);
let text = document.createTextNode(data.message);
shapeText.appendChild(text);
if (data.shapeType)
shape.classList.add(data.shapeType);
let parent = this.snackbar.querySelectorAll('.shape')[0];
if (parent) {
this.snackbar.insertBefore(shape, parent);
} else {
this.snackbar.appendChild(shape);
}
return shape;
}
/**
@ -22,24 +61,15 @@ export default class Controller extends Component {
* @param {Object} data The message data
*/
show(data) {
if (this.shown) {
this.hide();
this.onTransitionEnd();
}
this.clearTimeouts();
this.shown = true;
this.textNode.textContent = data.message;
this.actionHandler = data.actionHandler;
this.button.textContent =
data.actionText || this.$translate.instant('Hide');
let shape = this.createShape(data);
this.timeoutId = setTimeout(() =>
this.hide(), data.timeout || 6000);
setTimeout(() =>
this.hide(shape), data.timeout || 6000);
this.transitionTimeout = setTimeout(() =>
this.$snackbar.addClass('shown'), 30);
setTimeout(() =>
shape.classList.add('shown'), 30);
}
/**
@ -48,52 +78,41 @@ export default class Controller extends Component {
* @param {Object} data The message data
*/
showError(data) {
data.shapeType = 'error';
this.show(data);
}
/**
* Shows a success.
*
* @param {Object} data The message data
*/
showSuccess(data) {
data.shapeType = 'success';
this.show(data);
this.$snackbar.addClass('error');
}
/**
* Hides the snackbar.
* @param {Object} shape Snackbar element
*/
hide() {
if (!this.shown) return;
clearTimeout(this.timeoutId);
this.shown = false;
this.hideTimeout = setTimeout(() => this.onTransitionEnd(), 250);
this.transitionTimeout =
setTimeout(() => this.$snackbar.removeClass('shown'), 30);
}
onTransitionEnd() {
this.$snackbar.removeClass('error');
this.textNode.textContent = '';
this.button.textContent = '';
this.actionHandler = null;
hide(shape) {
setTimeout(() => shape.classList.remove('shown'), 30);
setTimeout(() => shape.remove(), 250);
}
onSnackbarClick(event) {
this.event = event;
}
onButtonClick() {
if (this.actionHandler)
onButtonClick(shape) {
if (this.actionHandler) {
this.actionHandler();
else
this.hide();
}
clearTimeouts() {
clearTimeout(this.timeoutId);
clearTimeout(this.hideTimeout);
clearTimeout(this.transitionTimeout);
this.timeoutId = null;
this.hideTimeout = null;
this.transitionTimeout = null;
}
$onDestroy() {
this.clearTimeouts();
} else {
this.hide(shape);
}
}
}
Controller.$inject = ['$element', '$translate'];

View File

@ -1,38 +1,50 @@
@import "colors";
vn-snackbar > div {
box-sizing: border-box;
background-color: #333;
color: white;
vn-snackbar #shapes {
position: fixed;
bottom: 0;
left: 50%;
right: 15px;
width: 20em;
margin-left: -10em;
padding: 1em;
border-top-left-radius: .2em;
border-top-right-radius: .2em;
transform: translateY(10em);
transition: transform 300ms ease-in-out;
max-height: 20.625em;
z-index: 100;
}
vn-snackbar .shape {
box-sizing: border-box;
background-color: rgba(1, 1, 1, 0.8);
color: white;
padding: 1em;
border-radius: .2em;
box-shadow: 0 0 .4em rgba(1,1,1,.4);
margin-bottom: 15px;
transform: translateX(20em);
transition: transform 300ms ease-in-out;
&.text {
text-align: center
}
&.shown {
transform: translateY(0);
transform: translateX(0);
}
&.notice {
background-color: #1e88e5;
&.success {
background-color: rgba(163, 209, 49, 0.8);
color: #445911;
& > button {
color: rgba(1, 1, 1, 0.6);
}
}
&.error {
background-color: #c62828;
background-color: rgba(198, 40, 40, 0.8);
& > button {
color: rgba(1, 1, 1, 0.6);
}
}
& > button {
cursor: pointer;
float: right;

View File

@ -177,7 +177,7 @@ export default class Watcher extends Component {
* Notifies the user that the data has been saved.
*/
notifySaved() {
this.vnApp.showMessage(this._.instant('Data saved!'));
this.vnApp.showSuccess(this._.instant('Data saved!'));
}
writeData(json, resolve) {

View File

@ -11,19 +11,28 @@ export default class App {
this.loaderStatus = 0;
this.loading = false;
}
showMessage(message) {
if (this.snackbar)
this.snackbar.show({message: message});
}
showSuccess(message) {
if (this.snackbar)
this.snackbar.showSuccess({message: message});
}
showError(message) {
if (this.snackbar)
this.snackbar.showError({message: message});
}
pushLoader() {
this.loaderStatus++;
if (this.loaderStatus === 1)
this.loading = true;
}
popLoader() {
this.loaderStatus--;
if (this.loaderStatus === 0)

View File

@ -3,6 +3,7 @@
.icon-volume:before { content: '\e801'; } /* '' */
.icon-barcode:before { content: '\e802'; } /* '' */
.icon-bucket:before { content: '\e803'; } /* '' */
.icon-reserva:before { content: '\e804'; } /* '' */
.icon-frozen:before { content: '\e808'; } /* '' */
.icon-disabled:before { content: '\e80b'; } /* '' */
.icon-invoices:before { content: '\e80c'; } /* '' */

View File

@ -44,7 +44,7 @@ class Controller {
return true;
}, res => {
if (res.data.error.message === 'NO_AGENCY_AVAILABLE')
this.vnApp.showError(
this.vnApp.showSuccess(
this.$translate.instant(`There's no available agency for this landing date`)
);
});

View File

@ -188,11 +188,9 @@ Nightmare.action('waitForSnackbarReset', function(done) {
});
Nightmare.action('waitForSnackbar', function(done) {
this.wait(500)
.waitForInnerText('vn-snackbar .text')
.then(value => {
this.waitForSnackbarReset()
.then(() => done(null, value));
this.wait(500).waitForShapes('vn-snackbar .shape .text')
.then(shapes => {
done(null, shapes);
});
});
@ -202,3 +200,17 @@ Nightmare.action('waitForURL', function(hashURL, done) {
}, hashURL)
.then(done);
});
Nightmare.action('waitForShapes', function(selector, done) {
this.wait(selector)
.evaluate_now(selector => {
let shapes = document.querySelectorAll(selector);
let shapesList = [];
for (let shape of shapes) {
shapesList.push(shape.innerText);
}
return shapesList;
}, done, selector);
});

View File

@ -67,7 +67,7 @@ describe('Client', () => {
.click(selectors.createClientView.createButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Some fields are invalid');
expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
});
});
@ -81,7 +81,7 @@ describe('Client', () => {
.click(selectors.createClientView.createButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Some fields are invalid');
expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
});
});
@ -94,7 +94,7 @@ describe('Client', () => {
.click(selectors.createClientView.createButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Some fields are invalid');
expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
});
});
@ -105,7 +105,7 @@ describe('Client', () => {
.click(selectors.createClientView.createButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -66,7 +66,7 @@ describe('Client', () => {
.click(selectors.clientBasicData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -109,7 +109,7 @@ describe('Client', () => {
.click(selectors.clientFiscalData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});
@ -118,7 +118,7 @@ describe('Client', () => {
.waitToClick(selectors.clientFiscalData.acceptPropagationButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Equivalent tax spreaded');
expect(result).toEqual(jasmine.arrayContaining(['Equivalent tax spreaded']));
});
});

View File

@ -58,7 +58,7 @@ describe('Client', () => {
.waitToClick(selectors.clientPayMethod.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('requires an IBAN');
expect(result).toEqual(jasmine.arrayContaining(['requires an IBAN']));
});
});
@ -69,7 +69,7 @@ describe('Client', () => {
.waitToClick(selectors.clientPayMethod.saveButton)
.waitForSnackbar()
.then(result => {
expect((result === 'Notification sent!' || result === 'Data saved!')).toBeTruthy();
expect(result).toEqual(jasmine.arrayContaining(['Data saved!', 'Notification sent!']));
});
});

View File

@ -90,7 +90,7 @@ describe('Client', () => {
.waitToClick(selectors.clientFiscalData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Some fields are invalid');
expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
});
});
@ -102,7 +102,7 @@ describe('Client', () => {
.click(selectors.clientAddresses.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
});
});
@ -143,7 +143,7 @@ describe('Client', () => {
.waitToClick(selectors.clientAddresses.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('The default consignee can not be unchecked');
expect(result).toEqual(jasmine.arrayContaining(['The default consignee can not be unchecked']));
});
});
});

View File

@ -65,7 +65,7 @@ describe('Client', () => {
.waitToClick(selectors.clientAddresses.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('type cannot be blank');
expect(result).toEqual(jasmine.arrayContaining(['type cannot be blank']));
});
});
@ -77,7 +77,7 @@ describe('Client', () => {
.waitToClick(selectors.clientAddresses.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Some fields are invalid');
expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
});
});
@ -91,7 +91,7 @@ describe('Client', () => {
.waitToClick(selectors.clientAddresses.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});
});

View File

@ -54,7 +54,7 @@ describe('Client', () => {
.waitToClick(selectors.clientWebAccess.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain(`Data saved!`);
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -62,7 +62,7 @@ describe('Client', () => {
.click(selectors.clientNotes.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -63,7 +63,7 @@ describe('Client', () => {
.click(selectors.clientCredit.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -63,7 +63,7 @@ describe('Client', () => {
.click(selectors.clientGreuge.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Some fields are invalid');
expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
});
});
@ -74,7 +74,7 @@ describe('Client', () => {
.click(selectors.clientGreuge.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -77,7 +77,7 @@ describe('Client', () => {
.click(selectors.clientFiscalData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});
@ -164,7 +164,7 @@ describe('Client', () => {
.waitToClick(selectors.clientFiscalData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});
@ -190,7 +190,7 @@ describe('Client', () => {
.click(selectors.clientFiscalData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});
@ -353,7 +353,7 @@ describe('Client', () => {
.waitToClick(selectors.clientFiscalData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});
@ -379,7 +379,7 @@ describe('Client', () => {
.click(selectors.clientFiscalData.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -61,7 +61,7 @@ describe('Item', () => {
.click(selectors.itemBasicData.submitBasicDataButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -55,7 +55,7 @@ describe('Item', () => {
.click(selectors.itemTax.submitTaxButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -56,7 +56,7 @@ describe('Item', () => {
.click(selectors.itemTags.submitItemTagsButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -54,7 +54,7 @@ describe('Item', () => {
.click(selectors.itemNiches.submitNichesButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -54,7 +54,7 @@ describe('Item', () => {
.waitToClick(selectors.itemBotanical.submitBotanicalButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});
@ -98,7 +98,7 @@ describe('Item', () => {
.waitToClick(selectors.itemBotanical.submitBotanicalButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -53,7 +53,7 @@ describe('Item', () => {
.waitToClick(selectors.itemBarcodes.submitBarcodesButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -73,7 +73,7 @@ describe('Item', () => {
.click(selectors.itemCreateView.createButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -55,7 +55,7 @@ describe('Ticket', () => {
.click(selectors.ticketNotes.submitNotesButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});

View File

@ -55,7 +55,7 @@
// .click(selectors.ticketPackages.savePackagesButton)
// .waitForSnackbar()
// .then(result => {
// expect(result).toContain('Some fields are invalid');
// expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
// });
// });
@ -65,7 +65,7 @@
// .click(selectors.ticketPackages.savePackagesButton)
// .waitForSnackbar()
// .then(result => {
// expect(result).toContain('Some fields are invalid');
// expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
// });
// });
@ -76,7 +76,7 @@
// .click(selectors.ticketPackages.savePackagesButton)
// .waitForSnackbar()
// .then(result => {
// expect(result).toContain('Some fields are invalid');
// expect(result).toEqual(jasmine.arrayContaining(['Some fields are invalid']));
// });
// });
@ -88,7 +88,7 @@
// .click(selectors.ticketPackages.savePackagesButton)
// .waitForSnackbar()
// .then(result => {
// expect(result).toContain('Package cannot be blank');
// expect(result).toEqual(jasmine.arrayContaining(['Package cannot be blank']));
// });
// });
@ -100,7 +100,7 @@
// .click(selectors.ticketPackages.savePackagesButton)
// .waitForSnackbar()
// .then(result => {
// expect(result).toContain('Data saved!');
// expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
// });
// });

View File

@ -61,7 +61,7 @@ describe('Ticket', () => {
.click(selectors.createStateView.saveStateButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('No changes to save');
expect(result).toEqual(jasmine.arrayContaining(['No changes to save']));
});
});
@ -73,7 +73,7 @@ describe('Ticket', () => {
.click(selectors.createStateView.saveStateButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});
@ -94,7 +94,7 @@ describe('Ticket', () => {
.click(selectors.createStateView.saveStateButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
expect(result).toEqual(jasmine.arrayContaining(['Data saved!']));
});
});
});