Skip to content

Commit c71b6ea

Browse files
authored
Use radio for pipeline choices in modal #618 (#641)
* Adjust the project form spacing #618 Signed-off-by: Thomas Druez <tdruez@nexb.com> * Split pipeline doc string into summary and description #618 Signed-off-by: Thomas Druez <tdruez@nexb.com> * Use pipeline summary as run description value #618 Signed-off-by: Thomas Druez <tdruez@nexb.com> * Use radio in place of select for pipeline choices in modal #618 Signed-off-by: Thomas Druez <tdruez@nexb.com> --------- Signed-off-by: Thomas Druez <tdruez@nexb.com>
1 parent 1705bb3 commit c71b6ea

16 files changed

Lines changed: 83 additions & 33 deletions

scanpipe/forms.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,14 @@ def save(self, project):
134134

135135

136136
class AddPipelineForm(PipelineBaseForm):
137-
def __init__(self, *args, **kwargs):
138-
"""Set the `pipeline` field as required for this form."""
139-
super().__init__(*args, **kwargs)
140-
self.fields["pipeline"].required = True
137+
pipeline = forms.ChoiceField(
138+
choices=[
139+
(name, pipeline_class.get_summary())
140+
for name, pipeline_class in scanpipe_app.pipelines.items()
141+
],
142+
widget=forms.RadioSelect(),
143+
required=True,
144+
)
141145

142146
def save(self, project):
143147
self.handle_pipeline(project)

scanpipe/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,7 @@ def add_uploads(self, uploads):
776776

777777
def add_pipeline(self, pipeline_name, execute_now=False):
778778
"""
779-
Create a new Run instance with the provided `pipeline` on the current
780-
project.
779+
Create a new Run instance with the provided `pipeline` on the current project.
781780
782781
If `execute_now` is True, the pipeline task is created.
783782
on_commit() is used to postpone the task creation after the transaction is
@@ -786,10 +785,13 @@ def add_pipeline(self, pipeline_name, execute_now=False):
786785
immediately.
787786
"""
788787
pipeline_class = scanpipe_app.pipelines.get(pipeline_name)
788+
if not pipeline_class:
789+
raise ValueError(f"Unknown pipeline: {pipeline_name}")
790+
789791
run = Run.objects.create(
790792
project=self,
791793
pipeline_name=pipeline_name,
792-
description=pipeline_class.get_doc(),
794+
description=pipeline_class.get_summary(),
793795
)
794796
if execute_now:
795797
transaction.on_commit(run.execute_task_async)

scanpipe/pipelines/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from contextlib import contextmanager
2929
from functools import wraps
3030
from pydoc import getdoc
31+
from pydoc import splitdoc
3132

3233
from django.utils import timezone
3334

@@ -66,7 +67,7 @@ def get_steps(cls):
6667

6768
@classmethod
6869
def get_doc(cls):
69-
"""Return a docstring."""
70+
"""Get the doc string of this pipeline."""
7071
return getdoc(cls)
7172

7273
@classmethod
@@ -78,12 +79,19 @@ def get_graph(cls):
7879

7980
@classmethod
8081
def get_info(cls):
81-
"""Return a dictionary of combined data about the current pipeline."""
82+
"""Get a dictionary of combined information data about this pipeline."""
83+
summary, description = splitdoc(cls.get_doc())
8284
return {
83-
"description": cls.get_doc(),
85+
"summary": summary,
86+
"description": description,
8487
"steps": cls.get_graph(),
8588
}
8689

90+
@classmethod
91+
def get_summary(cls):
92+
"""Get the doc string summary."""
93+
return cls.get_info()["summary"]
94+
8795
def log(self, message):
8896
"""Log the given `message` to the current module logger and Run instance."""
8997
now_as_localtime = timezone.localtime(timezone.now())

scanpipe/templates/scanpipe/includes/add_pipeline_modal.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
99
</header>
1010
<section class="modal-card-body">
1111
<div class="field">
12-
<label class="label" for="{{ add_pipeline_form.pipeline.id_for_label }}">Pipeline</label>
1312
<div class="control">
14-
<span class="select">
15-
{{ add_pipeline_form.pipeline }}
16-
</span>
13+
{% for label, summary in add_pipeline_form.pipeline.field.choices %}
14+
<div class="mb-3">
15+
<label class="radio label mb-0">
16+
<input type="radio" name="pipeline" value="{{ label }}">
17+
{{ label }}
18+
</label>
19+
<p class="help ml-4">{{ summary }}</p>
20+
</div>
21+
{% endfor %}
1722
</div>
1823
</div>
24+
<hr class="my-4">
1925
<div class="field">
2026
<label class="checkbox" for="{{ add_pipeline_form.execute_now.id_for_label }}">
2127
{{ add_pipeline_form.execute_now }}

