Passed
Push — master ( 490cad...87aaa1 )
by Christian
12:06 queued 10s
created

src/Administration/Resources/app/administration/src/app/component/app/sw-app-actions/index.js   A

Complexity

Total Complexity 10
Complexity/F 1.11

Size

Lines of Code 66
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 39
mnd 1
bc 1
fnc 9
dl 0
loc 66
rs 10
bpm 0.1111
cpm 1.1111
noi 2
c 0
b 0
f 0
1
import template from './sw-app-actions.html.twig';
2
import './sw-app-actions.scss';
3
4
const { Component, Utils } = Shopware;
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
5
6
Component.register('sw-app-actions', {
7
    template,
8
9
    inject: ['feature', 'appActionButtonService'],
10
11
    data() {
12
        return {
13
            actions: [],
14
            matchedRoutes: []
15
        };
16
    },
17
18
    computed: {
19
        entity() {
20
            return Utils.get(this.$route, 'meta.$module.entity');
21
        },
22
23
        view() {
24
            const matchedRoute = this.matchedRoutes.filter((match) => {
25
                return !!Utils.get(match, 'meta.appSystem.view');
26
            }).pop();
27
28
            return Utils.get(matchedRoute, 'meta.appSystem.view');
29
        },
30
31
        areActionsAvailable() {
32
            return this.feature.isActive('FEATURE_NEXT_10286')
33
                && !!this.actions
34
                && this.actions.length > 0
35
                && this.params.length > 0;
36
        },
37
38
        params() {
39
            return Shopware.State.get('shopwareApps').selectedIds;
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
40
        }
41
    },
42
43
    watch: {
44
        $route: {
45
            immediate: true,
46
            handler() {
47
                this.matchedRoutes = this.$router.currentRoute.matched;
48
                this.loadActions();
49
            }
50
        }
51
    },
52
53
    methods: {
54
        runAction(actionId) {
55
            this.appActionButtonService.runAction(actionId, { ids: this.params });
56
        },
57
58
        async loadActions() {
59
            try {
60
                this.actions = await this.appActionButtonService.getActionButtonsPerView(this.entity, this.view);
61
            } catch (e) {
62
                this.actions = [];
63
            }
64
        }
65
    }
66
});
67