Compare commits

..

38 Commits

Author SHA1 Message Date
Aurian JAULT e912930876 LAST COMMIT I HOPE
2 years ago
Aurian JAULT a7ef15726f derniere question
2 years ago
Aurian JAULT 358b399337 Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Aurian JAULT d9ffadb627 API fetch fonctionne
2 years ago
Bastien JACQUELIN 4b7af38fe5 auto increment <orking well
2 years ago
Aurian JAULT 964aa2f3c1 Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Aurian JAULT 43b8eee1fd fixe about v-for in home module
2 years ago
Aurian JAULT 16cdd797d6 Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Aurian JAULT cd863e76b7 update
2 years ago
Aurian JAULT d0a39549a4 Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Aurian JAULT 4974a831d8 update
2 years ago
Aurian JAULT df6d0e2305 Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Aurian JAULT cbffb21b00 coucou
2 years ago
Bastien JACQUELIN d3542591af Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Bastien JACQUELIN 6b467be21f id auto Increment
2 years ago
Aurian JAULT eaa131b29a CLEANING
2 years ago
Bastien JACQUELIN d544873864 Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Bastien JACQUELIN 4be186466a module home
2 years ago
Aurian JAULT 95f699e17a merge
2 years ago
Aurian JAULT f648e4dc27 nouvel element
2 years ago
Bastien JACQUELIN 24e6f4ff27 Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Bastien JACQUELIN 7d9f5ddd5e new module
2 years ago
Bastien JACQUELIN f6e4045fde Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Bastien JACQUELIN df9e050c32 sqdqsd
2 years ago
Bastien JACQUELIN 87d30198c7 add div home
2 years ago
Bastien JACQUELIN 232ca3b928 change name
2 years ago
Bastien JACQUELIN e7696557c5 add constraint if no team, button not display
2 years ago
Bastien JACQUELIN da8f034983 export option
2 years ago
Bastien JACQUELIN ad671bc9dc edit completly functional : fill autpo fields
2 years ago
Bastien JACQUELIN 7a6055a663 Merge branch 'master' of https://codefirst.iut.uca.fr/git/JavaScript-TP_note/Projet-note
2 years ago
Bastien JACQUELIN c25a135d98 link in api parameter
2 years ago
Bastien JACQUELIN 4e1aad113b update api
2 years ago
Bastien JACQUELIN 1e6b265bd8 question 9
2 years ago
Bastien JACQUELIN 388bf4a194 question 8
2 years ago
Bastien JACQUELIN c6d76d18c4 begin question 8
2 years ago
Bastien JACQUELIN 7b42b3dca7 question 7 donee
2 years ago
Bastien JACQUELIN 82fe3b02e6 end of question 7 - error management and red borders
2 years ago
Aurian JAULT 3735137d42 Merge pull request 'Teamcard' (#1) from Teamcard into master
2 years ago

@ -9,9 +9,9 @@
<body> <body>
<div id="app"> <div id="app">
<h1>TP-noté</h1> <h1>TP-noté</h1>
<nav-bar @add-team="addTeam"></nav-bar> <nav-bar></nav-bar>
<team-card v-for="team in teams" <team-card @edit-team="editTeam" v-for="team in teams"
:id="team.id" :id="team.id"
:nom="team.name" :nom="team.name"
:description="team.description"> :description="team.description">
@ -20,29 +20,33 @@
<script src="src/service/link-service.js"></script> <script src="src/service/link-service.js"></script>
<script src="src/class/team.js"></script> <script src="src/class/team.js"></script>
<script src="src/class/api-service.js"></script>
<script src="src/class/news-service.js"></script>
<script src="src/misc/const.js"></script> <script src="src/misc/const.js"></script>
<script src="main.js"></script> <script src="main.js"></script>
<script type="module"> <script type="module">
import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'; import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js';
import NavBar from '/src/view/nav-bar.js'; import NavBar from '/src/view/nav-bar.js';
import TeamCard from '/src/view/team-card.js'; import TeamCard from '/src/view/team-card.js';
import NewsCard from '/src/view/news-card.js';
const app = createApp({ const app = createApp({
created(){}, created(){},
data(){ data(){
return{ return{
teams: [] teams: [],
edit:false,
newTeam:null,
news: []
} }
}, },
methods:{ methods:{
addTeam: function(equipe){
console.log(equipe);
this.teams.push(equipe);
}
} }
}); });
app.component('NavBar', NavBar);
app.component('TeamCard', TeamCard); app.component('TeamCard', TeamCard);
app.component('NewsCard',NewsCard);
app.component('NavBar', NavBar);
app.mount('#app'); app.mount('#app');
</script> </script>

@ -1,2 +1,3 @@
let linkService = new LinkService(); let linkService = new LinkService();
linkService.getLinks(); linkService.getLinks();

@ -4,8 +4,12 @@
"description": "2a tp note js", "description": "2a tp note js",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {
"serve": "npx serv",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "jault aurian & jacquelin bastien", "author": "jault aurian & jacquelin bastien",
"license": "ISC" "license": "ISC",
"keywords": [
"JavaScript"
]
} }

