1 import { Component, OnInit } from '@angular/core'
2 import { PluginType } from '@shared/models/plugins/plugin.type'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { PluginApiService } from '@app/+admin/plugins/shared/plugin-api.service'
5 import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model'
6 import { ConfirmService, Notifier } from '@app/core'
7 import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
8 import { ActivatedRoute, Router } from '@angular/router'
11 selector: 'my-plugin-list-installed',
12 templateUrl: './plugin-list-installed.component.html',
14 '../shared/toggle-plugin-type.scss',
15 './plugin-list-installed.component.scss'
18 export class PluginListInstalledComponent implements OnInit {
19 pluginTypeOptions: { label: string, value: PluginType }[] = []
20 pluginType: PluginType = PluginType.PLUGIN
22 pagination: ComponentPagination = {
28 plugins: PeerTubePlugin[] = []
32 private pluginService: PluginApiService,
33 private notifier: Notifier,
34 private confirmService: ConfirmService,
35 private router: Router,
36 private route: ActivatedRoute
38 this.pluginTypeOptions = this.pluginService.getPluginTypeOptions()
42 const query = this.route.snapshot.queryParams
43 if (query['pluginType']) this.pluginType = parseInt(query['pluginType'], 10)
49 this.pagination.currentPage = 1
52 this.router.navigate([], { queryParams: { pluginType: this.pluginType }})
54 this.loadMorePlugins()
58 this.pluginService.getPlugins(this.pluginType, this.pagination, this.sort)
61 this.plugins = this.plugins.concat(res.data)
62 this.pagination.totalItems = res.total
65 err => this.notifier.error(err.message)
70 if (!hasMoreItems(this.pagination)) return
72 this.pagination.currentPage += 1
74 this.loadMorePlugins()
77 getNoResultMessage () {
78 if (this.pluginType === PluginType.PLUGIN) {
79 return this.i18n('You don\'t have plugins installed yet.')
82 return this.i18n('You don\'t have themes installed yet.')
85 async uninstall (plugin: PeerTubePlugin) {
86 const res = await this.confirmService.confirm(
87 this.i18n('Do you really want to uninstall {{pluginName}}?', { pluginName: plugin.name }),
88 this.i18n('Uninstall')
90 if (res === false) return
92 this.pluginService.uninstall(plugin.name, plugin.type)
95 this.notifier.success(this.i18n('{{pluginName}} uninstalled.', { pluginName: plugin.name }))
97 this.plugins = this.plugins.filter(p => p.name !== plugin.name)
98 this.pagination.totalItems--
101 err => this.notifier.error(err.message)
105 getShowRouterLink (plugin: PeerTubePlugin) {
106 return [ '/admin', 'plugins', 'show', this.pluginService.nameToNpmName(plugin.name, plugin.type) ]