Skip to content
This repository was archived by the owner on Apr 12, 2020. It is now read-only.
/ git-bundle Public archive

Commit c7130b7

Browse files
author
alexandresalome
committed
fancier diff file view
1 parent 1287147 commit c7130b7

File tree

6 files changed

+118
-24
lines changed

6 files changed

+118
-24
lines changed

Resources/doc/install/raw.rst

+13
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ When it's done, add the extension to your Twig:
2727
$twig->addExtension($extension);
2828
$twig->addPath('/path/to/Gitonomy/Bundle/GitBundle/Resources/views', '@GitonomyGitBundle');
2929
30+
Now, you just need to load those assets in your application:
31+
32+
Assets installation
33+
:::::::::::::::::::
34+
35+
You need to make your application load those stylesheets:
36+
37+
* Resources/public/css/all.css
38+
39+
And those javascripts:
40+
41+
* Resources/public/css/log.js
42+
* Resources/public/css/commit.js

Resources/doc/install/symfony2.rst

+1-8
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,7 @@ If you are using Assetic:
8383

8484
{% javascripts
8585
"bundles/gitonomytwig/js/log.js"
86+
"bundles/gitonomytwig/js/commit.js"
8687
%}
8788
<script type="text/javascript" src="{{ asset(asset_url) }}"></script>
8889
{% endjavascripts %}
89-
90-
If not, you just need to make your application load those stylesheets:
91-
92-
* @GitonomyGitBundle/Resources/public/css/all.css
93-
94-
And those javascripts:
95-
96-
* @GitonomyGitBundle/Resources/public/css/log.js

Resources/public/css/all.css

+48
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,53 @@
11
/** Diff **/
22

3+
ul.diff-summary {
4+
list-style-type: none;
5+
}
6+
7+
ul.diff-summary {
8+
margin: 0;
9+
}
10+
11+
ul.diff-summary input[type=checkbox] {
12+
margin: 0;
13+
}
14+
15+
ul.diff-summary a div.diff-file-label {
16+
display: inline-block;
17+
text-indent: 5px;
18+
font-family: monospace;
19+
}
20+
21+
ul.diff-summary a div.diff-file-label.creation:before {
22+
content: "[+] ";
23+
color: green;
24+
}
25+
26+
ul.diff-summary a div.diff-file-label.creation {
27+
color: green;
28+
}
29+
30+
ul.diff-summary a div.diff-file-label.deletion:before {
31+
content: "[-] ";
32+
color: red;
33+
}
34+
35+
ul.diff-summary a div.diff-file-label.deletion {
36+
color: red;
37+
}
38+
39+
ul.diff-summary a div.diff-file-label.modification:before {
40+
content: "[ ] ";
41+
}
42+
43+
ul.diff-summary a {
44+
color: black;
45+
}
46+
47+
ul.diff-summary a:hover > div {
48+
text-decoration: underline;
49+
}
50+
351
.file-wrapper .file {
452
margin-top: 10px;
553
}

Resources/public/js/commit.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Detects changes on single-file checkbox.
3+
*/
4+
$(document).on('change', 'ul.diff-summary input[type=checkbox]', function (event) {
5+
$t = $(event.currentTarget);
6+
$target = $("#" + $t.attr('data-file-id'));
7+
8+
if (undefined == $t.attr('checked')) {
9+
$target.hide();
10+
} else {
11+
$target.show();
12+
}
13+
});
14+
15+
/**
16+
* Detects changes on "toggle-all" on top of a commit.
17+
*/
18+
$(document).on('change', 'input[type=checkbox].diff-toggle-all', function (event) {
19+
var $t = $(event.currentTarget);
20+
var $target = $("#" + $t.attr('data-target') + " input[type=checkbox][data-file-id]");
21+
22+
if (undefined == $t.attr('checked')) {
23+
$target.removeAttr('checked');
24+
} else {
25+
$target.attr('checked', 'checked');
26+
}
27+
$target.trigger('change');
28+
});

Resources/translations/git.fr_FR.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Staging area": "Staging area"
33
"Pending modifications": "Modifications en attente"
44
"Gravatar of :user": "Gravatar de :user"
5-
"File mode changed from :old to :new": "Le mode de fichier a changé de :old pour :new"
65
"Filename": "Nom de fichier"
76
"Modification date": "Date de modification"
87
"Last commit": "Dernier commit"
8+
"Toggle all": "Permuter tous"

Resources/views/default_theme.html.twig

+27-15
Original file line numberDiff line numberDiff line change
@@ -165,34 +165,46 @@
165165
{% endspaceless %}
166166
{% endblock %}
167167

168+
{% block diff_file_label %}
169+
{% spaceless %}
170+
{% set text = file.name %}
171+
{% if file.creation %}
172+
{% set class = " creation" %}
173+
{% elseif file.deletion %}
174+
{% set class = " deletion" %}
175+
{% elseif file.rename %}
176+
{% set class = " rename" %}
177+
{% set text = file.oldName ~ ' > ' ~ file.newName %}
178+
{% else %}
179+
{% set class = " modification" %}
180+
{% endif %}
181+
{% if file.changeMode %}
182+
{% set text = text ~ " (" ~ file.oldMode ~ " > " ~ file.newMode ~ ")" %}
183+
{% endif %}
184+
<div class="diff-file-label{{ class }}">{{ text }}</div>
185+
{% endspaceless %}
186+
{% endblock %}
187+
168188
{% block diff_summary %}
169-
<ul class="summary">
189+
{% spaceless %}
190+
<ul class="diff-summary" id="{{ id_prefix }}-list">
191+
<li><em><input type="checkbox" class="diff-toggle-all" data-target="{{ id_prefix }}-list" checked="checked" /> {{ 'Toggle all'|trans({}, 'git') }}</em></li>
170192
{% for i,file in diff.files %}
171193
<li>
194+
<input type="checkbox" data-file-id="{{ id_prefix }}{{ i }}" checked="checked" />
172195
<a href="#{{ id_prefix }}{{ i }}">
173-
{{ file.name }}
196+
{{ git_render('diff_file_label', {file: file}) }}
174197
</a>
175198
</li>
176199
{% endfor %}
177200
</ul>
201+
{% endspaceless %}
178202
{% endblock %}
179203

180204
{% block diff_file %}
181205
{% spaceless %}
182206
<header id="{{ id }}">
183-
{% if file.oldName == file.newName and file.oldMode == file.newMode %}
184-
<span class="file">{{ file.oldName }}</span>
185-
{% elseif file.oldName == null %}
186-
<span class="file">{{ file.newName }} ({{ file.newMode }})</span>
187-
{% elseif file.newName == null %}
188-
<span class="file deleted">{{ file.oldName }} ({{ file.oldMode }})</span>
189-
{% elseif file.oldMode != file.newMode %}
190-
<span class="changemod">{{ 'File mode changed from :old to :new'|trans({':old': file.oldMode, ':new': file.newMode}) }}</span>
191-
{% else %}
192-
<ul>
193-
<li>{{ file.oldName }} ({{ file.oldMode }}) -&gt; {{ file.newName }} ({{ file.newMode }})</li>
194-
</ul>
195-
{% endif %}
207+
{{ git_render('diff_file_label', {file: file}) }}
196208
</header>
197209
<div class="file-changes">
198210
{% if file.isBinary %}

0 commit comments

Comments
 (0)