Skip to content

Commit

Permalink
Closes #123: Introduce template tags for branch action buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Sep 13, 2024
1 parent b623e53 commit 76f5b67
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 36 deletions.
41 changes: 5 additions & 36 deletions netbox_branching/templates/netbox_branching/branch.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{% load plugins %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% load branch_buttons %}

{% block extra_controls %}
{% if not object.is_active %}
Expand All @@ -22,44 +23,12 @@
</a>
{% endif %}
{% if object.ready %}
{% if perms.netbox_branching.sync_branch %}
<a href="{% url 'plugins:netbox_branching:branch_sync' pk=object.pk %}" class="btn btn-primary">
<i class="mdi mdi-sync"></i> {% trans "Sync" %}
</a>
{% else %}
<button type="button" class="btn btn-primary disabled" aria-disabled="true">
<i class="mdi mdi-sync"></i> {% trans "Sync" %}
</button>
{% endif %}
{% if perms.netbox_branching.merge_branch %}
<a href="{% url 'plugins:netbox_branching:branch_merge' pk=object.pk %}" class="btn btn-primary">
<i class="mdi mdi-merge"></i> {% trans "Merge" %}
</a>
{% else %}
<button type="button" class="btn btn-primary disabled" aria-disabled="true">
<i class="mdi mdi-merge"></i> {% trans "Merge" %}
</button>
{% endif %}
{% branch_sync_button object %}
{% branch_merge_button object %}
{% endif %}
{% if object.merged %}
{% if perms.netbox_branching.revert_branch %}
<a href="{% url 'plugins:netbox_branching:branch_revert' pk=object.pk %}" class="btn btn-primary">
<i class="mdi mdi-arrow-u-left-top"></i> {% trans "Revert" %}
</a>
{% else %}
<button type="button" class="btn btn-primary disabled" aria-disabled="true">
<i class="mdi mdi-arrow-u-left-top"></i> {% trans "Revert" %}
</button>
{% endif %}
{% if perms.netbox_branching.archive_branch %}
<a href="{% url 'plugins:netbox_branching:branch_archive' pk=object.pk %}" class="btn btn-primary">
<i class="mdi mdi-archive-outline"></i> {% trans "Archive" %}
</a>
{% else %}
<button type="button" class="btn btn-primary disabled" aria-disabled="true">
<i class="mdi mdi-archive-outline"></i> {% trans "Archive" %}
</button>
{% endif %}
{% branch_revert_button object %}
{% branch_archive_button object %}
{% endif %}
{% endblock %}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load i18n %}
{% if perms.netbox_branching.archive_branch %}
<a href="{% url 'plugins:netbox_branching:branch_archive' pk=branch.pk %}" class="btn btn-primary">
<i class="mdi mdi-archive-outline"></i> {% trans "Archive" %}
</a>
{% else %}
<button type="button" class="btn btn-primary disabled" aria-disabled="true">
<i class="mdi mdi-archive-outline"></i> {% trans "Archive" %}
</button>
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load i18n %}
{% if perms.netbox_branching.merge_branch %}
<a href="{% url 'plugins:netbox_branching:branch_merge' pk=branch.pk %}" class="btn btn-primary">
<i class="mdi mdi-merge"></i> {% trans "Merge" %}
</a>
{% else %}
<button type="button" class="btn btn-primary disabled" aria-disabled="true">
<i class="mdi mdi-merge"></i> {% trans "Merge" %}
</button>
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load i18n %}
{% if perms.netbox_branching.revert_branch %}
<a href="{% url 'plugins:netbox_branching:branch_revert' pk=branch.pk %}" class="btn btn-primary">
<i class="mdi mdi-arrow-u-left-top"></i> {% trans "Revert" %}
</a>
{% else %}
<button type="button" class="btn btn-primary disabled" aria-disabled="true">
<i class="mdi mdi-arrow-u-left-top"></i> {% trans "Revert" %}
</button>
{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load i18n %}
{% if perms.netbox_branching.sync_branch %}
<a href="{% url 'plugins:netbox_branching:branch_sync' pk=branch.pk %}" class="btn btn-primary">
<i class="mdi mdi-sync"></i> {% trans "Sync" %}
</a>
{% else %}
<button type="button" class="btn btn-primary disabled" aria-disabled="true">
<i class="mdi mdi-sync"></i> {% trans "Sync" %}
</button>
{% endif %}
Empty file.
42 changes: 42 additions & 0 deletions netbox_branching/templatetags/branch_buttons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from django import template

__all__ = (
'branch_sync_button',
'branch_merge_button',
'branch_revert_button',
'branch_archive_button',
)

register = template.Library()


@register.inclusion_tag('netbox_branching/buttons/branch_sync.html', takes_context=True)
def branch_sync_button(context, branch):
return {
'branch': branch,
'perms': context.get('perms'),
}


@register.inclusion_tag('netbox_branching/buttons/branch_merge.html', takes_context=True)
def branch_merge_button(context, branch):
return {
'branch': branch,
'perms': context.get('perms'),
}


@register.inclusion_tag('netbox_branching/buttons/branch_revert.html', takes_context=True)
def branch_revert_button(context, branch):
return {
'branch': branch,
'perms': context.get('perms'),
}


@register.inclusion_tag('netbox_branching/buttons/branch_archive.html', takes_context=True)
def branch_archive_button(context, branch):
return {
'branch': branch,
'perms': context.get('perms'),
}

0 comments on commit 76f5b67

Please sign in to comment.