Passed
Push — master ( 8b521b...1e81c0 )
by
unknown
10:11
created

myems-admin/app/controllers/users/log/log.controller.js   A

Complexity

Total Complexity 8
Complexity/F 1.6

Size

Lines of Code 51
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 36
dl 0
loc 51
rs 10
c 0
b 0
f 0
mnd 3
bc 3
fnc 5
bpm 0.6
cpm 1.6
noi 0
1
'use strict';
2
app.controller('LogController', function (
3
    $scope,
4
    $window,
5
    LogService,
6
    toaster,
7
    $translate
8
) {
9
    $scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user"));
10
11
    $scope.logs = [];
12
    $scope.paginatedLogs = [];
13
    $scope.paging = {
14
        currentPage: 1,
15
        pageSize: 15
16
    };
17
18
    $scope.updatePaginatedLogs = function () {
19
        var begin = ($scope.paging.currentPage - 1) * $scope.paging.pageSize;
20
        var end = begin + $scope.paging.pageSize;
21
        $scope.paginatedLogs = $scope.logs.slice(begin, end);
22
    };
23
24
    $scope.pageChanged = function () {
25
        $scope.updatePaginatedLogs();
26
    };
27
28
    $scope.getLogs = function () {
29
        let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
30
        LogService.getLogs(headers, function (response) {
31
            if (angular.isDefined(response.status) && response.status === 200) {
32
                $scope.logs = angular.isArray(response.data) ? response.data : [];
33
                $scope.paging.currentPage = 1;
34
                $scope.updatePaginatedLogs();
35
            } else {
36
                $scope.logs = [];
37
                $scope.updatePaginatedLogs();
38
                if (response.data && response.data.description) {
39
                    toaster.pop({
40
                        type: "error",
41
                        title: $translate.instant("TOASTER.ERROR_TITLE"),
42
                        body: $translate.instant(response.data.description),
43
                        showCloseButton: true,
44
                    });
45
                }
46
            }
47
        });
48
    };
49
50
    $scope.getLogs();
51
});
52
53
54