modal implementation #12

Merged
vincent merged 10 commits from dev into master 2019-05-11 14:21:09 +00:00
6 changed files with 141 additions and 95 deletions

View File

@ -2,12 +2,13 @@ from bs4 import BeautifulSoup
import urllib.request
import re
from datetime import datetime, timedelta
from time import sleep
#debug
#import pprint
class Emmission(object):
loading = False
def __init__(self):
self._LoadreferencePage()
@ -19,11 +20,17 @@ class Emmission(object):
return None
print("load")
self.html = BeautifulSoup(response.read(),"html.parser")
self.timeexp=datetime.utcnow() +timedelta(minutes=5)
self.timeexp=datetime.utcnow() +timedelta(seconds=30)
def parse_emmission(self,strsearch):
if (datetime.utcnow() > self.timeexp):
if ((datetime.utcnow() > self.timeexp) and (self.loading == False)):
self.loading = True
self._LoadreferencePage()
self.loading = False
else:
while(self.loading):
sleep(0.1)
pass
strsearch=strsearch.replace('É','E')
linkchaine=self.html.find(text=re.compile(re.escape(strsearch)))
if linkchaine == None:

View File

@ -10,6 +10,8 @@
<div class="field">
<div class="control">
<input
title="entrer des numéros de chaine ou une gamme lié par un -"
autofocus
class="input"
v-on:keyup.enter="checkchaine()"
name="chaine-input"
@ -49,7 +51,7 @@
<li>
<p>{{result.emission.synopsis}}</p>
</li>
<div v-if="result.emission.casting.length!=0">
<div v-if="result.emission.casting && result.emission.casting.length!=0">
<h4 class="title is-6">casting:</h4>
<div class="list is-hoverable">
<a
@ -71,23 +73,39 @@
</div>
</div>
</div>
<modalLogin v-show="showModalLogin" @close="showModalLogin = false" />
<modal v-show="showModal" @close="showModal = false">
<p>{{modalmessage}}</p>
<button class="button is-success" @click="showModal = false">close</button>
</modal>
</div>
</template>
<script>
import { putparsechaine } from '../api';
import modalLogin from './modalLogin'
import modal from './modal'
import { EventBus } from '../utils';
export default {
name: 'chainetv',
components: {
modalLogin,
modal,
},
data() {
return {
chaine: '',
showModalLogin: false,
showModal: false,
modalmessage:''
};
},
methods: {
checkchaine() {
if (this.chaine === '') {
alert('rentrer un numéro');
this.modalmessage='rentrer un numéro de chaine';
this.showModal=true;
return;
}
this.$store.state.arrayresultchaines = [];
@ -108,18 +126,20 @@ export default {
},
parsechaine() {
if (!this.$store.getters.isAuthenticated) {
this.$router.push('/login');
this.showModalLogin=true;
} else {
return putparsechaine(this.$store.state.jwt.token)
.then((res) => {
if (res.data === 'OK') {
alert('update database OK');
this.modalmessage='update database OK';
this.showModal=true;
}
})
.catch((error) => {
// eslint-disable-next-line
if (error.response) {
alert(error.response.data.message);
this.modalmessage=error.response.data.message;
this.showModal=true;
} else {
console.error(error);
}
@ -129,6 +149,11 @@ export default {
return true;
},
},
mounted() {
EventBus.$on('showmodallogin',()=>{
this.showModalLogin=true;
})
},
};
</script>
<style >

View File

@ -1,76 +0,0 @@
<!-- components/Login.vue -->
<template>
<div>
<section class="hero is-success">
<div class="hero-body">
<div class="container has-text-centered">
<h2 class="title">Login </h2>
<p class="subtitle error-msg">{{ errorMsg }}</p>
</div>
</div>
</section>
<section class="section">
<div class="container">
<div class="field">
<label class="label is-large" for="name">Name:</label>
<div class="control">
<input type="name" class="input is-large" id="email" v-model="name">
</div>
</div>
<div class="field">
<label class="label is-large" for="password">Password:</label>
<div class="control">
<input type="password" class="input is-large" id="password" v-model="password">
</div>
</div>
<div class="control">
<a class="button is-large is-success" @click="authenticate">Login</a>
</div>
</div>
</section>
</div>
</template>
<script>
import { EventBus } from '../utils';
export default {
data() {
return {
name: '',
password: '',
errorMsg: '',
};
},
methods: {
authenticate() {
this.$store.dispatch('login', { name: this.name, password: this.password })
.then(() => {
if (this.$store.getters.isAuthenticated) {
this.$router.push('/');
}
},
);
},
register() {
this.$store.dispatch('register', { name: this.name, password: this.password })
.then(() => this.$router.push('/'));
},
},
mounted() {
EventBus.$on('failedRegistering', (msg) => {
this.errorMsg = msg;
});
EventBus.$on('failedAuthentication', (msg) => {
this.errorMsg = msg;
});
},
beforeDestroy() {
EventBus.$off('failedRegistering');
EventBus.$off('failedAuthentication');
},
};
</script>

View File

@ -0,0 +1,16 @@
<template>
<div>
<div class="modal is-active">
<div class="modal-background"></div>
<button class="modal-close is-large" aria-label="close" @click="$emit('close')"></button>
<div class="modal-content box">
<slot></slot>
</div>
</div>
</div>
</template>
<script>
export default {
};
</script>

View File

@ -0,0 +1,74 @@
<!-- components/Login.vue -->
<template>
<modal @close="$emit('close')">
<div class="hero is-success">
<div class="hero-body has-text-centered">
<h2 class="title">Login</h2>
<p class="subtitle error-msg">{{ errorMsg }}</p>
</div>
</div>
<section v-on:keyup.enter="authenticate" class="section">
<div class="field">
<label class="label" for="name">Name:</label>
<div class="control">
<input type="name" class="input" id="email" v-model="name">
</div>
</div>
<div class="field">
<label class="label" for="password">Password:</label>
<div class="control">
<input type="password" class="input" id="password" v-model="password">
</div>
</div>
<div class="control">
<a class="button is-success is-large" @click="authenticate">Login</a>
</div>
</section>
</modal>
</template>
<script>
import { EventBus } from '../utils';
import modal from './modal'
export default {
data() {
return {
name: "",
password: "",
errorMsg: ""
};
},
components: {
modal
},
methods: {
authenticate() {
this.$store
.dispatch("login", { name: this.name, password: this.password })
.then(() => {
if (this.$store.getters.isAuthenticated) {
this.$emit("close");
}
});
},
register() {
this.$store
.dispatch("register", { name: this.name, password: this.password })
.then(() => this.$router.push("/"));
}
},
mounted() {
EventBus.$on("failedRegistering", msg => {
this.errorMsg = msg;
});
EventBus.$on("failedAuthentication", msg => {
this.errorMsg = msg;
});
},
beforeDestroy() {
EventBus.$off("failedRegistering");
EventBus.$off("failedAuthentication");
}
};
</script>

View File

@ -2,8 +2,8 @@ import Vue from 'vue';
import Router from 'vue-router';
import ping from '@/components/ping';
import chainetv from '@/components/chainetv';
import login from '@/components/login';
import store from '@/store';
import { EventBus } from '../utils';
Vue.use(Router);
export default new Router({
@ -13,22 +13,22 @@ export default new Router({
name: 'chaineTV',
component: chainetv,
},
{
path: '/login',
name: 'Login',
component: login,
},
{
path: '/ping',
name: 'ping',
component: ping,
beforeEnter(to, from, next) {
if (!store.getters.isAuthenticated) {
next('/login');
} else {
next();
}
autent(to,from,next)
},
},
],
});
function autent(to,from,next) {
if (!store.getters.isAuthenticated) {
next('/')
EventBus.$emit("showmodallogin")
} else {
next();
}
}