Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

Add destinations page - #205

Closed
stveit wants to merge 9 commits into
mainfrom
destinations
Closed

Add destinations page#205
stveit wants to merge 9 commits into
mainfrom
destinations

Conversation

@stveit

@stveit stveit commented Oct 25, 2024

Copy link
Copy Markdown
Contributor

Fixes Uninett/Argus#1001

Replaced by Uninett/Argus#970

Adds page where you can see and edit existing destinations and create new ones.

Since we are kinda locked to using the serializer for validating destinations (for now, changes will be made at some point) I ended up baking the serializer into the forms for creating/updating destinations. Its a bit wonky but should work fine until we can move on from the serializer and have ModelForm do everything they way it is supposed to.

Needs more styling to be complete, but not sure how to do it properly.. Error in fields are now added to the right of the field the error belongs to, so the buttons and everything gets moved to the right when theres an error.

@stveit stveit self-assigned this Oct 25, 2024
@hmpf

hmpf commented Oct 25, 2024

Copy link
Copy Markdown
Collaborator

Lookswise:

Having "Label", "Media", "Value" inside the same box as the actual changeable value looks terrible. I think the login form has the value on the outside.

There should be the rounded box around each if we want to have boxes, again see existing code.

I'm not sure the dropdowns are needed at all. We should not expect a zillion destinations per user.

The grey behind each box has to go. Too low contrast.

The "media" input in each box is redundant.

I think a header would look nicer than having one box for each type.

@hmpf

hmpf commented Oct 25, 2024

Copy link
Copy Markdown
Collaborator

Functions wise: make it work without HTMx first. Django has something called "formsets" you can use, see the abandoned code in #109 (which tries to do too much at once as well).

@hmpf

hmpf commented Oct 25, 2024

Copy link
Copy Markdown
Collaborator

DELETE and PATCH is API-stuff and htmx-stuff, not plain HTML. Make it work with plain HTML first.

@hmpf hmpf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good candidate for class based views actually. We should have a meeting.

Comment thread src/argus_htmx/destinations/forms.py Outdated
Comment thread src/argus_htmx/destinations/urls.py Outdated
Comment thread src/argus_htmx/destinations/views.py Outdated
Comment thread src/argus_htmx/destinations/urls.py Outdated
Comment thread src/argus_htmx/destinations/views.py Outdated
Comment thread src/argus_htmx/destinations/views.py Outdated
Comment thread src/argus_htmx/destinations/views.py Outdated
@stveit
stveit force-pushed the destinations branch 6 times, most recently from c293c0e to dc49e30 Compare October 31, 2024 12:43
@stveit
stveit marked this pull request as ready for review October 31, 2024 13:00
Comment thread src/argus_htmx/destinations/forms.py Outdated
Comment thread src/argus_htmx/destinations/forms.py
Comment thread src/argus_htmx/destinations/forms.py
Comment thread src/argus_htmx/destinations/forms.py
Comment thread src/argus_htmx/destinations/views.py Outdated
@hmpf
hmpf requested review from a team, hmpf and podliashanyk November 11, 2024 12:14

@hmpf hmpf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested it and it works except it's a bit confusing that when I edit/delete the url changes. Maybe redirect to "/destination/" after change? @podliashanyk might have a better idea.

Almost only renames following.

Comment thread src/argus_htmx/destinations/urls.py Outdated
Comment thread src/argus_htmx/destinations/views.py Outdated
Comment thread src/argus_htmx/destinations/views.py Outdated
Comment thread src/argus_htmx/destinations/views.py Outdated
Comment thread src/argus_htmx/destinations/views.py Outdated
)


def _get_settings_key_for_media(media: Media) -> str:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTS: should be in the destination plugin machinery.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As is, assumes that there is only one setting a user can set per plugin, which currently holds but might not in the future.

@stveit stveit Nov 26, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there should be a very clear way to ask the NotificationMedium where the email address or phone number etc is. Currently its a bit of a guess since there could be multiple required properties

Comment on lines +34 to +69
def _init_serializer(self):
serializer = RequestDestinationConfigSerializer(
data={
"media": self.cleaned_data["media"],
"label": self.cleaned_data.get("label", ""),
"settings": self.cleaned_data["settings"],
},
context={"request": self.request},
)
self.serializer = serializer

def _validate_serializer(self):
media = self.cleaned_data["media"]
settings_key = _get_settings_key_for_media(media)

# Add error messages from serializer to form
if not self.serializer.is_valid():
for error_name, error_detail in self.serializer.errors.items():
if error_name in ["media", "label", settings_key]:
if error_name == settings_key:
error_name = "settings"
self.add_error(error_name, error_detail)
# Serializer might add more data to the JSON dict
if settings := self.serializer.data.get("settings"):
self.cleaned_data["settings"] = settings
else:
# Serializer might add more data to the JSON dict
if settings := self.serializer.validated_data.get("settings"):
self.cleaned_data["settings"] = settings

if label := self.cleaned_data["label"]:
filter = DestinationConfig.objects.filter(label=label)
if self.instance:
filter = filter.exclude(pk=self.instance.pk)
if filter.exists():
self.add_error("label", "Name must be unique per media")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully all of this will go away when the plugins are changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤞

Comment thread src/argus_htmx/templates/htmx/destinations/destinations.html
Comment thread src/argus_htmx/templates/htmx/destinations/edit_or_delete_form.html Outdated
Comment thread src/argus_htmx/destinations/forms.py
@hmpf

hmpf commented Nov 11, 2024

Copy link
Copy Markdown
Collaborator

Ehh, and I almost forgot: media-field of the creation-form is bugged in "argus"-theme if the OS/browser is set to dark-mode:

image

Not a show-stopper but we ought to figure out how to fix it.

Pretty much copied from the destinations API, needs some changes
so it wont just crash to 500 when it raises a ValidationError

This commit doesnt make it show in the frontend, the button for
deleting a destination will be grouped with the forms for
updating destinations
Seems like a lot of changes .. but this is what the
wailwindcss script generated
@stveit

stveit commented Nov 27, 2024

Copy link
Copy Markdown
Contributor Author

I've tested it and it works except it's a bit confusing that when I edit/delete the url changes. Maybe redirect to "/destination/" after change? @podliashanyk might have a better idea.

I imagine HTMXifying this properly should fix this. Instead of loading the entire page when deleting, only the element containing the update/delete forms is updated etc.

Without HTMX: redirect works fine for deleting and updating when there is no error message, but when theres an error message you need the context from the delete/update view to show the error messages, in this case redirect feels bad

@hmpf

hmpf commented Nov 29, 2024

Copy link
Copy Markdown
Collaborator

Moved to argus-server

@hmpf hmpf closed this Nov 29, 2024
@hmpf
hmpf deleted the destinations branch February 11, 2025 08:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Make destinations-page

2 participants