PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/web/log.php

https://bitbucket.org/yoander/mtrack
PHP | 156 lines | 133 code | 18 blank | 5 comment | 18 complexity | 73b92f0925dca20e0bc9a918b84df777 MD5 | raw file
Possible License(s): BSD-3-Clause, Apache-2.0
  1. <?php # vim:ts=2:sw=2:et:
  2. /* For licensing and copyright terms, see the file named LICENSE */
  3. include '../inc/common.php';
  4. MTrackACL::requireAllRights('Browser', 'read');
  5. $pi = mtrack_get_pathinfo(true);
  6. $crumbs = MTrackSCM::makeBreadcrumbs($pi);
  7. if (!strlen($pi)) {
  8. $pi = '/';
  9. }
  10. $params = array();
  11. if (isset($_GET['jump']) && strlen($_GET['jump'])) {
  12. $jump = '?jump=' . urlencode($_GET['jump']);
  13. list($object, $ident) = explode(':', $_GET['jump'], 2);
  14. $params[$object] = $ident;
  15. } else {
  16. $_GET['jump'] = '';
  17. $jump = '';
  18. }
  19. $hist = MTrackAPI::invoke('GET', '/repo/history' . $pi, null, $params)->result;
  20. mtrack_head("Log $pi");
  21. /* Render a bread-crumb enabled location indicator */
  22. echo "<div class='browselocation'>Location: ";
  23. $location = null;
  24. $last = array_pop($crumbs);
  25. foreach ($crumbs as $i => $path) {
  26. if ($i == 0) {
  27. $path = '[root]';
  28. echo "<a href='{$ABSWEB}browse.php$jump'>$path</a> / ";
  29. } else if ($i == 1) {
  30. $location .= '/' . htmlentities(urlencode($path), ENT_QUOTES, 'utf-8');
  31. echo "<a href='{$ABSWEB}browse.php$location$jump'>$path</a> / ";
  32. } else {
  33. $location .= '/' . htmlentities(urlencode($path), ENT_QUOTES, 'utf-8');
  34. echo "<a href='{$ABSWEB}log.php$location$jump'>$path</a> / ";
  35. }
  36. }
  37. echo "$last";
  38. $branches = $hist->branches;
  39. $tags = $hist->tags;
  40. if (count($branches) + count($tags)) {
  41. $jumps = array("" => "- Select Branch / Tag - ");
  42. if (is_array($branches)) {
  43. foreach ($branches as $name => $notcare) {
  44. $jumps["branch:$name"] = "Branch: $name";
  45. }
  46. }
  47. if (is_array($tags)) {
  48. foreach ($tags as $name => $notcare) {
  49. $jumps["tag:$name"] = "Tag: $name";
  50. }
  51. }
  52. echo "<form>";
  53. echo mtrack_select_box("jump", $jumps, $_GET['jump']);
  54. echo "<button type='submit'>Choose</button></form>\n";
  55. }
  56. echo "</div>";
  57. $hist = json_encode($hist);
  58. echo <<<HTML
  59. <script type="text/template" id='hist-template'>
  60. <div class='histevent'>
  61. <a class='pmark' href='#<%- rev %>'>#</a> <a name='<%- rev %>'>&nbsp;</a><abbr class='timeinterval' title='<%- when %>'><%- when %></abbr> <%- who %>
  62. </div>
  63. <div class='histinfo'>
  64. <img class='gravatar' src="${ABSWEB}avatar.php?u=<%- who %>&amp;s=36">
  65. <a class='changesetlink' href='<%- url %>'>[<%- shortrev %>]</a>
  66. <% if (branch) { %>
  67. <span class='branchname'><%- branch %></span>
  68. <% } %>
  69. <% _.each(tags, function (t) { %>
  70. <span class='tagname'><%- t %></span>
  71. <% }); %>
  72. <div class='changelog'><%= changelog_html %></div>
  73. </div>
  74. </script>
  75. <div id="history">
  76. <em>No history for the requested path</em>
  77. </div>
  78. <script>
  79. $(document).ready(function () {
  80. var hist = $hist;
  81. var templ = _.template($('#hist-template').html());
  82. function get_more() {
  83. /* find earliest revision */
  84. var rev = hist.entries[hist.entries.length-1].rev;
  85. var params = {
  86. rev: rev,
  87. // ask for 1 more; we're basing off the last one we saw and this
  88. // will be included in the results
  89. limit: hist.limit + 1
  90. };
  91. $.ajax({
  92. url: ABSWEB + 'api.php/repo/history/' +
  93. hist.repo + '/' + hist.path,
  94. data: params,
  95. success: function(data) {
  96. if (data.entries.length > 1) {
  97. data.entries.shift(); // this is a duplicate; remove it
  98. data.prev = hist;
  99. hist = data;
  100. add_entries(data);
  101. }
  102. },
  103. complete: function() {
  104. $('#history button').removeAttr('disabled');
  105. }
  106. });
  107. }
  108. function add_entries(hist) {
  109. var H = $('#history');
  110. $('button', H).remove();
  111. _.each(hist.entries, function (ent) {
  112. var d = $('<div class="histentry"/>');
  113. ent.url = ABSWEB + 'changeset.php/' + hist.repo + '/' + ent.rev;
  114. var r = ent.rev + '';
  115. if (r.length > 12) {
  116. r = r.substr(0, 12);
  117. }
  118. ent.shortrev = r;
  119. d.html(templ(ent));
  120. H.append(d);
  121. });
  122. var b = $('<button>More</button>');
  123. H.append(b);
  124. b.click(function () {
  125. $(this).attr('disabled', 'disabled');
  126. get_more();
  127. });
  128. $('abbr.timeinterval', H).timeago();
  129. }
  130. if (hist.entries.length) {
  131. var H = $('#history');
  132. H.empty();
  133. add_entries(hist);
  134. }
  135. });
  136. </script>
  137. HTML;
  138. mtrack_foot();