Skip to content
This repository was archived by the owner on May 24, 2018. It is now read-only.

Commit c992f4a

Browse files
author
Kamil Mowinski
committed
[CDSK-969] Add PoC of autocomplete in projects dropdown
1 parent 163ea86 commit c992f4a

File tree

7 files changed

+119
-53
lines changed

7 files changed

+119
-53
lines changed

master/buildbot/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1525251296
1+
1526455518

master/buildbot/status/web/status_json.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import time
2323

2424
import jsonschema
25+
from operator import attrgetter
2526
from twisted.python import log
2627
from twisted.internet import defer
2728
from twisted.web import html, resource, server
@@ -950,10 +951,27 @@ class ProjectsJsonResource(JsonResource):
950951

951952
def __init__(self, status):
952953
JsonResource.__init__(self, status)
954+
self.putChild('list', ProjectsListJsonResource(status))
953955
for project_name, project_status in status.getProjects().iteritems():
954956
self.putChild(project_name, SingleProjectJsonResource(status, project_status))
955957

956958

959+
class ProjectsListJsonResource(JsonResource):
960+
help = """List the registered projects with sorting by priority and name"""
961+
pageTitle = 'Projects'
962+
963+
def __init__(self, status):
964+
JsonResource.__init__(self, status)
965+
self.status = status
966+
967+
def asDict(self, request):
968+
projects = sorted(
969+
self.status.getProjects().values(),
970+
key=attrgetter('priority', 'name'),
971+
)
972+
return map(lambda project: project.asDict(), projects)
973+
974+
957975
class LatestRevisionResource(JsonResource):
958976

959977
def __init__(self, status, project_status):

www/prod/script/main.js

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/prod/script/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/script/project/ui/dropdown.js

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/*global define, jQuery*/
2-
define(['jquery', 'screensize'], function ($, screenSize) {
3-
2+
define(function (require) {
43
"use strict";
4+
var $ = require('jquery'),
5+
screenSize = require('screensize'),
6+
hb = require('project/handlebars-extend');
57

68
// Extend our jquery object with dropdown widget
79
(function ($) {
@@ -159,12 +161,14 @@ define(['jquery', 'screensize'], function ($, screenSize) {
159161

160162
return {
161163
init: function () {
162-
163-
var mobileHTML,
164-
desktopHTML;
164+
var projects;
165+
var page = 0;
166+
var maxPage = 0;
167+
var maxShowedItems = 10;
165168

166169
$("#projectDropdown").dropdown({
167-
url: "/projects",
170+
url: "/json/projects/list",
171+
title: "<h3>Project list</h3>",
168172
beforeCreate: function ($elem) {
169173
$("#preloader").preloader("showPreloader");
170174
},
@@ -175,45 +179,58 @@ define(['jquery', 'screensize'], function ($, screenSize) {
175179
});
176180
},
177181
onResponse: function ($elem, $dropdown, response) {
178-
if (desktopHTML === undefined || mobileHTML === undefined) {
179-
//Cache desktop HTML
180-
desktopHTML = $(response).find('.tablesorter-js');
181-
182-
183-
var fw = $(response).find('.scLink');
184-
mobileHTML = $('<ul/>').addClass('submenu list-unstyled');
185-
$(fw).each(function () {
186-
var scLink = $(this).attr('data-sc');
187-
$(this).attr('href', scLink);
188-
var $li = $('<li/>').append($(this));
189-
mobileHTML.append($li);
190-
});
191-
192-
$(desktopHTML, mobileHTML).find("a").each(function () {
193-
var scLink = $(this).attr('data-sc');
194-
$(this).attr('href', scLink);
195-
});
196-
}
197-
182+
var self = this;
183+
projects = response.map(function(item) {
184+
return item.name;
185+
});
186+
maxPage = projects.length / maxShowedItems;
187+
var html = hb.projectListDropdown();
188+
var projectList = hb.projectList({projects: projects});
189+
$dropdown.append(html);
190+
$dropdown.append(projectList);
191+
$('body').on('keyup', '#project-list', function() {
192+
self.updateProject($(this).val());
193+
});
194+
$('body').on('click', '#prev-projects', function() {
195+
console.log('prev'); // @TODO
196+
});
197+
$('body').on('click', '#next-projects', function() {
198+
console.log('next'); // @TODO
199+
});
198200
return true;
199201
},
200-
beforeShow: function ($elem, $dropdown) {
201-
if (screenSize.isMediumScreen()) {
202-
$dropdown.append(desktopHTML);
203-
} else {
204-
$elem.append(mobileHTML);
205-
}
206-
},
207202
onShow: function ($elem, $dropdown) {
208203
if (!screenSize.isMediumScreen()) {
209204
$dropdown.hide();
210205
}
206+
if (page === 0) {
207+
$('#prev-projects').hide();
208+
}
209+
if (page === maxPage) {
210+
$('#next-projects').show();
211+
}
211212
},
212-
onHide: function ($elem, $dropdown) {
213-
$elem.find("ul").remove();
213+
onHide: function($elem, $dropdown) {
214+
$('#project-list').val('');
215+
},
216+
beforeShow: function() {
217+
this.updateProject("");
214218
},
215219
animate: function () {
216220
return screenSize.isMediumScreen();
221+
},
222+
updateProject: function(text) {
223+
var showedItems = 0;
224+
text = text.toLowerCase();
225+
$('#dropdown-project-list .item').each(function() {
226+
var name = $(this).data('name').toLowerCase();
227+
if(name.includes(text) && showedItems < maxShowedItems) {
228+
$(this).show();
229+
showedItems++;
230+
} else {
231+
$(this).hide();
232+
}
233+
});
217234
}
218235
});
219236

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div class="dataTables_filter" style="width: 100%; margin-bottom: 30px;">
2+
<label for="project-list" style="width: 100%">
3+
<input type="text" id="project-list" name="project-list" placeholder="Filter projects"/>
4+
</label>
5+
</div>

www/script/templates/project-list.hbs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<div>
2+
<table class="table table-katana table-stripes no-bg dataTable shortcut-js tools-js no-footer" id="dropdown-project-list" role="grid">
3+
<thead>
4+
<tr role="row">
5+
<th class="sorting" tabindex="0" rowspan="1" colspan="1">Name</th>
6+
</tr>
7+
</thead>
8+
<tbody>
9+
{{#each projects}}
10+
<tr role="row" class="odd item" data-name="{{this}}">
11+
<td>
12+
<a class="scLink" href="/projects/{{this}}" data-sc="/projects/{{this}}/builders?fmod_branch=master">
13+
{{this}}
14+
</a>
15+
</td>
16+
</tr>
17+
{{/each}}
18+
</tbody>
19+
</table>
20+
21+
<div class="dataTables_paginate" style="width: 100%; text-align: center;">
22+
<a id="prev-projects" class="paginate_button previous" href="#">Prev</a>
23+
<a href="/projects" class="paginiate_button">All projects</a>
24+
<a id="next-projects" class="paginate_button next" href="#">Next</a>
25+
</div>
26+
</div>

0 commit comments

Comments
 (0)