blob: dd4b7f5057167a74e23de038f0d0646208196f9a [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
2# BitBake Toaster Implementation
3#
4# Copyright (C) 2015 Intel Corporation
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License version 2 as
8# published by the Free Software Foundation.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19from toastergui.widgets import ToasterTypeAhead
20from orm.models import Project
21from django.core.urlresolvers import reverse
22
23class LayersTypeAhead(ToasterTypeAhead):
24 """ Typeahead for layers available and not added in the current project's
25 configuration """
26 def __init__(self):
27 super(LayersTypeAhead, self).__init__()
28
29 def apply_search(self, search_term, prj, request):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050030 layers = prj.get_all_compatible_layer_versions()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 layers = layers.order_by('layer__name')
32
33 # Unlike the other typeaheads we also don't want to show suggestions
34 # for layers already in the project unless required such as when adding
35 # layerdeps to a new layer.
36 if ("include_added" in request.GET and
37 request.GET['include_added'] != "true"):
Patrick Williamsf1e5d692016-03-30 15:21:19 -050038 layers = layers.exclude(
39 pk__in=prj.get_project_layer_versions(pk=True))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040
41 primary_results = layers.filter(layer__name__istartswith=search_term)
42 secondary_results = layers.filter(layer__name__icontains=search_term).exclude(pk__in=primary_results)
43
44 results = []
45
46 for layer_version in list(primary_results) + list(secondary_results):
47 vcs_reference = layer_version.get_vcs_reference()
48
49 detail = "[ %s | %s ]" % (layer_version.layer.vcs_url,
50 vcs_reference)
51 needed_fields = {
52 'id' : layer_version.pk,
53 'name' : layer_version.layer.name,
54 'layerdetailurl' : layer_version.get_detailspage_url(prj.pk),
55 'vcs_url' : layer_version.layer.vcs_url,
56 'vcs_reference' : vcs_reference,
57 'detail' : detail,
58 }
59
60 results.append(needed_fields)
61
62 return results
63
64class MachinesTypeAhead(ToasterTypeAhead):
65 """ Typeahead for all the machines available in the current project's
66 configuration """
67 def __init__(self):
68 super(MachinesTypeAhead, self).__init__()
69
70 def apply_search(self, search_term, prj, request):
71 machines = prj.get_available_machines()
72 machines = machines.order_by("name")
73
74 primary_results = machines.filter(name__istartswith=search_term)
75 secondary_results = machines.filter(name__icontains=search_term).exclude(pk__in=primary_results)
76 tertiary_results = machines.filter(layer_version__layer__name__icontains=search_term).exclude(pk__in=primary_results).exclude(pk__in=secondary_results)
77
78 results = []
79
80 for machine in list(primary_results) + list(secondary_results) + list(tertiary_results):
81
82 detail = "[ %s ]" % (machine.layer_version.layer.name)
83 needed_fields = {
84 'id' : machine.pk,
85 'name' : machine.name,
86 'detail' : detail,
87 }
88
89 results.append(needed_fields)
90
91 return results
92
93class RecipesTypeAhead(ToasterTypeAhead):
94 """ Typeahead for all the recipes available in the current project's
95 configuration """
96 def __init__(self):
97 super(RecipesTypeAhead, self).__init__()
98
99 def apply_search(self, search_term, prj, request):
100 recipes = prj.get_available_recipes()
101 recipes = recipes.order_by("name")
102
103
104 primary_results = recipes.filter(name__istartswith=search_term)
105 secondary_results = recipes.filter(name__icontains=search_term).exclude(pk__in=primary_results)
106 tertiary_results = recipes.filter(layer_version__layer__name__icontains=search_term).exclude(pk__in=primary_results).exclude(pk__in=secondary_results)
107
108 results = []
109
110 for recipe in list(primary_results) + list(secondary_results) + list(tertiary_results):
111
112 detail = "[ %s ]" % (recipe.layer_version.layer.name)
113 needed_fields = {
114 'id' : recipe.pk,
115 'name' : recipe.name,
116 'detail' : detail,
117 }
118
119 results.append(needed_fields)
120
121 return results
122
123class ProjectsTypeAhead(ToasterTypeAhead):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500124 """ Typeahead for all the projects, except for command line builds """
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125 def __init__(self):
126 super(ProjectsTypeAhead, self).__init__()
127
128 def apply_search(self, search_term, prj, request):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500129 projects = Project.objects.exclude(is_default=True).order_by("name")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130
131 primary_results = projects.filter(name__istartswith=search_term)
132 secondary_results = projects.filter(name__icontains=search_term).exclude(pk__in=primary_results)
133
134 results = []
135
136 for project in list(primary_results) + list(secondary_results):
137 needed_fields = {
138 'id' : project.pk,
139 'name' : project.name,
140 'detail' : "",
141 'projectPageUrl' : reverse('project', args=(project.pk,))
142 }
143
144 results.append(needed_fields)
145
146 return results