adding api for handlers and task

release/0.1.0
HerrHase 3 years ago
parent f3cc6f3e90
commit c483af9cc8

@ -1,5 +1,5 @@
{
"/public/js/spritemap.js": "/public/js/spritemap.js?id=2dda73ecee3bb668b395026efda6524c",
"/public/js/app.js": "/public/js/app.js?id=1c9307a192e1817119e543e388f2a43b",
"/public/js/app.js": "/public/js/app.js?id=0d34aa6088ee57ed4e67ebcbb9497b4e",
"/public/css/styles.css": "/public/css/styles.css?id=72a43d98017bdbcb83928c41f6289210"
}

@ -4,10 +4,10 @@
<!-- slot:title -->
<span slot="title">
<virtual if={ state.current.name }>
<virtual if={ state.current.id }>
Edit Task { state.current.name }
</virtual>
<virtual if={ !state.current.name }>
<virtual if={ !state.current.id }>
New Task
</virtual>
</span>
@ -30,22 +30,26 @@
</div>
<div class="field-group">
<label class="field-label">
requestHandler
requestHandlers
<select class="field-choice" name="requestHandler">
<option></option>
<option value="{ handler }" each={ handler in state.requestHandlers } selected={ action === state.current.requestHandler }></option>
<option value="{ requestHandler.file }" each={ requestHandler in state.requestHandlers } selected={ action === state.current.requestHandler }>
{ requestHandler.name }
</option>
</select>
<field-error name="requestHandler"></field-error>
<field-error name="requestHandlers"></field-error>
</label>
</div>
<div class="field-group">
<label class="field-label">
action
actionHandlers
<select class="field-choice" name="action">
<option></option>
<option value="{ action }" each={ action in state.actions } selected={ action === state.current.action }></option>
<option value="{ actionHandler.file }" each={ actionHandler in state.actionHandlers } selected={ action === state.current.actionHandler }>
{ actionHandler.name }
</option>
</select>
<field-error name="action"></field-error>
<field-error name="actionHandlers"></field-error>
</label>
</div>
<div class="field-group">
@ -87,68 +91,98 @@
*
*/
export default () => {
return {
...sidebar, // adding basic funtion for sidebar
state: {
requestHandlers: [],
validator: undefined,
current: {
name: '',
url: '',
requestHandler: '',
action: '',
options: {
export default () => {
return {
...sidebar, // adding basic funtion for sidebar
state: {
requestHandlers: [],
validator: undefined,
current: {
name: '',
url: '',
requestHandlers: '',
actionHandlers: '',
options: {
},
timer: ''
}
},
/**
*
*
*/
onMounted()
{
// creating formValidator
this.state.validator = new FormValidator(this.$('.form'), {
'name': {
'presence': true
},
'url': {
'presence': true
},
'requestHandler': {
'presence': true
},
'action': {
'presence': true
},
'timer': {
}
})
// adding on success
this.state.validator.onSuccess((event, data) => {
this.handleSuccess(event, data)
})
// adding on success
this.state.validator.onError((event, data) => {
this.state.isLoading = false
// add notification
notificationStore.danger('Error! Check your input!')
this.update()
})
//
taskFormStore.on('open', (data) => {
this.state.isOpen = true
this.update()
})
this.getRequestHandlers()
this.getActionHandlers()
},
},
timer: ''
}
getRequestHandlers()
{
fetch('/api/v1/handler/request', {
'method': 'GET'
})
.then((response) => response.json())
.then((response) => {
this.state.requestHandlers = response.data
this.update()
})
},
/**
*
*
*/
onMounted()
getActionHandlers()
{
// creating formValidator
this.state.validator = new FormValidator(this.$('.form'), {
'name': {
'presence': true
},
'url': {
'presence': true
},
'requestHandler': {
'presence': true
},
'action': {
'presence': true
},
'timer': {
'presence': true
}
})
// adding on success
this.state.validator.onSuccess((event, data) => {
this.handleSuccess(event, data)
})
// adding on success
this.state.validator.onError((event, data) => {
this.state.isLoading = false
notificationStore.danger('Error! Check your input!')
this.update()
})
taskFormStore.on('open', (data) => {
this.state.isOpen = true
this.update()
})
fetch('/api/v1/handler/action', {
'method': 'GET'
})
.then((response) => response.json())
.then((response) => {
this.state.actionHandlers = response.data
this.update()
})
},
/**
@ -158,11 +192,25 @@
*/
handleSuccess(event, data)
{
event.preventDefault()
fetch('/api/v1/task', {
'method': 'POST',
'body': JSON.stringify(data)
})
.then((response) => response.json())
.then((response) => {
// stop loading
this.state.isLoading = false
// add id to current
this.state.current.id = response.data.id
this.update()
})
}
}
}
}
</script>
</app-task-form>

@ -19,7 +19,4 @@
{% block script %}
<script async src="/js/app.js"></script>
<script>
const actions = {{ requestHandlers | json }}
</script>
{% endblock %}

@ -30,13 +30,17 @@ server.register(pov, {
* add routes
*
*/
import actionHttp from './http/api/action.js'
import taskHttp from './http/api/task.js'
import handlerHttp from './http/api/handler.js'
import indexHttp from './http/index.js'
import staticHttp from './http/static.js'
server
.register(actionHttp, {
'prefix': '/api'
.register(taskHttp, {
'prefix': '/api/v1'
})
.register(handlerHttp, {
'prefix': '/api/v1/'
})
.register(indexHttp)
.register(staticHttp)

@ -0,0 +1,47 @@
import * as fs from 'fs'
import * as path from 'path'
/**
* getting handlers
*
* @author Björn Hase, me@herr-hase.wtf
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/super-hog
*
*/
export default async function(fastify, opts)
{
fastify.get('/handler/:namespace(request|action)', async function (request, reply)
{
// handlers that found
const handlers = []
// directories to find
const directories = [
'custom',
'handlers'
]
// getting
directories.forEach((directory) => {
// create path
const directoryPath = './../runner/' + directory + '/' + request.params.namespace
// adding each from directory
fs.readdirSync(directoryPath).forEach(file => {
handlers.push({
'name': file.replace('.js', ''),
'file': path.resolve(file)
})
})
})
reply
.code(200)
.send({
'data': handlers
})
})
}

@ -21,7 +21,7 @@ export default async function(fastify, opts)
* @param {object} response
*
*/
fastify.get('/action', async function (request, reply)
fastify.get('/task/:id', async function (request, reply)
{
// getting actions
const actions = await actionRepository.find({ 'selector': {
@ -43,7 +43,7 @@ export default async function(fastify, opts)
* @param {object} response
*
*/
fastify.post('/action', async function (request, reply)
fastify.post('/task', async function (request, reply)
{
// getting actions
const action = await actionRepository.create()
@ -63,7 +63,7 @@ export default async function(fastify, opts)
* @param {object} response
*
*/
fastify.put('/action/:id', async function (request, reply)
fastify.put('/task/:id', async function (request, reply)
{
// getting actions
const action = await actionRepository.update({
@ -86,7 +86,7 @@ export default async function(fastify, opts)
* @param {object} response
*
*/
fastify.delete('/action/:id', async function (request, reply)
fastify.delete('/task/:id', async function (request, reply)
{
// getting actions
const action = await actionRepository.findOne({

@ -1,5 +1,6 @@
import token from '@fastify/csrf'
/**
* index
*
@ -24,12 +25,7 @@ export default async function(fastify, opts)
*/
fastify.get('/', (request, response) =>
{
response.view('../frontend/views/index', {
'responseHandlers': [{
test: 1
}],
'actions': []
})
response.view('../frontend/views/index')
})
/**

@ -549,11 +549,11 @@ riot__WEBPACK_IMPORTED_MODULE_1__.register('app-loading', _loading_riot__WEBPACK
bindingTypes,
getComponent
) => template(
'<div expr12="expr12"><div class="sidebar__inner"><div class="bar"><div class="bar__main"><slot expr13="expr13" name="title"></slot></div><div class="bar__end"><button expr14="expr14" class="button button--transparent" type="button"><svg class="icon fill-danger fill-text-hover" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-close"/></svg></button></div></div><div class="sidebar__body"><slot expr15="expr15" name="form"></slot><app-loading expr16="expr16"></app-loading></div><div class="sidebar__footer"><button expr17="expr17" class="button m-bottom-0" type="submit">\n Save\n <svg class="icon fill-success p-left-3" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-check"/></svg></button><button expr18="expr18" class="button m-bottom-0" type="submit" close>\n Save and Close\n <svg class="icon fill-success p-left-3" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-arrow-right"/></svg></button></div></div></div>',
'<div expr0="expr0"><div class="sidebar__inner"><div class="bar"><div class="bar__main"><slot expr1="expr1" name="title"></slot></div><div class="bar__end"><button expr2="expr2" class="button button--transparent" type="button"><svg class="icon fill-danger fill-text-hover" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-close"/></svg></button></div></div><div class="sidebar__body"><slot expr3="expr3" name="form"></slot><app-loading expr4="expr4"></app-loading></div><div class="sidebar__footer"><button expr5="expr5" class="button m-bottom-0" type="submit">\n Save\n <svg class="icon fill-success p-left-3" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-check"/></svg></button><button expr6="expr6" class="button m-bottom-0" type="submit" close>\n Save and Close\n <svg class="icon fill-success p-left-3" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-arrow-right"/></svg></button></div></div></div>',
[
{
redundantAttribute: 'expr12',
selector: '[expr12]',
redundantAttribute: 'expr0',
selector: '[expr0]',
expressions: [
{
@ -567,12 +567,12 @@ riot__WEBPACK_IMPORTED_MODULE_1__.register('app-loading', _loading_riot__WEBPACK
type: bindingTypes.SLOT,
attributes: [],
name: 'title',
redundantAttribute: 'expr13',
selector: '[expr13]'
redundantAttribute: 'expr1',
selector: '[expr1]'
},
{
redundantAttribute: 'expr14',
selector: '[expr14]',
redundantAttribute: 'expr2',
selector: '[expr2]',
expressions: [
{
@ -586,8 +586,8 @@ riot__WEBPACK_IMPORTED_MODULE_1__.register('app-loading', _loading_riot__WEBPACK
type: bindingTypes.SLOT,
attributes: [],
name: 'form',
redundantAttribute: 'expr15',
selector: '[expr15]'
redundantAttribute: 'expr3',
selector: '[expr3]'
},
{
type: bindingTypes.TAG,
@ -603,12 +603,12 @@ riot__WEBPACK_IMPORTED_MODULE_1__.register('app-loading', _loading_riot__WEBPACK
}
],
redundantAttribute: 'expr16',
selector: '[expr16]'
redundantAttribute: 'expr4',
selector: '[expr4]'
},
{
redundantAttribute: 'expr17',
selector: '[expr17]',
redundantAttribute: 'expr5',
selector: '[expr5]',
expressions: [
{
@ -624,8 +624,8 @@ riot__WEBPACK_IMPORTED_MODULE_1__.register('app-loading', _loading_riot__WEBPACK
]
},
{
redundantAttribute: 'expr18',
selector: '[expr18]',
redundantAttribute: 'expr6',
selector: '[expr6]',
expressions: [
{
@ -693,8 +693,8 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
current: {
name: '',
url: '',
requestHandler: '',
action: '',
requestHandlers: '',
actionHandlers: '',
options: {
},
@ -723,7 +723,7 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
'presence': true
},
'timer': {
'presence': true
}
})
@ -735,28 +735,73 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
// adding on success
this.state.validator.onError((event, data) => {
this.state.isLoading = false
// add notification
_stores_notification__WEBPACK_IMPORTED_MODULE_2__["default"].danger('Error! Check your input!')
this.update()
})
//
_stores_taskForm_js__WEBPACK_IMPORTED_MODULE_1__["default"].on('open', (data) => {
this.state.isOpen = true
this.update()
})
},
/**
*
*
*
*/
handleSuccess(event, data)
{
}
this.getRequestHandlers()
this.getActionHandlers()
},
getRequestHandlers()
{
fetch('/api/v1/handler/request', {
'method': 'GET'
})
.then((response) => response.json())
.then((response) => {
this.state.requestHandlers = response.data
this.update()
})
},
getActionHandlers()
{
fetch('/api/v1/handler/action', {
'method': 'GET'
})
.then((response) => response.json())
.then((response) => {
this.state.actionHandlers = response.data
this.update()
})
},
/**
*
*
*
*/
handleSuccess(event, data)
{
event.preventDefault()
fetch('/api/v1/task', {
'method': 'POST',
'body': JSON.stringify(data)
})
.then((response) => response.json())
.then((response) => {
// stop loading
this.state.isLoading = false
// add id to current
this.state.current.id = response.data.id
this.update()
})
}
}
},
},
template: (
template,
@ -779,7 +824,7 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
bindings: [
{
type: bindingTypes.IF,
evaluate: _scope => _scope.state.current.name,
evaluate: _scope => _scope.state.current.id,
redundantAttribute: 'expr23',
selector: '[expr23]',
@ -823,7 +868,7 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
},
{
type: bindingTypes.IF,
evaluate: _scope => !_scope.state.current.name,
evaluate: _scope => !_scope.state.current.id,
redundantAttribute: 'expr24',
selector: '[expr24]',
@ -852,7 +897,7 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
},
{
id: 'form',
html: '<form expr25="expr25" id="app-task-form" class="form" slot="form"><div class="field-group"><label class="field-label">\n name\n <input expr26="expr26" class="field-text" name="name" type="text"/><field-error expr27="expr27" name="name"></field-error></label></div><div class="field-group"><label class="field-label">\n url\n <input expr28="expr28" class="field-text" name="url" type="text"/><field-error expr29="expr29" name="url"></field-error></label></div><div class="field-group"><label class="field-label">\n requestHandler\n <select class="field-choice" name="requestHandler"><option></option><option expr30="expr30"></option></select><field-error expr31="expr31" name="requestHandler"></field-error></label></div><div class="field-group"><label class="field-label">\n action\n <select class="field-choice" name="action"><option></option><option expr32="expr32"></option></select><field-error expr33="expr33" name="action"></field-error></label></div><div class="field-group"><label class="field-label">\n options\n <input expr34="expr34" type="text" name="options" class="field-text"/><field-error expr35="expr35" name="options"></field-error></label></div><div class="field-group"><label class="field-label">\n timer\n <input expr36="expr36" type="text" name="timer" class="field-text"/><field-error expr37="expr37" name="timer"></field-error></label></div></form>',
html: '<form expr25="expr25" id="app-task-form" class="form" slot="form"><div class="field-group"><label class="field-label">\n name\n <input expr26="expr26" class="field-text" name="name" type="text"/><field-error expr27="expr27" name="name"></field-error></label></div><div class="field-group"><label class="field-label">\n url\n <input expr28="expr28" class="field-text" name="url" type="text"/><field-error expr29="expr29" name="url"></field-error></label></div><div class="field-group"><label class="field-label">\n requestHandlers\n <select class="field-choice" name="requestHandler"><option></option><option expr30="expr30"></option></select><field-error expr31="expr31" name="requestHandlers"></field-error></label></div><div class="field-group"><label class="field-label">\n actionHandlers\n <select class="field-choice" name="action"><option></option><option expr32="expr32"></option></select><field-error expr33="expr33" name="actionHandlers"></field-error></label></div><div class="field-group"><label class="field-label">\n options\n <input expr34="expr34" type="text" name="options" class="field-text"/><field-error expr35="expr35" name="options"></field-error></label></div><div class="field-group"><label class="field-label">\n timer\n <input expr36="expr36" type="text" name="timer" class="field-text"/><field-error expr37="expr37" name="timer"></field-error></label></div></form>',
bindings: [
{
@ -913,14 +958,24 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
condition: null,
template: template(
null,
' ',
[
{
expressions: [
{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => [
_scope.requestHandler.name
].join(
''
)
},
{
type: expressionTypes.ATTRIBUTE,
name: 'value',
evaluate: _scope => _scope.handler
evaluate: _scope => _scope.requestHandler.file
},
{
type: expressionTypes.ATTRIBUTE,
@ -934,7 +989,7 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
redundantAttribute: 'expr30',
selector: '[expr30]',
itemName: 'handler',
itemName: 'requestHandler',
indexName: null,
evaluate: _scope => _scope.state.requestHandlers
},
@ -953,19 +1008,29 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
condition: null,
template: template(
null,
' ',
[
{
expressions: [
{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => [
_scope.actionHandler.name
].join(
''
)
},
{
type: expressionTypes.ATTRIBUTE,
name: 'value',
evaluate: _scope => _scope.action
evaluate: _scope => _scope.actionHandler.file
},
{
type: expressionTypes.ATTRIBUTE,
name: 'selected',
evaluate: _scope => _scope.action === _scope.state.current.action
evaluate: _scope => _scope.action === _scope.state.current.actionHandler
}
]
}
@ -974,9 +1039,9 @@ riot__WEBPACK_IMPORTED_MODULE_5__.register('field-error', _tiny_components_valid
redundantAttribute: 'expr32',
selector: '[expr32]',
itemName: 'action',
itemName: 'actionHandler',
indexName: null,
evaluate: _scope => _scope.state.actions
evaluate: _scope => _scope.state.actionHandlers
},
{
type: bindingTypes.TAG,
@ -1113,11 +1178,11 @@ __webpack_require__.r(__webpack_exports__);
bindingTypes,
getComponent
) => template(
'<button expr11="expr11" class="button m-bottom-0 m-top-5"><svg class="icon fill-text fill-text-contrast-hover m-top-1 p-right-2" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-close"/></svg> </button>',
'<button expr7="expr7" class="button m-bottom-0 m-top-5"><svg class="icon fill-text fill-text-contrast-hover m-top-1 p-right-2" aria-hidden="true"><use xlink:href="/symbol-defs.svg#icon-close"/></svg> </button>',
[
{
redundantAttribute: 'expr11',
selector: '[expr11]',
redundantAttribute: 'expr7',
selector: '[expr7]',
expressions: [
{
@ -1209,7 +1274,7 @@ __webpack_require__.r(__webpack_exports__);
bindingTypes,
getComponent
) => template(
'<div class="tasks"><table class="table table--stripped"><thead><tr><th class="table__th">\n name\n </th><th class="table__th">\n url\n </th><th class="table__th">\n requestHandler\n </th><th class="table__th">\n actions\n </th><th class="table__th">\n cron\n </th><th class="table__th"></th><tr></tr><tbody><tr expr0="expr0"></tr><tr expr10="expr10"></tr></tbody></tr></thead></table></div>',
'<div class="tasks"><table class="table table--stripped"><thead><tr><th class="table__th">\n name\n </th><th class="table__th">\n url\n </th><th class="table__th">\n requestHandler\n </th><th class="table__th">\n actions\n </th><th class="table__th">\n cron\n </th><th class="table__th"></th><tr></tr><tbody><tr expr8="expr8"></tr><tr expr18="expr18"></tr></tbody></tr></thead></table></div>',
[
{
type: bindingTypes.EACH,
@ -1217,11 +1282,11 @@ __webpack_require__.r(__webpack_exports__);
condition: _scope => _scope.state.tasks.length > 0,
template: template(
'<td expr1="expr1" class="table__td"> </td><td expr2="expr2" class="table__td"> </td><td expr3="expr3" class="table__td"> </td><td class="table__td"><virtual expr4="expr4"></virtual></td><td expr7="expr7" class="table__td"> </td><td class="table__td"><button expr8="expr8" class="button">\n Edit\n </button><button expr9="expr9" class="button">\n Delete\n </button></td>',
'<td expr9="expr9" class="table__td"> </td><td expr10="expr10" class="table__td"> </td><td expr11="expr11" class="table__td"> </td><td class="table__td"><virtual expr12="expr12"></virtual></td><td expr15="expr15" class="table__td"> </td><td class="table__td"><button expr16="expr16" class="button">\n Edit\n </button><button expr17="expr17" class="button">\n Delete\n </button></td>',
[
{
redundantAttribute: 'expr1',
selector: '[expr1]',
redundantAttribute: 'expr9',
selector: '[expr9]',
expressions: [
{
@ -1237,8 +1302,8 @@ __webpack_require__.r(__webpack_exports__);
]
},
{
redundantAttribute: 'expr2',
selector: '[expr2]',
redundantAttribute: 'expr10',
selector: '[expr10]',
expressions: [
{
@ -1254,8 +1319,8 @@ __webpack_require__.r(__webpack_exports__);
]
},
{
redundantAttribute: 'expr3',
selector: '[expr3]',
redundantAttribute: 'expr11',
selector: '[expr11]',
expressions: [
{
@ -1286,12 +1351,12 @@ __webpack_require__.r(__webpack_exports__);
slots: [
{
id: 'default',
html: '<span expr5="expr5"> </span><span expr6="expr6"></span>',
html: '<span expr13="expr13"> </span><span expr14="expr14"></span>',
bindings: [
{
redundantAttribute: 'expr5',
selector: '[expr5]',
redundantAttribute: 'expr13',
selector: '[expr13]',
expressions: [
{
@ -1309,8 +1374,8 @@ __webpack_require__.r(__webpack_exports__);
{
type: bindingTypes.IF,
evaluate: _scope => _scope.actions.options,
redundantAttribute: 'expr6',
selector: '[expr6]',
redundantAttribute: 'expr14',
selector: '[expr14]',
template: template(
' ',
@ -1341,15 +1406,15 @@ __webpack_require__.r(__webpack_exports__);
]
),
redundantAttribute: 'expr4',
selector: '[expr4]',
redundantAttribute: 'expr12',
selector: '[expr12]',
itemName: 'action',
indexName: null,
evaluate: _scope => _scope.task.actions
},
{
redundantAttribute: 'expr7',
selector: '[expr7]',
redundantAttribute: 'expr15',
selector: '[expr15]',
expressions: [
{
@ -1365,8 +1430,8 @@ __webpack_require__.r(__webpack_exports__);
]
},
{
redundantAttribute: 'expr8',
selector: '[expr8]',
redundantAttribute: 'expr16',
selector: '[expr16]',
expressions: [
{
@ -1377,8 +1442,8 @@ __webpack_require__.r(__webpack_exports__);
]
},
{
redundantAttribute: 'expr9',
selector: '[expr9]',
redundantAttribute: 'expr17',
selector: '[expr17]',
expressions: [
{
@ -1391,8 +1456,8 @@ __webpack_require__.r(__webpack_exports__);
]
),
redundantAttribute: 'expr0',
selector: '[expr0]',
redundantAttribute: 'expr8',
selector: '[expr8]',
itemName: 'task',
indexName: null,
evaluate: _scope => _scope.state.tasks
@ -1400,8 +1465,8 @@ __webpack_require__.r(__webpack_exports__);
{
type: bindingTypes.IF,
evaluate: _scope => _scope.state.tasks.length === 0,
redundantAttribute: 'expr10',
selector: '[expr10]',
redundantAttribute: 'expr18',
selector: '[expr18]',
template: template(
'<td class="table__td center" colspan="6">\n Nothing found\n </td>',

Loading…
Cancel
Save