@ -0,0 +1,29 @@
class ApiService{
constructor(){}
async get(link){
const baseUrl = `${link}`;//edit
const headers = {
method: 'GET'
};
let response = await fetch(baseUrl, headers);
let responseJson = await response.json()
return responseJson
}
async post(link,value){
const baseUrl = `${link}`;//edit
const headers = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(value)
};
fetch(baseUrl, headers).then( (response) => {
if (response.ok)
console.log("Posted")
else
throw new Error('Une erreur est survenue durant l\'appel HTTP.');
})
}
}

@ -0,0 +1,15 @@
class NewsService{
constructor(){}
async getNews(){
const url = "https://newsapi.org/v2/everything?q=esport&apiKey=1639059dc5a942089bd2d29db40ee7e7";
const api = new ApiService()
let response = await api.get(url);
let tab = []
for (let i = 0; i < 5; i++) {
tab.push(response.articles[i]);
}
return tab;
}
}

@ -0,0 +1 @@
const KEYAPI = "1639059dc5a942089bd2d29db40ee7e7"

@ -1,82 +1,220 @@
export default{ export default{
emits: ['addTeam'],
data : function(){ data : function(){
return { return {
Home: '', teams:[],
Teams: '', news: [],
Results: '', id: 1,
id:'',
name:'', name:'',
description:'', description:'',
clicked: false, teamClicked: false,
errMessage:'' homeClicked: false,
resultsClicked: false,
errMessage:'',
errMessageMatch: '',
edit:false,
idxEdit:null
} }
}, },
methods: { methods: {
myfun: function() { clickTeams: function() {
this.clicked=!this.clicked; if(!this.teamClicked){
this.teamClicked=true;
this.homeClicked=false;
this.resultsClicked=false;
}
else{
this.teamClicked=false;
}
}, },
checkFields: function() { clickHome: async function() {
if(this.id===""){ if(!this.homeClicked){
this.errMessage+="The id field must be required " const api = new NewsService();
let infos = await api.getNews();
this.news = infos
this.homeClicked=true;
this.teamClicked=false;
this.resultsClicked=false;
} }
else if(this.name===""){ else{
this.errMessage+="The name field must be required " this.homeClicked=false;
} }
else if(this.description===""){ },
this.errMessage+="The description field must be required " clickResults: function(){
if(!this.resultsClicked)
{
this.resultsClicked = true;
this.teamClicked=false;
this.homeClicked=false;
}
else{
this.resultsClicked = false
}
},
checkFields: function() {
this.errMessage="";
document.querySelector("#name").removeAttribute("style");
document.querySelector("#desc").removeAttribute("style");
if(this.name===""||this.description===""){
this.errMessage+="The";
if(this.name===""){
this.errMessage+=" name";
document.querySelector("#name").setAttribute("style","border: 1px solid #d66");
}
if(this.description===""){
this.errMessage+=" description";
document.querySelector("#desc").setAttribute("style","border: 1px solid #d66");
}
this.errMessage+=" field must be required ";
} }
else{ else{
if(this.name.lenght<5){ if(this.name.lenght<5){
this.errMessage+="The name must have at least 5 caracters " this.errMessage+="The name must have at least 5 caracters ";
} }
if(this.description.lenght<20){ if(this.description.lenght<20){
this.description+="The description must have at least 20 caracters " this.description+="The description must have at least 20 caracters ";
} }
} }
if(this.errMessage.length===0){ if(this.errMessage.length===0){
console.log("jappelle la fonction")
this.addTeam(); this.addTeam();
} }
}, },
addTeam: function() { addTeam: function(){
let team = new Team(this.id, this.name, this.description); if(!this.edit){//adding a team
console.log(team); let team = new Team(this.id, this.name, this.description);
this.$emit("addTeam",team); console.log(team);
this.id=''; this.teams.push(team);
this.name=''; this.name='';
this.description='';
this.id=this.id+1
}
else{//editing a team
let team = new Team(this.teams[this.idxEdit].id, this.name, this.description);
console.log(team);
this.teams[this.idxEdit]=team;
this.name='';
this.description='';
this.edit=false;
}
}, },
myfun: function() { editTeam: function (team) {
console.log("gngn"); this.edit=!this.edit;
this.clicked=!this.clicked; this.teams.forEach((e,idx) => {
} if(e.id==team.id&&e.name==team.name&&e.description==team.description){
this.idxEdit=idx;
}
});
if(this.edit){
this.name=team.name ;
this.description=team.description;
}
else{
this.name='';
this.description='';
}
},
Export:function(){
console.log(JSON.stringify(this.teams))
},
Match: function(){
this.errMessageMatch=""
const equipe1 = document.querySelector("#equipe1").value
const equipe2 = document.querySelector("#equipe2").value
const stringEquipe1Score = document.querySelector("#equipe1Score").value
const stringEquipe2Score = document.querySelector("#equipe2Score").value
const equipe1Score = parseInt(stringEquipe1Score);
const equipe2Score = parseInt(stringEquipe2Score);
const res = this.teams.filter(item => item.name === equipe1)
const res2 = this.teams.filter(item => item.name === equipe2)
console.log(res)
console.log(res2)
let tab = [res,res2]
if (equipe1Score=="" || equipe2Score=="") {
this.errMessageMatch="Veuillez rentrer le score de TOUTES les equipes";
return;
}
if (equipe1Score < 0 || equipe2Score < 0) {
this.errMessageMatch = "Veuilez rentre un score positif";
return
}
try {
const api = ApiService();
api.post("http://www.post-result.com",tab)
} catch (Error) {
this.errMessageMatch="Une erreur sur la requette POST"
}
}
}, },
template: template:
` `
<div> <div>
<span>Home</span> <span @click="clickHome" style="cursor: pointer">Home</span>
<span @click="myfun" style="cursor: pointer">Teams</span> <span @click="clickTeams" style="cursor: pointer">Teams</span>
<span>Results</span> <span @click="clickResults" style="cursor: pointer">Results</span>
</div>
<form @submit.prevent v-if="clicked">
<br>
<label>{{errMessage}}</label><br/>
<div>
<label>id</label><br/>
<input type="number" v-model="id"/>
</div> </div>
<div v-if="homeClicked">
<news-card v-for="info in news"
:title="info.title"
:date="info.publishedAt"/>
</div>
<div id="Teams" v-if="teamClicked">
<form @submit.prevent>
<br>
<label>{{errMessage}}</label><br/>
<div> <div>
<label>Name</label><br/> <label>Name</label><br/>
<input type="text" v-model="name"/> <input id="name" type="text" v-model="name"/>
</div> </div>
<div> <div>
<label>Description</label><br/> <label>Description</label><br/>
<textarea v-model="description"></textarea> <textarea id="desc" v-model="description"></textarea>
</div>
<input type="submit" value="Submit" v-on:click="checkFields"/>
</form>
<team-card @edit-team="editTeam" v-for="team in teams"
:id="team.id"
:nom="team.name"
:description="team.description">
</team-card>
<input type="submit" value="Export" v-if="teams.length>0" v-on:click="Export" />
</div> </div>
<input type="submit" value="Submit" v-on:click="checkFields"/>
</form>
<div v-if="resultsClicked">
<label>{{errMessageMatch}}</label><br/>
<form @submit.prevent>
<label for="equipe1">Choose a Team1:</label>
<select name="equipe1" id="equipe1">
<option v-for="team in teams"
:value="team.name"
:label="team.name"/>
</select>
<span>Entre le score de l'équipe</span>
<input type="number" id="equipe1Score">
<br><br>
<label for="equipe2">Choose a Team2:</label>
<select name="equipe2" id="equipe2">
<option v-for="team in teams"
:value="team.name"
:label="team.name"/>
</select>
<span>Entre le score de l'équipe</span>
<input type="number" id="equipe2Score">
<br><br>
<input type="submit" value="Submit" v-on:click="Match">
</form>
</div>
` `
} }

@ -0,0 +1,12 @@
export default{
props: {
title: String,
date: String
},
template: `
<article>
<span>{{title}}</span>
<p>{{date.replace(/-/gi, "/").replace("Z", "").replace("T"," ").replace(":","h").split(":")[0]}}</p>
</article>
`
}

@ -1,19 +1,20 @@
export default{ export default{
emits: ['editTeam'],
props: { props: {
id: Number, id: Number,
nom: String, nom: String,
description: String description: String
}, },
methods: { methods: {
test: function(){ edit: function() {
console.log("test") this.$emit("editTeam", new Team(this.id,this.nom,this.description))
} }
}, },
template: ` template: `
<br>
<div id="teamCard"> <div id="teamCard">
<span>{{id}} {{nom}} description: {{description.slice(0,20)}}</span> <span>{{id}} {{nom}} description: {{description}}</span>
<br> <span @click="edit" style="cursor: pointer"> - éditer</span>
<span v-on:click="test">Editer</span>
</div> </div>
` `
} }

Loading…
Cancel
Save