Commit 00e457db authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

mise en ligne fonction modif dico et affichage log

parent b5a568d8
......@@ -8,6 +8,7 @@ import subprocess
import re
nlp = spacy.load('fr')
logFile = "../logs/dico_frwiktionary-20200301_v2.log"
def redirApp(request):
return HttpResponseRedirect('/app/')
......@@ -107,6 +108,10 @@ def editEntry(request):
}
return JsonResponse(rep)
def getLog(request):
rep = txtphono.sendMeLogPlease()
return JsonResponse(rep)
""" def commits(request):
data = commitData()
......
......@@ -15,17 +15,15 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from hello.views import loginView, signinView, addUser
from colorapp.views import main, dicoView, editEntry, redirApp, main0, dicoReq
from colorapp.views import main, dicoView, editEntry, redirApp, main0, dicoReq, getLog
urlpatterns = [
path('admin/', admin.site.urls),
path('', redirApp),
path('signIn/', signinView),
path('addUser/', addUser),
path('app/', main),
path('app/0', main0),
path('app/dico/', dicoView),
path('dicoSearch/', dicoReq),
path('modifEntry/', editEntry)
path('modifEntry/', editEntry),
path('getLog/', getLog)
]
// Récupération de la liste des modifications du dictionnaire
var logDic = {};
getLogFile();
function getLogFile() {
$.ajax({
url: '/getLog/',
data: {},
dataType: 'json',
success: function(data) {
logDic = data;
console.log(logDic);
},
error: function(){
console.log("Impossible de récupérer le log du dico !");
}
});
}
$(document).ready(function(){
console.log('Ready.');
......@@ -63,31 +81,36 @@ $(document).ready(function(){
for (i in dico) {
cptEntr += 1;
if(cptEntr > start && cptEntr <= nb) {
var entr = i;
var entr = dico[i][0];
// Y a-t-il une trace de modification pour cette entrée ?
var logEntr = '';
if (entr in logDic) {
logEntr = '<img src="/static/im/history.png" class="logEntr" onclick="getLogOfEntr(\''+entr+'\')" title="Historique des modifications">';
}
var lienWiki = '<a href="https://fr.wiktionary.org/wiki/'+entr.replace(' ','_')+'" target="_blank"><button role="button" class="btn btn-sm" title="Consulter le Wiktionnaire">W</button></a>';
//<button role="button" class="btn btn-sm" title="Consulter le Wiktionnaire"><a href="https://fr.wiktionary.org/wiki/'+entr.replace(' ','_')+'" target="_blank"><svg class="wikiLienIcon" aria-hidden="true" focusable="false" data-prefix="fab" data-icon="wikipedia-w" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512" data-fa-i2svg=""><path fill="currentColor" d="M640 51.2l-.3 12.2c-28.1.8-45 15.8-55.8 40.3-25 57.8-103.3 240-155.3 358.6H415l-81.9-193.1c-32.5 63.6-68.3 130-99.2 193.1-.3.3-15 0-15-.3C172 352.3 122.8 243.4 75.8 133.4 64.4 106.7 26.4 63.4.2 63.7c0-3.1-.3-10-.3-14.2h161.9v13.9c-19.2 1.1-52.8 13.3-43.3 34.2 21.9 49.7 103.6 240.3 125.6 288.6 15-29.7 57.8-109.2 75.3-142.8-13.9-28.3-58.6-133.9-72.8-160-9.7-17.8-36.1-19.4-55.8-19.7V49.8l142.5.3v13.1c-19.4.6-38.1 7.8-29.4 26.1 18.9 40 30.6 68.1 48.1 104.7 5.6-10.8 34.7-69.4 48.1-100.8 8.9-20.6-3.9-28.6-38.6-29.4.3-3.6 0-10.3.3-13.6 44.4-.3 111.1-.3 123.1-.6v13.6c-22.5.8-45.8 12.8-58.1 31.7l-59.2 122.8c6.4 16.1 63.3 142.8 69.2 156.7L559.2 91.8c-8.6-23.1-36.4-28.1-47.2-28.3V49.6l127.8 1.1.2.5z"></path></svg></a></button>';
var transList = '';
for (j in dico[i]) {
transList += dico[i][j];
if (j < dico[i].length-1) transList += ', '
for (j in dico[i][1]) {
transList += dico[i][1][j];
if (j < dico[i][1].length-1) transList += ', '
}
var btnModifier = '<button id="btnModifier'+cptEntr+'" class="btn btn-primary btn-perso" onclick="modifEntry('+cptEntr+',\''+entr+'\')"><span class="glyphicon glyphicon-edit" area-hidden="true" title="Modifier"></span></button>';
var btnValider = '<button id="btnValider'+cptEntr+'" class="btn btn-success btn-perso" style="display: none;" onclick="validEntry(\''+entr+'\','+cptEntr+')"><span class="glyphicon glyphicon-ok" area-hidden="true" title="Valider"></span></button>';
var btnAnnuler = '<button id="btnAnnuler'+cptEntr+'" class="btn btn-secondary btn-perso" style="display: none;" onclick="annuler('+cptEntr+')"><span class="glyphicon glyphicon-remove" area-hidden="true" title="Annuler"></span></button>';
document.getElementById('resultTable').innerHTML += '<tr id="tr'+cptEntr+'" class="tr"><td><span class="numEntr">'+cptEntr+'</span>'+lienWiki+' '+entr+'</td><td><input class="api-kb inputTrans" disabled="true" type="text" id="td'+cptEntr+'" value="'+transList+'"></td><td style="text-align:center">'+btnModifier+btnValider+btnAnnuler+'</td></tr>';
document.getElementById('resultTable').innerHTML += '<tr id="tr'+cptEntr+'" class="tr"><td><span class="numEntr">'+cptEntr+'</span>'+lienWiki+' '+entr+'</td><td><input class="api-kb inputTrans" disabled="true" type="text" id="td'+cptEntr+'" value="'+transList+'">'+logEntr+'</td><td style="text-align:center">'+btnModifier+btnValider+btnAnnuler+'</td></tr>';
getAPIkeyboard();
}
}
lastEntrShowed = nb;
if (nb >= Object.keys(dico).length) document.getElementById('btnShowMore').style.display = 'none';
}
});
});
var entrActif = 0;
......@@ -96,7 +119,6 @@ function modifEntry(cptEntr,entr) {
if (entrActif > 0) annuler(entrActif); // désélectionne la ligne active, si elle existe.
entrActif = cptEntr;
var thisTr = 'tr'+cptEntr;
var thisTd = 'td'+cptEntr;
thisTr = document.getElementById(thisTr);
......@@ -141,6 +163,7 @@ function validEntry(entr, cptEntr) {
window.alert(data.reponse);
document.getElementById('actionBlock').style.display = 'none';
annuler(cptEntr);
getLogFile();
},
error: function(){
// document.getElementById('loader').style.display = 'none';
......@@ -149,7 +172,6 @@ function validEntry(entr, cptEntr) {
document.getElementById('actionBlock').style.display = 'none';
}
});
}
function annuler(cptEntr) {
......@@ -175,4 +197,37 @@ function annuler(cptEntr) {
thisBtnAnnuler.style.display = 'none';
entrActif = 0;
}
\ No newline at end of file
}
//////////////////////////////////////
////////// PARAMÉTRAGE POPUP /////////
////////// POUR COPIER TEXTE /////////
//////////////////////////////////////
// Get the modal
var modal = document.getElementById("myModal");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// Fonction pour ouvrir le PopUp
function getLogOfEntr(entr) {
document.getElementById('popLogH2').innerHTML = 'Entrée : <i>"'+entr+'"</i>';
var logContent = '<ul>';
for (i in logDic[entr]) {
logContent += '<li>'+logDic[entr][i].date+' : '+logDic[entr][i].oldTransList+''+logDic[entr][i].newTransList+' ('+logDic[entr][i].Type+')</li>';
}
logContent += '</ul>';
document.getElementById('popLogInner').innerHTML = logContent;
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
......@@ -20,6 +20,8 @@ from colorapp.models import Entree, DicEntry
import tempfile
import csv
from collections import OrderedDict
import locale
locale.setlocale(locale.LC_ALL, "")
from sys import path as pylib #im naming it as pylib so that we won't get confused between os.path and sys.path
pylib += [os.path.relpath(r'../phon2graph')]
......@@ -70,12 +72,16 @@ phonFile.close()
# LECTURE DU DICTIONNAIRE
word2trans = {} # un mot → liste de trans possibles
with open(dicFile, 'r') as f:
word2trans = json.load(f)
word2trans = json.load(f)
print('len frwiki :',len(word2trans))
# LECTURE DU LOG
logDic = {}
with open(logFile, 'r') as logf:
logDic = json.load(logf)
def mimi(mot):
# Enregistrement de la casse
caseMemory = []
......@@ -146,7 +152,7 @@ def getEntryByWord(m,mc,t,tc):
if re.match(tc1+t+tc2,trans.replace('.','')):
transOK = True
if transOK: result[entree] = transList
return OrderedDict(sorted(result.items()))
return sorted(result.items(), key=lambda M: locale.strxfrm(M[0])) #OrderedDict(sorted(result.items()))
def modifEntry(user,mot,newTransList):
newTransList = newTransList.split(',')
......@@ -160,17 +166,32 @@ def modifEntry(user,mot,newTransList):
print("Modification du dictionnaire par",user,": mot =",mot,"; oldTransList =",oldTransList,"; newTransList = ",newTransList)
return "Modification effectuée avec succès !"
def rewriteDico():
with tempfile.NamedTemporaryFile(dir='.', delete=False, mode="w") as tmp:
json.dump(word2trans, tmp, ensure_ascii=False)
os.replace(tmp.name, dicFile)
print('Dico rewritten.')
def sendMeLogPlease():
return logDic
def writeLog(Type,user,mot,oldTransList,newTransList):
with open(logFile, mode="a") as logf:
now = datetime.datetime.now()
date = "{}-{}-{} {}:{}:{}".format(now.year, now.month, now.day, now.hour, now.minute, now.second)
logf.write("{},{},{},{},{},{}\n".format(date,user,mot,oldTransList,newTransList,Type))
now = datetime.datetime.now()
date = "{}-{}-{} {}:{}:{}".format(now.year, now.month, now.day, now.hour, now.minute, now.second)
if mot not in logDic.keys(): logDic[mot] = []
logDic[mot].append({
"date":date,
"user":user,
"oldTransList":oldTransList,
"newTransList":newTransList,
"Type":Type
})
with tempfile.NamedTemporaryFile(dir='.', delete=False, mode="w") as tmp:
json.dump(logDic, tmp, ensure_ascii=False, indent=4)
os.replace(tmp.name, logFile)
print("Log file updated.")
......
......@@ -27,7 +27,7 @@
animation-name: animatetop;
animation-duration: 0.4s
}
/* Add Animation */
@-webkit-keyframes animatetop {
from {top:-300px; opacity:0}
......@@ -59,7 +59,7 @@
background-color: #5cb85c;
color: white;
}
.modal-body {padding: 20px 16px;}
.modal-body p {
text-align: left;
......@@ -119,4 +119,37 @@
font-size: 2em;
text-align: left;
/* font-weight: bold; */
}
/* POP LOG */
.modal-content2 {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 50%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
text-align: left;
}
.modal-header2 {
padding: 2px 16px;
background-color: #7fbaf1;
}
.modal-header2 h2 {
font-size: 1.5em;
}
#popLogH2 {
font-size: 20pt;
}
.modal-footer2 {
padding: 2px 16px;
background-color: #7fbaf1;
font-style: italic;
text-align: right;
}
\ No newline at end of file
......@@ -265,6 +265,13 @@ tr:hover {
height: 1em;
}
.logEntr {
display: inline-block;
height: 25px;
margin-left: -5px;
cursor: pointer;
}
.dicEntry {
display: -ms-flexbox; /* IE10 */
display: flex;
......
......@@ -10,6 +10,7 @@
<script src="{% static 'scripts/jquery.keyboard.js'%}"></script>
<link href="{% static 'styles/keyboard-dark.css'%}" rel="stylesheet">
<link href="{% static 'styles/loading.css'%}" rel="stylesheet">
<link href="{% static 'styles/popup.css'%}" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
......@@ -68,6 +69,7 @@
</table>
<center><div id="loader" class="loader" style="display: none;"></div></center>
<button id="btnShowMore" class="btn btn-success" style="margin: 10px;display: none;" title="afficher plus de résultats"><span class="glyphicon glyphicon-plus" area-hidden="true"></span></button>
<!-- <button id="btnAddEntry" class="btn btn-primary" style="margin: 10px;" title="Ajouter une entrée">Ajouter une entrée</button> -->
<div id="actionBlock" style="display: none;"><div class="loader mainLoad"></div></div>
</div>
</div>
......@@ -77,19 +79,26 @@
</form>
</div>
{% include 'footer.html' %}
<script>if ("{{ data.message }}".length > 0){window.alert("{{ data.message }}");};</script>
<!-- Fenêtre d'historique des modifications -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content2">
<div class="modal-header2">
<span class="close">&times;</span>
<h2>Historique des modifications</h2>
</div>
<div class="modal-body">
<h2 id="popLogH2"></h2>
<div id="popLogInner"></div>
</div>
<div class="modal-footer2">
<h3>WikiColor</h3>
</div>
</div>
</div>
<script>
// var btnAdd = document.getElementById('btnAddEntry');
// btnAdd.addEventListener('click', addEntry);
// document.getElementById('hiddenFields').style.display='none';
// function addEntry(){
// document.getElementById('hiddenFields').style.display='';
// btnAdd.style.display='none';
// }
</script>
{% include 'footer.html' %}
<script src="{% static 'scripts/editDico.js' %}"></script>
<script src="{% static 'scripts/keyboard.js' %}"></script>
</body>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment