Skip to content

Commit

Permalink
add:lable group
Browse files Browse the repository at this point in the history
  • Loading branch information
xyctruth committed Jan 7, 2022
1 parent 1b17f06 commit 74e3f81
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
23 changes: 19 additions & 4 deletions pkg/apiserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewAPIServer(opt Options) *APIServer {
c.String(200, "I'm fine")
})
router.Use(HandleCors).GET("/api/targets", apiServer.listTarget)
router.Use(HandleCors).GET("/api/labels", apiServer.listLabel)
router.Use(HandleCors).GET("/api/group_labels", apiServer.listGroupLabel)
router.Use(HandleCors).GET("/api/sample_types", apiServer.listSampleTypes)
router.Use(HandleCors).GET("/api/group_sample_types", apiServer.listGroupSampleTypes)
router.Use(HandleCors).GET("/api/profile_meta/:sample_type", apiServer.listProfileMeta)
Expand Down Expand Up @@ -99,13 +99,28 @@ func (s *APIServer) listTarget(c *gin.Context) {
c.JSON(http.StatusOK, jobs)
}

func (s *APIServer) listLabel(c *gin.Context) {
jobs, err := s.store.ListLabel()
func (s *APIServer) listGroupLabel(c *gin.Context) {
labels, err := s.store.ListLabel()
if err != nil {
c.String(http.StatusInternalServerError, err.Error())
return
}
c.JSON(http.StatusOK, jobs)

customLabels := make([]string, 0, 5)
generateLabels := make([]string, 0, 5)

for _, label := range labels {
if strings.HasPrefix(label, "_") {
generateLabels = append(generateLabels, label)
} else {
customLabels = append(customLabels, label)
}
}

c.JSON(http.StatusOK, map[string][]string{
"custom": customLabels,
"generate": generateLabels,
})
}

func (s *APIServer) listSampleTypes(c *gin.Context) {
Expand Down
9 changes: 0 additions & 9 deletions pkg/storage/badger/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package badger

import (
"errors"
"sort"
"strconv"
"strings"
"time"

"github.com/dgraph-io/badger/v3"
Expand Down Expand Up @@ -344,13 +342,6 @@ func (s *store) ListLabel() ([]string, error) {
return nil
})

sort.Slice(labels, func(i, j int) bool {
if strings.HasPrefix(labels[j], "_") {
return true
}
return labels[i] < labels[j]
})

return labels, err
}

Expand Down
32 changes: 24 additions & 8 deletions ui/src/view/index/components/selectLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
placeholder="Select Label"
clearable="true"
filterable>
<el-option
v-for="(item,index) in options"
:key="index"
:label="item"
:value="item"
<el-option-group
v-for="group in options"
:key="group.label"
:label="group.label"
>
</el-option>
<el-option
v-for="(item,index) in group.options"
:key="index"
:label="item"
:value="item"
>
</el-option>
</el-option-group>
</el-select>
</template>

Expand All @@ -35,10 +41,20 @@ if (query.labels){
onMounted(() => {
axios({
url: "/api/labels",
url: "/api/group_labels",
})
.then((res) => {
options.value = res
const types = ["custom","generate"]
var data = []
for (const key of types) {
if (res[key]) {
data.push({
label: key,
options: res[key]
})
}
}
options.value = data
})
.catch((err) => {
console.log(err);
Expand Down

0 comments on commit 74e3f81

Please sign in to comment.