aboutsummaryrefslogtreecommitdiffstats
path: root/templates/gitrefinery/release.html
blob: 3344e6b82977ff50794e38e1a771c450bacbeca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
{% extends "base.html" %}
{% load i18n %}
{% load static %}

{% comment %}

  git-refinery-web - release page template

  Copyright (C) 2014-2018 Intel Corporation
  Licensed under the MIT license, see COPYING.MIT for details

{% endcomment %}


<!--
{% autoescape on %}
{% block title_append %} - {{ release.repository.name }} - {{ release.name }}{% endblock %}
{% endautoescape %}
-->

{% block content %}

{% autoescape on %}
        <ul class="breadcrumb">
            <li><a href="{% url 'repositories' %}">repositories</a> <span class="divider">&rarr;</span></li>
            <li><a href="{% url 'repository' release.repository.name %}">{{ release.repository.name }}</a> <span class="divider">&rarr;</span></li>
            <li class="active">{{ release.name }}</li>
        </ul>

        <div class="container-fluid">
            <div class="row">
                <div class="page-header">
                    <h1>{{ release.repository.name }} - {{ release.name }}
                        {% if user.is_authenticated %}
                            <span class="pull-right">
                                <a href="{% url 'edit_release' release.id %}" class="btn btn-default">Edit release</a>
                                <a href="{% url 'import_commits' release.id %}" class="btn btn-default">Import commits</a>
                                <a href="{% url 'delete_release' release.id %}?cancel=release" class="btn btn-warning">Delete release</a>
                            </span>
                        {% endif %}
                    </h1>
                </div>
            </div> <!--  end of row -->
        </div> <!-- end of container-fluid -->

        <div class="container-fluid">

            <div class="row">
                <form id="filter-form" class="form-inline" action="{% url 'release' release.id %}" method="get">
                    <input type="text" class="form-control input-xlarge" placeholder="Search commits" name="q" value="{{ search_keyword }}" />
                    <select name="category" class="form-control input-medium">
                        <option value="" {% if search_category == -1 %}selected{% endif %}>-------</option>
                        <option value="-2" {% if search_category == -2 %}selected{% endif %}>-uncategorised-</option>
                        {% for cat in release.repository.category_set.all %}
                            <option value="{{ cat.id }}" {% if search_category == cat.id %}selected{% endif %}>{{ cat.name }}</option>
                        {% endfor %}
                    </select>
                    <select name="authorgroup" class="form-control input-medium">
                        <option value="" {% if search_authorgroup == -1 %}selected{% endif %}>-------</option>
                        <option value="-2" {% if search_authorgroup == -2 %}selected{% endif %}>-no group-</option>
                        {% for group in authorgroups %}
                            <option value="{{ group.id }}" {% if search_authorgroup == group.id %}selected{% endif %}>{{ group.name }}</option>
                        {% endfor %}
                    </select>

                    <div class="input-group">
                        <input type="text" class="input-large" id="id_excludecategories_display" value="{{ excludecategories_display }}" />
                        <span class="input-group-btn">
                            <button type="button" id="id_select_excludecategories" class="btn btn-default" data-toggle="modal" data-target="#excludecategoryDialog">...</button>
                        </span>
                    </div>
                    <input type="hidden" id="id_excludecategories" name="excludecategories" value="{{ excludecategories|join:"," }}" />

                    <div id="excludecategoryDialog" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="categoryDialogLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal">×</button>
                                    <h3 id="categoryDialogLabel">Select categories to exclude</h3>
                                </div>
                                <div class="modal-body">
                                    <div class="scrolling" id="id_excludecategorydialog_list">
                                    </div>
                                    <div class="buttonblock">
                                    <button type="button" class="btn btn-default" id="id_excludecategorydialog_select_all">Select all</button>
                                    <button type="button" class="btn buttonblock-btn btn-default" id="id_excludecategorydialog_select_none">Select none</button>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button class="btn btn-primary" id="id_excludecategorydialog_ok" data-dismiss="modal">OK</button>
                                    <button class="btn btn-default" id="id_excludecategorydialog_cancel" data-dismiss="modal">Cancel</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <button class="btn btn-default" type="submit">Search</button>
                </form>
            </div>

            {% if commits %}
            <div class="row">
                <form id="recipe-select-form" method="POST">
                    {% csrf_token %}
                    <table class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                {% if user.is_authenticated %}
                                <th></th>
                                {% endif %}
                                <th class="col-md-8">Message</th>
                                <th>Author</th>
                                <th>Date</th>
                            </tr>
                        </thead>
                        {% if user.is_authenticated %}
                        <tfoot>
                            <tr class="form-inline">
                                <td colspan="4">
                                    <button class="btn btn-default" type="button" id="selectall">Select all</button>
                                    <button class="btn btn-default" type="button" id="selectnone">Select none</button>
                                    <select name="action" class="form-control input-large buttonblock-btn">
                                        <option value="categorise">Add to category</option>
                                        <option value="uncategorise">Remove from category</option>
                                    </select>
                                    <select name="catvalue" class="form-control input-medium">
                                        <option value="">-------</option>
                                        {% for cat in release.repository.category_set.all %}
                                            <option value="{{ cat.id }}">{{ cat.name }}</option>
                                        {% endfor %}
                                    </select>
                                    <button class="btn btn-default" type="submit" value="apply">Apply</button>
                                </td>
                            </tr>
                        </tfoot>
                        {% endif %}


                        <tbody>
                            {% for commit in commits %}
                                <tr {% if false %}class="text-muted"{% endif %} id="commitrow-{{ commit.revision }}">
                                    {% if user.is_authenticated %}
                                    <td><input type="checkbox" class="selecteditems" name="selecteditems" value="{{ commit.revision }}"></input></td>
                                    {% endif %}
                                    <td>
                                        <!-- <i class="glyphicon glyphicon-file{% if not commit.note %} hide{% endif %}" id="note-icon-{{ commit.revision }}"></i> -->
                                        <a href="#" data-toggle="collapse" class="commitlink" data-commit="{{ commit.revision }}" id="commitlink-{{ commit.revision }}">
                                            {{ commit.shortlog }}
                                        </a>
                                        {% for cat in commit.commitcategory_set.all %}
                                            <span class="commitcategory-{{ commit.revision }}-{{ cat.category.id }}">
                                                <a href="{% url 'release' release.id %}?category={{ cat.category.id }}"><span class="label {% if cat.has_unique_note %}label-success{% else %}label-warning{% endif %}" id="label-commitcat-{{ commit.revision }}-{{ cat.category.name }}">{{ cat.category.name }}</span></a>
                                            </span>
                                        {% endfor %}
                                        {% for tag in commit.tags %}
                                            <span class="label label-info">{{ tag }}</span>
                                        {% endfor %}
                                    </td>
                                    <td>{{ commit.author }}</td>
                                    <td>{{ commit.committed_date|date }}</td>
                                </tr>
                                <tr><td colspan="4" class="hidden-row"><div id="div-{{ commit.revision }}" class="accordian-body collapse commitmessage" data-commit="{{ commit.revision }}">
                                    <pre class="noborder">{{ commit.commit_message }}</pre>
                                    {% if commit.url %}<a href="{{ commit.url }}" target="_blank" rel="noreferrer">{% endif %}
                                    <small><p class="text-right">{{ commit.revision }}</p></small>
                                    {% if commit.url %}</a>{% endif %}
                                    {% if user.is_authenticated %}
                                        <div class="commitcategoryeditor template-element">
                                            <div class="form-inline">
                                                <div class="label label-warning"></div>
                                                <button type="button" class="btn btn-default savebutton">Save</button>
                                                <button type="button" class="btn btn-default removebutton">Remove</button>
                                                <span class="alert success fade" data-alert="alert">Saved</span>
                                            </div>
                                            <textarea rows="2" class="committext"></textarea>
                                        </div>

                                        {% for commitcat in commit.commitcategory_set.all %}
                                        <div class="commitcategoryeditor commitcategory-{{ commit.revision }}-{{ commitcat.category.id }}" data-commit="{{ commit.revision }}" data-category="{{ commitcat.category.id }}">
                                        <div class="form-inline">
                                            <div class="label {% if commitcat.has_unique_note %}label-success{% else %}label-warning{% endif %}">{{ commitcat.category.name }}</div>
                                            <button type="button" class="btn btn-default savebutton">Save</button>
                                            <button type="button" class="btn btn-default removebutton">Remove</button>
                                            <span class="alert success fade" data-alert="alert">Saved</span>
                                        </div>
                                        <textarea rows="2" class="committext">{{ commitcat.note }}</textarea>
                                        </div>
                                        {% endfor %}

                                        {% for cat in release.repository.category_set.all %}
                                            {% if not cat.hidden %}
                                            <a href="#" class="addcategory" data-category="{{ cat.id }}"><div class="label label-default">{{ cat.name }}</div></a>
                                            {% endif %}
                                        {% endfor %}
                                    {% elif commit.note %}
                                        <div class="well">{{ commit.note }}</div>
                                    {% endif %}
                                </div></td></tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </form>

                {% if is_paginated %}
                    {% load pagination %}
                    {% pagination page_obj %}
                {% endif %}

            {% else %}
                <p>No matching commits found for this release.</p>
            {% endif %}

            </div> <!-- end of row -->
            <a href="{% url 'release_notes' release.id %}" class="btn btn-lg btn-primary">Review notes &gt;</a>

        </div> <!-- end of container-fluid -->


