Passed
Push — master ( 6b9503...008c37 )
by Christian
12:05 queued 11s
created

src/Administration/Resources/app/administration/src/module/sw-promotion-v2/page/sw-promotion-v2-list/index.js   A

Complexity

Total Complexity 10
Complexity/F 1

Size

Lines of Code 102
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 69
dl 0
loc 102
rs 10
c 0
b 0
f 0
wmc 10
mnd 0
bc 0
fnc 10
bpm 0
cpm 1
noi 2
1
import template from './sw-promotion-v2-list.html.twig';
2
import './sw-promotion-v2-list.scss';
3
4
const { Component } = 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
const { Criteria } = Shopware.Data;
6
7
Component.register('sw-promotion-v2-list', {
8
    template,
9
10
    inject: [
11
        'repositoryFactory',
12
        'acl'
13
    ],
14
15
    mixins: [
16
        'listing'
17
    ],
18
19
    data() {
20
        return {
21
            isLoading: true,
22
            promotions: null,
23
            total: 0,
24
            showDeleteModal: false,
25
            sortBy: 'createdAt',
26
            sortDirection: 'DESC'
27
        };
28
    },
29
30
    metaInfo() {
31
        return {
32
            title: this.$createTitle()
33
        };
34
    },
35
36
    computed: {
37
        promotionRepository() {
38
            return this.repositoryFactory.create('promotion');
39
        },
40
41
        promotionCriteria() {
42
            return (new Criteria(this.page, this.limit))
43
                .setTerm(this.term)
44
                .addSorting(Criteria.sort(this.sortBy, this.sortDirection));
45
        },
46
47
        promotionColumns() {
48
            return this.getPromotionColumns();
49
        }
50
    },
51
52
    methods: {
53
        getList() {
54
            this.isLoading = true;
55
56
            return this.promotionRepository.search(this.promotionCriteria, Shopware.Context.api).then((searchResult) => {
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...
57
                this.isLoading = false;
58
                this.total = searchResult.total;
59
                this.promotions = searchResult;
60
61
                return this.promotions;
62
            });
63
        },
64
65
        onChangeLanguage() {
66
            this.getList();
67
        },
68
69
        getPromotionColumns() {
70
            return [{
71
                property: 'name',
72
                label: 'sw-promotion-v2.list.columnName',
73
                routerLink: 'sw.promotion.v2.detail',
74
                inlineEdit: 'string',
75
                allowResize: true,
76
                primary: true
77
            }, {
78
                property: 'active',
79
                label: 'sw-promotion-v2.list.columnActive',
80
                inlineEdit: 'boolean',
81
                allowResize: true,
82
                align: 'center'
83
            }, {
84
                property: 'validFrom',
85
                label: 'sw-promotion-v2.list.columnValidFrom',
86
                inlineEdit: 'date',
87
                allowResize: true,
88
                align: 'center'
89
            }, {
90
                property: 'validUntil',
91
                label: 'sw-promotion-v2.list.columnValidUntil',
92
                inlineEdit: 'date',
93
                allowResize: true,
94
                align: 'center'
95
            }];
96
        },
97
98
        updateTotal({ total }) {
99
            this.total = total;
100
        }
101
    }
102
});
103