|
1
|
|
|
import type { PropType } from 'vue'; |
|
2
|
|
|
import template from './sw-plugin-card.html.twig'; |
|
3
|
|
|
import './sw-plugin-card.scss'; |
|
4
|
|
|
|
|
5
|
|
|
type ComponentData = { |
|
6
|
|
|
pluginIsLoading: boolean, |
|
7
|
|
|
pluginIsSaveSuccessful: boolean, |
|
8
|
|
|
} |
|
9
|
|
|
|
|
10
|
|
|
type RecommendedPlugin = { |
|
11
|
|
|
active: boolean, |
|
12
|
|
|
name: string, |
|
13
|
|
|
iconPath: string, |
|
14
|
|
|
label: string, |
|
15
|
|
|
manufacturer: string, |
|
16
|
|
|
shortDescription: string, |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @package merchant-services |
|
21
|
|
|
* @deprecated tag:v6.6.0 - Will be private |
|
22
|
|
|
*/ |
|
23
|
|
|
// eslint-disable-next-line sw-deprecation-rules/private-feature-declarations |
|
24
|
|
|
export default Shopware.Component.wrapComponentConfig({ |
|
25
|
|
|
template, |
|
26
|
|
|
|
|
27
|
|
|
inject: ['cacheApiService', 'extensionHelperService'], |
|
28
|
|
|
|
|
29
|
|
|
mixins: [Shopware.Mixin.getByName('sw-extension-error')], |
|
30
|
|
|
|
|
31
|
|
|
props: { |
|
32
|
|
|
plugin: { |
|
33
|
|
|
type: Object as PropType<RecommendedPlugin>, |
|
34
|
|
|
required: true, |
|
35
|
|
|
}, |
|
36
|
|
|
showDescription: { |
|
37
|
|
|
type: Boolean, |
|
38
|
|
|
// TODO: Boolean props should only be opt in and therefore default to false |
|
39
|
|
|
// eslint-disable-next-line vue/no-boolean-default |
|
40
|
|
|
default: true, |
|
41
|
|
|
required: false, |
|
42
|
|
|
}, |
|
43
|
|
|
}, |
|
44
|
|
|
|
|
45
|
|
|
data(): ComponentData { |
|
46
|
|
|
return { |
|
47
|
|
|
pluginIsLoading: false, |
|
48
|
|
|
pluginIsSaveSuccessful: false, |
|
49
|
|
|
}; |
|
50
|
|
|
}, |
|
51
|
|
|
|
|
52
|
|
|
computed: { |
|
53
|
|
|
pluginIsNotActive(): boolean { |
|
54
|
|
|
return !this.plugin.active; |
|
55
|
|
|
}, |
|
56
|
|
|
}, |
|
57
|
|
|
|
|
58
|
|
|
methods: { |
|
59
|
|
|
onInstall(): void { |
|
60
|
|
|
void this.setupPlugin(); |
|
61
|
|
|
}, |
|
62
|
|
|
|
|
63
|
|
|
async setupPlugin(): Promise<void> { |
|
64
|
|
|
this.pluginIsLoading = true; |
|
65
|
|
|
this.pluginIsSaveSuccessful = false; |
|
66
|
|
|
|
|
67
|
|
|
try { |
|
68
|
|
|
await this.extensionHelperService.downloadAndActivateExtension(this.plugin.name); |
|
69
|
|
|
this.pluginIsSaveSuccessful = true; |
|
70
|
|
|
this.$emit('extension-activated'); |
|
71
|
|
|
} catch (error: unknown) { |
|
72
|
|
|
// ts can not recognize functions from mixins |
|
73
|
|
|
// @ts-expect-error |
|
74
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call |
|
75
|
|
|
this.showExtensionErrors(error); |
|
76
|
|
|
} finally { |
|
77
|
|
|
this.pluginIsLoading = false; |
|
78
|
|
|
|
|
79
|
|
|
// wait until cacheApiService is transpiled to ts |
|
80
|
|
|
// @ts-expect-error |
|
81
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call |
|
82
|
|
|
this.cacheApiService.clear(); |
|
83
|
|
|
|
|
84
|
|
|
this.$emit('onPluginInstalled', this.plugin.name); |
|
85
|
|
|
} |
|
86
|
|
|
}, |
|
87
|
|
|
}, |
|
88
|
|
|
}); |
|
89
|
|
|
|