mirror of
https://github.com/netbox-community/netbox.git
synced 2025-09-06 06:13:36 -06:00
feat(core): Add Sync button for DataSource actions
Introduces a sync button in the DataSource table for improved user interaction. Enables users to trigger sync actions directly from the table, with context-sensitive availability based on permissions and record status. Closes #19547
This commit is contained in:
parent
545773e221
commit
3b4894cfae
@ -4,6 +4,7 @@ import django_tables2 as tables
|
|||||||
from core.models import *
|
from core.models import *
|
||||||
from netbox.tables import NetBoxTable, columns
|
from netbox.tables import NetBoxTable, columns
|
||||||
from .columns import BackendTypeColumn
|
from .columns import BackendTypeColumn
|
||||||
|
from .template_code import DATA_SOURCE_SYNC_BUTTONS
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'DataFileTable',
|
'DataFileTable',
|
||||||
@ -37,6 +38,9 @@ class DataSourceTable(NetBoxTable):
|
|||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='core:datasource_list',
|
url_name='core:datasource_list',
|
||||||
)
|
)
|
||||||
|
actions = columns.ActionsColumn(
|
||||||
|
extra_buttons=DATA_SOURCE_SYNC_BUTTONS,
|
||||||
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(NetBoxTable.Meta):
|
||||||
model = DataSource
|
model = DataSource
|
||||||
|
@ -26,3 +26,21 @@ PLUGIN_IS_INSTALLED = """
|
|||||||
<span class="text-muted">—</span>
|
<span class="text-muted">—</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
DATA_SOURCE_SYNC_BUTTONS = """
|
||||||
|
{% load helpers %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% if perms.core.sync_datasource %}
|
||||||
|
{% if record.ready_for_sync %}
|
||||||
|
<button type="submit" class="btn btn-primary btn-sm" formaction="{% url 'core:datasource_sync' pk=record.pk %}?return_url={{ request.get_full_path|urlencode }}" formmethod="post">
|
||||||
|
<i class="mdi mdi-sync" aria-hidden="true"></i> {% trans "Sync" %}
|
||||||
|
</button>
|
||||||
|
{% else %}
|
||||||
|
<span class="inline-block" tabindex="0" data-bs-toggle="tooltip" data-bs-delay="100" data-bs-placement="bottom">
|
||||||
|
<button class="btn btn-primary" disabled>
|
||||||
|
<i class="mdi mdi-sync" aria-hidden="true"></i> {% trans "Sync" %}
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
"""
|
||||||
|
@ -85,6 +85,8 @@ class DataSourceSyncView(BaseObjectView):
|
|||||||
request,
|
request,
|
||||||
_("Queued job #{id} to sync {datasource}").format(id=job.pk, datasource=datasource)
|
_("Queued job #{id} to sync {datasource}").format(id=job.pk, datasource=datasource)
|
||||||
)
|
)
|
||||||
|
if return_url := request.POST.get('return_url'):
|
||||||
|
return redirect(return_url)
|
||||||
return redirect(datasource.get_absolute_url())
|
return redirect(datasource.get_absolute_url())
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user