-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
search-profile: load preset filters from search profile into project …
…overview
- Loading branch information
Showing
15 changed files
with
207 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
### Added | ||
- functions for the project overview to get its default state based on if a search profile exists or not | ||
- functionality to load a search profile's preset filters into project overview | ||
|
||
### Changed | ||
- added project status model instead of a field to be able to store a list of project statuses inside a search profile |
47 changes: 47 additions & 0 deletions
47
meinberlin/apps/kiezradar/migrations/0004_add_project_status.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,47 @@ | ||
# Generated by Django 4.2.11 on 2025-01-07 07:58 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("meinberlin_kiezradar", "0003_searchprofile_notification"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ProjectStatus", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"status", | ||
models.SmallIntegerField( | ||
choices=[(0, "running"), (1, "done"), (2, "future")], | ||
verbose_name="Status", | ||
), | ||
), | ||
], | ||
), | ||
migrations.RemoveField( | ||
model_name="searchprofile", | ||
name="status", | ||
), | ||
migrations.AddField( | ||
model_name="searchprofile", | ||
name="status", | ||
field=models.ManyToManyField( | ||
blank=True, | ||
related_name="search_profiles", | ||
to="meinberlin_kiezradar.projectstatus", | ||
), | ||
), | ||
] |
25 changes: 25 additions & 0 deletions
25
meinberlin/apps/kiezradar/migrations/0005_populate_project_status.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,25 @@ | ||
# Generated by Django 4.2.11 on 2025-01-07 07:59 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def populate_project_status(apps, schema_editor): | ||
ProjectStatus = apps.get_model("meinberlin_kiezradar", "ProjectStatus") | ||
ProjectStatus.objects.bulk_create( | ||
[ | ||
ProjectStatus(status=0), | ||
ProjectStatus(status=1), | ||
ProjectStatus(status=2), | ||
] | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("meinberlin_kiezradar", "0004_add_project_status"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(populate_project_status), | ||
] |
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
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
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
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
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,37 @@ | ||
const defaultState = { | ||
search: '', | ||
districts: [], | ||
// organisation is a single select but its simpler to just work with an | ||
// array because of the typeahead component | ||
organisation: [], | ||
participations: [], | ||
topics: [] | ||
} | ||
|
||
export const getDefaultState = (searchProfile) => { | ||
let mergeData = {} | ||
|
||
if (searchProfile) { | ||
mergeData = { | ||
search: searchProfile.query_text ?? '', | ||
districts: searchProfile.districts.map(d => d.name), | ||
organisation: searchProfile.organisations.map(o => o.name), | ||
participations: searchProfile.project_types.map(p => p.id), | ||
topics: searchProfile.topics.map((t) => t.code) | ||
} | ||
} | ||
|
||
return { | ||
...defaultState, | ||
...mergeData | ||
} | ||
} | ||
|
||
export const getDefaultProjectState = (searchProfile) => { | ||
const mapping = ['active', 'past', 'future'] | ||
if (searchProfile && searchProfile.status.length) { | ||
return searchProfile.status.map(s => mapping[s.status]) | ||
} | ||
|
||
return ['active', 'future'] | ||
} |
Oops, something went wrong.