Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 86d5d416 authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

editDico en cours- transition vers AlemDic

parent bf90ea39
......@@ -31,7 +31,8 @@ class LogStat:
cptDel: int
class DicEntry:
mot: str
mot: models.CharField(max_length=100)
url: models.CharField(max_length=150)
trans: str
class commitData:
......
......@@ -20,7 +20,7 @@ phonGraphFileEn = "../phon2graph/data/fidel_wikicolor_en_global.scsv" # ENGLISH
pinyin2apiFile = "../phon2graph/data/pinyin2api.json" # MANDARIN
api2classFile = "../phon2graph/data/api2class.json" # MANDARIN
dicFile = "../wikiphon/dico_frwiktionary-20200301_v2.json"
dicFileFr = "../wikiphon/dico_frwiktionary-20200301_v2.json"
dicFileEn = "../wikiphon/dico_enWikiCmuBritfone.json"
dicFileZh = "../wikiphon/dico_zhCCDict_20201206_v1.json"
......@@ -57,7 +57,7 @@ def getLenDicZh():
## FR
word2transFr = {} # un mot → liste de trans possibles
with open(dicFile, 'r') as f:
with open(dicFileFr, 'r') as f:
word2transFr = json.load(f)
print("Nombre d'entrées dans le dictionnaire de français :", getLenDic(word2transFr))
......@@ -352,76 +352,83 @@ def getEntryByWord(m,mc,t,tc,lang):
def modifEntry(user,mot,newTransList,lang):
if lang == "fr":
word2trans = word2transFr
phon2graph = phon2graphFr
newTransList = newTransList.split(',')
for ind,i in enumerate(newTransList):
newTransList[ind] = i.strip()
oldTransList = word2trans[mot]
if newTransList != oldTransList:
word2trans[mot] = newTransList
rewriteDico(lang)
writeLog(Type="MODIF", user=user, mot=mot, oldTransList=oldTransList, newTransList=newTransList, lang=lang)
print("Modification du dictionnaire par",user,": mot =",mot,"; oldTransList =",oldTransList,"; newTransList = ",newTransList)
return "Modification effectuée avec succès !"
elif lang == "en":
word2trans = word2transEn
phon2graph = phon2graphEn
newTransList = newTransList.split(',')
for ind,i in enumerate(newTransList):
newTransList[ind] = i.strip()
oldTransList = word2trans[mot]
if newTransList != oldTransList:
word2trans[mot] = newTransList
rewriteDico("fr")
writeLog(Type="MODIF", user=user, mot=mot, oldTransList=oldTransList, newTransList=newTransList, lang="fr")
print("Modification du dictionnaire par",user,": mot =",mot,"; oldTransList =",oldTransList,"; newTransList = ",newTransList)
return "Modification effectuée avec succès !"
return "La modification du dictionnaire anglais n'est pas encore possible."
def addEntry(user,mot,trans,lang):
if lang == "fr":
word2trans = word2transFr
phon2graph = phon2graphFr
trans = trans.replace('g','ɡ')
mot = mot.lower()
mot = mot.strip()
transList = trans.split(',')
for ind,i in enumerate(transList):
transList[ind] = i.strip()
if mot not in word2trans.keys():
word2trans[mot] = transList
rewriteDico("fr")
writeLog(Type="ADD", user=user, mot=mot, oldTransList="", newTransList=transList, lang="fr")
print("Modification du dictionnaire par",user,": ajout de mot =",mot,"; transList = ",transList)
return "Ajout effectué avec succès ! Merci pour votre participation !"
else:
return "Ce mot est déjà dans le dictionnaire !"
elif lang == "en":
word2trans = word2transEn
phon2graph = phon2graphEn
trans = trans.replace('g','ɡ')
mot = mot.lower()
mot = mot.strip()
transList = trans.split(',')
for ind,i in enumerate(transList):
transList[ind] = i.strip()
if mot not in word2trans.keys():
word2trans[mot] = transList
rewriteDico("fr")
writeLog(Type="ADD", user=user, mot=mot, oldTransList="", newTransList=transList, lang="fr")
print("Modification du dictionnaire par",user,": ajout de mot =",mot,"; transList = ",transList)
return "Ajout effectué avec succès ! Merci pour votre participation !"
else:
return "Ce mot est déjà dans le dictionnaire !"
return "La modification du dictionnaire anglais n'est pas encore possible."
def delEntry(user,mot,lang):
if lang == "fr":
word2trans = word2transFr
phon2graph = phon2graphFr
if mot in word2trans.keys():
word2trans.pop(mot)
if lang == "fr":
rewriteDico('fr')
writeLog(Type="DEL", user=user, mot=mot, oldTransList="", newTransList="",lang="fr")
if lang == "en":
rewriteDico('en')
writeLog(Type="DEL", user=user, mot=mot, oldTransList="", newTransList="",lang="en")
print("Modification du dictionnaire par",user,": suppression de mot =",mot)
return "Suppression effectuée avec succès."
elif lang == "en":
word2trans = word2transEn
phon2graph = phon2graphEn
if mot in word2trans.keys():
word2trans.pop(mot)
rewriteDico('fr')
writeLog(Type="DEL", user=user, mot=mot, oldTransList="", newTransList="",lang="fr")
print("Modification du dictionnaire par",user,": suppression de mot =",mot)
return "Suppression effectuée avec succès."
return "La modification du dictionnaire anglais n'est pas encore possible."
def rewriteDico(lang):
if lang == "fr":
word2trans = word2transFr
phon2graph = phon2graphFr
print("REWRITE DICO FR")
'''
print('Rewritting dictionary...')
with tempfile.NamedTemporaryFile(dir='.', delete=False, mode="w") as tmp:
json.dump(word2trans, tmp, ensure_ascii=False)
os.replace(tmp.name, dicFileFr)
print('Dico rewritten.')
'''
elif lang == "en":
word2trans = word2transEn
phon2graph = phon2graphEn
print('Rewritting dictionary...')
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.')
return "La modification du dictionnaire anglais n'est pas encore possible."
def sendMeLogPlease(lang):
if lang == "fr":
......
......@@ -267,27 +267,30 @@ def get_client_ip(request):
def editEntry(request):
mot = request.GET.get('mot', None)
lang = request.GET.get('lang', None)
transList = request.GET.get('transList', None)
ipCli = get_client_ip(request)
rep = {
'reponse': txtphono.modifEntry(ipCli,mot,transList,'fr')
'reponse': txtphono.modifEntry(ipCli,mot,transList,lang)
}
return JsonResponse(rep)
def newEntry(request):
mot = request.GET.get('mot', None)
trans = request.GET.get('trans', None)
lang = request.GET.get('lang', None)
ipCli = get_client_ip(request)
rep = {
'reponse': txtphono.addEntry(ipCli,mot,trans,'fr')
'reponse': txtphono.addEntry(ipCli,mot,trans,lang)
}
return JsonResponse(rep)
def supprEntry(request):
mot = request.GET.get('mot', None)
lang = request.GET.get('lang', None)
ipCli = get_client_ip(request)
rep = {
'reponse': txtphono.delEntry(ipCli,mot,'fr')
'reponse': txtphono.delEntry(ipCli,mot,lang)
}
return JsonResponse(rep)
......
......@@ -32,7 +32,7 @@ urlpatterns = [
path('app/dico/fr', colorapp_views.dicoViewFr),
path('app/dico/en', colorapp_views.dicoViewEn),
path('dicoSearch/', colorapp_views.dicoReq),
path('modifEntry/', colorapp_views.editEntry),
path('editEntry/', colorapp_views.editEntry),
path('addEntry/', colorapp_views.newEntry),
path('delEntry/', colorapp_views.supprEntry),
path('getLog/', colorapp_views.getLog)
......
......@@ -16,13 +16,13 @@ function getLogFile() {
});
}
var dicoLang = document.getElementById('dicoLang').value;
var localDico = {}; // contiendra la liste des résultats de la recherche
$(document).ready(function(){
console.log('Ready.');
$("#rechercher").click(function(){
var dicoLang = thisPageLang; //document.getElementById('dicoLang').value;
var mot = document.getElementById('inMot').value;
var trans = document.getElementById('inTrans').value;
var motCond = document.getElementById('condition-mot').value;
......@@ -62,7 +62,7 @@ $(document).ready(function(){
} else window.alert('Veuillez entrer une requête de recherche.');
function listEntries(data) {
localDico = data.listeEntrees;
document.getElementById('loader').style.display = 'none';
document.body.style.cursor = "default";
console.log(data)
......@@ -94,12 +94,12 @@ $(document).ready(function(){
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>';
var lienWiki = '<a href="https://'+dicoLang+'.wiktionary.org/wiki/'+entr.replace(' ','_')+'" target="_blank"><button role="button" class="btn btn-sm" title="Consulter le Wiktionnaire">W</button></a>';
var transList = '';
if (dicoLang == 'en'){
for (j in dico[i][1]) {
console.log(j, dico[i][1][j]);
//console.log(j, dico[i][1][j]);
transList += j + ' (' + dico[i][1][j].join(',') + ')\n'
}
} else {
......@@ -143,25 +143,118 @@ function modifEntry(cptEntr,entr) {
thisTr = document.getElementById(thisTr);
thisTd = document.getElementById(thisTd);
var thisBtnModifier = 'btnModifier'+cptEntr;
var thisBtnValider = 'btnValider'+cptEntr;
var thisBtnAnnuler = 'btnAnnuler'+cptEntr;
var thisBtnSupprimer = 'btnSupprimer'+cptEntr;
thisBtnModifier = document.getElementById(thisBtnModifier);
thisBtnValider = document.getElementById(thisBtnValider);
thisBtnAnnuler = document.getElementById(thisBtnAnnuler);
thisBtnSupprimer = document.getElementById(thisBtnSupprimer);
if (dicoLang == "fr"){
var thisBtnModifier = 'btnModifier'+cptEntr;
var thisBtnValider = 'btnValider'+cptEntr;
var thisBtnAnnuler = 'btnAnnuler'+cptEntr;
var thisBtnSupprimer = 'btnSupprimer'+cptEntr;
thisBtnModifier = document.getElementById(thisBtnModifier);
thisBtnValider = document.getElementById(thisBtnValider);
thisBtnAnnuler = document.getElementById(thisBtnAnnuler);
thisBtnSupprimer = document.getElementById(thisBtnSupprimer);
thisTd.classList.add('editTrans');
thisTd.disabled = false;
thisTd.focus();
thisBtnModifier.style.display = 'none';
thisBtnValider.style.display = '';
thisBtnAnnuler.style.display = '';
thisBtnSupprimer.style.display = '';
thisTr.style.backgroundColor = "lightgreen";
} else if (dicoLang == "en"){
var modalEditWord = document.getElementById('modalEditWord')
var thisWordTransList = localDico[cptEntr-1][1];
document.getElementById('transTable').innerHTML = "<tr><th>Transcription (IPA)</th><th>Region(s)/Variety</th></tr>";
for (t in thisWordTransList){
document.getElementById('transTable').innerHTML += '<tr><td><input id="" class="popwTrans inputTrans api-kb" type="text" value="'+ t +'"/></td><td style="cursor:pointer;" onclick="selectRegions(\''+entr+'\','+cptEntr+',\''+t+'\')">'+ thisWordTransList[t] +'</td></tr>'
}
thisTr.style.backgroundColor = "lightgreen";
document.getElementById('popwMot').innerHTML = entr;
document.getElementById('modalEditWordBtnDiv').innerHTML = '<button id="modalEditWordBtnValider" class="btn btn-success" onclick="validEntry(\''+entr+'\','+cptEntr+')">Save</button><button id="modalEditWordBtnSupprimer" class="btn btn-danger" onclick="supprimer(\''+entr+'\','+cptEntr+')">Delete this entry</button>'
modalEditWord.style.display = "block";
}
}
thisTd.classList.add('editTrans');
thisTd.disabled = false;
thisTd.focus();
function selectRegions(entr, cptEntr, trans) {
// Open the modal for selecting regions for this word pronunciation
var modalEditWordRegion = document.getElementById('modalEditWordRegion')
var listCheckbox = document.querySelectorAll('.wordRegionCheckbox');
let transList = localDico[cptEntr-1][1][trans];
for (cb in listCheckbox) {
listCheckbox[cb].checked = false; // réinitialisation des checkbox
for (r in transList) {
// for each region given in the dictionary for this trans, if the meta-region (cf. loc2stand.js) correspond to the current checkbox, set this latter to true.
if (loc2stand[transList[r]] == listCheckbox[cb].value) listCheckbox[cb].checked = true;
}
}
thisBtnModifier.style.display = 'none';
thisBtnValider.style.display = '';
thisBtnAnnuler.style.display = '';
thisBtnSupprimer.style.display = '';
document.getElementById('modalEditWordRegionWord').innerHTML = entr;
document.getElementById('modalEditWordRegionTrans').innerHTML = trans;
document.getElementById('modalEditWordRegionCptEntr').value = cptEntr;
if (transList.filter(function(item, index) { return /^\#/.test(item); }).length > 0) {
// si il y a déjà un commentaire
document.getElementById('modalEditWordRegionComment').value = transList.filter(function(item, index) { return /^\#/.test(item); })[0].replace('#','');
} else {
document.getElementById('modalEditWordRegionComment').value = "";
}
modalEditWordRegion.style.display = "block";
}
let metaRegions = ["UK", "US", "CA", "AU", "NZ"];
function validRegions() {
var cptEntr = Number(document.getElementById('modalEditWordRegionCptEntr').value);
var trans = document.getElementById('modalEditWordRegionTrans').innerHTML;
var entr = document.getElementById('modalEditWordRegionWord').innerHTML;
console.log(trans);
var listCheckbox = document.querySelectorAll('.wordRegionCheckbox');
var checkedRegions = [];
let transList = localDico[cptEntr-1][1][trans];
for (cb in listCheckbox) {
if (listCheckbox[cb].checked) {
checkedRegions.push(listCheckbox[cb].value);
}
}
// Mise à jour du localDico :
for (r in metaRegions) {
// Pour chaque metaRegion (var globale) on regarde si checkée ou pas et on met à jour localdico en fonction
if (checkedRegions.includes(metaRegions[r]) && !transList.includes(metaRegions[r])) {
// add the metaRegion if checked by user and not yet in localDico
transList.push(metaRegions[r])
} else if (!checkedRegions.includes(metaRegions[r]) && transList.includes(metaRegions[r])) {
// remove the metaRegion if found in localDico and not checked by user (→unchecked)
transList.splice(transList.indexOf(metaRegions[r]),1)
}
}
var comment = document.getElementById('modalEditWordRegionComment').value;
if (comment.length > 0) {
// Un commentaire commence par '#'
if (transList.filter(function(item, index) { return /^\#/.test(item); }).length > 0) {
// si il y a déjà un commentaire
var cmt = transList.filter(function(item, index) { return /^\#/.test(item); })[0].replace('#','');
if (comment != cmt) {
console.log('Comment changed!', comment);
transList[transList.indexOf('#'+cmt)] = '#'+comment;
}
} else {
console.log('New Comment!', comment);
transList.push('#'+comment);
}
}
modifEntry(cptEntr, entr); // réinitialiser la fenêtre "Edit an entry"
document.getElementById('modalEditWordRegion').style.display = "none"; // fermer la fenêtre "Regions"
}
function validEntry(entr, cptEntr) {
......@@ -173,10 +266,11 @@ function validEntry(entr, cptEntr) {
document.body.style.cursor = "wait";
$.ajax({
url: '/modifEntry/',
url: '/editEntry/',
data: {
mot: thisMot,
transList: thisTransList
transList: thisTransList,
lang: dicoLang
},
dataType: 'json',
success: function(data) {
......@@ -217,7 +311,8 @@ function supprimer(entr, cptEntr) {
$.ajax({
url: '/delEntry/',
data: {
mot: thisMot
mot: thisMot,
lang: dicoLang
},
dataType: 'json',
success: function(data) {
......@@ -284,7 +379,8 @@ function validAddEntry(mot, trans) {
url: '/addEntry/',
data: {
mot: mot,
trans: trans
trans: trans,
lang: dicoLang
},
dataType: 'json',
success: function(data) {
......@@ -357,10 +453,57 @@ function getLogOfAll() {
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
modalEditWord.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
window.addEventListener('click', function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
})
//////////////////////////////////////
////////// PARAMÉTRAGE POPUP /////////
////////// POUR MODIF DE MOT /////////
//////////////////////////////////////
// Get the modal
var modalEditWord = document.getElementById("modalEditWord");
// Get the <span> element that closes the modal
var spanEditWord = document.getElementById("closeEditWord");
// When the user clicks on <span> (x), close the modal
spanEditWord.onclick = function() {
modalEditWord.style.display = "none";
document.getElementById('transTable').innerHTML = '<tr><th>Transcription (IPA)</th><th>Region(s)/Variety</th></tr>';
}
// When the user clicks anywhere outside of the modal, close it
window.addEventListener('click', function(event) {
if (event.target == modalEditWord) {
modalEditWord.style.display = "none";
document.getElementById('transTable').innerHTML = '<tr><th>Transcription (IPA)</th><th>Region(s)/Variety</th></tr>';
}
})
//////////////////////////////////////
////////// PARAMÉTRAGE POPUP /////////
//////// POUR MODIF DE REGION ////////
//////////////////////////////////////
// Get the modal
var modalEditWordRegion = document.getElementById("modalEditWordRegion");
// Get the <span> element that closes the modal
var spanEditWordRegion = document.getElementById("closeEditWordRegion");
// When the user clicks on <span> (x), close the modal
spanEditWordRegion.onclick = function() {
modalEditWordRegion.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.addEventListener('click', function(event) {
if (event.target == modalEditWordRegion) {
modalEditWordRegion.style.display = "none";
}
})
\ No newline at end of file
......@@ -174,6 +174,7 @@
padding: 0;
border: 1px solid #888;
width: 40%;
min-width: 300px;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
......
......@@ -11,6 +11,7 @@
{% elif data.dicoLang == 'zh' %}
<h2>中文詞典中搜索詞語</h2>
{% endif %}
<input hidden id="dicoLang" value="{{ data.dicoLang }}">
<div class="searchWindow">
<div class="input">
......@@ -94,8 +95,72 @@
</div>
</div>
</div>
<!-- Modal qui apparaît pour afficher/modifier un mot au dictionnaire anglais -->
<div id="modalEditWord" class="modal">
<div class="popAddw-content" style="min-width:600px;">
<div class="popAddw-header d-flex justify-content-between align-items-center">
Edit an entry of the dictionary
<span class="close" id="closeEditWord">&times;</span>
</div>
<div class="popAddw-body">
<b>Word : </b>« <span id="popwMot"></span> »<br/>
<table id="transTable" style="width:100%">
<tr>
<th>Transcription (IPA)</th>
<th>Region(s)/Variety</th>
</tr>
</table>
<div id="modalEditWordBtnDiv"></div>
</div>
</div>
</div>
<!-- Modal qui apparaît pour afficher/modifier la/les régions d'un mot du dictionnaire anglais -->
<div id="modalEditWordRegion" class="modal" style="padding-top: 200px;">
<div class="popAddw-content" style="min-width:500px;">
<div class="popAddw-header d-flex justify-content-between align-items-center">
Select one or more regions for this pronunciation
<span class="close" id="closeEditWordRegion">&times;</span>
</div>
<div class="popAddw-body">
<b>Word: </b>« <span id="modalEditWordRegionWord"></span> »<br/>
<b>Pronunciation: </b>/<span id="modalEditWordRegionTrans" class="inputTrans"></span>/<br/>
<input hidden id="modalEditWordRegionCptEntr" value="">
<br/>
<div class="form-check form-check-inline">
<input class="form-check-input wordRegionCheckbox" type="checkbox" id="wordRegionUK" value="UK">
<label class="form-check-label" for="wordRegionUK" title="United Kingdom - Received Pronunciation">UK</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input wordRegionCheckbox" type="checkbox" id="wordRegionUS" value="US">
<label class="form-check-label" for="wordRegionUS" title="USA - General American">US</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input wordRegionCheckbox" type="checkbox" id="wordRegionCA" value="CA">
<label class="form-check-label" for="wordRegionCA" title="Canada">CA</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input wordRegionCheckbox" type="checkbox" id="wordRegionAU" value="AU">
<label class="form-check-label" for="wordRegionAU" title="Australia">AU</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input wordRegionCheckbox" type="checkbox" id="wordRegionNZ" value="NZ">
<label class="form-check-label" for="wordRegionNZ" title="New Zealand">NZ</label>
</div>
<br/><br/>
<b>Comment: </b><br/>
<textarea id="modalEditWordRegionComment" placeholder="Type any comment you want on this pronunciation."></textarea>
<div id="modalEditWordRegionBtnDiv">
<button class="btn btn-success" onclick="validRegions()">Save</button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block javascript %}
<script src="{% static 'scripts/loc2stand.js' %}"></script>
<script src="{% static 'scripts/editDico.js' %}"></script>
{% endblock %}
\ No newline at end of file
Markdown is supported
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