Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dashboard.directive.js « dashboard « angularjs « Dashboard « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 04c1a8e6a50ff2f45557b7cdecdfd7a0286f8a49 (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*!
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

/**
 * <div piwik-dashboard dashboard-id="5"></div>
 */
(function () {
    angular.module('piwikApp').directive('piwikDashboard', piwikDashboard);

    piwikDashboard.$inject = ['dashboardsModel', '$rootScope', '$q'];

    function piwikDashboard(dashboardsModel, $rootScope, $q) {

        function renderDashboard(dashboardId, dashboard, layout)
        {
            $('.dashboardSettings').show();
            initTopControls();

            // Embed dashboard / exported as widget
            if (!$('#topBars').length) {
                $('.dashboardSettings').after($('#Dashboard'));
                $('#Dashboard ul li').removeClass('active');
                $('#Dashboard_embeddedIndex_' + dashboardId).addClass('active');
            }

            widgetsHelper.getAvailableWidgets();

            $('#dashboardWidgetsArea').off('dashboardempty', showEmptyDashboardNotification);
            $('#dashboardWidgetsArea')
                .on('dashboardempty', showEmptyDashboardNotification)
                .dashboard({
                    idDashboard: dashboardId,
                    layout: layout,
                    name: dashboard ? dashboard.name : ''
                });

            $('#columnPreview').find('>div').each(function () {
                var width = [];
                $('div', this).each(function () {
                    width.push(this.className.replace(/width-/, ''));
                });
                $(this).attr('layout', width.join('-'));
            });

            $('#columnPreview').find('>div').on('click', function () {
                $('#columnPreview').find('>div').removeClass('choosen');
                $(this).addClass('choosen');
            });
        }

        function fetchDashboard(dashboardId) {
            var dashboardElement = $('#dashboardWidgetsArea');
            dashboardElement.dashboard('destroyWidgets');
            dashboardElement.empty();
            globalAjaxQueue.abort();

            var getDashboard = dashboardsModel.getDashboard(dashboardId);
            var getLayout = dashboardsModel.getDashboardLayout(dashboardId);

            $q.all([getDashboard, getLayout]).then(function (response) {
                var dashboard = response[0];
                var layout = response[1];

                $(function() {
                    renderDashboard(dashboardId, dashboard, layout);
                });
            });
        }

        function clearDashboard () {
            $('.top_controls .dashboard-manager').hide();
            $('#dashboardWidgetsArea').dashboard('destroy');
        }

        return {
            restrict: 'A',
            scope: {
                dashboardid: '=',
                layout: '='
            },
            link: function (scope, element, attrs) {

                scope.$parent.fetchDashboard = function (dashboardId) {
                    scope.dashboardId = dashboardId;
                    fetchDashboard(dashboardId)
                };

                fetchDashboard(scope.dashboardid);

                function onLocationChange(event, newUrl, oldUrl)
                {
                   if (broadcast.getValueFromUrl('module') != 'Widgetize' && newUrl !== oldUrl &&
                       newUrl.indexOf('category=Dashboard_Dashboard') === -1) {
                       // we remove the dashboard only if we no longer show a dashboard.
                       clearDashboard();
                   }
                }

                // should be rather handled in route or so.
                var unbind = $rootScope.$on('$locationChangeSuccess', onLocationChange);
                scope.$on('$destroy', onLocationChange);
                scope.$on('$destroy', unbind);
            }
        };
    }
})();