summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/toaster/toastergui/typeaheads.py145
-rw-r--r--bitbake/lib/toaster/toastergui/urls.py11
2 files changed, 156 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/toastergui/typeaheads.py b/bitbake/lib/toaster/toastergui/typeaheads.py
new file mode 100644
index 0000000000..d5bec58ea7
--- /dev/null
+++ b/bitbake/lib/toaster/toastergui/typeaheads.py
@@ -0,0 +1,145 @@
1#
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):
30 layers = prj.compatible_layerversions()
31 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"):
38 layers = layers.exclude(pk__in=prj.projectlayer_equivalent_set)
39
40 primary_results = layers.filter(layer__name__istartswith=search_term)
41 secondary_results = layers.filter(layer__name__icontains=search_term).exclude(pk__in=primary_results)
42
43 results = []
44
45 for layer_version in list(primary_results) + list(secondary_results):
46 vcs_reference = layer_version.get_vcs_reference()
47
48 detail = "[ %s | %s ]" % (layer_version.layer.vcs_url,
49 vcs_reference)
50 needed_fields = {
51 'id' : layer_version.pk,
52 'name' : layer_version.layer.name,
53 'layerdetailurl' : layer_version.get_detailspage_url(prj.pk),
54 'vcs_url' : layer_version.layer.vcs_url,
55 'vcs_reference' : vcs_reference,
56 'detail' : detail,
57 }
58
59 results.append(needed_fields)
60
61 return results
62
63class MachinesTypeAhead(ToasterTypeAhead):
64 """ Typeahead for all the machines available in the current project's
65 configuration """
66 def __init__(self):
67 super(MachinesTypeAhead, self).__init__()
68
69 def apply_search(self, search_term, prj, request):
70 machines = prj.get_available_machines()
71 machines = machines.order_by("name")
72
73 primary_results = machines.filter(name__istartswith=search_term)
74 secondary_results = machines.filter(name__icontains=search_term).exclude(pk__in=primary_results)
75 tertiary_results = machines.filter(layer_version__layer__name__icontains=search_term).exclude(pk__in=primary_results).exclude(pk__in=secondary_results)
76
77 results = []
78
79 for machine in list(primary_results) + list(secondary_results) + list(tertiary_results):
80
81 detail = "[ %s ]" % (machine.layer_version.layer.name)
82 needed_fields = {
83 'id' : machine.pk,
84 'name' : machine.name,
85 'detail' : detail,
86 }
87
88 results.append(needed_fields)
89
90 return results
91
92class RecipesTypeAhead(ToasterTypeAhead):
93 """ Typeahead for all the recipes available in the current project's
94 configuration """
95 def __init__(self):
96 super(RecipesTypeAhead, self).__init__()
97
98 def apply_search(self, search_term, prj, request):
99 recipes = prj.get_available_recipes()
100 recipes = recipes.order_by("name")
101
102
103 primary_results = recipes.filter(name__istartswith=search_term)
104 secondary_results = recipes.filter(name__icontains=search_term).exclude(pk__in=primary_results)
105 tertiary_results = recipes.filter(layer_version__layer__name__icontains=search_term).exclude(pk__in=primary_results).exclude(pk__in=secondary_results)
106
107 results = []
108
109 for recipe in list(primary_results) + list(secondary_results) + list(tertiary_results):
110
111 detail = "[ %s ]" % (recipe.layer_version.layer.name)
112 needed_fields = {
113 'id' : recipe.pk,
114 'name' : recipe.name,
115 'detail' : detail,
116 }
117
118 results.append(needed_fields)
119
120 return results
121
122class ProjectsTypeAhead(ToasterTypeAhead):
123 """ Typeahead for all the projects """
124 def __init__(self):
125 super(ProjectsTypeAhead, self).__init__()
126
127 def apply_search(self, search_term, prj, request):
128 projects = Project.objects.all().order_by("name")
129
130 primary_results = projects.filter(name__istartswith=search_term)
131 secondary_results = projects.filter(name__icontains=search_term).exclude(pk__in=primary_results)
132
133 results = []
134
135 for project in list(primary_results) + list(secondary_results):
136 needed_fields = {
137 'id' : project.pk,
138 'name' : project.name,
139 'detail' : "",
140 'projectPageUrl' : reverse('project', args=(project.pk,))
141 }
142
143 results.append(needed_fields)
144
145 return results
diff --git a/bitbake/lib/toaster/toastergui/urls.py b/bitbake/lib/toaster/toastergui/urls.py
index beb43038a1..b44c42f2e3 100644
--- a/bitbake/lib/toaster/toastergui/urls.py
+++ b/bitbake/lib/toaster/toastergui/urls.py
@@ -21,6 +21,7 @@ from django.views.generic import RedirectView, TemplateView
21 21
22from django.http import HttpResponseBadRequest 22from django.http import HttpResponseBadRequest
23from toastergui import tables 23from toastergui import tables
24from toastergui import typeaheads
24 25
25urlpatterns = patterns('toastergui.views', 26urlpatterns = patterns('toastergui.views',
26 # landing page 27 # landing page
@@ -127,6 +128,16 @@ urlpatterns = patterns('toastergui.views',
127 128
128 url(r'^xhr_datatypeahead/(?P<pid>\d+)$', 'xhr_datatypeahead', name='xhr_datatypeahead'), 129 url(r'^xhr_datatypeahead/(?P<pid>\d+)$', 'xhr_datatypeahead', name='xhr_datatypeahead'),
129 url(r'^xhr_configvaredit/(?P<pid>\d+)$', 'xhr_configvaredit', name='xhr_configvaredit'), 130 url(r'^xhr_configvaredit/(?P<pid>\d+)$', 'xhr_configvaredit', name='xhr_configvaredit'),
131 # typeahead api end points
132 url(r'^xhr_typeahead/(?P<pid>\d+)/layers$',
133 typeaheads.LayersTypeAhead.as_view(), name='xhr_layerstypeahead'),
134 url(r'^xhr_typeahead/(?P<pid>\d+)/machines$',
135 typeaheads.MachinesTypeAhead.as_view(), name='xhr_machinestypeahead'),
136 url(r'^xhr_typeahead/(?P<pid>\d+)/recipes$',
137 typeaheads.RecipesTypeAhead.as_view(), name='xhr_recipestypeahead'),
138 url(r'^xhr_typeahead/projects$',
139 typeaheads.ProjectsTypeAhead.as_view(), name='xhr_projectstypeahead'),
140
130 141
131 url(r'^xhr_importlayer/$', 'xhr_importlayer', name='xhr_importlayer'), 142 url(r'^xhr_importlayer/$', 'xhr_importlayer', name='xhr_importlayer'),
132 url(r'^xhr_updatelayer/$', 'xhr_updatelayer', name='xhr_updatelayer'), 143 url(r'^xhr_updatelayer/$', 'xhr_updatelayer', name='xhr_updatelayer'),