scanpipe/templates/scanpipe/project_form.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<div class="container is-max-desktop">
55
{% include 'scanpipe/includes/navbar_header.html' %}
66

7-
<section class="section pt-0">
8-
<h2 class="subtitle mb-0 pt-2 mb-5">
7+
<section class="mx-5 pt-0 pb-1">
8+
<h2 class="subtitle mb-0 mb-4">
99
Create a <strong>Project</strong>
1010
</h2>
1111

@@ -16,7 +16,7 @@ <h2 class="subtitle mb-0 pt-2 mb-5">
1616
</div>
1717

1818
<div class="columns">
19-
<div class="column is-three-fifths pr-5">
19+
<div class="column is-three-fifths pr-5 pb-0">
2020

2121
<form method="post" action="{% url 'project_add' %}" enctype="multipart/form-data">{% csrf_token %}
2222
<div class="field">
@@ -72,7 +72,7 @@ <h2 class="subtitle mb-0 pt-2 mb-5">
7272
</label>
7373
</div>
7474

75-
<div class="columns mt-6 is-variable is-1">
75+
<div class="columns mt-4 is-variable is-1">
7676
<div class="column is-one-third">
7777
<a href="{% url 'project_list' %}" class="button is-fullwidth">Cancel</a>
7878
</div>
@@ -102,7 +102,10 @@ <h3 class="subtitle mb-3">Pipelines:</h3>
102102
<button class="delete" aria-label="close"></button>
103103
</header>
104104
<div class="notification has-background-info-light has-text-weight-semibold is-radiusless mb-0">
105-
{{ pipeline_info.description }}
105+
<p>{{ pipeline_info.summary }}</p>
106+
{% if pipeline_info.description %}
107+
<p class="mt-3">{{ pipeline_info.description|linebreaks }}</p>
108+
{% endif %}
106109
</div>
107110
<section class="modal-card-body has-text-centered border-bottom-radius">
108111
{% for step in pipeline_info.steps %}
@@ -114,7 +117,7 @@ <h3 class="subtitle mb-3">Pipelines:</h3>
114117
</div>
115118
</div>
116119
</div>
117-
{{ pipeline_info.description }}
120+
{{ pipeline_info.summary }}
118121
</div>
119122
{% endfor %}
120123
</div>

scanpipe/tests/data/asgiref-3.3.0_load_inventory_expected.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
"pipeline_name": "load_inventory",
1010
"status": "not_started",
11-
"description": "Load one or more inventory from ScanCode-toolkit and ScanCode.io JSON scan results.\n\nAn inventory is composed of packages, dependencies, and resources.",
11+
"description": "Load one or more inventory from ScanCode-toolkit and ScanCode.io JSON scan results.",
1212
"scancodeio_version": "",
1313
"task_id": null,
1414
"task_start_date": null,

scanpipe/tests/data/daglib-0.6.0-py3-none-any.whl_scan_codebase.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{
1414
"pipeline_name": "scan_codebase",
1515
"status": "not_started",
16-
"description": "Scan a codebase with ScanCode-toolkit.\n\nIf the codebase consists of several packages and dependencies, it will try to\nresolve and scan those too.\n\nInput files are copied to the project's codebase/ directory and are extracted\nin place before running the scan.\nAlternatively, the code can be manually copied to the project codebase/\ndirectory.",
16+
"description": "Scan a codebase with ScanCode-toolkit.",
1717
"scancodeio_version": "",
1818
"task_id": null,
1919
"task_start_date": null,

scanpipe/tests/data/is-npm-1.0.0_scan_codebase.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{
1414
"pipeline_name": "scan_codebase",
1515
"status": "not_started",
16-
"description": "Scan a codebase with ScanCode-toolkit.\n\nIf the codebase consists of several packages and dependencies, it will try to\nresolve and scan those too.\n\nInput files are copied to the project's codebase/ directory and are extracted\nin place before running the scan.\nAlternatively, the code can be manually copied to the project codebase/\ndirectory.",
16+
"description": "Scan a codebase with ScanCode-toolkit.",
1717
"scancodeio_version": "",
1818
"task_id": null,
1919
"task_start_date": null,

scanpipe/tests/pipelines/do_nothing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424

2525

2626
class DoNothing(Pipeline):
27-
"""A pipeline that does nothing, in 2 steps."""
27+
"""
28+
Do nothing, in 2 steps.
29+
30+
Description section of the doc string.
31+
"""
2832

2933
@classmethod
3034
def steps(cls):

scanpipe/tests/pipelines/profile_step.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
class ProfileStep(Pipeline):
28-
"""A pipeline to profile a step using the @profile decorator."""
28+
"""Profile a step using the @profile decorator."""
2929

3030
@classmethod
3131
def steps(cls):

0 commit comments

Comments
 (0)