|
393 | 393 | }); |
394 | 394 |
|
395 | 395 | var WidgetsTable = countlyVue.views.create({ |
| 396 | + mixins: [ |
| 397 | + countlyVue.mixins.auth(FEATURE_NAME), |
| 398 | + countlyVue.mixins.commonFormatters |
| 399 | + ], |
| 400 | + |
396 | 401 | props: { |
397 | 402 | rows: { |
398 | | - type: Array, |
399 | | - default: [] |
| 403 | + default: [], |
| 404 | + type: Array |
400 | 405 | } |
401 | 406 | }, |
402 | 407 |
|
403 | | - mixins: [ |
404 | | - countlyVue.mixins.auth(FEATURE_NAME), |
405 | | - countlyVue.mixins.commonFormatters |
406 | | - ], |
| 408 | + emits: ['widgets-updated'], |
407 | 409 |
|
408 | | - data: function() { |
| 410 | + data() { |
409 | 411 | return { |
410 | 412 | cohortsEnabled: countlyGlobal.plugins.indexOf('cohorts') > -1, |
411 | 413 |
|
|
417 | 419 | }; |
418 | 420 | }, |
419 | 421 |
|
420 | | - emits: [ |
421 | | - 'widgets-updated' |
422 | | - ], |
423 | | - |
424 | 422 | computed: { |
425 | 423 | tableDynamicCols() { |
426 | 424 | const columns = [ |
427 | 425 | { |
428 | | - value: 'rating_score', |
429 | | - label: CV.i18n('feedback.rating-score'), |
430 | 426 | default: true, |
431 | | - required: true |
| 427 | + label: CV.i18n('feedback.rating-score'), |
| 428 | + required: true, |
| 429 | + value: 'rating_score' |
432 | 430 | }, |
433 | 431 | { |
434 | | - value: 'responses', |
435 | | - label: CV.i18n('feedback.responses'), |
436 | 432 | default: true, |
437 | | - required: true |
| 433 | + label: CV.i18n('feedback.responses'), |
| 434 | + required: true, |
| 435 | + value: 'responses' |
438 | 436 | }, |
439 | 437 | { |
440 | | - value: "target_pages", |
441 | | - label: CV.i18n("feedback.pages"), |
442 | 438 | default: true, |
443 | | - required: true |
| 439 | + label: CV.i18n("feedback.pages"), |
| 440 | + required: true, |
| 441 | + value: 'target_pages' |
444 | 442 | } |
445 | 443 | ]; |
446 | 444 |
|
447 | 445 | if (this.cohortsEnabled) { |
448 | 446 | columns.unshift({ |
449 | | - value: 'targeting', |
450 | | - label: CV.i18n('feedback.targeting'), |
451 | 447 | default: true, |
452 | | - required: true |
| 448 | + label: CV.i18n('feedback.targeting'), |
| 449 | + required: true, |
| 450 | + value: 'targeting' |
453 | 451 | }); |
454 | 452 | } |
455 | 453 |
|
456 | 454 | return columns; |
457 | 455 | }, |
458 | | - widgets: function() { |
459 | | - for (var i = 0; i < this.rows.length; i++) { |
460 | | - var ratingScore = 0; |
461 | | - if (this.rows[i].ratingsCount > 0) { |
462 | | - ratingScore = (this.rows[i].ratingsSum / this.rows[i].ratingsCount).toFixed(1); |
463 | | - } |
464 | | - this.rows[i].ratingScore = ratingScore; |
465 | | - this.rows[i].popup_header_text = replaceEscapes(this.rows[i].popup_header_text); |
466 | | - if (this.cohortsEnabled) { |
467 | | - this.rows[i] = this.parseTargeting(this.rows[i]); |
468 | | - } |
469 | | - this.rows[i].target_pages = this.rows[i].target_pages && this.rows[i].target_pages.length > 0 ? this.rows[i].target_pages.join(", ") : "-"; |
470 | | - } |
471 | | - return this.rows; |
| 456 | + |
| 457 | + widgets() { |
| 458 | + return JSON.parse(JSON.stringify(this.rows)) |
| 459 | + .map((widget) => { |
| 460 | + const { |
| 461 | + popup_header_text: popupHeaderText, |
| 462 | + ratingsCount, |
| 463 | + ratingsSum, |
| 464 | + target_pages: targetPages, |
| 465 | + targeting |
| 466 | + } = widget || {}; |
| 467 | + let ratingScore = 0; |
| 468 | + |
| 469 | + if (ratingsCount > 0) { |
| 470 | + ratingScore = (ratingsSum / ratingsCount).toFixed(1); |
| 471 | + } |
| 472 | + |
| 473 | + return { |
| 474 | + ...widget, |
| 475 | + popup_header_text: replaceEscapes(popupHeaderText), |
| 476 | + ratingScore, |
| 477 | + target_pages: Array.isArray(targetPages) && !!targetPages.length ? |
| 478 | + targetPages.join(', ') : |
| 479 | + '-', |
| 480 | + ...this.cohortsEnabled && { targeting: this.parseTargeting(targeting) } |
| 481 | + }; |
| 482 | + }); |
472 | 483 | } |
473 | 484 | }, |
474 | 485 |
|
|
506 | 517 | } |
507 | 518 | }, |
508 | 519 |
|
509 | | - formatExportFunction: function() { |
510 | | - var tableData = this.widgets; |
511 | | - var table = []; |
512 | | - for (var i = 0; i < tableData.length; i++) { |
513 | | - var item = {}; |
514 | | - |
515 | | - item[CV.i18n('feedback.status').toUpperCase()] = tableData[i].status ? "Active" : "Inactive"; |
516 | | - item[CV.i18n('feedback.ratings-widget-name').toUpperCase()] = tableData[i].popup_header_text; |
517 | | - item[CV.i18n('feedback.widget-id').toUpperCase()] = tableData[i]._id; |
518 | | - item[CV.i18n('feedback.targeting').toUpperCase()] = this.parseTargetingForExport(tableData[i].targeting).trim(); |
519 | | - item[CV.i18n('feedback.rating-score').toUpperCase()] = tableData[i].ratingScore; |
520 | | - item[CV.i18n('feedback.responses').toUpperCase()] = tableData[i].ratingsCount; |
521 | | - item[CV.i18n('feedback.pages').toUpperCase()] = tableData[i].target_pages; |
| 520 | + formatExportFunction() { |
| 521 | + const table = []; |
| 522 | + |
| 523 | + for (let i = 0; i < this.widgets.length; i++) { |
| 524 | + const item = {}; |
| 525 | + const { |
| 526 | + _id, |
| 527 | + popup_header_text: popupHeaderText, |
| 528 | + ratingScore, |
| 529 | + ratingsCount, |
| 530 | + status, |
| 531 | + target_pages: targetPages, |
| 532 | + targeting |
| 533 | + } = this.widgets[i] || {}; |
| 534 | + |
| 535 | + item[CV.i18n('feedback.status').toUpperCase()] = status ? "Active" : "Inactive"; |
| 536 | + item[CV.i18n('feedback.ratings-widget-name').toUpperCase()] = popupHeaderText; |
| 537 | + item[CV.i18n('feedback.widget-id').toUpperCase()] = _id; |
| 538 | + item[CV.i18n('feedback.targeting').toUpperCase()] = this.parseTargetingForExport(targeting).trim(); |
| 539 | + item[CV.i18n('feedback.rating-score').toUpperCase()] = ratingScore; |
| 540 | + item[CV.i18n('feedback.responses').toUpperCase()] = ratingsCount; |
| 541 | + item[CV.i18n('feedback.pages').toUpperCase()] = targetPages; |
522 | 542 |
|
523 | 543 | table.push(item); |
524 | 544 | } |
525 | | - return table; |
526 | 545 |
|
| 546 | + return table; |
527 | 547 | }, |
528 | 548 |
|
529 | | - goWidgetDetail: function(row) { |
530 | | - window.location.hash = "#/" + countlyCommon.ACTIVE_APP_ID + "/feedback/ratings/widgets/" + row._id; |
| 549 | + goWidgetDetail(row) { |
| 550 | + window.location.hash = `#/${countlyCommon.ACTIVE_APP_ID}/feedback/ratings/widgets/${row._id}`; |
531 | 551 | }, |
532 | 552 |
|
533 | | - parseTargeting: function(widget) { |
534 | | - if (widget.targeting) { |
| 553 | + parseTargeting(unparsedTargeting) { |
| 554 | + let targeting = JSON.parse(JSON.stringify(unparsedTargeting || null)); |
| 555 | + |
| 556 | + if (targeting) { |
| 557 | + const { steps = null, user_segmentation: userSegmentation = null } = targeting || {}; |
535 | 558 | try { |
536 | | - if (typeof widget.targeting.user_segmentation === "string") { |
537 | | - widget.targeting.user_segmentation = JSON.parse(widget.targeting.user_segmentation); |
| 559 | + if (typeof userSegmentation === 'string') { |
| 560 | + targeting.user_segmentation = JSON.parse(userSegmentation); |
538 | 561 | } |
539 | 562 | } |
540 | 563 | catch (e) { |
541 | | - widget.targeting.user_segmentation = {}; |
| 564 | + targeting.user_segmentation = {}; |
542 | 565 | } |
543 | 566 |
|
544 | 567 | try { |
545 | | - if (typeof widget.targeting.steps === "string") { |
546 | | - widget.targeting.steps = JSON.parse(widget.targeting.steps); |
| 568 | + if (typeof steps === 'string') { |
| 569 | + targeting.steps = JSON.parse(steps); |
547 | 570 | } |
548 | 571 | } |
549 | 572 | catch (e) { |
550 | | - widget.targeting.steps = []; |
| 573 | + targeting.steps = []; |
551 | 574 | } |
552 | | - |
553 | | - widget.targeting.user_segmentation = widget.targeting.user_segmentation || {}; |
554 | | - widget.targeting.steps = widget.targeting.steps || []; |
555 | 575 | } |
556 | | - return widget; |
| 576 | + |
| 577 | + return targeting; |
557 | 578 | }, |
558 | 579 |
|
559 | | - parseTargetingForExport: function(widget) { |
560 | | - var targeting = countlyCohorts.getSegmentationDescription(widget); |
561 | | - var html = targeting.behavior; |
562 | | - var div = document.createElement('div'); |
| 580 | + parseTargetingForExport(targeting) { |
| 581 | + const segmentationDescription = countlyCohorts.getSegmentationDescription(targeting); |
| 582 | + const html = segmentationDescription.behavior; |
| 583 | + const div = document.createElement('div'); |
| 584 | + |
563 | 585 | div.innerHTML = html; |
| 586 | + |
564 | 587 | return div.textContent || div.innerText || ""; |
565 | 588 | } |
566 | 589 | }, |
|
0 commit comments