/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/static/javascript/diff.js

  • Committer: Colin Watson
  • Date: 2022-08-08 17:26:06 UTC
  • mto: This revision was merged to the branch mainline in revision 529.
  • Revision ID: cjwatson@canonical.com-20220808172606-77xzhydq226ohtma
Modernize packaging.

There are new dependencies on `importlib_metadata` (for Python < 3.8)
and `packaging`, in order to avoid a self-import in `setup.py`.  People
proxying Loggerhead through Apache should install the
`loggerhead[proxied]` extra; people running it via FastCGI, SCGI, or AJP
should install the `loggerhead[flup]` extra.

The version handling rearrangements make it possible to install
Loggerhead using `pip`.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
var unified = true;
2
2
 
3
 
function make_unified(chunk) {
 
3
function make_unified(index) {
4
4
  var pending_added = [];
5
5
  function flush_adds(before) {
6
6
    for (var i = 0; i < pending_added.length; i++) {
7
 
      before.ancestor().insertBefore(pending_added[i], before);
 
7
      $(pending_added[i]).insertBefore(before);
8
8
    }
9
9
    pending_added.length = 0;
10
10
  }
11
 
  chunk.get('children').filter(".pseudorow").each(
12
 
    function (line) {
 
11
  $(this).children().filter(".pseudorow").each(
 
12
    function (i, line) {
 
13
      line = $(line);
13
14
      if (line.hasClass("context-row")) {
14
15
        flush_adds(line);
15
 
        line.removeChild(line.query('.code'));
 
16
        line.find('.code')[0].remove();
16
17
      }
17
18
      else if (line.hasClass("both-row")) {
18
 
        var added_line = line.create('<div class="pseudorow insert-row"><div class="lineNumber first">&nbsp;</div><div class="clear">&nbsp;</div></div>');
19
 
        var clear = added_line.query('.clear');
20
 
        added_line.insertBefore(line.query('.lineNumber.second'), clear);
21
 
        added_line.insertBefore(line.query('.code.insert'), clear);
 
19
        var added_line = $('<div class="pseudorow insert-row"><div class="lineNumber first">&nbsp;</div><div class="clear">&nbsp;</div></div>');
 
20
        var clear = $(added_line).find('.clear');
 
21
        $(line).find('.lineNumber.second').insertBefore(clear);
 
22
        $(line).find('.code.insert').insertBefore(clear);
22
23
        pending_added[pending_added.length] = added_line;
23
 
        line.insertBefore(line.create('<div class="lineNumber second">&nbsp;</div>'), line.query('.code.delete'));
24
 
        line.replaceClass("both-row", "delete-row");
 
24
        $('<div class="lineNumber second">&nbsp;</div>').insertBefore($(line).find('.code.delete'));
 
25
        line.addClass('delete-row').removeClass('both-row');
25
26
      }
26
27
      else if (line.hasClass("insert-row")) {
27
28
        flush_adds(line);
28
 
        line.removeChild(line.query('.blank'));
 
29
        line.find('.blank').remove();
29
30
      }
30
31
      else if (line.hasClass("delete-row")) {
31
 
        line.removeChild(line.query('.blank'));
32
 
        line.insertBefore(line.query('.lineNumber.second'), line.query('.code.delete'));
 
32
        $(line).find('.blank').remove();
 
33
        $(line).find('.lineNumber.second').insertBefore($(line).find('.code.delete'));
33
34
      }
34
35
    });
35
36
  flush_adds(null);
36
 
  chunk.replaceClass('sbs', 'unified');
 
37
  $(this).addClass('unified').removeClass('sbs');
37
38
}
38
39
 
39
 
function make_sbs(chunk) {
 
40
function make_sbs(index) {
40
41
  var added = [];
41
42
  var removed = [];
42
43
  function clear_bufs(before) {
45
46
    for (var i = 0; i < common; i++) {
46
47
      var a = added[i];
47
48
      var r = removed[i];
48
 
      a.ancestor().removeChild(a);
49
 
      r.removeChild(r.query('.lineNumber.second'));
50
 
      r.insertBefore(a.query('.lineNumber.second'), r.query('.clear'));
51
 
      r.insertBefore(a.query('.code.insert'), r.query('.clear'));
52
 
      r.replaceClass('removed-row', 'both-row');
 
49
      a.remove();
 
50
      r.find('.lineNumber.second').remove();
 
51
      $(a).find('.lineNumber.second').insertBefore($(r).find('.clear'));
 
52
      $(a).find('.code.insert').insertBefore($(r).find('.clear'));
 
53
      r.addClass('both-row').removeClass('removed-row');
53
54
    }
54
55
    if (added.length > removed.length) {
55
56
      for (var j = common; j < added.length; j++) {
56
 
        a = added[j];
57
 
        a.insertBefore(a.create('<div class="blank">&nbsp;</div>'), a.query('.lineNumber.second'));
 
57
        a = $(added[j]);
 
58
        a.find('.lineNumber.second').before('<div class="code blank">&nbsp;</div>');
58
59
      }
59
60
    }
60
61
    else if (added.length < removed.length) {
61
62
      for (var j = common; j < removed.length; j++) {
62
 
        r = removed[j];
63
 
        r.insertBefore(r.query('.code.delete'), r.query('.lineNumber.second'));
64
 
        r.insertBefore(r.create('<div class="blank">&nbsp;</div>'), r.query('.clear'));
 
63
        r = $(removed[j]);
 
64
        r.find('.code.delete').insertBefore(r.find('.lineNumber.second'));
 
65
        r.find('.clear').before('<div class="code blank">&nbsp;</div>')
65
66
      }
66
67
    }
67
68
    added.length = 0;
68
69
    removed.length = 0;
69
70
  }
70
 
  chunk.get('children').filter(".pseudorow").each(
71
 
    function (line) {
 
71
  $(this).children().filter(".pseudorow").each(
 
72
    function (i, line) {
 
73
      line = $(line);
72
74
      if (line.hasClass("context-row")) {
73
75
        clear_bufs(line);
74
 
        line.insertBefore(line.query('.code').cloneNode(true), line.query(".second"));
 
76
        $(line).find(".second").before($(line).find('.code').clone());
75
77
      }
76
78
      else if (line.hasClass("insert-row")) {
77
79
        added[added.length] = line;
81
83
      }
82
84
    });
83
85
  clear_bufs(null);
84
 
  chunk.replaceClass('unified', 'sbs');
 
86
  $(this).addClass('sbs').removeClass('unified');
85
87
 
86
88
}
87
89
 
88
90
function toggle_unified_sbs(event) {
89
91
  event.preventDefault();
90
 
  var pts = Y.all(".pseudotable");
 
92
  var pts = $(".pseudotable");
91
93
  if (unified) {
92
94
    pts && pts.each(make_sbs);
93
95
    unified = false;
94
 
    Y.get("#toggle_unified_sbs").set('innerHTML', "Show unified diffs");
 
96
    $("#toggle_unified_sbs").html("Show unified diffs");
95
97
  }
96
98
  else {
97
99
    pts && pts.each(make_unified);
98
100
    unified = true;
99
 
    Y.get("#toggle_unified_sbs").set('innerHTML', "Show diffs side-by-side");
 
101
    $("#toggle_unified_sbs").html("Show diffs side-by-side");
100
102
  }
101
103
}
102
104
 
103
 
Y.on("click", toggle_unified_sbs, '#toggle_unified_sbs');
 
105
$(function() {
 
106
$('#toggle_unified_sbs').on("click", toggle_unified_sbs);
 
107
});
104
108
 
105
109
function toggle_expand_all_revisionview(action)
106
110
{
107
 
  var diffs = Y.all('.diff');
 
111
  var diffs = $('.diff');
108
112
  if (diffs == null) return;
109
113
  diffs.each(
110
 
    function(item, i)
 
114
    function(i, item)
111
115
    {
112
116
      var collapsable = item.collapsable;
113
117
      if(action == 'close')
114
118
      {
115
 
        Y.get('#expand_all').setStyle('display','block');
116
 
        Y.get('#collapse_all').setStyle('display','none');
 
119
        $('#expand_all').css({'display': 'block'});
 
120
        $('#collapse_all').css({'display': 'none'});
117
121
        collapsable.close();
118
122
      }
119
123
      else if(action == 'open')
120
124
      {
121
 
        Y.get('#expand_all').setStyle('display','none');
122
 
        Y.get('#collapse_all').setStyle('display','block');
 
125
        $('#expand_all').css({'display': 'none'});
 
126
        $('#collapse_all').css({'display': 'block'});
123
127
        collapsable.open();
124
128
      }
125
129
    });
126
130
}
127
131
 
128
 
Y.on(
 
132
$(function() {
 
133
$('#expand_all a').on(
129
134
  'click',
130
135
  function (event) {
131
136
    event.preventDefault();
132
137
    toggle_expand_all_revisionview('open');
133
138
  },
134
 
  '#expand_all a'
135
139
);
 
140
});
136
141
 
137
 
Y.on(
 
142
$(function() {
 
143
$('#collapse_all a').on(
138
144
  'click',
139
145
  function (event) {
140
146
    event.preventDefault();
141
147
    toggle_expand_all_revisionview('close');
142
148
  },
143
 
  '#collapse_all a'
144
149
);
 
150
});
145
151
 
146
152
function node_process(node) {
147
153
  if (!unified) {
148
 
    node.get('children').filter('.pseudotable').each(make_sbs);
 
154
    node.children().filter('.pseudotable').each(make_sbs);
149
155
  }
150
156
}
151
157
 
152
158
function zoom_to_diff (path) {
153
 
  var collapsable = Y.get('#' + path_to_id[path]).collapsable;
 
159
  var collapsable = $('#' + path_to_id[path]).collapsable;
154
160
  if (!collapsable.is_open) {
155
161
    collapsable.open(
156
162
      function () {
159
165
  }
160
166
}
161
167
 
162
 
Y.on(
163
 
  "domready", function () {
164
 
    Y.all(".show_if_js").removeClass("show_if_js");
 
168
var original_diff_download_link = null;
 
169
 
 
170
function compute_diff_links() {
 
171
  var numlines = $('#contextLines').val();
 
172
  $('.diff').each(
 
173
    function(i, item)
 
174
    {
 
175
      item.collapsable.source = global_path + '+filediff/' + link_data[item.id] + '?context=' + numlines;
 
176
    });
 
177
  if(original_diff_download_link == null) original_diff_download_link = $('#download_link').attr('href');
 
178
  $('#download_link').attr('href', original_diff_download_link + '?context=' + numlines);
 
179
}
 
180
 
 
181
function get_num_lines() {
 
182
  var numlines = $('#contextLines').val();
 
183
  return numlines;
 
184
}
 
185
 
 
186
$(function () {
 
187
    $(".show_if_js").removeClass("show_if_js");
165
188
    if (!specific_path) {
166
 
      Y.all("#list-files a").on(
 
189
      $("a#list-files").on(
167
190
        'click',
168
191
        function (e) {
169
192
          e.preventDefault();
170
 
          var path = decodeURIComponent(e.target.get('href').split('#')[1]);
 
193
          var path = decodeURIComponent(e.target.href.split('#')[1]);
171
194
          window.location.hash = '#' + path;
172
195
          zoom_to_diff(path);
173
196
        });
174
197
    }
175
 
    var diffs = Y.all('.diff');
 
198
    var diffs = $('.diff');
176
199
    if (diffs == null) return;
 
200
    var numlines = $('#contextLines').val();
177
201
    diffs.each(
178
 
      function(item, i)
 
202
      function(i, item)
179
203
      {
180
 
        var source_url = null;
181
 
        if (!specific_path)
182
 
          source_url = global_path + '+filediff/' + link_data[item.get('id')];
183
 
        item.query('.the-link').on(
 
204
        var source_url = global_path + '+filediff/' + link_data[item.id] + '?context=' + numlines;
 
205
        $(item).find('.the-link').on(
184
206
          'click',
185
207
          function(e) {
186
208
            e.preventDefault();
 
209
            item.collapsable.source = global_path + '+filediff/' + link_data[item.id] + '?context=' + $('#contextLines').val();
187
210
            collapsable.toggle();
188
211
          });
189
212
        var collapsable = new Collapsable(
190
213
          {
191
 
            expand_icon: item.query('.expand_diff'),
192
 
            open_node: item.query('.diffinfo'),
 
214
            expand_icon: $(item).find('.expand_diff'),
 
215
            open_node: $(item).find('.diffinfo'),
193
216
            close_node: null,
194
217
            source: source_url,
195
218
            is_open: specific_path != null,
196
 
            loading: item.query('.loading'),
 
219
            loading: $(item).find('.loading'),
197
220
            node_process: node_process
198
221
          });
199
222
       item.collapsable=collapsable;
200
223
       });
 
224
    compute_diff_links();
201
225
    if (window.location.hash && !specific_path) {
202
226
      zoom_to_diff(window.location.hash.substring(1));
203
227
    }