diff --git a/.eslintrc.yml b/.eslintrc.yml index 380cf915b..82a1af501 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -31,6 +31,7 @@ rules: curly: [error, multi-or-nest] indent: [error, 4] arrow-parens: [error, as-needed] - jasmine/no-focused-tests: 0 no-multiple-empty-lines: ["error", { "max": 1, "maxEOF": 1 }] - space-in-parens: ["error", "never"] \ No newline at end of file + space-in-parens: ["error", "never"] + jasmine/no-focused-tests: 0 + jasmine/prefer-toHaveBeenCalledWith: 0 \ No newline at end of file diff --git a/db/changes/10180-holyWeek/00-claimState.sql b/db/changes/10180-holyWeek/00-claimState.sql index b4e8c68da..c39ba751d 100644 --- a/db/changes/10180-holyWeek/00-claimState.sql +++ b/db/changes/10180-holyWeek/00-claimState.sql @@ -15,3 +15,14 @@ UPDATE `vn`.`claimState` SET `code` = 'resolved' WHERE (`id` = '3'); UPDATE `vn`.`claimState` SET `code` = 'disputed' WHERE (`id` = '5'); UPDATE `vn`.`claimState` SET `code` = 'mana' WHERE (`id` = '6'); UPDATE `vn`.`claimState` SET `code` = 'managed' WHERE (`id` = '2'); + +ALTER TABLE `vn`.`claimState` +ADD COLUMN `priority` INT NOT NULL DEFAULT 1 AFTER `roleFk`; + +UPDATE `vn`.`claimState` SET `priority` = '1' WHERE (`id` = '1'); +UPDATE `vn`.`claimState` SET `priority` = '5' WHERE (`id` = '2'); +UPDATE `vn`.`claimState` SET `priority` = '7' WHERE (`id` = '3'); +UPDATE `vn`.`claimState` SET `priority` = '6' WHERE (`id` = '4'); +UPDATE `vn`.`claimState` SET `priority` = '3' WHERE (`id` = '5'); +UPDATE `vn`.`claimState` SET `priority` = '4' WHERE (`id` = '6'); +UPDATE `vn`.`claimState` SET `priority` = '2' WHERE (`id` = '7'); \ No newline at end of file diff --git a/db/changes/10190-postRegulation/00-claimState.sql b/db/changes/10190-postRegulation/00-claimState.sql deleted file mode 100644 index 72159d102..000000000 --- a/db/changes/10190-postRegulation/00-claimState.sql +++ /dev/null @@ -1,10 +0,0 @@ -ALTER TABLE `vn`.`claimState` -ADD COLUMN `priority` INT NOT NULL DEFAULT 1 AFTER `roleFk`; - -UPDATE `vn`.`claimState` SET `priority` = '1' WHERE (`id` = '1'); -UPDATE `vn`.`claimState` SET `priority` = '5' WHERE (`id` = '2'); -UPDATE `vn`.`claimState` SET `priority` = '7' WHERE (`id` = '3'); -UPDATE `vn`.`claimState` SET `priority` = '6' WHERE (`id` = '4'); -UPDATE `vn`.`claimState` SET `priority` = '3' WHERE (`id` = '5'); -UPDATE `vn`.`claimState` SET `priority` = '4' WHERE (`id` = '6'); -UPDATE `vn`.`claimState` SET `priority` = '2' WHERE (`id` = '7'); \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 9f43b440f..21f9a5234 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1185,16 +1185,16 @@ INSERT INTO `vn`.`travel`(`id`,`shipped`, `landed`, `warehouseInFk`, `warehouseO (7, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 5, 2, 1, 50.00, 500, 'seventh travel', 1), (8, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 5, 2, 1, 50.00, 500, 'eight travel', 1); -INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `companyFk`, `ref`,`isInventory`, `isRaid`, `notes`, `evaNotes`) +INSERT INTO `vn`.`entry`(`id`, `supplierFk`, `created`, `travelFk`, `isConfirmed`, `companyFk`, `ref`,`isInventory`, `isRaid`, `notes`, `evaNotes`) VALUES - (1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 442, 'Movement 1', 0, 0, '', ''), - (2, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 2, 442, 'Movement 2', 0, 0, 'this is the note two', 'observation two'), - (3, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 3, 442, 'Movement 3', 0, 0, 'this is the note three', 'observation three'), - (4, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 2, 69, 'Movement 4', 0, 0, 'this is the note four', 'observation four'), - (5, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 5, 442, 'Movement 5', 0, 0, 'this is the note five', 'observation five'), - (6, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 6, 442, 'Movement 6', 0, 0, 'this is the note six', 'observation six'), - (7, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 7, 442, 'Movement 7', 0, 0, 'this is the note seven', 'observation seven'), - (8, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 7, 442, 'Movement 8', 1, 1, '', ''); + (1, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 1, 442, 'Movement 1', 0, 0, '', ''), + (2, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 2, 0, 442, 'Movement 2', 0, 0, 'this is the note two', 'observation two'), + (3, 1, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 3, 0, 442, 'Movement 3', 0, 0, 'this is the note three', 'observation three'), + (4, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 2, 0, 69, 'Movement 4', 0, 0, 'this is the note four', 'observation four'), + (5, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 5, 0, 442, 'Movement 5', 0, 0, 'this is the note five', 'observation five'), + (6, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 6, 0, 442, 'Movement 6', 0, 0, 'this is the note six', 'observation six'), + (7, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'Movement 7', 0, 0, 'this is the note seven', 'observation seven'), + (8, 2, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 7, 0, 442, 'Movement 8', 1, 1, '', ''); INSERT INTO `vn`.`claimRatio`(`clientFk`, `yearSale`, `claimAmount`, `claimingRate`, `priceIncreasing`, `packingRate`) VALUES diff --git a/db/tests/vn/workerTimeControlCheck.spec.js b/db/tests/vn/workerTimeControlCheck.spec.js index 620377291..4869e38a6 100644 --- a/db/tests/vn/workerTimeControlCheck.spec.js +++ b/db/tests/vn/workerTimeControlCheck.spec.js @@ -1,7 +1,8 @@ const app = require('vn-loopback/server/server'); const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; -describe('worker workerTimeControl_check()', () => { +// #2257 xdescribe dbtest workerTimeControl_check() +xdescribe('worker workerTimeControl_check()', () => { it(`should throw an error if the worker can't sign on that tablet`, async() => { let stmts = []; let stmt; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 58ecb9499..ecf0d37e3 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -5,11 +5,11 @@ export default { userMenuButton: '#user', logoutButton: '#logout', applicationsMenuVisible: '.modules-menu', - clientsButton: '.modules-menu > li[ui-sref="client.index"]', - itemsButton: '.modules-menu > li[ui-sref="item.index"]', - ticketsButton: '.modules-menu > li[ui-sref="ticket.index"]', - invoiceOutButton: '.modules-menu > li[ui-sref="invoiceOut.index"]', - claimsButton: '.modules-menu > li[ui-sref="claim.index"]', + clientsButton: '.modules-menu [ui-sref="client.index"]', + itemsButton: '.modules-menu [ui-sref="item.index"]', + ticketsButton: '.modules-menu [ui-sref="ticket.index"]', + invoiceOutButton: '.modules-menu [ui-sref="invoiceOut.index"]', + claimsButton: '.modules-menu [ui-sref="claim.index"]', returnToModuleIndexButton: 'a[ui-sref="order.index"]', homeButton: 'vn-topbar > div.side.start > a', userLocalWarehouse: '.user-popover vn-autocomplete[ng-model="$ctrl.localWarehouseFk"]', @@ -56,8 +56,8 @@ export default { cancelButton: 'vn-button[href="#!/client/index"]' }, clientDescriptor: { - moreMenu: 'vn-client-descriptor vn-icon-menu[icon=more_vert]', - simpleTicketButton: '.vn-drop-down.shown li[name="Simple ticket"]' + moreMenu: 'vn-client-descriptor vn-icon-button[icon=more_vert]', + simpleTicketButton: '.vn-menu [name="simpleTicket"]' }, clientBasicData: { basicDataButton: 'vn-left-menu a[ui-sref="client.card.basicData"]', @@ -241,14 +241,14 @@ export default { }, itemDescriptor: { goBackToModuleIndexButton: 'vn-item-descriptor a[href="#!/item/index"]', - moreMenu: 'vn-item-descriptor vn-icon-menu[icon=more_vert]', - moreMenuRegularizeButton: '.vn-drop-down.shown li[name="Regularize stock"]', + moreMenu: 'vn-item-descriptor vn-icon-button[icon=more_vert]', + moreMenuRegularizeButton: '.vn-menu [name="regularizeStock"]', regularizeQuantity: '.vn-dialog.shown vn-textfield[ng-model="$ctrl.quantity"]', regularizeWarehouse: '.vn-dialog.shown vn-autocomplete[ng-model="$ctrl.warehouseFk"]', editButton: 'vn-item-descriptor vn-float-button[icon="edit"]', regularizeSaveButton: '.vn-dialog.shown tpl-buttons > button', inactiveIcon: 'vn-item-descriptor vn-icon[icon="icon-unavailable"]', - navigateBackToIndex: 'vn-item-descriptor vn-icon[icon="chevron_left"]' + navigateBackToIndex: 'vn-item-descriptor [name="goToModuleIndex"]' }, itemRequest: { firstRequestItemID: 'vn-item-request vn-tbody > vn-tr:nth-child(1) > vn-td-editable:nth-child(7)', @@ -378,7 +378,7 @@ export default { topbarSearch: 'vn-searchbar', advancedSearchButton: 'vn-ticket-search-panel button[type=submit]', searchButton: 'vn-searchbar vn-icon[icon="search"]', - moreMenu: 'vn-ticket-index vn-icon-menu[icon=more_vert]', + moreMenu: 'vn-ticket-index vn-icon-button[icon=more_vert]', sixthWeeklyTicket: 'vn-ticket-weekly-index vn-table vn-tr:nth-child(6)', weeklyTicket: 'vn-ticket-weekly-index vn-table > div > vn-tbody > vn-tr', firstWeeklyTicketDeleteIcon: 'vn-ticket-weekly-index vn-tr:nth-child(1) vn-icon-button[icon="delete"]', @@ -397,13 +397,13 @@ export default { idLabelValue: 'vn-ticket-descriptor vn-label-value[label="Id"]', stateLabelValue: 'vn-ticket-descriptor vn-label-value[label="State"]', goBackToModuleIndexButton: 'vn-ticket-descriptor a[ui-sref="ticket.index"]', - moreMenu: 'vn-ticket-descriptor vn-icon-menu[icon=more_vert]', - moreMenuAddStowaway: '.vn-drop-down.shown li[name="Add stowaway"]', - moreMenuDeleteStowawayButton: '.vn-drop-down.shown li[name="Delete stowaway"]', - moreMenuAddToTurn: '.vn-drop-down.shown li[name="Add turn"]', - moreMenuDeleteTicket: '.vn-drop-down.shown li[name="Delete ticket"]', - moreMenuMakeInvoice: '.vn-drop-down.shown li[name="Make invoice"]', - moreMenuChangeShippedHour: '.vn-drop-down.shown li[name="Change shipped hour"]', + moreMenu: 'vn-ticket-descriptor vn-icon-button[icon=more_vert]', + moreMenuAddStowaway: '.vn-menu [name="addStowaway"]', + moreMenuDeleteStowawayButton: '.vn-menu [name="deleteStowaway"]', + moreMenuAddToTurn: '.vn-menu [name="addTurn"]', + moreMenuDeleteTicket: '.vn-menu [name="deleteTicket"]', + moreMenuMakeInvoice: '.vn-menu [name="makeInvoice"]', + moreMenuChangeShippedHour: '.vn-menu [name="changeShipped"]', changeShippedHourDialog: '.vn-dialog.shown', changeShippedHour: '.vn-dialog.shown vn-input-time[ng-model="$ctrl.newShipped"]', addStowawayDialogFirstTicket: '.vn-dialog.shown vn-table vn-tbody vn-tr', @@ -412,7 +412,7 @@ export default { saturdayButton: '.vn-popup.shown vn-tool-bar > vn-button:nth-child(6)', acceptDeleteButton: '.vn-dialog.shown button[response="accept"]', acceptChangeHourButton: '.vn-dialog.shown button[response="accept"]', - descriptorDeliveryDate: 'vn-ticket-descriptor > div > div.body > div.attributes > vn-label-value:nth-child(6) > section > span', + descriptorDeliveryDate: 'vn-ticket-descriptor slot-body > .attributes > vn-label-value:nth-child(3) > section > span', acceptInvoiceOutButton: '.vn-confirm.shown button[response="accept"]', acceptDeleteStowawayButton: '.vn-dialog.shown button[response="accept"]' }, @@ -442,9 +442,9 @@ export default { saleLine: 'vn-table div > vn-tbody > vn-tr', saleDescriptorPopover: '.vn-popover.shown vn-item-descriptor', 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', + descriptorItemDiaryButton: '.vn-popover vn-item-descriptor vn-quick-link[icon="icon-transaction"] > a', newItemFromCatalogButton: 'vn-ticket-sale vn-float-button[icon="add"]', - newItemButton: 'vn-ticket-sale > vn-vertical > vn-card > vn-vertical > vn-one > vn-icon-button > button > vn-icon > i', + newItemButton: 'vn-ticket-sale vn-card vn-icon-button[icon="add_circle"]', moreMenu: 'vn-ticket-sale vn-tool-bar > vn-button-menu[vn-id="more-button"] > div > button', moreMenuCreateClaim: '.vn-drop-down.shown li[name="Add claim"]', moreMenuReserve: '.vn-drop-down.shown li[name="Mark as reserved"]', @@ -479,8 +479,8 @@ export default { secondSaleIdInput: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(4) > vn-autocomplete', secondSaleIdAutocomplete: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(2) > vn-td:nth-child(4) > vn-autocomplete', secondSaleQuantity: 'vn-ticket-sale vn-table vn-tr:nth-child(2) vn-input-number', - secondSaleConceptCell: 'vn-ticket-sale > vn-vertical > vn-card > vn-vertical > vn-table > div > 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', + secondSaleConceptCell: 'vn-ticket-sale vn-tbody > :nth-child(2) > :nth-child(6)', + secondSaleConceptInput: 'vn-ticket-sale vn-tbody > :nth-child(2) > vn-td-editable.ng-isolate-scope.selected vn-textfield', 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"]', @@ -558,8 +558,8 @@ export default { searchButton: 'vn-searchbar vn-icon[icon="search"]' }, claimDescriptor: { - moreMenu: 'vn-claim-descriptor vn-icon-menu[icon=more_vert]', - moreMenuDeleteClaim: '.vn-drop-down.shown li[name="Delete claim"]', + moreMenu: 'vn-claim-descriptor vn-icon-button[icon=more_vert]', + moreMenuDeleteClaim: '.vn-menu [name="deleteClaim"]', acceptDeleteClaim: '.vn-confirm.shown button[response="accept"]' }, claimSummary: { @@ -569,9 +569,9 @@ export default { 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', firstSaleDescriptorImage: '.vn-popover.shown vn-item-descriptor img', itemDescriptorPopover: '.vn-popover.shown vn-item-descriptor', - itemDescriptorPopoverItemDiaryButton: '.vn-popover.shown vn-item-descriptor a[href="#!/item/2/diary"]', + itemDescriptorPopoverItemDiaryButton: '.vn-popover vn-item-descriptor vn-quick-link[icon="icon-transaction"] > a', 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 vn-quick-links > a[href="#!/client/21/summary"]', + firstDevelopmentWorkerGoToClientButton: '.vn-popover vn-worker-descriptor vn-quick-link[icon="person"] > a', 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' }, @@ -618,9 +618,13 @@ export default { }, ordersIndex: { searchResult: 'vn-order-index vn-card > vn-table > div > vn-tbody > a.vn-tr', + firstSearchResultTotal: 'vn-order-index vn-card > vn-table > div > vn-tbody vn-tr vn-td:nth-child(9)', 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)', searchButton: 'vn-searchbar vn-icon[icon="search"]', + advancedSearchButton: 'vn-order-search-panel vn-submit[label="Search"]', + openAdvancedSearch: 'vn-searchbar vn-icon[icon="arrow_drop_down"]', + advancedSearchShowEmptyCheckbox: 'vn-order-search-panel vn-check[label="Show empty"]', createOrderButton: 'vn-float-button', }, orderDescriptor: { @@ -783,7 +787,7 @@ export default { 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"]', + navigateBackToIndex: 'vn-worker-descriptor [name="goToModuleIndex"]', acceptDeleteDialog: '.vn-confirm.shown button[response="accept"]' }, invoiceOutIndex: { @@ -792,10 +796,10 @@ export default { 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]', - moreMenuDeleteInvoiceOut: '.vn-drop-down.shown li[name="Delete Invoice"]', - moreMenuBookInvoiceOut: '.vn-drop-down.shown li[name="Book invoice"]', - moreMenuShowInvoiceOutPdf: '.vn-drop-down.shown li[name="Show invoice PDF"]', + moreMenu: 'vn-invoice-out-descriptor vn-icon-button[icon=more_vert]', + moreMenuDeleteInvoiceOut: '.vn-menu [name="deleteInvoice"]', + moreMenuBookInvoiceOut: '.vn-menu [name="bookInvoice"]', + moreMenuShowInvoiceOutPdf: '.vn-menu [name="showInvoicePdf"]', acceptDeleteButton: '.vn-confirm.shown button[response="accept"]', acceptBookingButton: '.vn-confirm.shown button[response="accept"]' }, @@ -847,8 +851,8 @@ export default { confirmed: 'vn-entry-summary vn-check[label="Confirmed"]', }, entryDescriptor: { - agency: 'vn-entry-descriptor div.body vn-label-value:nth-child(3) span', - travelsQuicklink: 'vn-entry-descriptor vn-quick-links > a:nth-child(1)', - entriesQuicklink: 'vn-entry-descriptor vn-quick-links > a:nth-child(2)' + agency: 'vn-entry-descriptor div.body vn-label-value:nth-child(2) span', + travelsQuicklink: 'vn-entry-descriptor vn-quick-link[icon="local_airport"] > a', + entriesQuicklink: 'vn-entry-descriptor vn-quick-link[icon="icon-entry"] > a' } }; diff --git a/e2e/paths/07-order/03_lines.spec.js b/e2e/paths/07-order/03_lines.spec.js index 9a214cfeb..c054bbaa3 100644 --- a/e2e/paths/07-order/03_lines.spec.js +++ b/e2e/paths/07-order/03_lines.spec.js @@ -32,10 +32,11 @@ describe('Order lines', () => { }); it('should confirm the order subtotal has changed', async() => { + await page.waitForTextInElement(selectors.orderLine.orderSubtotal, '90.10'); const result = await page .waitToGetProperty(selectors.orderLine.orderSubtotal, 'innerText'); - expect(result).toContain('80.54'); + expect(result).toContain('90.10'); }); it('should confirm the whole order and redirect to ticket index filtered by clientFk', async() => { diff --git a/e2e/paths/07-order/05_index.spec.js b/e2e/paths/07-order/05_index.spec.js new file mode 100644 index 000000000..ef55051aa --- /dev/null +++ b/e2e/paths/07-order/05_index.spec.js @@ -0,0 +1,34 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Order Index', () => { + let browser; + let page; + + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('employee', 'order'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it(`should check the first search result doesn't contain a total of 0€`, async() => { + await page.waitToClick(selectors.ordersIndex.searchButton); + const result = await page.waitToGetProperty(selectors.ordersIndex.firstSearchResultTotal, 'innerText'); + + expect(result).not.toContain('0.00'); + }); + + it('should search including empty orders', async() => { + await page.waitToClick(selectors.ordersIndex.openAdvancedSearch); + await page.waitToClick(selectors.ordersIndex.advancedSearchShowEmptyCheckbox); + await page.waitToClick(selectors.ordersIndex.advancedSearchButton); + await page.waitForTextInElement(selectors.ordersIndex.firstSearchResultTotal, '0.00'); + const result = await page.waitToGetProperty(selectors.ordersIndex.firstSearchResultTotal, 'innerText'); + + expect(result).toContain('0.00'); + }); +}); diff --git a/front/core/components/autocomplete/index.html b/front/core/components/autocomplete/index.html index feaa47bdb..69aac4d43 100755 --- a/front/core/components/autocomplete/index.html +++ b/front/core/components/autocomplete/index.html @@ -16,7 +16,7 @@
diff --git a/front/core/components/confirm/confirm.html b/front/core/components/confirm/confirm.html index 5ef8fde75..8ae66ccb2 100644 --- a/front/core/components/confirm/confirm.html +++ b/front/core/components/confirm/confirm.html @@ -1,10 +1,7 @@ -
- -
{{::$ctrl.message}}
- {{::$ctrl.question}} -
- - - - -
\ No newline at end of file + + {{::$ctrl.question}} + + + + + \ No newline at end of file diff --git a/front/core/components/confirm/confirm.js b/front/core/components/confirm/confirm.js index c0a1cc0c5..217b68fbc 100644 --- a/front/core/components/confirm/confirm.js +++ b/front/core/components/confirm/confirm.js @@ -1,20 +1,13 @@ import ngModule from '../../module'; import Dialog from '../dialog'; -import template from './confirm.html'; import './style.scss'; -export default class Confirm extends Dialog { - constructor($element, $, $transclude) { - super($element, $, $transclude); - this.fillSlots(template); - } -} +export default class Confirm extends Dialog {} ngModule.vnComponent('vnConfirm', { + slotTemplate: require('./confirm.html'), controller: Confirm, - transclude: true, bindings: { - question: '@', - message: '@?' + question: '@' } }); diff --git a/front/core/components/datalist/index.js b/front/core/components/datalist/index.js index 684918a5f..08744f1ed 100644 --- a/front/core/components/datalist/index.js +++ b/front/core/components/datalist/index.js @@ -33,9 +33,6 @@ export default class Datalist extends Textfield { if (this.validSelection(value)) return; - if (!oldValue) - return this.fetchSelection(); - this.$timeout.cancel(this.searchTimeout); if (this.model) { diff --git a/front/core/components/debug-info/index.js b/front/core/components/debug-info/index.js index 5e3d2e1ea..caac8126a 100644 --- a/front/core/components/debug-info/index.js +++ b/front/core/components/debug-info/index.js @@ -1,27 +1,31 @@ import ngModule from '../../module'; +import Component from '../../lib/component'; import './style.scss'; /** * Floating box displaying debugging information. * Enabled only in development environment. */ -export default class Controller { +export default class Controller extends Component { constructor($element, $) { + super($element, $); this.env = process.env.NODE_ENV || 'development'; if (this.env == 'development') this.interval = setInterval(() => $.$digest(), 2000); else $element[0].style.display = 'none'; + + $element[0].addEventListener('mouseover', + () => this.classList.toggle('right')); } $onDestroy() { clearInterval(this.interval); } } -Controller.$inject = ['$element', '$scope']; -ngModule.component('vnDebugInfo', { +ngModule.vnComponent('vnDebugInfo', { template: require('./index.html'), controller: Controller }); diff --git a/front/core/components/debug-info/style.scss b/front/core/components/debug-info/style.scss index b6171d4da..290b84890 100644 --- a/front/core/components/debug-info/style.scss +++ b/front/core/components/debug-info/style.scss @@ -1,6 +1,6 @@ @import "variables"; -vn-debug-info { +.vn-debug-info { position: fixed; bottom: 16px; left: 16px; @@ -13,8 +13,9 @@ vn-debug-info { box-shadow: $shadow; transition: opacity 400ms ease-in-out; - &:hover { - opacity: .5; + &.right { + left: auto; + right: 16px; } & > h6 { font-weight: normal; diff --git a/front/core/components/dialog/index.html b/front/core/components/dialog/index.html index c213042e1..b779de94d 100644 --- a/front/core/components/dialog/index.html +++ b/front/core/components/dialog/index.html @@ -1,22 +1,31 @@ -
- -
- - -
+
+ ng-if="$ctrl.loading" + class="loading-overlap shown"> +
-
-
- \ No newline at end of file + + +
+
+ + {{$ctrl.message}} + +
+
+
+
+
+
+
diff --git a/front/core/components/dialog/index.js b/front/core/components/dialog/index.js index dfc1e5d3a..8a9c583ca 100644 --- a/front/core/components/dialog/index.js +++ b/front/core/components/dialog/index.js @@ -1,6 +1,5 @@ import ngModule from '../../module'; import Popup from '../popup'; -import template from './index.html'; import './style.scss'; /** @@ -16,22 +15,6 @@ import './style.scss'; * @slot buttons The dialog HTML buttons */ export default class Dialog extends Popup { - constructor($element, $, $transclude) { - super($element, $, $transclude); - this.fillDefaultSlot(template); - } - - /** - * Fills the dialog slots, it is intended to be used by child classes. - * - * @param {String} template The HTML template string - */ - fillSlots(template) { - let $template = angular.element(template); - this.fillSlot('body', $template.find('tpl-body')); - this.fillSlot('buttons', $template.find('tpl-buttons')); - } - /** * Shows the dialog and optionally registers a handler for the response. * @@ -149,12 +132,15 @@ export default class Dialog extends Popup { } ngModule.vnComponent('vnDialog', { + slotTemplate: require('./index.html'), controller: Dialog, transclude: { - body: 'tplBody', + title: '?tplTitle', + body: '?tplBody', buttons: '?tplButtons' }, bindings: { + message: '@?', onResponse: '&?', onAccept: '&?' } diff --git a/front/core/components/dialog/style.scss b/front/core/components/dialog/style.scss index e4884c362..47837af7e 100644 --- a/front/core/components/dialog/style.scss +++ b/front/core/components/dialog/style.scss @@ -18,6 +18,9 @@ & > form { padding: $spacing-lg; + & > h6 { + margin-bottom: $spacing-md; + } & > .body > tpl-body { display: block; min-width: 256px; diff --git a/front/core/components/drop-down/index.html b/front/core/components/drop-down/index.html index 52ceeeaae..ab868f7b5 100644 --- a/front/core/components/drop-down/index.html +++ b/front/core/components/drop-down/index.html @@ -1,22 +1,24 @@ -
- - -
-
- -
- {{$ctrl.statusText}} + +
+ +
-
\ No newline at end of file +
+ +
+ {{$ctrl.statusText}} +
+
+ \ No newline at end of file diff --git a/front/core/components/drop-down/index.js b/front/core/components/drop-down/index.js index ed7de7179..dfdfbe18d 100644 --- a/front/core/components/drop-down/index.js +++ b/front/core/components/drop-down/index.js @@ -1,7 +1,6 @@ import './style.scss'; import ngModule from '../../module'; import Popover from '../popover'; -import template from './index.html'; import ArrayModel from '../array-model/array-model'; import CrudModel from '../crud-model/crud-model'; import {mergeWhere} from 'vn-loopback/util/filter'; @@ -21,7 +20,6 @@ export default class DropDown extends Popover { this.showLoadMore = true; this.showFilter = true; this.searchDelay = 300; - this.fillDefaultSlot(template); } get search() { @@ -458,6 +456,7 @@ function getPosition(parent, event) { } ngModule.vnComponent('vnDropDown', { + slotTemplate: require('./index.html'), controller: DropDown, transclude: { tplItem: '?tplItem' diff --git a/front/core/components/field/index.html b/front/core/components/field/index.html index c31fe2862..b1b78be66 100644 --- a/front/core/components/field/index.html +++ b/front/core/components/field/index.html @@ -8,7 +8,7 @@
diff --git a/front/core/components/form-input/index.js b/front/core/components/form-input/index.js index 0395922c7..c50102e8a 100644 --- a/front/core/components/form-input/index.js +++ b/front/core/components/form-input/index.js @@ -9,12 +9,6 @@ import Component from '../../lib/component'; * @property {Boolean} disabled Put component in disabled mode */ export default class FormInput extends Component { - constructor($element, $scope) { - super($element, $scope); - this.classList = this.element.classList; - this.classList.add(...this.constructor.$classNames); - } - $onInit() { // XXX: Compatibility with old inputs let attrs = this.$element[0].attributes; diff --git a/front/core/components/icon/style.scss b/front/core/components/icon/style.scss index 86345cbf4..ebfbfee77 100644 --- a/front/core/components/icon/style.scss +++ b/front/core/components/icon/style.scss @@ -7,6 +7,8 @@ vn-icon { & > i, & > i.material-icons { display: block; + } + & > i.material-icons { font-size: inherit; } } diff --git a/front/core/components/input-file/index.html b/front/core/components/input-file/index.html index ad71b744d..5ec7e1da4 100644 --- a/front/core/components/input-file/index.html +++ b/front/core/components/input-file/index.html @@ -19,7 +19,7 @@
diff --git a/front/core/components/input-number/index.html b/front/core/components/input-number/index.html index acce849e2..4d0227333 100644 --- a/front/core/components/input-number/index.html +++ b/front/core/components/input-number/index.html @@ -8,7 +8,7 @@
diff --git a/front/core/components/list/style.scss b/front/core/components/list/style.scss index fdadf460b..223748f4a 100644 --- a/front/core/components/list/style.scss +++ b/front/core/components/list/style.scss @@ -1,27 +1,11 @@ @import "./effects"; -/* -ul.menu { - list-style-type: none; - padding: 0; - padding-top: $spacing-md; - margin: 0; - font-size: inherit; - - & > li > a { - @extend %clickable; - display: block; - color: inherit; - padding: 9px 32px; - } -} -*/ vn-list, .vn-list { display: block; max-width: $width-sm; margin: 0 auto; - padding: 0; + padding: $spacing-sm 0; list-style-type: none; vn-list, @@ -32,6 +16,8 @@ vn-list, } } &.separated { + padding: 0; + vn-item, .vn-item { border-bottom: $border-thin-light; diff --git a/front/core/components/popover/index.js b/front/core/components/popover/index.js index 7c54ce494..d78179ab9 100644 --- a/front/core/components/popover/index.js +++ b/front/core/components/popover/index.js @@ -1,6 +1,5 @@ import ngModule from '../../module'; import Popup from '../popup'; -import template from './index.html'; import isMobile from '../../lib/is-mobile'; import './style.scss'; @@ -8,24 +7,27 @@ import './style.scss'; * A simple popover. * * @property {HTMLElement} parent The parent element to show drop down relative to + * @property {HTMLElement} content Element holding the popover content * * @event open Thrown when popover is displayed * @event close Thrown when popover is hidden */ export default class Popover extends Popup { - constructor($element, $, $transclude) { - super($element, $, $transclude); + constructor(...args) { + super(...args); this.displayMode = isMobile ? 'centered' : 'relative'; - this.template = template; } /** * Shows the popover emitting the open signal. If a parent is specified * it is shown in a visible relative position to it. * - * @param {HTMLElement} parent Overrides the parent property + * @param {HTMLElement|Event} parent Overrides the parent property */ show(parent) { + if (parent instanceof Event) + parent = event.target; + if (parent) this.parent = parent; super.show(); this.content = this.popup.querySelector('.content'); @@ -44,7 +46,6 @@ export default class Popover extends Popup { // Bug #2147 Popover loses parent location set parent(value) { this.__parent = value; - if (!value) return; const parentRect = value.getBoundingClientRect(); @@ -115,3 +116,7 @@ export default class Popover extends Popup { ngModule.vnComponent('vnPopover', { controller: Popover }); + +ngModule.run(['$compile', function($compile) { + Popover.prototype.contentLinkFn = $compile(require('./index.html')); +}]); diff --git a/front/core/components/popup/index.js b/front/core/components/popup/index.js index 0dea66254..2a2433770 100644 --- a/front/core/components/popup/index.js +++ b/front/core/components/popup/index.js @@ -1,18 +1,15 @@ import ngModule from '../../module'; import Component from '../../lib/component'; -import template from './index.html'; import './style.scss'; /** * Base class for windows displayed over application content. */ export default class Popup extends Component { - constructor($element, $scope, $transclude) { - super($element, $scope); - this.$transclude = $transclude; + constructor(...args) { + super(...args); this._shown = false; this.displayMode = 'centered'; - this.template = template; } $onDestroy() { @@ -34,7 +31,7 @@ export default class Popup extends Component { } /** - * Displays the dialog to the user. + * Displays the popup. */ show() { if (this.shown) return; @@ -45,11 +42,13 @@ export default class Popup extends Component { this.onClose(); } - let linkFn = this.$compile(this.template); this.$contentScope = this.$.$new(); - this.popup = linkFn(this.$contentScope, null, + this.contentLinkFn( + this.$contentScope, + element => this.popup = element[0], {parentBoundTranscludeFn: this.$transclude} - )[0]; + ); + this.windowEl = this.popup.querySelector('.window'); this.windowEl.focus(); @@ -75,7 +74,7 @@ export default class Popup extends Component { } /** - * Hides the dialog calling the response handler. + * Hides the popup. */ hide() { if (!this.shown) return; @@ -96,6 +95,11 @@ export default class Popup extends Component { this.emit('closeStart'); } + /** + * Called when closing transition ends and popup is not visible, it can + * be overriden by child classes (calling the super) to perform additional + * actions. + */ onClose() { this.closeTimeout = null; this.popup.remove(); @@ -127,5 +131,10 @@ ngModule.vnComponent('vnPopup', { transclude: true, bindings: { shown: '=?' - } + }, + installClasses: false }); + +ngModule.run(['$compile', function($compile) { + Popup.prototype.contentLinkFn = $compile(require('./index.html')); +}]); diff --git a/front/core/components/scroll-up/style.scss b/front/core/components/scroll-up/style.scss index 44d12f14f..5f316e58c 100644 --- a/front/core/components/scroll-up/style.scss +++ b/front/core/components/scroll-up/style.scss @@ -1,6 +1,9 @@ +@import "variables"; + vn-scroll-up { - top: 88px; - right: 32px; + right: 0; + top: $topbar-height; + margin: $float-spacing; display: none; position: fixed; } \ No newline at end of file diff --git a/front/core/components/searchbar/locale/en.yml b/front/core/components/searchbar/locale/en.yml new file mode 100644 index 000000000..52ab6a184 --- /dev/null +++ b/front/core/components/searchbar/locale/en.yml @@ -0,0 +1 @@ +Search by: Search by {{module | translate}} \ No newline at end of file diff --git a/front/core/components/searchbar/locale/es.yml b/front/core/components/searchbar/locale/es.yml new file mode 100644 index 000000000..730564a7b --- /dev/null +++ b/front/core/components/searchbar/locale/es.yml @@ -0,0 +1 @@ +Search by: Buscar por {{module | translate}} \ No newline at end of file diff --git a/front/core/components/searchbar/searchbar.html b/front/core/components/searchbar/searchbar.html index d6f4720f2..1de40fa23 100644 --- a/front/core/components/searchbar/searchbar.html +++ b/front/core/components/searchbar/searchbar.html @@ -1,7 +1,7 @@
.loader { position: relative; diff --git a/front/core/directives/acl.js b/front/core/directives/acl.js index 1cebddd42..9b7328524 100644 --- a/front/core/directives/acl.js +++ b/front/core/directives/acl.js @@ -9,7 +9,6 @@ function vnAcl(aclService) { priority: -1, link: function(_, $element, $attrs) { acls = $attrs.vnAcl.split(',').map(i => i.trim()); - if (acls[0] == '') return; let action = $attrs.vnAclAction || 'disable'; diff --git a/front/core/directives/click-stop.js b/front/core/directives/click-stop.js new file mode 100644 index 000000000..c13bbecae --- /dev/null +++ b/front/core/directives/click-stop.js @@ -0,0 +1,23 @@ +import ngModule from '../module'; + +/* + * Registers a handler for the click event and stops propagation when event + * is thrown, mainly when nesting clickable elements wich ignore the + * Event.defaultPrevented property, like ui-sref. + */ +export function directive($parse) { + return { + restrict: 'A', + link: function(scope, element, attrs) { + const fn = $parse(attrs.vnClickStop); + element.on('click', function(event) { + fn(scope, {$event: event}); + event.stopPropagation(); + event.preventDefault(); + }); + } + }; +} +directive.$inject = ['$parse']; + +ngModule.directive('vnClickStop', directive); diff --git a/front/core/directives/index.js b/front/core/directives/index.js index 185046a3c..4377afe8c 100644 --- a/front/core/directives/index.js +++ b/front/core/directives/index.js @@ -2,6 +2,7 @@ import './id'; import './focus'; import './dialog'; import './popover'; +import './click-stop'; import './rule'; import './acl'; import './on-error-src'; diff --git a/front/core/directives/specs/focus.spec.js b/front/core/directives/specs/focus.spec.js index dd917dc29..af88e7942 100644 --- a/front/core/directives/specs/focus.spec.js +++ b/front/core/directives/specs/focus.spec.js @@ -15,6 +15,7 @@ describe('Directive focus', () => { $element[0].focus = jasmine.createSpy('focus'); $element[0].select = jasmine.createSpy('select'); $compile($element)($scope); + $scope.$apply(); $flushPendingTasks(); }); }; @@ -37,7 +38,6 @@ describe('Directive focus', () => { it('should call select function on the element', () => { let html = ``; compile(html); - $scope.$apply(); expect($element[0].select).toHaveBeenCalledWith(); }); diff --git a/front/core/directives/uvc.html b/front/core/directives/uvc.html index 49b59b406..9de13b675 100644 --- a/front/core/directives/uvc.html +++ b/front/core/directives/uvc.html @@ -6,11 +6,9 @@ + vn-id="uvc" + message="Fields to show"> - -
Fields to show
-
{ + let idFilter; + + beforeEach(ngModule('vnCore')); + + beforeEach(inject(_idFilter_ => { + idFilter = _idFilter_; + })); + + it('should return empty string for input null', () => { + expect(idFilter(null)).toBe(''); + }); + + it('should return empty stringfor input empty', () => { + expect(idFilter('')).toBe(''); + }); + + it('should prefix a pad character', () => { + expect(idFilter('123')).toBe('#123'); + }); +}); diff --git a/front/core/filters/specs/percentage.spec.js b/front/core/filters/specs/percentage.spec.js index 0936c50ae..62f1a28b5 100644 --- a/front/core/filters/specs/percentage.spec.js +++ b/front/core/filters/specs/percentage.spec.js @@ -3,8 +3,9 @@ describe('Percentage filter', () => { beforeEach(ngModule('vnCore')); - beforeEach(inject(_percentageFilter_ => { + beforeEach(inject((_percentageFilter_, $translate) => { percentageFilter = _percentageFilter_; + jest.spyOn($translate, 'use').mockReturnValue('en-US'); })); it('should return null for input null', () => { diff --git a/front/core/lib/component.js b/front/core/lib/component.js index 4552dfbe7..f17db68a2 100644 --- a/front/core/lib/component.js +++ b/front/core/lib/component.js @@ -11,14 +11,29 @@ export default class Component extends EventEmitter { * * @param {HTMLElement} $element The main component element * @param {$rootScope.Scope} $scope The element scope + * @param {Function} $transclude The transclusion function */ - constructor($element, $scope) { + constructor($element, $scope, $transclude) { super(); + this.$ = $scope; + if (!$element) return; this.element = $element[0]; this.element.$ctrl = this; this.$element = $element; - this.$ = $scope; + this.$transclude = $transclude; + this.classList = this.element.classList; + + const constructor = this.constructor; + const $options = constructor.$options; + + if ($options && $options.installClasses) + this.classList.add(...this.constructor.$classNames); + + if ($transclude && constructor.slotTemplates) { + for (let slotTemplate of constructor.slotTemplates) + this.fillSlots(slotTemplate); + } } $postLink() { @@ -26,7 +41,7 @@ export default class Component extends EventEmitter { let attrs = this.$element[0].attributes; let $scope = this.$; for (let attr of attrs) { - if (attr.name.substr(0, 2) !== 'on') continue; + if (!attr.name.startsWith('on-')) continue; let eventName = kebabToCamel(attr.name.substr(3)); let callback = locals => $scope.$parent.$eval(attr.nodeValue, locals); this.on(eventName, callback); @@ -58,6 +73,72 @@ export default class Component extends EventEmitter { return this.$translate.instant(string, params); } + /** + * Fills the default transclude slot. + * + * @param {JQElement|String} template The slot template + */ + fillDefaultSlot(template) { + const linkFn = this.$compile(template); + this.$transclude.$$boundTransclude = this.createBoundTranscludeFn(linkFn); + } + + /** + * Fills a named transclude slot. + * + * @param {String} slot The trasnclude slot name + * @param {JQElement|String} template The slot template + */ + fillSlot(slot, template) { + const linkFn = this.$compile(template); + const slots = this.$transclude.$$boundTransclude.$$slots; + slots[slot] = this.createBoundTranscludeFn(linkFn); + } + + /** + * Fills component transclude slots using the passed HTML template string + * as source. + * + * @param {String} template The HTML template string + */ + fillSlots(template) { + const name = this.constructor.$options.name; + const transclude = this.constructor.$options.transclude; + + if (!transclude) + throw new Error(`No transclusion option defined in '${name}'`); + if (!this.$transclude) + throw new Error(`No $transclude injected in '${name}'`); + + let slotMap = {}; + for (let slotName in transclude) { + let slotTag = transclude[slotName].match(/\w+$/)[0]; + slotMap[slotTag] = slotName; + } + + const $template = angular.element(template); + for (let i = 0; i < $template.length; i++) { + let slotElement = $template[i]; + if (slotElement.nodeType != Node.ELEMENT_NODE) continue; + let tagName = kebabToCamel(slotElement.tagName.toLowerCase()); + + if (tagName == 'default') + this.fillDefaultSlot(slotElement.childNodes); + else { + let slotName = slotMap[tagName]; + if (!slotName) + throw new Error(`No slot found for '${tagName}' in '${name}'`); + this.fillSlot(slotName, slotElement); + } + } + } + + /** + * Creates a bounded transclude function from a linking function. + * + * @param {Function} linkFn The linking function + * @return {Function} The bounded transclude function + */ createBoundTranscludeFn(linkFn) { let scope = this.$; let previousBoundTranscludeFn = this.$transclude.$$boundTransclude; @@ -78,17 +159,6 @@ export default class Component extends EventEmitter { return vnBoundTranscludeFn; } - fillDefaultSlot(template) { - let linkFn = this.$compile(template); - this.$transclude.$$boundTransclude = this.createBoundTranscludeFn(linkFn); - } - - fillSlot(slot, template) { - let slots = this.$transclude.$$boundTransclude.$$slots; - let linkFn = this.$compile(template); - slots[slot] = this.createBoundTranscludeFn(linkFn); - } - copySlot(slot, $transclude) { this.$transclude.$$boundTransclude.$$slots[slot] = $transclude.$$boundTransclude.$$slots[slot]; @@ -96,44 +166,25 @@ export default class Component extends EventEmitter { } Component.$inject = ['$element', '$scope']; -function runFn( - $translate, - $q, - $http, - $state, - $stateParams, - $timeout, - $transitions, - $compile, - $filter, - $interpolate, - $window, - vnApp, - vnToken, - vnConfig, - aclService) { - Object.assign(Component.prototype, { - $translate, - $q, - $http, - $state, - $params: $stateParams, - $timeout, - $transitions, - $compile, - $filter, - $interpolate, - $window, - vnApp, - vnToken, - vnConfig, - aclService +/* + * Automatically adds the most used services to the prototype, so they are + * available as component properties. + */ +function runFn(...args) { + const proto = Component.prototype; + + for (let i = 0; i < runFn.$inject.length; i++) + proto[runFn.$inject[i]] = args[i]; + + Object.assign(proto, { + $params: proto.$stateParams }); } runFn.$inject = [ '$translate', '$q', '$http', + '$httpParamSerializer', '$state', '$stateParams', '$timeout', @@ -145,6 +196,7 @@ runFn.$inject = [ 'vnApp', 'vnToken', 'vnConfig', + 'vnModules', 'aclService' ]; diff --git a/front/core/lib/module-loader.js b/front/core/lib/module-loader.js index 18f0a3ea3..c48e7d93d 100644 --- a/front/core/lib/module-loader.js +++ b/front/core/lib/module-loader.js @@ -11,7 +11,7 @@ export function factory($http, $window, $ocLazyLoad, $translatePartialLoader, $t this.loaded = {}; this.imports = {}; this.moduleImport = moduleImport; - this.modelInfo = $http.get(`modelInfo`) + this.modelInfo = $http.get(`Schemas/modelInfo`) .then(json => { this.onModelInfoReady(json); this.modelInfo = true; diff --git a/front/core/lib/specs/module-loader.spec.js b/front/core/lib/specs/module-loader.spec.js index 2f756f7be..dbed5e9a0 100644 --- a/front/core/lib/specs/module-loader.spec.js +++ b/front/core/lib/specs/module-loader.spec.js @@ -23,7 +23,7 @@ describe('factory vnModuleLoader', () => { } ]; - $httpBackend.whenGET('modelInfo') + $httpBackend.whenGET('Schemas/modelInfo') .respond({ FooModel: { properties: { diff --git a/front/core/module.js b/front/core/module.js index 82a954892..f80f11853 100644 --- a/front/core/module.js +++ b/front/core/module.js @@ -1,6 +1,16 @@ import {ng, ngDeps} from './vendor'; import {camelToKebab} from './lib/string'; +/** + * Extended component options. + * + * @property {Boolean} installClassses Whether to install CSS classes equivalent to the component's and parents name + * @property {String} slotTemplate HTML template used to fill component transclude slots + */ +const defaultOptions = { + installClasses: true +}; + /** * Acts like native Module.component() function but merging component options * with parent component options. This method establishes the $options property @@ -17,7 +27,7 @@ import {camelToKebab} from './lib/string'; function vnComponent(name, options) { let controller = options.controller; let parent = Object.getPrototypeOf(controller); - let parentOptions = parent.$options || {}; + let parentOptions = parent.$options || defaultOptions; let parentTransclude = parentOptions.transclude; let transclude = parentTransclude instanceof Object @@ -32,10 +42,11 @@ function vnComponent(name, options) { } else if (options.transclude !== undefined) transclude = options.transclude; - let mergedOptions = Object.assign({}, + let $options = Object.assign({}, parentOptions, options, { + name, transclude, bindings: Object.assign({}, parentOptions.bindings, @@ -47,13 +58,17 @@ function vnComponent(name, options) { ) } ); - controller.$options = mergedOptions; + + let parentSlotTemplates = parent.slotTemplates || []; + if (options.slotTemplate) + controller.slotTemplates = parentSlotTemplates.concat([options.slotTemplate]); let classNames = [camelToKebab(name)]; if (parent.$classNames) classNames = classNames.concat(parent.$classNames); controller.$classNames = classNames; - return this.component(name, mergedOptions); + controller.$options = $options; + return this.component(name, $options); } const ngModuleFn = ng.module; @@ -72,33 +87,12 @@ export function config($translateProvider, $translatePartialLoaderProvider, $ani // For CSS browser targeting document.documentElement.setAttribute('data-browser', navigator.userAgent); - $translatePartialLoaderProvider.addPart('core'); - - let conf = {urlTemplate: '/locale/{part}/{lang}.json'}; - - let fallbackLang = 'es'; - let langs = ['en', 'es']; - let langAliases = { - en_US: 'en', - en_GB: 'en', - es_ES: 'es', - es_AR: 'es' - }; - $translateProvider .useSanitizeValueStrategy('escape') - .useLoader('$translatePartialLoader', conf) - .registerAvailableLanguageKeys(langs, langAliases) - // FIXME: Circular dependency due to vnInterceptor - // .fallbackLanguage(fallbackLang) - .determinePreferredLanguage(() => { - let locale = $translateProvider.resolveClientLocale(); - if (langs.indexOf(locale) !== -1) - return locale; - if (langAliases[locale]) - return langAliases[locale]; - return fallbackLang; + .useLoader('$translatePartialLoader', { + urlTemplate: '/locale/{part}/{lang}.json' }); + $translatePartialLoaderProvider.addPart('core'); $animateProvider.customFilter( node => node.tagName == 'UI-VIEW'); diff --git a/front/core/services/modules.js b/front/core/services/modules.js index 874a4a97b..4b0d93b76 100644 --- a/front/core/services/modules.js +++ b/front/core/services/modules.js @@ -10,15 +10,10 @@ export default class Modules { }); } - reset() { - this.modules = null; - } - - get() { - if (this.modules) - return this.modules; - + fetch() { + const map = {}; const modules = []; + for (let mod of this.$window.routes) { if (!mod || !mod.routes) continue; @@ -32,12 +27,15 @@ export default class Modules { if (res) keyBind = res.key.toUpperCase(); } - modules.push({ + const module = { name: mod.name || mod.module, icon: mod.icon || null, route, keyBind - }); + }; + + modules.push(module); + map[mod.module] = mod; } const sortedModules = modules.sort((a, b) => { @@ -46,9 +44,23 @@ export default class Modules { return translatedNameA.localeCompare(translatedNameB); }); this.modules = sortedModules; + this.map = map; + } + reset() { + this.modules = null; + this.map = null; + } + + get() { + if (!this.modules) this.fetch(); return this.modules; } + + getMap() { + if (!this.map) this.fetch(); + return this.map; + } } Modules.$inject = ['aclService', '$window', '$translate']; diff --git a/front/core/styles/font-family.scss b/front/core/styles/font-family.scss index db41ad750..035d96bc9 100644 --- a/front/core/styles/font-family.scss +++ b/front/core/styles/font-family.scss @@ -39,3 +39,8 @@ /* Support for IE. */ font-feature-settings: 'liga'; } + +[class^="icon-"] { + padding: .1em; + font-size: .833em; +} diff --git a/front/core/styles/layout.scss b/front/core/styles/layout.scss index 85088db6a..b287dfabd 100644 --- a/front/core/styles/layout.scss +++ b/front/core/styles/layout.scss @@ -4,17 +4,19 @@ html [vn-horizontal], vn-horizontal, .vn-horizontal, html [vn-vertical], vn-vertical, .vn-vertical { display: flex; + + & > * { + flex: 1; + } } html [vn-horizontal], vn-horizontal, .vn-horizontal { flex-direction: row; } -vn-horizontal[reverse] { - flex-direction: row-reverse; -} html [vn-vertical], vn-vertical, .vn-vertical { flex-direction: column; } -vn-vertical[reverse] { + +html [reverse] { flex-direction: column-reverse; } html [wrap] { @@ -26,27 +28,11 @@ html [wrap-reverse] { /* Horizontal & vertical childs */ -html [vn-auto], -html [vn-none], -html [vn-one], -html [vn-two], -html [vn-three], -html [vn-four], -html [vn-five], -html [vn-six], -html [vn-seven], -html [vn-eight], -html [vn-nine], -html [vn-ten], -html [vn-eleven], -html [vn-twelve]{ - flex-basis: .1px; -} html [vn-auto], vn-auto, .vn-auto { - flex-basis: auto; + flex: initial; } html [vn-none], vn-none, .vn-none { - flex: none; + flex: 0 0 auto; } html [vn-one], vn-one, .vn-one { flex: 1; diff --git a/front/core/styles/variables.scss b/front/core/styles/variables.scss index 0958c88b8..c71112ffe 100644 --- a/front/core/styles/variables.scss +++ b/front/core/styles/variables.scss @@ -4,6 +4,7 @@ $font-size: 12pt; $menu-width: 256px; $topbar-height: 56px; $mobile-width: 800px; +$float-spacing: 20px; // Width diff --git a/front/salix/components/app/app.html b/front/salix/components/app/app.html index 310ce8166..d32c9f68b 100644 --- a/front/salix/components/app/app.html +++ b/front/salix/components/app/app.html @@ -6,5 +6,4 @@ ng-if="!$ctrl.showLayout"> - - + diff --git a/front/salix/components/descriptor-popover/index.html b/front/salix/components/descriptor-popover/index.html new file mode 100644 index 000000000..224a81152 --- /dev/null +++ b/front/salix/components/descriptor-popover/index.html @@ -0,0 +1,6 @@ + +
+
+
\ No newline at end of file diff --git a/front/salix/components/descriptor-popover/index.js b/front/salix/components/descriptor-popover/index.js new file mode 100644 index 000000000..b746f5c81 --- /dev/null +++ b/front/salix/components/descriptor-popover/index.js @@ -0,0 +1,28 @@ +import ngModule from '../../module'; +import Popover from 'core/components/popover'; +import './style.scss'; + +export default class DescriptorPopover extends Popover { + show(parent, id) { + super.show(parent); + + this.id = id; + this.descriptor = this.content.querySelector('.vn-descriptor').$ctrl; + this.descriptor.load(id) + .then(() => this.$.$applyAsync(() => this.relocate())); + } + + hide() { + super.hide(); + this.id = null; + this.descriptor = null; + } +} + +ngModule.vnComponent('vnDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: DescriptorPopover, + transclude: { + descriptor: '?slotDescriptor' + } +}); diff --git a/front/salix/components/descriptor-popover/style.scss b/front/salix/components/descriptor-popover/style.scss new file mode 100644 index 000000000..3fc35a0af --- /dev/null +++ b/front/salix/components/descriptor-popover/style.scss @@ -0,0 +1,11 @@ +@import "variables"; + +.vn-descriptor-popover { + vn-descriptor-content > .descriptor { + width: 260px; + + & > .header > a:first-child { + visibility: hidden; + } + } +} diff --git a/front/salix/components/descriptor/index.html b/front/salix/components/descriptor/index.html index 4a50be430..20631333c 100644 --- a/front/salix/components/descriptor/index.html +++ b/front/salix/components/descriptor/index.html @@ -1,8 +1,40 @@ - - - - \ No newline at end of file + + +
+
+ + + + + + + + +
+ + + +
+
+
+
{{$ctrl.description}}
+
+ {{$ctrl.descriptor.id | id}} +
+
+
+
+
+
\ No newline at end of file diff --git a/front/salix/components/descriptor/index.js b/front/salix/components/descriptor/index.js index 504812b15..6b10b1ff9 100644 --- a/front/salix/components/descriptor/index.js +++ b/front/salix/components/descriptor/index.js @@ -1,12 +1,141 @@ import ngModule from '../../module'; +import Component from 'core/lib/component'; import './style.scss'; +import './quick-link'; -export default class QuickLinks {} +/** + * Small card with basing entity information and actions. + */ +export default class Descriptor extends Component { + $postLink() { + const content = this.element.querySelector('vn-descriptor-content'); + if (!content) throw new Error('Directive vnDescriptorContent not found'); -ngModule.component('vnQuickLinks', { - template: require('./index.html'), - controller: QuickLinks, + angular.element(content) + .controller('vnDescriptorContent') + .descriptor = this; + } + + get id() { + return this._id; + } + + set id(value) { + this.load(value); + } + + get entity() { + return this._entity; + } + + set entity(value) { + this._entity = value; + this._id = value && value.id; + } + + load(id) { + if (id == this._id) + return this.$q.resolve(); + + this._id = id; + + if (!id) { + this.entity = null; + return this.$q.resolve(); + } + + return this.loadData(); + } + + /** + * Reloads the descriptor data. Should be implemented or overriden by child + * classes. + */ + loadData() { + throw new Error('DescriptorPopover::loadData() method not implemented'); + } + + /** + * Performs a cancellable request. + * + * @param {String} url The http path + * @param {Object} options The request options + * @return {Promise} Resolved with request response + */ + getData(url, options) { + if (this.canceler) this.canceler.resolve(); + this.canceler = this.$q.defer(); + this.entity = null; + + options = Object.assign(options || {}, { + timeout: this.canceler.promise + }); + + return this.$http.get(url, options) + .finally(() => this.canceler = null); + } + + /** + * Shows a report in another window, automatically adds the authorization + * token to params. + * + * @param {String} report The report name + * @param {Object} params The report parameters + */ + showReport(report, params) { + params = Object.assign({ + authorization: this.vnToken.token + }, params); + const serializedParams = this.$httpParamSerializer(params); + window.open(`api/report/${report}?${serializedParams}`); + } + + /** + * Sends an email displaying a notification when it's sent. + * + * @param {String} report The email report name + * @param {Object} params The email parameters + * @return {Promise} Promise resolved when it's sent + */ + sendEmail(report, params) { + return this.$http.get(`email/${report}`, {params}) + .then(() => this.vnApp.showMessage(this.$t('Notification sent!'))); + } +} + +ngModule.vnComponent('vnDescriptor', { + controller: Descriptor, bindings: { - links: ' + + + \ No newline at end of file diff --git a/front/salix/components/descriptor/quick-link.js b/front/salix/components/descriptor/quick-link.js new file mode 100644 index 000000000..545f235a0 --- /dev/null +++ b/front/salix/components/descriptor/quick-link.js @@ -0,0 +1,13 @@ +import ngModule from '../../module'; + +export default class QuickLink {} + +ngModule.component('vnQuickLink', { + template: require('./quick-link.html'), + controller: QuickLink, + bindings: { + state: ' .header { - display: flex; - background: $color-main; - justify-content: space-between; - align-items: stretch; - color: $color-font-dark; - - & > * { - @extend %clickable; - min-width: 45px; - height: 45px; - box-sizing: border-box; - display: flex; - align-items: center; - justify-content: center; - color: inherit; - - & > vn-icon { - padding: 10px; - } - vn-icon { - font-size: 1.75rem; - } - } + & > vn-spinner { + display: block; + height: 40px; + padding: $spacing-md; } - & > .body { - padding: $spacing-sm; + & > div { + display: block; + box-shadow: 0 1px 3px $color-shadow; - & > * { - padding: $spacing-sm; - } - & > .attributes > h5 { - padding-bottom: $spacing-sm; - text-overflow: ellipsis; - white-space: nowrap; - overflow: hidden; - } - & > .icons { + & > .header { display: flex; - align-items: center; - justify-content: center; - padding: 0; - - & > vn-icon { - padding: $spacing-sm; - color: $color-marginal; - font-size: 1.5rem; - - &.bright { - color: $color-main; - opacity: 1; + background: $color-main; + justify-content: space-between; + align-items: stretch; + color: $color-font-dark; + + & > * { + display: flex; + min-width: 45px; + height: 45px; + box-sizing: border-box; + align-items: center; + justify-content: center; + } + & > a, + & > vn-icon-button { + @extend %clickable; + color: inherit; + + & > vn-icon { + padding: 10px; + } + vn-icon { + font-size: 1.75rem; } } } - .quicklinks, - vn-quick-links { - display: flex; - align-items: center; - justify-content: center; - - & > a { - padding: 0 $spacing-md; - margin: 0 $spacing-sm; + & > .body { + display: block; + padding: $spacing-md; - & > vn-icon { - font-size: 1.75rem; - padding: 0; + & > .top { + padding-bottom: $spacing-sm; + + & > * { + margin-bottom: 0; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + } + } + & > div > slot-body { + & > * { + padding-bottom: $spacing-md; + } + & > :last-child { + padding-bottom: 0; + } + & > .icons { + display: flex; + align-items: center; + justify-content: center; + + & > vn-icon { + padding: $spacing-xs $spacing-sm; + color: $color-marginal; + font-size: 1.5rem; + + &.bright { + color: $color-main; + opacity: 1; + } + } + } + & > .quicklinks { + display: flex; + align-items: center; + justify-content: center; + + vn-quick-link > a { + display: flex; + align-items: center; + justify-content: center; + padding: 0 $spacing-md; + margin: 0 $spacing-sm; + + & > vn-icon { + font-size: 1.75rem; + padding: 0; + } + } } } } } } -.vn-popover { - .vn-descriptor > .header > a:first-child { - visibility: hidden; - } -} \ No newline at end of file diff --git a/front/salix/components/index.js b/front/salix/components/index.js index 2afd55edf..1586272c0 100644 --- a/front/salix/components/index.js +++ b/front/salix/components/index.js @@ -1,6 +1,7 @@ import './app/app'; import './background/background'; import './descriptor'; +import './descriptor-popover'; import './home/home'; import './layout'; import './left-menu/left-menu'; diff --git a/front/salix/components/layout/index.html b/front/salix/components/layout/index.html index 0ad400114..8c716b84b 100644 --- a/front/salix/components/layout/index.html +++ b/front/salix/components/layout/index.html @@ -39,18 +39,26 @@
- + + + + + {{::mod.name}} + + + @@ -74,4 +82,5 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/front/salix/components/layout/style.scss b/front/salix/components/layout/style.scss index 14af8ac23..2b879040f 100644 --- a/front/salix/components/layout/style.scss +++ b/front/salix/components/layout/style.scss @@ -32,7 +32,7 @@ vn-layout { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; - padding-left: 6px; + padding-left: 10px; } & > vn-spinner { padding: 0 6px; @@ -80,7 +80,7 @@ vn-layout { padding-right: $menu-width; } [fixed-bottom-right] { - right: 64px + $menu-width; + right: $menu-width; } } & > .main-view { @@ -94,8 +94,9 @@ vn-layout { } [fixed-bottom-right] { position: fixed; - bottom: 32px; - right: 32px; + bottom: 0; + right: 0; + margin: $float-spacing; } &.ng-enter { vn-side-menu { @@ -133,7 +134,7 @@ vn-layout { padding-right: 0; } [fixed-bottom-right] { - right: 32px; + right: 0; } } ui-view > * { @@ -142,29 +143,6 @@ vn-layout { } } } -.vn-popover .modules-menu { - list-style-type: none; - margin: 0; - color: $color-font-dark; - - & > li { - @extend %clickable-light; - background-color: $color-main; - margin-bottom: 9px; - padding: 12px; - border-radius: 1px; - min-width: 128px; - white-space: nowrap; - - &:last-child { - margin-bottom: 0; - } - & > vn-icon { - padding-right: 4px; - vertical-align: middle; - } - } -} #user { font-size: 1.5rem; height: auto; diff --git a/front/salix/components/left-menu/left-menu.html b/front/salix/components/left-menu/left-menu.html index 7db36177b..ff32eea70 100644 --- a/front/salix/components/left-menu/left-menu.html +++ b/front/salix/components/left-menu/left-menu.html @@ -5,7 +5,7 @@ class="vn-item" ng-class="{active: item.active && !item.childs, expanded: item.active}" ng-click="$ctrl.setActive(item)"> - + diff --git a/front/salix/components/left-menu/style.scss b/front/salix/components/left-menu/style.scss index b98e2db2b..82562ea53 100644 --- a/front/salix/components/left-menu/style.scss +++ b/front/salix/components/left-menu/style.scss @@ -3,16 +3,12 @@ @import "variables"; vn-left-menu { - & > .vn-list { - padding: $spacing-md 0; - - & > li > .vn-item { - & > [side] > vn-icon[icon="keyboard_arrow_down"] { - transition: transform 200ms; - } - &.expanded > [side] > vn-icon[icon="keyboard_arrow_down"] { - transform: rotate(180deg); - } + & > .vn-list > li > .vn-item { + & > [side] > vn-icon[icon="keyboard_arrow_down"] { + transition: transform 200ms; + } + &.expanded > [side] > vn-icon[icon="keyboard_arrow_down"] { + transform: rotate(180deg); } } } diff --git a/front/salix/components/module-card/index.js b/front/salix/components/module-card/index.js index 9131cc772..9e547445f 100644 --- a/front/salix/components/module-card/index.js +++ b/front/salix/components/module-card/index.js @@ -6,11 +6,6 @@ import './style.scss'; * Base class for module cards. */ export default class ModuleCard extends Component { - constructor($element, $) { - super($element, $); - this.element.classList.add('vn-module-card'); - } - $onInit() { this.reload(); } diff --git a/front/salix/components/module-main/index.js b/front/salix/components/module-main/index.js index 39fbe42b8..ab292273c 100644 --- a/front/salix/components/module-main/index.js +++ b/front/salix/components/module-main/index.js @@ -2,12 +2,7 @@ import ngModule from '../../module'; import Component from 'core/lib/component'; import './style.scss'; -export default class ModuleMain extends Component { - constructor($element, $) { - super($element, $); - this.element.classList.add('vn-module-main'); - } -} +export default class ModuleMain extends Component {} ngModule.vnComponent('vnModuleMain', { template: require('./index.html'), diff --git a/front/salix/components/section/index.js b/front/salix/components/section/index.js index c34459147..f2440964c 100644 --- a/front/salix/components/section/index.js +++ b/front/salix/components/section/index.js @@ -2,17 +2,7 @@ import ngModule from '../../module'; import Component from 'core/lib/component'; import './style.scss'; -export default class Section extends Component { - constructor($element, $) { - super($element, $); - this.element.classList.add('vn-section'); - } - - stopEvent(event) { - event.preventDefault(); - event.stopImmediatePropagation(); - } -} +export default class Section extends Component {} ngModule.vnComponent('vnSection', { controller: Section diff --git a/front/salix/components/user-popover/index.js b/front/salix/components/user-popover/index.js index 764b0cae9..88efb26d1 100644 --- a/front/salix/components/user-popover/index.js +++ b/front/salix/components/user-popover/index.js @@ -1,15 +1,6 @@ import ngModule from '../../module'; import './style.scss'; - -let languages = { - es: 'Español', - en: 'English', - ca: 'Català', - pt: 'Português', - fr: 'Français', - nl: 'Nederlands', - mn: 'Монгол хэл' -}; +import config from '../../config.json'; class Controller { constructor($, $translate, vnConfig, vnAuth) { @@ -25,7 +16,7 @@ class Controller { for (let code of $translate.getAvailableLanguageKeys()) { this.langs.push({ code: code, - name: languages[code] ? languages[code] : code + name: config.languages[code] ? config.languages[code] : code }); } diff --git a/front/salix/config.json b/front/salix/config.json new file mode 100644 index 000000000..d87b70ae9 --- /dev/null +++ b/front/salix/config.json @@ -0,0 +1,25 @@ +{ + "imagePath": "//verdnatura.es/vn-image-data", + "langOptions": { + "fallbackLang": "es", + "langs": [ + "en", + "es" + ], + "langAliases": { + "en_US": "en", + "en_GB": "en", + "es_ES": "es", + "es_AR": "es" + } + }, + "languages": { + "es": "Español", + "en": "English", + "ca": "Català", + "pt": "Português", + "fr": "Français", + "nl": "Nederlands", + "mn": "Монгол хэл" + } +} diff --git a/front/salix/locale/es.yml b/front/salix/locale/es.yml index 3ce39af8d..287f840a5 100644 --- a/front/salix/locale/es.yml +++ b/front/salix/locale/es.yml @@ -12,7 +12,7 @@ Name: Nombre Preview: Vista previa Profile: Perfil Push on applications menu: Para abrir un módulo pulsa en el menú de aplicaciones -Return to module index: Volver a la página principal del módulo +Go to module index: Ir al índice del módulo What is new: Novedades de la versión Settings: Ajustes diff --git a/front/salix/module.js b/front/salix/module.js index 34e53b8bd..c3e8dcb8a 100644 --- a/front/salix/module.js +++ b/front/salix/module.js @@ -1,4 +1,5 @@ import {ng} from 'core/vendor'; +import appConfig from './config.json'; import 'core'; export const appName = 'salix'; @@ -8,6 +9,8 @@ export default ngModule; run.$inject = ['$window', '$rootScope', 'vnAuth', 'vnApp', '$state']; export function run($window, $rootScope, vnAuth, vnApp, $state) { + $rootScope.imagePath = appConfig.imagePath; + $window.validations = {}; vnApp.name = appName; @@ -57,8 +60,22 @@ export function run($window, $rootScope, vnAuth, vnApp, $state) { } ngModule.run(run); -config.$inject = ['$translatePartialLoaderProvider', '$httpProvider', '$compileProvider']; -export function config($translatePartialLoaderProvider, $httpProvider, $compileProvider) { +config.$inject = ['$translateProvider', '$translatePartialLoaderProvider', '$httpProvider', '$compileProvider']; +export function config($translateProvider, $translatePartialLoaderProvider, $httpProvider, $compileProvider) { + const langOptions = appConfig.langOptions; + $translateProvider + .registerAvailableLanguageKeys(langOptions.langs, langOptions.langAliases) + // TODO: Circular dependency due to vnInterceptor + // .fallbackLanguage(langOptions.fallbackLang) + .determinePreferredLanguage(() => { + const locale = $translateProvider.resolveClientLocale(); + if (langOptions.langs.indexOf(locale) !== -1) + return locale; + if (langOptions.langAliases[locale]) + return langOptions.langAliases[locale]; + return fallbackLang; + }); + $translatePartialLoaderProvider.addPart(appName); $httpProvider.interceptors.push('vnInterceptor'); diff --git a/front/salix/styles/order-product.scss b/front/salix/styles/order-product.scss index bd77144f2..11be8ebe0 100644 --- a/front/salix/styles/order-product.scss +++ b/front/salix/styles/order-product.scss @@ -6,6 +6,7 @@ justify-content: center; & > .product { + flex: initial; box-sizing: border-box; padding: $spacing-sm; width: 448px; diff --git a/loopback/common/models/schema.json b/loopback/common/models/schema.json index face506ff..1bdf0fcf7 100644 --- a/loopback/common/models/schema.json +++ b/loopback/common/models/schema.json @@ -3,11 +3,10 @@ "base": "PersistedModel", "acls": [ { - "property": "validations", - "accessType": "EXECUTE", + "property": "modelInfo", "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW" } ] -} +} \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 8003c31dd..eeb18fb73 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -131,5 +131,6 @@ "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto", "Distance must be lesser than 1000": "La distancia debe ser inferior a 1000", "This ticket is deleted": "Este ticket está eliminado", - "A travel with this data already exists": "Ya existe un travel con estos datos" + "A travel with this data already exists": "Ya existe un travel con estos datos", + "AMOUNT_NOT_MATCH_GROUPING": "AMOUNT_NOT_MATCH_GROUPING" } \ No newline at end of file diff --git a/loopback/server/boot/salix.js b/loopback/server/boot/salix.js deleted file mode 100644 index 018389e40..000000000 --- a/loopback/server/boot/salix.js +++ /dev/null @@ -1,9 +0,0 @@ -module.exports = function(app) { - // FIXME: Fix until the original can be used - app.get('/api/modelInfo', function(req, res) { - app.models.Schema.modelInfo({req}).then(json => { - res.set('Content-Type', 'application/json'); - res.send(JSON.stringify(json)); - }); - }); -}; diff --git a/modules/claim/back/models/claim-state.json b/modules/claim/back/models/claim-state.json index c905aacba..287a525ad 100644 --- a/modules/claim/back/models/claim-state.json +++ b/modules/claim/back/models/claim-state.json @@ -21,7 +21,7 @@ "required": true }, "priority": { - "type": "nomber", + "type": "Number", "required": true } }, diff --git a/modules/claim/front/action/index.html b/modules/claim/front/action/index.html index ad05082bb..69dfd255b 100644 --- a/modules/claim/front/action/index.html +++ b/modules/claim/front/action/index.html @@ -7,19 +7,16 @@ auto-save="true" on-save="$ctrl.onSave()"> - - -
@@ -57,7 +54,6 @@ on-change="$ctrl.save({isChargedToMana: value})">
- @@ -79,7 +75,7 @@ vn-repeat-last on-last="$ctrl.focusLastInput()"> {{::saleClaimed.sale.itemFk | zeroFill:6}} @@ -87,7 +83,7 @@ + ng-click="ticketDescriptor.show($event, saleClaimed.sale.ticketFk)"> {{::saleClaimed.sale.ticketFk}} @@ -121,7 +117,6 @@ -
- + on-accept="$ctrl.onUpdateGreugeAccept()"> \ No newline at end of file diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index 338d21cdf..2ba010ef2 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -41,18 +41,10 @@ export default class Controller extends Section { let query = `ClaimBeginnings/${this.$params.id}/importToNewRefundTicket`; return this.$http.post(query).then(() => { this.$.model.refresh(); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); }); } - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - - event.preventDefault(); - } - focusLastInput() { let inputs = document.querySelectorAll('#claimDestinationFk'); inputs[inputs.length - 1].querySelector('input').focus(); @@ -84,8 +76,7 @@ export default class Controller extends Section { }; this.$.lastTicketsModel.filter = filter; this.$.lastTicketsModel.refresh(); - this.$.lastTicketsPopover.parent = event.target; - this.$.lastTicketsPopover.show(); + this.$.lastTicketsPopover.show(event); } importTicketLines(ticketFk) { @@ -93,7 +84,7 @@ export default class Controller extends Section { let query = `ClaimEnds/importTicketSales`; this.$http.post(query, data).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); this.$.lastTicketsPopover.hide(); this.$.model.refresh(); }); @@ -105,7 +96,7 @@ export default class Controller extends Section { if (this.claim.responsibility >= Math.ceil(this.maxResponsibility) / 2) this.$.updateGreuge.show(); else - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); this.card.reload(); }); @@ -130,46 +121,36 @@ export default class Controller extends Section { }); } - onUpdateGreugeResponse(response) { - if (response == 'accept') { - const promises = []; - promises.push(this.getGreugeTypeId()); - promises.push(this.getGreugeConfig()); + onUpdateGreugeAccept() { + const promises = []; + promises.push(this.getGreugeTypeId()); + promises.push(this.getGreugeConfig()); - return Promise.all(promises).then(() => { - const data = { - clientFk: this.claim.clientFk, - description: this.$translate.instant('ClaimGreugeDescription', { - claimId: this.claim.id - }).toUpperCase(), - amount: this.freightPickUpPrice, - greugeTypeFk: this.greugeTypeFreightId, - ticketFk: this.claim.ticketFk - }; - return this.$http.post(`Greuges/`, data).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.vnApp.showMessage(this.$translate.instant('Greuge inserted')); - }); + return Promise.all(promises).then(() => { + const data = { + clientFk: this.claim.clientFk, + description: this.$t('ClaimGreugeDescription', { + claimId: this.claim.id + }).toUpperCase(), + amount: this.freightPickUpPrice, + greugeTypeFk: this.greugeTypeFreightId, + ticketFk: this.claim.ticketFk + }; + return this.$http.post(`Greuges`, data).then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.vnApp.showMessage(this.$t('Greuge inserted')); }); - } else - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - } - - showDescriptor(event, itemFk) { - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); + }); } save(data) { const query = `Claims/${this.$params.id}/updateClaimAction`; - this.$http.patch(query, data).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - }); + this.$http.patch(query, data) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); } onSave() { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showSuccess(this.$t('Data saved!')); } } diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index 503571f5b..c477984d9 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -6,20 +6,15 @@ describe('claim', () => { let controller; let $httpBackend; let $state; - let $httpParamSerializer; - let $scope; beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($rootScope, $componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => { - $scope = $rootScope.$new(); + beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; $state = _$state_; $state.params.id = 1; - const $element = angular.element(''); - controller = $componentController('vnClaimAction', {$element, $scope}); + controller = $componentController('vnClaimAction', {$element: null}); controller.claim = {ticketFk: 1}; controller.$.model = {refresh: () => {}}; controller.$.addSales = { @@ -67,8 +62,8 @@ describe('claim', () => { controller.importToNewRefundTicket(); $httpBackend.flush(); - expect(controller.$.model.refresh).toHaveBeenCalledWith(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.$.model.refresh).toHaveBeenCalled(); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); @@ -79,8 +74,8 @@ describe('claim', () => { controller.showLastTickets({}); - expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalledWith(); - expect(controller.$.lastTicketsPopover.show).toHaveBeenCalledWith(); + expect(controller.$.lastTicketsModel.refresh).toHaveBeenCalled(); + expect(controller.$.lastTicketsPopover.show).toHaveBeenCalled(); }); }); @@ -124,33 +119,21 @@ describe('claim', () => { controller.save(data); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); - describe('onUpdateGreugeResponse()', () => { + describe('onUpdateGreugeAccept()', () => { const greugeTypeId = 7; const freightPickUpPrice = 11; - it('should do nothing', () => { - jest.spyOn(controller.$http, 'post'); - jest.spyOn(controller.card, 'reload'); - jest.spyOn(controller.vnApp, 'showSuccess'); - - controller.onUpdateGreugeResponse('cancel'); - - expect(controller.$http.post).not.toHaveBeenCalledWith(); - expect(controller.card.reload).not.toHaveBeenCalledWith(); - expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Greuge inserted!'); - }); it('should make a query and get the greugeTypeId and greuge config', () => { jest.spyOn(controller.card, 'reload'); jest.spyOn(controller.vnApp, 'showSuccess'); - const greugeTypeParams = $httpParamSerializer({filter: {where: {code: 'freightPickUp'}}}); - $httpBackend.expect('GET', `GreugeTypes/findOne?${greugeTypeParams}`).respond({id: greugeTypeId}); - $httpBackend.expect('GET', `GreugeConfigs/findOne`).respond({freightPickUpPrice}); - controller.onUpdateGreugeResponse('accept'); + $httpBackend.expectRoute('GET', `GreugeTypes/findOne`).respond({id: greugeTypeId}); + $httpBackend.expectGET(`GreugeConfigs/findOne`).respond({freightPickUpPrice}); + controller.onUpdateGreugeAccept(); $httpBackend.flush(); expect(controller.greugeTypeFreightId).toEqual(greugeTypeId); @@ -181,7 +164,7 @@ describe('claim', () => { $httpBackend.expect('POST', `Greuges/`, data).respond(new Promise(resolve => { return resolve({id: freightPickUpPrice}); })); - controller.onUpdateGreugeResponse('accept').then(res => { + controller.onUpdateGreugeAccept().then(res => { }).catch(error => { diff --git a/modules/claim/front/descriptor/index.html b/modules/claim/front/descriptor/index.html index 789df37d6..52561b1d0 100644 --- a/modules/claim/front/descriptor/index.html +++ b/modules/claim/front/descriptor/index.html @@ -1,62 +1,81 @@ -
- -
+ + Send Pickup order + + + Delete claim + + +
-
{{$ctrl.claim.id}}
- - - - + - - - + - +
- - -
-
+ + + - diff --git a/modules/claim/front/descriptor/index.js b/modules/claim/front/descriptor/index.js index 55048c20c..ea7784f72 100644 --- a/modules/claim/front/descriptor/index.js +++ b/modules/claim/front/descriptor/index.js @@ -1,112 +1,43 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; - -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); - this.$httpParamSerializer = $httpParamSerializer; - - this.moreOptions = [ - {callback: this.showPickupOrder, name: 'Show Pickup order'}, - {callback: this.confirmPickupOrder, name: 'Send Pickup order'}, - {callback: this.confirmDeleteClaim, name: 'Delete claim', acl: 'salesAssistant'} - ]; - } - - onMoreOpen() { - let options = this.moreOptions.filter(option => { - const hasAclProperty = Object.hasOwnProperty.call(option, 'acl'); - - return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); - }); - this.$.moreButton.data = options; - } - - onMoreChange(callback) { - callback.call(this); - } +import Descriptor from 'salix/components/descriptor'; +class Controller extends Descriptor { get claim() { - return this._claim; + return this.entity; } set claim(value) { - this._claim = value; - - if (!value) return; - - this._quicklinks = { - btnOne: { - icon: 'person', - state: `client.card.summary({id: ${value.clientFk}})`, - tooltip: 'Client card' - }, - btnTwo: { - icon: 'icon-ticket', - state: `ticket.card.summary({id: ${this.claim.ticketFk}})`, - tooltip: 'Claimed ticket' - } - }; - } - - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; + this.entity = value; } showPickupOrder() { - const params = { + this.showReport('claim-pickup-order', { clientId: this.claim.clientFk, - claimId: this.claim.id, - authorization: this.vnToken.token - }; - const serializedParams = this.$httpParamSerializer(params); - let url = `api/report/claim-pickup-order?${serializedParams}`; - window.open(url); + claimId: this.claim.id + }); } - confirmPickupOrder() { - this.$.confirmPickupOrder.show(); + sendPickupOrder() { + return this.sendEmail('claim-pickup-order', { + recipient: this.claim.client.email, + clientId: this.claim.clientFk, + claimId: this.claim.id + }); } - sendPickupOrder(response) { - if (response === 'accept') { - const params = { - recipient: this.claim.client.email, - clientId: this.claim.clientFk, - claimId: this.claim.id - }; - this.$http.get(`email/claim-pickup-order`, {params}).then( - () => this.vnApp.showMessage(this.$translate.instant('Notification sent!')) - ); - } - } - - confirmDeleteClaim() { - this.$.confirmDeleteClaim.show(); - } - - deleteClaim(response) { - if (response === 'accept') { - this.$http.delete(`Claims/${this.claim.id}`).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Claim deleted!')); + deleteClaim() { + return this.$http.delete(`Claims/${this.claim.id}`) + .then(() => { + this.vnApp.showSuccess(this.$t('Claim deleted!')); this.$state.go('claim.index'); }); - } } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - -ngModule.component('vnClaimDescriptor', { +ngModule.vnComponent('vnClaimDescriptor', { template: require('./index.html'), controller: Controller, bindings: { - claim: '<', - tags: '<', - quicklinks: '<' + claim: '<' } }); diff --git a/modules/claim/front/descriptor/index.spec.js b/modules/claim/front/descriptor/index.spec.js index 4a78bda5a..1a18141ca 100644 --- a/modules/claim/front/descriptor/index.spec.js +++ b/modules/claim/front/descriptor/index.spec.js @@ -1,96 +1,62 @@ import './index.js'; describe('Item Component vnClaimDescriptor', () => { - let $httpParamSerializer; let $httpBackend; - let $element; - let $scope; let controller; + const claim = { + id: 2, + clientFk: 101, + client: {email: 'client@email'} + }; + beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { + beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - $scope = $rootScope.$new(); - $element = angular.element(''); - controller = $componentController('vnClaimDescriptor', {$element, $scope}); - controller.claim = {id: 2, clientFk: 101, client: {email: 'client@email'}}; + controller = $componentController('vnClaimDescriptor', {$element: null}, {claim}); })); describe('showPickupOrder()', () => { it('should open a new window showing a pickup order PDF document', () => { + controller.showReport = jest.fn(); + const params = { - clientId: controller.claim.clientFk, - claimId: controller.claim.id + clientId: claim.clientFk, + claimId: claim.id }; - const serializedParams = $httpParamSerializer(params); - let expectedPath = `api/report/claim-pickup-order?${serializedParams}`; - jest.spyOn(window, 'open').mockReturnThis(); controller.showPickupOrder(); - expect(window.open).toHaveBeenCalledWith(expectedPath); + expect(controller.showReport).toHaveBeenCalledWith('claim-pickup-order', params); }); }); - describe('confirmPickupOrder()', () => { - it('should call confirmPickupOrder.show()', () => { - controller.$.confirmPickupOrder = { - show: jasmine.createSpy('show') - }; - controller.claim = {id: 2}; - controller.confirmPickupOrder(); - - expect(controller.$.confirmPickupOrder.show).toHaveBeenCalledWith(); - }); - }); - - describe('sendPickupOrder(response)', () => { + describe('sendPickupOrder()', () => { it('should make a query and call vnApp.showMessage() if the response is accept', () => { - jest.spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller, 'sendEmail'); const params = { - recipient: 'client@email', - clientId: controller.claim.clientFk, - claimId: controller.claim.id + recipient: claim.client.email, + clientId: claim.clientFk, + claimId: claim.id }; - const serializedParams = $httpParamSerializer(params); + controller.sendPickupOrder(); - $httpBackend.when('GET', `email/claim-pickup-order?${serializedParams}`).respond(); - $httpBackend.expect('GET', `email/claim-pickup-order?${serializedParams}`).respond(); - controller.sendPickupOrder('accept'); - $httpBackend.flush(); - - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!'); + expect(controller.sendEmail).toHaveBeenCalledWith('claim-pickup-order', params); }); }); - describe('confirmDeleteClaim()', () => { - it('should call confirmDeleteClaim.show()', () => { - controller.$.confirmDeleteClaim = { - show: jasmine.createSpy('show') - }; - controller.claim = {id: 2}; - controller.confirmDeleteClaim(); - - expect(controller.$.confirmDeleteClaim.show).toHaveBeenCalledWith(); - }); - }); - - describe('deleteClaime(response)', () => { + describe('deleteClaim()', () => { it('should perform a query and call showSuccess if the response is accept', () => { - let response = 'accept'; - controller.claim = {id: 2}; - jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$state, 'go'); - $httpBackend.when('DELETE', `Claims/2`).respond(200); - $httpBackend.expect('DELETE', `Claims/2`); - controller.deleteClaim(response); + + $httpBackend.expectDELETE(`Claims/${claim.id}`).respond(); + controller.deleteClaim(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Claim deleted!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); expect(controller.$state.go).toHaveBeenCalledWith('claim.index'); }); }); diff --git a/modules/claim/front/detail/index.html b/modules/claim/front/detail/index.html index 7e225b16a..6061146c3 100644 --- a/modules/claim/front/detail/index.html +++ b/modules/claim/front/detail/index.html @@ -46,9 +46,9 @@ - + {{::saleClaimed.sale.concept}} @@ -81,10 +81,10 @@ + + Claimable sales from ticket {{$ctrl.claim.ticketFk}} + - -
Claimable sales from ticket {{$ctrl.claim.ticketFk}}
-
@@ -98,14 +98,17 @@ - + {{sale.landed | date: 'dd/MM/yyyy'}} {{sale.quantity}} - - {{sale.concept}} + + {{sale.itemFk}} - {{sale.concept}} {{sale.price | currency: 'EUR':2}} @@ -120,7 +123,7 @@
+ vn-id="itemDescriptor"> { }); }); - describe('showItemDescriptor()', () => { - it('should configure the descriptor then show it', () => { - const itemId = 500; - const event = { - stopImmediatePropagation: () => {}, - target: 'the target element' - }; - jest.spyOn(event, 'stopImmediatePropagation'); - jest.spyOn(controller.$.descriptor, 'show'); - - controller.showItemDescriptor(event, itemId); - - expect(event.stopImmediatePropagation).toHaveBeenCalledWith(); - expect(controller.$.descriptor.itemFk).toEqual(itemId); - expect(controller.$.descriptor.parent).toEqual(event.target); - expect(controller.$.descriptor.show).toHaveBeenCalledWith(); - }); - }); - describe('isClaimEditable()', () => { it('should check if the claim is editable', () => { controller.isClaimEditable(); diff --git a/modules/claim/front/development/index.html b/modules/claim/front/development/index.html index 2b504be11..3a78e6374 100644 --- a/modules/claim/front/development/index.html +++ b/modules/claim/front/development/index.html @@ -42,7 +42,6 @@ - {{::claim.id}} - + {{::claim.name}} {{::claim.created | date:'dd/MM/yyyy'}} - + {{::claim.nickName}} @@ -42,7 +44,7 @@ @@ -56,10 +58,10 @@ vn-id="clientDescriptor"> + vn-id="workerDescriptor"> - - + + + - \ No newline at end of file diff --git a/modules/claim/front/index/index.js b/modules/claim/front/index/index.js index df6d15b38..773c6a999 100644 --- a/modules/claim/front/index/index.js +++ b/modules/claim/front/index/index.js @@ -13,31 +13,9 @@ export default class Controller extends Section { } } - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - preview(event, claim) { + preview(claim) { this.claimSelected = claim; - this.$.dialogSummaryClaim.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); + this.$.summary.show(); } } diff --git a/modules/claim/front/locale/es.yml b/modules/claim/front/locale/es.yml index 26b1eba32..b65593bbd 100644 --- a/modules/claim/front/locale/es.yml +++ b/modules/claim/front/locale/es.yml @@ -14,4 +14,5 @@ Send Pickup order: Enviar orden de recogida Show Pickup order: Ver orden de recogida Search claim by id or client name: Buscar reclamaciones por identificador o nombre de cliente Claim deleted!: Reclamación eliminada! +claim: reclamacióm diff --git a/modules/claim/front/photos/index.html b/modules/claim/front/photos/index.html index 4a6e3e7b2..cb3f55b65 100644 --- a/modules/claim/front/photos/index.html +++ b/modules/claim/front/photos/index.html @@ -1,4 +1,6 @@ - @@ -25,19 +27,16 @@ - - - + on-accept="$ctrl.deleteDms($data)"> - + ng-click="$ctrl.openUploadDialog()" + fixed-bottom-right> diff --git a/modules/claim/front/photos/index.js b/modules/claim/front/photos/index.js index baf5fd154..0389e2d63 100644 --- a/modules/claim/front/photos/index.js +++ b/modules/claim/front/photos/index.js @@ -3,28 +3,13 @@ import Section from 'salix/components/section'; import './style.scss'; class Controller extends Section { - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.show(); - } - - showDeleteConfirm(index) { - this.dmsIndex = index; - this.$.confirm.show(); - } - - deleteDms(response) { - if (response === 'accept') { - const dmsFk = this.photos[this.dmsIndex].dmsFk; - const query = `claimDms/${dmsFk}/removeFile`; - this.$http.post(query).then(() => { - this.$.model.remove(this.dmsIndex); - this.vnApp.showSuccess(this.$translate.instant('Photo deleted')); + deleteDms(index) { + const dmsFk = this.photos[index].dmsFk; + return this.$http.post(`ClaimDms/${dmsFk}/removeFile`) + .then(() => { + this.$.model.remove(index); + this.vnApp.showSuccess(this.$t('Photo deleted')); }); - } } onDrop($event) { @@ -36,10 +21,10 @@ class Controller extends Section { } setDefaultParams() { - const params = {filter: { + const filter = { where: {code: 'claim'} - }}; - return this.$http.get('DmsTypes/findOne', {params}).then(res => { + }; + return this.$http.get('DmsTypes/findOne', {filter}).then(res => { const dmsTypeId = res.data && res.data.id; const companyId = this.vnConfig.companyFk; const warehouseId = this.vnConfig.warehouseFk; @@ -50,7 +35,7 @@ class Controller extends Section { warehouseId: warehouseId, companyId: companyId, dmsTypeId: dmsTypeId, - description: this.$translate.instant('FileDescription', { + description: this.$t('FileDescription', { claimId: this.claim.id, clientId: this.claim.client.id, clientName: this.claim.client.name @@ -91,7 +76,7 @@ class Controller extends Section { data: this.dms.files }; this.$http(options).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Photo uploaded!')); + this.vnApp.showSuccess(this.$t('Photo uploaded!')); this.$.model.refresh(); }); } diff --git a/modules/claim/front/photos/index.spec.js b/modules/claim/front/photos/index.spec.js index 1172800f6..9cb893bae 100644 --- a/modules/claim/front/photos/index.spec.js +++ b/modules/claim/front/photos/index.spec.js @@ -6,16 +6,13 @@ describe('Claim', () => { let $scope; let $httpBackend; let controller; - let $httpParamSerializer; beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { - $httpParamSerializer = _$httpParamSerializer_; + beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - const $element = angular.element(''); - controller = $componentController('vnClaimPhotos', {$element, $scope}); + controller = $componentController('vnClaimPhotos', {$element: null, $scope}); controller.$.model = crudModel; controller.claim = { id: 1, @@ -25,31 +22,25 @@ describe('Claim', () => { describe('deleteDms()', () => { it('should make an HTTP Post query', () => { - const dmsId = 1; - const dmsIndex = 0; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); - controller.photos = [{dmsFk: 1}]; - controller.dmsIndex = dmsIndex; - $httpBackend.when('POST', `claimDms/${dmsId}/removeFile`).respond({}); - $httpBackend.expect('POST', `claimDms/${dmsId}/removeFile`); - controller.deleteDms('accept'); + const dmsId = 1; + const dmsIndex = 0; + controller.photos = [{dmsFk: 1}]; + + $httpBackend.expectPOST(`ClaimDms/${dmsId}/removeFile`).respond(); + controller.deleteDms(dmsIndex); $httpBackend.flush(); expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Photo deleted'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('setDefaultParams()', () => { it('should make an HTTP GET query, then set all dms properties', () => { - const params = {filter: { - where: {code: 'claim'} - }}; - let serializedParams = $httpParamSerializer(params); - $httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({}); - $httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`); + $httpBackend.expectRoute('GET', `DmsTypes/findOne`).respond({}); controller.setDefaultParams(); $httpBackend.flush(); @@ -67,13 +58,12 @@ describe('Claim', () => { controller.dmsIndex = dmsIndex; controller.dms = {files: []}; - $httpBackend.when('POST', `claims/${claimId}/uploadFile`).respond({}); - $httpBackend.expect('POST', `claims/${claimId}/uploadFile`); + $httpBackend.expectPOST(`claims/${claimId}/uploadFile`).respond({}); controller.create(); $httpBackend.flush(); - expect(controller.$.model.refresh).toHaveBeenCalledWith(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Photo uploaded!'); + expect(controller.$.model.refresh).toHaveBeenCalled(); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); diff --git a/modules/claim/front/summary/index.html b/modules/claim/front/summary/index.html index 44a093336..ffc677572 100644 --- a/modules/claim/front/summary/index.html +++ b/modules/claim/front/summary/index.html @@ -6,16 +6,20 @@
{{::$ctrl.summary.claim.id}} - {{::$ctrl.summary.claim.client.name}}
- - - - @@ -61,7 +65,7 @@ {{::saleClaimed.sale.itemFk | zeroFill:6}} @@ -113,7 +117,7 @@ + ng-click="workerDescriptor.show($event, development.workerFk)"> {{::development.worker.user.nickname}} @@ -144,14 +148,14 @@ {{::action.sale.itemFk | zeroFill:6}} {{::action.sale.ticket.id | zeroFill:6}} @@ -177,8 +181,7 @@ vn-id="itemDescriptor"> + vn-id="workerDescriptor"> diff --git a/modules/claim/front/summary/index.js b/modules/claim/front/summary/index.js index a9bde7289..0ccf6dcd2 100644 --- a/modules/claim/front/summary/index.js +++ b/modules/claim/front/summary/index.js @@ -32,24 +32,6 @@ class Controller extends Section { this.summary = response.data; }); } - - showItemDescriptor(event, sale) { - this.$.itemDescriptor.itemFk = sale.itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } - - showWorkerDescriptor(event, workerFk) { - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - showTicketDescriptor(event, ticketId) { - this.$.ticketDescriptor.ticketFk = ticketId; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - } } ngModule.component('vnClaimSummary', { diff --git a/modules/client/front/address/create/index.html b/modules/client/front/address/create/index.html index 084af36e5..89c674a41 100644 --- a/modules/client/front/address/create/index.html +++ b/modules/client/front/address/create/index.html @@ -150,9 +150,9 @@ + on-accept="$ctrl.onCustomAgentAccept()" + message="New customs agent"> -
New customs agent
+ on-accept="$ctrl.onCustomAgentAccept()" + message="New customs agent"> -
New customs agent
- -
New payment
-
- - - - - - - - - - - - -
-
- - - - - \ No newline at end of file + + New payment + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/client/front/balance/create/index.js b/modules/client/front/balance/create/index.js index 5844e2204..880774f55 100644 --- a/modules/client/front/balance/create/index.js +++ b/modules/client/front/balance/create/index.js @@ -1,11 +1,9 @@ import ngModule from '../../module'; import Dialog from 'core/components/dialog'; -import template from './index.html'; class Controller extends Dialog { constructor($element, $, $transclude) { super($element, $, $transclude); - this.fillSlots(template); this.receipt = { payed: new Date(), @@ -76,8 +74,8 @@ class Controller extends Dialog { } ngModule.vnComponent('vnClientBalanceCreate', { + slotTemplate: require('./index.html'), controller: Controller, - transclude: true, bindings: { payed: '
@@ -66,19 +66,26 @@ + vn-click-stop="workerDescriptor.show($event, balance.workerFk)" + class="link"> {{::balance.userNickname}} - - {{balance.isInvoice ? 'BILL' : balance.ref | translate: {ref: balance.ref} }} - +
+ + {{'BILL' | translate: {ref: balance.ref} }} + + + {{::balance.ref}} + +
{{::balance.bankFk}} {{::balance.debit | currency: 'EUR':2}} @@ -121,10 +128,8 @@ company-fk="$ctrl.companyId"> + vn-id="workerDescriptor"> + vn-id="invoiceOutDescriptor"> \ No newline at end of file diff --git a/modules/client/front/balance/index/index.js b/modules/client/front/balance/index/index.js index 381800ad9..4030539ac 100644 --- a/modules/client/front/balance/index/index.js +++ b/modules/client/front/balance/index/index.js @@ -72,29 +72,6 @@ class Controller extends Section { } }); } - - showWorkerDescriptor(event, workerFk) { - if (event.defaultPrevented) return; - - event.preventDefault(); - event.stopPropagation(); - - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - showInvoiceOutDescriptor(event, balance) { - if (!balance.isInvoice) return; - if (event.defaultPrevented) return; - - event.preventDefault(); - event.stopPropagation(); - - this.selectedInvoiceOut = balance.id; - this.$.invoiceOutDescriptor.parent = event.target; - this.$.invoiceOutDescriptor.show(); - } } Controller.$inject = ['$element', '$scope']; diff --git a/modules/client/front/balance/index/locale/en.yml b/modules/client/front/balance/index/locale/en.yml new file mode 100644 index 000000000..53cb1313e --- /dev/null +++ b/modules/client/front/balance/index/locale/en.yml @@ -0,0 +1 @@ +BILL: N/INV {{ref}} \ No newline at end of file diff --git a/modules/client/front/billing-data/index.html b/modules/client/front/billing-data/index.html index 3be5de972..ca188955c 100644 --- a/modules/client/front/billing-data/index.html +++ b/modules/client/front/billing-data/index.html @@ -98,9 +98,9 @@ + on-accept="$ctrl.onBankEntityAccept()" + message="New bank entity"> -
New bank entity
{ describe('province() setter', () => { it(`should set countryFk property`, () => { + controller.client.countryFk = null; controller.province = { id: 1, name: 'New york', diff --git a/modules/client/front/descriptor-popover/index.html b/modules/client/front/descriptor-popover/index.html index e7b2f583a..28c271abc 100644 --- a/modules/client/front/descriptor-popover/index.html +++ b/modules/client/front/descriptor-popover/index.html @@ -1,12 +1,3 @@ - - - - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/modules/client/front/descriptor-popover/index.js b/modules/client/front/descriptor-popover/index.js index 1a1b41f76..12f7a1664 100644 --- a/modules/client/front/descriptor-popover/index.js +++ b/modules/client/front/descriptor-popover/index.js @@ -1,67 +1,9 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.client = null; - this._quicklinks = {}; - } +class Controller extends DescriptorPopover {} - set clientFk(id) { - if (id == this._clientFk) return; - - this._clientFk = id; - this.client = null; - this.getCard(); - } - - set client(value) { - this._client = value; - this.$timeout(() => this.$.popover.relocate()); - } - - get client() { - return this._client; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - getCard() { - if (this.canceler) - this.canceler.resolve(); - - this.canceler = this.$q.defer(); - - let options = {timeout: this.canceler.promise}; - this.$http.get(`Clients/${this._clientFk}/getCard`, options).then( - response => { - this.client = response.data; - this.canceler = null; - } - ); - } -} - -ngModule.component('vnClientDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - clientFk: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnClientDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/client/front/descriptor-popover/index.spec.js b/modules/client/front/descriptor-popover/index.spec.js deleted file mode 100644 index ff8ffceff..000000000 --- a/modules/client/front/descriptor-popover/index.spec.js +++ /dev/null @@ -1,80 +0,0 @@ -import './index'; - -describe('Client', () => { - describe('Component vnClientDescriptorPopover', () => { - let $httpBackend; - let $scope; - let controller; - let $element; - let $timeout; - - beforeEach(ngModule('client')); - - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { - $httpBackend = _$httpBackend_; - $timeout = _$timeout_; - $element = angular.element(`
`); - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnClientDescriptorPopover', {$scope, $element}); - })); - - describe('clientFk()', () => { - it(`should not apply any changes if the received id is the same stored in _clientFk`, () => { - controller.client = 'I exist!'; - controller._clientFk = 1; - jest.spyOn(controller, 'getCard'); - controller.clientFk = 1; - - expect(controller.client).toEqual('I exist!'); - expect(controller._clientFk).toEqual(1); - expect(controller.getCard).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _clientFk, set the client to null and then call getCard()`, () => { - controller.client = `Please don't`; - controller._clientFk = 1; - jest.spyOn(controller, 'getCard'); - controller.clientFk = 999; - - expect(controller.client).toBeNull(); - expect(controller._clientFk).toEqual(999); - expect(controller.getCard).toHaveBeenCalledWith(); - }); - }); - - describe('client()', () => { - it(`should save the client into _client and then call relocate()`, () => { - jest.spyOn(controller.$.popover, 'relocate'); - controller.client = `i'm the client!`; - $timeout.flush(); - - expect(controller._client).toEqual(`i'm the client!`); - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('getCard()', () => { - it(`should perform a get query to store the client data into the controller`, () => { - controller.clientFk = 1; - controller.canceler = null; - let response = {}; - $httpBackend.when('GET', `Clients/${controller._clientFk}/getCard`).respond(response); - $httpBackend.expect('GET', `Clients/${controller._clientFk}/getCard`); - controller.getCard(); - $httpBackend.flush(); - - expect(controller.client).toEqual(response); - }); - }); - }); -}); diff --git a/modules/client/front/descriptor-popover/style.scss b/modules/client/front/descriptor-popover/style.scss deleted file mode 100644 index 8de03b90b..000000000 --- a/modules/client/front/descriptor-popover/style.scss +++ /dev/null @@ -1,9 +0,0 @@ -vn-client-descriptor-popover { - vn-client-descriptor { - display: block; - width: 256px; - & > vn-card{ - margin: 0!important; - } - } -} diff --git a/modules/client/front/descriptor/index.html b/modules/client/front/descriptor/index.html index 1aedae1a5..44563aed6 100644 --- a/modules/client/front/descriptor/index.html +++ b/modules/client/front/descriptor/index.html @@ -1,43 +1,46 @@ -
- -
+ + Send SMS + + + Send consumer report + + +
-
{{$ctrl.client.name}}
- - - - - - -
@@ -68,36 +71,48 @@ ng-class="{bright: $ctrl.client.isTaxDataChecked == false}">
- - -
- - - - + + + + + + on-accept="$ctrl.onConsumerReportAccept()" + message="Send consumer report"> -
-
- Send consumer report -
- - - + + + -
diff --git a/modules/client/front/descriptor/index.js b/modules/client/front/descriptor/index.js index 70619dcf6..9948eab43 100644 --- a/modules/client/front/descriptor/index.js +++ b/modules/client/front/descriptor/index.js @@ -1,97 +1,58 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); - this.$httpParamSerializer = $httpParamSerializer; - - this.moreOptions = [ - {name: 'Simple ticket', callback: this.newTicket}, - {name: 'Send SMS', callback: this.showSMSDialog}, - {name: 'Send consumer report', callback: this.showConsumerReportDialog} - ]; +class Controller extends Descriptor { + get entity() { + return super.entity; } - onMoreChange(callback) { - callback.call(this); - } - - get client() { - return this._client; - } - - set client(value) { - this._client = value; - if (!value) return; + set entity(value) { + super.entity = value; if (this.$params.sendSMS) this.showSMSDialog(); - - this._quicklinks = { - btnOne: { - icon: 'icon-ticket', - state: `ticket.index({q: '{"clientFk": ${value.id}}'})`, - tooltip: 'Client ticket list' - }, - btnTwo: { - icon: 'icon-basketadd', - state: `order.create({clientFk: ${value.id}})`, - tooltip: 'New order' - } - }; } - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); + get client() { + return this.entity; } - get quicklinks() { - return this._quicklinks; + set client(value) { + this.entity = value; } - newTicket() { - this.$state.go('ticket.create', {clientFk: this.client.id}); + get filter() { + return JSON.stringify({clientFk: this.id}); + } + + loadData() { + return this.getData(`Clients/${this.id}/getCard`) + .then(res => this.entity = res.data); } showSMSDialog() { - const client = this.client; - const phone = this.$params.phone || client.mobile || client.phone; - const message = this.$params.message || ''; + const client = this.client || {}; this.newSMS = { - destinationFk: client.id, - destination: phone, - message: message + destinationFk: this.id, + destination: this.$params.phone || client.mobile || client.phone, + message: this.$params.message || '' }; this.$.sms.open(); } - showConsumerReportDialog() { - this.$.consumerReportDialog.show(); - } - - sendConsumerReport(response) { - if (response === 'accept') { - const params = { - authorization: this.vnToken.token, - clientId: this.client.id, - from: this.from, - to: this.to, - }; - const serializedParams = this.$httpParamSerializer(params); - const url = `api/report/campaign-metrics?${serializedParams}`; - window.open(url); - } + onConsumerReportAccept() { + this.showReport('campaign-metrics', { + clientId: this.id, + from: this.from, + to: this.to, + }); } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - -ngModule.component('vnClientDescriptor', { +ngModule.vnComponent('vnClientDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { - client: '<', - quicklinks: '<' - }, - controller: Controller + client: '<' + } }); diff --git a/modules/client/front/descriptor/index.spec.js b/modules/client/front/descriptor/index.spec.js new file mode 100644 index 000000000..1a123d901 --- /dev/null +++ b/modules/client/front/descriptor/index.spec.js @@ -0,0 +1,26 @@ +import './index'; + +describe('vnClientDescriptor', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('client')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnClientDescriptor', {$element: null}); + })); + + describe('loadData()', () => { + it(`should perform a get query to store the client data into the controller`, () => { + const id = 1; + const response = 'foo'; + + $httpBackend.expectGET(`Clients/${id}/getCard`).respond(response); + controller.id = id; + $httpBackend.flush(); + + expect(controller.client).toEqual(response); + }); + }); +}); diff --git a/modules/client/front/dms/index/index.html b/modules/client/front/dms/index/index.html index 987613d72..fd1527e23 100644 --- a/modules/client/front/dms/index/index.html +++ b/modules/client/front/dms/index/index.html @@ -62,7 +62,7 @@ + ng-click="workerDescriptor.show($event, document.dms.workerFk)"> {{::document.dms.worker.user.nickname | dashIfEmpty}} @@ -86,7 +86,7 @@ @@ -109,5 +109,5 @@ vn-id="confirm" message="This file will be deleted" question="Are you sure you want to continue?" - on-response="$ctrl.deleteDms($response)"> + on-accept="$ctrl.deleteDms($data)"> \ No newline at end of file diff --git a/modules/client/front/dms/index/index.js b/modules/client/front/dms/index/index.js index 2b47c3e57..577aff5be 100644 --- a/modules/client/front/dms/index/index.js +++ b/modules/client/front/dms/index/index.js @@ -24,8 +24,7 @@ class Controller extends Section { scope: { fields: ['name'] } - }, - { + }, { relation: 'worker', scope: { fields: ['userFk'], @@ -42,28 +41,13 @@ class Controller extends Section { }; } - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.show(); - } - - showDeleteConfirm(index) { - this.dmsIndex = index; - this.$.confirm.show(); - } - - deleteDms(response) { - if (response === 'accept') { - const dmsFk = this.clientDms[this.dmsIndex].dmsFk; - const query = `clientDms/${dmsFk}/removeFile`; - this.$http.post(query).then(() => { - this.$.model.remove(this.dmsIndex); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + deleteDms(index) { + const dmsFk = this.clientDms[index].dmsFk; + return this.$http.post(`ClientDms/${dmsFk}/removeFile`) + .then(() => { + this.$.model.remove(index); + this.vnApp.showSuccess(this.$t('Data saved!')); }); - } } } diff --git a/modules/client/front/dms/index/index.spec.js b/modules/client/front/dms/index/index.spec.js index 816e8a25d..e94cca806 100644 --- a/modules/client/front/dms/index/index.spec.js +++ b/modules/client/front/dms/index/index.spec.js @@ -12,27 +12,25 @@ describe('Client', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - const $element = angular.element(''); - controller = $componentController('vnClientDmsIndex', {$element, $scope}); + controller = $componentController('vnClientDmsIndex', {$element: null, $scope}); controller.$.model = crudModel; })); describe('deleteDms()', () => { it('should make an HTTP Post query', () => { - const dmsId = 1; - const dmsIndex = 0; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); - controller.clientDms = [{dmsFk: 1}]; - controller.dmsIndex = dmsIndex; - $httpBackend.when('POST', `clientDms/${dmsId}/removeFile`).respond({}); - $httpBackend.expect('POST', `clientDms/${dmsId}/removeFile`); - controller.deleteDms('accept'); + const dmsId = 1; + const dmsIndex = 0; + controller.clientDms = [{dmsFk: 1}]; + + $httpBackend.expectPOST(`ClientDms/${dmsId}/removeFile`).respond(); + controller.deleteDms(dmsIndex); $httpBackend.flush(); expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index fdbb0fafc..92e27e54f 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -98,14 +98,14 @@ export default class Controller extends Section { // Province auto complete set province(selection) { - const oldValue = this._province; this._province = selection; - if (!selection || !oldValue) return; + if (!selection) return; const country = selection.country; - this.client.countryFk = country.id; + if (!this.client.countryFk) + this.client.countryFk = country.id; } get town() { @@ -114,17 +114,19 @@ export default class Controller extends Section { // Town auto complete set town(selection) { - const oldValue = this._town; this._town = selection; - if (!selection || !oldValue) return; + if (!selection) return; const province = selection.province; const country = province.country; const postcodes = selection.postcodes; - this.client.provinceFk = province.id; - this.client.countryFk = country.id; + if (!this.client.provinceFk) + this.client.provinceFk = province.id; + + if (!this.client.countryFk) + this.client.countryFk = country.id; if (postcodes.length === 1) this.client.postcode = postcodes[0].code; @@ -145,9 +147,14 @@ export default class Controller extends Section { const province = town.province; const country = province.country; - this.client.city = town.name; - this.client.provinceFk = province.id; - this.client.countryFk = country.id; + if (!this.client.city) + this.client.city = town.name; + + if (!this.client.provinceFk) + this.client.provinceFk = province.id; + + if (!this.client.countryFk) + this.client.countryFk = country.id; } onResponse(response) { diff --git a/modules/client/front/fiscal-data/index.spec.js b/modules/client/front/fiscal-data/index.spec.js index a884f3e97..29608303c 100644 --- a/modules/client/front/fiscal-data/index.spec.js +++ b/modules/client/front/fiscal-data/index.spec.js @@ -26,9 +26,9 @@ describe('Client', () => { isTaxDataChecked: false }; - controller.province = {}; - controller.town = {}; - controller.postcode = {}; + controller._province = {}; + controller._town = {}; + controller._postcode = {}; })); describe('onSubmit()', () => { @@ -135,6 +135,7 @@ describe('Client', () => { describe('province() setter', () => { it(`should set countryFk property`, () => { + controller.client.countryFk = null; controller.province = { id: 1, name: 'New york', diff --git a/modules/client/front/locale/es.yml b/modules/client/front/locale/es.yml index 1b44b5652..42f3079bf 100644 --- a/modules/client/front/locale/es.yml +++ b/modules/client/front/locale/es.yml @@ -1,6 +1,7 @@ Active: Activo Amount: Importe Client: Cliente +client: cliente Comercial Name: Comercial Has to invoice: Factura Invoice by mail: Factura via e-mail diff --git a/modules/client/front/postcode/index.html b/modules/client/front/postcode/index.html index fd81534ed..ade256459 100644 --- a/modules/client/front/postcode/index.html +++ b/modules/client/front/postcode/index.html @@ -1,9 +1,9 @@ + on-accept="$ctrl.onAccept()" + message="New postcode"> -
New postcode

Please, ensure you put the correct data!

- - {{::sample.worker.user.nickname}} + + {{::sample.worker.user.nickname}} {{::sample.company.code}} @@ -41,8 +42,7 @@ + vn-id="workerDescriptor"> - -
+ + + + Show entry report + + +
- - @@ -47,8 +35,23 @@ ng-class="{bright: $ctrl.entry.isRaid}">
- - -
- + + + diff --git a/modules/entry/front/descriptor/index.js b/modules/entry/front/descriptor/index.js index 7b004754c..81b7946d1 100644 --- a/modules/entry/front/descriptor/index.js +++ b/modules/entry/front/descriptor/index.js @@ -1,84 +1,52 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; - -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); - this.$httpParamSerializer = $httpParamSerializer; - - this.moreOptions = [ - {name: 'Show entry report', callback: this.showEntryReport} - ]; - } - - onMoreChange(callback) { - callback.call(this); - } +import Descriptor from 'salix/components/descriptor'; +class Controller extends Descriptor { get entry() { - return this._entry; + return this.entity; } set entry(value) { - this._entry = value; - if (!value) return; + this.entity = value; + } - const date = value.travel.landed; - let to = new Date(date); - let from = new Date(date); + get travelFilter() { + return this.entry && JSON.stringify({ + agencyFk: this.entry.travel.agencyFk + }); + } + + get entryFilter() { + if (!this.entry) return null; + + const date = new Date(this.entry.travel.landed); + date.setHours(0, 0, 0, 0); + + const from = new Date(date.getTime()); + from.setDate(from.getDate() - 10); + + const to = new Date(date.getTime()); to.setDate(to.getDate() + 10); - to.setHours(0, 0, 0, 0); - - from.setDate(from.getDate() - 10); - from.setHours(0, 0, 0, 0); - - let links = { - btnOne: { - icon: 'local_airport', - state: `travel.index({q: '{"agencyFk": ${value.travel.agencyFk}}'})`, - tooltip: 'All travels with current agency' - }}; - - links.btnTwo = { - icon: 'icon-entry', - state: `entry.index({q: '{"supplierFk": ${value.supplierFk}, "to": "${to}", "from": "${from}"}'})`, - tooltip: 'All entries with current supplier' - }; - - this._quicklinks = links; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); + return JSON.stringify({ + supplierFk: this.entry.supplierFk, + from, + to + }); } showEntryReport() { - const params = { - authorization: this.vnToken.token, + this.showReport('entry-order', { clientId: this.vnConfig.storage.currentUserWorkerId, entryId: this.entry.id - }; - const serializedParams = this.$httpParamSerializer(params); - let url = `api/report/entry-order?${serializedParams}`; - window.open(url); + }); } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - -ngModule.component('vnEntryDescriptor', { +ngModule.vnComponent('vnEntryDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { - entry: '<', - quicklinks: '<' - }, - require: { - card: '^?vnEntryCard' - }, - controller: Controller + entry: '<' + } }); diff --git a/modules/entry/front/descriptor/index.spec.js b/modules/entry/front/descriptor/index.spec.js index f73604d51..c25755bcd 100644 --- a/modules/entry/front/descriptor/index.spec.js +++ b/modules/entry/front/descriptor/index.spec.js @@ -1,35 +1,26 @@ import './index.js'; describe('Entry Component vnEntryDescriptor', () => { - let $httpParamSerializer; let controller; - let $element; + const entry = {id: 2}; beforeEach(ngModule('entry')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, _$httpParamSerializer_) => { - $httpParamSerializer = _$httpParamSerializer_; - $element = angular.element(``); - controller = $componentController('vnEntryDescriptor', {$element}); - controller._entry = {id: 2}; - controller.vnConfig.storage = {currentUserWorkerId: 9}; - controller.cardReload = ()=> { - return true; - }; + beforeEach(inject($componentController => { + controller = $componentController('vnEntryDescriptor', {$element: null}, {entry}); })); describe('showEntryReport()', () => { it('should open a new window showing a delivery note PDF document', () => { + controller.showReport = jest.fn(); + const params = { clientId: controller.vnConfig.storage.currentUserWorkerId, - entryId: controller.entry.id + entryId: entry.id }; - const serializedParams = $httpParamSerializer(params); - let expectedPath = `api/report/entry-order?${serializedParams}`; - jest.spyOn(window, 'open').mockReturnThis(); controller.showEntryReport(); - expect(window.open).toHaveBeenCalledWith(expectedPath); + expect(controller.showReport).toHaveBeenCalledWith('entry-order', params); }); }); }); diff --git a/modules/entry/front/index/index.html b/modules/entry/front/index/index.html index 70601e104..e3d174cbf 100644 --- a/modules/entry/front/index/index.html +++ b/modules/entry/front/index/index.html @@ -43,7 +43,7 @@ + vn-click-stop="travelDescriptor.show($event, entry.travelFk)"> {{::entry.landed | date:'dd/MM/yyyy'}} @@ -58,21 +58,15 @@ + icon="insert_drive_file" + class="bright">
- + - - - - - - \ No newline at end of file + vn-id="travelDescriptor"> + \ No newline at end of file diff --git a/modules/entry/front/index/index.js b/modules/entry/front/index/index.js index ab0a901b7..60d70afcb 100644 --- a/modules/entry/front/index/index.js +++ b/modules/entry/front/index/index.js @@ -1,17 +1,7 @@ import ngModule from '../module'; import Section from 'salix/components/section'; -import './style.scss'; -export default class Controller extends Section { - showTravelDescriptor(event, travelFk) { - if (event.defaultPrevented) return; - event.preventDefault(); - event.stopPropagation(); - this.selectedTravel = travelFk; - this.$.travelDescriptor.parent = event.target; - this.$.travelDescriptor.show(); - } -} +export default class Controller extends Section {} ngModule.component('vnEntryIndex', { template: require('./index.html'), diff --git a/modules/entry/front/index/style.scss b/modules/entry/front/index/style.scss deleted file mode 100644 index ab759d2cc..000000000 --- a/modules/entry/front/index/style.scss +++ /dev/null @@ -1,5 +0,0 @@ -@import "variables"; - - vn-icon[icon=insert_drive_file]{ - color: $color-font-secondary; - } diff --git a/modules/entry/front/locale/es.yml b/modules/entry/front/locale/es.yml index 3de6c59a8..0858bb7f9 100644 --- a/modules/entry/front/locale/es.yml +++ b/modules/entry/front/locale/es.yml @@ -1,3 +1,5 @@ #Ordenar alfabeticamente +entry: entrada + # Sections diff --git a/modules/entry/front/summary/style.scss b/modules/entry/front/summary/style.scss index 8887e15b9..1374d2ec7 100644 --- a/modules/entry/front/summary/style.scss +++ b/modules/entry/front/summary/style.scss @@ -3,8 +3,4 @@ vn-entry-summary .summary { max-width: $width-lg; - - vn-icon[icon=insert_drive_file]{ - color: $color-font-secondary; - } } \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor-popover/index.html b/modules/invoiceOut/front/descriptor-popover/index.html index c4234535c..2bd912133 100644 --- a/modules/invoiceOut/front/descriptor-popover/index.html +++ b/modules/invoiceOut/front/descriptor-popover/index.html @@ -1,12 +1,4 @@ - - - - + + - \ No newline at end of file + \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor-popover/index.js b/modules/invoiceOut/front/descriptor-popover/index.js index c530bdd0f..fc9899da0 100644 --- a/modules/invoiceOut/front/descriptor-popover/index.js +++ b/modules/invoiceOut/front/descriptor-popover/index.js @@ -1,77 +1,9 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $,) { - super($element, $); - this.worker = null; - this._quicklinks = {}; - } +class Controller extends DescriptorPopover {} - set invoiceOutId(id) { - if (id == this._invoiceOutId) return; - - this._invoiceOutId = id; - this.invoiceOut = null; - this.loadData(); - } - - get invoiceOutId() { - return this._invoiceOutId; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - loadData() { - let query = `InvoiceOuts/findOne`; - let filter = { - where: { - id: this._invoiceOutId - }, - include: [ - { - relation: 'company', - scope: { - fields: ['id', 'code'] - } - }, - { - relation: 'client', - scope: { - fields: ['id', 'name'] - } - } - ] - }; - - this.$http.get(query, {params: {filter}}).then(res => { - this.invoiceOut = res.data; - this.$.$applyAsync(() => { - this.$.popover.relocate(); - }); - }); - } -} - -ngModule.component('vnInvoiceOutDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - invoiceOutId: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnInvoiceOutDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/invoiceOut/front/descriptor-popover/style.scss b/modules/invoiceOut/front/descriptor-popover/style.scss deleted file mode 100644 index f50481083..000000000 --- a/modules/invoiceOut/front/descriptor-popover/style.scss +++ /dev/null @@ -1,11 +0,0 @@ -vn-ticket-descriptor-popover { - vn-ticket-descriptor { - display: block; - width: 256px; - max-height: 448px; - - & > vn-card { - margin: 0!important; - } - } -} \ No newline at end of file diff --git a/modules/invoiceOut/front/descriptor/index.html b/modules/invoiceOut/front/descriptor/index.html index 1c18d92ed..9baebb636 100644 --- a/modules/invoiceOut/front/descriptor/index.html +++ b/modules/invoiceOut/front/descriptor/index.html @@ -1,43 +1,70 @@ -
- -
+ + Delete Invoice + + + Book invoice + + +
-
{{$ctrl.invoiceOut.ref}}
- - - + -
- - -
-
+ + + { - const hasAclProperty = Object.hasOwnProperty.call(option, 'acl'); - - return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); - }); - this.$.moreButton.data = options; - } - - onMoreChange(callback) { - callback.call(this); +class Controller extends Descriptor { + get invoiceOut() { + return this.entity; } set invoiceOut(value) { - this._invoiceOut = value; - - if (value) { - this._quicklinks = { - btnOne: { - icon: 'icon-person', - state: `client.card.summary({id: ${value.clientFk}})`, - tooltip: 'Client card' - }, - btnTwo: { - icon: 'icon-ticket', - state: `ticket.index({q: '{"refFk": "${value.ref}"}'})`, - tooltip: 'Invoice ticket list' - } - }; - } - } - - get invoiceOut() { - return this._invoiceOut; - } - - showInvoiceOutPdf() { - let url = `api/InvoiceOuts/${this.invoiceOut.id}/download?access_token=${this.accessToken}`; - window.open(url, '_blank'); - } - - showDeleteInvoiceOutDialog() { - this.$.deleteConfirmation.show(); - } - - showBookInvoiceOutDialog() { - this.$.bookConfirmation.show(); + this.entity = value; } deleteInvoiceOut() { - const query = `InvoiceOuts/${this.invoiceOut.id}/delete`; - return this.$http.post(query) + return this.$http.post(`InvoiceOuts/${this.id}/delete`) .then(() => this.$state.go('invoiceOut.index')) .then(() => this.vnApp.showSuccess(this.$t('InvoiceOut deleted'))); } bookInvoiceOut() { - const query = `InvoiceOuts/${this.invoiceOut.ref}/book`; - return this.$http.post(query) + return this.$http.post(`InvoiceOuts/${this.invoiceOut.ref}/book`) .then(() => this.$state.reload()) .then(() => this.vnApp.showSuccess(this.$t('InvoiceOut booked'))); } - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } + loadData() { + const filter = { + include: [ + { + relation: 'company', + scope: { + fields: ['id', 'code'] + } + }, { + relation: 'client', + scope: { + fields: ['id', 'name'] + } + } + ] + }; - get quicklinks() { - return this._quicklinks; + return this.getData(`InvoiceOuts/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -ngModule.component('vnInvoiceOutDescriptor', { +ngModule.vnComponent('vnInvoiceOutDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { - invoiceOut: '<', - quicklinks: '<' - }, - controller: Controller + invoiceOut: '<' + } }); diff --git a/modules/invoiceOut/front/index/index.html b/modules/invoiceOut/front/index/index.html index ad7c363ce..d5b911153 100644 --- a/modules/invoiceOut/front/index/index.html +++ b/modules/invoiceOut/front/index/index.html @@ -29,7 +29,7 @@ + vn-click-stop="clientDescriptor.show($event, invoiceOut.clientFk)"> {{::invoiceOut.clientSocialName | dashIfEmpty}} @@ -39,7 +39,7 @@ @@ -47,7 +47,7 @@ @@ -65,4 +65,3 @@ - \ No newline at end of file diff --git a/modules/invoiceOut/front/index/index.js b/modules/invoiceOut/front/index/index.js index d5c0fde3a..17eb44fec 100644 --- a/modules/invoiceOut/front/index/index.js +++ b/modules/invoiceOut/front/index/index.js @@ -2,30 +2,14 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - preview(event, invoiceOut) { + preview(invoiceOut) { this.selectedInvoiceOut = invoiceOut; this.$.summary.show(); - event.preventDefault(); - event.stopImmediatePropagation(); } - onDescriptorLoad() { - this.$.popover.relocate(); - } - - openPdf(id, event) { + openPdf(id) { let url = `api/InvoiceOuts/${id}/download?access_token=${this.vnToken.token}`; window.open(url, '_blank'); - event.preventDefault(); - event.stopImmediatePropagation(); } } diff --git a/modules/invoiceOut/front/locale/es.yml b/modules/invoiceOut/front/locale/es.yml index 87de48f56..9856dccfb 100644 --- a/modules/invoiceOut/front/locale/es.yml +++ b/modules/invoiceOut/front/locale/es.yml @@ -1,2 +1,3 @@ Invoice out: Facturas +invoiceOut: factura Search invoices by reference: Buscar facturas por referencia \ No newline at end of file diff --git a/modules/invoiceOut/front/summary/index.html b/modules/invoiceOut/front/summary/index.html index 19ceeb3ab..8deb7ddf8 100644 --- a/modules/invoiceOut/front/summary/index.html +++ b/modules/invoiceOut/front/summary/index.html @@ -54,14 +54,14 @@ {{ticket.id}} {{ticket.nickname}} diff --git a/modules/invoiceOut/front/summary/index.js b/modules/invoiceOut/front/summary/index.js index 7b9bb9efd..ef76768de 100644 --- a/modules/invoiceOut/front/summary/index.js +++ b/modules/invoiceOut/front/summary/index.js @@ -14,29 +14,8 @@ class Controller extends Section { } getSummary() { - this.$http.get(`InvoiceOuts/${this.invoiceOut.id}/summary`).then(response => { - this.summary = response.data; - }); - } - - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - } - - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - event.preventDefault(); - } - - preview(event, invoiceOut) { - this.selectedInvoiceOut = invoiceOut; - this.$.invoiceOutSummaryDialog.show(); - event.preventDefault(); + return this.$http.get(`InvoiceOuts/${this.invoiceOut.id}/summary`) + .then(res => this.summary = res.data); } } diff --git a/modules/invoiceOut/front/summary/style.scss b/modules/invoiceOut/front/summary/style.scss index dcad44362..e6e31fd94 100644 --- a/modules/invoiceOut/front/summary/style.scss +++ b/modules/invoiceOut/front/summary/style.scss @@ -3,8 +3,4 @@ vn-invoice-out-summary .summary { max-width: $width-lg; - - vn-icon[icon=insert_drive_file]{ - color: $color-font-secondary; - } } \ No newline at end of file diff --git a/modules/item/front/basic-data/index.html b/modules/item/front/basic-data/index.html index 3cd879945..7b3504b3c 100644 --- a/modules/item/front/basic-data/index.html +++ b/modules/item/front/basic-data/index.html @@ -145,9 +145,9 @@ + on-accept="$ctrl.onIntrastatAccept()" + message="New intrastat"> -
New intrastat
- - - + + + + + + - + diff --git a/modules/item/front/descriptor-popover/index.js b/modules/item/front/descriptor-popover/index.js index c7a62baae..92baefa9c 100644 --- a/modules/item/front/descriptor-popover/index.js +++ b/modules/item/front/descriptor-popover/index.js @@ -1,77 +1,23 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.item = null; - this._quicklinks = {}; +class Controller extends DescriptorPopover { + show(parent, id, lineFk) { + super.show(parent, id); + this.lineFk = lineFk; } - set itemFk(id) { - if (id == this._itemFk) return; - - this._itemFk = id; - this.item = null; - this._quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${id}, - })`, - tooltip: 'Item diary' - } - }; - this.getCard(); - } - - set item(value) { - this._item = value; - this.$timeout(() => this.$.popover.relocate()); - } - - get item() { - return this._item; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - getCard() { - if (this.canceler) - this.canceler.resolve(); - - this.canceler = this.$q.defer(); - - let options = {timeout: this.canceler.promise}; - this.$http.get(`Items/${this._itemFk}/getCard`, options).then( - response => { - this.item = response.data; - this.canceler = null; - } - ); + hide() { + super.hide(); + this.lineFk = null; } } -Controller.$inject = ['$element', '$scope']; -ngModule.component('vnItemDescriptorPopover', { - template: require('./index.html'), +ngModule.vnComponent('vnItemDescriptorPopover', { + slotTemplate: require('./index.html'), controller: Controller, bindings: { - itemFk: '<', - quicklinks: '<' + warehouseFk: ' { - describe('Component vnItemDescriptorPopover', () => { - let $httpBackend; - let $scope; - let controller; - let $timeout; - - beforeEach(ngModule('item')); - - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { - $httpBackend = _$httpBackend_; - $timeout = _$timeout_; - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - const $element = angular.element(''); - controller = $componentController('vnItemDescriptorPopover', {$element, $scope}); - })); - - describe('itemFk()', () => { - it(`should not apply any changes if the received id is the same stored in _itemFk`, () => { - controller.item = 'I exist!'; - controller._itemFk = 1; - jest.spyOn(controller, 'getCard'); - controller.itemFk = 1; - - expect(controller.item).toEqual('I exist!'); - expect(controller._itemFk).toEqual(1); - expect(controller.getCard).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _itemFk, set the item to null and then call getCard()`, () => { - controller.item = `Please don't`; - controller._itemFk = 1; - jest.spyOn(controller, 'getCard'); - controller.itemFk = 999; - - expect(controller.item).toBeNull(); - expect(controller._itemFk).toEqual(999); - expect(controller.getCard).toHaveBeenCalledWith(); - }); - }); - - describe('item()', () => { - it(`should save the item into _item and then call relocate()`, () => { - jest.spyOn(controller.$.popover, 'relocate'); - controller.item = `i'm the item!`; - $timeout.flush(); - - expect(controller._item).toEqual(`i'm the item!`); - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('getCard()', () => { - it(`should perform a get query to store the item data into the controller`, () => { - controller.itemFk = 1; - controller.canceler = null; - let response = {}; - $httpBackend.when('GET', `Items/${controller._itemFk}/getCard`).respond(response); - $httpBackend.expect('GET', `Items/${controller._itemFk}/getCard`); - controller.getCard(); - $httpBackend.flush(); - - expect(controller.item).toEqual(response); - }); - }); - }); -}); diff --git a/modules/item/front/descriptor-popover/style.scss b/modules/item/front/descriptor-popover/style.scss deleted file mode 100644 index 219e68bae..000000000 --- a/modules/item/front/descriptor-popover/style.scss +++ /dev/null @@ -1,5 +0,0 @@ -body > .vn-popover vn-item-descriptor { - display: block; - width: 256px; - min-height: 448px; -} \ No newline at end of file diff --git a/modules/item/front/descriptor/index.html b/modules/item/front/descriptor/index.html index 81f8299b0..a84f9eb95 100644 --- a/modules/item/front/descriptor/index.html +++ b/modules/item/front/descriptor/index.html @@ -1,28 +1,21 @@ -
-
- - - - - - - - -
-
+ + + + Regularize stock + + +
+ ng-src="{{::$root.imagePath}}/catalog/200x200/{{$ctrl.item.image}}" + zoom-image="{{::$root.imagePath}}/catalog/1600x900/{{$ctrl.item.image}}" + on-error-src + /> {{$ctrl.available | dashIfEmpty}}

-
-
+ +
-
{{$ctrl.item.id}}
- - - + ng-repeat="tag in $ctrl.item.tags | limitTo:4" + label="{{tag.tag.name}}" + value="{{tag.value}}">
@@ -64,36 +54,30 @@ ng-class="{bright: $ctrl.item.isActive == false}">
- - -
-
+ + + + on-open="$ctrl.warehouseFk = $ctrl.vnConfig.warehouseFk" + on-close="$ctrl.clearRegularizeDialog()" + on-accept="$ctrl.saveRegularize()" + message="Regularize stock"> -
-
- Regularize stock -
- - - - -
+ + + +
diff --git a/modules/item/front/descriptor/index.js b/modules/item/front/descriptor/index.js index e04fdb595..ab901faf5 100644 --- a/modules/item/front/descriptor/index.js +++ b/modules/item/front/descriptor/index.js @@ -1,87 +1,58 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; import './style.scss'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.moreOptions = [ - {callback: this.showRegularizeDialog, name: 'Regularize stock'} - ]; - } - - set quantity(value) { - this._quantity = parseInt(value); - } - - get quantity() { - return this._quantity; - } - - set warehouseFk(value) { - if (value) - this._warehouseFk = value; - } - get warehouseFk() { - if (!this._warehouseFk) - this._warehouseFk = this.vnConfig.warehouseFk; - - return this._warehouseFk; +class Controller extends Descriptor { + get item() { + return this.entity; } set item(value) { - this._item = value; - if (value && value.itemType && value.itemType.warehouseFk) - this.updateStock(value.itemType.warehouseFk); + this.entity = value; } - get item() { - return this._item; + get entity() { + return super.entity; } - updateStock(warehouseFk) { + set entity(value) { + super.entity = value; + this.updateStock(); + } + + loadData() { + return this.getData(`Items/${this.id}/getCard`) + .then(res => this.entity = res.data); + } + + updateStock() { this.available = null; this.visible = null; - if (this._item && this._item.id) { - let options = { - params: { - warehouseFk: warehouseFk - } - }; - this.$http.get(`Items/${this._item.id}/getVisibleAvailable`, options).then(response => { - this.available = response.data.available; - this.visible = response.data.visible; + if (!this.item) return; + + const params = { + warehouseFk: this.item.itemType.warehouseFk + }; + + return this.$http.get(`Items/${this.id}/getVisibleAvailable`, {params}) + .then(res => { + this.available = res.data.available; + this.visible = res.data.visible; }); - } } - onMoreChange(callback) { - callback.call(this); - } + saveRegularize() { + const params = { + itemFk: this.id, + quantity: parseInt(this.quantity), + warehouseFk: this.warehouseFk + }; - showRegularizeDialog() { - this.$.regularize.show(); - } - - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } - - saveRegularize(response) { - if (response == 'accept') { - this.$http.post(`Items/regularize`, { - itemFk: this.item.id, - quantity: this.quantity, - warehouseFk: this.warehouseFk - }).then(res => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.updateStock(this.item.itemType.warehouseFk); + return this.$http.post(`Items/regularize`, params) + .then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.updateStock(); }); - } } clearRegularizeDialog() { @@ -90,13 +61,10 @@ class Controller extends Component { } } -Controller.$inject = ['$element', '$scope']; - -ngModule.component('vnItemDescriptor', { +ngModule.vnComponent('vnItemDescriptor', { template: require('./index.html'), controller: Controller, bindings: { - item: '<', - quicklinks: '<' + item: '<' } }); diff --git a/modules/item/front/descriptor/index.spec.js b/modules/item/front/descriptor/index.spec.js new file mode 100644 index 000000000..7406d1800 --- /dev/null +++ b/modules/item/front/descriptor/index.spec.js @@ -0,0 +1,36 @@ +import './index'; + +describe('vnItemDescriptor', () => { + let controller; + let $httpBackend; + + const item = { + id: 1, + itemType: { + warehouseFk: 1 + } + }; + const stock = { + visible: 1, + available: 5 + }; + + beforeEach(ngModule('item')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + $httpBackend.whenRoute('GET', `Items/${item.id}/getVisibleAvailable`).respond(stock); + + controller = $componentController('vnItemDescriptor', {$element: null}); + })); + + describe('loadData()', () => { + it(`should perform a get query to store the item data into the controller`, () => { + $httpBackend.expectGET(`Items/${item.id}/getCard`).respond(item); + controller.id = item.id; + $httpBackend.flush(); + + expect(controller.item).toEqual(item); + }); + }); +}); diff --git a/modules/item/front/descriptor/style.scss b/modules/item/front/descriptor/style.scss index 336bfdf53..8b684a77b 100644 --- a/modules/item/front/descriptor/style.scss +++ b/modules/item/front/descriptor/style.scss @@ -1,16 +1,9 @@ vn-item-descriptor { - display: block; - img[ng-src] { min-height: 16em; height: 100%; width: 100%; display: block; } - vn-dialog[vn-id=regularize]{ - .vn-textfield{ - width: 100% - } - } } diff --git a/modules/item/front/diary/index.html b/modules/item/front/diary/index.html index 40d398e7a..eca9410fe 100644 --- a/modules/item/front/diary/index.html +++ b/modules/item/front/diary/index.html @@ -50,7 +50,7 @@ {{::sale.origin | dashIfEmpty}} @@ -58,9 +58,13 @@ {{::sale.stateName | dashIfEmpty}} {{::sale.reference | dashIfEmpty}} - + + {{::sale.name | dashIfEmpty}} + + {{::sale.name | dashIfEmpty}} @@ -84,5 +88,3 @@ - - \ No newline at end of file diff --git a/modules/item/front/diary/index.js b/modules/item/front/diary/index.js index 55b63a60e..f9065ca5e 100644 --- a/modules/item/front/diary/index.js +++ b/modules/item/front/diary/index.js @@ -57,30 +57,6 @@ class Controller extends Section { this.$location.hash(hash); this.$anchorScroll(); } - - showDescriptor(event, sale) { - if (!sale.isTicket) return; - - this.$.descriptor.ticketFk = sale.origin; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - - event.preventDefault(); - } - - showClientDescriptor(event, sale) { - if (!sale.isTicket) return; - - this.$.clientDescriptor.clientFk = sale.clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - - event.preventDefault(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } Controller.$inject = ['$element', '$scope', '$anchorScroll', '$location']; diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html index 154c64bb1..0ee6a8815 100644 --- a/modules/item/front/index/index.html +++ b/modules/item/front/index/index.html @@ -35,15 +35,15 @@ ui-sref="item.card.summary({id: item.id})"> - + {{::item.id | zeroFill:6}} @@ -73,7 +73,7 @@ + vn-click-stop="workerDescriptor.show($event, item.buyerFk)"> {{::item.userNickname}} @@ -87,12 +87,12 @@ @@ -106,18 +106,20 @@
- - - + + + + - - - - \ No newline at end of file + + + + \ No newline at end of file diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index ad978e0aa..e852d7985 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -5,68 +5,25 @@ import './style.scss'; class Controller extends Section { constructor($element, $) { super($element, $); - this.itemSelected = null; - this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; this.showFields = { id: false, actions: false }; } - stopEvent(event) { - event.preventDefault(); - event.stopImmediatePropagation(); - } - - showItemDescriptor(event, itemFk) { - if (event.defaultPrevented) return; - - event.preventDefault(); - event.stopPropagation(); - - this.$.itemDescriptor.itemFk = itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } - - showWorkerDescriptor(event, workerFk) { - if (event.defaltPrevented) return; - - event.preventDefault(); - event.stopPropagation(); - - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - cloneItem(event, item) { - this.stopEvent(event); - this.itemSelected = item; - this.$.clone.show(); - } - - onCloneAccept(response) { - if (!(response == 'accept' && this.itemSelected)) - return; - - this.$http.post(`Items/${this.itemSelected.id}/clone`).then(res => { - if (res && res.data && res.data.id) + onCloneAccept(itemFk) { + return this.$http.post(`Items/${itemFk}/clone`) + .then(res => { this.$state.go('item.card.tags', {id: res.data.id}); - }); - - this.itemSelected = null; + }); } - preview(event, item) { - this.stopEvent(event); + preview(item) { this.itemSelected = item; this.$.preview.show(); } } -Controller.$inject = ['$element', '$scope']; - ngModule.component('vnItemIndex', { template: require('./index.html'), controller: Controller diff --git a/modules/item/front/index/index.spec.js b/modules/item/front/index/index.spec.js index de07cd04d..f8cf07fe3 100644 --- a/modules/item/front/index/index.spec.js +++ b/modules/item/front/index/index.spec.js @@ -16,43 +16,14 @@ describe('Item', () => { })); describe('onCloneAccept()', () => { - it('should do nothing if response is not accept', () => { - jest.spyOn(controller.$state, 'go'); - - let response = 'ERROR!'; - controller.itemSelected = 'check me'; - - controller.onCloneAccept(response); - - expect(controller.$state.go).not.toHaveBeenCalledWith(); - expect(controller.itemSelected).toEqual('check me'); - }); - - it('should do nothing if response is accept but itemSelected is not defined in the controller', () => { - jest.spyOn(controller.$state, 'go'); - - let response = 'accept'; - controller.itemSelected = undefined; - - controller.onCloneAccept(response); - - expect(controller.$state.go).not.toHaveBeenCalledWith(); - expect(controller.itemSelected).toBeUndefined(); - }); - it('should perform a post query and then call go() then update itemSelected in the controller', () => { jest.spyOn(controller.$state, 'go'); - let response = 'accept'; - controller.itemSelected = {id: 1}; - - $httpBackend.when('POST', `Items/1/clone`).respond({id: 99}); - $httpBackend.expect('POST', `Items/1/clone`); - controller.onCloneAccept(response); + $httpBackend.expectRoute('POST', `Items/:id/clone`).respond({id: 99}); + controller.onCloneAccept(1); $httpBackend.flush(); expect(controller.$state.go).toHaveBeenCalledWith('item.card.tags', {id: 99}); - expect(controller.itemSelected).toBeNull(); }); }); }); diff --git a/modules/item/front/locale/es.yml b/modules/item/front/locale/es.yml index 9580fd156..8046fbafe 100644 --- a/modules/item/front/locale/es.yml +++ b/modules/item/front/locale/es.yml @@ -1,4 +1,5 @@ Item: Artículo +item: artículo View item: Ver artículo Category: Reino Description: Descripción diff --git a/modules/item/front/request/index.html b/modules/item/front/request/index.html index 0516e7ff5..85d44818d 100644 --- a/modules/item/front/request/index.html +++ b/modules/item/front/request/index.html @@ -3,18 +3,18 @@ url="TicketRequests/filter" limit="20" data="requests" - order="shipped DESC, isOk ASC"> + order="shipped DESC, isOk ASC" + auto-load="true"> - + info="Search request by id or alias" + model="model" + auto-state="false"> - - @@ -36,7 +36,7 @@ + ng-click="ticketDescriptor.show($event, request.ticketFk)"> {{request.ticketFk}} @@ -52,7 +52,7 @@ + ng-click="workerDescriptor.show($event, request.attenderFk)"> {{::request.atenderNickname}} @@ -76,7 +76,7 @@ {{request.itemDescription}} @@ -86,7 +86,8 @@ + icon="insert_drive_file" + class="bright"> + on-close="$ctrl.denyObservation = null" + message="Specify the reasons to deny this request"> -
Specify the reasons to deny this request
- - - - + +
diff --git a/modules/item/front/request/index.js b/modules/item/front/request/index.js index 51035c468..8383343de 100644 --- a/modules/item/front/request/index.js +++ b/modules/item/front/request/index.js @@ -25,11 +25,6 @@ export default class Controller extends Section { } } - $postLink() { - if (this.filter) - this.onSearch(this.filter); - } - getState(isOk) { if (isOk === null) return 'Nueva'; @@ -62,11 +57,11 @@ export default class Controller extends Section { quantity: request.saleQuantity }; - let endpoint = `Sales/${request.saleFk}/`; + let endpoint = `Sales/${request.saleFk}`; - this.$http.patch(endpoint, params).then(() => { - this.vnApp.showSuccess(this.$t('Data saved!')); - }).then(() => this.confirmRequest(request)); + this.$http.patch(endpoint, params) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))) + .then(() => this.confirmRequest(request)); } else this.confirmRequest(request); } @@ -85,69 +80,20 @@ export default class Controller extends Section { return 'success'; } - onSearch(params) { - if (params) - this.$.model.applyFilter(null, params); - else - this.$.model.clear(); - } - - showDenyReason(event, requestId) { - this.selectedRequest = requestId; - this.$.denyReason.parent = event.target; - this.$.denyReason.show(); - } - - clear() { - delete this.denyRequestId; - } - onDenyAccept(request) { let params = { observation: this.denyObservation }; - let query = `TicketRequests/${request.id}/deny`; - return this.$http.post(query, params).then(res => { - const newRequest = res.data; - request.isOk = newRequest.isOk; - request.attenderFk = newRequest.attenderFk; - request.response = newRequest.response; + return this.$http.post(`TicketRequests/${request.id}/deny`, params) + .then(res => { + const newRequest = res.data; + request.isOk = newRequest.isOk; + request.attenderFk = newRequest.attenderFk; + request.response = newRequest.response; - this.vnApp.showSuccess(this.$t('Data saved!')); - }); - } - - onDenyClose() { - this.denyObservation = null; - } - - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - showItemDescriptor(event, itemFk) { - this.$.itemDescriptor.itemFk = itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } - - showWorkerDescriptor(event, workerFk) { - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } - - preventNavigation(event) { - event.preventDefault(); + this.vnApp.showSuccess(this.$t('Data saved!')); + }); } } diff --git a/modules/item/front/request/index.spec.js b/modules/item/front/request/index.spec.js index 042b20996..8e384b04e 100644 --- a/modules/item/front/request/index.spec.js +++ b/modules/item/front/request/index.spec.js @@ -1,5 +1,4 @@ import './index.js'; -import crudModel from 'core/mocks/crud-model'; describe('Item', () => { describe('Component vnItemRequest', () => { @@ -12,10 +11,7 @@ describe('Item', () => { beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $scope.model = crudModel; - $scope.denyReason = {hide: () => {}}; - const $element = angular.element(''); - controller = $componentController('vnItemRequest', {$element, $scope}); + controller = $componentController('vnItemRequest', {$element: null, $scope}); })); afterAll(() => { @@ -49,23 +45,20 @@ describe('Item', () => { controller.confirmRequest(request); - expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).not.toHaveBeenCalled(); }); it('should perform a query and call vnApp.showSuccess() and refresh if the conditions are met', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - let model = controller.$.model; - jest.spyOn(model, 'refresh'); const expectedResult = {concept: 'Melee Weapon'}; let request = {itemFk: 1, saleQuantity: 1, id: 1}; - $httpBackend.when('POST', `TicketRequests/${request.id}/confirm`).respond(expectedResult); - $httpBackend.expect('POST', `TicketRequests/${request.id}/confirm`).respond(expectedResult); + $httpBackend.expectPOST(`TicketRequests/${request.id}/confirm`).respond(expectedResult); controller.confirmRequest(request); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); @@ -83,19 +76,17 @@ describe('Item', () => { let request = {saleFk: 1, saleQuantity: 1}; jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('PATCH', `Sales/${request.saleFk}/`).respond(); - $httpBackend.expect('PATCH', `Sales/${request.saleFk}/`).respond(); + $httpBackend.expectPATCH(`Sales/${request.saleFk}`).respond(); controller.changeQuantity(request); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('compareDate()', () => { it(`should return "success" if receives a future date`, () => { let date = '3019-02-18T11:00:00.000Z'; - let result = controller.compareDate(date); expect(result).toEqual('success'); @@ -103,7 +94,6 @@ describe('Item', () => { it(`should return "warning" if date is today`, () => { let date = new Date(); - let result = controller.compareDate(date); expect(result).toEqual('warning'); @@ -117,9 +107,8 @@ describe('Item', () => { response: 'new' }; - const url = `TicketRequests/:id/deny`; - $httpBackend.expectRoute('POST', url).respond({response: 'denied'}); - + $httpBackend.expectPOST(`TicketRequests/${request.id}/deny`) + .respond({response: 'denied'}); controller.onDenyAccept(request); $httpBackend.flush(); diff --git a/modules/item/front/request/style.scss b/modules/item/front/request/style.scss index 0af32c309..59612bbd6 100644 --- a/modules/item/front/request/style.scss +++ b/modules/item/front/request/style.scss @@ -12,7 +12,4 @@ vn-item-request { width: 100% } } - vn-icon[icon=insert_drive_file]{ - color: $color-font-secondary; - } } \ No newline at end of file diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html index bee9df310..938005828 100644 --- a/modules/item/front/summary/index.html +++ b/modules/item/front/summary/index.html @@ -3,8 +3,8 @@ + ng-src="{{::$root.imagePath}}/catalog/200x200/{{$ctrl.item.image}}" + zoom-image="{{::$root.imagePath}}/catalog/1600x900/{{$ctrl.item.image}}" on-error-src/>

Visible

diff --git a/modules/order/front/catalog-view/index.html b/modules/order/front/catalog-view/index.html index 7a588a464..739fdfe8e 100644 --- a/modules/order/front/catalog-view/index.html +++ b/modules/order/front/catalog-view/index.html @@ -1,57 +1,57 @@ -
- -
- -
-
-

- {{::item.name}} -

-

- {{::item.subName}} -

-
- - - - - - +
+ +
+
-
diff --git a/modules/order/front/catalog-view/index.js b/modules/order/front/catalog-view/index.js index 838da05ea..37a2b70a2 100644 --- a/modules/order/front/catalog-view/index.js +++ b/modules/order/front/catalog-view/index.js @@ -2,16 +2,7 @@ import ngModule from '../module'; import Component from 'core/lib/component'; import './style.scss'; -class Controller extends Component { - preview(event, item) { - event.preventDefault(); - this.$.pricesPopover.show(event, item); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } -} +class Controller extends Component {} ngModule.component('vnOrderCatalogView', { template: require('./index.html'), diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index f9c2c40bd..ab51e66fc 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -1,4 +1,3 @@ - - - diff --git a/modules/order/front/descriptor/index.html b/modules/order/front/descriptor/index.html index 0a9e2ee38..b16470bf2 100644 --- a/modules/order/front/descriptor/index.html +++ b/modules/order/front/descriptor/index.html @@ -1,59 +1,67 @@ -
-
- - - - - - - - -
-
+ + + + Delete order + + +
- + - - - - - - - - - -
- - -
-
+ + + \ No newline at end of file diff --git a/modules/order/front/descriptor/index.js b/modules/order/front/descriptor/index.js index b9d1e7973..5d22dd721 100644 --- a/modules/order/front/descriptor/index.js +++ b/modules/order/front/descriptor/index.js @@ -1,65 +1,32 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.moreOptions = [ - {name: 'Delete order', callback: () => this.showDeleteOrderDialog()} - ]; +class Controller extends Descriptor { + get order() { + return this.entity; } set order(value) { - this._order = value; - if (!value) return; - - if (value.isConfirmed) { - this._quicklinks = { - btnOne: { - icon: 'icon-ticket', - state: `ticket.index({q: '{"orderFk": ${value.id}}'})`, - tooltip: 'Order ticket list' - }, - btnTwo: { - icon: 'person', - state: `client.card.summary({id: ${value.clientFk}})`, - tooltip: 'Client card' - } - }; - } + this.entity = value; } - get order() { - return this._order; + get ticketFilter() { + return JSON.stringify({orderFk: this.id}); } - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } - - deleteOrder(response) { - if (response === 'accept') { - const params = {id: this.order.id}; - this.$http.delete(`Orders/${params.id}`).then(() => { + deleteOrder() { + return this.$http.delete(`Orders/${this.id}`) + .then(() => { this.$state.go('order.index'); - this.vnApp.showSuccess(this.$translate.instant('Order deleted')); + this.vnApp.showSuccess(this.$t('Order deleted')); }); - } - } - - showDeleteOrderDialog() { - this.$.deleteOrderConfirmation.show(); } } -ngModule.component('vnOrderDescriptor', { +ngModule.vnComponent('vnOrderDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { order: '<' - }, - controller: Controller + } }); diff --git a/modules/order/front/descriptor/index.spec.js b/modules/order/front/descriptor/index.spec.js index 5bb2ac087..e6147faee 100644 --- a/modules/order/front/descriptor/index.spec.js +++ b/modules/order/front/descriptor/index.spec.js @@ -2,42 +2,26 @@ import './index.js'; describe('Order Component vnOrderDescriptor', () => { let $httpBackend; - let $scope; let controller; + const order = {id: 1}; beforeEach(ngModule('order')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => { + beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - $scope = $rootScope.$new(); - const $element = angular.element(''); - controller = $componentController('vnOrderDescriptor', {$element, $scope}); - controller.order = {id: 1}; + controller = $componentController('vnOrderDescriptor', {$element: null}, {order}); })); describe('deleteOrder()', () => { - it(`should do nothing if the response isn't accept`, () => { - let response = 'WAGH!'; - + it(`should perform a DELETE query`, () => { jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$state, 'go'); - controller.deleteOrder(response); - expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Order deleted!'); - expect(controller.$state.go).not.toHaveBeenCalledWith('order.index'); - }); - - it(`should perform a DELETE query if the response was accept`, () => { - let response = 'accept'; - - jest.spyOn(controller.vnApp, 'showSuccess'); - jest.spyOn(controller.$state, 'go'); - $httpBackend.when('DELETE', `Orders/${controller.order.id}`).respond(200); - $httpBackend.expect('DELETE', `Orders/${controller.order.id}`); - controller.deleteOrder(response); + $httpBackend.expectDELETE(`Orders/${order.id}`).respond(); + controller.deleteOrder(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Order deleted'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); expect(controller.$state.go).toHaveBeenCalledWith('order.index'); }); }); diff --git a/modules/order/front/index/index.html b/modules/order/front/index/index.html index b16a1b25d..148531f2d 100644 --- a/modules/order/front/index/index.html +++ b/modules/order/front/index/index.html @@ -27,14 +27,16 @@ ui-sref="order.card.summary({id: {{::order.id}}})"> {{::order.id}} - + {{::order.clientName}} - + {{::order.workerNickname | dashIfEmpty}} @@ -51,9 +53,9 @@ {{::order.total | currency: 'EUR': 2 | dashIfEmpty}} + vn-click-stop="$ctrl.preview(order)" + icon="desktop_windows" + vn-tooltip="Preview"> @@ -72,10 +74,10 @@ vn-id="clientDescriptor"> + vn-id="workerDescriptor"> - + + - \ No newline at end of file diff --git a/modules/order/front/index/index.js b/modules/order/front/index/index.js index 99f00733e..40781bcdd 100644 --- a/modules/order/front/index/index.js +++ b/modules/order/front/index/index.js @@ -2,29 +2,7 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - event.stopImmediatePropagation(); - } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } - - preview(event, order) { - event.preventDefault(); - event.stopImmediatePropagation(); + preview(order) { this.selectedOrder = order; this.$.summary.show(); } diff --git a/modules/order/front/line/index.html b/modules/order/front/line/index.html index 72d019fe9..80aca98ec 100644 --- a/modules/order/front/line/index.html +++ b/modules/order/front/line/index.html @@ -32,12 +32,12 @@ - {{::row.itemFk | zeroFill:6}} diff --git a/modules/order/front/line/index.js b/modules/order/front/line/index.js index 9351c5df8..bd41acedc 100644 --- a/modules/order/front/line/index.js +++ b/modules/order/front/line/index.js @@ -48,13 +48,6 @@ class Controller extends Section { .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); } - showDescriptor(event, itemFk) { - let descriptor = this.$.descriptor; - descriptor.itemFk = itemFk; - descriptor.parent = event.target; - descriptor.show(); - } - save() { this.$http.post(`Orders/${this.$params.id}/confirm`).then(() => { this.vnApp.showSuccess(this.$t('Order confirmed')); diff --git a/modules/order/front/line/index.spec.js b/modules/order/front/line/index.spec.js index 543ffeedc..458bbbdd8 100644 --- a/modules/order/front/line/index.spec.js +++ b/modules/order/front/line/index.spec.js @@ -6,7 +6,8 @@ describe('Order', () => { let controller; let $httpBackend; - let rows = [ + const vat = 10.5; + const rows = [ { quantity: 4, price: 10.5 @@ -23,11 +24,10 @@ describe('Order', () => { $httpBackend = _$httpBackend_; $state.params.id = 1; - $httpBackend.whenRoute('GET', `OrderRows`).respond(rows); - $httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, 10.5); + $httpBackend.whenGET(`OrderRows`).respond(rows); + $httpBackend.whenRoute('GET', `Orders/:id/getVAT`).respond(200, vat); - let $element = angular.element('
'); - controller = $componentController('vnOrderLine', {$element}); + controller = $componentController('vnOrderLine', {$element: null}); })); describe('getRows()', () => { @@ -35,7 +35,7 @@ describe('Order', () => { controller.getRows(); $httpBackend.flush(); - expect(controller.rows).toBeDefined(); + expect(controller.rows).toEqual(rows); }); }); @@ -44,7 +44,7 @@ describe('Order', () => { controller.getVAT(); $httpBackend.flush(); - expect(controller.VAT).toBeDefined(); + expect(controller.VAT).toBe(vat); }); }); @@ -59,7 +59,7 @@ describe('Order', () => { $httpBackend.flush(); expect(controller.rows.length).toBe(1); - expect(controller.card.reload).toHaveBeenCalledWith(); + expect(controller.card.reload).toHaveBeenCalled(); }); }); }); diff --git a/modules/order/front/locale/es.yml b/modules/order/front/locale/es.yml index 565d4f251..58b62a3a5 100644 --- a/modules/order/front/locale/es.yml +++ b/modules/order/front/locale/es.yml @@ -20,4 +20,5 @@ Color and price: Color y precio Ascendant: Ascendente Descendant: Descendente Created from: Creado desde -Search orders by id: Buscar en la cesta por identificador \ No newline at end of file +Search order by id: Buscar el pedido por identificador +order: pedido \ No newline at end of file diff --git a/modules/order/front/prices-popover/index.html b/modules/order/front/prices-popover/index.html index 2a6f978fb..61d8bb1a7 100644 --- a/modules/order/front/prices-popover/index.html +++ b/modules/order/front/prices-popover/index.html @@ -1,19 +1,11 @@ - -
-
- - - - - -
-
+ + +
-
{{$ctrl.item.name}}
- - @@ -24,56 +16,60 @@ value="{{::tag.value}}">
- - -
- - - - - - - {{::price.warehouse}} - - - -
- - {{::price.grouping}} - - x {{::price.price | currency: 'EUR': 2}} -
-
- {{price.priceKg | currency: 'EUR'}}/Kg -
-
- - - - -
-
-
- - + + +
+ + + + + + {{::price.warehouse}} + + + +
+ {{::price.grouping}} + x {{::price.price | currency: 'EUR': 2}} +
+
+ {{price.priceKg | currency: 'EUR'}}/Kg +
+
+ + + + +
+
+
+ +
+
+ + diff --git a/modules/order/front/prices-popover/index.js b/modules/order/front/prices-popover/index.js index 307cbc8d6..c9620136d 100644 --- a/modules/order/front/prices-popover/index.js +++ b/modules/order/front/prices-popover/index.js @@ -1,10 +1,10 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Popover from 'core/components/popover'; import './style.scss'; -class Controller extends Component { - constructor($element, $) { - super($element, $); +class Controller extends Popover { + constructor(...args) { + super(...args); this.totalBasquet = 0; } @@ -19,41 +19,36 @@ class Controller extends Component { } getTags() { - let filter = { - where: {itemFk: this.item.id, - priority: {gte: 4}}, + const filter = { + where: { + itemFk: this.id, + priority: {gte: 4} + }, order: 'priority ASC', include: {relation: 'tag'} }; - this.quicklinks = { - btnOne: { - icon: 'icon-transaction', - state: `item.card.diary({id: ${this.item.id}})`, - tooltip: 'Diary' - } - }; - this.$http.get(`ItemTags?filter=${JSON.stringify(filter)}`).then(response => { - this.tags = response.data; - this.$.$applyAsync(() => { - this.$.popover.relocate(); + this.$http.get(`ItemTags`, {filter}) + .then(res => { + this.tags = res.data; + this.$.$applyAsync(() => this.relocate()); }); - }); } - show(event, item) { + show(parent, item) { this.item = JSON.parse(JSON.stringify(item)); + this.id = item.id; this.prices = this.item.prices; this.getTags(); - this.$.popover.parent = event.target; - this.$.popover.show(); - this.$.popover.relocate(); + super.show(parent); } - clear() { + onClose() { + this.id = null; this.item = {}; this.tags = {}; this._prices = {}; this.total = 0; + super.onClose(); } calculateMax() { @@ -76,7 +71,7 @@ class Controller extends Component { } getFilledLines() { - let filledLines = []; + const filledLines = []; let match; this.prices.forEach(price => { if (price.quantity && price.quantity > 0) { @@ -96,30 +91,28 @@ class Controller extends Component { submit() { this.calculateTotal(); - let filledLines = this.getFilledLines(); + const filledLines = this.getFilledLines(); if (filledLines.length <= 0) { - this.vnApp.showError(this.$translate.instant('First you must add some quantity')); + this.vnApp.showError(this.$t('First you must add some quantity')); return; } - let params = { + const params = { orderFk: this.order.id, items: filledLines }; - - this.$http.post(`OrderRows/addToOrder`, params).then(res => { - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.$.popover.hide(); - - if (this.card) - this.card.reload(); - }); + this.$http.post(`OrderRows/addToOrder`, params) + .then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.hide(); + if (this.card) this.card.reload(); + }); } } -ngModule.component('vnOrderPricesPopover', { - template: require('./index.html'), +ngModule.vnComponent('vnOrderPricesPopover', { + slotTemplate: require('./index.html'), controller: Controller, bindings: { order: '<' diff --git a/modules/order/front/prices-popover/style.scss b/modules/order/front/prices-popover/style.scss index edd2d1513..dbca75586 100644 --- a/modules/order/front/prices-popover/style.scss +++ b/modules/order/front/prices-popover/style.scss @@ -1,8 +1,11 @@ @import "variables"; -.vn-order-prices-popover { - display: block; +.vn-order-prices-popover .content { + max-width: 350px; + .header > a:first-child { + visibility: hidden; + } img[ng-src] { height: 100%; width: 100%; diff --git a/modules/order/front/summary/index.html b/modules/order/front/summary/index.html index c7ee5b4b6..cafd49f8a 100644 --- a/modules/order/front/summary/index.html +++ b/modules/order/front/summary/index.html @@ -63,7 +63,7 @@ {{::row.itemFk | zeroFill:6}} diff --git a/modules/order/front/summary/index.js b/modules/order/front/summary/index.js index ca6c29522..bff80638d 100644 --- a/modules/order/front/summary/index.js +++ b/modules/order/front/summary/index.js @@ -4,10 +4,8 @@ import './style.scss'; class Controller extends Section { setSummary() { - this.$http.get(`Orders/${this.order.id}/summary`).then(res => { - if (res && res.data) - this.summary = res.data; - }); + this.$http.get(`Orders/${this.order.id}/summary`) + .then(res => this.summary = res.data); } get formattedAddress() { @@ -23,16 +21,6 @@ class Controller extends Section { if (this.order && this.order.id) this.setSummary(); } - - showDescriptor(event, itemFk) { - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnOrderSummary', { diff --git a/modules/order/front/summary/index.spec.js b/modules/order/front/summary/index.spec.js index 2fa7c1c93..f0e831aab 100644 --- a/modules/order/front/summary/index.spec.js +++ b/modules/order/front/summary/index.spec.js @@ -16,14 +16,15 @@ describe('Order', () => { describe('getSummary()', () => { it('should now perform a GET query and define the summary property', () => { - let res = {id: 1, nickname: 'Batman'}; - $httpBackend.when('GET', `Orders/1/summary`).respond(200, res); - $httpBackend.expect('GET', `Orders/1/summary`); + let res = { + id: 1, + nickname: 'Batman' + }; + $httpBackend.expectGET(`Orders/1/summary`).respond(res); controller.setSummary(); $httpBackend.flush(); - expect(controller.summary).toBeDefined(); - expect(controller.summary.nickname).toEqual('Batman'); + expect(controller.summary).toEqual(res); }); }); diff --git a/modules/order/front/volume/index.html b/modules/order/front/volume/index.html index 36451f517..f15e4897b 100644 --- a/modules/order/front/volume/index.html +++ b/modules/order/front/volume/index.html @@ -34,7 +34,7 @@ {{::row.itemFk}} diff --git a/modules/order/front/volume/index.js b/modules/order/front/volume/index.js index f28763612..5941611ee 100644 --- a/modules/order/front/volume/index.js +++ b/modules/order/front/volume/index.js @@ -16,27 +16,15 @@ class Controller extends Section { onDataChange() { this.$http.get(`Orders/${this.$params.id}/getVolumes`) - .then(response => { - if (response.data) { - this.$.model.data.forEach(order => { - response.data.volumes.forEach(volume => { - if (order.itemFk === volume.itemFk) - order.volume = volume.volume; - }); + .then(res => { + this.$.model.data.forEach(order => { + res.data.volumes.forEach(volume => { + if (order.itemFk === volume.itemFk) + order.volume = volume.volume; }); - } + }); }); } - - showDescriptor(event, itemFk) { - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnOrderVolume', { diff --git a/modules/order/front/volume/index.spec.js b/modules/order/front/volume/index.spec.js index 194592406..241277d78 100644 --- a/modules/order/front/volume/index.spec.js +++ b/modules/order/front/volume/index.spec.js @@ -4,58 +4,39 @@ describe('Order', () => { describe('Component vnOrderVolume', () => { let controller; let $httpBackend; - let $state; let $scope; beforeEach(ngModule('order')); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, $rootScope) => { + beforeEach(angular.mock.inject(($componentController, $state, _$httpBackend_, $rootScope) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $scope.model = {data: [{itemFk: 1}, {itemFk: 2}], accept: () => { - return { - then: () => {} - }; - }}; - $scope.descriptor = {show: () => {}}; - $scope.popover = {relocate: () => {}}; - $state = _$state_; + $scope.model = { + data: [ + {itemFk: 1}, + {itemFk: 2} + ] + }; + $state.params.id = 1; const $element = angular.element(''); controller = $componentController('vnOrderVolume', {$element, $scope}); })); it('should join the sale volumes to its respective sale', () => { - let response = {volumes: [{itemFk: 1, volume: 0.008}, {itemFk: 2, volume: 0.003}]}; - $httpBackend.whenGET(`Orders/1/getVolumes`).respond(response); - $httpBackend.expectGET(`Orders/1/getVolumes`); + let response = { + volumes: [ + {itemFk: 1, volume: 0.008}, + {itemFk: 2, volume: 0.003} + ] + }; + + $httpBackend.expectGET(`Orders/1/getVolumes`).respond(response); controller.onDataChange(); $httpBackend.flush(); expect(controller.$.model.data[0].volume).toBe(0.008); expect(controller.$.model.data[1].volume).toBe(0.003); }); - - describe('showDescriptor()', () => { - it('should set $scope.descriptor.itemFk, $scope.descriptor.parent and call $scope.descriptor.show()', () => { - let event = {target: 1}; - let itemFk = 1; - jest.spyOn(controller.$.descriptor, 'show'); - controller.showDescriptor(event, itemFk); - - expect(controller.$.descriptor.itemFk).toBe(1); - expect(controller.$.descriptor.parent).toBe(1); - expect(controller.$.descriptor.show).toHaveBeenCalledWith(); - }); - }); - - describe('onDescriptorLoad()', () => { - it('should call $scope.popover.relocate()', () => { - jest.spyOn(controller.$.popover, 'relocate'); - controller.onDescriptorLoad(); - - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); }); }); diff --git a/modules/route/front/descriptor-popover/index.html b/modules/route/front/descriptor-popover/index.html index a0295c138..a7006ba41 100644 --- a/modules/route/front/descriptor-popover/index.html +++ b/modules/route/front/descriptor-popover/index.html @@ -1,12 +1,11 @@ - - - - + + + + + + - \ No newline at end of file + \ No newline at end of file diff --git a/modules/route/front/descriptor-popover/index.js b/modules/route/front/descriptor-popover/index.js index a0363839f..19696ad39 100644 --- a/modules/route/front/descriptor-popover/index.js +++ b/modules/route/front/descriptor-popover/index.js @@ -1,126 +1,9 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.route = null; - this._quicklinks = {}; - } +class Controller extends DescriptorPopover {} - set routeFk(id) { - if (id == this._routeFk) return; - - this._routeFk = id; - this.route = null; - this.getCard(); - } - - get routeFk() { - return this._routeFk; - } - - set route(value) { - this._route = value; - this.$timeout(() => this.$.popover.relocate()); - } - - get route() { - return this._route; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - getCard() { - if (this.canceler) - this.canceler.resolve(); - - this.canceler = this.$q.defer(); - - let query = 'Routes/findOne'; - - let filter = { - fields: [ - 'id', - 'workerFk', - 'agencyModeFk', - 'created', - 'm3', - 'warehouseFk', - 'description', - 'vehicleFk', - 'kmStart', - 'kmEnd', - 'started', - 'finished', - 'cost', - 'zoneFk' - ], - include: [ - { - relation: 'agencyMode', - scope: { - fields: ['id', 'name'] - } - }, { - relation: 'vehicle', - scope: { - fields: ['id', 'm3'] - } - }, { - relation: 'zone', - scope: { - fields: ['id', 'name'] - } - }, - { - relation: 'worker', - scope: { - fields: ['userFk'], - include: { - relation: 'user', - scope: { - fields: ['id'], - include: { - relation: 'emailUser', - scope: { - fields: ['email'] - } - } - } - } - } - } - ] - }; - this.$http.get(query, {params: {filter}}).then(res => { - this.route = res.data; - this.$.$applyAsync(() => { - this.$.popover.relocate(); - }); - }); - } -} - -ngModule.component('vnRouteDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - routeFk: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnRouteDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/route/front/descriptor-popover/index.spec.js b/modules/route/front/descriptor-popover/index.spec.js deleted file mode 100644 index e3277a9c1..000000000 --- a/modules/route/front/descriptor-popover/index.spec.js +++ /dev/null @@ -1,77 +0,0 @@ -import './index'; - -describe('vnRouteDescriptorPopover', () => { - let $httpBackend; - let $scope; - let controller; - let $element; - let $timeout; - - beforeEach(ngModule('route')); - - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { - $httpBackend = _$httpBackend_; - $timeout = _$timeout_; - $element = angular.element(`
`); - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnRouteDescriptorPopover', {$scope, $element}); - })); - - describe('routeFk()', () => { - it(`should do nothing if the received id isn't a new one`, () => { - controller.route = 'I exist!'; - controller._routeFk = 1; - jest.spyOn(controller, 'getCard'); - controller.routeFk = 1; - - expect(controller.route).toEqual('I exist!'); - expect(controller._routeFk).toEqual(1); - expect(controller.getCard).not.toHaveBeenCalled(); - }); - - it(`should set the received id, set the route null and then call getCard()`, () => { - controller.route = `Please don't`; - controller._routeFk = 1; - jest.spyOn(controller, 'getCard'); - controller.routeFk = 999; - - expect(controller.route).toBeNull(); - expect(controller._routeFk).toEqual(999); - expect(controller.getCard).toHaveBeenCalledWith(); - }); - }); - - describe('route()', () => { - it(`should save the client on the controller and then call relocate()`, () => { - jest.spyOn(controller.$.popover, 'relocate'); - let route = `i'm the route!`; - controller.route = route; - $timeout.flush(); - - expect(controller.route).toEqual(route); - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the popover show() method`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('getCard()', () => { - it(`should perform a get query to store the client data into the controller`, () => { - let response = {the: 'route'}; - - $httpBackend.whenRoute('GET', 'Routes/findOne').respond(response); - controller.routeFk = 1; - $httpBackend.flush(); - - expect(controller.route).toEqual(response); - }); - }); -}); diff --git a/modules/route/front/descriptor-popover/style.scss b/modules/route/front/descriptor-popover/style.scss deleted file mode 100644 index 163a032e3..000000000 --- a/modules/route/front/descriptor-popover/style.scss +++ /dev/null @@ -1,9 +0,0 @@ -vn-route-descriptor-popover { - vn-route-descriptor { - display: block; - width: 256px; - & > vn-card{ - margin: 0!important; - } - } -} diff --git a/modules/route/front/descriptor/index.html b/modules/route/front/descriptor/index.html index f04632244..442ee7838 100644 --- a/modules/route/front/descriptor/index.html +++ b/modules/route/front/descriptor/index.html @@ -1,41 +1,45 @@ -
-
- - - - - - - - -
-
+ + + + Show route report + + + Send route report + + + Update volume + + +
-
{{$ctrl.route.name}}
- - - - - - -
@@ -46,13 +50,15 @@ ng-class="{bright: $ctrl.route.m3 > $ctrl.route.vehicle.m3 && $ctrl.route.vehicle.m3 != NULL}">
- - +
\ No newline at end of file diff --git a/modules/route/front/descriptor/index.js b/modules/route/front/descriptor/index.js index 558d236b7..0fbc3a5e6 100644 --- a/modules/route/front/descriptor/index.js +++ b/modules/route/front/descriptor/index.js @@ -1,84 +1,105 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); - - this.$httpParamSerializer = $httpParamSerializer; - this.moreOptions = [ - {callback: this.showRouteReport, name: 'Show route report'}, - {callback: this.sendRouteReport, name: 'Send route report'}, - {callback: this.showUpdateVolumeDialog, name: 'Update volume', acl: 'deliveryBoss'} - ]; +class Controller extends Descriptor { + get route() { + return this.entity; } - onMoreOpen() { - let options = this.moreOptions.filter(option => { - const hasAclProperty = Object.hasOwnProperty.call(option, 'acl'); - - return !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); - }); - this.$.moreButton.data = options; - } - - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; - } - - onMoreChange(callback) { - callback.call(this); + set route(value) { + this.entity = value; } showRouteReport() { - const params = { - authorization: this.vnToken.token, + this.showReport('driver-route', { clientId: this.vnConfig.storage.currentUserWorkerId, - routeId: this.route.id - }; - const serializedParams = this.$httpParamSerializer(params); - let url = `api/report/driver-route?${serializedParams}`; - window.open(url); + routeId: this.id + }); } sendRouteReport() { const params = { recipient: user.emailUser.email, clientId: this.vnConfig.storage.currentUserWorkerId, - routeId: this.route.id + routeId: this.id }; - this.$http.get(`email/driver-route`, {params}).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Report sent')); - }); + return this.$http.get(`email/driver-route`, {params}) + .then(() => this.vnApp.showSuccess(this.$t('Report sent'))); } - showUpdateVolumeDialog() { - this.$.updateVolumeConfirmation.show(); - } - - updateVolume(response) { - if (response === 'accept') { - let url = `Routes/${this.route.id}/updateVolume`; - this.$http.post(url).then(() => { - this.vnApp.showSuccess(this.$translate.instant('Volume updated')); - this.cardReload(); + updateVolume() { + this.$http.post(`Routes/${this.id}/updateVolume`) + .then(() => { + if (this.cardReload) this.cardReload(); + this.vnApp.showSuccess(this.$t('Volume updated')); }); - } + } + + loadData() { + const filter = { + fields: [ + 'id', + 'workerFk', + 'agencyModeFk', + 'created', + 'm3', + 'warehouseFk', + 'description', + 'vehicleFk', + 'kmStart', + 'kmEnd', + 'started', + 'finished', + 'cost', + 'zoneFk' + ], + include: [ + { + relation: 'agencyMode', + scope: { + fields: ['id', 'name'] + } + }, { + relation: 'vehicle', + scope: { + fields: ['id', 'm3'] + } + }, { + relation: 'zone', + scope: { + fields: ['id', 'name'] + } + }, { + relation: 'worker', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['id'], + include: { + relation: 'emailUser', + scope: { + fields: ['email'] + } + } + } + } + } + } + ] + }; + + return this.getData(`Routes/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - -ngModule.component('vnRouteDescriptor', { +ngModule.vnComponent('vnRouteDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { route: '<', - cardReload: '&?', - quicklinks: '<' - }, - controller: Controller + cardReload: '&?' + } }); diff --git a/modules/route/front/descriptor/index.spec.js b/modules/route/front/descriptor/index.spec.js new file mode 100644 index 000000000..ab996d9b0 --- /dev/null +++ b/modules/route/front/descriptor/index.spec.js @@ -0,0 +1,26 @@ +import './index'; + +describe('vnRouteDescriptorPopover', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('route')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnRouteDescriptor', {$element: null}); + })); + + describe('loadData()', () => { + it(`should perform a get query to store the client data into the controller`, () => { + const id = 1; + const response = 'foo'; + + $httpBackend.expectRoute('GET', `Routes/${id}`).respond(response); + controller.id = id; + $httpBackend.flush(); + + expect(controller.route).toEqual(response); + }); + }); +}); diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html index ab8b1364b..16f6ad827 100644 --- a/modules/route/front/index/index.html +++ b/modules/route/front/index/index.html @@ -26,7 +26,7 @@ + vn-click-stop="workerDescriptor.show($event, route.workerFk)"> {{::route.workerNickname}} @@ -37,7 +37,7 @@ {{::route.description | dashIfEmpty}} @@ -53,13 +53,11 @@ + vn-id="workerDescriptor"> - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js index 0349af293..7014bc609 100644 --- a/modules/route/front/index/index.js +++ b/modules/route/front/index/index.js @@ -2,21 +2,7 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - showWorkerDescriptor(event, workerFk) { - if (event.defaultPrevented) return; - event.preventDefault(); - event.stopPropagation(); - - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - preview(event, route) { - if (event.defaultPrevented) return; - event.preventDefault(); - event.stopPropagation(); - + preview(route) { this.routeSelected = route; this.$.summary.show(); } diff --git a/modules/route/front/locale/es.yml b/modules/route/front/locale/es.yml index 421d40923..268bc4812 100644 --- a/modules/route/front/locale/es.yml +++ b/modules/route/front/locale/es.yml @@ -1,3 +1,4 @@ Routes: Rutas Search routes by id: Buscar rutas por identificador -New route: Nueva ruta \ No newline at end of file +New route: Nueva ruta +route: ruta \ No newline at end of file diff --git a/modules/route/front/main/index.js b/modules/route/front/main/index.js index 618989748..8aa6552e1 100644 --- a/modules/route/front/main/index.js +++ b/modules/route/front/main/index.js @@ -2,11 +2,6 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; export default class Route extends ModuleMain { - constructor($element, $, vnConfig) { - super($element, $); - this.vnConfig = vnConfig; - } - $postLink() { let to = new Date(); to.setDate(to.getDate() + 1); @@ -18,7 +13,6 @@ export default class Route extends ModuleMain { this.filter = {from, to, warehouseFk: this.vnConfig.warehouseFk}; } } -Route.$inject = ['$element', '$scope', 'vnConfig']; ngModule.vnComponent('vnRoute', { controller: Route, diff --git a/modules/route/front/summary/index.html b/modules/route/front/summary/index.html index 527f7fe96..d99f5e012 100644 --- a/modules/route/front/summary/index.html +++ b/modules/route/front/summary/index.html @@ -69,14 +69,14 @@ {{ticket.priority | dashIfEmpty}} {{ticket.id | zeroFill:6}} {{ticket.nickname}} @@ -90,7 +90,8 @@ + icon="insert_drive_file" + class="bright">
@@ -104,4 +105,4 @@ - \ No newline at end of file + diff --git a/modules/route/front/summary/index.js b/modules/route/front/summary/index.js index a922ad008..95e208b84 100644 --- a/modules/route/front/summary/index.js +++ b/modules/route/front/summary/index.js @@ -16,20 +16,6 @@ class Controller extends Section { }); } - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - event.preventDefault(); - } - - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - } - get route() { return this._route; } diff --git a/modules/route/front/summary/style.scss b/modules/route/front/summary/style.scss index b41512f32..659ba9d74 100644 --- a/modules/route/front/summary/style.scss +++ b/modules/route/front/summary/style.scss @@ -3,8 +3,4 @@ vn-route-summary .summary { max-width: $width-lg; - - vn-icon[icon=insert_drive_file]{ - color: $color-font-secondary; - } } \ No newline at end of file diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html index c4e4f8d7e..fee60dcca 100644 --- a/modules/route/front/tickets/index.html +++ b/modules/route/front/tickets/index.html @@ -60,14 +60,14 @@ {{ticket.id}} {{ticket.nickname}} @@ -78,11 +78,12 @@ {{ticket.address.postalCode}} {{ticket.address.street}} - - + icon="insert_drive_file" + class="bright"> + + on-response="$ctrl.setTicketsRoute($response)" + message="Tickets to add"> -
-
Tickets to add
-
@@ -176,4 +175,4 @@ vn-acl-action="remove" vn-bind="+" fixed-bottom-right> - \ No newline at end of file + diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js index 556ad0b6c..e7c6cb7b1 100644 --- a/modules/route/front/tickets/index.js +++ b/modules/route/front/tickets/index.js @@ -128,20 +128,6 @@ class Controller extends Section { }); } - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - event.preventDefault(); - } - - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - event.preventDefault(); - } - openPossibleTicketsDialog() { this.$.possibleTicketsModel.refresh(); this.$.possibleTicketsDialog.show(); diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js index f3c02cf51..c2671c3d7 100644 --- a/modules/route/front/tickets/index.spec.js +++ b/modules/route/front/tickets/index.spec.js @@ -213,36 +213,6 @@ describe('Route', () => { }); }); - describe('showTicketDescriptor()', () => { - it('should call the descriptor show function after setting the parent and the ticket id', () => { - controller.$.ticketDescriptor = {show: () => {}}; - jest.spyOn(controller.$.ticketDescriptor, 'show'); - const event = {target: {}, preventDefault: () => {}}; - jest.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: () => {}}; - jest.spyOn(controller.$.clientDescriptor, 'show'); - const event = {target: {}, preventDefault: () => {}}; - jest.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: () => {}}; diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index a39233563..20ee592c1 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -27,7 +27,7 @@ {{sale.itemFk | zeroFill:6}} @@ -66,5 +66,5 @@ + warehouse-fk="$ctrl.ticket.warehouseFk"> \ No newline at end of file diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index 40054571e..3efd7d56d 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -9,8 +9,7 @@ class Controller extends Section { order: 'concept ASC', include: [{ relation: 'item', - }, - { + }, { relation: 'components', scope: { fields: ['componentFk', 'value'], @@ -46,27 +45,6 @@ class Controller extends Section { return sum; } - - showDescriptor(event, sale) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${sale.itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - lineFk: ${sale.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = sale.itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketComponents', { diff --git a/modules/ticket/front/descriptor-popover/index.html b/modules/ticket/front/descriptor-popover/index.html index 00d387f73..0dc0f8d00 100644 --- a/modules/ticket/front/descriptor-popover/index.html +++ b/modules/ticket/front/descriptor-popover/index.html @@ -1,12 +1,4 @@ - - - - + + - \ No newline at end of file + \ No newline at end of file diff --git a/modules/ticket/front/descriptor-popover/index.js b/modules/ticket/front/descriptor-popover/index.js index 822296c5b..f6e66f3a1 100644 --- a/modules/ticket/front/descriptor-popover/index.js +++ b/modules/ticket/front/descriptor-popover/index.js @@ -1,114 +1,9 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; -import './style.scss'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.ticket = null; - this._quicklinks = {}; - } +class Controller extends DescriptorPopover {} - set ticketFk(id) { - if (id == this._ticketFk) return; - - this._ticketFk = id; - this.ticket = null; - this.getCard(); - } - - set ticket(value) { - this._ticket = value; - this.$timeout(() => this.$.popover.relocate()); - } - - get ticket() { - return this._ticket; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - getCard() { - if (this.canceler) - this.canceler.resolve(); - - this.canceler = this.$q.defer(); - - let options = {timeout: this.canceler.promise}; - - let filter = { - include: [ - { - relation: 'warehouse', - scope: { - fields: ['name'] - } - }, - { - relation: 'agencyMode', - scope: { - fields: ['name'] - } - }, - { - relation: 'client', - scope: { - fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'], - include: { - relation: 'salesPerson', - scope: { - fields: ['userFk'], - include: { - relation: 'user', - scope: { - fields: ['nickname'] - } - } - } - } - } - }, - { - relation: 'state', - scope: { - fields: ['stateFk'], - include: { - relation: 'state', - fields: ['id', 'name'], - } - } - } - ] - }; - let json = encodeURIComponent(JSON.stringify(filter)); - let query = `Tickets/${this._ticketFk}?filter=${json}`; - this.$http.get(query, options).then( - response => { - this.ticket = response.data; - this.canceler = null; - } - ); - } -} - -ngModule.component('vnTicketDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - ticketFk: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnTicketDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/ticket/front/descriptor-popover/index.spec.js b/modules/ticket/front/descriptor-popover/index.spec.js deleted file mode 100644 index 17682e5de..000000000 --- a/modules/ticket/front/descriptor-popover/index.spec.js +++ /dev/null @@ -1,125 +0,0 @@ -import './index.js'; - -describe('ticket Component vnTicketDescriptorPopover', () => { - let $httpBackend; - let $scope; - let controller; - let $element; - let $timeout; - - beforeEach(ngModule('ticket')); - - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { - $httpBackend = _$httpBackend_; - $timeout = _$timeout_; - $element = angular.element(`
`); - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnTicketDescriptorPopover', {$scope, $element}); - })); - - describe('ticketFk()', () => { - it(`should not apply any changes if the received id is the same stored in _ticketFk`, () => { - controller.ticket = 'I exist!'; - controller._ticketFk = 1; - jest.spyOn(controller, 'getCard'); - controller.ticketFk = 1; - - expect(controller.ticket).toEqual('I exist!'); - expect(controller._ticketFk).toEqual(1); - expect(controller.getCard).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _ticketFk, set the ticket to null and then call getCard()`, () => { - controller.ticket = `Please don't`; - controller._ticketFk = 1; - jest.spyOn(controller, 'getCard'); - controller.ticketFk = 999; - - expect(controller.ticket).toBeNull(); - expect(controller._ticketFk).toEqual(999); - expect(controller.getCard).toHaveBeenCalledWith(); - }); - }); - - describe('ticket()', () => { - it(`should save the ticket into _ticket and then call relocate()`, () => { - jest.spyOn(controller.$.popover, 'relocate'); - controller.ticket = `i'm the ticket!`; - $timeout.flush(); - - expect(controller._ticket).toEqual(`i'm the ticket!`); - expect(controller.$.popover.relocate).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('getCard()', () => { - it(`should perform a get query to store the ticket data into the controller`, () => { - controller.ticketFk = 1; - controller.canceler = null; - let response = {}; - - let filter = { - include: [ - { - relation: 'warehouse', - scope: { - fields: ['name'] - } - }, - { - relation: 'agencyMode', - scope: { - fields: ['name'] - } - }, - { - relation: 'client', - scope: { - fields: ['salesPersonFk', 'name', 'isActive', 'isFreezed', 'isTaxDataChecked'], - include: { - relation: 'salesPerson', - scope: { - fields: ['userFk'], - include: { - relation: 'user', - scope: { - fields: ['nickname'] - } - } - } - } - } - }, - { - relation: 'state', - scope: { - fields: ['stateFk'], - include: { - relation: 'state', - fields: ['id', 'name'], - } - } - } - ] - }; - let json = encodeURIComponent(JSON.stringify(filter)); - $httpBackend.when('GET', `Tickets/${controller._ticketFk}?filter=${json}`).respond(response); - $httpBackend.expect('GET', `Tickets/${controller._ticketFk}?filter=${json}`); - controller.getCard(); - $httpBackend.flush(); - - expect(controller.ticket).toEqual(response); - }); - }); -}); - diff --git a/modules/ticket/front/descriptor-popover/style.scss b/modules/ticket/front/descriptor-popover/style.scss deleted file mode 100644 index f50481083..000000000 --- a/modules/ticket/front/descriptor-popover/style.scss +++ /dev/null @@ -1,11 +0,0 @@ -vn-ticket-descriptor-popover { - vn-ticket-descriptor { - display: block; - width: 256px; - max-height: 448px; - - & > vn-card { - margin: 0!important; - } - } -} \ No newline at end of file diff --git a/modules/ticket/front/descriptor/addStowaway.html b/modules/ticket/front/descriptor/addStowaway.html index d15d7185d..f05a6584f 100644 --- a/modules/ticket/front/descriptor/addStowaway.html +++ b/modules/ticket/front/descriptor/addStowaway.html @@ -5,11 +5,9 @@ + on-open="model.refresh()" + message="Stowaways to add"> -
-
Stowaways to add
-
diff --git a/modules/ticket/front/descriptor/addStowaway.js b/modules/ticket/front/descriptor/addStowaway.js index 28286386b..4497fef82 100644 --- a/modules/ticket/front/descriptor/addStowaway.js +++ b/modules/ticket/front/descriptor/addStowaway.js @@ -6,8 +6,8 @@ class Controller extends Component { addStowaway(stowaway) { let params = {id: stowaway.id, shipFk: this.ticket.id}; this.$http.post(`Stowaways/`, params) + .then(() => this.cardReload()) .then(() => { - this.cardReload(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); this.$.dialog.hide(); }); diff --git a/modules/ticket/front/descriptor/index.html b/modules/ticket/front/descriptor/index.html index 2ea87839b..ede553b72 100644 --- a/modules/ticket/front/descriptor/index.html +++ b/modules/ticket/front/descriptor/index.html @@ -1,80 +1,166 @@ -
-
- - - - - - - - -
-
+ + + + Add turn + + + Show Delivery Note + + + Send Delivery Note + + + Delete ticket + + + Change shipped hour + + + SMS Pending payment + + + SMS Minimum import + + + Add stowaway + + + Delete stowaway + + + Make invoice + + + Regenerate invoice + + + Recalculate components + + +
-
{{::$ctrl.client.name}}
- - - - - - - - - -
- - - - -
- - +
-
-
+ +
-
- In which day you want to add the ticket? +
+ In which day you want to add the ticket?
- - + + + + + + + + + + + + + on-accept="$ctrl.changeShipped()" + message="Change shipped hour"> -
Change shipped hour
-
- - - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index 5dc7a3f70..1b9048bd7 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -1,153 +1,25 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; - -class Controller extends Component { - constructor($element, $, $httpParamSerializer) { - super($element, $); - this.$httpParamSerializer = $httpParamSerializer; - - this.moreOptions = [ - { - name: 'Add turn', - callback: this.showAddTurnDialog, - acl: 'buyer' - }, { - name: 'Show Delivery Note', - callback: this.showDeliveryNote - }, { - name: 'Send Delivery Note', - callback: this.confirmDeliveryNote - }, { - name: 'Delete ticket', - callback: this.showDeleteTicketDialog - }, { - name: 'Change shipped hour', - callback: this.showChangeShipped - }, { - name: 'SMS Pending payment', - callback: this.sendPaymentSms - }, { - name: 'SMS Minimum import', - callback: this.sendImportSms - }, { - name: 'Add stowaway', - callback: this.showAddStowaway, - show: () => this.canShowStowaway - }, { - name: 'Delete stowaway', - callback: this.showDeleteStowaway, - show: () => this.shouldShowDeleteStowaway() - }, { - name: 'Make invoice', - callback: this.showMakeInvoiceDialog, - show: () => !this.hasInvoice(), - acl: 'invoicing' - }, { - name: 'Regenerate invoice', - callback: this.showRegenerateInvoiceDialog, - show: () => this.hasInvoice(), - acl: 'invoicing' - }, { - name: 'Recalculate components', - callback: this.comfirmRecalculateComponents, - show: () => this.isEditable - }, - ]; - } +import Descriptor from 'salix/components/descriptor'; +class Controller extends Descriptor { get ticket() { - return this._ticket; + return this.entity; } set ticket(value) { - this._ticket = value; + this.entity = value; + } - if (!value) return; - - if (this.$params.sendSMS) - this.showSMSDialog(); + get entity() { + return super.entity; + } + set entity(value) { + super.entity = value; this.canStowaway(); - let links = { - btnOne: { - icon: 'person', - state: `client.card.summary({id: ${value.clientFk}})`, - tooltip: 'Client card' - }}; - - if (value.stowaway) { - links.btnTwo = { - icon: 'icon-stowaway', - state: `ticket.card.summary({id: ${value.stowaway.shipFk}})`, - tooltip: 'Ship stowaways' - }; - } - - if (value.ship) { - links.btnThree = { - icon: 'icon-stowaway', - state: `ticket.card.summary({id: ${value.ship.id}})`, - tooltip: 'Stowaway' - }; - } - - this._quicklinks = links; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - showChangeShipped() { - if (!this.isEditable) { - this.vnApp.showError(this.$t(`This ticket can't be modified`)); - return; - } - - this.newShipped = this.ticket.shipped; - this.$.changeShippedDialog.show(); - } - - changeShipped() { - let data = {shipped: this.newShipped}; - let query = `Tickets/${this.ticket.id}/updateEditableTicket`; - this.$http.post(query, data) - .then(() => this.cardReload()) - .then(() => this.vnApp.showSuccess(this.$t('Shipped hour updated'))); - } - - isTicketModule() { - let path = this.$state.getCurrentPath(); - const isTicket = path[1].state.name === 'ticket'; - if (isTicket) - return true; - - return false; - } - - onMoreChange(callback) { - callback.call(this); - } - - goToTicket(ticketID) { - this.$state.go('ticket.card.sale', {id: ticketID}, {absolute: true}); - } - - onMoreOpen() { - let options = this.moreOptions.filter(option => { - const hasShowProperty = Object.hasOwnProperty.call(option, 'show'); - const hasAclProperty = Object.hasOwnProperty.call(option, 'acl'); - const hasAcl = !hasAclProperty || (hasAclProperty && this.aclService.hasAny([option.acl])); - - return (!hasShowProperty || option.show === true || - typeof option.show === 'function' && option.show()) && hasAcl; - }); - this.$.moreButton.data = options; + if (value && this.$params.sendSMS) + this.showSMSDialog(); } get isEditable() { @@ -158,209 +30,209 @@ class Controller extends Component { return true; } - showAddTurnDialog() { - this.$.addTurn.show(); + get isInvoiced() { + return this.ticket.refFk !== null; + } + + get isTicketModule() { + return this.$state.getCurrentPath()[1].state.name === 'ticket'; + } + + get shouldShowDeleteStowaway() { + if (!this.ticket || !this.isTicketModule) + return false; + + return this.ticket.stowaway || this.ticket.ship; + } + + showChangeShipped() { + this.newShipped = this.ticket.shipped; + this.$.changeShippedDialog.show(); + } + + changeShipped() { + let data = { + shipped: this.newShipped + }; + return this.$http.post(`Tickets/${this.id}/updateEditableTicket`, data) + .then(() => this.cardReload()) + .then(() => this.vnApp.showSuccess(this.$t('Shipped hour updated'))); + } + + goToTicket(ticketId) { + this.$state.go('ticket.card.sale', {id: ticketId}, {absolute: true}); } addTurn(day) { let params = { - ticketFk: this.ticket.id, + ticketFk: this.id, weekDay: day, - agencyModeFk: this.ticket.agencyModeFk}; - this.$http.patch(`TicketWeeklies`, params).then(() => { - this.$.addTurn.hide(); - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + agencyModeFk: this.ticket.agencyModeFk + }; + return this.$http.patch(`TicketWeeklies`, params) + .then(() => { + this.$.addTurn.hide(); + this.vnApp.showSuccess(this.$t('Data saved!')); + }); } - showDeleteTicketDialog() { - if (!this.isEditable) { - this.vnApp.showError(this.$t('This ticket cant be deleted')); - return; - } - - this.$.deleteConfirmation.show(); - } - - deleteTicket(response) { - if (response === 'accept') { - const query = `Tickets/${this.ticket.id}/setDeleted`; - this.$http.post(query).then(() => { + deleteTicket() { + return this.$http.post(`Tickets/${this.id}/setDeleted`) + .then(() => { this.$state.go('ticket.index'); this.vnApp.showSuccess(this.$t('Ticket deleted')); }); - } } canStowaway() { - if (!this.isTicketModule()) return; + this.canShowStowaway = false; + if (!this.isTicketModule || !this.ticket) return; - this.$http.get(`Tickets/${this.ticket.id}/canHaveStowaway`).then(response => { - if (response.data === true) - return this.canShowStowaway = true; - - return this.canShowStowaway = false; - }); - } - - shouldShowDeleteStowaway() { - if (!this._ticket || !this.isTicketModule()) - return false; - - return this._ticket.stowaway || this._ticket.ship; - } - - showAddStowaway() { - this.$.addStowaway.show(); - } - - showDeleteStowaway() { - this.$.deleteStowaway.show(); + this.$http.get(`Tickets/${this.id}/canHaveStowaway`) + .then(res => this.canShowStowaway = !!res.data); } deleteStowaway() { - const query = `Tickets/${this.ticket.id}/deleteStowaway`; - this.$http.post(query).then(res => { - this.vnApp.showSuccess(this.$t('Data saved!')); - this.cardReload(); - }); + return this.$http.post(`Tickets/${this.id}/deleteStowaway`) + .then(() => { + this.vnApp.showSuccess(this.$t('Data saved!')); + this.cardReload(); + }); } showDeliveryNote() { - const params = { + this.showReport('delivery-note', { clientId: this.ticket.client.id, - ticketId: this.ticket.id, - authorization: this.vnToken.token - }; - const serializedParams = this.$httpParamSerializer(params); - let url = `api/report/delivery-note?${serializedParams}`; - window.open(url); + ticketId: this.id, + }); } sendDeliveryNote() { - const params = { + return this.sendEmail('delivery-note', { recipient: this.ticket.client.email, clientId: this.ticket.client.id, - ticketId: this.ticket.id - }; - this.$http.get(`email/delivery-note`, {params}).then( - () => this.vnApp.showMessage(this.$t('Notification sent!')) - ); + ticketId: this.id + }); } sendImportSms() { const params = { - ticketId: this.ticket.id, + ticketId: this.id, created: this.ticket.created }; - const message = this.$params.message || this.$t('Minimum is needed', params); - this.newSMS = {message}; - this.showSMSDialog(); + this.showSMSDialog({ + message: this.$params.message || this.$t('Minimum is needed', params) + }); } sendPaymentSms() { - const message = this.$params.message || this.$t('Make a payment'); - this.newSMS = {message}; - this.showSMSDialog(); + this.showSMSDialog({ + message: this.$params.message || this.$t('Make a payment') + }); } - showSMSDialog() { + showSMSDialog(params) { const address = this.ticket.address; const client = this.ticket.client; - const phone = this.$params.phone || address.mobile || address.phone || - client.mobile || client.phone; + const phone = this.$params.phone + || address.mobile + || address.phone + || client.mobile + || client.phone; - this.newSMS.destinationFk = this.ticket.clientFk; - this.newSMS.destination = phone; + this.newSMS = Object.assign({ + destinationFk: this.ticket.clientFk, + destination: phone + }, params); this.$.sms.open(); } - /** - * Shows an invoice confirmation - */ - showMakeInvoiceDialog() { - this.$.makeInvoiceConfirmation.show(); - } - - /** - * Makes an invoice - * from current ticket - * - * @param {String} response - Response result - */ - makeInvoice(response) { - if (response === 'accept') { - const query = `Tickets/${this.ticket.id}/makeInvoice`; - this.$http.post(query).then(() => { + makeInvoice() { + return this.$http.post(`Tickets/${this.id}/makeInvoice`) + .then(() => { this.vnApp.showSuccess(this.$t('Ticket invoiced')); this.$state.reload(); }); - } } - /** - * Shows an invoice confirmation - */ - showRegenerateInvoiceDialog() { - this.$.regenerateInvoiceConfirmation.show(); - } - - /** - * Sends an invoice to a regeneration queue - * for the current ticket - * - * @param {String} response - Response result - */ - regenerateInvoice(response) { - if (response === 'accept') { - const invoiceId = this.ticket.invoiceOut.id; - const query = `InvoiceOuts/${invoiceId}/regenerate`; - this.$http.post(query).then(() => { + regenerateInvoice() { + const invoiceId = this.ticket.invoiceOut.id; + return this.$http.post(`InvoiceOuts/${invoiceId}/regenerate`) + .then(() => { const snackbarMessage = this.$t( `Invoice sent for a regeneration, will be available in a few minutes`); this.vnApp.showSuccess(snackbarMessage); }); - } - } - - /** - * Returns if the current ticket - * is already invoiced - * @return {Boolean} - True if invoiced - */ - hasInvoice() { - return this.ticket.refFk !== null; - } - - /** - * Shows a delivery-note send confirmation - */ - confirmDeliveryNote() { - this.$.confirmDeliveryNote.show(); - } - - /** - * Shows an invoice confirmation - */ - comfirmRecalculateComponents() { - this.$.recalculateComponentsConfirmation.show(); } recalculateComponents() { - const query = `Tickets/${this.ticket.id}/recalculateComponents`; - this.$http.post(query).then(res => { - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + return this.$http.post(`Tickets/${this.id}/recalculateComponents`) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); + } + + cardReload() { + // Prevents error when not defined + } + + loadData() { + const filter = { + include: [ + { + relation: 'warehouse', + scope: { + fields: ['name'] + } + }, { + relation: 'agencyMode', + scope: { + fields: ['name'] + } + }, { + relation: 'client', + scope: { + fields: [ + 'salesPersonFk', + 'name', + 'isActive', + 'isFreezed', + 'isTaxDataChecked' + ], + include: { + relation: 'salesPerson', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['nickname'] + } + } + } + } + } + }, { + relation: 'state', + scope: { + fields: ['stateFk'], + include: { + relation: 'state', + fields: ['id', 'name'], + } + } + } + ] + }; + + return this.getData(`Tickets/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -Controller.$inject = ['$element', '$scope', '$httpParamSerializer']; - -ngModule.component('vnTicketDescriptor', { +ngModule.vnComponent('vnTicketDescriptor', { template: require('./index.html'), + controller: Controller, bindings: { ticket: '<', cardReload: '&' - }, - controller: Controller + } }); diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index 4f43ac010..f152f1f0f 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -1,47 +1,40 @@ import './index.js'; describe('Ticket Component vnTicketDescriptor', () => { - let $httpParamSerializer; let $httpBackend; let controller; let $state; + const ticket = { + id: 2, + clientFk: 101, + invoiceOut: {id: 1}, + client: { + id: 101, + email: 'client@email' + }, + address: { + id: 101, + mobile: 111111111, + phone: 2222222222 + }, + tracking: { + state: {alertLevel: 3} + } + }; + beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, $compile, _$state_, _$httpParamSerializer_) => { - let $element = $compile(``)($rootScope); - $state = _$state_; - $state.getCurrentPath = () => { - return [ - {state: {}}, - {state: {name: 'ticket'}} - ]; - }; + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$state_) => { $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - controller = $componentController('vnTicketDescriptor', {$element}); - controller._ticket = { - id: 2, - clientFk: 101, - invoiceOut: {id: 1}, - client: {id: 101, email: 'client@email'}, - address: {id: 101, mobile: 111111111, phone: 2222222222} - }; - controller.cardReload = ()=> { - return true; - }; + $httpBackend.whenGET(`Tickets/${ticket.id}/canHaveStowaway`).respond(true); + + $state = _$state_; + $state.getCurrentPath = () => [null, {state: {name: 'ticket'}}]; + + controller = $componentController('vnTicketDescriptor', {$element: null}, {ticket}); })); - describe('showAddTurnDialog()', () => { - it('should call controller.$.addTurn.show()', () => { - controller.$.addTurn = {show: () => {}}; - jest.spyOn(controller.$.addTurn, 'show'); - controller.showAddTurnDialog(); - - expect(controller.$.addTurn.show).toHaveBeenCalledWith(); - }); - }); - describe('addTurn()', () => { it('should make a query and call $.addTurn.hide() and vnApp.showSuccess()', () => { controller.$.addTurn = {hide: () => {}}; @@ -55,176 +48,114 @@ describe('Ticket Component vnTicketDescriptor', () => { }); }); - describe('showDeleteTicketDialog()', () => { - it('should call vnApp.showError() if the ticket isnt editable', () => { - controller.ticket.tracking = {state: {alertLevel: 3}}; - jest.spyOn(controller.vnApp, 'showError'); - controller.showDeleteTicketDialog(); - - expect(controller.vnApp.showError).toHaveBeenCalledWith('This ticket cant be deleted'); - }); - - it('should call deleteConfirmation.show() if the ticket is editable', () => { - controller.ticket.tracking = {state: {alertLevel: 0}}; - controller.$.deleteConfirmation = {show: () => {}}; - jest.spyOn(controller.$.deleteConfirmation, 'show'); - controller.showDeleteTicketDialog(); - - expect(controller.$.deleteConfirmation.show).toHaveBeenCalledWith(); - }); - }); - describe('deleteTicket()', () => { - it('should make a query and call vnApp.showSuccess() if the response is accept', () => { + it('should make a query and call vnApp.showSuccess()', () => { jest.spyOn(controller.$state, 'go').mockReturnValue('ok'); jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.expectPOST(`Tickets/2/setDeleted`).respond(); - controller.deleteTicket('accept'); + $httpBackend.expectPOST(`Tickets/${ticket.id}/setDeleted`).respond(); + controller.deleteTicket(); $httpBackend.flush(); expect(controller.$state.go).toHaveBeenCalledWith('ticket.index'); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket deleted'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('showDeliveryNote()', () => { it('should open a new window showing a delivery note PDF document', () => { + jest.spyOn(controller, 'showReport'); + const params = { - clientId: controller.ticket.client.id, - ticketId: controller.ticket.id + clientId: ticket.client.id, + ticketId: ticket.id }; - const serializedParams = $httpParamSerializer(params); - let expectedPath = `api/report/delivery-note?${serializedParams}`; - jest.spyOn(window, 'open').mockReturnThis(); controller.showDeliveryNote(); - expect(window.open).toHaveBeenCalledWith(expectedPath); + expect(controller.showReport).toHaveBeenCalledWith('delivery-note', params); }); }); describe('sendDeliveryNote()', () => { it('should make a query and call vnApp.showMessage()', () => { - jest.spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller, 'sendEmail'); const params = { - recipient: 'client@email', - clientId: controller.ticket.client.id, - ticketId: controller.ticket.id + recipient: ticket.client.email, + clientId: ticket.client.id, + ticketId: ticket.id }; - const serializedParams = $httpParamSerializer(params); - - $httpBackend.when('GET', `email/delivery-note?${serializedParams}`).respond(); - $httpBackend.expect('GET', `email/delivery-note?${serializedParams}`).respond(); controller.sendDeliveryNote(); - $httpBackend.flush(); - expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!'); + expect(controller.sendEmail).toHaveBeenCalledWith('delivery-note', params); }); }); describe('makeInvoice()', () => { - it('should make a query and call $state.reload() method if the response is accept', () => { + it('should make a query and call $state.reload() method', () => { jest.spyOn(controller.$state, 'reload').mockReturnThis(); jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('POST', 'Tickets/2/makeInvoice').respond(); - $httpBackend.expect('POST', 'Tickets/2/makeInvoice').respond(); - controller.makeInvoice('accept'); + $httpBackend.expectPOST(`Tickets/${ticket.id}/makeInvoice`).respond(); + controller.makeInvoice(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Ticket invoiced'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); expect(controller.$state.reload).toHaveBeenCalledWith(); }); }); describe('regenerateInvoice()', () => { - it('should make a query and show a success snackbar if the response is accept', () => { + it('should make a query and show a success snackbar', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('POST', 'InvoiceOuts/1/regenerate').respond(); - $httpBackend.expect('POST', 'InvoiceOuts/1/regenerate').respond(); - controller.regenerateInvoice('accept'); + $httpBackend.expectPOST(`InvoiceOuts/${ticket.invoiceOut.id}/regenerate`).respond(); + controller.regenerateInvoice(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Invoice sent for a regeneration, will be available in a few minutes'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); describe('changeShipped()', () => { it('should make a query and change the shipped hour if the response is accept', () => { - controller.ticket.id = 12; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller, 'cardReload'); - $httpBackend.expectRoute('POST', 'Tickets/:id/updateEditableTicket').respond(); - controller.changeShipped('accept'); + $httpBackend.expectPOST(`Tickets/${ticket.id}/updateEditableTicket`).respond(); + controller.changeShipped(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Shipped hour updated'); - expect(controller.cardReload).toHaveBeenCalledWith(); - }); - }); - - describe('showAddStowaway()', () => { - it('should show a dialog with a list of tickets available for an stowaway', () => { - controller.$.addStowaway = {}; - controller.$.addStowaway.show = jasmine.createSpy('show'); - controller.showAddStowaway(); - - expect(controller.$.addStowaway.show).toHaveBeenCalledWith(); - }); - }); - - describe('showRemoveStowaway()', () => { - it('should show a dialog for an stowaway removal', () => { - controller.$.deleteStowaway = {}; - controller.$.deleteStowaway.show = jasmine.createSpy('show'); - controller.showDeleteStowaway(); - - expect(controller.$.deleteStowaway.show).toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.cardReload).toHaveBeenCalled(); }); }); describe('canStowaway()', () => { - it('should make a query and return if the ticket can be stowawayed', () => { - controller.ticket.id = 16; - jest.spyOn(controller, 'isTicketModule'); - $httpBackend.when('GET', 'Tickets/16/canHaveStowaway').respond(true); - $httpBackend.expect('GET', 'Tickets/16/canHaveStowaway').respond(true); + fit('should make a query and return if the ticket can be stowawayed', () => { controller.canStowaway(); $httpBackend.flush(); expect(controller.canShowStowaway).toBeTruthy(); - expect(controller.isTicketModule).toHaveBeenCalledWith(); }); it('should not make a query if is not on the ticket module', () => { - controller.ticket.id = 16; - $state.getCurrentPath = () => { - return [ - {state: {}}, - {state: {name: 'client'}} - ]; - }; - jest.spyOn(controller, 'isTicketModule'); + $state.getCurrentPath = () => [null, {state: {name: 'client'}}]; controller.canStowaway(); - expect(controller.canShowStowaway).toBeUndefined(); - expect(controller.isTicketModule).toHaveBeenCalledWith(); + expect(controller.canShowStowaway).toBeFalsy(); }); }); describe('recalculateComponents()', () => { - it('should make a query and show a success snackbar', () => { + it('should make a query and show a success message', () => { jest.spyOn(controller.vnApp, 'showSuccess'); - $httpBackend.when('POST', 'Tickets/2/recalculateComponents').respond(); - $httpBackend.expect('POST', 'Tickets/2/recalculateComponents').respond(); + $httpBackend.expectPOST(`Tickets/${ticket.id}/recalculateComponents`).respond(); controller.recalculateComponents(); $httpBackend.flush(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); @@ -233,14 +164,25 @@ describe('Ticket Component vnTicketDescriptor', () => { controller.$.sms = {open: () => {}}; jest.spyOn(controller.$.sms, 'open'); - const clientId = 101; - const expectedPhone = 111111111; - controller.newSMS = {}; controller.showSMSDialog(); - expect(controller.newSMS.destinationFk).toEqual(clientId); - expect(controller.newSMS.destination).toEqual(expectedPhone); expect(controller.$.sms.open).toHaveBeenCalledWith(); + expect(controller.newSMS).toEqual({ + destinationFk: ticket.clientFk, + destination: ticket.address.mobile + }); + }); + }); + + describe('loadData()', () => { + it(`should perform a get query to store the ticket data into the controller`, () => { + controller.ticket = null; + + $httpBackend.expectRoute('GET', `Tickets/${ticket.id}`).respond(ticket); + controller.id = ticket.id; + $httpBackend.flush(); + + expect(controller.ticket).toEqual(ticket); }); }); }); diff --git a/modules/ticket/front/dms/index/index.html b/modules/ticket/front/dms/index/index.html index 3b690cfd3..176eed754 100644 --- a/modules/ticket/front/dms/index/index.html +++ b/modules/ticket/front/dms/index/index.html @@ -60,7 +60,7 @@ + ng-click="workerDescriptor.show($event, document.dms.workerFk)"> {{::document.dms.worker.user.nickname | dashIfEmpty}} @@ -83,7 +83,7 @@ @@ -106,5 +106,5 @@ vn-id="confirm" message="This file will be deleted" question="Are you sure you want to continue?" - on-response="$ctrl.deleteDms($response)"> + on-accept="$ctrl.deleteDms($data)"> \ No newline at end of file diff --git a/modules/ticket/front/dms/index/index.js b/modules/ticket/front/dms/index/index.js index a37d15426..85349f59e 100644 --- a/modules/ticket/front/dms/index/index.js +++ b/modules/ticket/front/dms/index/index.js @@ -42,28 +42,13 @@ class Controller extends Section { }; } - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.show(); - } - - showDeleteConfirm(index) { - this.dmsIndex = index; - this.$.confirm.show(); - } - - deleteDms(response) { - if (response === 'accept') { - const dmsFk = this.ticketDms[this.dmsIndex].dmsFk; - const query = `ticketDms/${dmsFk}/removeFile`; - this.$http.post(query).then(() => { - this.$.model.remove(this.dmsIndex); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + deleteDms(index) { + const dmsFk = this.ticketDms[index].dmsFk; + this.$http.post(`ticketDms/${dmsFk}/removeFile`) + .then(() => { + this.$.model.remove(index); + this.vnApp.showSuccess(this.$t('Data saved!')); }); - } } } diff --git a/modules/ticket/front/dms/index/index.spec.js b/modules/ticket/front/dms/index/index.spec.js index cd1fd0125..2cd63462a 100644 --- a/modules/ticket/front/dms/index/index.spec.js +++ b/modules/ticket/front/dms/index/index.spec.js @@ -10,27 +10,25 @@ describe('Ticket', () => { beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; - const $element = angular.element(''); - controller = $componentController('vnTicketDmsIndex', {$element}); + controller = $componentController('vnTicketDmsIndex', {$element: null}); controller.$.model = crudModel; })); describe('deleteDms()', () => { it('should make an HTTP Post query', () => { - const dmsId = 1; - const dmsIndex = 0; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); - controller.ticketDms = [{dmsFk: 1}]; - controller.dmsIndex = dmsIndex; - $httpBackend.when('POST', `ticketDms/${dmsId}/removeFile`).respond({}); - $httpBackend.expect('POST', `ticketDms/${dmsId}/removeFile`); - controller.deleteDms('accept'); + const dmsId = 1; + const dmsIndex = 0; + controller.ticketDms = [{dmsFk: 1}]; + + $httpBackend.expectPOST(`ticketDms/${dmsId}/removeFile`).respond({}); + controller.deleteDms(dmsIndex); $httpBackend.flush(); expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); diff --git a/modules/ticket/front/expedition/index.html b/modules/ticket/front/expedition/index.html index a90d48670..3b17a3b88 100644 --- a/modules/ticket/front/expedition/index.html +++ b/modules/ticket/front/expedition/index.html @@ -28,7 +28,7 @@ @@ -37,7 +37,7 @@ + ng-click="itemDescriptor.show($event, expedition.itemFk)"> {{expedition.itemFk | zeroFill:6}} @@ -48,7 +48,7 @@ + ng-click="workerDescriptor.show($event, expedition.workerFk)"> {{::expedition.userNickname | dashIfEmpty}} @@ -60,15 +60,15 @@ + warehouse-fk="this.ticket.warehouseFk", + ticket-fk="$ctrl.ticket.id"> + vn-id="workerDescriptor"> \ No newline at end of file diff --git a/modules/ticket/front/expedition/index.js b/modules/ticket/front/expedition/index.js index 28193cd3b..673c18e33 100644 --- a/modules/ticket/front/expedition/index.js +++ b/modules/ticket/front/expedition/index.js @@ -2,35 +2,9 @@ import ngModule from '../module'; import Section from 'salix/components/section'; class Controller extends Section { - deleteExpedition(expedition) { - this.expeditionId = expedition.id; - this.$.deleteExpedition.show(); - } - - returnDialog(response) { - if (response === 'accept') { - this.$http.delete(`Expeditions/${this.expeditionId}`).then( - () => this.$.model.refresh() - ); - } - } - - showItemDescriptor(event, sale) { - this.$.itemDescriptor.itemFk = sale.itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); + onDialogAccept(id) { + return this.$http.delete(`Expeditions/${id}`) + .then(() => this.$.model.refresh()); } } diff --git a/modules/ticket/front/expedition/index.spec.js b/modules/ticket/front/expedition/index.spec.js index 839108df7..761dc1fb6 100644 --- a/modules/ticket/front/expedition/index.spec.js +++ b/modules/ticket/front/expedition/index.spec.js @@ -14,20 +14,17 @@ describe('Ticket', () => { $scope.model = { refresh: () => {} }; - const $element = angular.element(''); - controller = $componentController('vnTicketExpedition', {$element, $scope}); + controller = $componentController('vnTicketExpedition', {$element: null, $scope}); })); - describe('returnDialog()', () => { + describe('onDialogAccept()', () => { it('should perform a DELETE query', () => { jest.spyOn($scope.model, 'refresh'); - let response = 'accept'; - controller.expeditionId = 1; + const id = 1; - $httpBackend.when('DELETE', `Expeditions/1`).respond(200); - $httpBackend.expect('DELETE', `Expeditions/1`); - controller.returnDialog(response); + $httpBackend.expectDELETE(`Expeditions/${id}`).respond(200); + controller.onDialogAccept(id); $httpBackend.flush(); expect($scope.model.refresh).toHaveBeenCalledWith(); diff --git a/modules/ticket/front/index/index.html b/modules/ticket/front/index/index.html index fd284333b..ab2501a13 100644 --- a/modules/ticket/front/index/index.html +++ b/modules/ticket/front/index/index.html @@ -36,7 +36,7 @@ + vn-click-stop> @@ -67,9 +67,9 @@ {{::ticket.id}} - + {{::ticket.userNickname | dashIfEmpty}} @@ -80,9 +80,9 @@ {{::ticket.shipped | date: 'HH:mm'}} - + {{::ticket.nickname}} @@ -103,12 +103,12 @@ @@ -118,7 +118,6 @@ - - - + + + vn-id="workerDescriptor"> - \ No newline at end of file diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 4803f40ff..59e5d949d 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -43,12 +43,6 @@ export default class Controller extends Section { return this.checked.length; } - goToLines(event, ticketFk) { - this.preventDefault(event); - let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true}); - window.open(url, '_blank'); - } - onMoreOpen() { let options = this.moreOptions.filter(o => o.always || this.isChecked); this.$.moreButton.data = options; @@ -89,30 +83,15 @@ export default class Controller extends Section { return 'warning'; } - showClientDescriptor(event, clientFk) { - this.preventDefault(event); - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); + goToLines(ticketFk) { + let url = this.$state.href('ticket.card.sale', {id: ticketFk}, {absolute: true}); + window.open(url, '_blank'); } - showWorkerDescriptor(event, workerFk) { - this.preventDefault(event); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - preview(event, ticket) { - this.preventDefault(event); + preview(ticket) { this.selectedTicket = ticket; this.$.summary.show(); } - - preventDefault(event) { - event.preventDefault(); - event.stopImmediatePropagation(); - } } ngModule.component('vnTicketIndex', { diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index 10bd88d3d..de619ef26 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -52,21 +52,6 @@ describe('Component vnTicketIndex', () => { }); }); - describe('showClientDescriptor()', () => { - it('should show the client descriptor popover', () => { - controller.$.clientDescriptor = {show: () => {}}; - controller.$.clientDescriptor.show = jasmine.createSpy('show'); - let event = new MouseEvent('click', { - view: $window, - bubbles: true, - cancelable: true - }); - controller.showClientDescriptor(event, tickets[0].clientFk); - - expect(controller.$.clientDescriptor.show).toHaveBeenCalledWith(); - }); - }); - describe('preview()', () => { it('should show the dialog summary', () => { controller.$.summary = {show: () => {}}; diff --git a/modules/ticket/front/locale/es.yml b/modules/ticket/front/locale/es.yml index 5cc2e115e..494725bb7 100644 --- a/modules/ticket/front/locale/es.yml +++ b/modules/ticket/front/locale/es.yml @@ -61,6 +61,7 @@ Invoice: Factura You are going to delete this ticket: Vas a eliminar este ticket Ticket deleted: Ticket borrado Search ticket by id or alias: Buscar tickets por identificador o alias +ticket: ticket #sections List: Listado diff --git a/modules/ticket/front/picture/index.html b/modules/ticket/front/picture/index.html index 58e13a451..52cab5b31 100644 --- a/modules/ticket/front/picture/index.html +++ b/modules/ticket/front/picture/index.html @@ -15,17 +15,17 @@ No results -
+

- + {{::sale.item.name}}

@@ -62,4 +62,6 @@ - + + diff --git a/modules/ticket/front/picture/index.js b/modules/ticket/front/picture/index.js index 257a53e6c..50d7cc777 100644 --- a/modules/ticket/front/picture/index.js +++ b/modules/ticket/front/picture/index.js @@ -13,16 +13,6 @@ class Controller extends Section { } }; } - - showDescriptor(event, itemFk) { - this.$.descriptor.itemFk = itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketPicture', { diff --git a/modules/ticket/front/request/index/index.html b/modules/ticket/front/request/index/index.html index eeb111a8f..3335a8a06 100644 --- a/modules/ticket/front/request/index/index.html +++ b/modules/ticket/front/request/index/index.html @@ -43,14 +43,14 @@ + ng-click="workerDescriptor.show($event, request.requesterFk)"> {{::request.requester.user.nickname | dashIfEmpty}} + ng-click="workerDescriptor.show($event, request.attenderFk)"> {{::request.atender.user.nickname | dashIfEmpty}} @@ -73,7 +73,7 @@ {{::request.saleFk | zeroFill:6}} @@ -101,12 +101,10 @@ + vn-id="itemDescriptor"> + vn-id="workerDescriptor">
{ beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject($componentController => { - const $element = angular.element(''); - controller = $componentController('vnTicketRequestIndex', {$element}); + beforeEach(inject($componentController => { + controller = $componentController('vnTicketRequestIndex', {$element: null}); })); describe('getRequestState()', () => { diff --git a/modules/ticket/front/sale-checked/index.html b/modules/ticket/front/sale-checked/index.html index e96d93d05..78ed6dfdc 100644 --- a/modules/ticket/front/sale-checked/index.html +++ b/modules/ticket/front/sale-checked/index.html @@ -50,5 +50,6 @@ + warehouse-fk="$ctrl.ticket.warehouseFk" + ticket-fk="$ctrl.ticket.id"> diff --git a/modules/ticket/front/sale-checked/index.js b/modules/ticket/front/sale-checked/index.js index ad98bfb12..5768785d8 100644 --- a/modules/ticket/front/sale-checked/index.js +++ b/modules/ticket/front/sale-checked/index.js @@ -5,38 +5,18 @@ class Controller extends Section { constructor($element, $) { super($element, $); this.filter = { - include: [{ - relation: 'item' - }, - { - relation: 'isChecked', - scope: { - fields: ['isChecked'] + include: [ + { + relation: 'item' + }, { + relation: 'isChecked', + scope: { + fields: ['isChecked'] + } } - }] + ] }; } - - showDescriptor(event, sale) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${sale.itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - lineFk: ${sale.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = sale.itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketSaleChecked', { diff --git a/modules/ticket/front/sale-tracking/index.html b/modules/ticket/front/sale-tracking/index.html index c5ef66d77..cf8f31d8e 100644 --- a/modules/ticket/front/sale-tracking/index.html +++ b/modules/ticket/front/sale-tracking/index.html @@ -34,7 +34,7 @@ {{sale.itemFk | zeroFill:6}} @@ -52,7 +52,7 @@ + ng-click="workerDescriptor.show($event, sale.workerFk)"> {{::sale.userNickname | dashIfEmpty}} @@ -63,10 +63,10 @@ - + + vn-id="workerDescriptor"> \ No newline at end of file diff --git a/modules/ticket/front/sale-tracking/index.js b/modules/ticket/front/sale-tracking/index.js index 6ad929636..ebb6f9ada 100644 --- a/modules/ticket/front/sale-tracking/index.js +++ b/modules/ticket/front/sale-tracking/index.js @@ -1,36 +1,7 @@ import ngModule from '../module'; import Section from 'salix/components/section'; -class Controller extends Section { - showItemDescriptor(event, sale) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${sale.itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - lineFk: ${sale.id} - })`, - tooltip: 'Item diary', - }, - }; - this.$.itemDescriptor.itemFk = sale.itemFk; - this.$.itemDescriptor.parent = event.target; - this.$.itemDescriptor.show(); - } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } -} +class Controller extends Section {} ngModule.component('vnTicketSaleTracking', { template: require('./index.html'), diff --git a/modules/ticket/front/sale/index.html b/modules/ticket/front/sale/index.html index a7315e79c..29294fd97 100644 --- a/modules/ticket/front/sale/index.html +++ b/modules/ticket/front/sale/index.html @@ -7,191 +7,191 @@ vn-id="watcher" data="$ctrl.sales"> - +
- - - - - - - - - - - - - - - -

Subtotal {{$ctrl.subtotal | currency: 'EUR':2}}

-

VAT {{$ctrl.VAT | currency: 'EUR':2}}

-

Total {{$ctrl.total | currency: 'EUR':2}}

-
-
- - - - - - - - - - Id - Quantity - Item - Price - Disc - Amount - - - - - - - - - -
- - - - - - - - - - - - - - {{sale.itemFk}} - - - - {{id}} - {{name}} - - - - - {{sale.quantity}} - - - - - - - - - - - - - - - - - - - - - - {{sale.price | currency: 'EUR':2}} - - - - - {{(sale.discount / 100) | percentage}} - - - - {{$ctrl.getSaleTotal(sale) | currency: 'EUR':2}} - + + + + + + + + + + + + + + +

Subtotal {{$ctrl.subtotal | currency: 'EUR':2}}

+

VAT {{$ctrl.VAT | currency: 'EUR':2}}

+

Total {{$ctrl.total | currency: 'EUR':2}}

+
+
+ + + + + + + + + + Id + Quantity + Item + Price + Disc + Amount + + + + + + + + + + + + + + + + + + + + + + + {{sale.itemFk}} + + + + {{id}} - {{name}} + + + + + {{sale.quantity}} + + + + + + + + + + + + + + + + + + + + + + {{sale.price | currency: 'EUR':2}} + + + + + {{(sale.discount / 100) | percentage}} + + + + {{$ctrl.getSaleTotal(sale) | currency: 'EUR':2}} + + - - + - +
- +
- + warehouse-fk="$ctrl.ticket.warehouseFk", + ticket-fk="$ctrl.ticket.id"> diff --git a/modules/ticket/front/sale/index.js b/modules/ticket/front/sale/index.js index f681b3193..f422fefa1 100644 --- a/modules/ticket/front/sale/index.js +++ b/modules/ticket/front/sale/index.js @@ -32,7 +32,6 @@ class Controller extends Section { }, ]; this._sales = []; - this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; } get ticket() { @@ -229,16 +228,6 @@ class Controller extends Section { } } - showRemoveLinesDialog() { - this.$.deleteLines.show(); - } - - showTransferPopover(event) { - this.setTransferParams(); - this.$.transfer.parent = event.target; - this.$.transfer.show(); - } - setTransferParams() { const checkedSales = JSON.stringify(this.checkedLines()); const sales = JSON.parse(checkedSales); @@ -295,28 +284,6 @@ class Controller extends Section { }); } - // Item Descriptor - showDescriptor(event, sale) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${sale.itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - lineFk: ${sale.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = sale.itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } - showEditPricePopover(event, sale) { if (!this.isEditable) return; this.sale = sale; diff --git a/modules/ticket/front/services/index.html b/modules/ticket/front/services/index.html index 57146661c..261b50d6f 100644 --- a/modules/ticket/front/services/index.html +++ b/modules/ticket/front/services/index.html @@ -74,9 +74,9 @@ + on-close="newServiceType = null" + message="New service type"> -
New service type
+ on-response="$ctrl.onResponse($response)" + message="Send SMS">
-
Send SMS
{{$ctrl.summary.routeFk}} @@ -121,7 +121,7 @@ {{sale.itemFk | zeroFill:6}} @@ -212,7 +212,7 @@ {{request.sale.itemFk | zeroFill:6}} @@ -232,12 +232,12 @@ + vn-id="routeDescriptor"> + warehouse-fk="$ctrl.ticket.warehouseFk", + ticket-fk="$ctrl.ticket.id"> diff --git a/modules/ticket/front/summary/index.js b/modules/ticket/front/summary/index.js index 020d1b16d..b8511a662 100644 --- a/modules/ticket/front/summary/index.js +++ b/modules/ticket/front/summary/index.js @@ -29,49 +29,6 @@ class Controller extends Section { }); } - showRouteDescriptor(event) { - this.routeQuicklinks = { - btnThree: { - icon: 'icon-delivery', - state: `route.card.summary({ - id: ${this.summary.routeFk}, - })`, - tooltip: 'Route summary' - } - }; - this.$.routeDescriptor.routeFk = this.summary.routeFk; - this.$.routeDescriptor.parent = event.target; - this.$.routeDescriptor.show(); - } - - showInvoiceOutDescriptor(event, refFk) { - if (!refFk) return; - this.$.invoiceOutDescriptor.invoiceOutId = this.summary.invoiceOut.id; - this.$.invoiceOutDescriptor.parent = event.target; - this.$.invoiceOutDescriptor.show(); - } - - showDescriptor(event, sale) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${sale.itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - lineFk: ${sale.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = sale.itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } - get isEditable() { try { return !this.ticket.state.state.alertLevel; diff --git a/modules/ticket/front/tracking/index/index.html b/modules/ticket/front/tracking/index/index.html index f66c62449..bf22bfb98 100644 --- a/modules/ticket/front/tracking/index/index.html +++ b/modules/ticket/front/tracking/index/index.html @@ -24,7 +24,7 @@ + ng-click="workerDescriptor.show($event, tracking.worker.user.id)"> {{::tracking.worker.user.nickname | dashIfEmpty}} @@ -38,6 +38,5 @@ + vn-id="workerDescriptor"> \ No newline at end of file diff --git a/modules/ticket/front/tracking/index/index.js b/modules/ticket/front/tracking/index/index.js index e58dc4300..2826cbf26 100644 --- a/modules/ticket/front/tracking/index/index.js +++ b/modules/ticket/front/tracking/index/index.js @@ -17,8 +17,7 @@ class Controller extends Section { } } } - }, - { + }, { relation: 'state', scope: { fields: ['name'] @@ -27,14 +26,6 @@ class Controller extends Section { ] }; } - - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } } ngModule.component('vnTicketTrackingIndex', { diff --git a/modules/ticket/front/volume/index.html b/modules/ticket/front/volume/index.html index 0ecd6ef91..23f179fc4 100644 --- a/modules/ticket/front/volume/index.html +++ b/modules/ticket/front/volume/index.html @@ -37,7 +37,7 @@ {{sale.itemFk | zeroFill:6}} @@ -58,7 +58,8 @@ - + diff --git a/modules/ticket/front/volume/index.js b/modules/ticket/front/volume/index.js index 3bdb9df9f..3d690764f 100644 --- a/modules/ticket/front/volume/index.js +++ b/modules/ticket/front/volume/index.js @@ -43,27 +43,6 @@ class Controller extends Section { }); }); } - - showDescriptor(event, sale) { - this.quicklinks = { - btnThree: { - icon: 'icon-transaction', - state: `item.card.diary({ - id: ${sale.itemFk}, - warehouseFk: ${this.ticket.warehouseFk}, - lineFk: ${sale.id} - })`, - tooltip: 'Item diary' - } - }; - this.$.descriptor.itemFk = sale.itemFk; - this.$.descriptor.parent = event.target; - this.$.descriptor.show(); - } - - onDescriptorLoad() { - this.$.popover.relocate(); - } } ngModule.component('vnTicketVolume', { diff --git a/modules/ticket/front/volume/index.spec.js b/modules/ticket/front/volume/index.spec.js index 2f6efee21..7807bfe10 100644 --- a/modules/ticket/front/volume/index.spec.js +++ b/modules/ticket/front/volume/index.spec.js @@ -66,16 +66,21 @@ describe('ticket', () => { }); }); - /* it('should join the sale volumes to its respective sale', () => { + /* + it('should join the sale volumes to its respective sale', () => { controller.ticket = {id: 1}; - let response = {volumes: [{saleFk: 1, m3: 0.008}, {saleFk: 2, m3: 0.003}]}; - $httpBackend.whenGET(`tickets/1/getVolume`).respond(response); - $httpBackend.expectGET(`tickets/1/getVolume`); + let response = {volumes: [ + {saleFk: 1, m3: 0.008}, + {saleFk: 2, m3: 0.003} + ]}; + + $httpBackend.expectGET(`tickets/1/getVolume`).respond(response); controller.onDataChange(); $httpBackend.flush(); expect($scope.model.data[0].volume.m3).toBe(0.008); expect($scope.model.data[1].volume.m3).toBe(0.003); - }); */ + }); + */ }); }); diff --git a/modules/ticket/front/weekly/index.html b/modules/ticket/front/weekly/index.html index e97d47eef..8411d4f72 100644 --- a/modules/ticket/front/weekly/index.html +++ b/modules/ticket/front/weekly/index.html @@ -32,23 +32,27 @@ - + - + {{weekly.ticketFk}} - + {{::weekly.clientName}} - + - + {{::weekly.warehouseName}} - + {{::weekly.nickName}} diff --git a/modules/ticket/front/weekly/index.js b/modules/ticket/front/weekly/index.js index a89dbbc2e..0c373eae3 100644 --- a/modules/ticket/front/weekly/index.js +++ b/modules/ticket/front/weekly/index.js @@ -19,36 +19,10 @@ export default class Controller extends Section { onUpdate(ticketFk, field, value) { const params = {ticketFk, [field]: value}; - this.$http.patch('TicketWeeklies', params).then(() => { - this.vnApp.showSuccess(this.$t('Data saved!')); - }); + this.$http.patch('TicketWeeklies', params) + .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); } - showClientDescriptor(event, clientFk) { - this.$.clientDescriptor.clientFk = clientFk; - this.$.clientDescriptor.parent = event.target; - this.$.clientDescriptor.show(); - this.stopEvent(event); - } - - showTicketDescriptor(event, ticketFk) { - this.$.ticketDescriptor.ticketFk = ticketFk; - this.$.ticketDescriptor.parent = event.target; - this.$.ticketDescriptor.show(); - this.stopEvent(event); - } - - showWorkerDescriptor(event, workerFk) { - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - this.stopEvent(event); - } - - deleteWeekly(event, ticketFk) { - this.$.deleteWeekly.show(ticketFk); - this.stopEvent(event); - } onDeleteWeeklyAccept(ticketFk) { return this.$http.delete(`TicketWeeklies/${ticketFk}`).then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); diff --git a/modules/travel/front/descriptor-popover/index.html b/modules/travel/front/descriptor-popover/index.html index fc0fb0301..376423bbc 100644 --- a/modules/travel/front/descriptor-popover/index.html +++ b/modules/travel/front/descriptor-popover/index.html @@ -1,12 +1,4 @@ - - - - + + - \ No newline at end of file + \ No newline at end of file diff --git a/modules/travel/front/descriptor-popover/index.js b/modules/travel/front/descriptor-popover/index.js index cb7e29bda..12c5908ca 100644 --- a/modules/travel/front/descriptor-popover/index.js +++ b/modules/travel/front/descriptor-popover/index.js @@ -1,84 +1,9 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.travel = null; - this._quicklinks = {}; - } +class Controller extends DescriptorPopover {} - set travelId(travelId) { - if (travelId == this._travelId) return; - - this._travelId = travelId; - this.travel = null; - this.loadData(); - } - - get travelId() { - return this._travelId; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - loadData() { - let query = `Travels/findOne`; - let filter = { - fields: [ - 'id', - 'ref', - 'shipped', - 'landed', - 'totalEntries', - 'warehouseInFk', - 'warehouseOutFk' - ], - where: { - id: this._travelId - }, - include: [ - { - relation: 'warehouseIn', - scope: { - fields: ['name'] - } - }, { - relation: 'warehouseOut', - scope: { - fields: ['name'] - } - } - ] - }; - - this.$http.get(query, {params: {filter}}).then(res => { - this.travel = res.data; - this.$.$applyAsync(() => { - this.$.popover.relocate(); - }); - }); - } -} - -ngModule.component('vnTravelDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - travelId: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnTravelDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/travel/front/descriptor-popover/index.spec.js b/modules/travel/front/descriptor-popover/index.spec.js deleted file mode 100644 index 0403c902a..000000000 --- a/modules/travel/front/descriptor-popover/index.spec.js +++ /dev/null @@ -1,100 +0,0 @@ -import './index.js'; - -describe('travel Component vnTravelDescriptorPopover', () => { - let $httpBackend; - let $httpParamSerializer; - let $scope; - let controller; - let $element; - - beforeEach(ngModule('travel')); - - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { - $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - $element = angular.element(`
`); - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - controller = $componentController('vnTravelDescriptorPopover', {$scope, $element}); - })); - - describe('travelId()', () => { - it(`should not apply any changes if the received id is the same stored in _travelId`, () => { - controller.travel = 'I exist!'; - controller._travelId = 1; - jest.spyOn(controller, 'loadData'); - controller.travelId = 1; - - expect(controller.travel).toEqual('I exist!'); - expect(controller._travelId).toEqual(1); - expect(controller.loadData).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _travelId, set the travel to null and then call loadData()`, () => { - controller.travel = `Please don't`; - controller._travelId = 1; - jest.spyOn(controller, 'loadData'); - controller.travelId = 999; - - expect(controller.travel).toBeNull(); - expect(controller._travelId).toEqual(999); - expect(controller.loadData).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('loadData()', () => { - it(`should perform a get query to store the worker data into the controller`, () => { - controller.travelId = 1; - controller.canceler = null; - let response = {}; - - let config = { - filter: { - fields: [ - 'id', - 'ref', - 'shipped', - 'landed', - 'totalEntries', - 'warehouseInFk', - 'warehouseOutFk' - ], - where: { - id: controller.travelId - }, - include: [ - { - relation: 'warehouseIn', - scope: { - fields: ['name'] - } - }, { - relation: 'warehouseOut', - scope: { - fields: ['name'] - } - } - ] - } - }; - - let json = $httpParamSerializer(config); - - $httpBackend.whenGET(`Travels/findOne?${json}`).respond(response); - $httpBackend.expectGET(`Travels/findOne?${json}`); - controller.loadData(); - $httpBackend.flush(); - - expect(controller.travel).toEqual(response); - }); - }); -}); diff --git a/modules/travel/front/descriptor/index.html b/modules/travel/front/descriptor/index.html index 3b932ef53..3e3ef5cdd 100644 --- a/modules/travel/front/descriptor/index.html +++ b/modules/travel/front/descriptor/index.html @@ -1,36 +1,28 @@ -
-
- - - - - - - -
-
+ +
- - - - - - - - -
-
-
+ + diff --git a/modules/travel/front/descriptor/index.js b/modules/travel/front/descriptor/index.js index 911cae010..6136d5347 100644 --- a/modules/travel/front/descriptor/index.js +++ b/modules/travel/front/descriptor/index.js @@ -1,13 +1,50 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -ngModule.component('vnTravelDescriptor', { +class Controller extends Descriptor { + get travel() { + return this.entity; + } + + set travel(value) { + this.entity = value; + } + + loadData() { + const filter = { + fields: [ + 'id', + 'ref', + 'shipped', + 'landed', + 'totalEntries', + 'warehouseInFk', + 'warehouseOutFk' + ], + include: [ + { + relation: 'warehouseIn', + scope: { + fields: ['name'] + } + }, { + relation: 'warehouseOut', + scope: { + fields: ['name'] + } + } + ] + }; + + return this.getData(`Travels/${this.id}`, {filter}) + .then(res => this.entity = res.data); + } +} + +ngModule.vnComponent('vnTravelDescriptor', { template: require('./index.html'), - controller: Component, + controller: Controller, bindings: { travel: '<' - }, - require: { - card: '^?vnTravelCard' - }, + } }); diff --git a/modules/travel/front/descriptor/index.spec.js b/modules/travel/front/descriptor/index.spec.js new file mode 100644 index 000000000..0a88c8607 --- /dev/null +++ b/modules/travel/front/descriptor/index.spec.js @@ -0,0 +1,26 @@ +import './index.js'; + +describe('vnTravelDescriptor', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('travel')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnTravelDescriptor', {$element: null}); + })); + + describe('loadData()', () => { + it(`should perform a get query to store the worker data into the controller`, () => { + const id = 1; + const response = 'foo'; + + $httpBackend.expectRoute('GET', `Travels/${id}`).respond(response); + controller.id = id; + $httpBackend.flush(); + + expect(controller.travel).toEqual(response); + }); + }); +}); diff --git a/modules/travel/front/index/index.html b/modules/travel/front/index/index.html index 1cb176d13..b1af5c8dd 100644 --- a/modules/travel/front/index/index.html +++ b/modules/travel/front/index/index.html @@ -37,12 +37,12 @@ @@ -70,5 +70,4 @@ on-accept="$ctrl.onCloneAccept($data)" question="Do you want to clone this travel?" message="All it's properties will be copied"> - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/travel/front/index/index.js b/modules/travel/front/index/index.js index 707f320cb..1115af2c3 100644 --- a/modules/travel/front/index/index.js +++ b/modules/travel/front/index/index.js @@ -2,17 +2,11 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - preview(event, travel) { - this.stopEvent(event); + preview(travel) { this.travelSelected = travel; this.$.summary.show(); } - cloneTravel(event, travel) { - this.stopEvent(event); - this.$.clone.show(travel); - } - onCloneAccept(travel) { const params = JSON.stringify({ ref: travel.ref, diff --git a/modules/travel/front/locale/es.yml b/modules/travel/front/locale/es.yml index 931f79ab8..06fc80601 100644 --- a/modules/travel/front/locale/es.yml +++ b/modules/travel/front/locale/es.yml @@ -13,6 +13,8 @@ Received: Recibido Travel id: Id envío Search travels by id: Buscar envíos por identificador New travel: Nuevo envío +travel: envio + # Sections Travels: Envíos Log: Historial diff --git a/modules/travel/front/summary/index.html b/modules/travel/front/summary/index.html index 5397c72ca..d921bb83d 100644 --- a/modules/travel/front/summary/index.html +++ b/modules/travel/front/summary/index.html @@ -2,10 +2,12 @@
{{$ctrl.travelData.id}} - {{$ctrl.travelData.ref}}
- - - - - - - - @@ -63,7 +71,7 @@ @@ -80,12 +88,14 @@ + icon="insert_drive_file" + class="bright"> + icon="insert_drive_file" + class="bright">
@@ -99,15 +109,15 @@ {{$ctrl.total('hb')}} {{$ctrl.total('freightValue') | currency: 'EUR': 2}} {{$ctrl.total('packageValue') | currency: 'EUR': 2}} - {{$ctrl.total('cc')}} - {{$ctrl.total('pallet')}} - {{$ctrl.total('m3')}} + {{$ctrl.total('cc') | number:2}} + {{$ctrl.total('pallet') | number:2}} + {{$ctrl.total('m3') | number:2}}
- +

Thermographs

@@ -131,10 +141,4 @@
- - - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/travel/front/summary/index.js b/modules/travel/front/summary/index.js index af940aa6c..1f2d14e58 100644 --- a/modules/travel/front/summary/index.js +++ b/modules/travel/front/summary/index.js @@ -22,35 +22,30 @@ class Controller extends Section { } getTravel() { - return this.$http.get(`/api/Travels/${this.travel.id}/getTravel`).then(response => { - this.travelData = response.data; - }); + return this.$http.get(`Travels/${this.travel.id}/getTravel`) + .then(res => this.travelData = res.data); } getEntries() { - return this.$http.get(`/api/Travels/${this.travel.id}/getEntries`).then(response => { - this.entries = response.data; - }); + return this.$http.get(`Travels/${this.travel.id}/getEntries`) + .then(res => this.entries = res.data); } getThermographs() { - const params = { - filter: { - include: { - relation: 'warehouse', - scope: { - fields: ['id', 'name'] - } - }, - where: { - travelFk: this.travel.id + const filter = { + include: { + relation: 'warehouse', + scope: { + fields: ['id', 'name'] } + }, + where: { + travelFk: this.travel.id } }; - return this.$http.get(`TravelThermographs`, {params}).then(res => { - this.travelThermographs = res.data; - }); + return this.$http.get(`TravelThermographs`, {filter}) + .then(res => this.travelThermographs = res.data); } total(field) { diff --git a/modules/travel/front/summary/index.spec.js b/modules/travel/front/summary/index.spec.js index 7f5c68aec..95f98bb85 100644 --- a/modules/travel/front/summary/index.spec.js +++ b/modules/travel/front/summary/index.spec.js @@ -36,7 +36,7 @@ describe('component vnTravelSummary', () => { it('should perform a get and then store data on the controller', () => { controller._travel = {id: 999}; - const query = `/api/Travels/${controller._travel.id}/getTravel`; + const query = `Travels/${controller._travel.id}/getTravel`; $httpBackend.expectGET(query).respond('I am the travelData'); controller.getTravel(); $httpBackend.flush(); @@ -49,7 +49,7 @@ describe('component vnTravelSummary', () => { it('should call the getEntries method to get the entries data', () => { controller._travel = {id: 999}; - const query = `/api/Travels/${controller._travel.id}/getEntries`; + const query = `Travels/${controller._travel.id}/getEntries`; $httpBackend.expectGET(query).respond('I am the entries'); controller.getEntries(); $httpBackend.flush(); @@ -61,22 +61,8 @@ describe('component vnTravelSummary', () => { describe('getThermographs()', () => { it('should call the getThermographs method to get the thermographs', () => { controller._travel = {id: 2}; - const params = { - filter: { - include: { - relation: 'warehouse', - scope: { - fields: ['id', 'name'] - } - }, - where: { - travelFk: controller._travel.id - } - } - }; - const serializedParams = $httpParamSerializer(params); - const query = `TravelThermographs?${serializedParams}`; - $httpBackend.expectGET(query).respond('I am the thermographs'); + + $httpBackend.expectGET(`TravelThermographs`).respond('I am the thermographs'); controller.getThermographs(); $httpBackend.flush(); diff --git a/modules/travel/front/summary/style.scss b/modules/travel/front/summary/style.scss index 922b36ad8..dd4cfa72d 100644 --- a/modules/travel/front/summary/style.scss +++ b/modules/travel/front/summary/style.scss @@ -3,8 +3,4 @@ vn-travel-summary .summary { max-width: $width-lg; - - vn-icon[icon=insert_drive_file]{ - color: $color-font-secondary; - } } \ No newline at end of file diff --git a/modules/worker/front/department/index.html b/modules/worker/front/department/index.html index 70932d55b..92102c7d3 100644 --- a/modules/worker/front/department/index.html +++ b/modules/worker/front/department/index.html @@ -27,17 +27,15 @@ + on-response="$ctrl.onCreateResponse($response)" + message="New department"> -
New department
- - - - + +
diff --git a/modules/worker/front/descriptor-popover/index.html b/modules/worker/front/descriptor-popover/index.html index 21f32f0c2..e98763d46 100644 --- a/modules/worker/front/descriptor-popover/index.html +++ b/modules/worker/front/descriptor-popover/index.html @@ -1,12 +1,4 @@ - - - - + + - \ No newline at end of file + \ No newline at end of file diff --git a/modules/worker/front/descriptor-popover/index.js b/modules/worker/front/descriptor-popover/index.js index 6463853f9..5c027635f 100644 --- a/modules/worker/front/descriptor-popover/index.js +++ b/modules/worker/front/descriptor-popover/index.js @@ -1,92 +1,9 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import DescriptorPopover from 'salix/components/descriptor-popover'; -class Controller extends Component { - constructor($element, $) { - super($element, $); - this.worker = null; - this._quicklinks = {}; - } +class Controller extends DescriptorPopover {} - set workerFk(workerFk) { - if (workerFk == this._workerFk) return; - - this._workerFk = workerFk; - this.worker = null; - this.loadData(); - } - - get workerFk() { - return this._workerFk; - } - - get quicklinks() { - return this._quicklinks; - } - - set quicklinks(value = {}) { - Object.keys(value).forEach(key => { - this._quicklinks[key] = value[key]; - }); - } - - show() { - this.$.popover.parent = this.parent; - this.$.popover.show(); - } - - loadData() { - let query = `Workers/findOne`; - let filter = { - where: { - id: this._workerFk - }, - include: [ - { - relation: 'user', - scope: { - fields: ['name'], - include: { - relation: 'emailUser', - scope: { - fields: ['email'] - } - } - } - }, - { - relation: 'client', - scope: {fields: ['fi']} - }, - { - relation: 'sip', - scope: {fields: ['extension']} - }, - { - relation: 'department', - scope: { - include: { - relation: 'department' - } - } - } - ] - }; - - this.$http.get(query, {params: {filter}}).then(res => { - this.worker = res.data; - this.$.$applyAsync(() => { - this.$.popover.relocate(); - }); - }); - } -} - -ngModule.component('vnWorkerDescriptorPopover', { - template: require('./index.html'), - controller: Controller, - bindings: { - workerFk: '<', - quicklinks: '<' - } +ngModule.vnComponent('vnWorkerDescriptorPopover', { + slotTemplate: require('./index.html'), + controller: Controller }); diff --git a/modules/worker/front/descriptor-popover/index.spec.js b/modules/worker/front/descriptor-popover/index.spec.js deleted file mode 100644 index 0b2746475..000000000 --- a/modules/worker/front/descriptor-popover/index.spec.js +++ /dev/null @@ -1,104 +0,0 @@ -import './index.js'; - -describe('worker Component vnWorkerDescriptorPopover', () => { - let $httpBackend; - let $httpParamSerializer; - let $scope; - let controller; - - beforeEach(ngModule('worker')); - - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => { - $httpBackend = _$httpBackend_; - $httpParamSerializer = _$httpParamSerializer_; - $scope = $rootScope.$new(); - $scope.popover = {relocate: () => {}, show: () => {}}; - const $element = angular.element(``); - controller = $componentController('vnWorkerDescriptorPopover', {$element, $scope}); - })); - - describe('workerFk()', () => { - it(`should not apply any changes if the received id is the same stored in _workerFk`, () => { - controller.worker = 'I exist!'; - controller._workerFk = 1; - jest.spyOn(controller, 'loadData'); - controller.workerFk = 1; - - expect(controller.worker).toEqual('I exist!'); - expect(controller._workerFk).toEqual(1); - expect(controller.loadData).not.toHaveBeenCalled(); - }); - - it(`should set the received id into _workerFk, set the worker to null and then call loadData()`, () => { - controller.worker = `Please don't`; - controller._workerFk = 1; - jest.spyOn(controller, 'loadData'); - controller.workerFk = 999; - - expect(controller.worker).toBeNull(); - expect(controller._workerFk).toEqual(999); - expect(controller.loadData).toHaveBeenCalledWith(); - }); - }); - - describe('show()', () => { - it(`should call the show()`, () => { - jest.spyOn(controller.$.popover, 'show'); - controller.show(); - - expect(controller.$.popover.show).toHaveBeenCalledWith(); - }); - }); - - describe('loadData()', () => { - it(`should perform a get query to store the worker data into the controller`, () => { - controller.workerFk = 1; - controller.canceler = null; - let response = {}; - - let config = { - filter: { - where: { - id: controller.workerFk - }, - include: [ - { - relation: 'user', - scope: { - fields: ['name'], - include: { - relation: 'emailUser', - scope: { - fields: ['email'] - } - } - } - }, { - relation: 'client', - scope: {fields: ['fi']} - }, { - relation: 'sip', - scope: {fields: ['extension']} - }, { - relation: 'department', - scope: { - include: { - relation: 'department' - } - } - } - ] - } - }; - - let json = $httpParamSerializer(config); - - $httpBackend.whenGET(`Workers/findOne?${json}`).respond(response); - $httpBackend.expectGET(`Workers/findOne?${json}`); - controller.loadData(); - $httpBackend.flush(); - - expect(controller.worker).toEqual(response); - }); - }); -}); diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index d26892bfd..e75d14322 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -1,40 +1,39 @@ -
- - - - - - - - - -
+ +
-
- {{$ctrl.worker.firstName}} {{$ctrl.worker.lastName}} -
- + - - - - - -
- - -
-
\ No newline at end of file + + + \ No newline at end of file diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index 82cfd0886..98f8f2f72 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -1,35 +1,56 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { +class Controller extends Descriptor { get worker() { - return this._worker; + return this.entity; } set worker(value) { - this._worker = value; + this.entity = value; + } - if (!value) return; - - this._quicklinks = { - btnOne: { - icon: 'person', - state: `client.card.summary({id: ${value.userFk}})`, - tooltip: 'Go to client' - } + loadData() { + const filter = { + include: [ + { + relation: 'user', + scope: { + fields: ['name'], + include: { + relation: 'emailUser', + scope: { + fields: ['email'] + } + } + } + }, { + relation: 'client', + scope: { + fields: ['fi'] + } + }, { + relation: 'sip', + scope: { + fields: ['extension'] + } + }, { + relation: 'department', + scope: { + include: { + relation: 'department' + } + } + } + ] }; - } - set quicklinks(value = {}) { - this._quicklinks = Object.assign(value, this._quicklinks); - } - - get quicklinks() { - return this._quicklinks; + return this.getData(`Workers/${this.id}`, {filter}) + .then(res => this.entity = res.data); } } -ngModule.component('vnWorkerDescriptor', { +ngModule.vnComponent('vnWorkerDescriptor', { template: require('./index.html'), controller: Controller, bindings: { diff --git a/modules/worker/front/descriptor/index.spec.js b/modules/worker/front/descriptor/index.spec.js new file mode 100644 index 000000000..dfb800415 --- /dev/null +++ b/modules/worker/front/descriptor/index.spec.js @@ -0,0 +1,26 @@ +import './index.js'; + +describe('vnWorkerDescriptor', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('worker')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnWorkerDescriptor', {$element: null}); + })); + + describe('loadData()', () => { + it(`should perform a get query to store the worker data into the controller`, () => { + const id = 1; + const response = 'foo'; + + $httpBackend.expectRoute('GET', `Workers/${id}`).respond(response); + controller.id = id; + $httpBackend.flush(); + + expect(controller.worker).toEqual(response); + }); + }); +}); diff --git a/modules/worker/front/dms/create/index.js b/modules/worker/front/dms/create/index.js index 388b9a333..79d7c5fdd 100644 --- a/modules/worker/front/dms/create/index.js +++ b/modules/worker/front/dms/create/index.js @@ -102,7 +102,7 @@ class Controller extends Section { } } -Controller.$inject = ['$element', '$scope', 'vnConfig']; +Controller.$inject = ['$element', '$scope']; ngModule.component('vnWorkerDmsCreate', { template: require('./index.html'), diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 1bf1af61e..e1cc1c90f 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -56,7 +56,7 @@ - @@ -64,7 +64,7 @@ @@ -74,10 +74,7 @@ - - - @@ -87,5 +84,5 @@ vn-id="confirm" message="This file will be deleted" question="Are you sure you want to continue?" - on-response="$ctrl.deleteDms($response)"> + on-accept="$ctrl.deleteDms($data)"> \ No newline at end of file diff --git a/modules/worker/front/dms/index/index.js b/modules/worker/front/dms/index/index.js index d322145a0..a950c1a42 100644 --- a/modules/worker/front/dms/index/index.js +++ b/modules/worker/front/dms/index/index.js @@ -19,51 +19,37 @@ class Controller extends Component { 'file', 'created', ], - include: [{ - relation: 'dmsType', - scope: { - fields: ['name'] + include: [ + { + relation: 'dmsType', + scope: { + fields: ['name'] + } + }, { + relation: 'worker', + scope: { + fields: ['userFk'], + include: { + relation: 'user', + scope: { + fields: ['nickname'] + } + }, + } } - }, - { - relation: 'worker', - scope: { - fields: ['userFk'], - include: { - relation: 'user', - scope: { - fields: ['nickname'] - } - }, - } - }] + ] }, } }; } - showWorkerDescriptor(event, workerFk) { - event.preventDefault(); - event.stopImmediatePropagation(); - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.workerFk = workerFk; - this.$.workerDescriptor.show(); - } - - showDeleteConfirm(index) { - this.dmsIndex = index; - this.$.confirm.show(); - } - - deleteDms(response) { - if (response === 'accept') { - const workerDmsId = this.workerDms[this.dmsIndex].id; - const query = `WorkerDms/${workerDmsId}/removeFile`; - this.$http.post(query).then(() => { - this.$.model.remove(this.dmsIndex); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + deleteDms(index) { + const workerDmsId = this.workerDms[index].dmsFk; + return this.$http.post(`WorkerDms/${workerDmsId}/removeFile`) + .then(() => { + this.$.model.remove(index); + this.vnApp.showSuccess(this.$t('Data saved!')); }); - } } } diff --git a/modules/worker/front/dms/index/index.spec.js b/modules/worker/front/dms/index/index.spec.js index 074f11524..9c1e87011 100644 --- a/modules/worker/front/dms/index/index.spec.js +++ b/modules/worker/front/dms/index/index.spec.js @@ -4,36 +4,33 @@ import crudModel from 'core/mocks/crud-model'; describe('Worker', () => { describe('Component vnWorkerDmsIndex', () => { let $scope; - let $element; let $httpBackend; let controller; beforeEach(ngModule('worker')); - beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => { + beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $element = angular.element(` { it('should make an HTTP Post query', () => { - const workerDmsId = 1; - const dmsIndex = 0; jest.spyOn(controller.vnApp, 'showSuccess'); jest.spyOn(controller.$.model, 'remove'); - controller.workerDms = [{id: 1, dmsFk: 4}]; - controller.dmsIndex = dmsIndex; - $httpBackend.when('POST', `WorkerDms/${workerDmsId}/removeFile`).respond({}); - $httpBackend.expect('POST', `WorkerDms/${workerDmsId}/removeFile`); - controller.deleteDms('accept'); + const workerDmsId = 4; + const dmsIndex = 0; + controller.workerDms = [{id: 1, dmsFk: 4}]; + + $httpBackend.expectPOST(`WorkerDms/${workerDmsId}/removeFile`).respond(); + controller.deleteDms(dmsIndex); $httpBackend.flush(); expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); }); diff --git a/modules/worker/front/locale/es.yml b/modules/worker/front/locale/es.yml index c3a493369..99cad90e4 100644 --- a/modules/worker/front/locale/es.yml +++ b/modules/worker/front/locale/es.yml @@ -18,3 +18,4 @@ User id: Id de usuario View worker: Ver trabajador Worker id: Id trabajador Workers: Trabajadores +worker: trabajador \ No newline at end of file diff --git a/modules/worker/front/log/index.html b/modules/worker/front/log/index.html index 8aa693924..7b2ffa445 100644 --- a/modules/worker/front/log/index.html +++ b/modules/worker/front/log/index.html @@ -32,7 +32,7 @@ Changed by: {{::log.user.name | dashIfEmpty}}
@@ -53,7 +53,7 @@ {{::log.user.name | dashIfEmpty}} @@ -99,6 +99,5 @@
+ vn-id="workerDescriptor"> diff --git a/modules/worker/front/log/index.js b/modules/worker/front/log/index.js index 5e42687d3..421ffec63 100644 --- a/modules/worker/front/log/index.js +++ b/modules/worker/front/log/index.js @@ -42,18 +42,6 @@ export default class Controller extends Section { } } - showWorkerDescriptor(event, workerFk) { - if (event.defaultPrevented) return; - if (!workerFk) return; - - event.preventDefault(); - event.stopPropagation(); - - this.selectedWorker = workerFk; - this.$.workerDescriptor.parent = event.target; - this.$.workerDescriptor.show(); - } - getInstance(instance) { const properties = []; let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/; diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index 10691d301..d2c91bf94 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -92,19 +92,15 @@
+ on-response="$ctrl.addTime($response)" + message="Add time"> -
-
- Add time -
- - -
+ +
diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 59ed5c944..5f83eb05e 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -27,15 +27,18 @@ fields="['code','townFk']" order="code, townFk" value-field="geoFk" - show-field="code" - > + show-field="code"> - {{code}} - {{town.name}} ({{town.province.name}}, - {{town.province.country.country}}) +
+ {{code}} {{town.name}} +
+
+ {{town.province.name}}, {{town.province.country.country}} +
diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index cf7ef14da..eb6d7795d 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -61,8 +61,7 @@ class Controller extends Section { }); } - preview(event, zone) { - this.stopEvent(event); + preview(zone) { this.selectedZone = zone; this.$.summary.show(); } diff --git a/modules/zone/front/descriptor/index.html b/modules/zone/front/descriptor/index.html index 8f6dd819b..e1fa1c0ea 100644 --- a/modules/zone/front/descriptor/index.html +++ b/modules/zone/front/descriptor/index.html @@ -1,53 +1,45 @@ -
- - - - - - - - - - -
+ + + + Delete + + +
- - - - - - - - - -
-
-
+ + - \ No newline at end of file + diff --git a/modules/zone/front/descriptor/index.js b/modules/zone/front/descriptor/index.js index b3808f256..a68a450ea 100644 --- a/modules/zone/front/descriptor/index.js +++ b/modules/zone/front/descriptor/index.js @@ -1,31 +1,22 @@ import ngModule from '../module'; -import Component from 'core/lib/component'; +import Descriptor from 'salix/components/descriptor'; -class Controller extends Component { - $onInit() { - this.moreOptions = [ - {callback: this.deleteZone, name: 'Delete'} - ]; +class Controller extends Descriptor { + get zone() { + return this.entity; } - onMoreChange(callback) { - callback.call(this); + set zone(value) { + this.entity = value; } - deleteZone() { - this.$.deleteZone.show(); - } - - returnDialog(response) { - if (response === 'accept') { - this.$http.delete(`Zones/${this.zone.id}`).then(() => { - this.$state.go('zone.index'); - }); - } + onDeleteAccept() { + return this.$http.delete(`Zones/${this.id}`) + .then(() => this.$state.go('zone.index')); } } -ngModule.component('vnZoneDescriptor', { +ngModule.vnComponent('vnZoneDescriptor', { template: require('./index.html'), controller: Controller, bindings: { diff --git a/modules/zone/front/events/index.html b/modules/zone/front/events/index.html index 0df58287f..eea24a132 100644 --- a/modules/zone/front/events/index.html +++ b/modules/zone/front/events/index.html @@ -49,14 +49,11 @@
- - {{::row.started | date:'dd/MM/yy'}} - {{::row.ended | date:'dd/MM/yy'}} - - - Indefinitely - - ({{::$ctrl.formatWdays(row.weekDays)}}) + {{::$ctrl.formatWdays(row.weekDays)}} + + + ({{::row.started | date:'dd/MM/yy'}} - {{::row.ended | date:'dd/MM/yy'}})
+ + + on-response="$ctrl.onIncludeResponse($response)" + message="{{$ctrl.isNew ? 'Add event' : 'Edit event'}}"> diff --git a/modules/zone/front/events/index.js b/modules/zone/front/events/index.js index bea352d06..d965d1892 100644 --- a/modules/zone/front/events/index.js +++ b/modules/zone/front/events/index.js @@ -41,7 +41,7 @@ class Controller extends Section { if (events.length) this.edit(events[0]); else - this.create(days, type, weekday); + this.create(type, days, weekday); } else { if (exclusions.length) this.exclusionDelete(exclusions); @@ -62,12 +62,12 @@ class Controller extends Section { this.$.dialog.show(); } - create(days, type, weekday) { + create(type, days, weekday) { this.isNew = true; if (type == 'weekday') { let wdays = []; - wdays[weekday] = true; + if (weekday) wdays[weekday] = true; this.selected = { type: 'indefinitely', diff --git a/modules/zone/front/events/locale/es.yml b/modules/zone/front/events/locale/es.yml index eb0894c63..eb581a719 100644 --- a/modules/zone/front/events/locale/es.yml +++ b/modules/zone/front/events/locale/es.yml @@ -1,4 +1,6 @@ Edit mode: Modo de edición Include: Incluir Exclude: Excluir -Events: Eventos \ No newline at end of file +Events: Eventos +Add event: Añadir evento +Edit event: Editar evento diff --git a/modules/zone/front/index/index.html b/modules/zone/front/index/index.html index f26dd1e54..55760d770 100644 --- a/modules/zone/front/index/index.html +++ b/modules/zone/front/index/index.html @@ -29,14 +29,14 @@ @@ -66,4 +66,3 @@ vn-acl-action="remove"> - \ No newline at end of file diff --git a/modules/zone/front/index/index.js b/modules/zone/front/index/index.js index 9750a949f..b39c6139a 100644 --- a/modules/zone/front/index/index.js +++ b/modules/zone/front/index/index.js @@ -2,17 +2,11 @@ import ngModule from '../module'; import Section from 'salix/components/section'; export default class Controller extends Section { - preview(event, zone) { - this.stopEvent(event); + preview(zone) { this.selectedZone = zone; this.$.summary.show(); } - clone(event, zone) { - this.stopEvent(event); - this.$.clone.show(zone); - } - onCloneAccept(zone) { return this.$http.post(`Zones/${zone.id}/clone`) .then(res => { diff --git a/modules/zone/front/locale/es.yml b/modules/zone/front/locale/es.yml index afe63bafc..29f984287 100644 --- a/modules/zone/front/locale/es.yml +++ b/modules/zone/front/locale/es.yml @@ -29,4 +29,5 @@ Volumetric: Volumétrico Warehouse: Almacén Warehouses: Almacenes Week days: Días de la semana -Zones: Zonas \ No newline at end of file +Zones: Zonas +zone: zona \ No newline at end of file diff --git a/modules/zone/front/warehouses/index.html b/modules/zone/front/warehouses/index.html index 72d88fa0a..835880c75 100644 --- a/modules/zone/front/warehouses/index.html +++ b/modules/zone/front/warehouses/index.html @@ -30,15 +30,13 @@ vn-id="dialog" on-response="$ctrl.onSave($response)"> - - - - + + diff --git a/package-lock.json b/package-lock.json index 6affdde84..b46d40dcc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17888,7 +17888,7 @@ }, "xmlbuilder": { "version": "9.0.7", - "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", + "resolved": "http://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz", "integrity": "sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0=" }, "xmlcreate": {