Passed
Push — master ( f7a740...0639f4 )
by Christian
13:29 queued 12s
created

src/Administration/Resources/app/administration/src/module/sw-cms/elements/image/component/index.js   A

Complexity

Total Complexity 14
Complexity/F 2

Size

Lines of Code 77
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 42
mnd 7
bc 7
fnc 7
dl 0
loc 77
rs 10
bpm 1
cpm 2
noi 1
c 0
b 0
f 0
1
import template from './sw-cms-el-image.html.twig';
2
import './sw-cms-el-image.scss';
3
4
const { Component, Mixin, Filter } = 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-cms-el-image', {
7
    template,
8
9
    mixins: [
10
        Mixin.getByName('cms-element')
11
    ],
12
13
    computed: {
14
        displayModeClass() {
15
            if (this.element.config.displayMode.value === 'standard') {
16
                return null;
17
            }
18
19
            return `is--${this.element.config.displayMode.value}`;
20
        },
21
22
        styles() {
23
            return {
24
                'min-height': this.element.config.displayMode.value === 'cover' &&
25
                              this.element.config.minHeight.value !== 0 ? this.element.config.minHeight.value : '340px',
26
                'align-self': !this.element.config.verticalAlign.value ? null : this.element.config.verticalAlign.value
27
            };
28
        },
29
30
        mediaUrl() {
31
            const elemData = this.element.data.media;
32
            const mediaSource = this.element.config.media.source;
33
34
            if (mediaSource === 'mapped') {
35
                const demoMedia = this.getDemoValue(this.element.config.media.value);
36
37
                if (demoMedia && demoMedia.url) {
38
                    return demoMedia.url;
39
                }
40
            }
41
42
            if (elemData && elemData.id) {
43
                return this.element.data.media.url;
44
            }
45
46
            if (elemData && elemData.url) {
47
                return this.assetFilter(elemData.url);
48
            }
49
50
            return this.assetFilter('administration/static/img/cms/preview_mountain_large.jpg');
51
        },
52
53
        assetFilter() {
54
            return Filter.getByName('asset');
55
        }
56
    },
57
58
    watch: {
59
        cmsPageState: {
60
            deep: true,
61
            handler() {
62
                this.$forceUpdate();
63
            }
64
        }
65
    },
66
67
    created() {
68
        this.createdComponent();
69
    },
70
71
    methods: {
72
        createdComponent() {
73
            this.initElementConfig('image');
74
            this.initElementData('image');
75
        }
76
    }
77
});
78