Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 1773-1774-travel_summary
gitea/salix/1773-1774-travel_summary This commit looks good Details

This commit is contained in:
Bernat 2019-10-24 12:49:23 +02:00
commit afd7c5684a
137 changed files with 2603 additions and 2299 deletions

View File

@ -471,7 +471,7 @@ INSERT INTO `vn`.`ticket`(`id`, `priority`, `agencyModeFk`,`warehouseFk`,`routeF
(11, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 102, 'NY roofs', 122, NULL, 0, 3, CURDATE()),
(12, 1, 1, 1, 1, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 1, CURDATE()),
(13, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 103, 'Phone Box', 123, NULL, 0, 3, CURDATE()),
(14, 1, 2, 1, NULL, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 104, 'Malibu Point', 4, NULL, 0, 9, CURDATE()),
(14, 1, 2, 1, NULL, CURDATE(), CURDATE(), 104, 'Malibu Point', 4, NULL, 0, 9, CURDATE()),
(15, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 105, 'Plastic Cell', 125, NULL, 0, 3, CURDATE()),
(16, 1, 7, 1, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()),
(17, 1, 7, 2, 6, CURDATE(), DATE_ADD(CURDATE(), INTERVAL + 1 DAY), 106, 'Many Places', 126, NULL, 0, 3, CURDATE()),

View File

@ -61,7 +61,7 @@ export default {
fiscalDataButton: 'vn-left-menu a[ui-sref="client.card.fiscalData"]',
socialNameInput: `vn-textfield input[name="socialName"]`,
fiscalIdInput: `vn-textfield input[name="fi"]`,
equalizationTaxCheckbox: 'vn-check[label="Is equalizated"]',
equalizationTaxCheckbox: 'vn-check[ng-model="$ctrl.client.isEqualizated"]',
acceptPropagationButton: 'vn-client-fiscal-data > vn-confirm button[response=ACCEPT]',
addressInput: `vn-textfield input[name="street"]`,
postcodeInput: `vn-textfield input[name="postcode"]`,
@ -136,7 +136,7 @@ export default {
addCreditFloatButton: `vn-float-button`,
creditInput: `vn-input-number input[name="credit"]`,
saveButton: `button[type=submit]`,
firstCreditText: 'vn-client-credit-index vn-card > div vn-table vn-tbody > vn-tr'
firstCreditText: 'vn-client-credit-index vn-card vn-table vn-tbody > vn-tr'
},
clientGreuge: {
addGreugeFloatButton: `vn-float-button`,
@ -144,13 +144,13 @@ export default {
descriptionInput: `vn-textfield input[name="description"]`,
typeAutocomplete: 'vn-autocomplete[ng-model="$ctrl.greuge.greugeTypeFk"]',
saveButton: `button[type=submit]`,
firstGreugeText: 'vn-client-greuge-index vn-card > div vn-table vn-tbody > vn-tr'
firstGreugeText: 'vn-client-greuge-index vn-card vn-table vn-tbody > vn-tr'
},
clientMandate: {
firstMandateText: 'vn-client-mandate vn-card > div vn-table vn-tbody > vn-tr'
firstMandateText: 'vn-client-mandate vn-card vn-table vn-tbody > vn-tr'
},
clientInvoices: {
firstInvoiceText: 'vn-client-invoice vn-card > div vn-table vn-tbody > vn-tr'
firstInvoiceText: 'vn-client-invoice vn-card vn-table vn-tbody > vn-tr'
},
clientLog: {
logButton: 'vn-left-menu a[ui-sref="client.card.log"]',
@ -307,7 +307,7 @@ export default {
fifthLineCreatedProperty: 'vn-item-log > vn-log vn-tbody > vn-tr:nth-child(5) > vn-td > vn-one:nth-child(3) > div span:nth-child(3)',
},
ticketSummary: {
header: 'vn-ticket-summary > vn-card > div > h5',
header: 'vn-ticket-summary > vn-card > h5',
state: 'vn-ticket-summary vn-label-value[label="State"] > section > span',
route: 'vn-ticket-summary vn-label-value[label="Route"] > section > a',
total: 'vn-ticket-summary vn-one.taxes > p:nth-child(3) > strong',
@ -319,14 +319,14 @@ export default {
popoverDiaryButton: '.vn-popover.shown vn-item-descriptor vn-icon[icon="icon-transaction"]',
firstSaleQuantity: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3)',
firstSaleDiscount: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6)',
invoiceOutRef: 'vn-ticket-summary > vn-card > div > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(6) > section > span',
invoiceOutRef: 'vn-ticket-summary > vn-card > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(6) > section > span',
setOk: 'vn-ticket-summary vn-button[label="SET OK"] > button'
},
ticketsIndex: {
openAdvancedSearchButton: 'vn-ticket-index vn-searchbar .append vn-icon[icon="arrow_drop_down"]',
advancedSearchInvoiceOut: 'vn-ticket-search-panel vn-textfield[ng-model="filter.refFk"] input',
newTicketButton: 'vn-ticket-index > a',
searchResult: 'vn-ticket-index vn-card > div > vn-table > div > vn-tbody > a.vn-tr',
searchResult: 'vn-ticket-index vn-card > vn-table > div > vn-tbody > a.vn-tr',
searchWeeklyResult: 'vn-ticket-weekly-index vn-table vn-tbody > vn-tr',
searchResultDate: 'vn-ticket-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(5)',
searchTicketInput: `vn-ticket-index vn-textfield input`,
@ -403,7 +403,7 @@ export default {
saleDescriptorPopoverSummaryButton: '.vn-popover.shown vn-item-descriptor a[ui-sref="item.card.summary({id: $ctrl.item.id})"]',
descriptorItemDiaryButton: 'vn-item-descriptor .quicklinks.ng-scope > vn-horizontal > a > vn-icon > i',
newItemFromCatalogButton: 'vn-ticket-sale vn-float-button[icon="add"]',
newItemButton: 'vn-ticket-sale > vn-vertical > vn-card > div > vn-vertical > vn-one > vn-icon-button > button > vn-icon > i',
newItemButton: 'vn-ticket-sale > vn-vertical > vn-card > vn-vertical > vn-one > vn-icon-button > button > vn-icon > i',
moreMenu: 'vn-ticket-sale vn-tool-bar > vn-button-menu[vn-id="more-button"] > div > button',
moreMenuCreateClaim: '.vn-popover.shown .vn-drop-down li[name="Add claim"]',
moreMenuReserve: '.vn-popover.shown .vn-drop-down li[name="Mark as reserved"]',
@ -443,7 +443,7 @@ export default {
secondSaleQuantity: 'vn-ticket-sale vn-table vn-tr:nth-child(2) vn-input-number input',
secondSaleConceptCell: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(2) > vn-td-editable:nth-child(6)',
secondSaleConceptInput: 'vn-ticket-sale vn-table vn-tr:nth-child(2) > vn-td-editable.ng-isolate-scope.selected vn-textfield input',
totalImport: 'vn-ticket-sale > vn-vertical > vn-card > div > vn-vertical > vn-horizontal > vn-one > p:nth-child(3) > strong',
totalImport: 'vn-ticket-sale > vn-vertical > vn-card > vn-vertical > vn-horizontal > vn-one > p:nth-child(3) > strong',
selectAllSalesCheckbox: 'vn-ticket-sale vn-thead vn-check',
secondSaleCheckbox: 'vn-ticket-sale vn-tr:nth-child(2) vn-check[ng-model="sale.checked"]',
thirdSaleCheckbox: 'vn-ticket-sale vn-tr:nth-child(3) vn-check[ng-model="sale.checked"]',
@ -472,7 +472,7 @@ export default {
zoneAutocomplete: 'vn-autocomplete[ng-model="$ctrl.zoneId"]',
nextStepButton: 'vn-step-control .buttons > section:last-child vn-button',
finalizeButton: 'vn-step-control .buttons > section:last-child button[type=submit]',
stepTwoTotalPriceDif: 'vn-ticket-basic-data-step-two > form > vn-card > div > vn-horizontal > table > tfoot > tr > td:nth-child(4)',
stepTwoTotalPriceDif: 'vn-ticket-basic-data-step-two > form > vn-card > vn-horizontal > table > tfoot > tr > td:nth-child(4)',
chargesReasonAutocomplete: 'vn-autocomplete[ng-model="$ctrl.ticket.option"]',
},
ticketComponents: {
@ -481,8 +481,8 @@ export default {
ticketRequests: {
addRequestButton: 'vn-ticket-request-index > a > vn-float-button > button',
request: 'vn-ticket-request-index vn-table vn-tr',
descriptionInput: 'vn-ticket-request-create > form > div > vn-card > div > vn-horizontal:nth-child(1) > vn-textfield input',
atenderAutocomplete: 'vn-ticket-request-create vn-autocomplete[ng-model="$ctrl.ticketRequest.atenderFk"]',
descriptionInput: 'vn-ticket-request-create > form > div > vn-card > vn-horizontal:nth-child(1) > vn-textfield input',
atenderAutocomplete: 'vn-ticket-request-create vn-autocomplete[ng-model="$ctrl.ticketRequest.attenderFk"]',
quantityInput: 'vn-ticket-request-create vn-input-number input[name=quantity]',
priceInput: 'vn-ticket-request-create vn-input-number input[name=price]',
firstRemoveRequestButton: 'vn-ticket-request-index vn-icon[icon="delete"]:nth-child(1)',
@ -505,7 +505,7 @@ export default {
firstVatTypeAutocomplete: 'vn-ticket-service vn-autocomplete[label="Tax class"]',
fistDeleteServiceButton: 'vn-ticket-service form vn-horizontal:nth-child(1) vn-icon-button[icon="delete"]',
newDescriptionInput: 'vn-ticket-service > vn-dialog vn-textfield[ng-model="$ctrl.newServiceType.name"] input',
serviceLine: 'vn-ticket-service > form > vn-card > div > vn-one:nth-child(2) > vn-horizontal',
serviceLine: 'vn-ticket-service > form > vn-card > vn-one:nth-child(2) > vn-horizontal',
saveServiceButton: `button[type=submit]`,
saveDescriptionButton: 'vn-ticket-service > vn-dialog[vn-id="createServiceTypeDialog"] > div > form > div.buttons > tpl-buttons > button'
},
@ -517,7 +517,7 @@ export default {
},
claimsIndex: {
searchClaimInput: `vn-claim-index vn-textfield input`,
searchResult: 'vn-claim-index vn-card > div > vn-table > div > vn-tbody > a',
searchResult: 'vn-claim-index vn-card > vn-table > div > vn-tbody > a',
searchButton: 'vn-claim-index vn-searchbar vn-icon[icon="search"]'
},
claimDescriptor: {
@ -526,7 +526,7 @@ export default {
acceptDeleteClaim: 'vn-claim-descriptor > vn-confirm[vn-id="confirm-delete-claim"] button[response="ACCEPT"]'
},
claimSummary: {
header: 'vn-claim-summary > vn-card > div > h5',
header: 'vn-claim-summary > vn-card > h5',
state: 'vn-claim-summary vn-label-value[label="State"] > section > span',
observation: 'vn-claim-summary vn-textarea[ng-model="$ctrl.summary.claim.observation"] textarea',
firstSaleItemId: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(4) vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(1) > span',
@ -534,8 +534,8 @@ export default {
itemDescriptorPopover: '.vn-popover.shown vn-item-descriptor',
itemDescriptorPopoverItemDiaryButton: '.vn-popover.shown vn-item-descriptor a[href="#!/item/2/diary"]',
firstDevelopmentWorker: 'vn-claim-summary vn-horizontal > vn-auto:nth-child(5) vn-table > div > vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > span',
firstDevelopmentWorkerGoToClientButton: '.vn-popover.shown vn-worker-descriptor div.quicklinks > a[href="#!/client/21/summary"]',
firstActionTicketId: 'vn-claim-summary > vn-card > div > vn-horizontal > vn-auto:nth-child(6) vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span',
firstDevelopmentWorkerGoToClientButton: '.vn-popover.shown vn-worker-descriptor vn-quick-links > a[href="#!/client/21/summary"]',
firstActionTicketId: 'vn-claim-summary > vn-card > vn-horizontal > vn-auto:nth-child(6) vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span',
firstActionTicketDescriptor: '.vn-popover.shown vn-ticket-descriptor'
},
claimBasicData: {
@ -545,19 +545,19 @@ export default {
saveButton: `button[type=submit]`
},
claimDetail: {
secondItemDiscount: 'vn-claim-detail > vn-vertical > vn-card > div > vn-vertical > vn-table > div > vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(6) > span',
secondItemDiscount: 'vn-claim-detail > vn-vertical > vn-card > vn-vertical > vn-table > div > vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(6) > span',
discountInput: '.vn-popover.shown vn-input-number[ng-model="$ctrl.newDiscount"] input',
discoutPopoverMana: '.vn-popover.shown .content > div > vn-horizontal > h5',
addItemButton: 'vn-claim-detail a vn-float-button',
firstClaimableSaleFromTicket: 'vn-claim-detail > vn-dialog vn-tbody > vn-tr',
claimDetailLine: 'vn-claim-detail > vn-vertical > vn-card > div > vn-vertical > vn-table > div > vn-tbody > vn-tr',
claimDetailLine: 'vn-claim-detail > vn-vertical > vn-card > vn-vertical > vn-table > div > vn-tbody > vn-tr',
firstItemQuantityInput: 'vn-claim-detail vn-tr:nth-child(1) vn-input-number[ng-model="saleClaimed.quantity"] input',
totalClaimed: 'vn-claim-detail > vn-vertical > vn-card > div > vn-vertical > vn-horizontal > div > vn-label-value:nth-child(2) > section > span',
secondItemDeleteButton: 'vn-claim-detail > vn-vertical > vn-card > div > vn-vertical > vn-table > div > vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(8) > vn-icon-button > button > vn-icon > i'
totalClaimed: 'vn-claim-detail > vn-vertical > vn-card > vn-vertical > vn-horizontal > div > vn-label-value:nth-child(2) > section > span',
secondItemDeleteButton: 'vn-claim-detail > vn-vertical > vn-card > vn-vertical > vn-table > div > vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(8) > vn-icon-button > button > vn-icon > i'
},
claimDevelopment: {
addDevelopmentButton: 'vn-claim-development > vn-vertical > vn-card > div > vn-vertical > vn-one > vn-icon-button > button > vn-icon',
firstDeleteDevelopmentButton: 'vn-claim-development > vn-vertical > vn-card > div > vn-vertical > form > vn-horizontal:nth-child(2) > vn-icon-button > button > vn-icon',
addDevelopmentButton: 'vn-claim-development > vn-vertical > vn-card > vn-vertical > vn-one > vn-icon-button > button > vn-icon',
firstDeleteDevelopmentButton: 'vn-claim-development > vn-vertical > vn-card > vn-vertical > form > vn-horizontal:nth-child(2) > vn-icon-button > button > vn-icon',
firstClaimReasonAutocomplete: 'vn-claim-development vn-horizontal:nth-child(1) vn-autocomplete[ng-model="claimDevelopment.claimReasonFk"]',
firstClaimResultAutocomplete: 'vn-claim-development vn-horizontal:nth-child(1) vn-autocomplete[ng-model="claimDevelopment.claimResultFk"]',
firstClaimResponsibleAutocomplete: 'vn-claim-development vn-horizontal:nth-child(1) vn-autocomplete[ng-model="claimDevelopment.claimResponsibleFk"]',
@ -580,7 +580,7 @@ export default {
isPaidWithManaCheckbox: 'vn-check[ng-model="$ctrl.claim.isChargedToMana"]'
},
ordersIndex: {
searchResult: 'vn-order-index vn-card > div > vn-table > div > vn-tbody > a.vn-tr',
searchResult: 'vn-order-index vn-card > vn-table > div > vn-tbody > a.vn-tr',
searchResultDate: 'vn-order-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(4)',
searchResultAddress: 'vn-order-index vn-table vn-tbody > a:nth-child(1) > vn-td:nth-child(6)',
searchOrderInput: `vn-order-index vn-textfield input`,
@ -641,7 +641,7 @@ export default {
volume: 'vn-route-descriptor vn-label-value[label="Volume"] > section > span'
},
routeSummary: {
routeId: 'vn-route-summary > vn-card > div > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(1) > section > span'
routeId: 'vn-route-summary > vn-card > vn-horizontal > vn-one:nth-child(1) > vn-label-value:nth-child(1) > section > span'
},
routeBasicData: {
workerAutoComplete: 'vn-route-basic-data vn-autocomplete[ng-model="$ctrl.route.workerFk"]',
@ -671,57 +671,58 @@ export default {
},
workerTimeControl: {
timeDialogInput: '.vn-dialog.shown [ng-model="$ctrl.newTime"]',
mondayAddTimeButton: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(1) > vn-icon-button > button > vn-icon',
tuesdayAddTimeButton: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(2) > vn-icon-button > button > vn-icon',
wednesdayAddTimeButton: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(3) > vn-icon-button > button > vn-icon',
thursdayAddTimeButton: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(4) > vn-icon-button > button > vn-icon',
fridayAddTimeButton: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(5) > vn-icon-button > button > vn-icon',
saturdayAddTimeButton: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(6) > vn-icon-button > button > vn-icon',
sundayAddTimeButton: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(7) > vn-icon-button > button > vn-icon',
mondayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(1) > vn-icon-button',
tuesdayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(2) > vn-icon-button',
wednesdayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(3) > vn-icon-button',
thursdayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(4) > vn-icon-button',
fridayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(5) > vn-icon-button',
saturdayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(6) > vn-icon-button',
sundayAddTimeButton: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(2) > vn-td:nth-child(7) > vn-icon-button',
confirmButton: 'vn-worker-time-control > vn-dialog > div > form > div.buttons > tpl-buttons > button',
firstEntryOfMonday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(1) > span',
firstEntryOfTuesday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(1) > span',
firstEntryOfWednesday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(1) > span',
firstEntryOfThursday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(1) > span',
firstEntryOfFriday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(1) > span',
firstEntryOfSaturday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(1) > span',
firstEntryOfSunday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(1) > span',
secondEntryOfMonday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(2) > span',
secondEntryOfTuesday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(2) > span',
secondEntryOfWednesday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(2) > span',
secondEntryOfThursday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(2) > span',
secondEntryOfFriday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(2) > span',
secondEntryOfSaturday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(2) > span',
secondEntryOfSunday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(2) > span',
thirdEntryOfMonday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(3) > span',
thirdEntryOfTuesday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(3) > span',
thirdEntryOfWednesday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(3) > span',
thirdEntryOfThursday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(3) > span',
thirdEntryOfFriday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(3) > span',
thirdEntryOfSaturday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(3) > span',
thirdEntryOfSunday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(3) > span',
fourthEntryOfMonday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(4) > span',
fourthEntryOfTuesday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(4) > span',
fourthEntryOfWednesday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(4) > span',
fourthEntryOfThursday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(4) > span',
fourthEntryOfFriday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(4) > span',
fourthEntryOfSaturday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(4) > span',
fourthEntryOfSunday: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(4) > span',
mondayWorkedHours: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(1)',
tuesdayWorkedHours: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(2)',
wednesdayWorkedHours: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(3)',
thursdayWorkedHours: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(4)',
fridayWorkedHours: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(5)',
saturdayWorkedHours: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(6)',
sundayWorkedHours: 'vn-worker-time-control > div > vn-card > div > vn-horizontal > vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(7)',
weekWorkedHours: 'vn-worker-time-control > div > vn-side-menu > div > vn-vertical > vn-vertical > vn-label-value > section > span',
nextMonthButton: 'vn-worker-time-control > div > vn-side-menu > div > vn-calendar > div > vn-horizontal > vn-auto:nth-child(3) > vn-icon',
firstEntryOfMonday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(1) > span',
firstEntryOfTuesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(1) > span',
firstEntryOfWednesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(1) > span',
firstEntryOfThursday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(1) > span',
firstEntryOfFriday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(1) > span',
firstEntryOfSaturday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(1) > span',
firstEntryOfSunday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(1) > span',
secondEntryOfMonday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(2) > span',
secondEntryOfTuesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(2) > span',
secondEntryOfWednesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(2) > span',
secondEntryOfThursday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(2) > span',
secondEntryOfFriday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(2) > span',
secondEntryOfSaturday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(2) > span',
secondEntryOfSunday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(2) > span',
thirdEntryOfMonday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(3) > span',
thirdEntryOfTuesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(3) > span',
thirdEntryOfWednesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(3) > span',
thirdEntryOfThursday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(3) > span',
thirdEntryOfFriday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(3) > span',
thirdEntryOfSaturday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(3) > span',
thirdEntryOfSunday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(3) > span',
fourthEntryOfMonday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(1) > section:nth-child(4) > span',
fourthEntryOfTuesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > section:nth-child(4) > span',
fourthEntryOfWednesday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(3) > section:nth-child(4) > span',
fourthEntryOfThursday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(4) > section:nth-child(4) > span',
fourthEntryOfFriday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(5) > section:nth-child(4) > span',
fourthEntryOfSaturday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(6) > section:nth-child(4) > span',
fourthEntryOfSunday: 'vn-worker-time-control vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(7) > section:nth-child(4) > span',
mondayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(1)',
tuesdayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(2)',
wednesdayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(3)',
thursdayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(4)',
fridayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(5)',
saturdayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(6)',
sundayWorkedHours: 'vn-worker-time-control vn-table > div > vn-tfoot > vn-tr:nth-child(1) > vn-td:nth-child(7)',
weekWorkedHours: 'vn-worker-time-control vn-side-menu vn-label-value > section > span',
nextMonthButton: 'vn-worker-time-control vn-side-menu vn-calendar vn-button[icon=keyboard_arrow_right]',
secondWeekDay: 'vn-worker-time-control vn-side-menu vn-calendar .day:nth-child(8) > .day-number',
navigateBackToIndex: 'vn-worker-descriptor vn-icon[icon="chevron_left"]'
},
invoiceOutIndex: {
searchInvoiceOutInput: `vn-invoice-out-index vn-textfield input`,
searchButton: 'vn-invoice-out-index vn-searchbar vn-icon[icon="search"]',
searchResult: 'vn-invoice-out-index vn-card > div > vn-table > div > vn-tbody > a.vn-tr',
searchResult: 'vn-invoice-out-index vn-card > vn-table > div > vn-tbody > a.vn-tr',
},
invoiceOutDescriptor: {
moreMenu: 'vn-invoice-out-descriptor vn-icon-menu[icon=more_vert]',
@ -732,6 +733,6 @@ export default {
acceptBookingButton: 'vn-invoice-out-descriptor > vn-confirm[vn-id="bookConfirmation"] button[response="ACCEPT"]'
},
invoiceOutSummary: {
bookedLabel: 'vn-invoice-out-summary > vn-card > div > vn-horizontal > vn-one > vn-label-value:nth-child(4) > section > span'
bookedLabel: 'vn-invoice-out-summary > vn-card > vn-horizontal > vn-one > vn-label-value:nth-child(4) > section > span'
}
};

View File

@ -286,11 +286,11 @@ describe('Worker time control path', () => {
});
});
describe('as salesBoss', () => {
describe('as hr', () => {
describe('on Saturday', () => {
beforeAll(() => {
nightmare
.loginAndModule('salesBoss', 'worker')
.loginAndModule('hr', 'worker')
.accessToSearchResult('HankPym')
.accessToSection('worker.card.timeControl');
});
@ -358,10 +358,11 @@ describe('Worker time control path', () => {
it(`should check Hank Pym doesn't have hours set on the next months first week`, async() => {
const wholeWeekHours = await nightmare
.waitToClick(selectors.workerTimeControl.nextMonthButton)
.waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '00:00 Hours')
.waitToClick(selectors.workerTimeControl.secondWeekDay)
.waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '00:00 h.')
.waitToGetProperty(selectors.workerTimeControl.weekWorkedHours, 'innerText');
expect(wholeWeekHours).toEqual('00:00 Hours');
expect(wholeWeekHours).toEqual('00:00 h.');
});
it(`should check he didn't scan in this week yet`, async() => {
@ -371,7 +372,7 @@ describe('Worker time control path', () => {
.accessToSection('worker.card.timeControl')
.waitToGetProperty(selectors.workerTimeControl.weekWorkedHours, 'innerText');
expect(wholeWeekHours).toEqual('00:00 Hours');
expect(wholeWeekHours).toEqual('00:00 h.');
});
});
});
@ -386,10 +387,10 @@ describe('Worker time control path', () => {
it('should Hank Pym check his hours are alright', async() => {
const wholeWeekHours = await nightmare
.waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '56:00 Hours')
.waitForTextInElement(selectors.workerTimeControl.weekWorkedHours, '56:00 h.')
.waitToGetProperty(selectors.workerTimeControl.weekWorkedHours, 'innerText');
expect(wholeWeekHours).toEqual('56:00 Hours');
expect(wholeWeekHours).toEqual('56:00 h.');
});
});
});

