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

Feature: More links on admin page #177

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions teknologr/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ def to_representation(self, instance):
'end_date': gm.group.end_date,
} for gm in instance.group_memberships.all()]

if self.is_staff:
data['membertypes'] = [{
'type': mt.type,
'begin_date': mt.begin_date,
'end_date': mt.end_date,
} for mt in instance.member_types.all()]

# Modify certain fields if necessary
if hide:
data['given_names'] = instance.get_given_names_with_initials()
Expand Down
14 changes: 12 additions & 2 deletions teknologr/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ def setUp(self):
GroupMembership.objects.create(group=g2, member=self.m2)
GroupMembership.objects.create(group=g2, member=self.m3)

self.mt = MemberType.objects.create(member=self.m1, type='OM', begin_date=d1)
self.mt = MemberType.objects.create(member=self.m1, type='PH', begin_date=d1)
MemberType.objects.create(member=self.m2, type='PH', begin_date=d1)
MemberType.objects.create(member=self.m3, type='PH', begin_date=d1)

self.a = Applicant.objects.create(
given_names='Märta',
Expand Down Expand Up @@ -244,6 +246,7 @@ def test_post_for_superuser(self):

# MEMBERS

# Always shown
MEMBER_PUBLIC = {
'id': int,
'given_names': str,
Expand All @@ -253,6 +256,7 @@ def test_post_for_superuser(self):
'n_groups': int,
'n_decorations': int,
}
# Shown if member is not hidden
MEMBER_PERSONAL = {
**MEMBER_PUBLIC,
'street_address': str,
Expand All @@ -266,6 +270,7 @@ def test_post_for_superuser(self):
'graduated': bool,
'graduated_year': int,
}
# Shown only to admins
MEMBER_ADMIN = {
**MEMBER_PERSONAL,
'created': str,
Expand Down Expand Up @@ -316,6 +321,11 @@ def test_post_for_superuser(self):
MEMBER_ADMIN_DETAIL = {
**MEMBER_ADMIN,
**MEMBER_DETAIL,
'membertypes': [{
'type': str,
'begin_date': str,
'end_date': (str, None),
}],
}

class MembersAPITest(BaseAPITest, GetAllMethodTests, PostMethodTests):
Expand Down Expand Up @@ -627,7 +637,7 @@ def setUp(self):
'created': str,
'modified': str,
}
self.n_all = 1
self.n_all = 3
self.post_data = {
'member': self.m2.id,
'type': 'OM',
Expand Down
32 changes: 31 additions & 1 deletion teknologr/members/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,36 @@ tr.active {
background-color: rgb(242, 242, 242);
}

.katalogen-link {
.clickable {
cursor: pointer;
}

/* Dropdown content, hidden by default */
.dropdown-content {
display: none;
position: absolute;
left: 0px;
top: 36px;
min-width: 160px;
z-index: 1;
border: #dddddd 1px solid;
}

/* Links inside the dropdown */
.dropdown-content a {
background-color: #ffffff;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #dddddd
}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
7 changes: 7 additions & 0 deletions teknologr/members/static/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ $(document).ready(function () {
placement : 'top'
});

/**
* Make elements function as clickable links.
*/
$(".clickable").click(function() {
window.location = $(this).data("href");
});

/**
* Populate modal for editing a decoration ownership.
* Can not be placed in functionary.js because it is needed on the member page too.
Expand Down
16 changes: 11 additions & 5 deletions teknologr/members/templates/decoration.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
{% load static %}

{% block main %}
<div class="container-fluid page-header">
<h1 class="list-inline-item"><a class="katalogen-link" href="{% url 'katalogen:decoration' decoration.id %}">{{ decoration.name }}</a></h1>
<i class="list-inline-item far fa-edit text-info align-self-center icon-20" role="button" title="Editera betygelse" data-toggle="modal" data-target="#edit-d-modal"></i>
<i id="delete-d-button" class="list-inline-item fas fa-times text-danger icon-20" role="button" title="Radera betygelse" data-id="{{ decoration.id }}"></i>
{% include "modals/decoration_edit.html" with modalname="edit-d-modal" title="Editera betygelse" form=edit_d_form decoration=decoration only %}
<div class="container-fluid">
<div class="row mb-2">
<div class="col-12">
<button class="btn btn-primary" title="Editera betygelse" data-toggle="modal" data-target="#edit-d-modal">Editera</button>
<button id="delete-d-button" class="btn btn-danger" title="Radera betygelse" data-id="{{ decoration.id }}">Radera</button>
<a class="btn btn-secondary" href="{% url 'katalogen:decoration' decoration.id %}">Katalogen</a>
<a class="btn btn-secondary" href="{% url 'api:decoration-detail' decoration.id %}">API</a>
{% include "modals/decoration_edit.html" with modalname="edit-d-modal" title="Editera betygelse" form=edit_d_form decoration=decoration only %}
</div>
</div>
<h1 class="page-header">{{ decoration.name }}</h1>
</div>


Expand Down
16 changes: 11 additions & 5 deletions teknologr/members/templates/functionary.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
{% load static %}

{% block main %}
<div class="container-fluid page-header">
<h1 class="list-inline-item"><a class="katalogen-link" href="{% url 'katalogen:functionary_type' functionary_type.id %}">{{ functionary_type.name }}</a></h1>
<i class="list-inline-item far fa-edit text-info align-self-center icon-20" role="button" title="Editera post" data-toggle="modal" data-target="#edit-ft-modal"></i>
<i id="delete-ft-button" class="list-inline-item fas fa-times text-danger icon-20" role="button" title="Radera post" data-id="{{ functionary_type.id }}"></i>
{% include "modals/functionarytype_edit.html" with modalname="edit-ft-modal" title="Editera post" form=edit_ft_form functionary_type=functionary_type only %}
<div class="container-fluid">
<div class="row mb-2">
<div class="col-12">
<button class="btn btn-primary" title="Editera post" data-toggle="modal" data-target="#edit-ft-modal">Editera</button>
<button id="delete-ft-button" class="btn btn-danger" title="Radera post" data-id="{{ functionary_type.id }}">Radera</button>
<a class="btn btn-secondary" href="{% url 'katalogen:functionary_type' functionary_type.id %}">Katalogen</a>
<a class="btn btn-secondary" href="{% url 'api:functionarytype-detail' functionary_type.id %}">API</a>
{% include "modals/functionarytype_edit.html" with modalname="edit-ft-modal" title="Editera post" form=edit_ft_form functionary_type=functionary_type only %}
</div>
</div>
<h1 class="page-header">{{ functionary_type.name }}</h1>
</div>

<div class="container-fluid">
Expand Down
35 changes: 28 additions & 7 deletions teknologr/members/templates/group.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,33 @@
{% load static %}

{% block main %}
<div class="container-fluid page-header">
<h1 class="list-inline-item"><a class="katalogen-link" href="{% url 'katalogen:groups' grouptype.id %}">{{ grouptype.name }}</a></h1>
<i class="list-inline-item far fa-edit text-info align-self-center icon-20" role="button" title="Editera grupp" data-toggle="modal" data-target="#edit-gt-modal"></i>
<i id="delete-gt-button" class="list-inline-item fas fa-times text-danger icon-20" role="button" title="Radera grupp" data-id="{{ grouptype.id }}"></i>
{% include "modals/grouptype_edit.html" with modalname="edit-gt-modal" title="Editera grupp" form=edit_gt_form grouptype=grouptype only %}
<div class="container-fluid">
<div class="row mb-2">
<div class="col-12">
<button class="btn btn-primary" title="Editera grupp" data-toggle="modal" data-target="#edit-gt-modal">Editera</button>
<button id="delete-gt-button" class="btn btn-danger" title="Radera grupp" data-id="{{ grouptype.id }}">Radera</button>
<div class="btn btn-secondary dropdown">
Katalogen <i class="fa fa-caret-down"></i>
<div class="dropdown-content">
<a href="{% url 'katalogen:groups' grouptype.id %}">Grupp</a>
<a href="{% url 'katalogen:group_memberships' grouptype.id %}">Gruppmedlemmar</a>
</div>
</div>
<div class="btn btn-secondary dropdown">
API <i class="fa fa-caret-down"></i>
<div class="dropdown-content">
<a href="{% url 'api:grouptype-detail' grouptype.id %}">Grupp</a>
<a href="{% url 'api:groupmembership-list' %}?group__grouptype__id={{ grouptype.id }}">Gruppmedlemmar</a>
<a href="{% url 'api:group-list' %}?grouptype__id={{ grouptype.id }}">Undergrupper</a>
{% if group %}
<a href="{% url 'api:group-detail' group.id %}">Undergrupp</a>
{% endif %}
</div>
</div>
{% include "modals/grouptype_edit.html" with modalname="edit-gt-modal" title="Editera grupp" form=edit_gt_form grouptype=grouptype only %}
</div>
</div>
<h1 class="page-header">{{ grouptype.name }}</h1>
</div>

<div class="container-fluid">
Expand Down Expand Up @@ -34,9 +56,8 @@ <h4 class="list-inline-item">Undergrupper</h4>
</thead>
<tbody>
{% for g in groups %}
<tr {% if group.id == g.id %} class="active" {% endif %}>
<tr class="clickable {% if group.id == g.id %} active {% endif %}" data-href="{% url 'admin:group' grouptype.id g.id %}">
<td>
<a href="{% url 'admin:group' grouptype.id g.id %}"><i class="far fa-eye text-info" title="Hantera undergrupp"></i></a>
<i class="fas fa-times delete-g-button text-danger" role="button" title="Radera undergrupp" data-id="{{ g.id }}" data-grouptype_id="{{ grouptype.id }}"></i>
</td>
<td class="text-center">{{ g.begin_date }}</td>
Expand Down