From 5e925a4ed635af0634a2e5d32671ac2429e43c0e Mon Sep 17 00:00:00 2001 From: Pierros Papadeas Date: Thu, 7 Feb 2019 20:06:39 +0200 Subject: [PATCH] Add utilization factor to station model and UI --- network/api/serializers.py | 3 +- network/api/tests.py | 1 + network/base/admin.py | 4 +- network/base/forms.py | 3 +- .../0054_station_target_utilization.py | 21 ++ network/base/models.py | 5 + network/static/css/pages/_station.scss | 8 + network/static/js/station_edit.js | 27 +++ network/templates/base/station_edit.html | 194 ++++++++++++------ network/templates/base/station_view.html | 8 + 10 files changed, 205 insertions(+), 69 deletions(-) create mode 100644 network/base/migrations/0054_station_target_utilization.py create mode 100644 network/static/js/station_edit.js diff --git a/network/api/serializers.py b/network/api/serializers.py index 8de1ef6..6b37859 100644 --- a/network/api/serializers.py +++ b/network/api/serializers.py @@ -88,7 +88,8 @@ class StationSerializer(serializers.ModelSerializer): model = Station fields = ('id', 'name', 'altitude', 'min_horizon', 'lat', 'lng', 'qthlocator', 'location', 'antenna', 'created', 'last_seen', - 'status', 'observations', 'description', 'client_version') + 'status', 'observations', 'description', 'client_version', + 'target_utilization') def get_altitude(self, obj): return obj.alt diff --git a/network/api/tests.py b/network/api/tests.py index 1936271..a2737f3 100644 --- a/network/api/tests.py +++ b/network/api/tests.py @@ -74,6 +74,7 @@ class StationViewApiTest(TestCase): u'name': self.station.name, u'observations': 0, u'qthlocator': self.station.qthlocator, + u'target_utilization': self.station.target_utilization, u'status': self.station.get_status_display()} response = self.client.get('/api/stations/') diff --git a/network/base/admin.py b/network/base/admin.py index 65d048a..977eb19 100644 --- a/network/base/admin.py +++ b/network/base/admin.py @@ -26,7 +26,7 @@ class AntennaAdmin(admin.ModelAdmin): @admin.register(Station) class StationAdmin(admin.ModelAdmin): list_display = ('id', 'name', 'owner', 'get_email', 'lng', 'lat', 'qthlocator', - 'client_version', 'created_date', 'state') + 'client_version', 'created_date', 'state', 'target_utilization') list_filter = ('status', 'created', 'client_version') actions = [export_as_csv] @@ -62,7 +62,7 @@ class TransmitterAdmin(admin.ModelAdmin): list_display = ('uuid', 'description', 'satellite', 'type', 'alive', 'mode', 'uplink_low', 'uplink_high', 'uplink_drift', 'downlink_low', 'downlink_high', 'downlink_drift', 'baud', 'sync_to_db') - search_fields = ('satellite', 'uuid', 'satellite__name', 'satellite__norad_cat_id') + search_fields = ('uuid', 'satellite__name', 'satellite__norad_cat_id') list_filter = ('type', 'mode', 'alive', 'sync_to_db') readonly_fields = ('uuid', 'description', 'satellite', 'type', 'uplink_low', 'uplink_high', 'uplink_drift', 'downlink_low', 'downlink_high', 'downlink_drift', diff --git a/network/base/forms.py b/network/base/forms.py index e4611a1..3fc79e3 100644 --- a/network/base/forms.py +++ b/network/base/forms.py @@ -7,7 +7,8 @@ class StationForm(forms.ModelForm): class Meta: model = Station fields = ['name', 'image', 'alt', 'lat', 'lng', 'qthlocator', - 'horizon', 'antenna', 'testing', 'description'] + 'horizon', 'antenna', 'testing', 'description', + 'target_utilization'] image = forms.ImageField(required=False) diff --git a/network/base/migrations/0054_station_target_utilization.py b/network/base/migrations/0054_station_target_utilization.py new file mode 100644 index 0000000..4e4a30a --- /dev/null +++ b/network/base/migrations/0054_station_target_utilization.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-02-07 17:52 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0053_remove_station_uuid'), + ] + + operations = [ + migrations.AddField( + model_name='station', + name='target_utilization', + field=models.IntegerField(blank=True, help_text=b'Target utilization factor for your station', null=True, validators=[django.core.validators.MaxValueValidator(100), django.core.validators.MinValueValidator(0)]), + ), + ] diff --git a/network/base/models.py b/network/base/models.py index b648104..3628c19 100644 --- a/network/base/models.py +++ b/network/base/models.py @@ -167,6 +167,11 @@ class Station(models.Model): horizon = models.PositiveIntegerField(help_text='In degrees above 0', default=10) description = models.TextField(max_length=500, blank=True, help_text='Max 500 characters') client_version = models.CharField(max_length=45, blank=True) + target_utilization = models.IntegerField(validators=[MaxValueValidator(100), + MinValueValidator(0)], + help_text='Target utilization factor for ' + ' your station', + null=True, blank=True) class Meta: ordering = ['-status'] diff --git a/network/static/css/pages/_station.scss b/network/static/css/pages/_station.scss index 4f1c69b..3d47864 100644 --- a/network/static/css/pages/_station.scss +++ b/network/static/css/pages/_station.scss @@ -115,3 +115,11 @@ font-size: 2em; } } + +#horizon_value, #utilization_value { + margin: 0 0 0 20px; + + .slider-selection { + background: #5bc0de; + } +} diff --git a/network/static/js/station_edit.js b/network/static/js/station_edit.js new file mode 100644 index 0000000..b6e560a --- /dev/null +++ b/network/static/js/station_edit.js @@ -0,0 +1,27 @@ +$(document).ready(function() { + 'use strict'; + + $('.selectpicker').selectpicker(); + + var horizon_value = $('#horizon').val(); + $('#horizon').slider({ + id: 'horizon_value', + min: 0, + max: 90, + step: 1, + value: horizon_value}); + + var utilization_value = $('#utilization').val(); + $('#utilization').slider({ + id: 'utilization_value', + min: 0, + max: 100, + step: 1, + value: utilization_value}); + + var station_image = $('#station-image').data('existing'); + $('#station-image').fileinput({ + initialPreview: station_image, + initialPreviewAsData: true, + }); +}); diff --git a/network/templates/base/station_edit.html b/network/templates/base/station_edit.html index 7be81a2..7f0e1aa 100644 --- a/network/templates/base/station_edit.html +++ b/network/templates/base/station_edit.html @@ -4,6 +4,12 @@ {% block title %}{% if station %} - Edit Ground Station {{ station.name }}{% else %} - Add Ground Station{% endif %}{% endblock %} +{% block css %} + + + +{% endblock css %} + {% block content %}
@@ -18,77 +24,135 @@
-
-
{% csrf_token %} -
- - -
-
- - - {% if form.image.value %} - - {% endif %} -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - - {{ form.antenna.help_text|safe }} -
-
- - -
-
-
- + {% csrf_token %} +
+
+
+

General Info

+
+
+
+ + +
+
+ + +
+
+
+

Location

+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ + +
+
+
+ +
+ + +
+
+
+ +
+
+

Image

+
+
+
+ +
+
+
+
+ +
+
+
+

Settings

+
+
+
+ + + +
+ +
+ + + {{ form.antenna.help_text|safe }} +
+ +
+ +
+ + + +
+ +
+ +
+
+ +
+
+
+
+ - -
+ +
+
{% endblock %} {% block javascript %} + + + + {% endblock javascript %} diff --git a/network/templates/base/station_view.html b/network/templates/base/station_view.html index 0586541..4d0930d 100644 --- a/network/templates/base/station_view.html +++ b/network/templates/base/station_view.html @@ -81,6 +81,14 @@ {{ station.horizon }}°
+ {% if station.target_utilization %} +
+ Target Utilization + + {{ station.target_utilization }} % + +
+ {% endif %} {% if station.antenna %}
Antennas