add frontend frame and service logic
This commit is contained in:
31
frontend-frame/src/App.vue
Normal file
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
BIN
frontend-frame/src/assets/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
60
frontend-frame/src/components/HelloWorld.vue
Normal file
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
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
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
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
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
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
|
||||
}
|
Reference in New Issue
Block a user