edit.twig 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. {% extends 'layout.twig' %}
  2. {% block title %}{{ consumer.name }} — Consumer — IRDB{% endblock %}
  3. {% block content %}
  4. <div class="mx-auto max-w-3xl">
  5. <a href="/app/consumers" class="text-sm text-slate-500 hover:underline dark:text-slate-400">← Back to consumers</a>
  6. <h1 class="mt-3 text-2xl font-semibold tracking-tight font-mono">{{ consumer.name }}</h1>
  7. <form method="post" action="/app/consumers/{{ consumer.id }}" class="mt-6 rounded-2xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900">
  8. <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
  9. <div class="grid grid-cols-1 gap-3 md:grid-cols-2 text-sm">
  10. <div>
  11. <label for="c-name" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Name</label>
  12. <input type="text" id="c-name" name="name" value="{{ consumer.name }}" {% if not can_write %}readonly{% endif %}
  13. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 font-mono dark:border-slate-700 dark:bg-slate-950">
  14. </div>
  15. <div>
  16. <label for="c-policy" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Policy</label>
  17. <select id="c-policy" name="policy_id" {% if not can_write %}disabled{% endif %}
  18. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 dark:border-slate-700 dark:bg-slate-950">
  19. {% for p in policies %}
  20. <option value="{{ p.id }}" {% if consumer.policy_id == p.id %}selected{% endif %}>{{ p.name }}</option>
  21. {% endfor %}
  22. </select>
  23. </div>
  24. <div class="md:col-span-2">
  25. <label for="c-desc" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Description</label>
  26. <input type="text" id="c-desc" name="description" value="{{ consumer.description|default('') }}" {% if not can_write %}readonly{% endif %}
  27. class="mt-1 w-full rounded-md border border-slate-300 bg-white px-2 py-1.5 dark:border-slate-700 dark:bg-slate-950">
  28. </div>
  29. <div class="md:col-span-2">
  30. <label class="flex items-center gap-2 text-xs text-slate-600 dark:text-slate-400">
  31. <input type="checkbox" name="is_active" value="1" {% if consumer.is_active %}checked{% endif %} {% if not can_write %}disabled{% endif %}>
  32. active
  33. </label>
  34. </div>
  35. </div>
  36. {% if can_write %}
  37. <div class="mt-4 flex justify-end">
  38. <button type="submit" class="rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-indigo-500">Save</button>
  39. </div>
  40. {% endif %}
  41. </form>
  42. <section class="mt-8 overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900">
  43. <header class="flex items-center justify-between gap-3 border-b border-slate-200 px-5 py-3 dark:border-slate-800">
  44. <div>
  45. <h2 class="text-sm font-semibold tracking-tight">Last activity</h2>
  46. <p class="text-xs text-slate-500 dark:text-slate-400">10 most recent audit entries for this consumer.</p>
  47. </div>
  48. <a href="/app/audit?entity_type=consumer&amp;entity_id={{ consumer.id }}" class="whitespace-nowrap text-xs font-medium text-indigo-600 hover:underline dark:text-indigo-400">View all in audit log →</a>
  49. </header>
  50. {% if audit_items|default([])|length > 0 %}
  51. <div x-data="{ open: null }">
  52. <table class="w-full text-sm">
  53. <thead class="border-b border-slate-200 bg-slate-50 text-left text-xs uppercase tracking-wider text-slate-500 dark:border-slate-800 dark:bg-slate-950 dark:text-slate-400">
  54. <tr>
  55. <th class="px-5 py-2 font-medium">When</th>
  56. <th class="px-5 py-2 font-medium">Actor</th>
  57. <th class="px-5 py-2 font-medium">Action</th>
  58. <th class="px-5 py-2 text-right font-medium">Payload</th>
  59. </tr>
  60. </thead>
  61. <tbody class="divide-y divide-slate-100 dark:divide-slate-800">
  62. {% for ev in audit_items %}
  63. <tr>
  64. <td class="px-5 py-2 align-top"><time class="irdb-dt font-mono text-xs text-slate-600 dark:text-slate-300" datetime="{{ ev.occurred_at }}" title="{{ ev.occurred_at }}">{{ ev.occurred_at }}</time></td>
  65. <td class="px-5 py-2 align-top text-xs">
  66. <span class="rounded bg-slate-100 px-1.5 py-0.5 font-mono uppercase tracking-tight text-slate-700 dark:bg-slate-800 dark:text-slate-300">{{ ev.actor_kind }}</span>
  67. {% if ev.actor_id %}<span class="ml-1 font-mono text-slate-500">#{{ ev.actor_id }}</span>{% endif %}
  68. </td>
  69. <td class="px-5 py-2 align-top">
  70. <span class="inline-block rounded bg-cyan-100 px-2 py-0.5 font-mono text-[0.7rem] uppercase tracking-tight text-cyan-900 dark:bg-cyan-900 dark:text-cyan-100">{{ ev.action }}</span>
  71. </td>
  72. <td class="px-5 py-2 align-top text-right">
  73. {% if ev.details %}
  74. <button type="button" x-on:click="open = (open === {{ ev.id }} ? null : {{ ev.id }})" class="rounded border border-slate-300 px-2 py-0.5 text-xs hover:bg-slate-50 dark:border-slate-700 dark:hover:bg-slate-800">View</button>
  75. {% else %}
  76. <span class="text-xs text-slate-400">—</span>
  77. {% endif %}
  78. </td>
  79. </tr>
  80. {% if ev.details %}
  81. <tr x-show="open === {{ ev.id }}" x-cloak>
  82. <td colspan="4" class="bg-slate-50 px-5 py-3 dark:bg-slate-950">
  83. {% if ev.details.changes is defined and ev.details.changes is iterable and ev.details.changes|length > 0 %}
  84. <div class="mb-2 text-[0.7rem] font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400">Changes</div>
  85. <table class="w-full text-xs">
  86. <thead class="text-left text-[0.7rem] uppercase text-slate-500 dark:text-slate-400">
  87. <tr>
  88. <th class="px-2 py-1 font-medium">Field</th>
  89. <th class="px-2 py-1 font-medium">Before</th>
  90. <th class="px-2 py-1 font-medium">After</th>
  91. </tr>
  92. </thead>
  93. <tbody class="divide-y divide-slate-200 bg-white dark:divide-slate-800 dark:bg-slate-900">
  94. {% for field, change in ev.details.changes %}
  95. <tr>
  96. <td class="px-2 py-1 font-mono text-slate-700 dark:text-slate-200">{{ field }}</td>
  97. <td class="px-2 py-1 align-top">
  98. {% if change.from is null %}
  99. <span class="text-slate-400">∅</span>
  100. {% elseif change.from is iterable %}
  101. <pre class="overflow-x-auto rounded bg-rose-50 px-2 py-1 font-mono text-[0.7rem] text-rose-900 dark:bg-rose-950 dark:text-rose-200">{{ change.from|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
  102. {% else %}
  103. <span class="rounded bg-rose-50 px-1.5 py-0.5 font-mono text-rose-900 dark:bg-rose-950 dark:text-rose-200">{{ change.from }}</span>
  104. {% endif %}
  105. </td>
  106. <td class="px-2 py-1 align-top">
  107. {% if change.to is null %}
  108. <span class="text-slate-400">∅</span>
  109. {% elseif change.to is iterable %}
  110. <pre class="overflow-x-auto rounded bg-emerald-50 px-2 py-1 font-mono text-[0.7rem] text-emerald-900 dark:bg-emerald-950 dark:text-emerald-200">{{ change.to|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
  111. {% else %}
  112. <span class="rounded bg-emerald-50 px-1.5 py-0.5 font-mono text-emerald-900 dark:bg-emerald-950 dark:text-emerald-200">{{ change.to }}</span>
  113. {% endif %}
  114. </td>
  115. </tr>
  116. {% endfor %}
  117. </tbody>
  118. </table>
  119. {% else %}
  120. <pre class="overflow-x-auto rounded bg-white p-3 text-xs dark:bg-slate-900">{{ ev.details|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
  121. {% endif %}
  122. </td>
  123. </tr>
  124. {% endif %}
  125. {% endfor %}
  126. </tbody>
  127. </table>
  128. </div>
  129. {% else %}
  130. <p class="px-5 py-6 text-center text-sm text-slate-400">No activity yet.</p>
  131. {% endif %}
  132. </section>
  133. </div>
  134. {% endblock %}