-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from wmo-raf/dev
Updates for custom data parameters
- Loading branch information
Showing
11 changed files
with
198 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
forecastmanager/migrations/0022_alter_forecastdataparameters_parameter_type_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 4.2.3 on 2024-04-15 06:55 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('forecastmanager', '0021_forecastsetting_weather_reports_page'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='forecastdataparameters', | ||
name='parameter_type', | ||
field=models.CharField(choices=[('numeric', 'Number'), ('text', 'Text')], default='numeric', max_length=100, verbose_name='Parameter Type'), | ||
), | ||
migrations.AlterField( | ||
model_name='forecastsetting', | ||
name='default_city', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='forecastmanager.city', verbose_name='Default City'), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
forecastmanager/migrations/0023_forecastdataparameters_use_known_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.3 on 2024-04-15 11:07 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('forecastmanager', '0022_alter_forecastdataparameters_parameter_type_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='forecastdataparameters', | ||
name='use_known_parameters', | ||
field=models.BooleanField(default=True, verbose_name='Use known parameters'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
forecastmanager/static/forecastmanager/js/forecast-data-parameter-widget.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
function DataParameterWidget(id, initialValue) { | ||
const inputId = '#' + id | ||
this.input = $(inputId); | ||
|
||
const parameterListSelectId = id + "_parameter_list" | ||
this.parameterListSelectInput = $("#" + parameterListSelectId); | ||
|
||
const useKnownParameterInputId = id.split("-parameter")[0] + "-use_known_parameters" | ||
this.checkIsKnownParameterInput = $("#" + useKnownParameterInputId) | ||
|
||
const that = this | ||
|
||
this.checkIsKnownParameterInput.change(function () { | ||
const checked = $(this).is(":checked") | ||
|
||
if (checked) { | ||
that.input.hide() | ||
that.parameterListSelectInput.show() | ||
} else { | ||
that.input.show() | ||
that.parameterListSelectInput.hide() | ||
} | ||
|
||
}) | ||
|
||
if (this.checkIsKnownParameterInput.is(":checked")) { | ||
// clear any previous value | ||
that.parameterListSelectInput.show() | ||
} else { | ||
that.input.show() | ||
} | ||
|
||
this.parameterListSelectInput.change(function () { | ||
const selectedVal = $(this).val() | ||
that.setState(selectedVal) | ||
}) | ||
} | ||
|
||
DataParameterWidget.prototype.setState = function (newState) { | ||
this.input.val(newState); | ||
}; | ||
|
||
DataParameterWidget.prototype.getState = function () { | ||
return this.input.val(); | ||
}; | ||
|
||
DataParameterWidget.prototype.getValue = function () { | ||
return this.input.val(); | ||
}; | ||
|
||
DataParameterWidget.prototype.focus = function () { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
forecastmanager/templates/forecastmanager/forecast_data_parameter_widget.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} | ||
value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} | ||
style="display: none"> | ||
|
||
<select style="display: none" id="{{ widget.attrs.id }}_parameter_list"> | ||
<option value="">-----------</option> | ||
{% for option in widget.parameter_list %} | ||
<option value="{{ option.value }}" | ||
{% if widget.value and widget.value == option.value %}selected{% endif %}>{{ option.label }}</option> | ||
{% endfor %} | ||
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters