Skip to content

Commit

Permalink
"sync datasets feature"
Browse files Browse the repository at this point in the history
  • Loading branch information
sfermi committed Jan 31, 2019
1 parent 21a126d commit 57fddee
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
15 changes: 15 additions & 0 deletions cli/contrib.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,18 @@ import (
func GetAllDatasets(c *gin.Context) {
c.JSON(http.StatusOK, dataset.FetchAllDatasets())
}

type AddRegistryRequest struct {
URL string `json:"url"`
}

// POST /datasets/registry
func AddNewRegistry(c *gin.Context) {
var addRegistryRequest AddRegistryRequest
c.BindJSON(&addRegistryRequest)
dataset.AddNewRegistry(addRegistryRequest.URL)
c.JSON(http.StatusOK, gin.H{
"code": "200",
"status": "Finished",
})
}
3 changes: 2 additions & 1 deletion cli/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ func runServer(port string) {
r.GET("/socket.io/", socketHandler)
r.POST("/socket.io/", socketHandler)
// Contrib Related Routes
r.GET("/datasets", GetAllDatasets)
r.GET("/contrib/datasets", GetAllDatasets)
r.POST("/contrib/datasets/registries", AddNewRegistry)
r.Handle("WS", "/socket.io/", socketHandler)
r.Handle("WSS", "/socket.io/", socketHandler)
r.Run("0.0.0.0:" + port)
Expand Down
31 changes: 31 additions & 0 deletions dashboard/src/pages/contrib/dataset/Datasets.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<v-container>
<v-card>
<v-btn outline color="indigo" @click="trigger_sync()">
<v-icon left dark>fas fa-sync</v-icon>Sync
</v-btn>
<v-data-table :items="datasets" :headers="headers" class="elevation-1">
<template slot="items" slot-scope="props">
<td class="text-xs-left">{{ props.item.Name }}</td>
Expand Down Expand Up @@ -46,6 +49,24 @@
</v-card-actions>
</v-card>
</v-dialog>
<v-dialog v-model="datasetSyncDialog">
<v-card>
<v-card-title>
<span class="headline">Sync Database</span>
</v-card-title>
<v-card-text>
<v-text-field
label="Datasets URL*"
required
v-model="databaseURL"
hint="e.g: https://premium.file.cvtron.xyz/cvpm/data/registry/dataset.toml"
></v-text-field>
</v-card-text>
<v-card-actions>
<v-btn color="indigo darken-1" outline @click="sync()">Sync</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</v-container>
</template>

Expand All @@ -57,6 +78,8 @@ export default {
datasets: [],
searchName: '',
detailDialog: false,
datasetSyncDialog: false,
databaseURL: 'https://premium.file.cvtron.xyz/cvpm/data/registry/dataset.toml',
detailInfo: {},
searchTag: '',
headers: [
Expand Down Expand Up @@ -88,6 +111,14 @@ export default {
}
},
methods: {
trigger_sync () {
this.datasetSyncDialog = true
},
sync () {
systemService.SyncDatabase(this.databaseURL).then(function (res) {
location.reload()
})
},
filterTags (tag) {
if (tag !== '') {
return tag
Expand Down
13 changes: 12 additions & 1 deletion dashboard/src/services/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,18 @@ class SystemService {
// contrib
getAllDatasets () {
return new Promise((resolve, reject) => {
axios.get(this.endpoint + '/datasets', {
axios.get(this.endpoint + '/contrib/datasets', {
}).then(function (res) {
resolve(res)
}).then(function (err) {
reject(err)
})
})
}
SyncDatabase (datasetsUrl) {
return new Promise((resolve, reject) => {
axios.post(this.endpoint + '/contrib/datasets/registries', {
url: datasetsUrl
}).then(function (res) {
resolve(res)
}).then(function (err) {
Expand Down

0 comments on commit 57fddee

Please sign in to comment.