Thymeleaf + Vue application

This commit is contained in:
Tom Hombergs
2020-06-08 21:51:46 +10:00
parent b8c0923f23
commit 5e0f15e4cc
34 changed files with 19241 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
.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?
/coverage/
/.storybook/
/build/

View File

@@ -0,0 +1,24 @@
# client
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run serve
```
### Compiles and minifies for production
```
npm run build
```
### Lints and fixes files
```
npm run 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,9 @@
plugins {
id "com.github.node-gradle.node" version "2.2.4"
}
task build(type: NpmTask) {
inputs.dir("src")
outputs.dir("dist")
args = ['run', 'build']
}

View File

@@ -0,0 +1,10 @@
module.exports = {
preset: "@vue/cli-plugin-unit-jest",
collectCoverage: true,
collectCoverageFrom: ["src/**/*.{js,vue}", "!**/node_modules/**"],
coverageReporters: ["html", "text-summary"],
setupFilesAfterEnv: [
"./jest/console-error-to-exception.setup.js",
"./jest/mock-canvas.setup.js"
]
};

View File

@@ -0,0 +1,35 @@
import { format } from "util";
/**
* Log UnhandledRejection exceptions to console.error to be picked up by
* below logging patterns. This will cause tests to fail when Vue components
* are missing required props, for example.
*/
process.on("unhandledRejection", (error) => {
// Will print "unhandledRejection err is not defined"
console.error("unhandledRejection", error.message);
});
/**
* Intercept calls to console.error and fail a test on certain logging patterns.
*/
beforeEach(() => {
const { error } = global.console;
global.console.error = (...args) => {
for (let i = 0; i < args.length; i += 1) {
const arg = args[i];
// add patterns here that should fail a test
if (
typeof arg === "string" &&
(arg.includes("Vue warn") ||
arg.includes("unhandledRejection") ||
arg.includes("Not implemented"))
) {
throw new Error(format(...args));
}
}
error(...args);
};
});

View File

@@ -0,0 +1,2 @@
// Import mock canvas to be able to assert canvas operations.
import 'jest-canvas-mock';

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,56 @@
{
"name": "client",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build --target lib --dest dist/WeekChart --name WeekChart src/components/WeekChart.vue",
"lint": "vue-cli-service lint",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"test": "vue-cli-service test:unit"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"chart.js": "^2.9.3"
},
"devDependencies": {
"@babel/core": "^7.10.2",
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-links": "^5.3.19",
"@storybook/addons": "^5.3.19",
"@storybook/vue": "^5.3.19",
"@vue/cli-plugin-babel": "~4.4.0",
"@vue/cli-plugin-eslint": "~4.4.0",
"@vue/cli-service": "~4.4.0",
"@vue/cli-plugin-unit-jest": "^4.4.0",
"@vue/test-utils": "^1.0.3",
"jest-canvas-mock": "^2.2.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-preset-vue": "^2.0.2",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}

View File

