Events on elements now are emitted after component linking

This commit is contained in:
Juan 2018-10-22 13:29:52 +02:00
parent a190100cae
commit 0034991251
7 changed files with 19 additions and 20 deletions

View File

@ -31,6 +31,7 @@ export default class Autocomplete extends Input {
} }
$postLink() { $postLink() {
super.$postLink();
this.assignDropdownProps(); this.assignDropdownProps();
this.showField = this.$.dropDown.showField; this.showField = this.$.dropDown.showField;
this.valueField = this.$.dropDown.valueField; this.valueField = this.$.dropDown.valueField;

View File

@ -30,6 +30,7 @@ export default class DropDown extends Component {
} }
$postLink() { $postLink() {
super.$postLink();
this.input = this.element.querySelector('.search input'); this.input = this.element.querySelector('.search input');
this.ul = this.element.querySelector('ul'); this.ul = this.element.querySelector('ul');
this.list = this.element.querySelector('.list'); this.list = this.element.querySelector('.list');

View File

@ -19,6 +19,7 @@ export default class Popover extends Component {
} }
$postLink() { $postLink() {
super.$postLink();
this.$element.addClass('vn-popover'); this.$element.addClass('vn-popover');
this.docKeyDownHandler = e => this.onDocKeyDown(e); this.docKeyDownHandler = e => this.onDocKeyDown(e);

View File

@ -4,9 +4,10 @@ import {kebabToCamel} from './string';
* Implemented by all those classes that emit events. * Implemented by all those classes that emit events.
*/ */
export default class EventEmitter { export default class EventEmitter {
constructor($element, $scope) { $postLink() {
if (!$element) return; if (!this.$element) return;
let attrs = $element[0].attributes; let attrs = this.$element[0].attributes;
let $scope = this.$;
for (let attr of attrs) { for (let attr of attrs) {
if (attr.name.substr(0, 2) !== 'on') continue; if (attr.name.substr(0, 2) !== 'on') continue;
let eventName = kebabToCamel(attr.name.substr(3)); let eventName = kebabToCamel(attr.name.substr(3));

View File

@ -48,7 +48,7 @@
icon="warning"> icon="warning">
</vn-icon> </vn-icon>
</vn-td> </vn-td>
<vn-td number>{{::ticket.ticketFk}}</vn-td> <vn-td number>{{::ticket.id}}</vn-td>
<vn-td>{{::ticket.salesPerson | dashIfEmpty}}</vn-td> <vn-td>{{::ticket.salesPerson | dashIfEmpty}}</vn-td>
<vn-td>{{::ticket.shipped | dateTime: 'dd/MM/yyyy'}}</vn-td> <vn-td>{{::ticket.shipped | dateTime: 'dd/MM/yyyy'}}</vn-td>
<vn-td>{{::ticket.shipped | dateTime: 'HH:mm'}}</vn-td> <vn-td>{{::ticket.shipped | dateTime: 'HH:mm'}}</vn-td>

View File

@ -31,10 +31,9 @@ module.exports = Self => {
stmt = new ParameterizedSQL( stmt = new ParameterizedSQL(
`CREATE TEMPORARY TABLE tmp.filter `CREATE TEMPORARY TABLE tmp.filter
(PRIMARY KEY (ticketFk)) ENGINE = MEMORY (INDEX (id)) ENGINE = MEMORY
SELECT SELECT
t.id, t.id,
t.id AS ticketFk,
t.shipped, t.shipped,
t.nickname, t.nickname,
t.refFk, t.refFk,
@ -49,8 +48,7 @@ module.exports = Self => {
w.name AS warehouse, w.name AS warehouse,
am.name AS agencyMode, am.name AS agencyMode,
st.name AS state, st.name AS state,
wk.name AS salesPerson, wk.name AS salesPerson
CAST(0 AS DECIMAL(10, 2)) AS total
FROM ticket t FROM ticket t
LEFT JOIN address a ON a.id = t.addressFk LEFT JOIN address a ON a.id = t.addressFk
LEFT JOIN province p ON p.id = a.provinceFk LEFT JOIN province p ON p.id = a.provinceFk
@ -66,29 +64,26 @@ module.exports = Self => {
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticket'); stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticket');
stmts.push(` stmts.push(`
CREATE TEMPORARY TABLE tmp.ticket CREATE TEMPORARY TABLE tmp.ticket
(PRIMARY KEY (ticketFk)) ENGINE = MEMORY (INDEX (ticketFk)) ENGINE = MEMORY
SELECT ticketFk FROM tmp.filter`); SELECT id ticketFk FROM tmp.filter`);
stmts.push('CALL ticketGetTotal()'); stmts.push('CALL ticketGetTotal()');
stmts.push(`
UPDATE tmp.filter f
JOIN tmp.ticketTotal tt ON f.ticketFk = tt.ticketFk
SET f.total = tt.total`);
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems'); stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems');
stmts.push(` stmts.push(`
CREATE TEMPORARY TABLE tmp.ticketGetProblems CREATE TEMPORARY TABLE tmp.ticketGetProblems
(PRIMARY KEY (ticketFk)) ENGINE = MEMORY (INDEX (ticketFk)) ENGINE = MEMORY
SELECT ticketFk, clientFk, warehouseFk, shipped SELECT id ticketFk, clientFk, warehouseFk, shipped
FROM tmp.filter`); FROM tmp.filter`);
stmts.push('CALL ticketGetProblems()'); stmts.push('CALL ticketGetProblems()');
stmt = new ParameterizedSQL(` stmt = new ParameterizedSQL(`
SELECT SELECT
f.*, f.*,
tt.total,
tp.problem tp.problem
FROM tmp.filter f FROM tmp.filter f
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.ticketFk`); LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.id
LEFT JOIN tmp.ticketTotal tt ON tt.ticketFk = f.id`);
stmt.merge(Self.buildOrderBy(filter)); stmt.merge(Self.buildOrderBy(filter));
let ticketsIndex = stmts.push(stmt) - 1; let ticketsIndex = stmts.push(stmt) - 1;

View File

@ -4,7 +4,7 @@ describe('ticket filter()', () => {
it('should call the filter method', async() => { it('should call the filter method', async() => {
let filter = {order: 'shipped DESC'}; let filter = {order: 'shipped DESC'};
let result = await app.models.Ticket.filter(filter); let result = await app.models.Ticket.filter(filter);
let ticketId = result[0].ticketFk; let ticketId = result[0].id;
expect(ticketId).toEqual(15); expect(ticketId).toEqual(15);
}); });