Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/templates
akuma06 c6168be8b1 Tag Search + Tests + Search slight refactor [DONE] (#1342)
* Tag Search + Tests + Search slight refactor

First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far.

Added new behaviour as discussed in #1334

* fix fallback to ES

* Added some comments to explain PG fallback + log err moved

* Refactored search

Nearly fully covered
WhereParams struct has disappeared for Query struct instead
In DB model, we use an interface implementing Query struct methods

* 1rst Refactor of Tags (WTF already?!)

Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags.
Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values.

Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas.
In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags.

This behaviour depends on the callbackOnType function in tag/helpers.go

* fix for modtools :')

* Added anidb, vndb, dlsite & vmdb id fields in torrent model.
Tags don't have an accepted field anymore.
Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags.

New Helper + New Changelog for translation string.

* New upload/edit form for torrent tags.
Now the inputs are dynamically generated by the helper tag_form.
No more modal window in those form, only inputs.
Support of tags in API
New translation string for the  link to the modal on torrent view.
More comments in the functions for tags

* Improving how config for tags work. Adding a test on them with understandable messages.
Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model.
Fixing some errors

* Fix compile error + Tests Errors

* Improve performance by caching the list of tags with an index
Adding/removing tags works/tested
New translation strings

TODO: test/fix adding tag on upload/edit

* Mini fix to display video quality
+ tags works/tested on modo edit

* Fix editing tags on modpanel

* Edit tags works

* Add translation string

* Add search backend for tags.
?tags=xxx,eee,ddd
?anidb=21
?vndb=23
?vgmdb=24
?vq=full_hd

* Fix Ajax tag Removal&Add

* Added form for descriptive tags

* Forgot to add the link between database and form for descriptive tags.

* Adding the increase/decrease pantsu for descriptive tags

* Fix #1370

* When you actually forgot to commit files after having forgotten commits
2017-08-22 11:48:10 +10:00
..
admin Tag Search + Tests + Search slight refactor [DONE] (#1342) 2017-08-22 11:48:10 +10:00
errors Fix more style issues 2017-07-24 15:03:43 +10:00
layouts Tag Search + Tests + Search slight refactor [DONE] (#1342) 2017-08-22 11:48:10 +10:00
site Tag Search + Tests + Search slight refactor [DONE] (#1342) 2017-08-22 11:48:10 +10:00
helpers.go Tag Search + Tests + Search slight refactor [DONE] (#1342) 2017-08-22 11:48:10 +10:00
README.md Information on how to use nyaa template system (#1384) 2017-08-21 10:30:47 +10:00
template.go Tag Search + Tests + Search slight refactor [DONE] (#1342) 2017-08-22 11:48:10 +10:00
template_functions.go Fixing FileList IdentifierChain not available error 2017-07-19 22:12:03 +02:00
template_functions_test.go fix travis error 2017-08-02 18:04:44 +02:00
template_test.go Tag Search + Tests + Search slight refactor [DONE] (#1342) 2017-08-22 11:48:10 +10:00

How-To Template

Templating system is based on CloudyKit Jet Template. Therefore it is very much like the Golang basic template system but with some improvements. For all syntaxic question, it is recommanded to look into Jet Template documentation here.

File naming

You can, pretty much, name your files however you want. But, to keep some homogenuity, it would be preferable to keep the name in lowercase, you can use underscores and you have to use the suffix ".jet.html"

Global Variables

In every template file, besides the built-in functions from Jet Template, you have also some Nyaa Global Variables that you can access to. Those variables are set in template.go in CommonVariable function. If you want to add a global variable, it is there. Be aware to set only important variables here, not page specific one.

What do they do?

Here we will try to look into each variable and explain how do they work.

  • Config variable is the website configuration set in config/config.yml. You can access every exported Properties and functions from config/struct.go. For example, Config.Torrents.Tags.Default return the default tag type and Config.Port return the running port.
  • CsrfToken variable return a string for the csrf input field. You have to use it in a hidden input every time you want to make a POST request.
  • Errors variable is a map[string][] with all the errors listed, from an internal error to a more simple form input error. Better to use the yield function errors().
  • Infos variable is a map[string][] with all the information messages listed. Better to use the yield function infos().
  • Mascot variable is the choosen mascot.
  • MascotURL variable is the url of the mascot set by the user.
  • Search variable is link to the search form state. For example, you can access to the set category with Search.Category. This variables also inherit all exported Properties from TorrentParam (utils/search/torrentParam.go).
  • Theme variable is the name of the choosen theme.
  • URL variable is the current URL of the page. This variable is a net/url.Url struct. Therefore you can use all exported properties and functions from it. More information in the golang doc.
  • User variable is the current User. This variable is defined in models/user.go. Every exported properties and functions are available. For example, User.Username gives you the user's username and User.IsModerator() tells you if a user is a moderator or not.

How to use them?

Pretty simple, just type: {{ NameOfVariable }}. For example, {{ URL.String() }} to get the current URL.

Global Functions

Same as global variables, there are also global functions. They are all defined here.

  • contains(language, string) tells you if a language corresponds to the language code provided
  • genActivityContent(activity, T function) returns the translated activty.
  • genUploaderLink(uploaderID, uploaderName, hidden) return a <a href="">Username</a> for the user provided based on the elements provided. For example, if you provide a username and no userID or a hidden bool to true. Then it won't return a link but will return "renchon" username.
  • getCategory(MainCategory, keepParent) return an array of Category (struct set in utils/categories/categories.go) based on the MainCategory string provided and the bool keepParent. If keepParent is true, the MainCategory is included.
  • categoryName(maincat, subcat) returns the category name And many more...

How to use them?

Same as global variables, just do {{ function() }}. For example, flagCode("fr-fr") returns the flag code "fr".

Helpers Functions

Beside global functions accessible whenever you want, you can also import template functions or make them. All template functions beside the global ones, should be set in separate files in /templates/layouts/partials/helpers/. List of template functions available (non exhaustive, please look for them in helpers folder):

  • badge_user() is a function used in menu to display the user badge
  • captcha(captchaid) is a function used in forms to display a captcha input, it needs a captchaid to work
  • csrf_field() is a function used in forms to add a hidden input for the csrf check. The token is directly taken from the global variables
  • errors(name) is a function used to display the error messages. You just need to specify what errors do you want.
  • infos(name) is a function used to display the informations messages. You just to specify what infos do you want.

How to use them?

A bit less easy, you need to use this format: {{ yield function(param="something") }}. For example, {{ yield csrf_field() }} will add a csrf hidden input or {{ errors(name="Description") }} will display all the errors for Description. Furthermore, you need to import (relative to /templates/) the file where the function is defined at the start of template! For example, {{ import "layouts/partials/helpers/csrf" }} to import the csrf_field() function and use it.