summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/adapter/search.py5
-rw-r--r--service/pixelated/controllers/mails_controller.py4
-rw-r--r--web-ui/app/js/services/mail_service.js29
-rw-r--r--web-ui/test/spec/services/mail_service.spec.js4
4 files changed, 23 insertions, 19 deletions
diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py
index a5b31c67..ad5c3bbb 100644
--- a/service/pixelated/adapter/search.py
+++ b/service/pixelated/adapter/search.py
@@ -134,8 +134,9 @@ class SearchEngine(object):
window = int(window)
with self._index.searcher() as searcher:
- results = searcher.search_page(query, page, pagelen=window)
- return [mail['ident'] for mail in results]
+ tags_facet = sorting.FieldFacet('tag', allow_overlap=True, maptype=sorting.Count)
+ results = searcher.search_page(query, page, pagelen=window, groupedby=tags_facet)
+ return [mail['ident'] for mail in results], sum(results.results.groups().values())
def prepare_query(self, query):
query = (
diff --git a/service/pixelated/controllers/mails_controller.py b/service/pixelated/controllers/mails_controller.py
index f6414f27..d1de4973 100644
--- a/service/pixelated/controllers/mails_controller.py
+++ b/service/pixelated/controllers/mails_controller.py
@@ -29,13 +29,13 @@ class MailsController:
self._search_engine = search_engine
def mails(self, _request=request):
- mail_ids = self._search_engine.search(_request.args.get('q'), _request.args.get('w'), _request.args.get('p'))
+ mail_ids, total = self._search_engine.search(_request.args.get('q'), _request.args.get('w'), _request.args.get('p'))
mails = self._mail_service.mails(mail_ids)
mails = sorted(mails, key=lambda mail: dateparser.parse(mail.date), reverse=True)
response = {
"stats": {
- "total": len(mails),
+ "total": total,
"read": 0,
"starred": 0,
"replied": 0
diff --git a/web-ui/app/js/services/mail_service.js b/web-ui/app/js/services/mail_service.js
index af957a7b..4337da0e 100644
--- a/web-ui/app/js/services/mail_service.js
+++ b/web-ui/app/js/services/mail_service.js
@@ -230,7 +230,7 @@ define(
};
this.nextPage = function () {
- if (this.attr.currentPage < (this.attr.numPages - 1)) {
+ if (this.attr.currentPage < (this.attr.numPages)) {
this.updateCurrentPageNumber(this.attr.currentPage + 1);
this.refreshResults();
}
@@ -263,18 +263,21 @@ define(
this.after('initialize', function () {
that = this;
- this.on(events.mail.tags.update, this.updateTags);
- this.on(events.mail.draftReply.want, this.wantDraftReplyForMail);
- this.on(events.mail.want, this.fetchSingle);
- this.on(events.mail.read, this.readMail);
- this.on(events.mail.unread, this.unreadMail);
- this.on(events.mail.delete, this.deleteMail);
- this.on(events.mail.deleteMany, this.deleteManyMails);
- this.on(events.search.perform, this.newSearch);
- this.on(events.ui.mails.fetchByTag, this.fetchByTag);
- this.on(events.ui.mails.refresh, this.refreshResults);
- this.on(events.ui.page.previous, this.previousPage);
- this.on(events.ui.page.next, this.nextPage);
+ if (features.isEnabled('tags')) {
+ this.on(events.mail.tags.update, this.updateTags);
+ }
+
+ this.on(document, events.mail.draftReply.want, this.wantDraftReplyForMail);
+ this.on(document, events.mail.want, this.fetchSingle);
+ this.on(document, events.mail.read, this.readMail);
+ this.on(document, events.mail.unread, this.unreadMail);
+ this.on(document, events.mail.delete, this.deleteMail);
+ this.on(document, events.mail.deleteMany, this.deleteManyMails);
+ this.on(document, events.search.perform, this.newSearch);
+ this.on(document, events.ui.mails.fetchByTag, this.fetchByTag);
+ this.on(document, events.ui.mails.refresh, this.refreshResults);
+ this.on(document, events.ui.page.previous, this.previousPage);
+ this.on(document, events.ui.page.next, this.nextPage);
});
}
}
diff --git a/web-ui/test/spec/services/mail_service.spec.js b/web-ui/test/spec/services/mail_service.spec.js
index 3ce223cc..897d3d5f 100644
--- a/web-ui/test/spec/services/mail_service.spec.js
+++ b/web-ui/test/spec/services/mail_service.spec.js
@@ -238,8 +238,8 @@ describeComponent('services/mail_service', function () {
expect(this.component.attr.currentPage).toEqual(2);
});
- it('won\'t change the page if it was already at the first page and trying to go to previous', function() {
- this.component.attr.numPages = 10;
+ it('won\'t change the page if it is at the last mail when ui:page:next is fired', function() {
+ this.component.attr.numPages = 9;
this.component.attr.currentPage = 9;
this.component.trigger(Pixelated.events.ui.page.next);