summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/templates/layers.html
blob: db34fe48186e24fdcb631e56a78706f329e9317c (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
{% extends "baseprojectpage.html" %}
{% load projecttags %}
{% load humanize %}

{% block localbreadcrumb %}
<li>Layers</li>
{% endblock %}

{% block projectinfomain %}
                <div class="page-header">
                    <h1>
  {% if request.GET.filter and objects.paginator.count >  0 or request.GET.search and objects.paginator.count >  0 %}
      {{objects.paginator.count}} layer{{objects.paginator.count|pluralize}} found
  {% elif request.GET.filter and objects.paginator.count ==  0 or request.GET.search and objects.paginator.count == 0 %}
      No layers found
  {%else%}
      All layers
  {%endif%}
                        <i class="icon-question-sign get-help heading-help" title="This page lists all the layers compatible with {{project.release.name}} that Toaster knows about."></i>
                     </h1>
                </div>

  <div id="zone1alerts">
  </div>


{% include "basetable_top_layers.html" %}
    {% for o in objects %}
    <tr class="data">
            <td class="layer"><a href="{% url 'layerdetails' o.id %}">{{o.layer.name}}</a></td>
            <td class="description">{% if o.layer.summary %}{{o.layer.summary}}{%endif%}</td>
            <td class="source"><a href="{% url 'layerdetails' o.pk %}">{{o.layer_source.name}}</a></td>
            <td class="git-repo"><a href="{% url 'layerdetails' o.pk %}"><code>{{o.layer.vcs_url}}</code></a>
            {% if o.get_vcs_link_url %}
            <a target="_blank" href="{{ o.get_vcs_link_url }}"><i class="icon-share get-info"></i></a>
        {% endif %}
        </td>
            <td class="git-subdir" style="display: table-cell;"><a href="{% url 'layerdetails' o.pk %}"><code>{{o.dirpath}}</code></a>
                {% if o.dirpath and o.get_vcs_dirpath_link_url %}
            <a target="_blank" href="{{ o.get_vcs_dirpath_link_url }}"><i class="icon-share get-info"></i></a>
                {% endif %}
        </td>
            <td class="branch">{% if o.branch %}{{o.branch}}{% else %}{{o.up_branch.name}}{% endif %}</td>
            <td class="dependencies">
        {% with ods=o.dependencies.all%}
            {% if ods.count %}
                    <a class="btn"
                        title="<a href='{% url "layerdetails" o.pk %}'>{{o.layer.name}}</a> dependencies"
                        data-content="<ul class='unstyled'>
                          {% for i in ods%}
                            <li><a href='{% url "layerdetails" i.depends_on.pk %}'>{{i.depends_on.layer.name}}</a></li>
                          {% endfor %}
                        </ul>">
                        {{ods.count}}
                    </a>
            {% endif %}
        {% endwith %}
            </td>
            {% if project %}
            <td class="add-del-layers" value="{{o.pk}}">
                <div id="layer-tooltip-{{o.pk}}" style="display: none; font-size: 11px; line-height: 1.3;" class="tooltip-inner">layer was modified</div>
                <button id="layer-del-{{o.pk}}" class="btn btn-danger btn-block remove-layer layerbtn" style="display:none;" onclick="layerDel({{o.pk}}, '{{o.layer.name}}', '{%url 'layerdetails' o.pk%}')" >
                    <i class="icon-trash"></i>
                    Delete layer
                </button>
                <button id="layer-add-{{o.pk}}" class="btn btn-block layerbtn" style="display:none;" onclick="layerAdd({{o.pk}}, '{{o.layer.name}}', '{%url 'layerdetails' o.pk%}')" title="layer added">
                    <i class="icon-plus"></i>
                    Add layer
                </button>
            </td>
            {% endif %}
     </tr>
    {% endfor %}
{% include "basetable_bottom.html" %}

    <!-- Modals -->

    <!-- 'Layer dependencies modal' -->
    <div id="dependencies_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true">
        <form id="dependencies_modal_form" style="margin: 0px">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
            <h3><span class="layer-name"></span> dependencies</h3>
        </div>
        <div class="modal-body">
            <p><strong class="layer-name"></strong> depends on some layers that are not added to your project. Select the ones you want to add:</p>
            <ul class="unstyled" id="dependencies_list">
            </ul>
        </div>
        <div class="modal-footer">
            <button class="btn btn-primary" type="submit">Add layers</button>
            <button class="btn" type="reset" data-dismiss="modal">Cancel</button>
        </div>
        </form>
    </div>

{% if project %}
<script>

var tooltipUpdateText;

function _makeXHREditCall(data, onsuccess, onfail) {
    $.ajax( {
        type: "POST",
        url: "{% url 'xhr_projectedit' project.id %}",
        data: data,
        headers: { 'X-CSRFToken' : $.cookie('csrftoken')},
        success: function (_data) {
            if (_data.error != "ok") {
                alert(_data.error);
            } else {
                updateButtons(_data.layers.map(function (e) {return e.id}));
                if (onsuccess != undefined) onsuccess(_data);
            }
        },
        error: function (_data) {
            alert("Call failed");
            console.log(_data);
        }
    });
}


function layerDel(layerId, layerName, layerURL) {
    tooltipUpdateText = "1 layer deleted";
    _makeXHREditCall({ 'layerDel': layerId }, function () {
        show_alert("You have deleted <strong>1</strong> layer from <a href=\"{% url 'project' project.id%}\">{{project.name}}</a>: <a href=\""+layerURL+"\">" + layerName +"</a>");
    });
}

function show_alert(text, cls) {
    $("#zone1alerts").html("<div class=\"alert alert-info lead\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\">&times;</button>" + text + "</div>");
}

function show_dependencies_modal(layerId, layerName, layerURL, dependencies) {
    // update layer name
    $('.layer-name').text(layerName);
    var deplistHtml = "";
    for (var i = 0; i < dependencies.length; i++) {
        deplistHtml += "<li><label class=\"checkbox\"><input name=\"dependencies\" value=\""
        deplistHtml += dependencies[i].id;
        deplistHtml +="\" type=\"checkbox\" checked=\"checked\"/>";
        deplistHtml += dependencies[i].name;
        deplistHtml += "</label></li>";
    }
    $('#dependencies_list').html(deplistHtml);

    var selected = [layerId];
    var layer_link_list = "<a href='"+layerURL+"'>"+layerName+"</a>";

    $("#dependencies_modal_form").submit(function (e) {
        e.preventDefault();
        $("input[name='dependencies']:checked").map(function () { selected.push(parseInt($(this).val()))});
        if (selected.length > 1) {
            tooltipUpdateText = "" + selected.length + " layers added";
        } else {
            tooltipUpdateText = "1 layer added";
        }

        for (var i = 0; i < selected.length; i++) {
            for (var j = 0; j < dependencies.length; j++) {
                if (dependencies[j].id == selected[i]) {
                    layer_link_list+= ", <a href='"+dependencies[j].layerdetailurl+"'>"+dependencies[j].name+"</a>"
                    break;
                }
            }
        }

        $('#dependencies_modal').modal('hide');

    {% if project %}
        _makeXHREditCall({ 'layerAdd': selected.join(",") }, function () {
            show_alert("You have added <strong>"+selected.length+"</strong> layers to <a href=\"{% url 'project' project.id%}\">{{project.name}}</a>: " + layer_link_list);
        });
    {% endif %}

    });
    $('#dependencies_modal').modal('show');
}


function layerAdd(layerId, layerName, layerURL) {
    $.ajax({
        url: '{% url "xhr_datatypeahead" %}',
        data: {'type': 'layerdeps','value':layerId},
        success: function(_data) {
                if (_data.error != "ok") {
                    alert(_data.error);
                } else {
                    if (_data.list.length > 0) {
                        show_dependencies_modal(layerId, layerName, layerURL, _data.list);
                    }
                    else {
                        tooltipUpdateText = "1 layer added";
                        _makeXHREditCall({ 'layerAdd': layerId }, function () {
        show_alert("You have added <strong>1</strong> layer to <a href=\"{% url 'project' project.id%}\">{{project.name}}</a>: <a href=\""+layerURL+"\">" + layerName +"</a>");
                        });
                    }
                }
            }
    })
}

function button_set(id, state) {
    var tohide, toshow;
    if (state == "add")
    {
        tohide = "#layer-del-";
        toshow = "#layer-add-";
    }
    else if (state == "del")
    {
        tohide = "#layer-add-";
        toshow = "#layer-del-";
    }


    var previouslyvisible = $(tohide + id).is(":visible");
    if (previouslyvisible) {
        $(tohide + id).fadeOut( function() {
            $("#layer-tooltip-" + id).text(tooltipUpdateText);
            $("#layer-tooltip-" + id).fadeIn().delay(2000).fadeOut(function(){
                $(toshow + id).delay(300).fadeIn();
            });
        });
    } else {
        $(tohide + id).hide();
        $("#layer-tooltip-" + id).hide();
        $(toshow + id).show();
    }
};

function updateButtons(projectLayers) {
    var displayedLayers = [];
    $(".add-del-layers").map(function () { displayedLayers.push(parseInt($(this).attr('value')))});
    for (var i=0; i < displayedLayers.length; i++) {
        if (projectLayers.indexOf(displayedLayers[i]) > -1) {
            button_set(displayedLayers[i], "del");
        }
        else {
            button_set(displayedLayers[i], "add");
        }
    }
}

$(document).ready(function (){
    $('.layerbtn').tooltip({ trigger: 'manual' });
    updateButtons({{projectlayerset}});
});

</script>
{%endif%}

{% endblock %}