All files / web/bundles/pimui/js/job/execution summary-table.js

100% Statements 19/19
100% Branches 2/2
100% Functions 7/7
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94                383x                 383x                     1x 1x 1x 1x     1x             643x   643x             605x   605x             1952x 1952x   9760x                   1952x                     1749x 1749x 904x     1749x          
'use strict';
/**
 * Displays the summary table for a job execution
 *
 * @author    Alban Alnot <alban.alnot@consertotech.pro>
 * @copyright 2017 Akeneo SAS (http://www.akeneo.com)
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
define(
    [
        'jquery',
        'underscore',
        'oro/translator',
        'pim/form',
        'pim/template/job-execution/summary-table'
    ],
    function ($, _, __, BaseForm, template) {
        return BaseForm.extend({
            template: _.template(template),
            events: {
                'click .data': 'toggleDisplayWarning'
            },
 
            /**
             * Display or hide a warning details
             * @param event
             */
            toggleDisplayWarning: function (event) {
                var stepIndex = event.currentTarget.dataset.stepIndex;
                var warningIndex = event.currentTarget.dataset.warningIndex;
                var model = this.getFormData();
                model.stepExecutions[stepIndex].warnings[warningIndex].expanded =
                    !model.stepExecutions[stepIndex].warnings[warningIndex].expanded;
 
                this.render();
            },
 
            /**
             * {@inheritdoc}
             */
            initialize: function (config) {
                this.config = config.config;
 
                BaseForm.prototype.initialize.apply(this, arguments);
            },
 
            /**
             * {@inheritdoc}
             */
            configure: function () {
                this.listenTo(this.getRoot(), 'pim_enrich:form:entity:post_update', this.render);
 
                return BaseForm.prototype.configure.apply(this, arguments);
            },
 
            /**
             * {@inheritdoc}
             */
            render: function () {
                var model = this.getFormData();
                this.$el.html(this.template({
                    transAndUpperCase: function (str) {
                        return __(str).toUpperCase();
                    },
                    __: __,
                    stepExecutions: model.stepExecutions,
                    status: model.status,
                    failures: model.failures,
                    id: model.meta.id,
                    translateStepExecutionLabel: this.translateStepExecutionLabel
                }));
 
                return this;
            },
 
            /**
             * Get the translation of a stepExecution.
             * If the translation exists for this specific job, returns it, else returns the default one.
             *
             * @param stepExecution
             * @returns {string}
             */
            translateStepExecutionLabel: function(stepExecution) {
                let key = 'batch_jobs.' + stepExecution.job + '.' + stepExecution.label + '.label';
                if (__(key) === key) {
                    key = 'batch_jobs.default_steps.' + stepExecution.label;
                }
 
                return __(key);
            }
        });
    }
);