add frontend frame and service logic

This commit is contained in:
2021-07-03 00:41:03 -05:00
parent 87312fbc86
commit be789ae882
49 changed files with 10019 additions and 65 deletions

23
frontend-frame/.gitignore vendored Normal file
View 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
View 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/).

View File

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

View 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"
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View 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

View 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>

View File

@ -0,0 +1,2 @@
User-agent: *
Disallow:

View 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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View 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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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
};

View File

@ -0,0 +1,10 @@
// SYSTEM-BUILDER-{{component}}-interfaces
// e.g.
// interface {{Component}}Config {
// }
export {
// SYSTEM-BUILDER-{{component}}-exports
};

View 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')

View 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)
}
})
}

View 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
View 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
View File

@ -0,0 +1,4 @@
declare module '*.vue' {
import Vue from 'vue'
export default Vue
}

View 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

File diff suppressed because it is too large Load Diff