Passed
Push — 6.5.0.0 ( 78fa09...9b9d4d )
by Christian
14:01 queued 12s
created

src/Administration/Resources/app/administration/src/app/component/structure/sw-admin/index.ts   A

Complexity

Total Complexity 9
Complexity/F 1.5

Size

Lines of Code 63
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 63
rs 10
c 0
b 0
f 0
wmc 9
mnd 3
bc 3
fnc 6
bpm 0.5
cpm 1.5
noi 0

6 Functions

Rating   Name   Duplication   Size   Complexity  
A index.ts ➔ isLoggedIn 0 2 1
A index.ts ➔ beforeDestroy 0 3 2
A index.ts ➔ onUserActivity 0 2 1
A index.ts ➔ data 0 6 1
A index.ts ➔ created 0 16 3
A index.ts ➔ metaInfo 0 4 1
1
import template from './sw-admin.html.twig';
2
3
const { Component } = Shopware;
4
5
/**
6
 * @package admin
7
 *
8
 * @private
9
 */
10
Component.register('sw-admin', {
11
    template,
12
13
    inject: ['userActivityService', 'loginService'],
14
15
    metaInfo() {
16
        return {
17
            title: this.$tc('global.sw-admin-menu.textShopwareAdmin'),
18
        };
19
    },
20
21
    data(): {
22
        channel: BroadcastChannel | null,
23
        } {
24
        return {
25
            channel: null,
26
        };
27
    },
28
29
    computed: {
30
        isLoggedIn() {
31
            return this.loginService.isLoggedIn();
32
        },
33
    },
34
35
    created() {
36
        this.channel = new BroadcastChannel('session_channel');
37
        this.channel.onmessage = (event) => {
38
            const data = event.data as { inactive?: boolean };
39
40
            if (!data || !Shopware.Utils.object.hasOwnProperty(data, 'inactive')) {
41
                return;
42
            }
43
44
            const routeBlocklist = ['sw.inactivity.login.index', 'sw.login.index.login'];
45
            if (!data.inactive || routeBlocklist.includes(this.$router.currentRoute.name || '')) {
46
                return;
47
            }
48
49
            this.loginService.forwardLogout(true, true);
50
        };
51
    },
52
53
    beforeDestroy() {
54
        this.channel?.close();
55
    },
56
57
    methods: {
58
        onUserActivity() {
59
            this.userActivityService.updateLastUserActivity();
60
        },
61
    },
62
});
63