@@ -0,0 +1,28 @@
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'App',
components: {
HelloWorld
}
}
</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,58 @@
<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-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>
export default {
name: 'HelloWorld',
props: {
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,44 @@
<template>
<div class="chart-container">
<canvas ref="chart"></canvas>
</div>
</template>
<script>
import Chart from "chart.js";
export default {
name: "WeekChart",
props: {
chartData: {
type: Array,
required: true,
},
},
mounted: function() {
const config = {
type: "bar",
data: {
labels: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
datasets: [
{
data: this.chartData
},
]
},
};
new Chart(this.$refs.chart, config);
}
};
</script>
<style scoped>
.chart-container {
position: relative;
height: 100%;
width: 100%;
}
</style>

View File

@@ -0,0 +1,8 @@
import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')

View File

@@ -0,0 +1,16 @@
import { shallowMount } from "@vue/test-utils";
import WeekChart from "../../components/WeekChart.vue";
describe("WeekChart", () => {
it("renders without error", () => {
const wrapper = shallowMount(WeekChart, {
propsData: {
chartData: [1, 2, 3, 4, 5, 6, 7],
},
});
const chart = wrapper.findComponent({ name: "WeekChart" });
expect(chart.exists()).toBe(true);
});
});

View File

@@ -0,0 +1,18 @@
import { linkTo } from '@storybook/addon-links';
import Welcome from './Welcome';
export default {
title: 'Welcome',
component: Welcome,
};
export const ToStorybook = () => ({
components: { Welcome },
template: '<welcome :showApp="action" />',
methods: { action: linkTo('Button') },
});
ToStorybook.story = {
name: 'to Storybook',
};

View File

@@ -0,0 +1,29 @@
import { action } from '@storybook/addon-actions';
import { linkTo } from '@storybook/addon-links';
import MyButton from './MyButton';
export default {
title: 'Button',
component: MyButton,
};
export const Text = () => ({
components: { MyButton },
template: '<my-button @click="action">Hello Button</my-button>',
methods: { action: action('clicked') },
});
export const Jsx = () => ({
components: { MyButton },
render(h) {
return <my-button onClick={this.action}>With JSX</my-button>;
},
methods: { action: linkTo('clicked') },
});
export const Emoji = () => ({
components: { MyButton },
template: '<my-button @click="action">😀 😎 👍 💯</my-button>',
methods: { action: action('clicked') },
});

View File

@@ -0,0 +1,29 @@
export default {
name: 'my-button',
data() {
return {
buttonStyles: {
border: '1px solid #eee',
borderRadius: 3,
backgroundColor: '#FFFFFF',
cursor: 'pointer',
fontSize: 15,
padding: '3px 10px',
margin: 10,
},
};
},
template: `
<button :style="buttonStyles" @click="onClick">
<slot></slot>
</button>
`,
methods: {
onClick() {
this.$emit('click');
},
},
};

View File

@@ -0,0 +1,13 @@
import WeekChart from '../src/components/WeekChart.vue';
export default {
title: 'WeekChart',
component: WeekChart,
};
export const DefaultState = () => ({
components: {
chart: WeekChart
},
template: `<chart v-bind:chartData="[1,2,3,4,5,6,7]" />`
});

View File

@@ -0,0 +1,121 @@
// eslint-disable-next-line no-console
const log = () => console.log('Welcome to storybook!');
export default {
name: 'welcome',
props: {
showApp: {
type: Function,
default: log,
},
},
data() {
return {
main: {
padding: 15,
lineHeight: 1.4,
fontFamily: '"Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif',
backgroundColor: '#ffffff',
},
logo: {
width: 200,
},
link: {
color: '#1474f3',
textDecoration: 'none',
borderBottom: '1px solid #1474f3',
paddingBottom: 2,
},
code: {
fontSize: 15,
fontWeight: 600,
padding: '2px 5px',
border: '1px solid #eae9e9',
borderRadius: 4,
backgroundColor: '#f3f2f2',
color: '#3a3a3a',
},
note: {
opacity: 0.5,
},
};
},
template: `
<div :style="main">
<h1>Welcome to STORYBOOK</h1>
<p>
This is a UI component dev environment for your app.
</p>
<p>
We've added some basic stories inside the
<br />
<code :style="code">src/stories</code>
<br />
directory.
<br />
A story is a single state of one or more UI components. You can have as many stories as
you want.
<br />
(Basically a story is like a visual test case.)
</p>
<p>
See these sample
<br />
<a :style="link" @click="onClick" role="button" tabIndex="0">stories</a>
<br />
for a component called
<br />
<code :style="code">Button</code>
.
</p>
<p>
Just like that, you can add your own components as stories.
<br />
You can also edit those components and see changes right away.
<br />
(Try editing the <code :style="code">Button</code> component
located at <code :style="code">src/stories/Button.js</code>.)
</p>
<p>
This is just one thing you can do with Storybook.
<br />
Have a look at the
<br />
<a
:style="link"
href="https://github.com/storybookjs/storybook"
target="_blank"
rel="noopener noreferrer"
>
Storybook
</a>
<br />
repo for more information.
</p>
<p :style="note">
<b>NOTE:</b>
<br />
Have a look at the
<br />
<code :style="code">.storybook/webpack.config.js</code>
<br />
to add webpack
loaders and plugins you are using in this project.
</p>
</div>
`,
methods: {
onClick(event) {
event.preventDefault();
this.showApp();
},
},
};