From 96f199adaa572193aeae4787c4882b6f045651fb Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sat, 24 Sep 2016 16:07:35 +0200 Subject: [PATCH] Fix issue #1 --- bower.json | 5 +- src/Gist/Model/Gist.php | 2 +- .../Resources/views/View/cipherJs.html.twig | 30 +++++++++ .../Resources/views/View/revisions.html.twig | 62 ++++++++++++++++++- src/Gist/Resources/views/View/view.html.twig | 31 +--------- src/Gist/Service/Gist.php | 4 ++ web/app/js/app.js | 20 +++++- 7 files changed, 116 insertions(+), 38 deletions(-) create mode 100644 src/Gist/Resources/views/View/cipherJs.html.twig diff --git a/bower.json b/bower.json index f1f83b6..201d38d 100644 --- a/bower.json +++ b/bower.json @@ -11,11 +11,12 @@ "GIT" ], "license": "LGPL", - "homepage": "https://gitlab.deblan.org/deblan/gist.deblan.org", + "homepage": "https://gitnet.fr/deblan/gist", "dependencies": { "bootstrap": "3.3.4", "flag-icon-css": "0.7.1", "SyntaxHighlighter": "3.0.83", - "iframe-resizer": "2.8.6" + "iframe-resizer": "2.8.6", + "jsdiff": "~2.2.2" } } diff --git a/src/Gist/Model/Gist.php b/src/Gist/Model/Gist.php index 31fa5d9..c0cb024 100644 --- a/src/Gist/Model/Gist.php +++ b/src/Gist/Model/Gist.php @@ -39,7 +39,7 @@ class Gist extends BaseGist { $data = array( 'javascript' => 'js', - 'yaml'=> 'yml', + 'yaml' => 'yml', 'perl' => 'pl', 'python' => 'py', 'bash' => 'sh', diff --git a/src/Gist/Resources/views/View/cipherJs.html.twig b/src/Gist/Resources/views/View/cipherJs.html.twig new file mode 100644 index 0000000..1bd89a3 --- /dev/null +++ b/src/Gist/Resources/views/View/cipherJs.html.twig @@ -0,0 +1,30 @@ + + + + diff --git a/src/Gist/Resources/views/View/revisions.html.twig b/src/Gist/Resources/views/View/revisions.html.twig index 7ba0b47..78bf52b 100644 --- a/src/Gist/Resources/views/View/revisions.html.twig +++ b/src/Gist/Resources/views/View/revisions.html.twig @@ -52,9 +52,10 @@

{% if not loop.first %} -
- {{ commit.diff|raw }} + {% if not gist.cipher %} + {{ commit.diff|raw }} + {% endif %}
{% endif %}
@@ -74,4 +75,61 @@ {% block js %} {{ parent() }} + + {% if gist.cipher %} + {{ include('View/cipherJs.html.twig') }} + + + + + {% endif %} {% endblock %} diff --git a/src/Gist/Resources/views/View/view.html.twig b/src/Gist/Resources/views/View/view.html.twig index 518a0ed..97db4ca 100644 --- a/src/Gist/Resources/views/View/view.html.twig +++ b/src/Gist/Resources/views/View/view.html.twig @@ -84,35 +84,6 @@ {{ parent() }} {% if gist.cipher %} - - - - + {{ include('View/cipherJs.html.twig') }} {% endif %} {% endblock %} diff --git a/src/Gist/Service/Gist.php b/src/Gist/Service/Gist.php index 45337f8..234678c 100644 --- a/src/Gist/Service/Gist.php +++ b/src/Gist/Service/Gist.php @@ -65,6 +65,10 @@ class Gist 'diff' => $this->highlight('diff', $diff), ); + if ($gist->isCipher()) { + $data['content'] = $this->getContent($gist, $commit); + } + $history[] = $data; } diff --git a/web/app/js/app.js b/web/app/js/app.js index 59c691c..b325e5a 100644 --- a/web/app/js/app.js +++ b/web/app/js/app.js @@ -66,14 +66,28 @@ var editorEvents = function() { $(this).trigger('change'); }); + var key = getKey(); + + if (key) { + $('.show-diff').each(function() { + var href = $(this).attr('href'); + href = href.replace('#', '#key=' + key + '&'); + + $(this).attr('href', href); + }); + } + $('.show-diff').click(function() { $($(this).data('target')).toggle(); }); - if ((document.location.href).indexOf('#diff-') !== -1) { + var diffLinkTest1 = (document.location.href).indexOf('#diff-') !== -1; + var diffLinkTest2 = (document.location.href).indexOf('&diff-') !== -1; + + if (diffLinkTest1 || diffLinkTest2) { var anchor = '#' + (document.location.href).toString().split('#')[1]; + $('.show-diff[href="' + anchor + '"]').click(); - document.location.href = anchor; } } @@ -119,7 +133,7 @@ var getKey = function() { var parts = url.split('#key='); if (parts.length === 2) { - return parts[1]; + return parts[1].split('&')[0]; } return null;