-
-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A gift to javascript naysayers #897
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #897 +/- ##
=======================================
Coverage ? 72.31%
=======================================
Files ? 56
Lines ? 3887
Branches ? 2185
=======================================
Hits ? 2811
Misses ? 1074
Partials ? 2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
a462906
to
0838067
Compare
@kelson42 I haven't written tests yet (still reading through how to write them, should be done soon along with some code polishing) but you can test the main functionality. Testing endpoint is Notes: |
@juuz0 Thank you very much for your PR. I have put @rgaudin as functional reviewer because he has requested the feature and has probably stronger opninion abuot how this shoudl be fixed. I have as well put @veloman-yunkan for the technical review (and functional as well :) |
e9687d6
to
9f6b559
Compare
OK, I've tested it and it works fine ; congrats. Couple of comments though:
@kelson42 what's the merge strategy for this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I skimmed through the changes very quickly and I think that it is yet premature commenting on the code. At this point I will provide high level input:
- Shouldn't the output be paginated?
- What about translation? Once Internationalization of kiwix-serve's frontend #846 is merged you can reuse the same strings for translating in the backend.
|
src/server/internalServer.cpp
Outdated
auto filter = get_search_filter(request); | ||
try { | ||
if (request.get_argument("category") == "") { | ||
filter.clearCategory(); | ||
} | ||
if (request.get_argument("lang") == "") { | ||
filter.clearLang(); | ||
} | ||
} catch (...) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised about that. In which context get_search_filter
will set a filter on the category and we need to clear it ?
Shouldn't be better to fix get_search_filter
if it is buggy ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reasoning for not touching get_search_filter
was if the behaviour was intentional to display no books when lang/category == "" and if I change that logic, I would break some other functionality.
In kiwix-serve welcome page filters, "" means all categories while get_search_filter
seems to consider "" as a valid category and rightly shows no book associated.
Would appreciate your input on how it should be done here? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say that get_search_filter
behavior is correct. We should not pass a filter argument if we don't want to filter on this argument.
More over, we don't use kiwix-serve welcome page here as we are nojs here. When do we have a category==""
filter ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had assumed category==""
was for all categories filter
Is there a specific category for "all categories" then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about what we are speaking about.
But if we are speaking about the request send to the http api, if we don't want to filter on the category, we must not pass a category==""
query string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There needs to be a way for the server to know that the user requests "ALL CATEGORIES", I dont think a query param can be cleared without javascript on the client side hence I consider category=""
as ALL categories & clear that on the server side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There needs to be a way for the server to know that the user requests "ALL CATEGORIES"
The absence of filter on category seems to me a good way to specify all categories.
I dont think a query param can be cleared without javascript on the client side hence I consider category="" as ALL categories & clear that on the server side.
Why we need to clear it ?
The html code is generated server side, so we can generate the request we want, without a category
parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think a query param can be cleared without javascript on the client side hence I consider category="" as ALL categories & clear that on the server side.
Why we need to clear it ? The html code is generated server side, so we can generate the request we want, without a
category
parameter.
On the server side we generate the HTML for the search form. The form is filled and submitted from the client side. Values are sent for all inputs of the form (unless it is a request generated via JS).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha yes, I've forget about the search form.
I would say that get_search_filter
should be the only (and correct) way to create a filter from query string.
If we add a modification on the filter in specific api, it will introduce inconsistency in the API and we can be sure that we will mix things later.
while get_search_filter seems to consider "" as a valid category and rightly shows no book associated.
I finally think it is wrong. The only valid use case of searching for no category is to search for book which have no category associated. So it is more something about undefined
category than category.
Maybe we could extend a bit the api to accept to specific values [all]
and [empty]
(or [none]
) for no filtering (all) and filtering for book without category (empty/none).
The []
would prevent a potential conflict with a real category all
or none
.
What do you think about that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extending the API would make life easier definitely & bring more consistency.
Would've been nice if all
/none
be reserved words for filters but I don't really mind the [all]
or [empty/none]
(none
is better word imo).
Only consideration would be if this looks pleasant on the eye in URL: TLD/?lang=[all]&category=[none]
Hiding nav, body, footer when javascript is not enabled & displaying a text "This page can only be accessed with Javascript enabled, please head over to
It is clickable though? I had to reduce clickable area (currently it's only the description part) because HTML spec doesn't allow
Will go by mgautierfr's suggestion, thanks!
normal welcome page (JS one) isn't paginated so why this? Performance reasons?
Noted, should be done soon - once I understand how to write tests which is taking some effort :) |
Fine by me. What do others think about?
No it's not clickable. That's the point, it makes user think it is because it grows
Way to go. This endpoint also handles the mainPath so that should be easy… although this URL should normally be retrieved from OPDS I suppose…
It is. Just look at https://library.kiwix.org/ there's an automatic loading of new cards on scroll. I'm not in favor or paginating for a first version. It's unlikely this will be really useful in practice and adds some complexity. Let's wait for user requests for this. |
Done as discussed.
Removed hover effect
Done.
Still pending, I'm so scared to rebase this PR on top of main currently. Should be done soon. Added two tests |
dunno why CI is failing :( |
Done :) |
@rgaudin ping because there's no button to re request a review! >:) |
For translations, use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested 8c10936
- Home points to
/nojs
as expected 👍 - Links points to
/content
👍 - i18n translation works fine 👍
- I still get the hover effect on the Tag: text is larger, bold and the pointer changes as well. ❌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope that this was the last complete review of this PR. Please address the comments using fixup commits.
@@ -51,7 +51,7 @@ | |||
<div class="book__list"> | |||
{{#books}} | |||
<div class="book__wrapper"> | |||
<a class="book__link" href="#" data-hover="Preview"> | |||
<a class="book__link" href="{{root}}/content/{{id}}" data-hover="Preview"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that the data-hover
attribute was copied from static/skin/index.js
where it is supposedly used by isotope.js
(however it doesn't seem to show up in the UI in any way). In plain HTML a different attribute must be used (of course, if we want such a hint/tooltip, whereupon I also have the following remarks:
- Is "Preview" a good hint text?
- It seems that it remained untranslated (this applies to the JS-ful version too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced this with title & aria-label.
Is "Preview" a good hint text?
Good enough to me to be honest. Preview book
or Open book
may also fit.
For the full JS version, I think its better to do in a new ticket? Or should I do that here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the full JS version, I think its better to do in a new ticket?
Yes, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are almost done. Please fix the last issue (discovered during final testing) in a rebased-and-fixed-up clean version of this PR ready to merge.
Please, also update |
This change creates a new common class for dumping the library into various formats: LibraryDumper
HTMLDumper class will be used to dump library in HTML format. It inherits from LibraryDumper
Adds /nojs endpoint for fallback. Currently, it serves an HTML with book names in library
Tries to copy the same design of tiles as main page with javascript enabled
Adds span elements for tags
If the tiles are now clicked, they redirect to main page of book.
ce93755
to
3d3d695
Compare
Done. I also lost a commit while rebasing earlier, that change is re added in 3d3d695 (my question is: do we translate this text? what should be the preferred strategy because JS is disabled) |
The download-link links to /nojs/download/<bookname> for all 4 types of downloads.
Adds an html form to search books by the q= parameter
Shows "x results" label where x = number of books based on filters
Adds language and category filter in /nojs. Unlike the main page, the filtering is only done after user submits the form.
Uses the string from #846 for translations. A couple new translations are also added for <title> tag.
Shows a link to reset filter if there are no books.
Added 4 tests for /nojs endpoint Test 1: no_js_default - Without any filters Test 2: no_js_eng_lang - With lang=eng as filter Test 3: no_js_no_books - For 0 results case Test 4: no_js_download - To test download page
Added a <noscript> elements which hides everything on the welcome page if javascript is not enabled. It displays a text to tell the user to navigate to /nojs endpoint
Fixes #615