]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts
WIP plugins: list installed plugins in client
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / plugins / plugin-list-installed / plugin-list-installed.component.ts
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 { Notifier } from '@app/core'
7 import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
8
9 @Component({
10 selector: 'my-plugin-list-installed',
11 templateUrl: './plugin-list-installed.component.html',
12 styleUrls: [ './plugin-list-installed.component.scss' ]
13 })
14 export class PluginListInstalledComponent implements OnInit {
15 pluginTypeOptions: { label: string, value: PluginType }[] = []
16 pluginType: PluginType = PluginType.PLUGIN
17
18 pagination: ComponentPagination = {
19 currentPage: 1,
20 itemsPerPage: 10
21 }
22 sort = 'name'
23
24 plugins: PeerTubePlugin[] = []
25
26 constructor (
27 private i18n: I18n,
28 private pluginService: PluginApiService,
29 private notifier: Notifier
30 ) {
31 this.pluginTypeOptions = this.pluginService.getPluginTypeOptions()
32 }
33
34 ngOnInit () {
35 this.reloadPlugins()
36 }
37
38 reloadPlugins () {
39 this.pagination.currentPage = 1
40 this.plugins = []
41
42 this.loadMorePlugins()
43 }
44
45 loadMorePlugins () {
46 this.pluginService.getPlugins(this.pluginType, this.pagination, this.sort)
47 .subscribe(
48 res => {
49 this.plugins = this.plugins.concat(res.data)
50 this.pagination.totalItems = res.total
51 },
52
53 err => this.notifier.error(err.message)
54 )
55 }
56
57 onNearOfBottom () {
58 if (!hasMoreItems(this.pagination)) return
59
60 this.pagination.currentPage += 1
61
62 this.loadMorePlugins()
63 }
64
65 getNoResultMessage () {
66 if (this.pluginType === PluginType.PLUGIN) {
67 return this.i18n('You don\'t have plugins installed yet.')
68 }
69
70 return this.i18n('You don\'t have themes installed yet.')
71 }
72 }