Skip to content

Commit

Permalink
Merge pull request #84 from ansibleguy76/release/v4.0.10
Browse files Browse the repository at this point in the history
v4.0.10 into main
  • Loading branch information
ansibleguy76 authored May 23, 2023
2 parents bdde059 + ac701d5 commit 12350dc
Show file tree
Hide file tree
Showing 16 changed files with 206 additions and 65 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [4.0.10] - 2023-05-23

### Fixed

- help added
- fixed sql init
- set a few columns to utf8mb4 for emoticon issues
- add interval to cleanup 1 day old running jobs
- better database check error handling, if the database is offline, no create schema button will be shown

### Added

- Added alias type 'local' => expression, runLocal, hide, noOutput

## [4.0.9] - 2023-05-07

### Added
Expand Down Expand Up @@ -499,7 +513,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow change password for current local user
- Start tracking versions

[Unreleased]: https://github.com/ansibleguy76/ansibleforms/compare/4.0.9...HEAD
[Unreleased]: https://github.com/ansibleguy76/ansibleforms/compare/4.0.10...HEAD

[4.0.10]: https://github.com/ansibleguy76/ansibleforms/compare/4.0.9...4.0.10

[4.0.9]: https://github.com/ansibleguy76/ansibleforms/compare/4.0.8...4.0.9

