add frontend frame and service logic
@ -0,0 +1,31 @@
|
|||||||
|
DEBUG=frame:*
|
||||||
|
|
||||||
|
OAUTH2_HOST=https://p01.bergx.io
|
||||||
|
WELL_KNOWN=https://p01.bergx.io/.well-known/openid-configuration
|
||||||
|
AUTHORIZATION_URL=https://p01.bergx.io/oauth/dialog/authorize
|
||||||
|
TOKEN_URL=https://p01.bergx.io/oauth/token
|
||||||
|
CLIENT_ID={{oauth-client-id}}
|
||||||
|
CLIENT_SECRET={{oauth-client-secret}}
|
||||||
|
|
||||||
|
# Update this to be your host name
|
||||||
|
CALLBACK_URL={{your-host-name}}/auth/callback
|
||||||
|
|
||||||
|
BX_CLIENT_ID={{bergx-client-id}}
|
||||||
|
BX_CLIENT_SECRET={{bergx-client-secret}}
|
||||||
|
|
||||||
|
|
||||||
|
# DB stuff
|
||||||
|
DB_HOST={{db-host}}
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_USER={{db-user}}
|
||||||
|
DB_PASSWORD={db-user-password}}
|
||||||
|
DB_NAME={{db-name}}
|
||||||
|
|
||||||
|
# Session stuff
|
||||||
|
DOMAIN={{your-host-name}}
|
||||||
|
DB_HOST={{session-db-host}}
|
||||||
|
DB_PORT=3306
|
||||||
|
SESSION_DB_USER={{session-db-user}}
|
||||||
|
SESSION_DB_PASSWORD={{session-db-password}}
|
||||||
|
SESSION_DB_NAME={{session-db-name}}
|
||||||
|
SESSION_SECRET={{session-db-user-password
|
||||||
|
23
frontend-frame/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
.DS_Store
|
||||||
|
node_modules
|
||||||
|
/dist
|
||||||
|
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# Log files
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
24
frontend-frame/README.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# frontend-frame
|
||||||
|
|
||||||
|
## Project setup
|
||||||
|
```
|
||||||
|
yarn install
|
||||||
|
```
|
||||||
|
|
||||||
|
### Compiles and hot-reloads for development
|
||||||
|
```
|
||||||
|
yarn serve
|
||||||
|
```
|
||||||
|
|
||||||
|
### Compiles and minifies for production
|
||||||
|
```
|
||||||
|
yarn build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Lints and fixes files
|
||||||
|
```
|
||||||
|
yarn lint
|
||||||
|
```
|
||||||
|
|
||||||
|
### Customize configuration
|
||||||
|
See [Configuration Reference](https://cli.vuejs.org/config/).
|
5
frontend-frame/babel.config.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
'@vue/cli-plugin-babel/preset'
|
||||||
|
]
|
||||||
|
}
|
51
frontend-frame/package.json
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend-frame",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"serve": "vue-cli-service serve",
|
||||||
|
"build": "vue-cli-service build",
|
||||||
|
"lint": "vue-cli-service lint"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"core-js": "^3.6.5",
|
||||||
|
"register-service-worker": "^1.7.1",
|
||||||
|
"vue": "^2.6.11",
|
||||||
|
"vue-class-component": "^7.2.3",
|
||||||
|
"vue-property-decorator": "^9.1.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@typescript-eslint/eslint-plugin": "^4.18.0",
|
||||||
|
"@typescript-eslint/parser": "^4.18.0",
|
||||||
|
"@vue/cli-plugin-babel": "~4.5.0",
|
||||||
|
"@vue/cli-plugin-eslint": "~4.5.0",
|
||||||
|
"@vue/cli-plugin-pwa": "~4.5.0",
|
||||||
|
"@vue/cli-plugin-typescript": "~4.5.0",
|
||||||
|
"@vue/cli-service": "~4.5.0",
|
||||||
|
"@vue/eslint-config-typescript": "^7.0.0",
|
||||||
|
"eslint": "^6.7.2",
|
||||||
|
"eslint-plugin-vue": "^6.2.2",
|
||||||
|
"typescript": "~4.1.5",
|
||||||
|
"vue-template-compiler": "^2.6.11"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"root": true,
|
||||||
|
"env": {
|
||||||
|
"node": true
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"plugin:vue/essential",
|
||||||
|
"eslint:recommended",
|
||||||
|
"@vue/typescript/recommended"
|
||||||
|
],
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2020
|
||||||
|
},
|
||||||
|
"rules": {}
|
||||||
|
},
|
||||||
|
"browserslist": [
|
||||||
|
"> 1%",
|
||||||
|
"last 2 versions",
|
||||||
|
"not dead"
|
||||||
|
]
|
||||||
|
}
|
BIN
frontend-frame/public/favicon.ico
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
frontend-frame/public/img/icons/android-chrome-192x192.png
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
frontend-frame/public/img/icons/android-chrome-512x512.png
Normal file
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 6.3 KiB |
After Width: | Height: | Size: 22 KiB |
BIN
frontend-frame/public/img/icons/apple-touch-icon-120x120.png
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
frontend-frame/public/img/icons/apple-touch-icon-152x152.png
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
frontend-frame/public/img/icons/apple-touch-icon-180x180.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
frontend-frame/public/img/icons/apple-touch-icon-60x60.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
frontend-frame/public/img/icons/apple-touch-icon-76x76.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
frontend-frame/public/img/icons/apple-touch-icon.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
frontend-frame/public/img/icons/favicon-16x16.png
Normal file
After Width: | Height: | Size: 799 B |
BIN
frontend-frame/public/img/icons/favicon-32x32.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
frontend-frame/public/img/icons/msapplication-icon-144x144.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
frontend-frame/public/img/icons/mstile-150x150.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
3
frontend-frame/public/img/icons/safari-pinned-tab.svg
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M8.00251 14.9297L0 1.07422H6.14651L8.00251 4.27503L9.84583 1.07422H16L8.00251 14.9297Z" fill="black"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 215 B |
17
frontend-frame/public/index.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
|
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||||
|
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>
|
||||||
|
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||||
|
</noscript>
|
||||||
|
<div id="app"></div>
|
||||||
|
<!-- built files will be auto injected -->
|
||||||
|
</body>
|
||||||
|
</html>
|
2
frontend-frame/public/robots.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
User-agent: *
|
||||||
|
Disallow:
|
31
frontend-frame/src/App.vue
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<template>
|
||||||
|
<div id="app">
|
||||||
|
|
||||||
|
<!-- SYSTEM-BUILDER-list-components-html -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { Component, Vue } from 'vue-property-decorator';
|
||||||
|
import HelloWorld from './components/HelloWorld.vue';
|
||||||
|
// SYSTEM-BUILDER-list-components-imports
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
components: {
|
||||||
|
// SYSTEM-BUILDER-list-components-decorator
|
||||||
|
},
|
||||||
|
})
|
||||||
|
export default class App extends Vue {}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#app {
|
||||||
|
font-family: Avenir, Helvetica, Arial, sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
text-align: center;
|
||||||
|
color: #2c3e50;
|
||||||
|
margin-top: 60px;
|
||||||
|
}
|
||||||
|
</style>
|
BIN
frontend-frame/src/assets/logo.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
60
frontend-frame/src/components/HelloWorld.vue
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<template>
|
||||||
|
<div class="hello">
|
||||||
|
<h1>{{ msg }}</h1>
|
||||||
|
<p>
|
||||||
|
For a guide and recipes on how to configure / customize this project,<br>
|
||||||
|
check out the
|
||||||
|
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
|
||||||
|
</p>
|
||||||
|
<h3>Installed CLI Plugins</h3>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
|
||||||
|
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-typescript" target="_blank" rel="noopener">typescript</a></li>
|
||||||
|
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa" target="_blank" rel="noopener">pwa</a></li>
|
||||||
|
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint" target="_blank" rel="noopener">eslint</a></li>
|
||||||
|
</ul>
|
||||||
|
<h3>Essential Links</h3>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://vuejs.org" target="_blank" rel="noopener">Core Docs</a></li>
|
||||||
|
<li><a href="https://forum.vuejs.org" target="_blank" rel="noopener">Forum</a></li>
|
||||||
|
<li><a href="https://chat.vuejs.org" target="_blank" rel="noopener">Community Chat</a></li>
|
||||||
|
<li><a href="https://twitter.com/vuejs" target="_blank" rel="noopener">Twitter</a></li>
|
||||||
|
<li><a href="https://news.vuejs.org" target="_blank" rel="noopener">News</a></li>
|
||||||
|
</ul>
|
||||||
|
<h3>Ecosystem</h3>
|
||||||
|
<ul>
|
||||||
|
<li><a href="https://router.vuejs.org" target="_blank" rel="noopener">vue-router</a></li>
|
||||||
|
<li><a href="https://vuex.vuejs.org" target="_blank" rel="noopener">vuex</a></li>
|
||||||
|
<li><a href="https://github.com/vuejs/vue-devtools#vue-devtools" target="_blank" rel="noopener">vue-devtools</a></li>
|
||||||
|
<li><a href="https://vue-loader.vuejs.org" target="_blank" rel="noopener">vue-loader</a></li>
|
||||||
|
<li><a href="https://github.com/vuejs/awesome-vue" target="_blank" rel="noopener">awesome-vue</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||||
|
|
||||||
|
@Component
|
||||||
|
export default class HelloWorld extends Vue {
|
||||||
|
@Prop() private msg!: string;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
||||||
|
<style scoped>
|
||||||
|
h3 {
|
||||||
|
margin: 40px 0 0;
|
||||||
|
}
|
||||||
|
ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
li {
|
||||||
|
display: inline-block;
|
||||||
|
margin: 0 10px;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: #42b983;
|
||||||
|
}
|
||||||
|
</style>
|
@ -0,0 +1,27 @@
|
|||||||
|
<template>
|
||||||
|
<div class="{{component}}-editor">
|
||||||
|
<div class="property-row">
|
||||||
|
<label>Grant Name: </label>
|
||||||
|
<div>grant.name</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- SYSTEM-BUILDER-property-row -->
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||||
|
import { {{Component}}Config } from './{{component}}Types.ts';
|
||||||
|
|
||||||
|
@Component
|
||||||
|
export default class {{Component}}Editor extends Vue {
|
||||||
|
@Prop() private {{component}}!: {{Component}}Config;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="css">
|
||||||
|
.errorMessage {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
</style>
|
@ -0,0 +1,66 @@
|
|||||||
|
<template>
|
||||||
|
<div class="{{component}}-editor">
|
||||||
|
<div class="input-row">
|
||||||
|
<label>Grant Name: </label>
|
||||||
|
<input class="form-control" type="text" ref="name" placeholder="Grant Name" v-model="grant.name" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- SYSTEM-BUILDER-input-row -->
|
||||||
|
|
||||||
|
<div class="errorMessage" v-if="errorMessage != ''">{{errorMessage}}</div>
|
||||||
|
<div class="action-buttons">
|
||||||
|
<button class="btn" @click="close()">Cancel</button>
|
||||||
|
<button class="btn btn-secondary" :disabled="!isComplete" @click="isComplete && save{{Component}}()">Save</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||||
|
import { {{component}}Service } from './{{component}}Service.ts';
|
||||||
|
import { {{Component}}Config } from './{{component}}Types.ts';
|
||||||
|
|
||||||
|
@Component
|
||||||
|
export default class {{Component}}Editor extends Vue {
|
||||||
|
@Prop() private {{component}}!: {{Component}}Config;
|
||||||
|
private loading: boolean = false;
|
||||||
|
private errorMessage: string = '';
|
||||||
|
|
||||||
|
get isComplete() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private save{{Component}}() {
|
||||||
|
this.loading = true;
|
||||||
|
this.errorMessage = '';
|
||||||
|
// either create or update...
|
||||||
|
if (this.{{component}}.id === '') { // TODO: use the primary key instead of 'id' here
|
||||||
|
{{component}}Service.create{{Component}}(this.{{component}}).then(() => {
|
||||||
|
// success
|
||||||
|
this.loading = false;
|
||||||
|
this.errorMessage = '';
|
||||||
|
this.close();
|
||||||
|
}).catch(this.handleError.bind(this));
|
||||||
|
} else {
|
||||||
|
{{component}}Service.update{{Component}}(this.{{component}}).then(() => {
|
||||||
|
// success
|
||||||
|
this.loading = false;
|
||||||
|
this.errorMessage = '';
|
||||||
|
this.close();
|
||||||
|
}).catch(this.handleError.bind(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleError(err: any) {
|
||||||
|
// error
|
||||||
|
this.loading = false;
|
||||||
|
this.errorMessage = err.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="css">
|
||||||
|
.errorMessage {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
</style>
|
@ -0,0 +1,52 @@
|
|||||||
|
<template>
|
||||||
|
<div class="{{component}}-editor">
|
||||||
|
<div>TODO: search</div>
|
||||||
|
|
||||||
|
<div v-for="item in items" :key="item.id" class="input-row">
|
||||||
|
<div class="">{{ item.id }}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="errorMessage" v-if="errorMessage != ''">{{errorMessage}}</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||||
|
import { {{component}}Service } from './{{component}}Service.ts';
|
||||||
|
import { {{Component}}Config } from './{{component}}Types.ts';
|
||||||
|
|
||||||
|
@Component
|
||||||
|
export default class {{Component}}Editor extends Vue {
|
||||||
|
private items!: {{Component}}Config[];
|
||||||
|
private loading: boolean = false;
|
||||||
|
private errorMessage: string = '';
|
||||||
|
// SYSTEM-BUILDER-component-variables
|
||||||
|
|
||||||
|
// SYSTEM-BUILDER-component-functions
|
||||||
|
|
||||||
|
private get{{Component}}s() {
|
||||||
|
this.loading = true;
|
||||||
|
this.errorMessage = '';
|
||||||
|
{{component}}Service.get{{Component}}s().then((listItems: {{Component}}Config[]) => {
|
||||||
|
// success
|
||||||
|
this.loading = false;
|
||||||
|
this.errorMessage = '';
|
||||||
|
this.items = listItems;
|
||||||
|
}).catch(this.handleError.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add a search function if there is an endpoint with type 'search'
|
||||||
|
|
||||||
|
private handleError(err: any) {
|
||||||
|
// error
|
||||||
|
this.loading = false;
|
||||||
|
this.errorMessage = err.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="css">
|
||||||
|
.errorMessage {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
</style>
|
@ -0,0 +1,13 @@
|
|||||||
|
import { del, get, post, put } from '@/services/fetch';
|
||||||
|
|
||||||
|
class {{Component}}Service {
|
||||||
|
// SYSTEM-BUILDER-service-variables
|
||||||
|
// SYSTEM-BUILDER-service-functions
|
||||||
|
}
|
||||||
|
|
||||||
|
let {{component}}Service = new {{Component}}Service();
|
||||||
|
|
||||||
|
export {
|
||||||
|
{{component}}Service,
|
||||||
|
{{Component}}Service
|
||||||
|
};
|
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
// SYSTEM-BUILDER-{{component}}-interfaces
|
||||||
|
|
||||||
|
// e.g.
|
||||||
|
// interface {{Component}}Config {
|
||||||
|
// }
|
||||||
|
|
||||||
|
export {
|
||||||
|
// SYSTEM-BUILDER-{{component}}-exports
|
||||||
|
};
|
9
frontend-frame/src/main.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import App from './App.vue'
|
||||||
|
import './registerServiceWorker'
|
||||||
|
|
||||||
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
|
new Vue({
|
||||||
|
render: h => h(App),
|
||||||
|
}).$mount('#app')
|
32
frontend-frame/src/registerServiceWorker.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
|
import { register } from 'register-service-worker'
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||||
|
ready () {
|
||||||
|
console.log(
|
||||||
|
'App is being served from cache by a service worker.\n' +
|
||||||
|
'For more details, visit https://goo.gl/AFskqB'
|
||||||
|
)
|
||||||
|
},
|
||||||
|
registered () {
|
||||||
|
console.log('Service worker has been registered.')
|
||||||
|
},
|
||||||
|
cached () {
|
||||||
|
console.log('Content has been cached for offline use.')
|
||||||
|
},
|
||||||
|
updatefound () {
|
||||||
|
console.log('New content is downloading.')
|
||||||
|
},
|
||||||
|
updated () {
|
||||||
|
console.log('New content is available; please refresh.')
|
||||||
|
},
|
||||||
|
offline () {
|
||||||
|
console.log('No internet connection found. App is running in offline mode.')
|
||||||
|
},
|
||||||
|
error (error) {
|
||||||
|
console.error('Error during service worker registration:', error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
100
frontend-frame/src/services/fetch.ts
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
declare var window: any;
|
||||||
|
const defaultBasePath = '';
|
||||||
|
|
||||||
|
export function fetchAsync(method: 'GET' | 'POST' | 'DELETE' | 'PUT', url: string, body?: any) {
|
||||||
|
const headers = { 'Content-Type': 'application/json; charset=utf-8' };
|
||||||
|
// if (access_token) headers['Authorization'] = `Token ${access_token}`;
|
||||||
|
return window.fetch(`${defaultBasePath}${url}`, {
|
||||||
|
method,
|
||||||
|
headers,
|
||||||
|
body: body && JSON.stringify(body)
|
||||||
|
}).then((response: any) => {
|
||||||
|
if (response.status === 401) {
|
||||||
|
window.location.href = '/auth/login';
|
||||||
|
// throw new Error('401');
|
||||||
|
}
|
||||||
|
if (response.status === 403 && url === '/api/v1/organization/') {
|
||||||
|
// this indicates a user that is not supposed to be in bx-console
|
||||||
|
window.location.href = '/auth/logout';
|
||||||
|
}
|
||||||
|
const result = response.json();
|
||||||
|
if (!response.ok) throw result;
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function get<T>(url: string): Promise<T> {
|
||||||
|
return fetchAsync('GET', url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function post<T>(url: string, body?: any): Promise<T> {
|
||||||
|
return fetchAsync('POST', url, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function postWithFile<T>(url: string, body?: any): Promise<T> {
|
||||||
|
return fetchWithFile('POST', url, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function putWithFile<T>(url: string, body?: any): Promise<T> {
|
||||||
|
return fetchWithFile('PUT', url, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fetchWithFile<T>(method: string, url: string, body?: any): Promise<T> {
|
||||||
|
return window.fetch(`${defaultBasePath}${url}`, {
|
||||||
|
method: method,
|
||||||
|
body: body
|
||||||
|
}).then((response: any) => {
|
||||||
|
if (response.status === 401) {
|
||||||
|
window.location.href = '/auth/login';
|
||||||
|
// throw new Error('401');
|
||||||
|
}
|
||||||
|
const result = response.json();
|
||||||
|
if (!response.ok) throw result;
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function del(url: string) {
|
||||||
|
return fetchAsync('DELETE', url);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function put(url: string, body?: any) {
|
||||||
|
return fetchAsync('PUT', url, body);
|
||||||
|
}
|
||||||
|
export function toQueryString(obj: any) {
|
||||||
|
const parts = [];
|
||||||
|
for (var i in obj) {
|
||||||
|
if (obj.hasOwnProperty(i)) {
|
||||||
|
parts.push(encodeURIComponent(i) + "=" + encodeURIComponent(obj[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parts.join("&");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function serializeObject<T>(form: any) {
|
||||||
|
let obj: {[key: string]: any} = {};
|
||||||
|
if (typeof form == 'object' && form.nodeName == "FORM") {
|
||||||
|
for (let i = 0; i < form.elements.length; i++) {
|
||||||
|
const field = form.elements[i];
|
||||||
|
if (field.name
|
||||||
|
&& field.type != 'file'
|
||||||
|
&& field.type != 'reset'
|
||||||
|
&& field.type != 'submit'
|
||||||
|
&& field.type != 'button') {
|
||||||
|
if (field.type == 'select-multiple') {
|
||||||
|
obj[field.name] = '';
|
||||||
|
let tempvalue = '';
|
||||||
|
for (let j = 0; j < form.elements[i].options.length; j++) {
|
||||||
|
if (field.options[j].selected)
|
||||||
|
tempvalue += field.options[j].value + ';';
|
||||||
|
}
|
||||||
|
if (tempvalue.charAt(tempvalue.length - 1) === ';') obj[field.name] = tempvalue.substring(0, tempvalue.length - 1);
|
||||||
|
|
||||||
|
} else if ((field.type != 'checkbox' && field.type != 'radio') || field.checked) {
|
||||||
|
obj[field.name] = field.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj as T;
|
||||||
|
}
|
13
frontend-frame/src/shims-tsx.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import Vue, { VNode } from 'vue'
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
namespace JSX {
|
||||||
|
// tslint:disable no-empty-interface
|
||||||
|
interface Element extends VNode {}
|
||||||
|
// tslint:disable no-empty-interface
|
||||||
|
interface ElementClass extends Vue {}
|
||||||
|
interface IntrinsicElements {
|
||||||
|
[elem: string]: any
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4
frontend-frame/src/shims-vue.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
declare module '*.vue' {
|
||||||
|
import Vue from 'vue'
|
||||||
|
export default Vue
|
||||||
|
}
|
40
frontend-frame/tsconfig.json
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "esnext",
|
||||||
|
"module": "esnext",
|
||||||
|
"strict": true,
|
||||||
|
"jsx": "preserve",
|
||||||
|
"importHelpers": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"baseUrl": ".",
|
||||||
|
"types": [
|
||||||
|
"webpack-env"
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": [
|
||||||
|
"src/*"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"lib": [
|
||||||
|
"esnext",
|
||||||
|
"dom",
|
||||||
|
"dom.iterable",
|
||||||
|
"scripthost"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts",
|
||||||
|
"src/**/*.tsx",
|
||||||
|
"src/**/*.vue",
|
||||||
|
"tests/**/*.ts",
|
||||||
|
"tests/**/*.tsx"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules"
|
||||||
|
]
|
||||||
|
}
|
9198
frontend-frame/yarn.lock
Normal file
@ -7,7 +7,7 @@
|
|||||||
"pluralize": "^8.0.0"
|
"pluralize": "^8.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "rm -rf dist && tsc && cp -r frame dist/ && cd dist && node index.js"
|
"start": "rm -rf dist && tsc && cp -r frame dist/ && cp -r frontend-frame dist/ && cd dist && node index.js"
|
||||||
},
|
},
|
||||||
"name": "system-builder",
|
"name": "system-builder",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -1,19 +1,13 @@
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import {
|
import {
|
||||||
SystemDef,
|
|
||||||
StorageDef,
|
StorageDef,
|
||||||
EndpointDef,
|
|
||||||
Order,
|
|
||||||
Filter,
|
|
||||||
TableDef,
|
TableDef,
|
||||||
ColumnDef,
|
ColumnDef,
|
||||||
BelongsToDef,
|
BelongsToDef,
|
||||||
ManyToManyDef
|
ManyToManyDef
|
||||||
} from '../systemGenService';
|
} from '../systemGenService';
|
||||||
|
|
||||||
let outDir = 'test';
|
|
||||||
|
|
||||||
export function createDatabase(storageDef: StorageDef) {
|
export function createDatabase(storageDef: StorageDef) {
|
||||||
let tableCreationQueries: string[] = [];
|
let tableCreationQueries: string[] = [];
|
||||||
let tableDeletionQueries: string[] = [];
|
let tableDeletionQueries: string[] = [];
|
||||||
|
@ -124,6 +124,7 @@ let def: SystemDef = {
|
|||||||
filters: [
|
filters: [
|
||||||
{
|
{
|
||||||
param: 'list',
|
param: 'list',
|
||||||
|
type: 'string',
|
||||||
column: {
|
column: {
|
||||||
name: 'list_id',
|
name: 'list_id',
|
||||||
table: 'task'
|
table: 'task'
|
||||||
@ -133,6 +134,7 @@ let def: SystemDef = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
param: 'completed',
|
param: 'completed',
|
||||||
|
type: 'boolean',
|
||||||
column: {
|
column: {
|
||||||
name: 'completed',
|
name: 'completed',
|
||||||
table: 'task'
|
table: 'task'
|
||||||
@ -176,6 +178,7 @@ let def: SystemDef = {
|
|||||||
filters: [
|
filters: [
|
||||||
{
|
{
|
||||||
param: 'list',
|
param: 'list',
|
||||||
|
type: 'string',
|
||||||
column: {
|
column: {
|
||||||
name: 'list_id',
|
name: 'list_id',
|
||||||
table: 'task'
|
table: 'task'
|
||||||
@ -185,6 +188,7 @@ let def: SystemDef = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
param: 'completed',
|
param: 'completed',
|
||||||
|
type: 'boolean',
|
||||||
column: {
|
column: {
|
||||||
name: 'completed',
|
name: 'completed',
|
||||||
table: 'task'
|
table: 'task'
|
||||||
@ -194,6 +198,7 @@ let def: SystemDef = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
param: 'name',
|
param: 'name',
|
||||||
|
type: 'string',
|
||||||
column: {
|
column: {
|
||||||
name: 'name',
|
name: 'name',
|
||||||
table: 'task'
|
table: 'task'
|
||||||
@ -203,6 +208,7 @@ let def: SystemDef = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
param: 'description',
|
param: 'description',
|
||||||
|
type: 'string',
|
||||||
column: {
|
column: {
|
||||||
name: 'description',
|
name: 'description',
|
||||||
table: 'task'
|
table: 'task'
|
||||||
@ -246,6 +252,7 @@ let def: SystemDef = {
|
|||||||
filters: [
|
filters: [
|
||||||
{
|
{
|
||||||
param: 'list',
|
param: 'list',
|
||||||
|
type: 'string',
|
||||||
column: {
|
column: {
|
||||||
name: 'list_id',
|
name: 'list_id',
|
||||||
table: 'task'
|
table: 'task'
|
||||||
@ -255,6 +262,7 @@ let def: SystemDef = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
param: 'completed',
|
param: 'completed',
|
||||||
|
type: 'boolean',
|
||||||
column: {
|
column: {
|
||||||
name: 'completed',
|
name: 'completed',
|
||||||
table: 'task'
|
table: 'task'
|
||||||
@ -273,23 +281,27 @@ let def: SystemDef = {
|
|||||||
name: 'name',
|
name: 'name',
|
||||||
table: 'task',
|
table: 'task',
|
||||||
param: 'name',
|
param: 'name',
|
||||||
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'list_id',
|
name: 'list_id',
|
||||||
table: 'task',
|
table: 'task',
|
||||||
param: 'list',
|
param: 'list',
|
||||||
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'description',
|
name: 'description',
|
||||||
table: 'task',
|
table: 'task',
|
||||||
param: 'description'
|
param: 'description',
|
||||||
|
type: 'string'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'completed',
|
name: 'completed',
|
||||||
table: 'task',
|
table: 'task',
|
||||||
param: 'completed'
|
param: 'completed',
|
||||||
|
type: 'boolean',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@ -302,21 +314,25 @@ let def: SystemDef = {
|
|||||||
name: 'name',
|
name: 'name',
|
||||||
table: 'task',
|
table: 'task',
|
||||||
param: 'name',
|
param: 'name',
|
||||||
|
type: 'string'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'description',
|
name: 'description',
|
||||||
table: 'task',
|
table: 'task',
|
||||||
param: 'description'
|
param: 'description',
|
||||||
|
type: 'string'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'completed',
|
name: 'completed',
|
||||||
table: 'task',
|
table: 'task',
|
||||||
param: 'completed'
|
param: 'completed',
|
||||||
|
type: 'boolean'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'completed_date',
|
name: 'completed_date',
|
||||||
table: 'task',
|
table: 'task',
|
||||||
param: 'completedDate'
|
param: 'completedDate',
|
||||||
|
type: 'string'
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
filters: [
|
filters: [
|
||||||
@ -327,6 +343,7 @@ let def: SystemDef = {
|
|||||||
},
|
},
|
||||||
comparison: '=',
|
comparison: '=',
|
||||||
param: 'task',
|
param: 'task',
|
||||||
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -344,6 +361,7 @@ let def: SystemDef = {
|
|||||||
},
|
},
|
||||||
comparison: '=',
|
comparison: '=',
|
||||||
param: 'task',
|
param: 'task',
|
||||||
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -382,6 +400,7 @@ let def: SystemDef = {
|
|||||||
},
|
},
|
||||||
comparison: '=',
|
comparison: '=',
|
||||||
param: 'task',
|
param: 'task',
|
||||||
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@ -428,6 +447,7 @@ let def: SystemDef = {
|
|||||||
filters: [
|
filters: [
|
||||||
{
|
{
|
||||||
param: 'user',
|
param: 'user',
|
||||||
|
type: 'string',
|
||||||
column: {
|
column: {
|
||||||
name: 'user_id',
|
name: 'user_id',
|
||||||
table: 'list_user'
|
table: 'list_user'
|
||||||
|
94
src/frontend-services/fe-service-creator.ts
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import {ComponentDef, EndpointDef, SystemDef} from "../systemGenService";
|
||||||
|
import path from "path";
|
||||||
|
import {initializeComponentFile} from "../helpers";
|
||||||
|
import fs from "fs";
|
||||||
|
import {buildServiceFunctionName, getFuncParams} from "../views/service-creator";
|
||||||
|
import {METHOD, URL} from "../views/routes-creator";
|
||||||
|
const ncp = require('ncp').ncp;
|
||||||
|
|
||||||
|
export function createFrontend(systemDef: SystemDef) {
|
||||||
|
let fePromises = [];
|
||||||
|
for (let i in systemDef.components) {
|
||||||
|
fePromises.push(createComponent(systemDef.components[i], systemDef));
|
||||||
|
// TODO: add a vue view and add it to App.vue
|
||||||
|
}
|
||||||
|
return Promise.all(fePromises);
|
||||||
|
}
|
||||||
|
|
||||||
|
function componentSource() {
|
||||||
|
return path.join(process.cwd(), 'frontend-frame', 'src', 'components', '{{component}}');
|
||||||
|
}
|
||||||
|
|
||||||
|
function componentDestination(systemDefName: string, componentName: string) {
|
||||||
|
return path.join(process.cwd(), `frontend-${systemDefName}`, 'src', 'components', componentName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createComponent(component: ComponentDef, systemDef: SystemDef) {
|
||||||
|
return new Promise<void>((componentResolve, componentReject) => {
|
||||||
|
ncp(componentSource(), componentDestination(systemDef.name, component.component), (err: any) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
componentReject();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
let componentDest: string = componentDestination(systemDef.name, component.component);
|
||||||
|
let servicePromise = initializeComponentFile(path.join(componentDest, '{{component}}Service.ets'), path.join(componentDest, `${component.component}Service.ts`), component.component, systemDef.name);
|
||||||
|
for (let i in component.endpoints) {
|
||||||
|
servicePromise = servicePromise.then(() => {
|
||||||
|
return insertFEServiceCode(component.endpoints[i], componentDest);
|
||||||
|
});
|
||||||
|
// TODO: use templates for Details, Editor, List and Types view based on the endpoints provided
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertFEServiceCode(view: EndpointDef, outDir: string) {
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
const separator: string = `// SYSTEM-BUILDER-service-functions`;
|
||||||
|
let fileLocation = path.join(outDir, `${view.component}Service.ts`)
|
||||||
|
let initServiceFile: string = fs.readFileSync(fileLocation, 'utf8');
|
||||||
|
let parts = initServiceFile.split(separator);
|
||||||
|
parts[0] = parts[0] + createFEServiceFunc(view);
|
||||||
|
let newServiceFile = parts.join(separator);
|
||||||
|
fs.writeFileSync(fileLocation, newServiceFile, 'utf8');
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createFEServiceFunc(view: EndpointDef): string {
|
||||||
|
let func: string = '';
|
||||||
|
let isListOrSearch: boolean = view.type === 'list' || view.type === 'search';
|
||||||
|
let funcName: string = buildServiceFunctionName(view);
|
||||||
|
let funcParams: string[] = getFuncParams(view, true);
|
||||||
|
let columnParams: string[] = view.columns?.filter(column => column.param).map(column => { return '\n ' + column.param + ': ' + column.param; });
|
||||||
|
let filterParams: string[] = view.filters?.filter(filter => filter.param).map(filter => { return '\n ' + filter.param + ': ' + filter.param; }) || [];
|
||||||
|
|
||||||
|
if (isListOrSearch) {
|
||||||
|
funcParams.push('offset: number');
|
||||||
|
funcParams.push('limit: number');
|
||||||
|
filterParams.push('\n offset: offset');
|
||||||
|
filterParams.push('\n limit: limit');
|
||||||
|
}
|
||||||
|
|
||||||
|
let isGetOrDelete = view.type === 'item' || view.type === 'delete';
|
||||||
|
let method = METHOD[view.type];
|
||||||
|
if (method === 'delete') {
|
||||||
|
method = 'del';
|
||||||
|
}
|
||||||
|
|
||||||
|
func = `
|
||||||
|
public ${funcName}(${funcParams.join(', ')}) {`;
|
||||||
|
|
||||||
|
if (!isGetOrDelete) {
|
||||||
|
func = func + `
|
||||||
|
let params = {${columnParams}${columnParams.length ? ',' : ''}${filterParams}
|
||||||
|
};`;
|
||||||
|
}
|
||||||
|
func = func + `
|
||||||
|
return ${method}('/api/v1/${URL[view.type](view)}${isGetOrDelete ? '/\' + ' + funcParams[0].split(":")[0] : '\', params'});
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
return func;
|
||||||
|
}
|
46
src/helpers.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
import {EndpointDef} from "./systemGenService";
|
||||||
|
import path from "path";
|
||||||
|
import {createServiceFunc} from "./views/service-creator";
|
||||||
|
|
||||||
|
function uppercaseFirstLetter(input: string) {
|
||||||
|
return input.charAt(0).toUpperCase() + input.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function lowercaseFirstLetter(input: string) {
|
||||||
|
return input.charAt(0).toLowerCase() + input.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initializeComponentFile(sourceFile: string, destinationFile: string, component: string, outDir: string) {
|
||||||
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
fs.rename(sourceFile, destinationFile, (err: any) => {
|
||||||
|
let fileContents = fs.readFileSync(destinationFile, 'utf8');
|
||||||
|
var uppercaseFirstLetterComponentName = uppercaseFirstLetter(component);
|
||||||
|
var lowercaseFirstLetterComponentName = lowercaseFirstLetter(component);
|
||||||
|
let newFileContents = fileContents.split('{{Component}}').join(uppercaseFirstLetterComponentName);
|
||||||
|
newFileContents = newFileContents.split('{{component}}').join(lowercaseFirstLetterComponentName);
|
||||||
|
fs.writeFileSync(destinationFile, newFileContents, 'utf8');
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertServiceCode(view: EndpointDef, outDir: string): Promise<void> {
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
const separator: string = `// SYSTEM-BUILDER-${view.component}-service`;
|
||||||
|
let fileLocation = path.join(process.cwd(), outDir, 'src', 'components', view.component, `${view.component}Service.ts`);
|
||||||
|
let initServiceFile: string = fs.readFileSync(fileLocation, 'utf8');
|
||||||
|
let parts = initServiceFile.split(separator);
|
||||||
|
parts[0] = parts[0] + createServiceFunc(view);
|
||||||
|
let newServiceFile = parts.join(separator);
|
||||||
|
fs.writeFileSync(fileLocation, newServiceFile, 'utf8');
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
uppercaseFirstLetter,
|
||||||
|
lowercaseFirstLetter,
|
||||||
|
initializeComponentFile,
|
||||||
|
insertServiceCode
|
||||||
|
}
|
@ -2,12 +2,14 @@ import * as path from 'path';
|
|||||||
const ncp = require('ncp').ncp;
|
const ncp = require('ncp').ncp;
|
||||||
import { createDatabase, writeMigrationsToFile } from './database/database-creator';
|
import { createDatabase, writeMigrationsToFile } from './database/database-creator';
|
||||||
import { createViews } from './views/views-creator';
|
import { createViews } from './views/views-creator';
|
||||||
|
import {createFrontend} from "./frontend-services/fe-service-creator";
|
||||||
|
|
||||||
class SystemGenService {
|
class SystemGenService {
|
||||||
|
|
||||||
public runSysGen(defs: SystemDef) {
|
public runSysGen(defs: SystemDef) {
|
||||||
ncp(path.join(process.cwd(), 'frame'), path.join(process.cwd(), defs.name), (err: any) => {
|
ncp(path.join(process.cwd(), 'frame'), path.join(process.cwd(), defs.name), (err: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
console.log("error in ncp");
|
||||||
console.log(err);
|
console.log(err);
|
||||||
} else {
|
} else {
|
||||||
console.log('success copying files');
|
console.log('success copying files');
|
||||||
@ -15,6 +17,16 @@ class SystemGenService {
|
|||||||
this.buildViews(defs, defs.name);
|
this.buildViews(defs, defs.name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ncp(path.join(process.cwd(), 'frontend-frame'), path.join(process.cwd(), `frontend-${defs.name}`), (err: any) => {
|
||||||
|
if (err) {
|
||||||
|
console.log("error in frontend ncp");
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
console.log("success copying frontend files");
|
||||||
|
this.buildFrontend(defs);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public buildDatabase(storage: StorageDef, outDir: string) {
|
public buildDatabase(storage: StorageDef, outDir: string) {
|
||||||
@ -25,6 +37,14 @@ class SystemGenService {
|
|||||||
public buildViews(systemDef: SystemDef, outDir: string) {
|
public buildViews(systemDef: SystemDef, outDir: string) {
|
||||||
createViews(systemDef);
|
createViews(systemDef);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public buildFrontend(systemDef: SystemDef) {
|
||||||
|
createFrontend(systemDef);
|
||||||
|
}
|
||||||
|
|
||||||
|
public cleanup() {
|
||||||
|
// TODO: remove 'component/{{component}}' folder
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const systemGenService = new SystemGenService();
|
const systemGenService = new SystemGenService();
|
||||||
@ -69,6 +89,7 @@ interface Filter {
|
|||||||
column: ColumnRef;
|
column: ColumnRef;
|
||||||
comparison: '=' | '!=' | '>' | '<' | 'contains' | 'LIKE';
|
comparison: '=' | '!=' | '>' | '<' | 'contains' | 'LIKE';
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
|
type?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface TableDef {
|
interface TableDef {
|
||||||
@ -91,6 +112,7 @@ interface ColumnRef {
|
|||||||
table: string;
|
table: string;
|
||||||
param?: string;
|
param?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
|
type?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ValueDef {
|
interface ValueDef {
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
function uppercaseFirstLetter(input: string)
|
|
||||||
{
|
|
||||||
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function lowercaseFirstLetter(input: string)
|
|
||||||
{
|
|
||||||
return input.charAt(0).toLowerCase() + input.slice(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
uppercaseFirstLetter,
|
|
||||||
lowercaseFirstLetter
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
import {ColumnRef, EndpointDef, Filter, JoinDef, Order} from "../systemGenService";
|
import {ColumnRef, EndpointDef, Filter, JoinDef, Order} from "../systemGenService";
|
||||||
import pluralize from "pluralize";
|
import pluralize from "pluralize";
|
||||||
import {uppercaseFirstLetter, lowercaseFirstLetter} from "./helpers";
|
import {uppercaseFirstLetter, lowercaseFirstLetter} from "../helpers";
|
||||||
|
|
||||||
function createMapperFunc(view: EndpointDef): string {
|
function createMapperFunc(view: EndpointDef): string {
|
||||||
let func: string = '';
|
let func: string = '';
|
||||||
@ -171,7 +171,7 @@ function constructFilters(view: EndpointDef, isSearch=false) {
|
|||||||
*/
|
*/
|
||||||
optionalFilterParts = optionalFilterParts + `
|
optionalFilterParts = optionalFilterParts + `
|
||||||
if (params.${f.param}) {
|
if (params.${f.param}) {
|
||||||
query = query + ' ${isSearch ? 'OR' : 'AND'} ${f.column.table}.${f.column.name} ${isSearch ? 'LIKE' : f.comparison} ?';
|
query = query + ' ${isSearch ? 'OR' : 'AND'} ${f.column.table}.${f.column.name} ${f.comparison} ?';
|
||||||
queryValues.push(${isSearch ? '\'%\' + params.' + f.param + ' + \'%\'' : 'params.' + f.param});
|
queryValues.push(${isSearch ? '\'%\' + params.' + f.param + ' + \'%\'' : 'params.' + f.param});
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
@ -186,7 +186,7 @@ function buildGetList(view: EndpointDef, isSearch=false): string {
|
|||||||
// This would be so much simpler and easy if it were just the queries wanted
|
// This would be so much simpler and easy if it were just the queries wanted
|
||||||
let func: string = '';
|
let func: string = '';
|
||||||
let funcName: string = '';
|
let funcName: string = '';
|
||||||
let columns: string = view.type === 'count' ? `count(*)` : `${view.component}.${view.component}_id, ${view.columns.map(c => `${c.table}.${c.name}`).join(', ')}`;
|
let columns: string = view.type === 'count' ? `count(*) as Count` : `${view.component}.${view.component}_id, ${view.columns.map(c => `${c.table}.${c.name}`).join(', ')}`;
|
||||||
let query: string = '';
|
let query: string = '';
|
||||||
let tables: string = view.join?.length ? buildJoin(view) : `${view.table}`;
|
let tables: string = view.join?.length ? buildJoin(view) : `${view.table}`;
|
||||||
funcName = buildMapperFunctionName(view);
|
funcName = buildMapperFunctionName(view);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {EndpointDef} from "../systemGenService";
|
import {EndpointDef} from "../systemGenService";
|
||||||
import {lowercaseFirstLetter, uppercaseFirstLetter} from "./helpers";
|
import {lowercaseFirstLetter, uppercaseFirstLetter} from "../helpers";
|
||||||
import {buildServiceFunctionName, getFuncParams} from "./service-creator";
|
import {buildServiceFunctionName, getFuncParams} from "./service-creator";
|
||||||
import pluralize from "pluralize";
|
import pluralize from "pluralize";
|
||||||
|
|
||||||
@ -70,5 +70,7 @@ function serviceInstance(view: EndpointDef): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
createRoutesFunc
|
createRoutesFunc,
|
||||||
|
METHOD,
|
||||||
|
URL
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
import {ColumnDef, EndpointDef, Filter} from "../systemGenService";
|
import {ColumnDef, EndpointDef, Filter} from "../systemGenService";
|
||||||
import {lowercaseFirstLetter} from "./helpers";
|
import {lowercaseFirstLetter} from "../helpers";
|
||||||
import {buildMapperFunctionName} from "./mapper-creator";
|
import {buildMapperFunctionName} from "./mapper-creator";
|
||||||
|
|
||||||
|
|
||||||
@ -31,19 +31,21 @@ function buildServiceFunction(view: EndpointDef): string {
|
|||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFuncParams(view: EndpointDef): string[] {
|
function getFuncParams(view: EndpointDef, addTypes=false): string[] {
|
||||||
let filters = view.filters || [];
|
let filters = view.filters || [];
|
||||||
let columnList: ParamDef[] = view.columns?.filter((column) => {return column.param;}).map((column) => {
|
let columnList: ParamDef[] = view.columns?.filter((column) => {return column.param;}).map((column) => {
|
||||||
return {
|
return {
|
||||||
param: column.param,
|
param: column.param,
|
||||||
required: column.required
|
required: column.required,
|
||||||
|
type: column.type
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
let filterList: ParamDef[] = filters.filter((column) => {return column.param;}).map((filter) => {
|
let filterList: ParamDef[] = filters.filter((column) => {return column.param;}).map((filter) => {
|
||||||
return {
|
return {
|
||||||
param: filter.param,
|
param: filter.param,
|
||||||
required: filter.required
|
required: filter.required,
|
||||||
|
type: filter.type
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -62,6 +64,9 @@ function getFuncParams(view: EndpointDef): string[] {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return combinedList.map((param) => {
|
return combinedList.map((param) => {
|
||||||
|
if (param.type && addTypes) {
|
||||||
|
return `${param.param}: ${param.type}`;
|
||||||
|
}
|
||||||
return param.param || ''; // both lists have already been filtered so the value should never return as an empty string
|
return param.param || ''; // both lists have already been filtered so the value should never return as an empty string
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -77,6 +82,7 @@ function mapperInstance(view: EndpointDef): string {
|
|||||||
interface ParamDef {
|
interface ParamDef {
|
||||||
param?: string;
|
param?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
|
type?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -6,8 +6,7 @@ import {
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import {createMapperFunc} from "./mapper-creator";
|
import {createMapperFunc} from "./mapper-creator";
|
||||||
import {uppercaseFirstLetter, lowercaseFirstLetter} from "./helpers";
|
import {initializeComponentFile, insertServiceCode} from "../helpers";
|
||||||
import {createServiceFunc} from "./service-creator";
|
|
||||||
import {createRoutesFunc} from "./routes-creator";
|
import {createRoutesFunc} from "./routes-creator";
|
||||||
|
|
||||||
const ncp = require('ncp').ncp;
|
const ncp = require('ncp').ncp;
|
||||||
@ -26,6 +25,8 @@ function createComponent(component: ComponentDef, systemDef: SystemDef) {
|
|||||||
ncp(path.join(process.cwd(), 'frame', 'src', 'components', '{{component}}'), path.join(process.cwd(), systemDef.name, 'src', 'components', component.component), (err: any) => {
|
ncp(path.join(process.cwd(), 'frame', 'src', 'components', '{{component}}'), path.join(process.cwd(), systemDef.name, 'src', 'components', component.component), (err: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
componentReject();
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
let mapperPromise = initializeComponentFile(path.join(process.cwd(), systemDef.name, 'src', 'components', component.component, '{{component}}Mapper.ets'), path.join(process.cwd(), systemDef.name, 'src', 'components', component.component, `${component.component}Mapper.ts`), component.component, systemDef.name);
|
let mapperPromise = initializeComponentFile(path.join(process.cwd(), systemDef.name, 'src', 'components', component.component, '{{component}}Mapper.ets'), path.join(process.cwd(), systemDef.name, 'src', 'components', component.component, `${component.component}Mapper.ts`), component.component, systemDef.name);
|
||||||
for (let i in component.endpoints) {
|
for (let i in component.endpoints) {
|
||||||
@ -53,25 +54,10 @@ function createComponent(component: ComponentDef, systemDef: SystemDef) {
|
|||||||
componentResolve();
|
componentResolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// TODO: remove {{component}} folder that hasn't been used
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeComponentFile(sourceFile: string, destinationFile: string, component: string, outDir: string) {
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
|
||||||
fs.rename(sourceFile, destinationFile, (err: any) => {
|
|
||||||
let fileContents = fs.readFileSync(destinationFile, 'utf8');
|
|
||||||
var uppercaseFirstLetterComponentName = uppercaseFirstLetter(component);
|
|
||||||
var lowercaseFirstLetterComponentName = lowercaseFirstLetter(component);
|
|
||||||
let newFileContents = fileContents.split('{{Component}}').join(uppercaseFirstLetterComponentName);
|
|
||||||
newFileContents = newFileContents.split('{{component}}').join(lowercaseFirstLetterComponentName);
|
|
||||||
fs.writeFileSync(destinationFile, newFileContents, 'utf8');
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function addInitializeServiceCode(component: string, outDir: string) {
|
function addInitializeServiceCode(component: string, outDir: string) {
|
||||||
let fileLocation = path.join(process.cwd(), outDir, 'src', 'initializeServices.ts');
|
let fileLocation = path.join(process.cwd(), outDir, 'src', 'initializeServices.ts');
|
||||||
let initServicesFile: string = fs.readFileSync(fileLocation, 'utf8');
|
let initServicesFile: string = fs.readFileSync(fileLocation, 'utf8');
|
||||||
@ -113,19 +99,6 @@ function insertMapperCode(view: EndpointDef, outDir: string): Promise<void> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertServiceCode(view: EndpointDef, outDir: string): Promise<void> {
|
|
||||||
return new Promise<void>((resolve) => {
|
|
||||||
const separator: string = `// SYSTEM-BUILDER-${view.component}-service`;
|
|
||||||
let fileLocation = path.join(process.cwd(), outDir, 'src', 'components', view.component, `${view.component}Service.ts`);
|
|
||||||
let initServiceFile: string = fs.readFileSync(fileLocation, 'utf8');
|
|
||||||
let parts = initServiceFile.split(separator);
|
|
||||||
parts[0] = parts[0] + createServiceFunc(view);
|
|
||||||
let newServiceFile = parts.join(separator);
|
|
||||||
fs.writeFileSync(fileLocation, newServiceFile, 'utf8');
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function insertRoutesCode(view: EndpointDef, outDir: string): Promise<void> {
|
function insertRoutesCode(view: EndpointDef, outDir: string): Promise<void> {
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
const separator: string = `// SYSTEM-BUILDER-${view.component}-routes`;
|
const separator: string = `// SYSTEM-BUILDER-${view.component}-routes`;
|
||||||
|