Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add destinations page #205

Closed
wants to merge 9 commits into from
Closed

Add destinations page #205

wants to merge 9 commits into from

Conversation

stveit
Copy link
Contributor

@stveit stveit commented Oct 25, 2024

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
Copy link
Collaborator

hmpf commented Oct 25, 2024

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
Copy link
Collaborator

hmpf commented Oct 25, 2024

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
Copy link
Collaborator

hmpf commented Oct 25, 2024

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

Copy link
Collaborator

@hmpf hmpf left a comment

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.

src/argus_htmx/destinations/forms.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/urls.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/views.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/urls.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/views.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/views.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/views.py Outdated Show resolved Hide resolved
@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
src/argus_htmx/destinations/forms.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/forms.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/forms.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/forms.py Outdated Show resolved Hide resolved
@hmpf hmpf requested review from podliashanyk, a team and hmpf November 11, 2024 12:14
Copy link
Collaborator

@hmpf hmpf left a comment

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.

src/argus_htmx/destinations/urls.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/views.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/views.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/views.py Outdated Show resolved Hide resolved
src/argus_htmx/destinations/views.py Outdated Show resolved Hide resolved
)


def _get_settings_key_for_media(media: Media) -> str:
Copy link
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
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.

Copy link
Contributor Author

@stveit stveit Nov 26, 2024

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
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
Contributor Author

Choose a reason for hiding this comment

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

🤞

src/argus_htmx/destinations/forms.py Outdated Show resolved Hide resolved
@hmpf
Copy link
Collaborator

hmpf commented Nov 11, 2024

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
Copy link
Contributor Author

stveit commented Nov 27, 2024

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
Copy link
Collaborator

hmpf commented Nov 29, 2024

Moved to argus-server

@hmpf hmpf closed this Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Make destinations-page
2 participants