@@ -13,6 +13,7 @@ import (
1313
1414 "github.com/1Panel-dev/1Panel/agent/app/dto"
1515 "github.com/1Panel-dev/1Panel/agent/app/model"
16+ "github.com/1Panel-dev/1Panel/agent/app/repo"
1617 "github.com/1Panel-dev/1Panel/agent/constant"
1718 "github.com/1Panel-dev/1Panel/agent/global"
1819 "github.com/1Panel-dev/1Panel/agent/utils/ai_tools/gpu"
@@ -31,14 +32,13 @@ import (
3132type DashboardService struct {}
3233
3334type IDashboardService interface {
34- Sync (req dto.AppLauncherSync ) error
35-
3635 LoadOsInfo () (* dto.OsInfo , error )
3736 LoadBaseInfo (ioOption string , netOption string ) (* dto.DashboardBase , error )
3837 LoadCurrentInfoForNode () * dto.NodeCurrent
3938 LoadCurrentInfo (ioOption string , netOption string ) * dto.DashboardCurrent
4039
4140 LoadAppLauncher () ([]dto.AppLauncher , error )
41+ ChangeShow (req dto.SettingUpdate ) error
4242 ListLauncherOption (filter string ) ([]dto.LauncherOption , error )
4343 Restart (operation string ) error
4444}
@@ -47,14 +47,6 @@ func NewIDashboardService() IDashboardService {
4747 return & DashboardService {}
4848}
4949
50- func (u * DashboardService ) Sync (req dto.AppLauncherSync ) error {
51- var launchers []model.AppLauncher
52- for _ , item := range req .Keys {
53- launchers = append (launchers , model.AppLauncher {Key : item })
54- }
55- return launcherRepo .SyncAll (launchers )
56- }
57-
5850func (u * DashboardService ) Restart (operation string ) error {
5951 if operation != "1panel" && operation != "system" && operation != "1panel-agent" {
6052 return fmt .Errorf ("handle restart operation %s failed, err: nonsupport such operation" , operation )
@@ -285,7 +277,7 @@ func (u *DashboardService) LoadAppLauncher() ([]dto.AppLauncher, error) {
285277 return data , err
286278 }
287279
288- showList := loadShowList ()
280+ showList , _ := launcherRepo . ListName ()
289281 defaultList := []string {"openresty" , "mysql" , "halo" , "redis" , "maxkb" , "wordpress" }
290282 allList := common .RemoveRepeatStr (append (defaultList , showList ... ))
291283 for _ , showItem := range allList {
@@ -343,8 +335,23 @@ func (u *DashboardService) LoadAppLauncher() ([]dto.AppLauncher, error) {
343335 return data , nil
344336}
345337
338+ func (u * DashboardService ) ChangeShow (req dto.SettingUpdate ) error {
339+ launcher , _ := launcherRepo .Get (repo .WithByKey (req .Key ))
340+ if req .Value == constant .StatusEnable && launcher .ID == 0 {
341+ if err := launcherRepo .Create (& model.AppLauncher {Key : req .Key }); err != nil {
342+ return err
343+ }
344+ }
345+ if req .Value == constant .StatusDisable && launcher .ID != 0 {
346+ if err := launcherRepo .Delete (repo .WithByKey (req .Key )); err != nil {
347+ return err
348+ }
349+ }
350+ return nil
351+ }
352+
346353func (u * DashboardService ) ListLauncherOption (filter string ) ([]dto.LauncherOption , error ) {
347- showList := loadShowList ()
354+ showList , _ := launcherRepo . ListName ()
348355 var data []dto.LauncherOption
349356 optionMap := make (map [string ]bool )
350357 appInstalls , err := appInstallRepo .ListBy (context .Background ())
@@ -500,25 +507,6 @@ func loadGPUInfo() []dto.GPUInfo {
500507 return data
501508}
502509
503- func loadShowList () []string {
504- var data []string
505- if global .IsMaster {
506- var list []AppLauncher
507- if err := global .CoreDB .Model (AppLauncher {}).Where ("1 == 1" ).Find (& list ).Error ; err != nil {
508- return []string {}
509- }
510- for _ , item := range list {
511- data = append (data , item .Key )
512- }
513- return data
514- }
515- list , _ := launcherRepo .List ()
516- for _ , item := range list {
517- data = append (data , item .Key )
518- }
519- return data
520- }
521-
522510type AppLauncher struct {
523511 Key string `json:"key"`
524512}
0 commit comments