All files / web/bundles/akeneopimenrichment/js completeness-widget.js

100% Statements 14/14
83.33% Branches 5/6
100% Functions 4/4
100% Lines 14/14

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 381110x         1110x         1125x 1125x 2511x 2511x 2511x   2511x       2511x 4893x 4893x       4893x     2511x     1125x          
define(
    ['jquery', 'underscore', 'pim/dashboard/abstract-widget', 'pim/dashboard/template/completeness-widget'],
    function ($, _, AbstractWidget, template) {
        'use strict';
 
        return AbstractWidget.extend({
            id: 'completeness-widget',
            template: _.template(template),
 
            _processResponse: function (data) {
                var channelArray = [];
                _.each(data, function (channel, channelLabel) {
                    channel.name = channelLabel;
                    channel.locales = channel.locales || {};
                    var divider = channel.total * _.keys(channel.locales).length;
 
                    channel.percentage = divider === 0 ?
                        0 :
                        Math.round(channel.complete / divider * 100);
 
                    _.each(channel.locales, function (localeCompleteCount, localeLabel) {
                        var divider = channel.total;
                        var ratio = divider === 0 ?
                            0 :
                            Math.round(localeCompleteCount / divider * 100);
 
                        channel.locales[localeLabel] = { ratio: ratio };
                    });
 
                    channelArray.push(channel);
                });
 
                return channelArray;
            }
        });
    }
);