diff --git a/bitbake/lib/toaster/toastergui/static/js/machines.js b/bitbake/lib/toaster/toastergui/static/js/machines.js new file mode 100644 index 0000000000..a3ea43baed --- /dev/null +++ b/bitbake/lib/toaster/toastergui/static/js/machines.js @@ -0,0 +1,89 @@ +"use strict" + +function machinesPageInit (ctx) { + + + function setLayerInCurrentPrj(addLayerBtn, depsList){ + var alertMsg = $("#alert-msg"); + + $(".select-or-add").each(function(){ + /* If we have added a layer it may also enable other machines so search + * for other machines that have that layer and enable them */ + var selectMachineBtn = $(this).children(".select-machine-btn"); + var otherAddLayerBtns = $(this).children(".add-layer"); + + if (addLayerBtn.data('layer-version-id') == selectMachineBtn.data('layer-version-id')) { + otherAddLayerBtns.fadeOut(function(){ + selectMachineBtn.fadeIn(); + }); + } + }); + + /* Reset alert message */ + alertMsg.text(""); + + /* If we have added layer dependencies */ + if (depsList) { + alertMsg.append("You have added "+(depsList.length+1)+" layers: and its dependencies "); + + /* Build the layer deps list */ + depsList.map(function(layer, i){ + var link = $(""); + + link.attr("href", layer.layerdetailurl); + link.text(layer.name); + link.tooltip({title: layer.tooltip}); + + if (i != 0) + alertMsg.append(", "); + + alertMsg.append(link); + }); + } else { + alertMsg.append("You have added 1 layer: "); + } + + var layerName = addLayerBtn.data('layer-name'); + alertMsg.children("#layer-affected-name").text(layerName); + $("#alert-area").show(); + } + + /* Add or remove this layer from the project */ + $(".add-layer").click(function() { + var btn = $(this); + /* If adding get the deps for this layer */ + var layer = { + id : $(this).data('layer-version-id'), + name : $(this).data('layer-name'), + }; + + libtoaster.getLayerDepsForProject(ctx.xhrDataTypeaheadUrl, ctx.projectId, layer.id, function (data) { + /* got result for dependencies */ + if (data.list.length == 0){ + var editData = { layerAdd : layer.id }; + libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, editData, + function() { + setLayerInCurrentPrj(btn); + }); + return; + } else { + /* The add deps will include this layer so no need to add it + * separately. + */ + show_layer_deps_modal(ctx.projectId, layer, data.list, null, null, true, function () { + /* Success add deps and layer */ + setLayerInCurrentPrj(btn, data.list); + console.log ("TODO SUCCESS"); + }); + } + }, null); + }); + + $(".select-machine-btn").click(function(){ + var data = { machineName : $(this).data('machine-name') }; + libtoaster.editProject(ctx.xhrEditProjectUrl, ctx.projectId, data, + function (){ + window.location.replace(ctx.projectPageUrl); + }, null); + }); +} diff --git a/bitbake/lib/toaster/toastergui/templates/machines.html b/bitbake/lib/toaster/toastergui/templates/machines.html index e0bda51cf5..c0d4c6cc33 100644 --- a/bitbake/lib/toaster/toastergui/templates/machines.html +++ b/bitbake/lib/toaster/toastergui/templates/machines.html @@ -1,62 +1,65 @@ {% extends "baseprojectpage.html" %} {% load projecttags %} {% load humanize %} - +{% load static %} {% block localbreadcrumb %}
  • All compatible machines
  • {% endblock %} {% block projectinfomain %} - - - - + + +{% include "layers_dep_modal.html" %} + + + {% include "basetable_top.html" %} - {% for o in objects %} - - - {{o.name}} - - - {{o.description}} - - {{o.file_path}} - - - {{o.layer_version.layer.name}} - {{o.layer_source.name}} - {{o.layer_version.commit}} - - - - - Add layer - - - - - {% endfor %} +{% for o in objects %} + + {{o.name}} + {{o.description}} + {{o.layer_version.layer.name}} + {{o.layer_source.name}} + {{o.layer_version.commit}} + + Select machine + + + Add layer + + + + +{% endfor %} {% include "basetable_bottom.html" %} diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 73a5c7e99f..641170e639 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -2770,6 +2770,9 @@ if toastermain.settings.MANAGED: return response def machines(request): + if not 'project_id' in request.session: + raise Exception("invalid page: cannot show page without a project") + template = "machines.html" # define here what parameters the view needs in the GET portion in order to # be able to display something. 'count' and 'page' are mandatory for all views @@ -2785,18 +2788,19 @@ if toastermain.settings.MANAGED: (filter_string, search_term, ordering_string) = _search_tuple(request, Machine) queryset_all = Machine.objects.all() -# if 'project_id' in request.session: -# queryset_all = queryset_all.filter(Q(layer_version__up_branch__name = Project.objects.get(request.session['project_id']).release.branch_name) | Q(layer_version__build__in = Project.objects.get(request.session['project_id']).build_set.all())) queryset_with_search = _get_queryset(Machine, queryset_all, None, search_term, ordering_string, '-name') queryset = _get_queryset(Machine, queryset_all, filter_string, search_term, ordering_string, '-name') + project_layers = ProjectLayer.objects.filter(project_id=request.session['project_id']).values_list('layercommit',flat=True) + # retrieve the objects that will be displayed in the table; machines a paginator and gets a page range to display machine_info = _build_page_range(Paginator(queryset, request.GET.get('count', 10)),request.GET.get('page', 1)) context = { 'objects' : machine_info, + 'project_layers' : project_layers, 'objectname' : "machines", 'default_orderby' : 'name:+', 'total_count': queryset_with_search.count(), @@ -2810,10 +2814,6 @@ if toastermain.settings.MANAGED: 'dclass': 'span5', 'clclass': 'description', }, - { 'name': 'Machine file', - 'clclass': 'machine-file', - 'hidden': 1, - }, { 'name': 'Layer', 'clclass': 'layer', },