Skip to content

Commit

Permalink
Improve packages webui (#111)
Browse files Browse the repository at this point in the history
Some web ui improvements
+ fix beta label and use different labels for active and inactive packages
+ apply "beta" to package versions instead of packages
+ use green labels for active packages
+ use default (gray) label for inactive packages and add tooltip telling the package is inactive
+ update version date (cut microseconds)
+ fix unclosed span tag in package.html
Show packages without active versions (leftover of #106)
+ do not hide package in packages when there is no active version (Where is the debian-chroot package for DSM5.2? spksrc#5803)
+ remove obsolete TODOs
Fix webpage footer (fixes #116)
+ correct link for SynoCommunity members
  • Loading branch information
hgy59 authored Feb 24, 2024
1 parent 13ace8a commit 2db02f3
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 53 deletions.
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
6 changes: 3 additions & 3 deletions spkrepo/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@

<footer class="footer" role="contentinfo">
<div class="container">
<p>Powered by <a href="https://github.com/Diaoul/spkrepo">spkrepo</a>.</p>
<p>Developed by <a href="https://github.com/Diaoul">Antoine Bertin</a>.</p>
<p>Code licensed under <a href="https://github.com/Diaoul/spkrepo/blob/master/LICENSE" target="_blank">MIT</a>.</p>
<p>Designed by Antoine Bertin.</p>
<p>Maintained by <a href="https://github.com/orgs/SynoCommunity/people">SynoCommunity</a> with the help of <a href="https://github.com/SynoCommunity/spksrc/graphs/contributors">contributors</a>.</p>
<p>Code licensed under <a href="https://github.com/SynoCommunity/spkrepo/blob/master/LICENSE" target="_blank">MIT</a>.</p>
</div>
</footer>

Expand Down
1 change: 0 additions & 1 deletion spkrepo/templates/security/login_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
{% block content %}
<h1>Login</h1>
{{ wtf.quick_form(login_user_form, field_order=['email'], button_map={'submit': 'primary'}) }}
<p><a href="{{ url_for('security.forgot_password') }}">I forgot my password</a></p>
{% endblock %}
121 changes: 91 additions & 30 deletions spkrepo/tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,85 +12,146 @@ class IndexTestCase(BaseTestCase):
def test_get_anonymous(self):
response = self.client.get(url_for("frontend.index"))
self.assert200(response)
self.assertIn("Login", response.data.decode())
self.assertIn("Register", response.data.decode())
response_data = response.data.decode()
self.assertIn("Login", response_data)
self.assertIn("Register", response_data)

def test_get_logged_user(self):
with self.logged_user():
response = self.client.get(url_for("frontend.index"))
self.assert200(response)
self.assertIn("Logout", response.data.decode())
self.assertIn("Profile", response.data.decode())
response_data = response.data.decode()
self.assertIn("Logout", response_data)
self.assertIn("Profile", response_data)


class PackagesTestCase(BaseTestCase):
def test_get_active_stable(self):
build = BuildFactory(version__report_url=None, active=True)
# Assert beta is not shown on Packages page
def test_get_active_not_stable(self):
build = BuildFactory(active=True)
db.session.commit()
response = self.client.get(url_for("frontend.packages"))
self.assert200(response)
response_data = response.data.decode()
self.assertIn(
build.version.displaynames["enu"].displayname,
response.data.decode(),
response_data,
)
self.assertNotIn("beta", response.data.decode())
self.assertNotIn("beta", response_data)

def test_get_active_not_stable(self):
build = BuildFactory(active=True)
# Assert package with only inactive version(s) is shown on Packages page
def test_get_not_active_not_stable(self):
build = BuildFactory(active=False)
db.session.commit()
response = self.client.get(url_for("frontend.packages"))
self.assert200(response)
response_data = response.data.decode()
self.assertIn(
build.version.displaynames["enu"].displayname,
response.data.decode(),
response_data,
)
self.assertIn("beta", response.data.decode())
self.assertNotIn("beta", response_data)

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(
response_data = response.data.decode()
for a in build.architectures:
self.assertIn(a.code, response_data)
self.assertIn(
build.version.displaynames["enu"].displayname,
response.data.decode(),
response_data,
)
self.assertNotIn("beta", response.data.decode())
self.assertIn(
build.version.descriptions["enu"].description,
response_data,
)
self.assertNotIn("beta", response_data)
self.assertIn("label label-success", response_data)

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(
response_data = response.data.decode()
for a in build.architectures:
self.assertIn(a.code, response_data)
self.assertIn(
build.version.displaynames["enu"].displayname,
response.data.decode(),
response_data,
)
self.assertNotIn("beta", response.data.decode())

self.assertIn(
build.version.descriptions["enu"].description,
response_data,
)
self.assertNotIn("beta", response_data)
self.assertIn("label label-default", response_data)

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()
response = self.client.get(
url_for("frontend.package", name=build.version.package.name)
)
self.assert200(response)
response_data = response.data.decode()
for a in build.architectures:
self.assertIn(a.code, response_data)
self.assertIn(
build.version.displaynames["enu"].displayname,
response_data,
)
self.assertIn(
build.version.descriptions["enu"].description,
response_data,
)
self.assertIn("beta", response_data)
self.assertIn("label label-success", response_data)

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)
response_data = response.data.decode()
for a in build.architectures:
self.assertIn(a.code, response.data.decode())
self.assertIn(a.code, response_data)
self.assertIn(
build.version.displaynames["enu"].displayname,
response.data.decode(),
response_data,
)
self.assertIn(
build.version.descriptions["enu"].description,
response.data.decode(),
response_data,
)
self.assertIn("beta", response_data)
self.assertIn("label label-default", response_data)
self.assertIn("Inactive: Manual installation only.", response_data)

def test_get_no_package(self):
response = self.client.get(url_for("frontend.package", name="no-package"))
Expand Down
5 changes: 2 additions & 3 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,9 +96,8 @@ 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:
if package is None or not package.versions:
abort(404)
return render_template("frontend/package.html", package=package)

Expand Down

0 comments on commit 2db02f3

Please sign in to comment.