From 3af8d11720a57842b03742bb3691d356983c6af6 Mon Sep 17 00:00:00 2001 From: jce <28319872+JasperCraeghs@users.noreply.github.com> Date: Thu, 1 Aug 2024 15:08:16 +0200 Subject: [PATCH 1/4] Require Ctrl keypress in combination with RMB to expand item-matrix row --- mlx/traceability/assets/traceability.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mlx/traceability/assets/traceability.js b/mlx/traceability/assets/traceability.js index e17252f1..73a55c48 100644 --- a/mlx/traceability/assets/traceability.js +++ b/mlx/traceability/assets/traceability.js @@ -57,8 +57,15 @@ $(document).ready(function () { }); $('table > tbody > tr[class^=item-group-]').each(function (i) { + var row = $(this); + const titleOnHidden = 'Ctrl+RMB to expand'; + const titleOnVisible = 'Ctrl+RMB to collapse'; + row.attr('title', titleOnHidden); $(this).on("contextmenu", function (event) { + if (!event.ctrlKey) { + return; + } event.preventDefault() var groupName = /item-group-\d+/.exec($(this).attr('class'))[0]; $(this).parent().find(`tr.${groupName} > td > p.item-link`).each(function (j) { @@ -67,7 +74,13 @@ $(document).ready(function () { cell.css("maxWidth", maxWidth); const content = $(this).children('div.content').first(); if (content.length) { - content.toggle(); + if (content.is(":visible")) { + content.hide(); + row.attr('title', titleOnHidden); + } else { + row.attr('title', titleOnVisible); + content.show(); + } } else { var link = $(this).children('a').first(); var container = $('
', { class: 'content' }); @@ -76,6 +89,7 @@ $(document).ready(function () { container.find('*').css("width", "inherit"); paragraph.append(container); }); + row.attr('title', titleOnVisible); } }); } From d4297c0eb46b4d330570688c9f5ad347efe1cd92 Mon Sep 17 00:00:00 2001 From: jce <28319872+JasperCraeghs@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:42:44 +0200 Subject: [PATCH 2/4] Add version to filename of JS file and minify it --- mlx/traceability/traceability.py | 2 +- pyproject.toml | 2 +- setup.py | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mlx/traceability/traceability.py b/mlx/traceability/traceability.py index 2f6f3bcc..e4ebdafb 100644 --- a/mlx/traceability/traceability.py +++ b/mlx/traceability/traceability.py @@ -479,7 +479,7 @@ def setup(app): # Javascript and stylesheet for the tree-view app.add_js_file('https://cdn.rawgit.com/aexmachina/jquery-bonsai/master/jquery.bonsai.js') app.add_css_file('https://cdn.rawgit.com/aexmachina/jquery-bonsai/master/jquery.bonsai.css') - app.add_js_file('traceability.js') + app.add_js_file(f'traceability-{version}.min.js') # Since Sphinx 6, jquery isn't bundled anymore and we need to ensure that # the sphinxcontrib-jquery extension is enabled. diff --git a/pyproject.toml b/pyproject.toml index ba5cd66d..889a6227 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=61", "setuptools_scm>=7.1.0"] +requires = ["setuptools>=61", "setuptools_scm>=7.1.0", "css-html-js-minify>=2.5.5,<3"] build-backend = "setuptools.build_meta" [tool.setuptools_scm] diff --git a/setup.py b/setup.py index 68758e89..98a63740 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,11 @@ # -*- coding: utf-8 -*- +from css_html_js_minify import process_single_js_file from setuptools import setup, find_namespace_packages +from setuptools_scm import get_version +version = get_version() + project_url = 'https://github.com/melexis/sphinx-traceability-extension' requires = [ @@ -13,6 +17,8 @@ 'python-decouple', 'requests', ] +js_file_path = 'mlx/traceability/assets/traceability.js' +process_single_js_file(js_file_path, output_path=js_file_path.replace('.js', f'-{version}.min.js')) setup( name='mlx.traceability', @@ -65,5 +71,5 @@ 'ISO26262', 'ASIL', ], - package_data={'mlx.traceability': ['assets/*.js']}, + package_data={'mlx.traceability': ['assets/traceability-*.js']}, ) From 7975b7b16f2ed0c994c4a87a6282fb34b43ee450 Mon Sep 17 00:00:00 2001 From: jce <28319872+JasperCraeghs@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:13:14 +0200 Subject: [PATCH 3/4] Ignore minified JS file in GIT --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 1906f64f..36f94781 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ doc/_images # Custom hyperlink colors mlx/traceability/assets/hyperlink_colors.css + +# Minified JS file +mlx/traceability/assets/traceability-*.min.js From 74b0dcef178c0b3976d35b822102ca98c4034435 Mon Sep 17 00:00:00 2001 From: jce <28319872+JasperCraeghs@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:59:13 +0200 Subject: [PATCH 4/4] Exclude autogenerated minified JS file --- MANIFEST.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index f4b4acb9..a3857dc0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,7 +2,8 @@ include *.md # Include the assets - javascript -include mlx/traceability/assets/*.js +include mlx/traceability/assets/traceability.js +exclude mlx/traceability/assets/traceability-*.min.js exclude mlx/traceability/__traceability_version__.py