Page MenuHomeSoftware Heritage

Add option to select code language
ClosedPublic

Authored by kalpitk on Jul 12 2019, 8:26 PM.

Details

Summary

Related T1909

Diff Detail

Event Timeline

  • Refactor updateLanguage
  • Add chosen plugin for searchable dropdown
  • add dropdown
  • import css for chosen

I have added chosen-js plugin for searching and filtering of languages dropdown.

Importing chosen-js in swh/web/assets/src/bundles/vendors/index.js doesn't import the css. On adding imports for css and png separately, webpack fails. I am not able to figure out why ?

  • Fix webpack error and trigger updateLanguage with dropdown

CSS needs to be updated for the dropdown.
Rest everything is done.

swh/web/assets/config/webpack.config.development.js
297

Not sure why (\?v=\d+\.\d+\.\d+) is used here. Should this be used with images also?

311

Will directory 'img/imports' be fine for outputPath?

vlorentz added inline comments.
swh/web/assets/config/webpack.config.development.js
297

I don't know... don't use it if it's not needed.

306

Do we need GIF and JPEG for now?

311

What about img/thirdParty (to match the name used elsewhere)?

swh/web/templates/includes/top-navigation.html
134

What does this line do?

swh/web/assets/config/webpack.config.development.js
297

ok

306

No. Should I remove gif and jpeg from here?

311

ok

swh/web/templates/includes/top-navigation.html
134

It was for initialising chosen on select.

It works without this line, because of the next line.
Will remove it.

swh/web/assets/config/webpack.config.development.js
306

If we don't need it, yes.

I had to use !important everywhere to override the default css. I guess, there must be a way to avoid it.

kalpitk retitled this revision from [WIP] Add option to select code language to Add option to select code language.Jul 17 2019, 1:22 PM
kalpitk retitled this revision from Add option to select code language to [WIP] Add option to select code language.

Update CSS and refactor

kalpitk retitled this revision from [WIP] Add option to select code language to Add option to select code language.Jul 17 2019, 3:04 PM

It's really nice!

Just a few remarks:

  • it's unclear what language_select does, especially as it's used both as a list of languages and a boolean to tell whether the language selector should be shown. It should be renamed to available_languages
swh/web/browse/views/utils/snapshot_context.py
457 ↗(On Diff #5860)

"Override language with user-selected language"

swh/web/templates/includes/content-display.html
68

This currently works because there are no other params, but it would be nice to support other parameters in the URL, so we don't get unexpected bugs later.

swh/web/templates/includes/top-navigation.html
133
swh/web/browse/views/utils/snapshot_context.py
457 ↗(On Diff #5860)

ok

swh/web/templates/includes/content-display.html
68

I tested it with other params like origin_url, it works.
I mean for links like "http://127.0.0.1:5004/browse/content/sha1_git:33217f73631dbfa1860b41060e5a6a5a62420f69/?origin_url=https%3A%2F%2Fgithub.com%2Fusartkom%2Flearning_pyhon&language=gherkin", everything works.

(URLSearchParams stores all params in url)

swh/web/templates/includes/top-navigation.html
133

Django auto-escapes template variables by default.

language_select renamed available_languages

vlorentz added inline comments.
swh/web/templates/includes/content-display.html
68

Indeed, my bad

This revision is now accepted and ready to land.Jul 18 2019, 10:25 AM
This revision was automatically updated to reflect the committed changes.