Skip to content
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

Improve packages webui #111

Merged
merged 8 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions spkrepo/templates/frontend/package.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
</a>
<div class="media-body">
<h1 class="media-heading">{{ package.versions[-1].displaynames['enu'].displayname }}
<small>v{{ package.versions[-1].version_string }}
{% if package.versions[-1].report_url %}<span class="label label-danger">beta</span>{% endif %}
</small>
<small>v{{ package.versions[-1].version_string }}</small>
</h1>
<p>{{ package.versions[-1].descriptions['enu'].description }}</p>
<div class="package-screenshots">
Expand All @@ -20,31 +18,36 @@ <h1 class="media-heading">{{ package.versions[-1].displaynames['enu'].displaynam
</div>
{% for version in package.versions|reverse %}
<dl>
<dt>Version {{ version.version_string | safe }}</dt>
<dt>Version {{ version.version_string | safe }}{% if version.report_url %} <span class="label label-danger">beta</span>{% endif %}</dt>
<dd>{{ version.changelog | safe }}</dd>
<dt>Date</dt>
<dd>{{ version.insert_date }}</dd>
<dd>{{ version.insert_date.replace(microsecond=0) }}</dd>
<dt>Architectures</dt>
<dd>
{% for (version, builds) in version.builds_per_dsm.items() %}
{% for (version, builds) in version.builds_per_dsm.items() %}
<!-- Group firmware by DSM or SRM if 1.x -->
{% if version == '1' %}
SRM {{ version }}.x:
SRM {{ version }}.x:
{% else %}
DSM {{ version }}.x:
DSM {{ version }}.x:
{% endif %}
{% for build in builds %}
{% for arch in build.architectures %}
<a href="{{ url_for('nas.data', path=build.path) }}"><span class="label label-default">{{ build.firmware.version }} {{ arch.code }}</span></a>
{% endfor %}
{% if build.active %}
{% for arch in build.architectures %}
<a href="{{ url_for('nas.data', path=build.path) }}"><span class="label label-success">{{ build.firmware.version }} {{ arch.code }}</span></a>
{% endfor %}
{% else %}
{% for arch in build.architectures %}
<a href="{{ url_for('nas.data', path=build.path) }}"><span class="label label-default" data-toggle="tooltip" title="Inactive: Manual installation only. This Package might be under development and have pending issues.">{{ build.firmware.version }} {{ arch.code }}</span></a>
{% endfor %}
{% endif %}
{% endfor %}
<br/>
{% endfor %}
{% endfor %}
</dd>
</dl>
{% endfor %}
</div>
<span
</div>
</div>
{% endblock %}
4 changes: 1 addition & 3 deletions spkrepo/templates/frontend/packages.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
</a>
<div class="media-body">
<h4 class="media-heading">{{ version.displaynames['enu'].displayname }}
<small>v{{ version.version_string }}
{% if version.report_url %}<span class="label label-danger">beta</span>{% endif %}
</small>
<small>v{{ version.version_string }}</small>
</h4>
<div class="ellipsis package-description">
<p>{{ version.descriptions['enu'].description }}</p>
Expand Down
75 changes: 60 additions & 15 deletions spkrepo/tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_get_logged_user(self):


class PackagesTestCase(BaseTestCase):
def test_get_active_stable(self):
def test_get_active(self):
build = BuildFactory(version__report_url=None, active=True)
hgy59 marked this conversation as resolved.
Show resolved Hide resolved
db.session.commit()
response = self.client.get(url_for("frontend.packages"))
Expand All @@ -35,45 +35,67 @@ def test_get_active_stable(self):
)
self.assertNotIn("beta", response.data.decode())

hgy59 marked this conversation as resolved.
Show resolved Hide resolved
def test_get_active_not_stable(self):
build = BuildFactory(active=True)
def test_get_not_active(self):
build = BuildFactory(active=False)
db.session.commit()
response = self.client.get(url_for("frontend.packages"))
self.assert200(response)
self.assertIn(
build.version.displaynames["enu"].displayname,
response.data.decode(),
)
self.assertIn("beta", response.data.decode())

def test_get_not_active_not_stable(self):
build = BuildFactory(active=False)

class PackageTestCase(BaseTestCase):
def test_get_active_stable(self):
build = BuildFactory(
version__package__author=UserFactory(),
version__report_url=None,
active=True,
)
db.session.commit()
response = self.client.get(url_for("frontend.packages"))
response = self.client.get(
url_for("frontend.package", name=build.version.package.name)
)
self.assert200(response)
self.assertNotIn(
for a in build.architectures:
self.assertIn(a.code, response.data.decode())
self.assertIn(
build.version.displaynames["enu"].displayname,
response.data.decode(),
)
self.assertIn(
build.version.descriptions["enu"].description,
response.data.decode(),
)
self.assertNotIn("beta", response.data.decode())

def test_get_not_active_stable(self):
build = BuildFactory(active=False)
build = BuildFactory(
version__package__author=UserFactory(),
version__report_url=None,
active=False,
)
db.session.commit()
response = self.client.get(url_for("frontend.packages"))
response = self.client.get(
url_for("frontend.package", name=build.version.package.name)
)
self.assert200(response)
self.assertNotIn(
for a in build.architectures:
self.assertIn(a.code, response.data.decode())
self.assertIn(
build.version.displaynames["enu"].displayname,
response.data.decode(),
)
self.assertIn(
build.version.descriptions["enu"].description,
response.data.decode(),
)
self.assertNotIn("beta", response.data.decode())


class PackageTestCase(BaseTestCase):
def test_get(self):
def test_get_active_not_stable(self):
build = BuildFactory(
version__package__author=UserFactory(),
version__report_url=None,
active=True,
)
db.session.commit()
Expand All @@ -91,6 +113,29 @@ def test_get(self):
build.version.descriptions["enu"].description,
response.data.decode(),
)
self.assertIn("beta", response.data.decode())

def test_get_not_active_not_stable(self):
build = BuildFactory(
version__package__author=UserFactory(),
active=False,
)
db.session.commit()
response = self.client.get(
url_for("frontend.package", name=build.version.package.name)
)
self.assert200(response)
for a in build.architectures:
self.assertIn(a.code, response.data.decode())
self.assertIn(
build.version.displaynames["enu"].displayname,
response.data.decode(),
)
self.assertIn(
build.version.descriptions["enu"].description,
response.data.decode(),
)
self.assertIn("beta", response.data.decode())

def test_get_no_package(self):
response = self.client.get(url_for("frontend.package", name="no-package"))
Expand Down
4 changes: 2 additions & 2 deletions spkrepo/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def on_model_delete(self, model):
("upgrade_wizard", "upgrade_wizard"),
("startable", "startable"),
)
# TODO: Add beta and all_builds_active with Flask-Admin>1.0.8

column_default_sort = (Version.insert_date, True)

# Custom queries
Expand Down Expand Up @@ -533,7 +533,7 @@ def can_unsign(self):
("insert_date", "insert_date"),
("active", "active"),
)
# TODO: Add version.package with Flask-Admin>1.0.8

column_default_sort = (Build.insert_date, True)

# Custom queries
Expand Down
3 changes: 1 addition & 2 deletions spkrepo/views/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def profile():

@frontend.route("/packages")
def packages():
# show only packages with at least one version, but ignore whether builds are active
latest_version = (
db.session.query(
Version.package_id, db.func.max(Version.version).label("latest_version")
)
.join(Build)
.filter(Build.active)
.group_by(Version.package_id)
.subquery()
)
Expand All @@ -96,7 +96,6 @@ def packages():

@frontend.route("/package/<name>")
def package(name):
# TODO: show only packages with at least a version and an active build
package = Package.query.filter_by(name=name).first()
if package is None:
abort(404)
Expand Down