Expand Down
4 changes: 2 additions & 2 deletions app_versions.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ext.version_code = 40009
ext.version_name = "4.0.9"
ext.version_code = 40010
ext.version_name = "4.0.10"
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ansible_forms_vue",
"version": "4.0.9",
"version": "4.0.10",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
52 changes: 27 additions & 25 deletions client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</div>
</BulmaModal>
<BulmaNav v-if="version" :isAdmin="isAdmin" @profile="showProfile=true" @about="showAbout=true" :approvals="approvals" :authenticated="authenticated" :profile="profile" @logout="logout()" :version="version" />
<router-view :isAdmin="isAdmin" :profile="profile" :authenticated="authenticated" :errorMessage="errorMessage" :errorData="errorData" @authenticated="login()" @logout="logout()" @refreshApprovals="loadApprovals()" />
<router-view v-if="isLoaded" :isAdmin="isAdmin" :profile="profile" :authenticated="authenticated" :errorMessage="errorMessage" :errorData="errorData" @authenticated="login()" @logout="logout()" @refreshApprovals="loadApprovals()" />
</div>
</template>
<script>
Expand All @@ -82,6 +82,7 @@
isAdmin:false,
version:undefined,
approvals:0,
isLoaded:false,
showAbout:false,
showEasterEgg:false,
thanks:[
Expand Down Expand Up @@ -135,33 +136,34 @@
},
checkDatabase(){
var ref=this;
console.log("Checking database")
axios.get('/api/v1/schema') // check database
.then((result)=>{
if(result.data.status=="error"){
console.log("aha error")
ref.errorMessage=result.data.message;
ref.errorData=result.data.data;
if(!ref.errorMessage)ref.errorMessage="Unknown error"
if(typeof ref.errorMessage=="object"){ref.errorMessage=ref.errorMessage.message}
if(ref.errorMessage.startsWith("ERROR")){ // actual error, send to error page
ref.errorMessage="Failed to check AnsibleForms database schema\n\n" + ref.errorMessage;
ref.$router.replace({name:"Error"}).catch(err => {});
}else{ // not a real error, send to schema page
ref.$router.replace({name:"Schema"}).catch(err => {});
}
}else{
this.loadVersion()
this.login()
.then((result)=>{
if(result.data.status=="error"){
ref.errorMessage=result.data.message;
ref.errorData=result.data.data;
if(!ref.errorMessage)ref.errorMessage="Unknown error"
if(typeof ref.errorMessage=="object"){ref.errorMessage=ref.errorMessage.message}
if(ref.errorMessage.startsWith("ERROR")){ // actual error, send to error page
ref.errorMessage="Failed to check AnsibleForms database schema\n\n" + ref.errorMessage;
ref.$router.replace({name:"Error"}).catch(err => {});
}else{ // not a real error, send to schema page
ref.$router.replace({name:"Schema"}).catch(err => {});
}
ref.isLoaded=true
}else{
this.loadVersion()
this.login()
ref.isLoaded=true
}
})
.catch(function(err){
ref.$toast.error("Failed to check AnsibleForms database schema");
ref.errorMessage="Failed to check AnsibleForms database schema\n\n" + err
ref.$router.replace({name:"Error"}).catch(err => {});
});
})
.catch(function(err){
ref.$toast.error("Failed to check AnsibleForms database schema");
ref.errorMessage="Failed to check AnsibleForms database schema\n\n" + err
ref.$router.replace({name:"Error"}).catch(err => {});
ref.isLoaded=true
});
},
loadProfile(){
var ref=this;
Expand Down
13 changes: 11 additions & 2 deletions client/src/components/Form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@
this.currentForm.fields.forEach((item,i) => {
if(["expression"].includes(item.type)){
var testRegex = /\$\(([^)]+)\)/g;
var matches=(item.expression || item.query).matchAll(testRegex);
var matches=(item.expression || item.query || '').matchAll(testRegex);
for(var match of matches){
foundmatch = match[0]; // found $(xxx)
foundfield = match[1]; // found xxx
Expand Down Expand Up @@ -1981,6 +1981,15 @@
this.fieldOptions["__user__"]={
type:"expression"
}
// process aliases
this.currentForm.fields.forEach((item, i) => {
if(item.type=="local"){
item.hide=item.hide??true
item.noOutput=item.noOutput??true
item.type="expression"
item.runLocal=true
}
})
// initialize defaults
this.currentForm.fields.forEach((item, i) => {
// extra query parameters and store in externalData
Expand All @@ -2004,7 +2013,7 @@
}
Vue.set(ref.fieldOptions,item.name,{}) // storing some easy to find options
Vue.set(ref.fieldOptions[item.name],"evalDefault",item.evalDefault??false)
if(["expression","query","enum","table"].includes(item.type)){
if(["expression","query","enum","table","html"].includes(item.type)){
Vue.set(ref.fieldOptions[item.name],"isDynamic",!!(item.expression??item.query??false))
Vue.set(ref.fieldOptions[item.name],"valueColumn",item.valueColumn||"")
Vue.set(ref.fieldOptions[item.name],"placeholderColumn",item.placeholderColumn||"")
Expand Down
28 changes: 18 additions & 10 deletions client/src/views/Schema.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<div class="container">
<div class="columns is-centered">
<div class="column is-6-tablet is-6-desktop is-6-widescreen">
<div class="notification is-danger" v-if="errorMessage!=''" v-text="errorMessage"></div>
<div class="notification is-danger" v-if="error!=''" v-text="error"></div>
<div class="notification is-success" v-if="success" v-html="success"></div>
<div class="notification is-warning" v-if="failed" v-html="failed"></div>
<form action="" class="box">
<form action="" class="box" v-if="error!='FATAL ERROR'">
<div class="content">
If this is the first time setup and you don't have your own schema and tables.<br><br>
Would you like me to try and create the schema and tables ?<br>
Expand All @@ -26,6 +26,12 @@
</button>
</div>
</form>
<div v-else class="box">
<div class="content">
Something went wrong. Most likely the database is simply not reachable.
</div>

</div>
</div>
</div>
</div>
Expand All @@ -34,7 +40,6 @@
</template>

<script>
import Vue from 'vue'
import axios from 'axios'
Expand All @@ -47,6 +52,7 @@
},
data() {
return {
error:this.errorMessage
}
},
computed:{
Expand All @@ -69,19 +75,21 @@
create() {
var ref=this
this.$toast.info("Creating... wait a moment")
axios.post("/api/v1/schema")
axios.post("/api/v1/schema",{})
.then((result)=>{
if(result.data.status!="error"){
ref.errorMessage=""
setTimeout(()=>{ref.$router.push({name:"Login"})},3000)
ref.error=""
this.$toast.success(result.data.message)
//setTimeout(()=>{ref.$router.push({name:"Login"})},3000)
}else{
ref.errorMessage=result.data.message
ref.error=result.data.message
}
console.log(result)
}).catch(function (error) {
ref.errorMessage=error
ref.error=error
})
console.log("creating")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ansible_forms",
"version": "4.0.9",
"version": "4.0.10",
"repository": {
"type": "git",
"url": "git://github.com/ansibleguy76/ansibleforms.git"
Expand Down
26 changes: 25 additions & 1 deletion server/schema/forms_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,30 @@
},
"required": ["expression"]
},
{
"properties": {
"type": {
"enum": ["local"]
},
"values": {"not":{}},
"minValue": {"not":{}},
"maxValue": {"not":{}},
"sticky": {"not":{}},
"horizontal": {"not":{}},
"pctColumns": {"not":{}},
"filterColumns": {"not":{}},
"dbConfig": {"not":{}},
"multiple": {"not":{}},
"allowDelete": {"not":{}},
"allowInsert": {"not":{}},
"deleteMarker": {"not":{}},
"insertMarker": {"not":{}},
"readonlyColumns": {"not":{}},
"keydown": {"not":{}},
"outputObject": {"not":{}}
},
"required": ["expression"]
},
{
"properties": {
"type": {
Expand Down Expand Up @@ -932,7 +956,7 @@
"properties": {
"type": {
"type": "string",
"enum": ["text","textarea", "password", "checkbox", "enum", "query", "number", "radio", "expression", "table","datetime","html"]
"enum": ["text","textarea", "password", "checkbox", "enum", "query", "number", "radio", "expression","local", "table","datetime","html"]
},
"name": {
"$id": "/formfield",
Expand Down
26 changes: 22 additions & 4 deletions server/schema/help.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,7 @@
help: A help message
- name: html
description: An HTML field
version: 4.0.9
examples:
- name: Alert
code: |
Expand Down Expand Up @@ -1670,10 +1671,12 @@
* **database query** : you can use the query and dbConfig property to query a mysql, mssql server, postgres or mongodb.
* **expression** : you can use the expression property to create or retrieve data. in this case the output of the expression can be any type.
The expression itself is pure javascript. You can do inline javascript or you can use a function. Read more on security concerns about expressions You can extend the functions with your own in the custom.js file. You can have synchronous and asynchronous functions. This allows you to retrieve any kind of data, whether it's reading a file or accessing a rest-api, or querying a foreign database. You can run the expression locally (`runLocal`) in the browser for simple expressions. This is faster and there is no limitation on the expression.
The expression itself is pure javascript. You can do inline javascript or you can use a function. Read more on security concerns about expressions You can extend the functions with your own in the custom.js file. You can have synchronous and asynchronous functions. This allows you to retrieve any kind of data, whether it's reading a file or accessing a rest-api, or querying a foreign database. You can run the expression locally (`runLocal`) in the browser for simple expressions. This is faster and there is no limitation on the expression. Use the alias type `local` to quickly make an expression type with runLocal, hide and noOutput.
Advanced helper functions (local and remote) are available, to query from rest for example.
Explore the separate section on Expressions for multiple demo's.
Explore the separate section on Expressions for multiple demo's.
Alias : `local` (type='expression', runLocal=true, hide=true, noOutput=true) // since version 4.0.10
examples:
- name: Expressions
code: |
Expand Down Expand Up @@ -1794,19 +1797,21 @@
- name: label
type: string
allowed: Free text
with_types: text, textarea, datetime, number, password, checkbox, radio, enum, expression, table
short: Field label
description: |
A friendly name/label for the field
- name: placeholder
type: string
allowed: Free text
with_types: text, textarea, datetime, number, password, checkbox, radio, enum, expression, table
short: In-field help value
description: |
Some form fields allow an in-field hint value.
with_types: text, textarea, number, password, checkbox, enum, datetime
- name: help
type: string
allowed: Free text
with_types: text, textarea, datetime, number, password, checkbox, radio, enum, expression, table
short: Field help message
description: |
Some fields require additional help information.
Expand Down Expand Up @@ -2220,7 +2225,9 @@
However in combination with `runLocal`, the evaluation is ran in the browsers sandbox and allows the full javascript power.
When used in an `enum` field, the expression must return a flat array or array of flat objects, to make it presentable in a dropdown box.
An expression supports placeholders. Read more about placeholders here. [TODO]
Click here to find out more about the predefined functions. [TODO]
Click here to find out more about the predefined functions. [TODO]
**tip** : use the alias `local` (type='expression',runLocal=true,hide=true,noOutput=true)
with_types: enum, expression, table, html
examples:
- name: Get a list of users from a rest api
Expand All @@ -2244,6 +2251,15 @@
type: enum
expression: Array.from({length: 10}, (_, i) => i + 1)
runLocal: true
- name: Use the alias `local`
code: |
- name: uppercase
type: local
expression: "'test'.toUpperCase()"
runLocal: true // this is default with type=local
hide: true // this is default with type=local
noOutput: true // this is default with type=local
- name: runLocal
type: boolean
default: false
Expand Down Expand Up @@ -3143,6 +3159,8 @@
description: |
The following example are assumed to run with the field property `runLocal` true.
They are ran in the sandbox of the browser and can leverage the full javascript engine.
**Tip** : use the type `local` as an alias for 'type=expression, runLocal=true, hide=true, noOutput=true'
examples:
- name: naming convention
description: Use string manipulations to apply naming conventions
Expand Down
11 changes: 9 additions & 2 deletions server/src/controllers/schema.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ var RestResult = require('../models/restResult.model');
exports.hasSchema = function(req, res) {
Schema.hasSchema()
.then((result)=>{ res.json(new RestResult("success","schema and tables are ok",result.data?.success,result.data?.failed)) })
.catch((result)=>{ res.json(new RestResult("error","schema and tables are not ok",result.data?.success,result.data?.failed)) })
.catch((result)=>{
if(!result?.data){
res.json(new RestResult("error","FATAL ERROR",[],[result.message]))
}else{
res.json(new RestResult("error","schema and tables are not ok",result.data?.success,result.data?.failed))
}

})
};
exports.create = function(req, res) {
Schema.create()
.then((result)=>{res.json(new RestResult("success",result,null,""))})
.then((result)=>{ res.json(new RestResult("success",result,null,""))})
.catch((err)=>{res.json(new RestResult("error",err,null,null))})
};
Loading

0 comments on commit 12350dc

Please sign in to comment.