Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle Polling from the UI #174

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion frontend/client/views/settings/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
</div>
</div>
</tab-pane>
<tab-pane label="Manage Settings" icon="fa fa-wrench">
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
<manage-settings/>
</tab-pane>
</tabs>
</div>

Expand Down Expand Up @@ -355,6 +358,7 @@
import Notification from 'vue-bulma-notification-fixed'
import {mapGetters} from 'vuex'
import ManagePermissions from './permissions/manage-permissions'
import ManageSettings from './settings/manage-settings'
import {EventBus} from '../../app'

const NotificationComponent = Vue.extend(Notification)
Expand Down Expand Up @@ -382,7 +386,8 @@
TabPane,
Modal,
Collapse,
CollapseItem
CollapseItem,
ManageSettings
},

data () {
Expand Down
154 changes: 154 additions & 0 deletions frontend/client/views/settings/settings/manage-settings.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<template>
michelvocks marked this conversation as resolved.
Show resolved Hide resolved
<div class="tile is-vertical">
<div class="tile is-parent">
<article class="tile is-child notification content-article box">
<div class="tile is-parent">
<article class="tile is-child notification content-article box">
<vue-good-table
:columns="settingColumns"
:rows="settingRows"
:paginate="true"
:global-search="true"
:defaultSortBy="{field: 'name', type: 'desc'}"
globalSearchPlaceholder="Search ..."
styleClass="table table-grid table-own-bordered">
<template slot="table-row" slot-scope="props">
<td>
<span>{{ props.row.display_name }}</span>
</td>
<td v-tippy="{ arrow : true, animation : 'shift-away'}">
<toggle-button
v-model="props.row.display_value"
id="pollertoggle"
:color="{checked: '#7DCE94', unchecked: '#82C7EB'}"
:labels="{checked: 'On', unchecked: 'Off'}"
@change="settingsTogglePollerSwitch"
:sync="true"/>
</td>
</template>
<div slot="emptystate" class="empty-table-text">
No settings found.
</div>
</vue-good-table>
</article>
</div>
</article>
</div>
</div>
</template>

<script>
import Vue from 'vue'
import { ToggleButton } from 'vue-js-toggle-button'
import {TabPane, Tabs} from 'vue-bulma-tabs'
import VueGoodTable from 'vue-good-table'
import VueTippy from 'vue-tippy'
import Notification from 'vue-bulma-notification-fixed'
const NotificationComponent = Vue.extend(Notification)
const openNotification = (propsData = {
title: '',
message: '',
type: '',
direction: '',
duration: 4500,
container: '.notifications'
}) => {
return new NotificationComponent({
el: document.createElement('div'),
propsData
})
}

Vue.use(VueGoodTable)
Vue.use(VueTippy)

export default {
name: 'manage-settings',
components: {Tabs, TabPane, ToggleButton},
data () {
return {
// search: '',
Skarlso marked this conversation as resolved.
Show resolved Hide resolved
settingsTogglePollerValue: false,
settingColumns: [
{
label: 'Name',
field: 'display_name'
},
{
label: 'Value',
field: 'display_value'
}
],
settingRows: []
}
},
mounted () {
this.setSettings()
},
methods: {
settingsTogglePollerSwitch (val) {
if (val.value) {
this.$http
.post('/api/v1/settings/poll/on')
.then(response => {
openNotification({
title: 'Poll turned on!',
message: 'Polling has been enabled.',
type: 'success'
})
})
.catch((error) => {
this.$onError(error)
})
} else {
this.$http
.post('/api/v1/settings/poll/off')
.then(response => {
openNotification({
title: 'Poll turned off!',
message: 'Polling has been disabled.',
type: 'success'
})
})
.catch((error) => {
this.$onError(error)
})
}
},
setSettings () {
this.$http
.get('/api/v1/settings/poll', {showProgressBar: false})
.then(response => {
this.settingRows = [{
display_name: 'Polling',
display_value: response.data.Status
}]
})
.catch((error) => {
this.$onError(error)
})
}
}
}
</script>

<style scoped>
.settings-row {
cursor: pointer;
}
.table-general {
background: #413F4A;
border: 2px solid #000;
}
.table-general th {
color: #4da2fc;
}
.table-general td {
border: 2px solid #000;
color: #8c91a0;
}
.table-settings td:hover {
background: #575463;
cursor: pointer;
}
</style>
38 changes: 29 additions & 9 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"vue-bulma-progress-bar": "^1.0.2",
"vue-bulma-tabs": "^1.1.3",
"vue-good-table": "^1.19.2",
"vue-js-toggle-button": "^1.3.2",
"vue-lodash": "^1.0.4",
"vue-nprogress": "0.1.5",
"vue-router": "^3.0.1",
Expand Down
5 changes: 5 additions & 0 deletions handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func InitHandlers(e *echo.Echo) error {
e.GET(p+"pipeline/latest", PipelineGetAllWithLatestRun)
e.POST(p+"pipeline/periodicschedules", PipelineCheckPeriodicSchedules)

// Settings
e.POST(p+"settings/poll/on", SettingsPollOn)
e.POST(p+"settings/poll/off", SettingsPollOff)
e.GET(p+"settings/poll", SettingsPollGet)

// PipelineRun
e.POST(p+"pipelinerun/:pipelineid/:runid/stop", PipelineStop)
e.GET(p+"pipelinerun/:pipelineid/:runid", PipelineRunGet)
Expand Down
40 changes: 40 additions & 0 deletions handlers/settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package handlers

import (
"net/http"

"github.com/gaia-pipeline/gaia/workers/pipeline"

"github.com/gaia-pipeline/gaia"
"github.com/labstack/echo"
)

// SettingsPollOn turn on polling functionality.
func SettingsPollOn(c echo.Context) error {
gaia.Cfg.Poll = true
err := pipeline.StartPoller()
if err != nil {
c.String(http.StatusBadRequest, err.Error())
}
return c.String(http.StatusOK, "Polling is turned on.")
}

// SettingsPollOff turn off polling functionality.
func SettingsPollOff(c echo.Context) error {
gaia.Cfg.Poll = false
err := pipeline.StopPoller()
if err != nil {
c.String(http.StatusBadRequest, err.Error())
}
return c.String(http.StatusOK, "Polling is turned off.")
}

// SettingsPollGet get status of polling functionality.
func SettingsPollGet(c echo.Context) error {
poll := struct {
Status bool
}{
Status: gaia.Cfg.Poll,
}
return c.JSON(http.StatusOK, poll)
}
Loading