Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Ajout d'une interface de merge pour les contenus #4151

Closed
wants to merge 97 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
d19997d
First commit
Anto59290 Nov 28, 2016
12e6167
ajout de routes, netoyage, test
Anto59290 Dec 5, 2016
1d6c888
Remove useless routes, add tests, add permissions, typos, styling
Anto59290 Dec 15, 2016
9fb78c1
Ajout de test, retrait de todo
Anto59290 Dec 19, 2016
2ff88ac
Testing
Anto59290 Dec 23, 2016
520c8bd
Tests
Anto59290 Dec 24, 2016
a86b075
Add validator, test
Anto59290 Dec 29, 2016
d64117f
Fixing tests, adding tests
Anto59290 Jan 2, 2017
615f5d4
tests
Anto59290 Jan 3, 2017
fa17b76
fixing test
Anto59290 Jan 4, 2017
4ecf63c
testing'
Anto59290 Jan 5, 2017
89eda18
Remove useless code, update todo list, style
Anto59290 Jan 5, 2017
d209ad7
Update settings.py
Anto59290 Jan 5, 2017
405f17c
First POC
Anto59290 Jan 10, 2017
6b78028
clean, remove useless file
Anto59290 Jan 10, 2017
2b19e0d
Clean, industrialisation du processus, divers bugs réglés
Anto59290 Jan 10, 2017
68ecbb1
ajout de la conclusion
Anto59290 Jan 11, 2017
14e987a
change alert to msg
Anto59290 Jan 12, 2017
8be724e
Nettoyage et style, diverses améliorations visuelles
Anto59290 Jan 12, 2017
0977079
style
Anto59290 Jan 12, 2017
c465f32
style
Anto59290 Jan 12, 2017
cbfe255
ajout du package, simplifie le formulaire
Anto59290 Jan 12, 2017
1daa48a
js plus logique
Anto59290 Jan 12, 2017
25276f0
Documentation JS, Refacto JS, ajout d'un TODO
Anto59290 Jan 13, 2017
1ec13cc
Style
Anto59290 Jan 13, 2017
9335ccc
better UX, remove todo
Anto59290 Jan 17, 2017
1e40465
ajout de l'interface de merge aux autres formulaires
Anto59290 Jan 23, 2017
f64b319
Update forms.py
Anto59290 Jan 23, 2017
e81dc71
ajout aux autres forms
Anto59290 Jan 24, 2017
9a62434
Merge branch 'dev' into 3251_git_diff_2
Anto59290 Jan 26, 2017
0541a3e
Update forms.py
Anto59290 Jan 26, 2017
b091f73
merge
Anto59290 Jan 26, 2017
20bf699
fix style
Anto59290 Jan 26, 2017
a199b20
fix style
Anto59290 Jan 26, 2017
f30e30d
merge
Anto59290 Jan 26, 2017
f32e2ba
Update forms.py
Anto59290 Feb 2, 2017
185cc00
Update settings.py
Anto59290 Feb 21, 2017
4e2dbfb
Update auto-merge.js
Anto59290 Feb 21, 2017
7f2c913
Update forms.py
Anto59290 Feb 28, 2017
3c735ff
Remove mege info
Anto59290 Apr 15, 2017
f411710
Merging
Anto59290 Apr 15, 2017
3227078
Merging
Anto59290 Apr 15, 2017
6b73cfc
Merge branch 'dev' into 3251_git_diff_2
Anto59290 Apr 20, 2017
6033f61
Update forms.py
Anto59290 Apr 20, 2017
e5fe212
Update forms.py
Anto59290 Apr 20, 2017
42d52aa
Update forms.py
Anto59290 Apr 22, 2017
43a76af
Update main.scss
Anto59290 Apr 22, 2017
7e12347
Merge branch 'dev' into 3251_git_diff_2
Anto59290 May 7, 2017
516583f
Merge branch 'dev' of https://github.com/zestedesavoir/zds-site into …
Anto59290 May 9, 2017
dd0444c
Fix styles, add sccs files
Anto59290 May 9, 2017
ed5e0cf
merge
Anto59290 May 9, 2017
c30ad5f
Update models.py
Anto59290 May 10, 2017
ca9952d
Update models.py
Anto59290 May 10, 2017
e61d8cf
Update models.py
Anto59290 May 10, 2017
588b3a9
Update models.py
Anto59290 May 10, 2017
32e5899
Update forms.py
Anto59290 May 10, 2017
868945a
Update forms.py
Anto59290 May 10, 2017
ab60b13
Remove files
Anto59290 May 10, 2017
8feb1ec
Merge branch '3251_git_diff_2' of https://github.com/Anto59290/zds-si…
Anto59290 May 10, 2017
aa4afcc
Fix rebase
Anto59290 May 10, 2017
ba88ccc
Update tests_models.py
Anto59290 May 10, 2017
e924cc3
Update permissions.py
Anto59290 May 10, 2017
21141ef
Update forms.py
Anto59290 May 10, 2017
42b4996
Update tests.py
Anto59290 May 10, 2017
696bb81
Update views.py
Anto59290 May 10, 2017
868f7c3
Update
Anto59290 May 10, 2017
ef875a5
Update urls.py
Anto59290 May 11, 2017
dc5c9e4
Update permissions.py
Anto59290 May 11, 2017
9b94737
Update forms.py
Anto59290 May 11, 2017
0d19446
Update models.py
Anto59290 May 11, 2017
c0d07af
Update urls.py
Anto59290 May 13, 2017
59cd3d4
Merge branch 'dev' into 3251_git_diff_2
Anto59290 May 31, 2017
39ead6e
Remove old code
Anto59290 May 31, 2017
b4567b8
Peping
Anto59290 Jun 1, 2017
d00b293
Style
Anto59290 Jun 1, 2017
c80d546
fix tests
Anto59290 Jun 2, 2017
63075aa
Just PEPing
Anto59290 Jun 3, 2017
fba3423
Just PEPing so more forms
Anto59290 Jun 3, 2017
f64ec59
Merge branch 'dev' into 3251_git_diff_2
Anto59290 Aug 15, 2017
5863c8c
Refacto
Anto59290 Aug 22, 2017
c7e8103
Merge branch 'dev' into 3251_git_diff_2
Anto59290 Aug 26, 2017
2602d09
I hate Js
Anto59290 Aug 27, 2017
cbf62b2
Merge branch 'dev' into 3251_git_diff_2
Anto59290 Aug 27, 2017
fcd9eee
Working example
Anto59290 Sep 18, 2017
3571d27
Merge branch '3251_git_diff_2' of https://github.com/Anto59290/zds-si…
Anto59290 Sep 23, 2017
3df61ec
Code style
Anto59290 Oct 28, 2017
782c8aa
Try to rebase
Anto59290 Nov 2, 2017
21ee83f
Fixing merge
Anto59290 Nov 2, 2017
1623c63
Update settings.py
Anto59290 Nov 2, 2017
dd97dde
Refactoring
Anto59290 Nov 5, 2017
af4f552
Merge branch '3251_git_diff_2' of https://github.com/Anto59290/zds-si…
Anto59290 Nov 5, 2017
08a2c30
Merge branch 'dev' into 3251_git_diff_2
Anto59290 Nov 5, 2017
909b53e
Linting
Anto59290 Nov 5, 2017
af170c0
Linting and remove py2 u
Anto59290 Nov 5, 2017
b95cc17
Update auto-merge.js
Anto59290 Nov 5, 2017
88a9290
Update auto-merge.js
Anto59290 Nov 6, 2017
21255b0
Merge branch 'dev' into 3251_git_diff_2
Anto59290 Jan 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Nettoyage et style, diverses améliorations visuelles
  • Loading branch information
