]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+admin/plugins/plugin-list-installed/plugin-list-installed.component.ts
Refactor admin plugins
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / plugins / plugin-list-installed / plugin-list-installed.component.ts
index 6af2249207b552e63b353dd30ca4dfd001fb8359..6d66869dd1c08499503805ab9cd9d1ac5434c6ca 100644 (file)
@@ -4,21 +4,16 @@ import { ActivatedRoute, Router } from '@angular/router'
 import { PluginApiService } from '@app/+admin/plugins/shared/plugin-api.service'
 import { ComponentPagination, ConfirmService, hasMoreItems, Notifier } from '@app/core'
 import { PluginService } from '@app/core/plugins/plugin.service'
-import { compareSemVer } from '@shared/core-utils/miscs/miscs'
+import { compareSemVer } from '@shared/core-utils'
 import { PeerTubePlugin, PluginType } from '@shared/models'
 
 @Component({
   selector: 'my-plugin-list-installed',
   templateUrl: './plugin-list-installed.component.html',
-  styleUrls: [
-    '../shared/toggle-plugin-type.scss',
-    '../shared/plugin-list.component.scss',
-    './plugin-list-installed.component.scss'
-  ]
+  styleUrls: [ './plugin-list-installed.component.scss' ]
 })
 export class PluginListInstalledComponent implements OnInit {
-  pluginTypeOptions: { label: string, value: PluginType }[] = []
-  pluginType: PluginType = PluginType.PLUGIN
+  pluginType: PluginType
 
   pagination: ComponentPagination = {
     currentPage: 1,
@@ -40,37 +35,43 @@ export class PluginListInstalledComponent implements OnInit {
     private router: Router,
     private route: ActivatedRoute
   ) {
-    this.pluginTypeOptions = this.pluginApiService.getPluginTypeOptions()
   }
 
   ngOnInit () {
-    const query = this.route.snapshot.queryParams
-    if (query['pluginType']) this.pluginType = parseInt(query['pluginType'], 10)
+    if (!this.route.snapshot.queryParams['pluginType']) {
+      const queryParams = { pluginType: PluginType.PLUGIN }
 
-    this.reloadPlugins()
+      this.router.navigate([], { queryParams })
+    }
+
+    this.route.queryParams.subscribe(query => {
+      if (!query['pluginType']) return
+
+      this.pluginType = parseInt(query['pluginType'], 10)
+
+      this.reloadPlugins()
+    })
   }
 
   reloadPlugins () {
     this.pagination.currentPage = 1
     this.plugins = []
 
-    this.router.navigate([], { queryParams: { pluginType: this.pluginType } })
-
     this.loadMorePlugins()
   }
 
   loadMorePlugins () {
     this.pluginApiService.getPlugins(this.pluginType, this.pagination, this.sort)
-        .subscribe(
-          res => {
+        .subscribe({
+          next: res => {
             this.plugins = this.plugins.concat(res.data)
             this.pagination.totalItems = res.total
 
             this.onDataSubject.next(res.data)
           },
 
-          err => this.notifier.error(err.message)
-        )
+          error: err => this.notifier.error(err.message)
+        })
   }
 
   onNearOfBottom () {
@@ -113,16 +114,16 @@ export class PluginListInstalledComponent implements OnInit {
     if (res === false) return
 
     this.pluginApiService.uninstall(plugin.name, plugin.type)
-      .subscribe(
-        () => {
+      .subscribe({
+        next: () => {
           this.notifier.success($localize`${plugin.name} uninstalled.`)
 
           this.plugins = this.plugins.filter(p => p.name !== plugin.name)
           this.pagination.totalItems--
         },
 
-        err => this.notifier.error(err.message)
-      )
+        error: err => this.notifier.error(err.message)
+      })
   }
 
   async update (plugin: PeerTubePlugin) {
@@ -143,8 +144,8 @@ export class PluginListInstalledComponent implements OnInit {
 
     this.pluginApiService.update(plugin.name, plugin.type)
         .pipe()
-        .subscribe(
-          res => {
+        .subscribe({
+          next: res => {
             this.updating[updatingKey] = false
 
             this.notifier.success($localize`${plugin.name} updated.`)
@@ -152,8 +153,8 @@ export class PluginListInstalledComponent implements OnInit {
             Object.assign(plugin, res)
           },
 
-          err => this.notifier.error(err.message)
-        )
+          error: err => this.notifier.error(err.message)
+        })
   }
 
   getShowRouterLink (plugin: PeerTubePlugin) {