build / Garde-fou (pull_request) Failing after 7s
build / Images Harbor (catalog-sync, Dockerfile.catalog-sync) (pull_request) Skipped
build / Images Harbor (web, Dockerfile) (pull_request) Skipped
build / Garde-fou (push) Failing after 8s
build / Images Harbor (catalog-sync, Dockerfile.catalog-sync) (push) Skipped
build / Images Harbor (web, Dockerfile) (push) Skipped
118 lines
4.7 KiB
JavaScript
118 lines
4.7 KiB
JavaScript
/* Moderation des soumissions de packs. */
|
|
|
|
'use strict';
|
|
|
|
var liste = document.getElementById('liste');
|
|
var detail = document.getElementById('detail');
|
|
var filtre = document.getElementById('filtre-statut');
|
|
|
|
function creer(tag, props) {
|
|
var noeud = document.createElement(tag);
|
|
Object.keys(props || {}).forEach(function (cle) {
|
|
if (cle === 'onclick') noeud.addEventListener('click', props[cle]);
|
|
else noeud[cle] = props[cle];
|
|
});
|
|
return noeud;
|
|
}
|
|
|
|
function json(url, options) {
|
|
options = options || {};
|
|
options.headers = Object.assign({ 'Content-Type': 'application/json' }, options.headers || {});
|
|
return fetch(url, options).then(function (r) {
|
|
return r.json().catch(function () { return {}; }).then(function (corps) {
|
|
if (!r.ok) throw new Error(corps.erreur || 'echec de la requete');
|
|
return corps;
|
|
});
|
|
});
|
|
}
|
|
|
|
function charger() {
|
|
detail.hidden = true;
|
|
liste.innerHTML = '';
|
|
json('/api/moderation/soumissions?statut=' + encodeURIComponent(filtre.value))
|
|
.then(function (soumissions) {
|
|
if (!soumissions.length) {
|
|
liste.appendChild(creer('p', { className: 'lede', textContent: 'Rien dans cette file.' }));
|
|
return;
|
|
}
|
|
soumissions.forEach(function (s) {
|
|
var ligne = creer('div', { className: 'pack-ligne' });
|
|
var texte = creer('div');
|
|
texte.appendChild(creer('b', { textContent: s.nom || s.pack_id }));
|
|
texte.appendChild(creer('span', { className: 'tag', textContent: s.statut.replace('_', ' ') }));
|
|
texte.appendChild(creer('div', {
|
|
className: 'desc',
|
|
textContent: s.pack_id + ' — ' + s.categorie + ' — propose par ' + (s.auteur || 'inconnu') +
|
|
' le ' + (s.cree_le || '').slice(0, 10)
|
|
}));
|
|
if (s.url_pr) {
|
|
var lien = creer('a', { href: s.url_pr, textContent: 'demande de fusion', target: '_blank' });
|
|
lien.rel = 'noopener';
|
|
texte.appendChild(lien);
|
|
}
|
|
if (s.reponse) texte.appendChild(creer('div', { className: 'desc', textContent: 'Motif : ' + s.reponse }));
|
|
ligne.appendChild(texte);
|
|
var actions = creer('div', { className: 'barre' });
|
|
actions.appendChild(creer('button', {
|
|
type: 'button', className: 'small', textContent: 'Examiner',
|
|
onclick: function () { examiner(s.id); }
|
|
}));
|
|
ligne.appendChild(actions);
|
|
liste.appendChild(ligne);
|
|
});
|
|
})
|
|
.catch(function (erreur) {
|
|
liste.appendChild(creer('div', { className: 'notice bad', textContent: erreur.message }));
|
|
});
|
|
}
|
|
|
|
function examiner(identifiant) {
|
|
json('/api/moderation/soumissions/' + identifiant).then(function (s) {
|
|
detail.hidden = false;
|
|
detail.innerHTML = '';
|
|
detail.appendChild(creer('h3', { textContent: (s.nom || s.pack_id) + ' — ' + s.pack_id }));
|
|
if (s.message) {
|
|
var mot = creer('div', { className: 'notice' });
|
|
mot.appendChild(creer('b', { textContent: "Mot de l'auteur" }));
|
|
mot.appendChild(creer('p', { textContent: s.message }));
|
|
detail.appendChild(mot);
|
|
}
|
|
detail.appendChild(creer('div', {
|
|
className: 'notice',
|
|
textContent: "Contribution externe : relire les lignes de commande, les macros et les " +
|
|
'prerequis. Publier ouvre une demande de fusion, ca ne modifie pas la branche principale.'
|
|
}));
|
|
detail.appendChild(creer('pre', { className: 'code', textContent: s.contenu }));
|
|
|
|
if (s.statut === 'en_attente') {
|
|
var barre = creer('div', { className: 'barre' });
|
|
barre.appendChild(creer('button', {
|
|
type: 'button', className: 'primary auto', textContent: 'Publier (ouvre une demande de fusion)',
|
|
onclick: function () {
|
|
json('/api/moderation/soumissions/' + identifiant + '/publier', { method: 'POST' })
|
|
.then(function (resultat) {
|
|
alert('Demande de fusion ouverte : ' + (resultat.url_pr || 'voir Gitea'));
|
|
charger();
|
|
})
|
|
.catch(function (erreur) { alert('Publication impossible : ' + erreur.message); });
|
|
}
|
|
}));
|
|
barre.appendChild(creer('button', {
|
|
type: 'button', className: 'danger', textContent: 'Refuser',
|
|
onclick: function () {
|
|
var motif = prompt('Motif du refus, communique a l\'auteur :');
|
|
if (motif === null) return;
|
|
json('/api/moderation/soumissions/' + identifiant + '/refuser', {
|
|
method: 'POST', body: JSON.stringify({ motif: motif })
|
|
}).then(charger).catch(function (erreur) { alert(erreur.message); });
|
|
}
|
|
}));
|
|
detail.appendChild(barre);
|
|
}
|
|
detail.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
}).catch(function (erreur) { alert(erreur.message); });
|
|
}
|
|
|
|
filtre.addEventListener('change', charger);
|
|
charger();
|