Anto59290 committed Jan 12, 2017
commit 8be724e6b1532dfaf510ce2129babb6706aff266
137 changes: 62 additions & 75 deletions assets/js/auto-merge.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,66 @@


$(document).ready(function () {
console.log('oooooo');

$('.compare-introduction').mergely({
width: 'auto',
height: 400,
sidebar: false,
cmsettings: { readOnly: false, lineNumbers: true },
lhs: function(setValue) {
setValue($("#your_introduction").html());
},
rhs: function(setValue) {
setValue($("#id_introduction").text());
}
});
(function($, undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il faudrait réindenter ce fichier comme le reste, avec des espaces et non des tabulations.

"use strict";

$('.compare-conclusion').mergely({
width: 'auto',
height: 400,
sidebar: false,
cmsettings: { readOnly: false, lineNumbers: true },
lhs: function(setValue) {
setValue($("#your_conclusion").html());
},
rhs: function(setValue) {
setValue($("#id_conclusion").text());
$(document).ready(function () {

/**
* Sets up the merge interface (using mergely).
*/
function mergelySetUp(div, left, right)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peux-tu mettre un $ devant chaque variable (car c'est du jQuery).
De même, peux-tu changer le nom pour que ça soit plus proche du sens "fonctionnel" c'est à dire $local et $remote au lieu de left et right. du moins je pense (@vhf tu en dis quoi?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi pas changer le nom. Après local et remote c'est une convention pour nous (car le code actuel écrase), par sur que ça soit clair nom plus... Je vais détailler les commentaires avant pour expliquer les paramètres.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectivement les variables jQuery doivent être préfixées par $. Je te fais vite un exemple :

var $lala = $('.foo').find('.bar').get(1);
var baz = $lala.val();

Je sais pas comment nommer idéalement left et right. Si c'est côté JS qu'on charge les contenus à afficher à gauche et à droite, c'est côté JS qu'on sait quelle version risque d'écraser quelle version, et c'est sur ça qu'on devrait se baser pour nommer explicitement ces paramètres. Genre au lieu de left on pourrait avoir currentVersion et au lieu de right on aurait submittedVersion. Un truc dans ce genre. Ça a du sens pour vous ?

{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L’accolade doit être sur la même ligne que function.

div.mergely({
width: "auto",
height: 400,
sidebar: false,
cmsettings: { readOnly: false, lineNumbers: true, lineWrapping: true },
lhs: function(setValue) {
setValue(left.html());
},
rhs: function(setValue) {
setValue(right.text());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peux-tu mettre un commentaire dans le code pour expliquer pourquoi on a "html" d'un côté et "text" de l'autre stp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bien vu, j'ai uniformisé car il n'y avait pas de raison en particulier.

}
});
}
});

// TODO a voir comment on peut factoriser ce code.

$("#compare-editor-lhs").append('Votre Version');
$("#compare-editor-rhs").append('La version courante');



/**
* Merge introduction
*/
$(".merge-btn").on("click", function(e){
console.log('click');
e.stopPropagation();
e.preventDefault();
// var $form = $(this).parents("form:first");
var button = $(this);

console.log(button);

var classList = button.attr('class').split(/\s+/);
console.log(classList);
for (var i = 0; i < classList.length; i++) {
if (classList[i].indexOf('need-to-merge-') >= 0) {

// Cut the string to get the ending part
console.log(classList[i])
var substring = classList[i].substring(14)

// TODO : problème des retours à la ligne qui s'en vont (ou normal car markdown ?) ?
$intro = $("#id_" + substring);
$to_merge = $(".compare-" + substring).mergely('get','rhs');
$intro.val($to_merge);

console.log($intro.val());
// TODO : un bon petit alert des familles
var msg = '<div class="alert-box alert"> \
<span>Le merge a bien été effectué</span> \
<a href="#close-alert-box" class="close-alert-box ico-after cross white">{% trans "Masquer l\'alerte" %}</a> \
</div>';

$(".compare-" + substring).append(msg)

alert('Contenu bien mergé');
}
}
});
mergelySetUp($(".compare-introduction"),$("#your_introduction"),$("#id_introduction"));
mergelySetUp($(".compare-conclusion"),$("#your_conclusion"),$("#id_conclusion"));

$("#compare-editor-lhs").append("Votre Version");
$("#compare-editor-rhs").append("La version courante");


/**
* Merge content
*/
$(".merge-btn").on("click", function(e){

e.stopPropagation();
e.preventDefault();

var button = $(this);
var classList = button.attr("class").split(/\s+/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum pas sûr que ça soit la méthode la plus facile d'autant qu'il existe déjà l'attribut classList (this.classList).
Ensuite plutôt qu'un simple for, je suis d'avis d'utiliser un this.classList.forEach(function(){...}/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

De mémoire .classList à un support limité (voir inexistant) avec < IE9, d'où le choix de .attr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on ne supporte que IE 11 et supérieur, chrome last, firefox last, safari last.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ca marche alors ;)


for (var i = 0; i < classList.length; i++) {
if (classList[i].indexOf("need-to-merge-") >= 0) {

// Cut the string to get the ending part
var substring = classList[i].substring(14);

var $intro = $("#id_" + substring);
var $toMerge = $(".compare-" + substring).mergely("get","rhs");
$intro.val($toMerge);


});
// Display confirmation message
var msg = "<div class='alert-box success'>" +
"<span>Le merge a bien été effectué</span>" +
"<a href='#close-alert-box' class='close-alert-box ico-after cross white'>Masquer l'alerte</a>" +
"</div>";

button.before(msg);
}
}
});

});
})(jQuery);
1 change: 0 additions & 1 deletion zds/settings.py
Original file line number Diff line number Diff line change
@@ -31,7 +31,6 @@
},
}

ALLOWED_HOSTS = ['zds-anto59290.c9users.io']
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
10 changes: 4 additions & 6 deletions zds/tutorialv2/forms.py
Original file line number Diff line number Diff line change
@@ -237,27 +237,25 @@ def __init__(self, *args, **kwargs):

if kwargs.get('data') is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi la condition apparaît-elle deux fois?

old_intro = kwargs.get('data').get('introduction')
# TODO retirer le br et passer en style

self.helper.layout.append(Layout(Field('introduction', css_class='hidden')))
self.helper.layout.append(Layout(HTML('<div id="your_introduction" class="hidden" >'+old_intro+'</div>')))
self.helper.layout.append(Layout(HTML('<br><br><div id="compare" class="compare-introduction"></div><br><br>')))
self.helper.layout.append(Layout(HTML('<div id="compare" class="compare-introduction"></div>')))

self.helper.layout.append(Layout(
ButtonHolder(StrictButton(_(u'Merger'), type='merge', name='merge', css_class='btn btn-submit merge-btn need-to-merge-introduction'))))

else :
self.helper.layout.append(Layout(Field('introduction', css_class='md-editor')))

if kwargs.get('data') is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

il te manque un , None pour forcer le get à te donner une valeur par défaut.

old_conclusion = kwargs.get('data').get('conclusion')
# TODO retirer le br et passer en style

self.helper.layout.append(Layout(Field('conclusion', css_class='hidden')))
self.helper.layout.append(Layout(HTML('<div id="your_conclusion" class="hidden" >'+old_conclusion+'</div>')))
self.helper.layout.append(Layout(HTML('<br><br><div id="compare" class="compare-conclusion"></div><br><br>')))
self.helper.layout.append(Layout(HTML('<div id="compare" class="compare-conclusion"></div>')))

self.helper.layout.append(Layout(
ButtonHolder(StrictButton(_(u'Merger'), type='merge', name='merge', css_class='btn btn-submit merge-btn need-to-merge-conclusion'))))

else :
self.helper.layout.append(Layout(Field('conclusion', css_class='md-editor')))