View File

@ -17,7 +17,7 @@ describe('Ticket Summary path', () => {
it(`should display details from the ticket and it's client on the top of the header`, async() => {
let result = await nightmare
.waitForSpinnerLoad()
.waitForTextInElement(selectors.ticketSummary.header, 'Bruce Banner')
.waitToGetProperty(selectors.ticketSummary.header, 'innerText');
expect(result).toContain(`Ticket #${ticketId}`);

View File

@ -48,5 +48,5 @@
vn-id="drop-down"
on-select="$ctrl.onDropDownSelect(item)"
on-data-ready="$ctrl.onDataReady()"
on-close-start="$ctrl.focus()">
on-close-start="$ctrl.onDropDownClose()">
</vn-drop-down>

View File

@ -209,6 +209,10 @@ export default class Autocomplete extends Field {
this.field = value;
}
onDropDownClose() {
setTimeout(() => this.focus());
}
onContainerKeyDown(event) {
if (event.defaultPrevented) return;
@ -224,13 +228,10 @@ export default class Autocomplete extends Field {
else
return;
}
event.preventDefault();
}
onContainerClick(event) {
if (event.defaultPrevented) return;
event.preventDefault();
this.showDropDown();
}

View File

@ -15,6 +15,5 @@
</button>
<vn-drop-down
vn-id="drop-down"
on-select="$ctrl.onDropDownSelect(item)"
ng-click="$ctrl.onDropDownClick($event)">
on-select="$ctrl.onDropDownSelect(item)">
</vn-drop-down>

View File

@ -44,15 +44,10 @@ export default class ButtonMenu extends Button {
onClick(event) {
if (this.disabled) return;
if (event.defaultPrevented) return;
event.preventDefault();
this.emit('open');
this.showDropDown();
}
onDropDownClick(event) {
event.preventDefault();
}
onDropDownSelect(item) {
const value = item[this.valueField];
this.field = value;

View File

@ -6,11 +6,8 @@ export default class Button extends FormInput {
constructor($element, $scope) {
super($element, $scope);
this.design = 'colored';
this.input = this.element.querySelector('button');
let element = this.element;
element.tabIndex = 0;
element.classList.add('vn-button');
this.initTabIndex();
this.classList.add('vn-button');
this.element.addEventListener('keyup', e => this.onKeyup(e));
this.element.addEventListener('click', e => this.onClick(e));
}
@ -21,16 +18,17 @@ export default class Button extends FormInput {
}
onKeyup(event) {
if (event.code == 'Space')
this.onClick(event);
if (event.defaultPrevented) return;
switch (event.code) {
case 'Space':
case 'Enter':
return this.element.click();
}
}
onClick(event) {
if (event.defaultPrevented) return;
// event.preventDefault();
// FIXME: Don't stop event propagation
if (this.disabled) event.stopImmediatePropagation();
if (this.disabled)
event.stopImmediatePropagation();
}
}
Button.$inject = ['$element', '$scope'];

View File

@ -1,82 +1,46 @@
<div>
<vn-horizontal class="header">
<vn-auto>
<vn-icon
icon="keyboard_arrow_left"
class="pointer"
ng-click="$ctrl.movePrevious($ctrl.skip)"
ng-show="$ctrl.displayControls"/>
</vn-icon>
</vn-auto>
<vn-one>
<div>
<span translate>{{$ctrl.defaultDate | date: 'MMMM'}}</span>
<span>{{$ctrl.defaultDate | date: 'yyyy'}}</span>
<div class="header">
<vn-button
icon="keyboard_arrow_left"
class="flat"
ng-click="$ctrl.movePrevious()"
translate-attr="::{title: 'Previous'}"
ng-if="$ctrl.displayControls"/>
</vn-button>
<div class="title">
<span translate>{{$ctrl.defaultDate | date: 'MMMM'}}</span>
<span ng-hide="::$ctrl.hideYear">{{$ctrl.defaultDate | date: 'yyyy'}}</span>
</div>
<vn-button
icon="keyboard_arrow_right"
class="flat"
ng-click="$ctrl.moveNext()"
translate-attr="::{title: 'Next'}"
ng-if="$ctrl.displayControls">
</vn-button>
</div>
<div class="weekdays">
<section
ng-repeat="day in ::$ctrl.weekDays"
translate-attr="::{title: day.name}"
ng-click="$ctrl.selectWeekDay(day.index)">
<span>{{::day.localeChar}}</span>
</section>
</div>
<div
class="days"
ng-class="{'hide-contiguous': $ctrl.hideContiguous}">
<section
ng-repeat="day in $ctrl.days"
class="day"
ng-class="::$ctrl.getDayClasses(day)"
vn-repeat-last
on-last="$ctrl.repeatLast()">
<div
class="day-number"
ng-click="$ctrl.select(day)">
{{::day | date: 'd'}}
</div>
</vn-one>
<vn-auto>
<vn-icon
icon="keyboard_arrow_right"
class="pointer"
ng-click="$ctrl.moveNext($ctrl.skip)"
ng-show="$ctrl.displayControls">
</vn-icon>
</vn-auto>
</vn-horizontal>
<vn-vertical class="body">
<vn-horizontal class="weekdays">
<section title="{{'Monday' | translate}}"
ng-click="$ctrl.selectAll(1)">
<span>L</span>
</section>
<section title="{{'Tuesday' | translate}}"
ng-click="$ctrl.selectAll(2)">
<span>M</span>
</section>
<section title="{{'Wednesday' | translate}}"
ng-click="$ctrl.selectAll(3)">
<span>X</span>
</section>
<section title="{{'Thursday' | translate}}"
ng-click="$ctrl.selectAll(4)">
<span>J</span>
</section>
<section title="{{'Friday' | translate}}"
ng-click="$ctrl.selectAll(5)">
<span>V</span>
</section>
<section title="{{'Saturday' | translate}}"
ng-click="$ctrl.selectAll(6)">
<span>S</span>
</section>
<section title="{{'Sunday' | translate}}"
ng-click="$ctrl.selectAll(0)">
<span>D</span>
</section>
</vn-horizontal>
<vn-horizontal class="days">
<section
ng-repeat="day in $ctrl.days"
class="day {{::$ctrl.getClass({$day: day.dated})}}"
ng-class="::{primary: day.events.length > 0 || $ctrl.hasEvents({$day: day.dated})}">
<div class="content">
<div class="day-number"
title="{{(day.eventName) | translate}}"
ng-style="$ctrl.renderStyle(day.style)"
ng-click="$ctrl.select($index)">
{{::day.dated | date: 'd'}}
</div>
<div ng-if="day.events" class="events">
<div ng-repeat="event in day.events" class="event"
title="{{(event.description || event.name) | translate}}">
<span class="chip ellipsize"
ng-style="::$ctrl.renderStyle(event.style)">
{{::event.name}}
</span>
</div>
</div>
</div>
</section>
</vn-horizontal>
</vn-vertical>
</section>
</div>
</div>

View File

@ -1,43 +1,26 @@
import ngModule from '../../module';
import Component from '../../lib/component';
import FormInput from '../form-input';
import './style.scss';
/**
* Flat calendar.
*
* @property {Array} data Array of events
* @property {Array} defaultDate Array of events
* @property {Function} hasEvents Determines if an events exists for a day
* @property {Function} getClass Class to apply to specific day
* @event selection Emitted when day or weekday is selected
* @event move Emitted when month changes
*/
export default class Calendar extends Component {
constructor($element, $scope) {
export default class Calendar extends FormInput {
constructor($element, $scope, vnWeekDays) {
super($element, $scope);
this.events = [];
this.weekDays = vnWeekDays.locales;
this.defaultDate = new Date();
this.displayControls = true;
this.disabled = false;
this.skip = 1;
this.window.addEventListener('resize', () => {
this.checkSize();
});
}
/**
* Resizes the calendar
* based on component height
*/
checkSize() {
const height = this.$element[0].clientHeight;
if (height < 530)
this.$element.addClass('small');
else
this.$element.removeClass('small');
}
/**
* Returns the initial date
* The initial date
*
* @return {Date} - Default date
*/
@ -45,11 +28,6 @@ export default class Calendar extends Component {
return this._defaultDate;
}
/**
* Sets a new initial date
*
* @param {Date} value - New default date
*/
set defaultDate(value) {
if (value) {
value = new Date(value);
@ -58,67 +36,10 @@ export default class Calendar extends Component {
}
this._defaultDate = value;
this.month = value.getMonth();
this.repaint();
}
/**
* Sets events
*
* @param {Array} value - Array of events
* @param {Date} event.dated - Day to add event
* @param {String} event.name - Tooltip description
* @param {String} event.className - ClassName style
* @param {Object} event.style - Style properties
*/
set data(value) {
if (!value) return;
this.events = [];
value.forEach(event => {
event.dated = new Date(event.dated);
event.dated.setHours(0, 0, 0, 0);
this.events.push(event);
});
if (this.defaultDate) {
this.repaint();
this.checkSize();
}
}
/**
* Gets current month date
*/
get currentMonth() {
return this.defaultDate;
}
/**
* Gets next month date
*
* @return {Date}
*/
get nextMonth() {
const newDate = new Date(this.currentMonth);
newDate.setMonth(this.currentMonth.getMonth() + 1);
return newDate;
}
/**
* Gets previous month date
*
* @return {Date}
*/
get previousMonth() {
const newDate = new Date(this.currentMonth);
newDate.setMonth(this.currentMonth.getMonth() - 1);
return newDate;
}
/**
* Returns first day of month from a given date
*
@ -126,185 +47,113 @@ export default class Calendar extends Component {
* @return {Integer}
*/
firstDay(date) {
const newDate = new Date(
return new Date(
date.getFullYear(),
date.getMonth(), 1);
return newDate;
date.getMonth(),
1
);
}
/**
* Returns last day of month from a given date
*
* @param {Date} date - Origin date
* @return {Integer}
* Repaints the calendar.
*/
lastDay(date) {
const newDate = new Date(
date.getFullYear(),
date.getMonth() + 1, 0);
return newDate;
}
repaint() {
const firstWeekday = this.firstDay(this.currentMonth).getDay();
const previousLastDay = this.lastDay(this.previousMonth).getDate();
const currentLastDay = this.lastDay(this.currentMonth).getDate();
const maxFields = 42; // Max field limit
const firstWeekday = this.firstDay(this.defaultDate).getDay() - 1;
let weekdayOffset = firstWeekday >= 0 ? firstWeekday : 6;
let weekdayOffset = firstWeekday > 0 ? firstWeekday : 7;
let dayPrevious = previousLastDay - (weekdayOffset - 2);
let dayCurrent = 1;
let dayNext = 1;
let dayIndex = new Date(this.defaultDate.getTime());
dayIndex.setDate(1 - weekdayOffset);
this.days = [];
for (let fieldIndex = 1; fieldIndex < maxFields; fieldIndex++) {
// Insert previous month days
if (fieldIndex < weekdayOffset) {
const dated = new Date(
this.previousMonth.getFullYear(),
this.previousMonth.getMonth(), dayPrevious);
this.insertDay(dated, 'gray');
dayPrevious++;
}
// Insert current month days
if (fieldIndex >= weekdayOffset && dayCurrent <= currentLastDay) {
const dated = new Date(
this.currentMonth.getFullYear(),
this.currentMonth.getMonth(), dayCurrent);
this.insertDay(dated);
dayCurrent++;
}
// Insert next month days
if (fieldIndex >= weekdayOffset && dayCurrent > currentLastDay) {
const dated = new Date(
this.nextMonth.getFullYear(),
this.nextMonth.getMonth(), dayNext);
this.insertDay(dated, 'gray');
dayNext++;
}
for (let i = 1; i <= 42; i++) {
this.days.push(new Date(dayIndex.getTime()));
dayIndex.setDate(dayIndex.getDate() + 1);
}
}
/**
* Inserts a date on an array of month days
* Gets CSS classes to apply to the specified day.
*
* @param {Date} dated - Date of month
* @param {String} className - Default class style
* @param {Date} day The day
* @return {Object} The CSS classes to apply
*/
insertDay(dated) {
let events = this.events.filter(event => {
return event.dated >= dated && event.dated <= dated;
});
getDayClasses(day) {
let wday = day.getDay();
let month = day.getMonth();
const params = {dated: dated, events: events /**/, style: {}};
const isSaturday = dated.getDay() === 6;
const isSunday = dated.getDay() === 0;
const isCurrentMonth = dated.getMonth() === this.currentMonth.getMonth();
const hasEvents = events.length > 0;
let classes = {
weekend: wday === 6 || wday === 0,
previous: month < this.month,
current: month == this.month,
next: month > this.month,
event: this.hasEvents({$day: day})
};
if (isCurrentMonth && isSunday && !hasEvents)
params.style = {color: '#999'};
let userClass = this.getClass({$day: day});
if (userClass) classes[userClass] = true;
if (isCurrentMonth && isSaturday && !hasEvents)
params.style = {color: '#999'};
if (!isCurrentMonth)
params.style = {opacity: '0.5'};
if (events.length > 0) {
const eventStyle = events[0].style;
const eventName = events[0].description || events[0].name;
if (eventStyle)
Object.assign(params.style, eventStyle);
if (eventName)
params.eventName = eventName;
}
this.days.push(params);
return classes;
}
/**
* Moves to next month(s)
*
* @param {Integer} skip - Months to skip at once
*/
moveNext(skip = 1) {
let next = this.defaultDate.getMonth() + skip;
this.defaultDate.setMonth(next);
this.repaint();
this.emit('moveNext');
moveNext() {
this.move(1);
}
/**
* Moves to previous month(s)
*
* @param {Integer} skip - Months to skip at once
*/
movePrevious(skip = 1) {
let previous = this.defaultDate.getMonth() - skip;
this.defaultDate.setMonth(previous);
this.repaint();
this.emit('movePrevious');
movePrevious() {
this.move(-1);
}
/**
* Day selection event
* Moves @direction months backwards/forwards.
*
* @param {Integer} index - Index from days array
* @param {Number} direction Negative to move backwards, positive forwards
*/
select(index) {
if (this.disabled) return;
let day = this.days[index].dated;
move(direction) {
let date = new Date(this.defaultDate.getTime());
date.setMonth(date.getMonth() + direction);
this.defaultDate = date;
this.repaint();
this.emit('move', {$date: date});
}
/*
* Day selection event
*/
select(day) {
if (!this.editable) return;
this.field = day;
this.emit('selection', {
$days: [day],
$type: 'day'
});
this.repaint();
}
/**
/*
* WeekDay selection event
*
* @param {Integer} weekday - weekday index
*/
selectAll(weekday) {
if (this.disabled) return;
selectWeekDay(weekday) {
if (!this.editable) return;
let days = [];
for (let i in this.days) {
const day = this.days[i].dated;
if (day.getDay() === weekday && day.getMonth() == this.defaultDate.getMonth())
for (let day of this.days) {
if (day.getDay() === weekday && day.getMonth() == this.month)
days.push(day);
}
this.field = days[0];
this.emit('selection', {
$days: days,
$type: 'weekday',
$weekday: weekday
});
}
renderStyle(style) {
const normalizedStyle = {};
if (style) {
const properties = Object.keys(style);
properties.forEach(attribute => {
const attrName = attribute.split(/(?=[A-Z])/).
join('-').toLowerCase();
normalizedStyle[attrName] = style[attribute];
});
}
return normalizedStyle;
this.repaint();
}
hasEvents() {
@ -314,24 +163,31 @@ export default class Calendar extends Component {
getClass() {
return '';
}
repeatLast() {
if (!this.formatDay) return;
let days = this.element.querySelectorAll('.days > .day');
for (let i = 0; i < days.length; i++) {
this.formatDay({
$day: this.days[i],
$element: days[i]
});
}
}
}
Calendar.$inject = ['$element', '$scope', 'vnWeekDays'];
Calendar.$inject = ['$element', '$scope'];
ngModule.component('vnCalendar', {
ngModule.vnComponent('vnCalendar', {
template: require('./index.html'),
controller: Calendar,
bindings: {
model: '<',
data: '<?',
defaultDate: '=?',
onSelection: '&?',
onMoveNext: '&?',
onMovePrevious: '&?',
hasEvents: '&?',
getClass: '&?',
formatDay: '&?',
displayControls: '<?',
disabled: '<?',
skip: '<?'
hideYear: '<?',
hideContiguous: '<?'
}
});

View File

@ -2,6 +2,10 @@ describe('Component vnCalendar', () => {
let controller;
let $element;
let date = new Date();
date.setHours(0, 0, 0, 0);
date.setDate(1);
beforeEach(angular.mock.module('vnCore', $translateProvider => {
$translateProvider.translations('en', {});
}));
@ -9,79 +13,55 @@ describe('Component vnCalendar', () => {
beforeEach(inject(($compile, $rootScope) => {
$element = $compile(`<vn-calendar></vn-calendar`)($rootScope);
controller = $element.controller('vnCalendar');
controller.defaultDate = new Date();
controller.defaultDate = date;
}));
afterEach(() => {
$element.remove();
});
describe('data() setter', () => {
it(`should set an array of events and convert string dates to string object, then call repaint() method`, () => {
spyOn(controller, 'repaint');
let currentDate = new Date().toString();
controller.data = [
{dated: currentDate, name: 'Event 1'},
{dated: currentDate, name: 'Event 2'},
];
expect(controller.events[0].dated instanceof Object).toBeTruthy();
expect(controller.repaint).toHaveBeenCalledWith();
});
});
describe('moveNext()', () => {
it(`should shift to the next n months, then emit a 'moveNext' event`, () => {
it(`should shift to the next month, then emit a 'move' event`, () => {
spyOn(controller, 'emit');
const currentMonth = controller.defaultDate.getMonth();
let nextMonth = currentMonth + 1;
let nextMonth = new Date(date.getTime());
nextMonth.setMonth(nextMonth.getMonth() + 1);
controller.moveNext(1);
controller.moveNext();
expect(controller.defaultDate.getMonth()).toEqual(nextMonth);
expect(controller.emit).toHaveBeenCalledWith('moveNext');
expect(controller.month).toEqual(nextMonth.getMonth());
expect(controller.emit).toHaveBeenCalledWith('move', {$date: nextMonth});
});
});
describe('movePrevious()', () => {
it(`should shift to the previous n months, then emit a 'movePrevious' event`, () => {
it(`should shift to the previous month, then emit a 'move' event`, () => {
spyOn(controller, 'emit');
const currentMonth = controller.defaultDate.getMonth();
let previousMonth = currentMonth - 1;
let previousMonth = new Date(date.getTime());
previousMonth.setMonth(previousMonth.getMonth() - 1);
controller.movePrevious(1);
controller.movePrevious();
expect(controller.defaultDate.getMonth()).toEqual(previousMonth);
expect(controller.emit).toHaveBeenCalledWith('movePrevious');
expect(controller.month).toEqual(previousMonth.getMonth());
expect(controller.emit).toHaveBeenCalledWith('move', {$date: previousMonth});
});
});
describe('select()', () => {
it(`should return the selected element, then emit a 'selection' event`, () => {
spyOn(controller, 'emit');
const dated = new Date();
const days = [{dated}];
controller.days = days;
controller.select(0);
const day = new Date();
day.setHours(0, 0, 0, 0);
controller.select(day);
let res = {
$days: [dated],
$days: [day],
$type: 'day'
};
expect(controller.field).toEqual(day);
expect(controller.emit).toHaveBeenCalledWith('selection', res);
});
});
describe('renderStyle()', () => {
it(`should normalize CSS attributes`, () => {
const result = controller.renderStyle({
backgroundColor: 'red'
});
expect(result['background-color']).toEqual('red');
});
});
});

View File

@ -1,103 +1,97 @@
@import "variables";
vn-calendar.small {
.events {
display: none
}
}
vn-calendar {
display: block;
.header vn-one {
text-align: center;
padding: 0.2em 0;
height: 1.5em
}
.weekdays {
color: $color-font-secondary;
margin-bottom: 0.5em;
padding: 0.5em 0;
font-weight: bold;
font-size: 0.8em;
}
.weekdays section {
cursor: pointer
}
.weekdays section, .day {
position: relative;
text-align: center;
box-sizing: border-box;
width: 14.28%;
outline: 0;
}
.days {
justify-content: flex-start;
align-items: flex-start;
flex-wrap: wrap;
}
.day {
.content {
position: absolute;
bottom: 0;
right: 0;
left: 0;
top: 0
}
.day-number {
transition: background-color 0.3s;
text-align:center;
float:inline-end;
margin: 0 auto;
border-radius: 50%;
font-size: 0.85em;
width:2.2em;
height: 1.2em;
padding: 0.5em 0;
cursor: pointer;
outline: 0
}
.day-number:hover {
background-color: lighten($color-font-secondary, 20%);
opacity: 0.8
}
}
.day::after {
content: "";
display: block;
padding-top: 100%;
}
.day.primary .day-number {
background-color: $color-main;
color: $color-font-dark;
}
.events {
margin-top: 0.5em;
font-size: 0.6em
}
.events {
color: $color-font-secondary;
& > div {
& > .header {
display: flex;
margin-bottom: 0.5em;
align-items: center;
height: 2.4em;
.event {
margin-bottom: .1em;
& > .title {
flex: 1;
text-align: center;
padding: 0.2em 0;
}
& > .vn-button {
color: inherit;
}
}
& > .weekdays {
display: flex;
color: $color-font-secondary;
margin-bottom: 0.5em;
padding: 0.5em 0;
font-weight: bold;
font-size: 0.8em;
text-align: center;
& > section {
width: 14.28%;
cursor: pointer;
}
}
& > .days {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
& > .day {
width: 14.28%;
height: 40px;
display: flex;
justify-content: center;
align-items: center;
&.weekend {
color: $color-font-secondary;
}
&.previous,
&.next {
opacity: .5;
}
&.event .day-number {
background-color: $color-main;
color: $color-font-dark;
}
& > .day-number {
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
font-size: 14px;
width: 2.2em;
height: 2.2em;
cursor: pointer;
outline: 0;
transition: background-color 300ms ease-in-out;
&:hover {
background-color: lighten($color-font-secondary, 20%);
opacity: .8
}
}
}
&.hide-contiguous > .day {
&.previous,
&.next {
visibility: hidden;
}
}
}
}
.chip {
background-color: $color-main;
color: $color-font-bg;
display: inline-block;
border-radius: .3em;
padding: 0.3em .8em;
max-width: 5em;
}
.day.gray {
.day-number {
color: $color-font-secondary
}
}
.day.sunday {
.day-number {
color: $color-alert;
font-weight: bold
&.disabled,
&.readonly {
& > div {
& > .weekdays > section {
cursor: initial;
}
& > .days > .day > .day-number {
cursor: initial;
}
}
}
}

View File

@ -1 +0,0 @@
<div></div>

View File

@ -5,12 +5,11 @@ export default function directive() {
return {
restrict: 'E',
transclude: true,
template: require('./card.html'),
link: function($scope, $element, $attrs, $ctrl, $transclude) {
$element.addClass('demo-card-wide vn-shadow bg-panel');
$element[0].classList.add('vn-shadow', 'bg-panel');
$transclude($scope, function(clone) {
angular.element($element[0].querySelector('div')).append(clone);
$element.append(clone);
});
}
};

View File

@ -0,0 +1,9 @@
<h6>Debug info</h6>
<ul>
<li>
{{$ctrl.env}}
</li>
<li>
<span ng-class="{alert: $root.$$watchersCount > 500}">{{$root.$$watchersCount}}</span> watchers
</li>
</ul>

View File

@ -0,0 +1,27 @@
import ngModule from '../../module';
import './style.scss';
/**
* Floating box displaying debugging information.
* Enabled only in development environment.
*/
export default class Controller {
constructor($element, $) {
this.env = process.env.NODE_ENV || 'development';
if (this.env == 'development')
this.interval = setInterval(() => $.$digest(), 2000);
else
$element[0].style.display = 'none';
}
$onDestroy() {
clearInterval(this.interval);
}
}
Controller.$inject = ['$element', '$scope'];
ngModule.component('vnDebugInfo', {
template: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1,44 @@
@import "variables";
vn-debug-info {
position: fixed;
bottom: 1em;
left: 1em;
padding: 1em;
min-width: 8em;
background-color: #3f51b5;
color: $color-font-dark;
border-radius: 4px;
z-index: 999;
box-shadow: $shadow;
transition: opacity 400ms ease-in-out;
&:hover {
opacity: .5;
}
& > h6 {
font-weight: normal;
color: rgba(255, 255, 255, .5);
font-size: 1em;
}
ul {
list-style-type: none;
padding: 0;
margin: 0;
& > li {
margin-top: .2em;
font-size: .95em;
& > span {
padding: .05em .2em;
border-radius: 4px;
transition: background-color 200ms ease-in-out;
&.alert {
background-color: $color-alert;
}
}
}
}
}

View File

@ -31,7 +31,7 @@
tpl-body {
display: block;
min-width: 20em;
min-width: 16em;
}
& > button.close {
@extend %clickable;

View File

@ -218,17 +218,14 @@ export default class DropDown extends Component {
onLoadMoreClick(event) {
if (event.defaultPrevented) return;
event.preventDefault();
this.model.loadMore();
}
onContainerClick(event) {
if (event.defaultPrevented) return;
let index = getPosition(this.$.ul, event);
if (index != -1) {
event.preventDefault();
if (index != -1)
this.selectOption(index);
}
}
onDocKeyDown(event) {

View File

@ -153,13 +153,8 @@ export default class Field extends FormInput {
fix.innerText = text || '';
}
refreshTabIndex() {
this.input.tabIndex = this.disabled ? -1 : this.tabIndex;
}
onClick() {
// if (event.defaultPrevented) return;
// event.preventDefault();
if (this.input !== document.activeElement)
this.focus();
@ -177,19 +172,10 @@ export default class Field extends FormInput {
onClear(event) {
if (event.defaultPrevented) return;
event.preventDefault();
this.field = null;
this.input.dispatchEvent(new Event('change'));
}
focus() {
this.input.focus();
}
select() {
this.input.select();
}
buildInput(type) {
let template = `<input type="${type}" ng-model="$ctrl.field"></input>`;
this.input = this.$compile(template)(this.$)[0];

View File

@ -49,8 +49,9 @@ export default class FormInput extends Component {
set disabled(value) {
this._disabled = boolTag(value);
this.input.disabled = this._disabled;
this.classList.toggle('disabled', this._disabled);
if (this.input)
this.input.disabled = this._disabled;
this.refreshTabIndex();
}
@ -60,8 +61,9 @@ export default class FormInput extends Component {
set readonly(value) {
this._readonly = boolTag(value);
this.input.readOnly = this._readonly;
this.classList.toggle('readonly', this._readonly);
if (this.input)
this.input.readOnly = this._readonly;
}
get readonly() {
@ -77,16 +79,30 @@ export default class FormInput extends Component {
return this._tabIndex;
}
get inputEl() {
return this.input || this.element;
}
get editable() {
return !(this.readonly || this.disabled);
}
select() {
this.input.select();
if (this.inputEl.select)
this.inputEl.select();
}
focus() {
this.input.focus();
this.inputEl.focus();
}
initTabIndex() {
if (!this.element.hasAttribute('tabindex'))
this.element.tabIndex = 0;
}
refreshTabIndex() {
this.element.tabIndex = this.disabled ? -1 : this.tabIndex;
this.inputEl.tabIndex = this.disabled ? -1 : this.tabIndex;
}
}

View File

@ -28,6 +28,7 @@ import './check';
import './chip';
import './data-viewer';
import './date-picker';
import './debug-info';
import './field';
import './float-button';
import './icon-menu';
@ -44,3 +45,4 @@ import './td-editable';
import './textarea';
import './th';
import './treeview';
import './wday-picker';

View File

@ -68,7 +68,6 @@ export default class InputNumber extends Field {
onStep(event, way) {
if (event.defaultPrevented) return;
event.preventDefault();
if (way == 'up')
this.stepUp();

View File

@ -1,17 +1,17 @@
import ngModule from '../../module';
import Component from 'core/lib/component';
import './style.scss';
export default class Controller {
constructor($element, $translate, $attrs) {
this.element = $element[0];
this._ = $translate;
export default class Controller extends Component {
constructor($element, $, $attrs) {
super($element, $);
this.hasInfo = Boolean($attrs.info);
this.info = $attrs.info || null;
}
set label(value) {
let label = this.element.querySelector('vn-label');
label.textContent = this._.instant(value);
label.textContent = this.$t(value);
this._label = value;
}
@ -55,7 +55,7 @@ export default class Controller {
element.textContent = hasValue ? this.value : '-';
}
}
Controller.$inject = ['$element', '$translate', '$attrs'];
Controller.$inject = ['$element', '$scope', '$attrs'];
ngModule.component('vnLabelValue', {
controller: Controller,

View File

@ -190,7 +190,6 @@ export default class Popover extends Component {
onBgMouseDown(event) {
if (event == this.lastMouseEvent || event.defaultPrevented) return;
event.preventDefault();
this.hide();
}
}

View File

@ -65,7 +65,6 @@ export default class Controller extends Component {
openPanel(event) {
if (event.defaultPrevented) return;
event.preventDefault();
this.$panelScope = this.$.$new();
this.$panel = this.$compile(`<${this.panel}/>`)(this.$panelScope);

View File

@ -81,18 +81,6 @@ describe('Component vnSearchbar', () => {
});
});
describe('openPanel()', () => {
it(`should do nothing if the event is prevented`, () => {
let event = {
defaultPrevented: true,
preventDefault: jasmine.createSpy('preventDefault')
};
controller.openPanel(event);
expect(event.preventDefault).not.toHaveBeenCalledWith();
});
});
describe('onPopoverClose()', () => {
it(`should get rid of $panel and $panelScope`, () => {
controller.$panel = {

View File

@ -10,43 +10,20 @@ import './style.scss';
export default class Toggle extends FormInput {
constructor($element, $) {
super($element, $);
let element = this.element;
element.tabIndex = 0;
element.addEventListener('click', e => this.onClick(e));
element.addEventListener('keydown', e => this.onKeydown(e));
element.classList.add('vn-toggle');
}
set disabled(value) {
this._disabled = value;
this.classList.toggle('disabled', Boolean(value));
this.refreshTabIndex();
}
get disabled() {
return this._disabled;
}
set readonly(value) {
this._readonly = value;
this.classList.toggle('readonly', Boolean(value));
}
get readonly() {
return this._readonly;
this.initTabIndex();
this.classList.add('vn-toggle');
this.element.addEventListener('click', e => this.onClick(e));
this.element.addEventListener('keydown', e => this.onKeydown(e));
}
onKeydown(event) {
if (event.code == 'Space')
this.onClick(event);
if (!event.defaultPrevented && event.code == 'Space')
this.element.click();
}
onClick(event) {
if (this.disabled || event.defaultPrevented)
if (!this.editable || event.defaultPrevented)
return true;
event.preventDefault();
}
changed() {

View File

@ -235,7 +235,6 @@ export function directive($document, $compile, $templateRequest) {
$element[0].title = '';
$element.on('mouseover', function(event) {
if (event.defaultPrevented) return;
event.preventDefault();
tooltip.show($element[0]);
});
$element.on('mouseout', function() {

View File

@ -9,12 +9,12 @@
<section class="buttons" ng-if="::!$ctrl.treeview.readOnly">
<vn-icon-button translate-attr="::{title: 'Remove'}"
icon="delete"
ng-click="$ctrl.treeview.onRemove($ctrl.item)"
ng-click="$ctrl.treeview.onRemove($event, $ctrl.item)"
ng-if="$ctrl.item.parent">
</vn-icon-button>
<vn-icon-button translate-attr="::{title: 'Create'}"
icon="add_circle"
ng-click="$ctrl.treeview.onCreate($ctrl.item)">
ng-click="$ctrl.treeview.onCreate($event, $ctrl.item)">
</vn-icon-button>
</section>
</div>

View File

@ -2,7 +2,7 @@
<ul ng-if="$ctrl.items">
<li ng-repeat="item in $ctrl.items">
<vn-treeview-child item="item" ng-class="{expanded: item.active}"
ng-click="$ctrl.onClick($event, item)">
ng-click="$ctrl.treeview.onToggle($event, item)">
</vn-treeview-child>
<vn-treeview-childs
items="item.childs">

View File

@ -1,13 +1,6 @@
import ngModule from '../../module';
import Component from '../../lib/component';
class Controller extends Component {
onClick(event, item) {
if (event.defaultPrevented || !item.sons) return;
event.preventDefault();
this.treeview.onToggle(item);
}
}
class Controller {}
ngModule.component('vnTreeviewChilds', {
template: require('./childs.html'),

View File

@ -141,7 +141,12 @@ export default class Treeview extends Component {
});
}
onToggle(item) {
onToggle(event, item) {
let ignoreEvent = event.defaultPrevented
|| event == this.lastActionEvent
|| !item.sons;
if (ignoreEvent) return;
if (item.active)
this.fold(item);
else
@ -175,7 +180,8 @@ export default class Treeview extends Component {
}).then(() => item.active = true);
}
onRemove(item) {
onRemove(event, item) {
this.lastActionEvent = event;
if (this.removeFunc)
this.removeFunc({$item: item});
}
@ -191,7 +197,8 @@ export default class Treeview extends Component {
if (parent) parent.sons--;
}
onCreate(parent) {
onCreate(event, parent) {
this.lastActionEvent = event;
if (this.createFunc)
this.createFunc({$parent: parent});
}

View File

@ -102,11 +102,16 @@ describe('Component vnTreeview', () => {
spyOn(controller, 'fold');
spyOn(controller, 'unfold');
const item = {name: 'My item'};
let event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
const item = {name: 'My item', sons: 1};
controller.onToggle(item);
controller.onToggle(event, item);
item.active = true;
controller.onToggle(item);
controller.onToggle(event, item);
expect(controller.unfold).toHaveBeenCalledWith(item);
expect(controller.fold).toHaveBeenCalledWith(item);
@ -148,9 +153,15 @@ describe('Component vnTreeview', () => {
describe('onRemove()', () => {
it(`should call the removeFunc() method`, () => {
let event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
spyOn(controller, 'removeFunc');
const item = {name: 'My item'};
controller.onRemove(item);
controller.onRemove(event, item);
expect(controller.removeFunc).toHaveBeenCalledWith({$item: item});
});
@ -172,9 +183,15 @@ describe('Component vnTreeview', () => {
describe('onCreate()', () => {
it(`should call the createFunc() method`, () => {
let event = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
spyOn(controller, 'createFunc');
const parent = {name: 'My item'};
controller.onCreate(parent);
controller.onCreate(event, parent);
expect(controller.createFunc).toHaveBeenCalledWith({$parent: parent});
});

View File

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

View File

@ -0,0 +1,8 @@
<span
ng-repeat="day in $ctrl.days"
translate-attr="::{title: day.name}"
ng-class="{marked: $ctrl.field[day.code]}"
ng-click="$ctrl.field[day.code] = !$ctrl.field[day.code]">
{{day.localeChar}}
</span>

View File

@ -0,0 +1,17 @@
import ngModule from '../../module';
import FormInput from '../form-input';
import './style.scss';
export default class WdayPicker extends FormInput {
constructor($element, $scope, vnWeekDays) {
super($element, $scope);
this.days = vnWeekDays.locales;
this.initTabIndex();
}
}
WdayPicker.$inject = ['$element', '$scope', 'vnWeekDays'];
ngModule.vnComponent('vnWdayPicker', {
template: require('./index.html'),
controller: WdayPicker
});

View File

@ -0,0 +1,27 @@
@import "effects";
vn-wday-picker {
text-align: center;
&:focus {
outline: solid 1px rgba(0, 0, 0, .1);
}
& > span {
@extend %clickable;
border-radius: 50%;
padding: .4em;
margin: .2em;
display: inline-flex;
width: 1.5em;
height: 1.5em;
justify-content: center;
align-items: center;
outline: none;
background-color: rgba(0, 0, 0, .05);
&.marked {
background: $color-main;
color: $color-font-dark;
}
}
}

View File

@ -2,15 +2,14 @@ import ngModule from '../module';
directive.$inject = ['$document'];
export function directive($document) {
let modifiers = ["alt", "ctrl", "meta", "shift"];
let modifiers = ['alt', 'ctrl', 'meta', 'shift'];
function checkAttributes($attrs) {
let shortcut = $attrs.vnBind.split(' ');
let keys = {};
if (shortcut[0] == "") {
if (shortcut[0] == '')
throw new Error('vnBind: Binding keys not defined');
}
if (shortcut.length == 1) {
keys.altKey = true;
@ -41,7 +40,8 @@ export function directive($document) {
let correctShortcut = true;
for (const key in shortcut) {
correctShortcut = correctShortcut && shortcut[key] == event[key];
correctShortcut = correctShortcut
&& shortcut[key] == event[key];
}
if (correctShortcut) {
event.preventDefault();
@ -49,7 +49,7 @@ export function directive($document) {
}
}
$document.on("keyup", onKeyUp);
$document.on('keyup', onKeyUp);
$element.on('$destroy', function() {
$document.off('keyup', onKeyUp);
});

View File

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

View File

@ -3,7 +3,7 @@ import ngModule from '../module';
const regex = /Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i;
export const isMobile = regex.test(navigator.userAgent);
export function focus(input) {
export function focus($scope, input) {
if (isMobile) return;
const element = input;
@ -23,9 +23,9 @@ export function focus(input) {
}
input.focus();
if (input.select)
$scope.$applyAsync(() => {
input.select();
});
}
/**
@ -37,7 +37,7 @@ export function directive() {
return {
restrict: 'A',
link: function($scope, $element) {
$scope.$watch('', () => focus($element[0]));
$scope.$watch('', () => focus($scope, $element[0]));
}
};
}

View File

@ -12,13 +12,13 @@ export function directive() {
restrict: 'A',
link: function($scope, $element, $attrs) {
$element.on('click', function(event) {
if (event.defaultPrevented) return;
let popoverKey = kebabToCamel($attrs.vnPopover);
let popover = $scope[popoverKey];
if (popover instanceof Popover) {
popover.parent = $element[0];
popover.show();
}
event.preventDefault();
});
}
};

View File

@ -40,6 +40,7 @@ describe('Directive focus', () => {
it('should call select function on the element', () => {
let html = `<input vn-focus></input>`;
compile(html);
$scope.$apply();
expect($element[0].select).toHaveBeenCalledWith();
});

View File

@ -44,7 +44,7 @@ export function directive($timeout) {
restrict: 'A',
link: function($scope, $element, $attrs) {
$element.on('click', function(event) {
event.preventDefault();
if (event.defaultPrevented) return;
let src = $attrs.zoomImage || $attrs.src;
if (src)

View File

@ -1,3 +1,4 @@
import ngModule from '../module';
import EventEmitter from './event-emitter';
import {kebabToCamel} from './string';
@ -44,5 +45,30 @@ export default class Component extends EventEmitter {
get document() {
return this.element.ownerDocument;
}
/**
* Translates an string.
*
* @param {String} string String to translate
* @param {Array} params Translate parameters
* @return {String} The translated string
*/
$t(string, params) {
return this.$translate.instant(string, params);
}
}
Component.$inject = ['$element', '$scope'];
function runFn($translate, $q, $http, vnApp, $state, $stateParams) {
Object.assign(Component.prototype, {
$translate,
$q,
$http,
vnApp,
$state,
$params: $stateParams
});
}
runFn.$inject = ['$translate', '$q', '$http', 'vnApp', '$state', '$stateParams'];
ngModule.run(runFn);

View File

@ -1,34 +0,0 @@
import Component from './component';
/**
* Class with commonly injected services assigned as properties. It also has
* abbreviations for commonly used methods like tranlation.
*
* @property {Object} $translate Angular tranlation service
* @property {Object} $http Angular HTTP service
* @property {Object} $state Router state service
* @property {Object} $stateParams Router state parameters
*/
export default class Section extends Component {
constructor($element, $scope, $translate, $http, $state) {
super($element, $scope);
Object.assign(this, {
$translate,
$http,
$state,
$stateParams: $state.params
});
}
/**
* Translates an string.
*
* @param {String} string String to translate
* @param {Array} params Translate parameters
* @return {String} The translated string
*/
_(string, params) {
return this.$translate.instant(string, params, );
}
}
Section.$inject = ['$element', '$scope', '$translate', '$http', '$state'];

View File

@ -4,10 +4,12 @@ class AclService {
constructor($http) {
this.$http = $http;
}
reset() {
this.user = null;
this.roles = null;
}
load() {
return this.$http.get('/api/Accounts/acl').then(res => {
this.user = res.data.user;
@ -19,6 +21,7 @@ class AclService {
}
});
}
hasAny(roles) {
if (this.roles) {
for (let role of roles) {

View File

@ -20,6 +20,7 @@ export default class Auth {
loggedIn: false
});
}
initialize() {
let criteria = {
to: state => state.name != 'login'
@ -42,6 +43,7 @@ export default class Auth {
return redirectToLogin();
});
}
login(user, password, remember) {
if (!user)
return this.$q.reject(new UserError('Please enter your username'));
@ -54,6 +56,7 @@ export default class Auth {
return this.$http.post('/api/Accounts/login', params).then(
json => this.onLoginOk(json, remember));
}
onLoginOk(json, remember) {
this.vnToken.set(json.data.token, remember);
@ -65,6 +68,7 @@ export default class Auth {
this.$state.go('home');
});
}
logout() {
let promise = this.$http.post('/api/Accounts/logout', null, {
headers: {Authorization: this.vnToken.token}
@ -78,6 +82,7 @@ export default class Auth {
return promise;
}
loadAcls() {
return this.aclService.load()
.then(() => {

View File

@ -6,3 +6,4 @@ import './token';
import './modules';
import './interceptor';
import './config';
import './week-days';

View File

@ -0,0 +1,71 @@
import ngModule from '../module';
class WeekDays {
constructor($translate) {
this.$translate = $translate;
this.days = [
{
code: 'sun',
name: 'Sunday'
}, {
code: 'mon',
name: 'Monday'
}, {
code: 'tue',
name: 'Tuesday'
}, {
code: 'wed',
name: 'Wednesday'
}, {
code: 'thu',
name: 'Thursday'
}, {
code: 'fri',
name: 'Friday'
}, {
code: 'sat',
name: 'Saturday'
}
];
this.map = {};
for (let i = 0; i < this.days.length; i++) {
let day = this.days[i];
day.index = i;
day.char = day.name.substr(0, 1);
day.abr = day.name.substr(0, 3);
this.map[day.code] = day;
}
this.getLocales();
}
getLocales() {
for (let day of this.days) {
let locale = this.$translate.instant(day.name);
Object.assign(day, {
locale,
localeChar: locale.substr(0, 1),
localeAbr: locale.substr(0, 3)
});
}
this.localeCodes = [
'mon',
'tue',
'wed',
'thu',
'fri',
'sat',
'sun'
];
this.locales = [];
for (let code of this.localeCodes)
this.locales.push(this.map[code]);
}
}
WeekDays.$inject = ['$translate'];
ngModule.service('vnWeekDays', WeekDays);

View File

@ -1,9 +1,12 @@
@import "variables";
html, body {
html {
background-color: $color-bg;
overflow: auto;
height: 100%;
}
body {
height: 100%;
font-family: vn-font;
color: $color-font;
font-size: $font-size;

View File

@ -42,13 +42,13 @@
h1, h2, h3, h4, h5, h6 {
padding: 0;
margin-top: 0;
margin-bottom: .2em;
margin-bottom: .3em;
}
/* Colors */
.text-primary {
color: $color-font;
color: $color-main;
}
.text-secondary {
color: $color-font-secondary;

View File

@ -25,4 +25,5 @@
ng-class="{padding: $ctrl.showTopbar}">
<vn-home></vn-home>
</div>
<vn-snackbar vn-id="snackbar"></vn-snackbar>
<vn-snackbar vn-id="snackbar"></vn-snackbar>
<vn-debug-info></vn-debug-info>

View File

@ -1,7 +1,7 @@
<a ng-if="$ctrl.links.btnOne"
vn-tooltip="{{::$ctrl.links.btnOne.tooltip}}"
class="vn-button colored"
ui-sref="{{::$ctrl.links.btnOne.state}}" target="_blank">
ui-sref="{{::$ctrl.links.btnOne.state}}">
<vn-icon
icon="{{::$ctrl.links.btnOne.icon}}">
</vn-icon>
@ -9,7 +9,7 @@
<a ng-if="$ctrl.links.btnTwo"
vn-tooltip="{{::$ctrl.links.btnTwo.tooltip}}"
class="vn-button colored"
ui-sref="{{::$ctrl.links.btnTwo.state}}" target="_blank">
ui-sref="{{::$ctrl.links.btnTwo.state}}">
<vn-icon
icon="{{::$ctrl.links.btnTwo.icon}}">
</vn-icon>
@ -17,7 +17,7 @@
<a ng-if="$ctrl.links.btnThree"
vn-tooltip="{{::$ctrl.links.btnThree.tooltip}}"
class="vn-button colored"
ui-sref="{{::$ctrl.links.btnThree.state}}" target="_blank">
ui-sref="{{::$ctrl.links.btnThree.state}}">
<vn-icon
icon="{{::$ctrl.links.btnThree.icon}}">
</vn-icon>

View File

@ -1,16 +1,17 @@
import ngModule from '../../module';
import Component from 'core/lib/component';
import './style.scss';
export default class Controller {
constructor(vnModules, $state, $translate, $sce) {
export default class Controller extends Component {
constructor($element, $, vnModules, $sce) {
super($element, $);
this.modules = vnModules.get();
this.$state = $state;
this._ = $translate;
this.$sce = $sce;
}
getModuleName(mod) {
let getName = mod => {
let name = this._.instant(mod.name);
let name = this.$t(mod.name);
let upper = name.toUpperCase();
if (!mod.keyBind) return name;
let index = upper.indexOf(mod.keyBind);
@ -25,8 +26,7 @@ export default class Controller {
return this.$sce.trustAsHtml(getName(mod));
}
}
Controller.$inject = ['vnModules', '$state', '$translate', '$sce'];
Controller.$inject = ['$element', '$scope', 'vnModules', '$sce'];
ngModule.component('vnHome', {
template: require('./home.html'),

View File

@ -18,6 +18,9 @@ vn-main-menu {
vertical-align: middle;
font-weight: bold;
margin-right: .2em;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
cursor: pointer;
}
& > .vn-button {

View File

@ -39,7 +39,6 @@ export default class SideMenu {
onEscape(event) {
if (!event.defaultPrevented && event.key == 'Escape') {
event.preventDefault();
this.hide();
this.$.$digest();
}

View File

@ -4,50 +4,48 @@
margin: 0 auto;
max-width: 950px;
& > div {
& > h5 {
padding: $spacing-sm;
border: none;
background: $color-main;
color: $color-font-dark;
margin: 0;
text-align: center;
line-height: 1.3em;
& > h5 {
padding: $spacing-sm;
border: none;
background: $color-main;
color: $color-font-dark;
margin: 0;
text-align: center;
line-height: 1.3em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
& > vn-horizontal {
flex-wrap: wrap;
padding: $spacing-md;
overflow: hidden;
align-items: flex-start;
h4 {
margin-bottom: $spacing-md;
text-transform: uppercase;
font-size: 15pt;
line-height: 1;
padding: 7px;
padding-bottom: 4px; /* Bottom line-height fix */
font-weight: lighter;
background-color: $color-main-light;
border-bottom: .1em solid $color-main;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
& > vn-horizontal {
flex-wrap: wrap;
padding: $spacing-md;
overflow: hidden;
align-items: flex-start;
h4 {
margin-bottom: $spacing-md;
text-transform: uppercase;
font-size: 15pt;
line-height: 1;
padding: 7px;
padding-bottom: 4px; /* Bottom line-height fix */
font-weight: lighter;
background-color: $color-main-light;
border-bottom: .1em solid $color-main;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
& > * {
margin: $spacing-sm;
min-width: 14em;
padding: 0;
}
& > vn-auto {
width: 100%;
}
vn-label-value > section {
margin-bottom: .3em;
}
& > * {
margin: $spacing-sm;
min-width: 14em;
padding: 0;
}
& > vn-auto {
width: 100%;
}
vn-label-value > section {
margin-bottom: .3em;
}
}
p:after {

View File

@ -61,11 +61,11 @@ vn-bg-title {
}
.totalBox {
border: 1px solid #CCC;
text-align: right !important;
text-align: right;
justify-content: center;
align-items: center;
padding: 18px;
max-width: 12em;
padding: $spacing-md;
max-width: 14em;
}
.form {
height: 100%;

View File

@ -11,7 +11,7 @@
width: 28em;
overflow: hidden;
& > vn-card > div {
& > vn-card {
display: flex;
height: 12em;

View File

@ -1,22 +1,28 @@
<vn-calendar
vn-id="stMonth"
skip="2"
has-events="$ctrl.hasEvents($day)"
get-class="$ctrl.getClass($day)"
on-selection="$ctrl.onSelection($days, $type, $weekday)"
on-move-next="ndMonth.moveNext(2)"
on-move-previous="ndMonth.movePrevious(2)"
vn-acl="deliveryBoss"
class="vn-pa-md">
</vn-calendar>
<vn-calendar
vn-id="ndMonth"
skip="2"
has-events="$ctrl.hasEvents($day)"
get-class="$ctrl.getClass($day)"
on-selection="$ctrl.onSelection($days, $type, $weekday)"
default-date="$ctrl.ndMonthDate"
vn-acl="deliveryBoss"
display-controls="false"
class="vn-pa-md">
</vn-calendar>
<vn-card>
<div class="header">
<vn-button
icon="navigate_before"
ng-click="$ctrl.step(-1)"
class="flat">
</vn-button>
<span>{{$ctrl.firstDay | date:'MMMM yyyy'}} - {{$ctrl.lastDay | date:'MMMM yyyy'}}</span>
<vn-button
icon="navigate_next"
ng-click="$ctrl.step(1)"
class="flat">
</vn-button>
</div>
<div class="calendars vn-pa-md">
<vn-calendar
ng-repeat="date in $ctrl.months track by date.getTime()"
default-date="date"
display-controls="false"
hide-contiguous="true"
has-events="$ctrl.hasEvents($day)"
get-class="$ctrl.getClass($day)"
on-selection="$ctrl.onSelection($days, $type, $weekday)"
class="vn-pa-md"
style="min-width: 250px; flex: 1;">
</vn-calendar>
</div>
</vn-card>

View File

@ -1,100 +1,155 @@
import ngModule from '../module';
import Section from 'core/lib/section';
import Component from 'core/lib/component';
import './style.scss';
class Controller extends Section {
constructor($el, $, $t, $http, $state) {
super($el, $, $t, $http, $state);
class Controller extends Component {
constructor($element, $) {
super($element, $);
this.nMonths = 4;
this.excls = {};
this.resetEvents();
this.ndMonthDate = new Date();
this.ndMonthDate.setMonth(this.ndMonthDate.getMonth() + 1);
let date = new Date();
date.setDate(1);
date.setHours(0, 0, 0, 0);
this.date = date;
}
get date() {
return this._date;
}
set date(value) {
this._date = value;
let stamp = value.getTime();
let firstDay = new Date(stamp);
firstDay.setDate(1);
this.firstDay = firstDay;
let lastDay = new Date(stamp);
lastDay.setMonth(lastDay.getMonth() + this.nMonths);
lastDay.setDate(0);
this.lastDay = lastDay;
this.months = [];
for (let i = 0; i < this.nMonths; i++) {
let monthDate = new Date(stamp);
monthDate.setMonth(value.getMonth() + i);
this.months.push(monthDate);
}
this.refreshEvents();
}
step(direction) {
let date = new Date(this.date.getTime());
date.setMonth(date.getMonth() + (this.nMonths * direction));
this.date = date;
}
get data() {
return this._data;
}
set data(value) {
this._data = value;
value = value || {};
this.events = value.events;
this.exclusions = value.exclusions;
if (this.events) {
let codes = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
for (event of this.events) {
if (!event.weekDays) continue;
let weekDays = event.weekDays.split(',');
event.wdays = [];
for (let wday of weekDays) {
let index = codes.indexOf(wday);
if (index !== -1) event.wdays[index] = true;
}
}
}
this.refreshEvents();
let calendars = this.element.querySelectorAll('vn-calendar');
for (let calendar of calendars)
calendar.$ctrl.repaint();
}
refreshEvents() {
function getDate(date) {
return date && new Date(date).setHours(0, 0, 0, 0);
}
let exclusionsMap = {};
if (this.exclusions) {
for (let exclusion of this.exclusions)
exclusionsMap[getDate(exclusion.day)] = exclusion;
}
this.days = {};
let day = new Date(this.firstDay.getTime());
while (day < this.lastDay) {
let stamp = day.getTime();
let wday = day.getDay();
let dayEvents = [];
if (this.events) {
for (let event of this.events) {
let match;
let from = getDate(event.from);
let to = getDate(event.to);
if (event.from && event.to) {
match = stamp >= from && stamp <= to
&& event.wdays[wday];
} else if (event.from)
match = from == stamp;
else
match = event.wdays[wday];
if (match)
dayEvents.push(event);
}
}
let exclusion = exclusionsMap[stamp];
if (dayEvents.length || exclusion) {
let dayData = {};
if (dayEvents.length) dayData.events = dayEvents;
if (exclusion) dayData.exclusion = exclusion;
this.days[stamp] = dayData;
}
day.setDate(day.getDate() + 1);
}
}
onSelection($days, $type, $weekday) {
this.emit('selection', {$days, $type, $weekday});
}
resetEvents() {
this.wdays = [];
this.days = {};
this.ranges = [];
}
get events() {
return this._events;
}
set events(value) {
this._events = value;
this.resetEvents();
if (!value) return;
function setWdays(wdays, weekDays) {
let codes = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
if (!weekDays) return [];
weekDays = weekDays.split(',');
for (let wday of weekDays)
wdays[codes.indexOf(wday)] = true;
return wdays;
let $data = [];
for (let day of $days) {
let dayData = this.days[day.getTime()];
if (dayData) $data.push(dayData);
}
for (let event of value) {
if (event.from && event.to) {
this.ranges.push({
from: new Date(event.from).setHours(0, 0, 0, 0),
to: new Date(event.to).setHours(0, 0, 0, 0),
wdays: setWdays([], event.weekDays)
});
} else if (event.from) {
let day = new Date(event.from).setHours(0, 0, 0, 0);
this.days[day] = true;
} else
setWdays(this.wdays, event.weekDays);
}
this.repaint();
}
get exclusions() {
return this._exclusions;
}
set exclusions(value) {
this._exclusions = value;
this.excls = {};
if (!value) return;
value.forEach(exclusion => {
let day = new Date(exclusion.day).setHours(0, 0, 0, 0);
this.excls[day] = true;
this.emit('selection', {
$days,
$type,
$weekday,
$data
});
this.repaint();
}
hasRange(time, wday) {
let range = this.ranges.find(e => e.from <= time && e.to >= time);
return range && range.wdays[wday];
}
hasEvents(day) {
let time = day.getTime();
let wday = day.getDay();
return this.wdays[wday]
|| this.days[time]
|| this.hasRange(time, wday);
return this.days[day.getTime()] != null;
}
getClass(day) {
if (this.excls[day.getTime()])
return 'excluded';
}
repaint() {
this.$.stMonth.repaint();
this.$.ndMonth.repaint();
let dayData = this.days[day.getTime()];
return dayData && dayData.exclusion ? 'excluded' : '';
}
}
@ -102,7 +157,6 @@ ngModule.component('vnZoneCalendar', {
template: require('./index.html'),
controller: Controller,
bindings: {
events: '<?',
exclusions: '<?'
data: '<?'
}
});

View File

@ -1,13 +1,40 @@
@import "variables";
vn-zone-calendar {
vn-calendar .day {
&.primary .day-number {
background-color: $color-success;
display: block;
& > vn-card {
& > .header {
display: flex;
align-items: center;
justify-content: space-between;
background-color: $color-main;
color: white;
font-weight: bold;
height: 45px;
& > .vn-button {
color: inherit;
height: 100%;
}
}
&.excluded .day-number {
background-color: $color-alert;
color: $color-font-dark;
& > .calendars {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
& > vn-calendar {
max-width: 18em;
.day {
&.event .day-number {
background-color: $color-success;
}
&.excluded .day-number {
background-color: $color-alert;
}
}
}
}
}
}

View File

@ -1,47 +1,43 @@
<div style="margin: 0 auto; max-width: 40em;">
<div class="vn-w-md">
<form ng-submit="$ctrl.onSubmit()">
<vn-card class="vn-pa-md">
<vn-vertical>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Agency"
ng-model="$ctrl.params.agencyModeFk"
url="/api/AgencyModes/isActive">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Province"
ng-model="$ctrl.params.provinceFk"
url="/api/Provinces"
fields="['countryFk']"
include="'country'"
style="margin-right: .5em;">
<tpl-item>
<div>{{name}}</div>
<div style="font-size: .9em; color: gray; line-height: .8em;">
{{country.country}}
</div>
</tpl-item>
</vn-autocomplete>
<vn-textfield
vn-one
label="Postcode"
ng-model="$ctrl.params.postCode">
</vn-textfield>
</vn-horizontal>
</vn-vertical>
<vn-card class="vn-pa-lg">
<vn-horizontal>
<vn-autocomplete
vn-one
label="Agency"
ng-model="$ctrl.params.agencyModeFk"
url="/api/AgencyModes/isActive">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
label="Province"
ng-model="$ctrl.params.provinceFk"
url="/api/Provinces"
fields="['countryFk']"
include="'country'"
style="margin-right: .5em;">
<tpl-item>
<div>{{name}}</div>
<div style="font-size: .9em; color: gray; line-height: .8em;">
{{country.country}}
</div>
</tpl-item>
</vn-autocomplete>
<vn-textfield
vn-one
label="Postcode"
ng-model="$ctrl.params.postCode">
</vn-textfield>
</vn-horizontal>
</vn-card>
<vn-button-bar>
<vn-submit label="Query"></vn-submit>
</vn-button-bar>
</form>
<vn-card class="vn-pa-md vn-mt-md">
<vn-zone-calendar
events="events.events"
exclusions="events.exclusions">
</vn-zone-calendar>
</vn-card>
<vn-zone-calendar
data="data"
class="vn-mt-md">
</vn-zone-calendar>
</div>

View File

@ -11,7 +11,7 @@ class Controller {
onSubmit() {
this.$http.get(`/api/Zones/getEvents`, {params: this.params})
.then(res => this.$.events = res.data);
.then(res => this.$.data = res.data);
}
}
Controller.$inject = ['$scope', '$http'];

View File

@ -1,27 +1,60 @@
<div class="main-with-right-menu">
<vn-data-viewer
<vn-zone-calendar
id="calendar"
data="data"
is-loading="!data"
on-selection="$ctrl.onSelection($days, $type, $weekday, $data)"
class="vn-w-md">
</vn-zone-calendar>
</div>
<vn-side-menu side="right">
<div class="vn-pa-md">
<h6
class="text-secondary"
style="font-weight: normal;"
translate>
Edit mode
</h6>
<vn-vertical>
<vn-radio
label="Include"
val="include"
ng-model="$ctrl.editMode">
</vn-radio>
<vn-radio
label="Exclude"
val="exclude"
ng-model="$ctrl.editMode">
</vn-radio>
</vn-vertical>
</div>
<h6
class="text-secondary vn-px-md"
style="font-weight: normal;"
translate>
Events
</h6>
<vn-data-viewer
data="data.events"
is-loading="!data.events"
class="vn-w-sm">
<vn-card>
<div class="vn-list">
<a
ng-repeat="row in data"
ng-repeat="row in data.events"
translate-attr="{title: 'Edit'}"
ng-click="$ctrl.onEdit(row, $event)"
ng-click="$ctrl.onEditClick(row, $event)"
class="vn-list-item">
<vn-horizontal>
<vn-one>
<div
ng-if="::row.from && !row.to"
class="vn-mb-sm">
{{::row.from | date:'dd/MM/yyyy'}}
{{::row.from | date:'dd/MM/yy'}}
</div>
<div
ng-if="::!row.from || row.to"
class="vn-mb-sm">
class="vn-mb-sm ellipsize">
<span ng-if="row.to">
{{::row.from | date:'dd/MM/yyyy'}} - {{::row.to | date:'dd/MM/yyyy'}}
{{::row.from | date:'dd/MM/yy'}} - {{::row.to | date:'dd/MM/yy'}}
</span>
<span ng-if="!row.to" translate>
Indefinitely
@ -51,21 +84,13 @@
<vn-icon-button
icon="delete"
translate-attr="{title: 'Delete'}"
ng-click="$ctrl.onDelete(row.id, $event)">
ng-click="$ctrl.onDeleteClick(row.id, $event)">
</vn-icon-button>
</vn-horizontal>
</vn-horizontal>
</a>
</div>
</vn-card>
</vn-data-viewer>
</div>
<vn-side-menu side="right">
<vn-zone-calendar
events="data"
exclusions="exclusions"
on-selection="$ctrl.onCreate($days, $type, $weekday)">
</vn-zone-calendar>
</vn-side-menu>
<vn-dialog
vn-id="dialog"
@ -89,16 +114,11 @@
val="range">
</vn-radio>
</vn-vertical>
<div
<vn-wday-picker
ng-if="$ctrl.eventType != 'day'"
class="week-days">
<span
ng-repeat="wday in $ctrl.wdays"
ng-class="{marked: $ctrl.selected.wdays[wday.code]}"
ng-click="$ctrl.selected.wdays[wday.code] = !$ctrl.selected.wdays[wday.code]">
{{wday.abr}}
</span>
</div>
ng-model="$ctrl.selected.wdays"
class="vn-mt-sm vn-mb-md">
</vn-wday-picker>
<vn-date-picker
ng-if="$ctrl.eventType == 'day'"
label="Day"
@ -140,8 +160,21 @@
</vn-vertical>
</tpl-body>
<tpl-buttons>
<input type="button" response="CANCEL" translate-attr="{value: 'Cancel'}"/>
<button response="ACCEPT" translate>Save</button>
<input
type="button"
response="CANCEL"
translate-attr="{value: 'Cancel'}">
</input>
<button
ng-if="!$ctrl.isNew"
response="DELETE"
translate>
Delete
</button>
<button response="ACCEPT">
<span ng-if="$ctrl.isNew" translate>Add</span>
<span ng-if="!$ctrl.isNew" translate>Save</span>
</button>
</tpl-buttons>
</vn-dialog>
<vn-confirm

View File

@ -1,53 +1,27 @@
import ngModule from '../module';
import Section from 'core/lib/section';
import './style.scss';
import Component from 'core/lib/component';
class Controller extends Section {
constructor($el, $, $t, $http, $state) {
super($el, $, $t, $http, $state);
class Controller extends Component {
constructor($element, $, vnWeekDays) {
super($element, $);
this.vnWeekDays = vnWeekDays;
this.editMode = 'include';
this.wdays = [
{
code: 'mon',
name: 'Monday'
}, {
code: 'tue',
name: 'Tuesday'
}, {
code: 'wed',
name: 'Wednesday'
}, {
code: 'thu',
name: 'Thursday'
}, {
code: 'fri',
name: 'Friday'
}, {
code: 'sat',
name: 'Saturday'
}, {
code: 'sun',
name: 'Sunday'
}
];
this.abrWdays = {};
for (let wday of this.wdays) {
let locale = this._(wday.name);
this.abrWdays[wday.code] = locale.substr(0, 3);
wday.abr = locale.substr(0, 1);
}
this.$http.get(`/api/Zones/${this.$stateParams.id}/exclusions`)
.then(res => this.$.exclusions = res.data);
this.path = `/api/Zones/${this.$stateParams.id}/events`;
this.path = `api/Zones/${this.$params.id}/events`;
this.exclusionsPath = `api/Zones/${this.$params.id}/exclusions`;
this.refresh();
}
refresh() {
this.$http.get(this.path)
.then(res => this.$.data = res.data);
let data = {};
this.$q.all([
this.$http.get(this.path)
.then(res => data.events = res.data),
this.$http.get(this.exclusionsPath)
.then(res => data.exclusions = res.data)
]).finally(() => {
this.$.data = data;
});
}
formatWdays(weekDays) {
@ -55,16 +29,42 @@ class Controller extends Section {
let abrWdays = [];
for (let wday of weekDays.split(','))
abrWdays.push(this.abrWdays[wday]);
abrWdays.push(this.vnWeekDays.map[wday].localeAbr);
return abrWdays.length < 7
? abrWdays.join(', ')
: this._('Everyday');
}
onEdit(row, event) {
if (event.defaultPrevented) return;
onSelection(days, type, weekday, data) {
if (this.editMode == 'include') {
let dayData = data[0] || {};
let event = dayData.events && dayData.events[0];
if (event)
this.edit(event);
else
this.create(days, type, weekday);
} else {
let exclusions = [];
for (let dayData of data) {
if (dayData.exclusion)
exclusions.push(dayData.exclusion.id);
}
if (exclusions.length)
this.exclusionDelete(exclusions);
else
this.exclusionCreate(days);
}
}
onEditClick(row, event) {
if (event.defaultPrevented) return;
this.edit(row);
}
edit(row) {
this.isNew = false;
if (row.from && !row.to)
@ -86,67 +86,74 @@ class Controller extends Section {
this.$.dialog.show();
}
onCreate($day, $type, $weekday) {
create(days, type, weekday) {
this.isNew = true;
this.eventType = $type == 'day' ? 'day' : 'indefinitely';
this.eventType = type == 'day' ? 'day' : 'indefinitely';
if ($type == 'weekday') {
if (type == 'weekday') {
let wdays = [];
let index = $weekday - 1;
if (index < 0) index = 7 - index;
wdays[this.wdays[index].code] = true;
let code = this.vnWeekDays.days[weekday].code;
wdays[code] = true;
this.selected = {wdays};
} else
this.selected = {from: $day[0]};
this.selected = {from: days[0]};
this.$.dialog.show();
}
onSave(response) {
if (response != 'ACCEPT') return;
if (response == 'ACCEPT') {
let selected = this.selected;
let selected = this.selected;
if (this.eventType == 'indefinitely') {
selected.from = null;
selected.to = null;
}
if (this.eventType != 'day') {
let weekDays = [];
for (let wday in selected.wdays) {
if (selected.wdays[wday])
weekDays.push(wday);
if (this.eventType == 'indefinitely') {
selected.from = null;
selected.to = null;
}
selected.weekDays = weekDays.join(',');
} else {
selected.to = null;
selected.weekDays = '';
if (this.eventType != 'day') {
let weekDays = [];
for (let wday in selected.wdays) {
if (selected.wdays[wday])
weekDays.push(wday);
}
selected.weekDays = weekDays.join(',');
} else {
selected.to = null;
selected.weekDays = '';
}
let req;
if (this.isNew)
req = this.$http.post(this.path, selected);
else
req = this.$http.put(`${this.path}/${selected.id}`, selected);
req.then(() => {
this.selected = null;
this.isNew = null;
this.$.dialog.hide();
this.refresh();
});
return false;
} else if (response == 'DELETE') {
this.onDelete(this.selected.id);
return false;
}
let req;
if (this.isNew)
req = this.$http.post(this.path, selected);
else
req = this.$http.put(`${this.path}/${selected.id}`, selected);
req.then(() => {
this.selected = null;
this.isNew = null;
this.$.dialog.hide();
this.refresh();
});
return false;
}
onDelete(id, event) {
onDeleteClick(id, event) {
if (event.defaultPrevented) return;
event.preventDefault();
this.$.confirm.show();
this.onDelete(id);
}
onDelete(id) {
this.deleteId = id;
this.$.confirm.show();
}
delete(response) {
@ -156,9 +163,33 @@ class Controller extends Section {
.then(() => {
this.refresh();
this.deleteId = null;
this.$.dialog.hide();
});
}
exclusionCreate(days) {
let exclusions = days.map(day => {
return {day};
});
this.$http.post(this.exclusionsPath, exclusions)
.then(() => this.refresh());
}
exclusionDelete(ids) {
let promises = [];
for (let id of ids) {
promises.push(
this.$http.delete(`${this.exclusionsPath}/${id}`)
);
}
this.$q.all(promises)
.then(() => this.refresh());
}
}
Controller.$inject = ['$element', '$scope', 'vnWeekDays'];
ngModule.component('vnZoneEvents', {
template: require('./index.html'),

View File

@ -0,0 +1,4 @@
Edit mode: Modo de edición
Include: Incluir
Exclude: Excluir
Events: Eventos

View File

@ -1,28 +0,0 @@
@import "effects";
vn-zone-events {
.week-days {
margin-top: $spacing-sm;
margin-bottom: $spacing-md;
text-align: center;
& > span {
@extend %clickable;
border-radius: 50%;
padding: .4em;
margin: .2em;
display: inline-flex;
width: 1.5em;
height: 1.5em;
justify-content: center;
align-items: center;
outline: none;
background-color: rgba(0, 0, 0, .05);
&.marked {
background: $color-main;
color: $color-font-dark;
}
}
}
}

View File

@ -1,30 +0,0 @@
<div class="main-with-right-menu">
<vn-data-viewer
data="data"
is-loading="!data"
class="vn-w-xs">
<vn-card>
<vn-table>
<vn-tbody>
<vn-tr ng-repeat="row in data | orderBy:'day'">
<vn-td>{{::row.day | date:'dd/MM/yyyy'}}</vn-td>
<vn-td shrink>
<vn-icon-button
icon="delete"
translate-attr="{title: 'Delete'}"
ng-click="$ctrl.onDelete(row.id)">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
</vn-data-viewer>
</div>
<vn-side-menu side="right">
<vn-zone-calendar
events="events"
exclusions="data"
on-selection="$ctrl.onCreate($days)">
</vn-zone-calendar>
</vn-side-menu>

View File

@ -1,35 +0,0 @@
import ngModule from '../module';
import Section from 'core/lib/section';
class Controller extends Section {
constructor($el, $, $t, $http, $state) {
super($el, $, $t, $http, $state);
this.$http.get(`/api/Zones/${this.$stateParams.id}/events`)
.then(res => this.$.events = res.data);
this.path = `/api/Zones/${this.$stateParams.id}/exclusions`;
this.refresh();
}
refresh() {
this.$http.get(this.path)
.then(res => this.$.data = res.data);
}
onCreate($days) {
this.$http.post(this.path, {day: $days[0]})
.then(() => this.refresh());
}
onDelete(id) {
if (!id) return;
this.$http.delete(`${this.path}/${id}`)
.then(() => this.refresh());
}
}
ngModule.component('vnZoneExclusions', {
template: require('./index.html'),
controller: Controller
});

View File

@ -12,6 +12,5 @@ import './basic-data';
import './warehouses';
import './events';
import './calendar';
import './exclusions';
import './location';
import './calendar';

View File

@ -1,6 +1,6 @@
<vn-crud-model
vn-id="model"
url="/api/Zones/{{$ctrl.$stateParams.id}}/getLeaves"
url="/api/Zones/{{$ctrl.$params.id}}/getLeaves"
filter="::$ctrl.filter">
</vn-crud-model>
<div class="vn-w-md">
@ -19,6 +19,7 @@
ng-model="item.selected"
on-change="$ctrl.onSelection(value, item)"
triple-state="true"
ng-click="$event.preventDefault()"
label="{{::item.name}}">
</vn-check>
</vn-treeview>

View File

@ -1,8 +1,8 @@
import ngModule from '../module';
import Section from 'core/lib/section';
import Component from 'core/lib/component';
import './style.scss';
class Controller extends Section {
class Controller extends Component {
onSearch(params) {
this.$.model.applyFilter({}, params).then(() => {
const data = this.$.model.data;

View File

@ -8,8 +8,7 @@
{"state": "zone.card.basicData", "icon": "settings"},
{"state": "zone.card.location", "icon": "my_location"},
{"state": "zone.card.warehouses", "icon": "home"},
{"state": "zone.card.events", "icon": "today"},
{"state": "zone.card.exclusions", "icon": "block"}
{"state": "zone.card.events", "icon": "today"}
],
"routes": [
{
@ -65,11 +64,6 @@
"state": "zone.card.events",
"component": "vn-zone-events",
"description": "Calendar"
}, {
"url": "/exclusions",
"state": "zone.card.exclusions",
"component": "vn-zone-exclusions",
"description": "Exclusions"
}, {
"url": "/location?q",
"state": "zone.card.location",

View File

@ -1,11 +1,11 @@
import ngModule from '../module';
import Section from 'core/lib/section';
import Component from 'core/lib/component';
class Controller extends Section {
constructor($el, $, $t, $http, $state) {
super($el, $, $t, $http, $state);
class Controller extends Component {
constructor($element, $) {
super($element, $);
this.path = `/api/Zones/${this.$stateParams.id}/warehouses`;
this.path = `/api/Zones/${this.$params.id}/warehouses`;
this.refresh();
}

View File

@ -1,10 +1,14 @@
<vn-crud-model auto-load="true"
vn-id="model"
<vn-crud-model vn-id="model" auto-load="true" auto-save="true"
url="claim/api/ClaimEnds"
filter="$ctrl.filter"
data="$ctrl.salesClaimed">
</vn-crud-model>
<vn-crud-model auto-load="true"
url="/claim/api/ClaimDestinations"
data="claimDestinations">
</vn-crud-model>
<vn-card class="vn-mb-md vn-pa-lg vn-w-lg" style="text-align: right"
ng-if="$ctrl.salesClaimed.length > 0">
<vn-label-value label="Total claimed"
@ -28,7 +32,6 @@
translate-attr="{title: 'Imports ticket lines'}">
</vn-button>
<vn-range
vn-one
label="Responsability"
min-label="Company"
max-label="Sales/Client"
@ -82,14 +85,12 @@
</span>
</vn-td>
<vn-td>
<vn-autocomplete vn-one
id="claimDestinationFk"
<vn-autocomplete vn-one id="claimDestinationFk"
ng-model="saleClaimed.claimDestinationFk"
url="/claim/api/ClaimDestinations"
data="claimDestinations"
fields="['id','description']"
value-field="id"
show-field="description"
on-change="$ctrl.setClaimDestination(saleClaimed.id, value)">
show-field="description">
</vn-autocomplete>
</vn-td>
<vn-td>{{::saleClaimed.sale.ticket.landed | date: 'dd/MM/yyyy'}}</vn-td>

View File

@ -19,7 +19,8 @@ class Controller {
}
}
},
{relation: 'claimBeggining'}
{relation: 'claimBeggining'},
{relation: 'claimDestination'}
]
};
this.resolvedState = 3;
@ -82,16 +83,6 @@ class Controller {
this.calculateTotals();
}
setClaimDestination(id, claimDestinationFk) {
if (claimDestinationFk) {
let params = {id: id, claimDestinationFk: claimDestinationFk};
let query = `claim/api/ClaimEnds/`;
this.$http.patch(query, params).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
});
}
}
calculateTotals() {
this.claimedTotal = 0;
this.salesClaimed.forEach(sale => {

View File

@ -82,17 +82,6 @@ describe('claim', () => {
});
});
describe('setClaimDestination(id, claimDestinationFk)', () => {
it('should make a patch and call refresh and showSuccess', () => {
spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expectPATCH(`claim/api/ClaimEnds/`).respond({});
controller.setClaimDestination(1, 1);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
describe('calculateTotals()', () => {
it('should calculate the total price of the items claimed', () => {
controller.salesClaimed = [

View File

@ -29,10 +29,9 @@
</vn-textfield>
<vn-none>
<vn-icon-button
pointer
class="vn-my-md"
vn-tooltip="Remove contact"
icon="delete"
tabindex="-1"
ng-click="model.remove($index)">
</vn-icon-button>
</vn-none>

View File

@ -13,6 +13,10 @@ class Controller {
callback.call(this);
}
get client() {
return this._client;
}
set client(value) {
this._client = value;
@ -32,10 +36,6 @@ class Controller {
};
}
get client() {
return this._client;
}
set quicklinks(value = {}) {
this._quicklinks = Object.assign(value, this._quicklinks);
}

View File

@ -52,24 +52,31 @@ class Controller {
get freeLineIndex() {
let lines = this.$scope.model.data;
let currentDate = new Date();
currentDate.setHours(0, 0, 0);
let minDate = new Date();
minDate.setHours(0, 0, 0, 0);
let maxDate = new Date();
maxDate.setHours(23, 59, 59, 59);
for (let i = 0; i < lines.length; i++) {
let isFutureDate = new Date(lines[i].date) >= currentDate;
const dated = new Date(lines[i].date);
if (isFutureDate)
let isForFuture = dated > maxDate;
let isForToday = (dated >= minDate && dated <= maxDate);
if (isForFuture || isForToday)
return i;
}
}
get onPreparationLineIndex() {
let lines = this.$scope.model.data;
for (let i = this.freeLineIndex; i >= 0; i--) {
let line = lines[i];
let currentDate = new Date();
currentDate.setHours(0, 0, 0);
currentDate.setHours(0, 0, 0, 0);
let isPastDate = new Date(lines[i].date) < currentDate;
let isPicked = line.alertLevel == 1 && line.isPicked;
@ -95,6 +102,7 @@ class Controller {
let selectedTicketLineIndex = this.givenTicketIndex;
let lineIndex = this.onPreparationLineIndex;
let lines = body.querySelector('vn-tbody').children;
if (lineIndex == undefined || !lines.length) return;
@ -120,7 +128,6 @@ class Controller {
offsetTop = onPreparationLine.offsetTop - headerHeight;
this.$window.scrollTo(0, offsetTop);
this.ticketFk = null;
}

View File

@ -8,12 +8,11 @@
<div class="content-block">
<vn-card class="vn-pa-md vn-w-sm">
<vn-horizontal style="align-items: center;">
<vn-searchbar
<vn-searchbar vn-focus
panel="vn-item-search-panel"
on-search="$ctrl.onSearch($params)"
info="Search items by id, name or barcode"
suggested-filter="{isActive: true}"
vn-focus>
suggested-filter="{isActive: true}">
</vn-searchbar>
<vn-icon-menu
vn-id="more-button"

View File

@ -16,7 +16,7 @@
</vn-textfield>
<vn-autocomplete
vn-one
ng-model="filter.atenderFk"
ng-model="filter.attenderFk"
url="/client/api/Clients/activeWorkersWithRole"
search-function="{firstName: $search}"
value-field="id"

View File

@ -1,121 +1,116 @@
<vn-crud-model
<vn-crud-model auto-load="true"
vn-id="model"
url="/ticket/api/TicketRequests/filter"
limit="20"
data="requests"
order="isOk ASC"
auto-load="false">
order="shipped DESC, isOk ASC">
</vn-crud-model>
<form name="form">
<div class="vn-ma-md">
<vn-card class="vn-pa-md vn-list">
<vn-horizontal>
<vn-searchbar
auto-load="false"
panel="vn-request-search-panel"
on-search="$ctrl.onSearch($params)"
info="Search request by id or alias"
vn-one
vn-focus>
</vn-searchbar>
</vn-horizontal>
<vn-searchbar vn-one vn-focus
auto-load="false"
panel="vn-request-search-panel"
on-search="$ctrl.onSearch($params)"
info="Search request by id or alias"
suggested-filter="$ctrl.filter.where">
</vn-searchbar>
</vn-card>
<vn-card class="vn-my-md">
<vn-table model="model" auto-load="false">
<vn-thead>
<vn-tr>
<vn-th field="ticketFk" number>Ticket ID</vn-th>
<vn-th field="shipped">Shipped</vn-th>
<vn-th field="warehouse">Warehouse</vn-th>
<vn-th field="salesPersonNickname">SalesPerson</vn-th>
<vn-th field="description">Description</vn-th>
<vn-th field="quantity" number editable>Quantity</vn-th>
<vn-th field="price" number>Price</vn-th>
<vn-th field="atenderNickname">Atender</vn-th>
<vn-th field="itemFk">Item</vn-th>
<vn-th field="description">Concept</vn-th>
<vn-th field="saleQuantity" number>Sale quantity</vn-th>
<vn-th field="isOk">State</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="request in requests">
<vn-td number>
<span class="link"
ng-click="$ctrl.showTicketDescriptor($event, request.ticketFk)">
{{request.ticketFk}}
</span>
</vn-td>
<vn-td>
<span title="{{::request.shipped | date: 'dd/MM/yyyy'}}"
class="chip {{$ctrl.compareDate(request.shipped)}}">
{{::request.shipped | date: 'dd/MM/yyyy'}}
</span>
</vn-td>
<vn-td>{{::request.warehouse}}</vn-td>
<vn-td>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, request.salesPersonFk)">
{{::request.salesPersonNickname}}
</span>
</vn-td>
<vn-td title="{{::request.description}}">{{::request.description}}</vn-td>
<vn-td number>{{::request.quantity}}</vn-td>
<vn-td number>{{::request.price | currency: 'EUR':2}}</vn-td>
<vn-td>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, request.atenderFk)">
{{::request.atenderNickname}}
</span>
</vn-td>
<vn-td-editable disabled="request.isOk === 0" number>
<text>{{request.itemFk}}</text>
<field>
<vn-input-number
ng-model="request.itemFk"
on-change="$ctrl.confirmRequest(request)">
</vn-input-number>
</field>
</vn-td-editable>
<vn-td>
<span
class="link"
ng-click="$ctrl.showItemDescriptor($event, request.itemFk)"
title="{{::request.itemDescription}}">
{{::request.itemDescription}}
</span>
</vn-td>
<vn-td-editable disabled="request.isOk === 0" number>
<text number>{{request.saleQuantity}}</text>
<field>
<vn-input-number
ng-model="request.saleQuantity"
on-change="$ctrl.changeQuantity(request)">
</vn-input-number>
</field>
</vn-td-editable>
<vn-td>{{::$ctrl.getState(request.isOk)}}</vn-td>
<vn-td>
<vn-icon
ng-if="request.response.length"
vn-tooltip="{{request.response}}"
icon="insert_drive_file">
</vn-icon>
<vn-icon-button
ng-if="request.isOk != 0"
number
icon="thumb_down"
ng-click="$ctrl.showDenyReason($event, request.id)"
vn-tooltip="Discard">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
<vn-pagination model="model"></vn-pagination>
<vn-data-viewer model="model" class="vn-my-md">
<vn-card>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th field="ticketFk" number>Ticket ID</vn-th>
<vn-th field="shipped">Shipped</vn-th>
<vn-th field="warehouse">Warehouse</vn-th>
<vn-th field="salesPersonNickname">SalesPerson</vn-th>
<vn-th field="description">Description</vn-th>
<vn-th field="quantity" number editable>Requested</vn-th>
<vn-th field="price" number>Price</vn-th>
<vn-th field="atenderNickname">Atender</vn-th>
<vn-th field="itemFk">Item</vn-th>
<vn-th field="saleQuantity">Achieved</vn-th>
<vn-th field="description">Concept</vn-th>
<vn-th field="isOk">State</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="request in requests">
<vn-td number>
<span class="link"
ng-click="$ctrl.showTicketDescriptor($event, request.ticketFk)">
{{request.ticketFk}}
</span>
</vn-td>
<vn-td>
<span title="{{::request.shipped | date: 'dd/MM/yyyy'}}"
class="chip {{$ctrl.compareDate(request.shipped)}}">
{{::request.shipped | date: 'dd/MM/yyyy'}}
</span>
</vn-td>
<vn-td>{{::request.warehouse}}</vn-td>
<vn-td>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, request.salesPersonFk)">
{{::request.salesPersonNickname}}
</span>
</vn-td>
<vn-td title="{{::request.description}}">{{::request.description}}</vn-td>
<vn-td number>{{::request.quantity}}</vn-td>
<vn-td number>{{::request.price | currency: 'EUR':2}}</vn-td>
<vn-td>
<span
class="link"
ng-click="$ctrl.showWorkerDescriptor($event, request.attenderFk)">
{{::request.atenderNickname}}
</span>
</vn-td>
<vn-td-editable disabled="request.isOk != null" number>
<text>{{request.itemFk}}</text>
<field>
<vn-input-number class="dense" vn-focus
ng-model="request.itemFk">
</vn-input-number>
</field>
</vn-td-editable>
<vn-td-editable disabled="!request.itemFk || request.isOk != null" number>
<text number>{{request.saleQuantity}}</text>
<field>
<vn-input-number class="dense" vn-focus
ng-model="request.saleQuantity"
on-change="$ctrl.changeQuantity(request)">
</vn-input-number>
</field>
</vn-td-editable>
<vn-td>
<span
class="link"
ng-click="$ctrl.showItemDescriptor($event, request.itemFk)"
title="{{request.itemDescription}}">
{{request.itemDescription}}
</span>
</vn-td>
<vn-td>{{$ctrl.getState(request.isOk)}}</vn-td>
<vn-td>
<vn-icon
ng-if="request.response.length"
ranslate-attr="{title: request.response}"
icon="insert_drive_file">
</vn-icon>
<vn-icon-button
ng-if="request.isOk != 0"
icon="thumb_down"
ng-click="$ctrl.showDenyReason($event, request)"
translate-attr="{title: 'Discard'}">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
</vn-data-viewer>
</div>
</form>
<vn-worker-descriptor-popover
@ -129,21 +124,17 @@
</vn-item-descriptor-popover>
<vn-dialog
vn-id="denyReason"
class="modal-form">
on-response="$ctrl.denyRequest(response)">
<tpl-body>
<vn-horizontal class="header">
<h5><span translate>Indicate the reasons to deny this request</span></h5>
</vn-horizontal>
<h5 class="vn-pa-md" translate>Specify the reasons to deny this request</h5>
<vn-horizontal class="vn-pa-md">
<vn-textarea
ng-model="$ctrl.denyObservation">
</vn-textarea>
</vn-horizontal>
<vn-horizontal class="vn-pa-md">
<vn-button
label="Save"
ng-click="$ctrl.denyRequest()">
</vn-button>
</vn-horizontal>
</tpl-body>
<tpl-buttons>
<input type="button" response="CANCEL" translate-attr="{value: 'Cancel'}"/>
<button response="ACCEPT" translate>Save</button>
</tpl-buttons>
</vn-dialog>

View File

@ -1,16 +1,28 @@
import ngModule from '../module';
import Component from 'core/lib/component';
import './style.scss';
export default class Controller {
constructor($, vnApp, $translate, $http, $state, $stateParams) {
this.$state = $state;
this.$stateParams = $stateParams;
this.$http = $http;
this.$ = $;
this.vnApp = vnApp;
this._ = $translate;
if (!$stateParams.q)
this.filter = {isOk: false, mine: true};
export default class Controller extends Component {
constructor($element, $) {
super($element, $);
if (!this.$state.q) {
const today = new Date();
today.setHours(23, 59, 59, 59);
const lastWeek = new Date();
lastWeek.setHours(0, 0, 0, 0);
lastWeek.setDate(lastWeek.getDate() - 7);
this.filter = {
where: {
isOk: false,
mine: true,
from: lastWeek,
to: today
}
};
}
}
$postLink() {
@ -21,7 +33,7 @@ export default class Controller {
getState(isOk) {
if (isOk === null)
return 'Nueva';
else if (isOk === -1 || isOk === 1)
else if (isOk === -1 || isOk)
return 'Aceptada';
else
return 'Denegada';
@ -34,14 +46,12 @@ export default class Controller {
quantity: request.saleQuantity
};
let endpoint = `/api/TicketRequests/${request.id}/confirm`;
let query = `/api/TicketRequests/${request.id}/confirm`;
this.$http.post(query, params).then(res => {
request.itemDescription = res.data.concept;
request.isOk = true;
this.$http.post(endpoint, params).then(() => {
this.vnApp.showSuccess(this._.instant('Data saved!'));
this.$.model.refresh();
}).catch( e => {
this.$.model.refresh();
throw e;
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
}
@ -55,11 +65,8 @@ export default class Controller {
let endpoint = `/api/Sales/${request.saleFk}/`;
this.$http.patch(endpoint, params).then(() => {
this.vnApp.showSuccess(this._.instant('Data saved!'));
}).catch( e => {
this.$.model.refresh();
throw e;
});
this.vnApp.showSuccess(this.$t('Data saved!'));
}).then(() => this.confirmRequest(request));
} else
this.confirmRequest(request);
}
@ -86,7 +93,7 @@ export default class Controller {
}
showDenyReason(event, requestId) {
this.denyRequestId = requestId;
this.selectedRequest = requestId;
this.$.denyReason.parent = event.target;
this.$.denyReason.show();
document.querySelector('vn-item-request vn-textarea textArea').focus();
@ -96,17 +103,21 @@ export default class Controller {
delete this.denyRequestId;
}
denyRequest() {
denyRequest(response) {
if (response !== 'ACCEPT') return;
let params = {
observation: this.denyObservation
};
let endpoint = `/api/TicketRequests/${this.denyRequestId}/deny`;
let query = `/api/TicketRequests/${this.selectedRequest.id}/deny`;
this.$http.post(query, params).then(res => {
const request = res.data;
this.selectedRequest.isOk = request.isOk;
this.selectedRequest.attenderFk = request.attenderFk;
this.selectedRequest.response = request.response;
this.$http.post(endpoint, params).then(() => {
this.vnApp.showSuccess(this._.instant('Data saved!'));
this.$.model.refresh();
this.$.denyReason.hide();
this.vnApp.showSuccess(this.$t('Data saved!'));
this.denyObservation = null;
});
}
@ -140,8 +151,6 @@ export default class Controller {
}
}
Controller.$inject = ['$scope', 'vnApp', '$translate', '$http', '$state', '$stateParams'];
ngModule.component('vnItemRequest', {
template: require('./index.html'),
controller: Controller

View File

@ -4,6 +4,7 @@ import crudModel from 'core/mocks/crud-model';
describe('Item', () => {
describe('Component vnItemRequest', () => {
let $scope;
let $element;
let controller;
let $httpBackend;
@ -16,9 +17,15 @@ describe('Item', () => {
$scope = $rootScope.$new();
$scope.model = crudModel;
$scope.denyReason = {hide: () => {}};
controller = $componentController('vnItemRequest', {$scope: $scope});
$element = angular.element('<vn-item-request></vn-item-request>');
controller = $componentController('vnItemRequest', {$element, $scope});
}));
afterAll(() => {
$scope.$destroy();
$element.remove();
});
describe('getState()', () => {
it(`should return an string depending to the isOK value`, () => {
let isOk = null;
@ -53,15 +60,15 @@ describe('Item', () => {
let model = controller.$.model;
spyOn(model, 'refresh');
const expectedResult = {concept: 'Melee Weapon'};
let request = {itemFk: 1, saleQuantity: 1, id: 1};
$httpBackend.when('POST', `/api/TicketRequests/${request.id}/confirm`).respond();
$httpBackend.expect('POST', `/api/TicketRequests/${request.id}/confirm`).respond();
$httpBackend.when('POST', `/api/TicketRequests/${request.id}/confirm`).respond(expectedResult);
$httpBackend.expect('POST', `/api/TicketRequests/${request.id}/confirm`).respond(expectedResult);
controller.confirmRequest(request);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect($scope.model.refresh).toHaveBeenCalledWith();
});
});
@ -110,20 +117,17 @@ describe('Item', () => {
describe('denyRequest()', () => {
it(`should perform a query and call vnApp.showSuccess(), refresh(), hide() and set denyObservation to null in the controller`, () => {
spyOn(controller.vnApp, 'showSuccess');
let model = controller.$.model;
spyOn(model, 'refresh');
spyOn(controller.$.denyReason, 'hide');
controller.denyRequestId = 1;
const request = {id: 1};
const expectedResult = {isOk: false, attenderFk: 106, response: 'Denied!'};
controller.selectedRequest = request;
$httpBackend.when('POST', `/api/TicketRequests/${controller.denyRequestId}/deny`).respond();
$httpBackend.expect('POST', `/api/TicketRequests/${controller.denyRequestId}/deny`).respond();
controller.denyRequest();
$httpBackend.when('POST', `/api/TicketRequests/${request.id}/deny`).respond(expectedResult);
$httpBackend.expect('POST', `/api/TicketRequests/${request.id}/deny`).respond(expectedResult);
controller.denyRequest('ACCEPT');
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect($scope.model.refresh).toHaveBeenCalledWith();
expect($scope.denyReason.hide).toHaveBeenCalledWith();
});
});
});

View File

@ -1,5 +1,6 @@
Discard: Descartar
Indicate the reasons to deny this request: Indique las razones para descartar esta peticion
Specify the reasons to deny this request: Especifica las razones para descartar la petición
Buy requests: Peticiones de compra
Search request by id or alias: Buscar peticiones por identificador o alias
Sale quantity: C. conseguida
Requested: Solicitado
Achieved: Conseguido

View File

@ -28,12 +28,6 @@ module.exports = Self => {
fields: ['id', 'packages', 'warehouseFk', 'nickname', 'clientFk', 'priority', 'addressFk'],
order: 'priority',
include: [
{
relation: 'client',
scope: {
fields: ['id', 'street', 'postcode'],
}
},
{
relation: 'state',
scope: {

View File

@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Route getSelectedItems() should return the selected items 1`] = `
Array [
Object {
"checked": true,
"id": 1,
},
Object {
"checked": true,
"id": 3,
},
Object {
"checked": true,
"id": 5,
},
]
`;

View File

@ -1,104 +1,105 @@
<vn-crud-model
vn-id="model"
url="/api/Routes/{{$ctrl.$stateParams.id}}/getTickets"
url="api/Routes/{{$ctrl.$stateParams.id}}/getTickets"
order="priority ASC"
data="$ctrl.tickets"
auto-load="true">
</vn-crud-model>
<form name="form">
<vn-card class="vn-pa-lg">
<vn-tool-bar class="vn-mb-sm">
<vn-button
icon="icon-wand"
ng-click="$ctrl.guessPriority()"
vn-tooltip="Sort routes">
</vn-button>
<vn-button
disabled="!$ctrl.isChecked"
ng-click="$ctrl.goToBuscaman()"
vn-tooltip="Open buscaman"
tooltip-position="up"
icon="icon-buscaman">
</vn-button>
</vn-tool-bar>
<vn-icon-button
vn-tooltip="Load more"
ng-click="$ctrl.goToBuscaman()">
</vn-icon-button>
<vn-table model="model" auto-load="false">
<vn-thead>
<vn-tr>
<vn-th shrink>
<vn-multi-check
model="model">
</vn-multi-check>
</vn-th>
<vn-th>Order</vn-th>
<vn-th number>Ticket</vn-th>
<vn-th>Client</vn-th>
<vn-th number shrink>Packages</vn-th>
<vn-th shrink></vn-th>
<vn-th shrink>Warehouse</vn-th>
<vn-th shrink>PC</vn-th>
<vn-th>Street</vn-th>
<vn-th shrink></vn-th>
<vn-th shrink></vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="ticket in $ctrl.tickets">
<vn-td shrink>
<vn-check
ng-model="ticket.checked">
</vn-check>
</vn-td>
<vn-td>
<vn-input-number
on-change="$ctrl.setPriority(ticket.id, ticket.priority)"
ng-model="ticket.priority"
rule="Ticket">
</vn-input-number>
</vn-td>
<vn-td number>
<span
ng-click="$ctrl.showTicketDescriptor($event, ticket.id)"
class="link">
{{ticket.id}}
</span>
</vn-td>
<vn-td>
<span
ng-click="$ctrl.showClientDescriptor($event, ticket.clientFk)"
class="link">
{{ticket.nickname}}
</span>
</vn-td>
<vn-td number shrink>{{ticket.packages}}</vn-td>
<vn-td shrink>{{ticket.volume}}</vn-td>
<vn-td shrink>{{ticket.warehouse.name}}</vn-td>
<vn-td shrink>{{ticket.client.postcode}}</vn-td>
<vn-td expand title="{{ticket.client.street}}">{{ticket.client.street}}</vn-td>
<vn-td shrink>
<vn-icon-button
ng-if="ticket.notes.length"
title="::{{ticket.notes[0].description}}"
icon="insert_drive_file">
</vn-icon-button>
</vn-td>
<vn-td>
<vn-icon-button
translate-attr="::{title: 'Remove ticket'}"
icon="delete"
ng-click="$ctrl.showDeleteConfirm(ticket.id)"
tabindex="-1">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
</form>
<vn-data-viewer model="model">
<form name="form">
<vn-card class="vn-pa-lg">
<vn-tool-bar class="vn-mb-sm">
<vn-button
icon="icon-wand"
ng-click="$ctrl.guessPriority()"
vn-tooltip="Sort routes">
</vn-button>
<vn-button
disabled="!$ctrl.isChecked"
ng-click="$ctrl.goToBuscaman()"
vn-tooltip="Open buscaman"
tooltip-position="up"
icon="icon-buscaman">
</vn-button>
</vn-tool-bar>
<vn-icon-button
vn-tooltip="Load more"
ng-click="$ctrl.goToBuscaman()">
</vn-icon-button>
<vn-table model="model" auto-load="false">
<vn-thead>
<vn-tr>
<vn-th shrink>
<vn-multi-check
model="model">
</vn-multi-check>
</vn-th>
<vn-th>Order</vn-th>
<vn-th number>Ticket</vn-th>
<vn-th>Client</vn-th>
<vn-th number shrink>Packages</vn-th>
<vn-th shrink></vn-th>
<vn-th shrink>Warehouse</vn-th>
<vn-th expand>Postcode</vn-th>
<vn-th>Street</vn-th>
<vn-th shrink></vn-th>
<vn-th shrink></vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="ticket in $ctrl.tickets">
<vn-td shrink>
<vn-check
ng-model="ticket.checked">
</vn-check>
</vn-td>
<vn-td>
<vn-input-number
on-change="$ctrl.setPriority(ticket.id, ticket.priority)"
ng-model="ticket.priority"
rule="Ticket">
</vn-input-number>
</vn-td>
<vn-td number>
<span
ng-click="$ctrl.showTicketDescriptor($event, ticket.id)"
class="link">
{{ticket.id}}
</span>
</vn-td>
<vn-td>
<span
ng-click="$ctrl.showClientDescriptor($event, ticket.clientFk)"
class="link">
{{ticket.nickname}}
</span>
</vn-td>
<vn-td number shrink>{{ticket.packages}}</vn-td>
<vn-td shrink>{{ticket.volume}}</vn-td>
<vn-td shrink>{{ticket.warehouse.name}}</vn-td>
<vn-td number shrink>{{ticket.address.postalCode}}</vn-td>
<vn-td expand title="{{ticket.address.street}}">{{ticket.address.street}}</vn-td>
<vn-td shrink>
<vn-icon-button
ng-if="ticket.notes.length"
title="::{{ticket.notes[0].description}}"
icon="insert_drive_file">
</vn-icon-button>
</vn-td>
<vn-td>
<vn-icon-button
translate-attr="::{title: 'Remove ticket'}"
icon="delete"
ng-click="$ctrl.showDeleteConfirm(ticket.id)"
tabindex="-1">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-card>
</form>
</vn-data-viewer>
<vn-ticket-descriptor-popover
vn-id="ticketDescriptor">
</vn-ticket-descriptor-popover>
@ -109,4 +110,72 @@
vn-id="confirm"
question="Delete ticket from route?"
on-response="$ctrl.removeTicketFromRoute(response)">
</vn-confirm>
</vn-confirm>
<vn-crud-model
vn-id="possibleTicketsModel"
url="api/Tickets"
filter="$ctrl.possibleTicketsFilter"
data="$ctrl.possibleTickets">
</vn-crud-model>
<vn-dialog
vn-id="possibleTicketsDialog"
on-response="$ctrl.setTicketsRoute(response)">
<tpl-body>
<section class="header vn-pa-md">
<h5><span translate>Tickets to add</span></h5>
</section>
<vn-data-viewer class="vn-pa-md" model="possibleTicketsModel">
<vn-table model="possibleTicketsModel" auto-load="false">
<vn-thead>
<vn-tr>
<vn-th shrink>
<vn-multi-check
model="possibleTicketsModel">
</vn-multi-check>
</vn-th>
<vn-th number>Ticket</vn-th>
<vn-th>Client</vn-th>
<vn-th number shrink>Packages</vn-th>
<vn-th shrink>Warehouse</vn-th>
<vn-th expand>Postcode</vn-th>
<vn-th>Address</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="ticket in $ctrl.possibleTickets">
<vn-td shrink>
<vn-check
ng-model="ticket.checked">
</vn-check>
</vn-td>
<vn-td number>{{ticket.id}}</vn-td>
<vn-td number>
<span
ng-click="$ctrl.showClientDescriptor($event, ticket.clientFk)"
class="link">
{{ticket.nickname}}
</span>
</vn-td>
<vn-td number shrink>{{ticket.packages}}</vn-td>
<vn-td expand>{{ticket.warehouse.name}}</vn-td>
<vn-td number shrink>{{ticket.address.postalCode}}</vn-td>
<vn-td expand title="{{ticket.address.street}}">{{ticket.address.street}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-data-viewer>
</tpl-body>
<tpl-buttons>
<input type="button" response="CANCEL" translate-attr="{value: 'Cancel'}"/>
<button response="ACCEPT" translate>Add</button>
</tpl-buttons>
</vn-dialog>
<vn-float-button
icon="add"
ng-click="$ctrl.openPossibleTicketsDialog()"
vn-tooltip="Add ticket"
vn-acl="delivery"
vn-acl-action="remove"
vn-bind="+"
fixed-bottom-right>
</vn-float-button>

View File

@ -2,12 +2,23 @@ import ngModule from '../module';
import './style.scss';
class Controller {
constructor($stateParams, $, $translate, $http, vnApp) {
constructor($stateParams, $scope, $translate, $http, vnApp, $filter) {
this.$translate = $translate;
this.$stateParams = $stateParams;
this.$ = $;
this.$ = $scope;
this.$http = $http;
this.vnApp = vnApp;
this.$filter = $filter;
}
set route(value) {
this._route = value;
if (value)
this.buildPossibleTicketsFilter();
}
get route() {
return this._route;
}
get isChecked() {
@ -19,13 +30,37 @@ class Controller {
return false;
}
buildPossibleTicketsFilter() {
let minDate = new Date(this.route.finished);
minDate.setHours(0, 0, 0, 0);
let maxDate = new Date(this.route.finished);
maxDate.setHours(23, 59, 59, 59);
this.possibleTicketsFilter = {
where: {
zoneFk: this.route.zoneFk,
routeFk: null,
landed: {between: [minDate, maxDate]},
},
include: [
{
relation: 'warehouse',
scope: {
fields: ['name']
},
}, {
relation: 'address'
}
]
};
}
getHighestPriority() {
let max = 0;
this.$.model.data.forEach(tag => {
if (tag.priority > max)
max = tag.priority;
});
return max + 1;
let highestPriority = Math.max(...this.$.model.data.map(tag => {
return tag.priority;
}));
return highestPriority + 1;
}
setPriority(id, priority) {
@ -37,16 +72,16 @@ class Controller {
});
}
getCheckedLines() {
let lines = [];
let data = this.tickets;
if (data) {
for (let i = 0; i < data.length; i++) {
if (data[i].checked)
lines.push(data[i]);
getSelectedItems(items) {
const selectedItems = [];
if (items) {
for (let i = 0; i < items.length; i++) {
if (items[i].checked)
selectedItems.push(items[i]);
}
}
return lines;
return selectedItems;
}
goToBuscaman() {
@ -54,7 +89,7 @@ class Controller {
let firstAddress = `46460 Av Espioca 100-46460 Silla`;
let addresses = firstAddress;
let lines = this.getCheckedLines();
let lines = this.getSelectedItems(this.tickets);
let url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
lines.forEach(line => {
@ -64,8 +99,8 @@ class Controller {
window.open(url + addresses, '_blank');
}
showDeleteConfirm(ticket) {
this.selectedTicket = ticket;
showDeleteConfirm(id) {
this.selectedTicket = id;
this.$.confirm.show();
}
@ -109,14 +144,38 @@ class Controller {
this.$.clientDescriptor.show();
event.preventDefault();
}
openPossibleTicketsDialog() {
this.$.possibleTicketsModel.refresh();
this.$.possibleTicketsDialog.show();
}
setTicketsRoute(response) {
if (response === 'ACCEPT') {
let tickets = this.getSelectedItems(this.possibleTickets);
for (let i = 0; i < tickets.length; i++) {
delete tickets[i].checked;
tickets[i].routeFk = this.route.id;
}
return this.$.possibleTicketsModel.save().then(() => {
this.$.model.data = this.$.model.data.concat(tickets);
});
}
return Promise.resolve();
}
}
Controller.$inject = ['$stateParams', '$scope', '$translate', '$http', 'vnApp'];
Controller.$inject = ['$stateParams', '$scope', '$translate', '$http', 'vnApp', '$filter'];
ngModule.component('vnRouteTickets', {
template: require('./index.html'),
controller: Controller,
require: {
card: '^vnRouteCard'
},
controller: Controller
bindings: {
route: '<'
}
});

View File

@ -0,0 +1,288 @@
import './index.js';
describe('Route', () => {
let controller;
let $httpBackend;
beforeEach(angular.mock.module('route', $translateProvider => {
$translateProvider.translations('en', {});
}));
beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnRouteTickets');
}));
describe('route setter/getter', () => {
it('should return the route id', () => {
controller.route = 2;
expect(controller.route).toEqual(2);
});
});
describe('isChecked getter', () => {
it('should return false if none of the tickets is checked or there are no tickets', () => {
expect(controller.isChecked).toBeFalsy();
});
it('should return true if any of the tickets is checked', () => {
controller.tickets = [{checked: true}];
expect(controller.isChecked).toBeTruthy();
});
});
describe('buildPossibleTicketsFilter()', () => {
it('should build the possible tickets filter', () => {
let expectedFilter = {
include: [
{
relation: 'warehouse',
scope: {
fields: ['name']
}
}, {
relation: 'address'
}
],
where: {
landed: {
between: [
jasmine.any(Date),
jasmine.any(Date)
]
},
routeFk: null,
zoneFk: 67
}
};
controller.route = {
finished: new Date(),
routeFk: null,
zoneFk: 67
};
controller.buildPossibleTicketsFilter();
expect(controller.possibleTicketsFilter).toEqual(expectedFilter);
});
});
describe('getHighestPriority()', () => {
it('should return the highest value found in priorities plus 1', () => {
controller.$.model = {data: [
{priority: 99},
{priority: 1},
{priority: 2},
{priority: 3},
{priority: 4},
{priority: 5},
]};
let result = controller.getHighestPriority();
expect(result).toEqual(100);
});
});
describe('setPriority()', () => {
it('should set a ticket priority', () => {
controller.$.model = {refresh: () => {}};
spyOn(controller.$.model, 'refresh');
spyOn(controller.vnApp, 'showSuccess');
const ticketId = 1;
const priority = 999;
$httpBackend.expectPATCH(`/api/Tickets/${ticketId}/`).respond('ok');
controller.setPriority(ticketId, priority);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
describe('getSelectedItems()', () => {
it('should return the selected items', () => {
let items = [
{id: 1, checked: true},
{id: 2, checked: false},
{id: 3, checked: true},
{id: 4, checked: false},
{id: 5, checked: true},
];
let selectedItems = controller.getSelectedItems(items);
expect(selectedItems).toMatchSnapshot();
});
});
describe('goToBuscaman()', () => {
it('should open buscaman with the given arguments', () => {
spyOn(window, 'open');
const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460 Av Espioca 100-46460 Silla+to:n19 my street-n19 London';
controller.tickets = [
{
id: 1,
checked: true,
address: {
street: 'my street',
postalCode: 'n19',
city: 'London'
}
},
];
controller.goToBuscaman();
expect(window.open).toHaveBeenCalledWith(expectedUrl, '_blank');
});
});
describe('showDeleteConfirm()', () => {
it('should open a confirm dialog after setting the selected ticket into the controller', () => {
controller.$.confirm = {show: () => {}};
spyOn(controller.$.confirm, 'show');
let ticketId = 1;
controller.showDeleteConfirm(ticketId);
expect(controller.selectedTicket).toEqual(ticketId);
expect(controller.$.confirm.show).toHaveBeenCalledWith();
});
});
describe('removeTicketFromRoute()', () => {
it('should perform a patch query then call showSuccess and updateVolume methods', () => {
spyOn(controller, 'updateVolume');
spyOn(controller.vnApp, 'showSuccess');
let ticketId = 1;
controller.selectedTicket = ticketId;
$httpBackend.expectPATCH(`/api/Tickets/${ticketId}/`).respond('ok');
controller.removeTicketFromRoute('ACCEPT');
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket removed from route');
expect(controller.updateVolume).toHaveBeenCalledWith();
});
});
describe('updateVolume()', () => {
it('should perform a POST query then call both reload and refresh methods', () => {
controller.$.model = {refresh: () => {}};
controller.card = {reload: () => {}};
controller.$stateParamds = {id: 999};
spyOn(controller.$.model, 'refresh');
spyOn(controller.card, 'reload');
let ticketId = 1;
controller.selectedTicket = ticketId;
const url = `/route/api/Routes/${controller.$stateParams.id}/updateVolume`;
$httpBackend.expectPOST(url).respond('ok');
controller.updateVolume();
$httpBackend.flush();
expect(controller.$.model.refresh).toHaveBeenCalledWith();
expect(controller.card.reload).toHaveBeenCalledWith();
});
});
describe('guessPriority()', () => {
it('should perform a GET query then call both refresh and showSuccess methods', () => {
controller.$.model = {refresh: () => {}};
spyOn(controller.$.model, 'refresh');
spyOn(controller.vnApp, 'showSuccess');
controller.$stateParams = {id: 99};
const url = `/api/Routes/${controller.$stateParams.id}/guessPriority/`;
$httpBackend.expectGET(url).respond('ok');
controller.guessPriority();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Order changed');
expect(controller.$.model.refresh).toHaveBeenCalledWith();
});
});
describe('showTicketDescriptor()', () => {
it('should call the descriptor show function after setting the parent and the ticket id', () => {
controller.$.ticketDescriptor = {show: () => {}};
spyOn(controller.$.ticketDescriptor, 'show');
const event = {target: {}, preventDefault: () => {}};
spyOn(event, 'preventDefault');
const ticketId = 999;
controller.showTicketDescriptor(event, ticketId);
expect(controller.$.ticketDescriptor.ticketFk).toEqual(ticketId);
expect(controller.$.ticketDescriptor.show).toHaveBeenCalledWith();
expect(event.preventDefault).toHaveBeenCalledWith();
});
});
describe('showClientDescriptor()', () => {
it('should call the descriptor show method after setting the parent and the client id', () => {
controller.$.clientDescriptor = {show: () => {}};
spyOn(controller.$.clientDescriptor, 'show');
const event = {target: {}, preventDefault: () => {}};
spyOn(event, 'preventDefault');
const clientId = 999;
controller.showClientDescriptor(event, clientId);
expect(controller.$.clientDescriptor.clientFk).toEqual(clientId);
expect(controller.$.clientDescriptor.show).toHaveBeenCalledWith();
expect(event.preventDefault).toHaveBeenCalledWith();
});
});
describe('openPossibleTicketsDialog()', () => {
it('should call both refresh and show methods in posible tickets model and dialog', () => {
controller.$.possibleTicketsModel = {refresh: () => {}};
spyOn(controller.$.possibleTicketsModel, 'refresh');
controller.$.possibleTicketsDialog = {show: () => {}};
spyOn(controller.$.possibleTicketsDialog, 'show');
controller.openPossibleTicketsDialog();
expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith();
expect(controller.$.possibleTicketsDialog.show).toHaveBeenCalledWith();
});
});
describe('setTicketsRoute()', () => {
it('should perform a POST query to add tickets to the route', done => {
controller.$.possibleTicketsModel = {save: () => {}};
spyOn(controller.$.possibleTicketsModel, 'save').and.returnValue(Promise.resolve());
controller.$.model = {data: [
{id: 1, checked: false}
]};
controller.route = {id: 111};
controller.possibleTickets = [
{id: 2, checked: false},
{id: 3, checked: true},
{id: 4, checked: false},
{id: 5, checked: true},
];
let expectedResult = [
{checked: false, id: 1},
{id: 3, routeFk: 111},
{id: 5, routeFk: 111}
];
controller.setTicketsRoute('ACCEPT').then(() => {
expect(controller.$.model.data).toEqual(expectedResult);
done();
}).catch(done.fail);
});
it('should just return a promise', () => {
expect(controller.setTicketsRoute('CANCEL')).toEqual(jasmine.any(Promise));
});
});
});

View File

@ -3,4 +3,6 @@ Open buscaman: Abrir buscaman
Ticket removed from route: Ticket borrado de la ruta
Order changed: Orden cambiado
Delete ticket from route?: ¿Borrar ticket de la ruta?
Sort routes: Ordenar rutas
Sort routes: Ordenar rutas
Add ticket: Añadir ticket
Tickets to add: Tickets a añadir

View File

@ -38,27 +38,27 @@ module.exports = Self => {
try {
let options = {transaction: tx};
let item = await models.Item.findById(ctx.args.itemFk);
let item = await models.Item.findById(ctx.args.itemFk, null, options);
if (!item)
throw new UserError(`That item doesn't exists`);
let request = await models.TicketRequest.findById(ctx.args.id, {
include: {relation: 'ticket'}
});
}, options);
let [[stock]] = await Self.rawSql(`CALL vn.getItemVisibleAvailable(?,?,?,?)`, [
ctx.args.itemFk,
request.ticket().shipped,
request.ticket().warehouseFk,
false
]);
], options);
if (stock.available < 0)
throw new UserError(`This item is not available`);
if (request.saleFk) {
sale = await models.Sale.findById(request.saleFk);
sale = await models.Sale.findById(request.saleFk, null, options);
sale.updateAttributes({
itemFk: ctx.args.itemFk,
quantity: ctx.args.quantity,
@ -71,7 +71,11 @@ module.exports = Self => {
quantity: ctx.args.quantity,
concept: item.name
}, options);
request.updateAttributes({saleFk: sale.id, itemFk: sale.itemFk, isOk: true}, options);
request.updateAttributes({
saleFk: sale.id,
itemFk: sale.itemFk,
isOk: true
}, options);
}
query = `CALL vn.ticketCalculateSale(?)`;
@ -86,6 +90,8 @@ module.exports = Self => {
}, options);
await tx.commit();
return sale;
} catch (error) {
await tx.rollback();
throw error;

View File

@ -29,7 +29,7 @@ module.exports = Self => {
let params = {
isOk: false,
atenderFk: worker.id,
attenderFk: worker.id,
response: ctx.args.observation,
};

View File

@ -28,7 +28,7 @@ module.exports = Self => {
type: 'Number',
description: `Search by warehouse`
}, {
arg: 'atenderFk',
arg: 'attenderFk',
type: 'Number',
description: `Search requests atended by the given worker`
}, {
@ -65,7 +65,7 @@ module.exports = Self => {
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}});
if (ctx.args.mine)
ctx.args.atenderFk = worker.id;
ctx.args.attenderFk = worker.id;
let where = buildFilter(ctx.args, (param, value) => {
switch (param) {
@ -75,7 +75,7 @@ module.exports = Self => {
: {'t.nickname': {like: `%${value}%`}};
case 'ticketFk':
return {'t.id': value};
case 'atenderFk':
case 'attenderFk':
return {'tr.atenderFk': value};
case 'isOk':
return {'tr.isOk': value};
@ -106,13 +106,13 @@ module.exports = Self => {
tr.ticketFk,
tr.quantity,
tr.price,
tr.atenderFk,
tr.atenderFk attenderFk,
tr.description,
tr.response,
tr.saleFk,
tr.isOk,
s.quantity AS saleQuantity,
s.itemFK,
s.itemFk,
i.name AS itemDescription,
t.shipped,
t.nickname,

View File

@ -1,27 +1,14 @@
const app = require('vn-loopback/server/server');
describe('ticket-request confirm()', () => {
let request;
let sale;
let originalRequest;
let originalSale;
let createdSaleId;
afterAll(async done => {
const paramsForRequest = {
saleFk: request.saleFk,
isOk: request.isOk,
itemFk: request.itemFk,
ticketFk: request.ticketFk
};
const paramsForSale = {
itemFk: sale.itemFk,
quantity: sale.quantity,
concept: sale.concept,
};
await request.updateAttributes(paramsForRequest);
await sale.updateAttributes(paramsForSale);
app.models.Sale.destroyById(createdSaleId);
await originalRequest.updateAttributes(originalRequest);
await originalSale.updateAttributes(originalSale);
await app.models.Sale.destroyById(createdSaleId);
done();
});
@ -65,10 +52,11 @@ describe('ticket-request confirm()', () => {
const itemId = 1;
const quantity = 10;
request = await app.models.TicketRequest.findById(requestId);
sale = await app.models.Sale.findById(saleId);
originalRequest = await app.models.TicketRequest.findById(requestId);
originalSale = await app.models.Sale.findById(saleId);
request.updateAttributes({saleFk: saleId});
const request = await app.models.TicketRequest.findById(requestId);
await request.updateAttributes({saleFk: saleId});
let ctx = {req: {accessToken: {userId: 9}}, args: {
itemFk: itemId,
@ -89,7 +77,8 @@ describe('ticket-request confirm()', () => {
const itemId = 1;
const quantity = 10;
request.updateAttributes({saleFk: null});
const request = await app.models.TicketRequest.findById(requestId);
await request.updateAttributes({saleFk: null});
let ctx = {req: {accessToken: {userId: 9}}, args: {
itemFk: itemId,

View File

@ -5,7 +5,7 @@ describe('ticket-request deny()', () => {
afterAll(async done => {
let params = {
isOk: null,
atenderFk: request.atenderFk,
attenderFk: request.attenderFk,
response: null,
};

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