Skip to content

Commit

Permalink
feat(site): add status filter #633
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Oct 19, 2024
1 parent ef7be18 commit 0e1efd3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
25 changes: 18 additions & 7 deletions api/sites/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import (
"strings"
)

func GetDomains(c *gin.Context) {
func GetSiteList(c *gin.Context) {
name := c.Query("name")
enabled := c.Query("enabled")
orderBy := c.Query("order_by")
sort := c.DefaultQuery("sort", "desc")

Expand All @@ -44,9 +45,19 @@ func GetDomains(c *gin.Context) {
file := configFiles[i]
fileInfo, _ := file.Info()
if !file.IsDir() {
// name filter
if name != "" && !strings.Contains(file.Name(), name) {
continue
}
// status filter
if enabled != "" {
if enabled == "true" && !enabledConfigMap[file.Name()] {
continue
}
if enabled == "false" && enabledConfigMap[file.Name()] {
continue
}
}
configs = append(configs, config.Config{
Name: file.Name(),
ModifiedAt: fileInfo.ModTime(),
Expand All @@ -64,7 +75,7 @@ func GetDomains(c *gin.Context) {
})
}

func GetDomain(c *gin.Context) {
func GetSite(c *gin.Context) {
rewriteName, ok := c.Get("rewriteConfigFileName")
name := c.Param("name")

Expand Down Expand Up @@ -164,7 +175,7 @@ func GetDomain(c *gin.Context) {
})
}

func SaveDomain(c *gin.Context) {
func SaveSite(c *gin.Context) {
name := c.Param("name")

if name == "" {
Expand Down Expand Up @@ -256,10 +267,10 @@ func SaveDomain(c *gin.Context) {
}
}

GetDomain(c)
GetSite(c)
}

func EnableDomain(c *gin.Context) {
func EnableSite(c *gin.Context) {
configFilePath := nginx.GetConfPath("sites-available", c.Param("name"))
enabledConfigFilePath := nginx.GetConfPath("sites-enabled", c.Param("name"))

Expand Down Expand Up @@ -303,7 +314,7 @@ func EnableDomain(c *gin.Context) {
})
}

func DisableDomain(c *gin.Context) {
func DisableSite(c *gin.Context) {
enabledConfigFilePath := nginx.GetConfPath("sites-enabled", c.Param("name"))
_, err := os.Stat(enabledConfigFilePath)
if err != nil {
Expand Down Expand Up @@ -338,7 +349,7 @@ func DisableDomain(c *gin.Context) {
})
}

func DeleteDomain(c *gin.Context) {
func DeleteSite(c *gin.Context) {
var err error
name := c.Param("name")
availablePath := nginx.GetConfPath("sites-available", name)
Expand Down
12 changes: 6 additions & 6 deletions api/sites/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package sites
import "github.com/gin-gonic/gin"

func InitRouter(r *gin.RouterGroup) {
r.GET("domains", GetDomains)
r.GET("domain/:name", GetDomain)
r.POST("domain/:name", SaveDomain)
r.POST("domain/:name/enable", EnableDomain)
r.POST("domain/:name/disable", DisableDomain)
r.GET("domains", GetSiteList)
r.GET("domain/:name", GetSite)
r.POST("domain/:name", SaveSite)
r.POST("domain/:name/enable", EnableSite)
r.POST("domain/:name/disable", DisableSite)
r.POST("domain/:name/advance", DomainEditByAdvancedMode)
r.DELETE("domain/:name", DeleteDomain)
r.DELETE("domain/:name", DeleteSite)
r.POST("domain/:name/duplicate", DuplicateSite)
r.POST("auto_cert/:name", AddDomainToAutoCert)
r.DELETE("auto_cert/:name", RemoveDomainFromAutoCert)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ onMounted(() => {
:default-active-first-option="false"
:mode="props.multiple ? 'multiple' : undefined"
style="min-width: 180px"
allow-clear
:get-popup-container="triggerNode => triggerNode.parentNode"
/>
</template>
Expand Down
9 changes: 8 additions & 1 deletion app/src/views/site/SiteList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import StdTable from '@/components/StdDesign/StdDataDisplay/StdTable.vue'
import type { customRender } from '@/components/StdDesign/StdDataDisplay/StdTableTransformer'
import { datetime } from '@/components/StdDesign/StdDataDisplay/StdTableTransformer'
import domain from '@/api/domain'
import { input } from '@/components/StdDesign/StdDataEntry'
import { input, select } from '@/components/StdDesign/StdDataEntry'
import SiteDuplicate from '@/views/site/components/SiteDuplicate.vue'
import InspectConfig from '@/views/config/InspectConfig.vue'
import type { Column, JSXElements } from '@/components/StdDesign/types'
Expand Down Expand Up @@ -35,6 +35,13 @@ const columns: Column[] = [{
return h('div', template)
},
search: {
type: select,
mask: {
true: $gettext('Enabled'),
false: $gettext('Disabled'),
},
},
sortable: true,
pithy: true,
}, {
Expand Down
4 changes: 0 additions & 4 deletions model/config_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import (

type ConfigBackup struct {
Model

Name string `json:"name"`
FilePath string `json:"filepath"`
Content string `json:"content" gorm:"type:text"`
}

type ConfigBackupListItem struct {
Model

Name string `json:"name"`
FilePath string `json:"filepath"`
}
Expand All @@ -25,13 +23,11 @@ func GetBackupList(path string) (configs []ConfigBackupListItem) {
db.Model(&ConfigBackup{}).
Where(&ConfigBackup{FilePath: path}).
Find(&configs)

return
}

func GetBackup(id int) (config ConfigBackup) {
db.First(&config, id)

return
}

Expand Down

0 comments on commit 0e1efd3

Please sign in to comment.