diff --git a/backend/right_tree/api/data/fixtures/006_zones.json b/backend/right_tree/api/data/fixtures/006_zones.json index 7509de1..eeca0ad 100644 --- a/backend/right_tree/api/data/fixtures/006_zones.json +++ b/backend/right_tree/api/data/fixtures/006_zones.json @@ -690,7 +690,7 @@ "name": "SPRAY ZONE", "variant": "Coastal", "refined_variant": "Bush Edge", - "redirect_habitat": null, + "redirect_habitat": 2, "ignore_soil_order_filter": false, "ignore_location_filter": false } diff --git a/backend/right_tree/api/data/fixtures/007_sample_habitat_images.json b/backend/right_tree/api/data/fixtures/007_sample_habitat_images.json index 511d5f3..c835ddd 100644 --- a/backend/right_tree/api/data/fixtures/007_sample_habitat_images.json +++ b/backend/right_tree/api/data/fixtures/007_sample_habitat_images.json @@ -16,5 +16,14 @@ "name": "Salt Marsh", "image_filename": "03-coastal-grass-reeds-scrub.png" } + }, + { + "model": "api.habitatimage", + "pk": 3, + "fields": { + "habitat": 2, + "name": "Bush Hillsides", + "image_filename": "07-riparian-bush-hillsides.png" + } } ] \ No newline at end of file diff --git a/backend/right_tree/api/migrations/0008_alter_zone_redirect_habitat.py b/backend/right_tree/api/migrations/0008_alter_zone_redirect_habitat.py new file mode 100644 index 0000000..20cb7f3 --- /dev/null +++ b/backend/right_tree/api/migrations/0008_alter_zone_redirect_habitat.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.8 on 2021-11-10 22:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0007_alter_zoneimagesegment_segment_percentage_width'), + ] + + operations = [ + migrations.AlterField( + model_name='zone', + name='redirect_habitat', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='zone_redirects', to='api.habitat'), + ), + ] diff --git a/backend/right_tree/api/models.py b/backend/right_tree/api/models.py index 88df35d..38572b3 100644 --- a/backend/right_tree/api/models.py +++ b/backend/right_tree/api/models.py @@ -75,7 +75,7 @@ class Zone(models.Model): variant = models.CharField(null=True, blank=True, max_length=50) refined_variant = models.CharField(null=True, blank=True, max_length=100) redirect_habitat = models.ForeignKey( - HabitatImage, blank=True, null=True, on_delete=models.CASCADE, related_name='zone_redirects') + Habitat, blank=True, null=True, on_delete=models.CASCADE, related_name='zone_redirects') ignore_soil_order_filter = models.BooleanField(default=False) ignore_location_filter = models.BooleanField(default=False) diff --git a/backend/right_tree/api/serializers.py b/backend/right_tree/api/serializers.py index 2fd847c..b0ca8f4 100644 --- a/backend/right_tree/api/serializers.py +++ b/backend/right_tree/api/serializers.py @@ -39,18 +39,25 @@ class SoilVariantSerializer(serializers.HyperlinkedModelSerializer): model = SoilVariant fields = ['name'] - class SimpleHabitatImageSerializer(serializers.HyperlinkedModelSerializer): id = serializers.ReadOnlyField() class Meta: model = HabitatImage - fields = ['id', 'name', 'image_filename'] + fields = ['id'] + +class SimpleHabitatSerializer(serializers.HyperlinkedModelSerializer): + id = serializers.ReadOnlyField() + images = SimpleHabitatImageSerializer(many=True) + + class Meta: + model = Habitat + fields = ['id', 'name', 'images'] class ZoneSerializer(serializers.HyperlinkedModelSerializer): id = serializers.ReadOnlyField() - redirect_habitat = SimpleHabitatImageSerializer() + redirect_habitat = SimpleHabitatSerializer() class Meta: model = Zone diff --git a/frontend/src/assets/img/habitats/07-riparian-bush-hillsides.png b/frontend/src/assets/img/habitats/07-riparian-bush-hillsides.png new file mode 100644 index 0000000..2a45409 Binary files /dev/null and b/frontend/src/assets/img/habitats/07-riparian-bush-hillsides.png differ diff --git a/frontend/src/components/Stepper.js b/frontend/src/components/Stepper.js index 9f28952..a8594bd 100644 --- a/frontend/src/components/Stepper.js +++ b/frontend/src/components/Stepper.js @@ -24,20 +24,30 @@ const steps = [ export default function StepperWizard(props) { const [activeStep, setActiveStep] = React.useState(0); const [nextDisabled, setNextDisabled] = React.useState(true); + const [redirectBack, setRedirectBack] = React.useState(false); + + const resetStepState = () => { + setNextDisabled(true); + setRedirectBack(false); + } const handleNext = () => { - setActiveStep((prevActiveStep) => prevActiveStep + 1); - setNextDisabled(true); + if (redirectBack) { + setActiveStep((prevActiveStep) => prevActiveStep - 1); + } else { + setActiveStep((prevActiveStep) => prevActiveStep + 1); + } + resetStepState(); }; const handleBack = () => { setActiveStep((prevActiveStep) => prevActiveStep - 1); - setNextDisabled(true); + resetStepState(); }; const handleReset = () => { setActiveStep(0); - setNextDisabled(true); + resetStepState(); props.resetFilterState() }; @@ -55,7 +65,7 @@ export default function StepperWizard(props) { })} - +