{% endautoescape %}

{% endblock %}


{% block scripts %}
    <script src="{% static "js/ajax.js" %}"></script>
<script>
    update_excludecategories_display = function() {
        categorynames = [];
        categoryids = [];
        $('.filtercategorycheckbox:checked').each(function() {
            categorynames.push($("label[for="+parseInt($(this).attr('id'))+"]").html());
            categoryids.push($(this).attr('value'));
        });
        if(categorynames.length)
            $('#id_excludecategories_display').val(categorynames)
        else
            $('#id_excludecategories_display').val(' (none)');
        $('#id_excludecategories').val(categoryids)
    }

{% if user.is_authenticated %}
    // Borrowed from  http://www.jquery4u.com/tutorials/jqueryhtml5-input-focus-cursor-positions/
    $.fn.setCursorPosition = function(pos) {
        this.each(function(index, elem) {
            if (elem.setSelectionRange) {
                elem.setSelectionRange(pos, pos);
            }
            else if (elem.createTextRange) {
                var range = elem.createTextRange();
                range.collapse(true);
                range.moveEnd('character', pos);
                range.moveStart('character', pos);
                range.select();
            }
        });
        return this;
    };

    var saveTimer = null;
    saveMessage = function(commit, category) {
        clearTimeout(saveTimer);
        editor = $(".commitcategoryeditor").filter("[data-commit=" + commit + "]").filter("[data-category=" + category + "]")
        note = $(".committext", editor).val()
        alert = $(".alert", editor)
        $.ajax({type: "POST", url : '{% url 'set_commit_note' %}',
            data: {
                "release": "{{ release.id }}",
                "commit": commit,
                "category": category,
                "note": note,
                },
            error: function (xhr, ajaxOptions, errorThrown) {
                alert.removeClass('alert-success')
                alert.addClass('alert-error')
                alert.addClass('in');
                alert.html('Saving failed')
            },
            success: function (data) {
                /*
                noteicon = $('#note-icon-' + commit)
                if ( note.length ) {
                    noteicon.removeClass('hide');
                    noteicon.show();
                }
                else {
                    noteicon.hide();
                }
                */
                alert.removeClass('alert-error')
                alert.addClass('alert-success')
                alert.addClass('in');
                alert.html('Saved successfully')
                setTimeout(function() {
                    alert.removeClass('in');
                }, 2000);
            }
        });
    }

    dropCategory = function(commit, category) {
        $(".commitcategory-" + commit + "-" + category).remove()
        $(".commitmessage").filter("[data-commit=" + commit + "]").children(".addcategory").filter("[data-category=" + category + "]").show()
    }

    removeCommitCategory = function(commit, category) {
        alert = $('#alert-' + commit + '-' + category)
        $.ajax({type: "POST", url : '{% url 'remove_commit_category' %}',
            data: {
                "release": "{{ release.id }}",
                "commit": commit,
                "category": category,
                },
            error: function (xhr, ajaxOptions, errorThrown) {
                alert.removeClass('alert-success')
                alert.addClass('alert-error')
                alert.addClass('in');
                alert.html('Removing from category failed')
            },
            success: function (data) {
                dropCategory(commit, category)
            }
        });
    }
{% endif %}

    select_excludecategory_checkboxes = function() {
        $('.filtercategorycheckbox').prop('checked', false);
        excludecategories = $('#id_excludecategories').val().split(',');
        for(i in excludecategories) {
            $('#id_categorycheckbox_' + excludecategories[i]).prop('checked', true);
        }
    }
    setup_excludecategory_list = function() {
        if( $.trim($('#id_excludecategorydialog_list').html()) ) {
            select_excludecategory_checkboxes()
        }
        else {
            $('#id_excludecategorydialog_list').html('Loading...');
            $('#id_excludecategorydialog_ok').prop('disabled', true)
            $('#id_excludecategorydialog_ok').addClass('disabled')
            $.ajax({
                url: '{% url 'category_checklist' release.repository.id %}',
                dataType: 'html',
                success: function( resp ) {
                    $('#id_excludecategorydialog_list').html(resp);
                    select_excludecategory_checkboxes()
                    $('#id_excludecategorydialog_ok').prop('disabled', false)
                    $('#id_excludecategorydialog_ok').removeClass('disabled')
                },
                error: function( req, status, err ) {
                    $('#id_excludecategorydialog_list').html(err);
                    console.log( 'something went wrong', status, err );
                }
            });
        }
    }
    $(document).ready(function() {
        $('#id_excludecategories_display').prop('readonly', true)
    });
    $('#id_excludecategorydialog_select_all').click(function (e) {
        $('.filtercategorycheckbox').prop('checked', true);
    });
    $('#id_excludecategorydialog_select_none').click(function (e) {
        $('.filtercategorycheckbox').prop('checked', false);
    });
    $('#id_excludecategorydialog_ok').click(function (e) {
        update_excludecategories_display()
    });
    $('#id_select_excludecategories').click(function (e) {
        setup_excludecategory_list()
    });

    $('a[href=\\#]').click(function(e) {
        // Prevent invalid links from jumping page scroll
        e.preventDefault()
    });
    $('.commitlink').on('click', function () {
        commit = $(this).attr("data-commit")
        commit_div = $('#div-' + commit)
        if ( commit_div.hasClass("in")) {
            commit_div.collapse("hide");
        }
        else {
            $('.commitmessage').not(commit_div).each(function() {
                if ( $(this).hasClass("in")) {
                    $(this).collapse("hide");
                }
            });
            commit_div.collapse("show");
        }
    });
{% if user.is_authenticated %}
    $('.commitmessage').on('shown', function () {
        commit = $(this).attr("data-commit")
        el = $(this).find('textarea').first()
        if(el.length) {
            el.focus()
            el.setCursorPosition(el.val().length)
        }
    });
    $('#selectall').click(function() {
        $(".selecteditems").prop("checked", true)
    });
    $('#selectnone').click(function() {
        $(".selecteditems").prop("checked", false)
    });

    $('.savebutton').click(function() {
        editor = $(this).parents(".commitcategoryeditor")
        commit = editor.attr("data-commit")
        category = editor.attr("data-category")
        saveMessage(commit, category);
    });
    $('.removebutton').click(function() {
        editor = $(this).parents(".commitcategoryeditor")
        commit = editor.attr("data-commit")
        category = editor.attr("data-category")
        removeCommitCategory(commit, category)
    });
    $('.addcategory').click(function() {
        commit_div = $(this).parents(".commitmessage")
        commit = commit_div.attr("data-commit")
        category = $(this).attr("data-category")
        newcat = $(".template-element", commit_div).filter('.commitcategoryeditor').clone(true)
        newcat.insertAfter($(".commitcategoryeditor", commit_div).last())
        newcat.removeClass("template-element")
        newcat.addClass("commitcategory-" + commit + "-" + category)
        $(".label", newcat).text($(this).text())
        newcat.show()
        newcat.attr("data-commit", commit)
        newcat.attr("data-category", category)
        $(this).hide()
        el = $(".committext", newcat)
        el.focus()
        el.setCursorPosition(el.val().length)
        saveMessage(commit, category);
    });
    $('.committext').keyup(function() {
        editor = $(this).parents(".commitcategoryeditor")
        commit = editor.attr("data-commit")
        category = editor.attr("data-category")
        $('.alert', parent).removeClass('in');
        if (saveTimer) {
            clearTimeout(saveTimer);
        }
        saveTimer = setTimeout(function() {
            saveMessage(commit, category)
        }, 1000);
    });

    $('.commitcategoryeditor').each(function() {
        category = $(this).attr("data-category")
        $(this).parent().children(".addcategory").filter("[data-category=" + category + "]").hide()
    });
{% endif %}

</script>
{% endblock %}