index.twig 5.6 KB

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