index.twig 5.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. {% extends 'layout.twig' %}
  2. {% block title %}Consumers — IRDB{% endblock %}
  3. {% block content %}
  4. {% import 'partials/sort.twig' as sort %}
  5. {% set policy_name_by_id = {} %}
  6. {% for p in policies %}
  7. {% set policy_name_by_id = policy_name_by_id|merge({(p.id): p.name}) %}
  8. {% endfor %}
  9. <div class="mx-auto max-w-5xl">
  10. <div class="flex items-center justify-between">
  11. <h1 class="text-2xl font-semibold tracking-tight">Consumers</h1>
  12. <span class="text-sm text-slate-500 dark:text-slate-400">{{ list.total|default(0) }} total</span>
  13. </div>
  14. {% if can_write %}
  15. <section class="mt-6 rounded-2xl border border-slate-200 bg-white p-5 shadow-sm dark:border-slate-800 dark:bg-slate-900">
  16. <h2 class="text-sm font-semibold uppercase tracking-wider text-slate-500 dark:text-slate-400">New consumer</h2>
  17. <form method="post" action="/app/consumers" class="mt-3 grid grid-cols-1 gap-3 md:grid-cols-3 text-sm">
  18. <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
  19. <div>
  20. <label for="c-name" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Name</label>
  21. <input type="text" id="c-name" name="name" required
  22. 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">
  23. </div>
  24. <div>
  25. <label for="c-policy" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Policy</label>
  26. <select id="c-policy" name="policy_id" required
  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. <option value="">— pick one —</option>
  29. {% for p in policies %}
  30. <option value="{{ p.id }}">{{ p.name }}</option>
  31. {% endfor %}
  32. </select>
  33. </div>
  34. <div>
  35. <label for="c-desc" class="block text-xs font-medium text-slate-600 dark:text-slate-400">Description</label>
  36. <input type="text" id="c-desc" name="description"
  37. 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">
  38. </div>
  39. <div class="md:col-span-3 flex justify-end">
  40. <button type="submit" class="rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-indigo-500">Create</button>
  41. </div>
  42. </form>
  43. </section>
  44. {% endif %}
  45. <section class="mt-6 overflow-hidden rounded-2xl border border-slate-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900">
  46. <table class="w-full text-sm" data-sortable-table="consumers-index">
  47. <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">
  48. <tr>
  49. {{ sort.th('Name', 'name') }}
  50. {{ sort.th('Policy', 'policy') }}
  51. {{ sort.th('Description', 'description') }}
  52. {{ sort.th('Status', 'status') }}
  53. {% if can_write %}<th class="px-4 py-2 text-right font-medium">Actions</th>{% endif %}
  54. </tr>
  55. </thead>
  56. <tbody class="divide-y divide-slate-100 dark:divide-slate-800">
  57. {% for c in list.data|default([]) %}
  58. <tr>
  59. <td class="px-4 py-2" data-sort-value="{{ c.name }}"><a href="/app/consumers/{{ c.id }}" class="font-mono text-indigo-600 hover:underline dark:text-indigo-400">{{ c.name }}</a></td>
  60. <td class="px-4 py-2 font-mono text-slate-600 dark:text-slate-300" data-sort-value="{{ policy_name_by_id[c.policy_id]|default('') }}">{{ policy_name_by_id[c.policy_id]|default('?') }}</td>
  61. <td class="px-4 py-2 text-slate-600 dark:text-slate-300" data-sort-value="{{ c.description|default('') }}">{{ c.description|default('—') }}</td>
  62. <td class="px-4 py-2" data-sort-value="{{ c.is_active ? 'active' : 'inactive' }}">
  63. {% if c.is_active %}
  64. <span class="rounded bg-emerald-100 px-1.5 py-0.5 text-xs uppercase text-emerald-800 dark:bg-emerald-900 dark:text-emerald-100">active</span>
  65. {% else %}
  66. <span class="rounded bg-slate-100 px-1.5 py-0.5 text-xs uppercase text-slate-600 dark:bg-slate-800 dark:text-slate-400">inactive</span>
  67. {% endif %}
  68. </td>
  69. {% if can_write %}
  70. <td class="px-4 py-2 text-right">
  71. <a href="/app/consumers/{{ c.id }}" class="mr-2 text-xs text-indigo-600 hover:underline dark:text-indigo-400">Edit</a>
  72. {% if c.is_active %}
  73. {% include 'partials/confirm_form.twig' with {
  74. action: '/app/consumers/' ~ c.id ~ '/delete',
  75. label: 'Deactivate',
  76. description: 'Soft-delete this consumer.',
  77. } only %}
  78. {% endif %}
  79. </td>
  80. {% endif %}
  81. </tr>
  82. {% else %}
  83. <tr><td colspan="5" class="px-4 py-6 text-center text-slate-400">No consumers.</td></tr>
  84. {% endfor %}
  85. </tbody>
  86. </table>
  87. </section>
  88. </div>
  89. {% endblock %}