Source

noodle-bucket / templates / repos / repo.html

Full commit
{% extends "base.html" %}
{% load nbfilters %}

{% block title %}{{ repo.user_name }}/{{ repo.repo_name }}{% endblock %}

{% block script %}
<script type="text/javascript" charset="utf-8">
    $(document).ready(function() {
        var COL_WIDTH = 15;
        var NODE_CIRCLE_RADIUS = 3;
        var changesets = {% include "pasta-scripts/cset-list.js" %}
        var cset_count = {{ repo.changeset_set.all.count }};
        var paper = Raphael('pasta-bowl', 360, (cset_count + 2) * 21);
        
        var biggest_col = 0;
        var cset_col_map = {};
        var rendered = {};
        cset_col_map[changesets[0]['hash']] = 0;
        
        // Iterate through all the csets in order.
        _.each(changesets, function(cset) {
            var y = 10 + 21 + (cset['index'] * 21);
            
            var col;
            if (cset['hash'] in cset_col_map) {
                // If we know where this changeset needs to go, put it there.
                col = cset_col_map[cset['hash']];
            } else {
                // Otherwise it's a new changeset whose parent we haven't seen
                // and needs to go to the right of all the others.
                biggest_col += 1;
                col = biggest_col;
            };
            
            // Draw the node for the cset.
            // TODO: Add some sweet Intertube2.0 rollover effects.
            var node = paper.circle(
                (col * COL_WIDTH + COL_WIDTH / 2), y, NODE_CIRCLE_RADIUS
            );
            rendered[cset['hash']] = node;
            
            // If the parent changeset isn't already in the cset map, add it.
            if (!cset_col_map[cset['parent1']]) {
                cset_col_map[cset['parent1']] = col;
            };
        });
        
        // Root node to account for changesets we haven't loaded yet.
        var root = paper.circle(COL_WIDTH/2, ({{ repo.changeset_set.all.count }} + 2) * 21 - COL_WIDTH/2, NODE_CIRCLE_RADIUS);
        
        // Render the connection between nodes.
        // TODO: For now we're going to render anything we haven't seen as a
        // "root" node at the base of the graph.  This is fucking ugly and
        // needs to be fixed before we go live.
        var connections = [];
        _.each(changesets, function(cset) {
            if (cset['parent1'] in rendered) {
                connections.push(
                    paper.connection(rendered[cset['hash']], rendered[cset['parent1']], "#000", "#000|2")
                );
            } else {
                connections.push(
                    paper.connection(rendered[cset['hash']], root, "#000", "#000|2")
                );
            };
            
            // We might not have a second parent, but if we do we need to
            // connect it.
            if (cset['parent2'] != null) {
                if (cset['parent2'] in rendered) {
                    connections.push(
                        paper.connection(rendered[cset['hash']], rendered[cset['parent2']], "#000", "#000|2")
                    );
                } else {
                    connections.push(
                        paper.connection(rendered[cset['hash']], root, "#000", "#000|2")
                    );
                };
            };
        });
    });
</script>
{% endblock %}

{% block content %}
    <h2>
        Noodles of
        <a href="{{ repo.bitbucket_url }}">{{ repo.user_name }}/{{ repo.repo_name }}</a>
    </h2>
    
    <div id="repo-noodles-log">
        <div class="repo-noodle noodle-header">
            <span class="noodle-hash">Changeset</span>
            <span class="noodle-author">Author</span>
            <span class="noodle-message">Message</span>
        </div>
        {% for cset in repo.changeset_set.all %}
            <div class="repo-noodle">
                <span class="noodle-hash"><a href="{{ repo.bitbucket_url }}changeset/{{ cset.cset_hash }}/">{{ cset.cset_hash }}</a></span>
                <span class="noodle-author">{{ cset.cset_author|truncate_chars:15 }}</span>
                <span class="noodle-message">{{ cset.cset_message|firstline|truncate_chars:35 }}</span>
            </div>
        {% endfor %}
    </div>
    <div id="pasta-bowl"></div>
{% endblock %}