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

Commit e2609d7

Browse files
author
Kamil Mowinski
committed
[CDSK-969] Add prev and next button
1 parent c992f4a commit e2609d7

File tree

5 files changed

+56
-25
lines changed

5 files changed

+56
-25
lines changed

master/buildbot/VERSION

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

www/prod/script/main.js

Lines changed: 4 additions & 4 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: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ define(function (require) {
161161

162162
return {
163163
init: function () {
164-
var projects;
164+
var allProjects;
165+
var visibleProjects;
165166
var page = 0;
166167
var maxPage = 0;
167168
var maxShowedItems = 10;
@@ -180,53 +181,83 @@ define(function (require) {
180181
},
181182
onResponse: function ($elem, $dropdown, response) {
182183
var self = this;
183-
projects = response.map(function(item) {
184+
allProjects = response.map(function(item) {
184185
return item.name;
185186
});
186-
maxPage = projects.length / maxShowedItems;
187+
maxPage = allProjects.length / maxShowedItems;
187188
var html = hb.projectListDropdown();
188-
var projectList = hb.projectList({projects: projects});
189+
var projectList = hb.projectList({projects: allProjects});
189190
$dropdown.append(html);
190191
$dropdown.append(projectList);
191-
$('body').on('keyup', '#project-list', function() {
192+
193+
var $body = $('body');
194+
$body.on('keyup', '#project-list', function() {
195+
page = 0;
192196
self.updateProject($(this).val());
193197
});
194-
$('body').on('click', '#prev-projects', function() {
195-
console.log('prev'); // @TODO
198+
$body.on('click', '#prev-projects', function(e) {
199+
e.preventDefault();
200+
page--;
201+
self.updateProject($('#project-list').val());
196202
});
197-
$('body').on('click', '#next-projects', function() {
198-
console.log('next'); // @TODO
203+
$body.on('click', '#next-projects', function(e) {
204+
e.preventDefault();
205+
page++;
206+
self.updateProject($('#project-list').val());
199207
});
200208
return true;
201209
},
202210
onShow: function ($elem, $dropdown) {
203211
if (!screenSize.isMediumScreen()) {
204212
$dropdown.hide();
205213
}
206-
if (page === 0) {
207-
$('#prev-projects').hide();
208-
}
209-
if (page === maxPage) {
210-
$('#next-projects').show();
211-
}
214+
this.updatePagination();
212215
},
213216
onHide: function($elem, $dropdown) {
214217
$('#project-list').val('');
218+
page = 0;
219+
visibleProjects = allProjects;
215220
},
216221
beforeShow: function() {
217222
this.updateProject("");
218223
},
219224
animate: function () {
220225
return screenSize.isMediumScreen();
221226
},
227+
updatePagination: function() {
228+
if (page === 0) {
229+
$('#prev-projects').hide();
230+
} else {
231+
$('#prev-projects').show();
232+
}
233+
if (visibleProjects.length < maxShowedItems) {
234+
$('#next-projects').hide();
235+
} else {
236+
$('#next-projects').show();
237+
}
238+
},
222239
updateProject: function(text) {
223-
var showedItems = 0;
224240
text = text.toLowerCase();
241+
visibleProjects = allProjects
242+
.map(function(project) {return project.toLowerCase();} )
243+
.filter(function(project) { return project.includes(text);} );
244+
245+
if (visibleProjects.length > maxShowedItems) {
246+
visibleProjects = visibleProjects.slice(
247+
page * maxShowedItems, (page + 1) * maxShowedItems
248+
)
249+
250+
} else {
251+
// there is only one page, no needed pagination
252+
$('#prev-projects').hide();
253+
$('#next-projects').hide();
254+
}
255+
this.updatePagination();
256+
225257
$('#dropdown-project-list .item').each(function() {
226258
var name = $(this).data('name').toLowerCase();
227-
if(name.includes(text) && showedItems < maxShowedItems) {
259+
if(visibleProjects.includes(name)) {
228260
$(this).show();
229-
showedItems++;
230261
} else {
231262
$(this).hide();
232263
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="dataTables_filter" style="width: 100%; margin-bottom: 30px;">
22
<label for="project-list" style="width: 100%">
3-
<input type="text" id="project-list" name="project-list" placeholder="Filter projects"/>
3+
<input type="text" id="project-list" name="project-list" placeholder="Filter results" />
44
</label>
55
</div>

0 commit comments

Comments
 (0)