Simple cards displaying and actions.

This commit is contained in:
aminecmi 2021-10-30 16:27:29 +02:00
parent 1b2fbfc7f8
commit 2bfcc80f0e
7 changed files with 82 additions and 63 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -4,7 +4,6 @@
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0"> <meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title> <title><%= htmlWebpackPlugin.options.title %></title>
</head> </head>
<body> <body>

View File

@ -1,17 +1,16 @@
<template> <template>
<div id="app"> <div id="app">
<img alt="Vue logo" src="./assets/logo.png"> <Table/>
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div> </div>
</template> </template>
<script> <script>
import HelloWorld from './components/HelloWorld.vue' import Table from './components/Table.vue'
export default { export default {
name: 'App', name: 'App',
components: { components: {
HelloWorld Table
} }
} }
</script> </script>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -1,58 +0,0 @@
<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>

59
src/components/Table.vue Normal file
View File

@ -0,0 +1,59 @@
<template>
<div>
<h1>Table</h1>
<button v-on:click="reset()">RESET</button>
<button v-on:click="initHand()">Tirer des cartes</button>
<div v-if="cards != null && cards.length > 0">
<h2>Cartes</h2>
<div v-for="card in cards" v-bind:key="card">
{{card}}
</div>
<button v-on:click="sortMyHand()">Tirer des cartes</button>
</div>
<div v-if="sortResult != null">
<h2>Cartes Triées</h2>
<h3><em>Shape order : {{sortResult.shapeOrder}}</em></h3>
<h3><em>Number order : {{sortResult.numberOrder}}</em></h3>
<div v-for="card in sortResult.sortedCards" v-bind:key="card">
{{card}}
</div>
</div>
</div>
</template>
<script>
import {getHand, sortHand, resetDeck} from '../services/DeckService'
export default {
name: "Table",
data() {
return {
cards: [],
sortResult: null
}
},
methods: {
initHand() {
this.sortResult = null;
getHand().then(r => {
this.cards = r;
})
},
sortMyHand() {
sortHand(this.cards).then(r => {
this.sortResult = r;
});
},
reset() {
this.cards = null;
this.sortResult = null;
resetDeck();
}
}
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,20 @@
export async function getHand() {
const response = await fetch('http://localhost:8080/api/deck/hand');
return await response.json();
}
export async function sortHand(hand) {
const response = await fetch(`http://localhost:8080/api/deck/hand:sort`, {
method: 'PUT',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(hand)
})
return await response.json();
}
export async function resetDeck() {
const response = await fetch(`http://localhost:8080/api/deck:reset`, {
method: 'PUT'
})
await response;
}