Browse Source

add mediation and cache

main
Christoph Marzell 3 weeks ago
parent
commit
0b66a0d431
  1. 2
      Gemfile
  2. 5
      Gemfile.lock
  3. 2
      app/models/entry.rb
  4. 2
      app/models/user.rb
  5. 18
      app/views/entries/index.html.erb
  6. 41
      app/views/layouts/application.html.erb
  7. 8
      config/environments/development.rb
  8. 4
      config/environments/production.rb
  9. 38
      docker-compose-dev.yml
  10. 12
      docker-compose.yml

2
Gemfile

@ -25,7 +25,7 @@ gem 'jquery-ui-rails'
# Use Sass to process CSS
gem "sassc-rails"
gem "redis"
# Use Redis adapter to run Action Cable in production
# gem "redis", ">= 4.0.1"

5
Gemfile.lock

@ -254,6 +254,10 @@ GEM
erb
psych (>= 4.0.0)
tsort
redis (5.4.1)
redis-client (>= 0.22.0)
redis-client (0.29.0)
connection_pool
reline (0.6.2)
io-console (~> 0.5)
responders (3.2.0)
@ -331,6 +335,7 @@ DEPENDENCIES
pghero
puma (>= 5.0)
rails (~> 7.1.5, >= 7.1.5.2)
redis
rufus-scheduler
sassc-rails
sprockets-rails

2
app/models/entry.rb

@ -10,7 +10,7 @@ class Entry < ApplicationRecord
before_save :normalize_time
PRAKTIKUMSTYPEN = %w[propädeutikum fachspezifikum]
PRAKTIKUMSTYPEN = %w[propädeutikum fachspezifikum mediation]
ENTRY_ARTEN = [
"Praktikum",
"Selbsterfahrung",

2
app/models/user.rb

@ -6,7 +6,7 @@ class User < ApplicationRecord
has_many :entries, dependent: :destroy
PRAKTIKUMSTYPEN = %w[propädeutikum fachspezifikum]
PRAKTIKUMSTYPEN = %w[propädeutikum fachspezifikum mediation]
ENTRY_ARTEN = [
"Praktikum",
"Selbsterfahrung",

18
app/views/entries/index.html.erb

@ -321,11 +321,19 @@
</td>
<td>
<% if entry.praktikums_typ != 'mediation' %>
<%= ["Fortbildung", "Semesterkosten"].include?(entry.entry_art) ? entry.entry_art : entry.praktikums_typ.capitalize %>
<% else %>
<%= entry.praktikums_typ&.capitalize%>
<% end %>
</td>
<td>
<%= ["Fortbildung", "Semesterkosten"].include?(entry.entry_art) ? entry.beschreibung : entry.entry_art.capitalize %>
<% if entry.praktikums_typ != 'mediation' %>
<%= ["Fortbildung", "Semesterkosten"].include?(entry.entry_art) ? entry.entry_art : entry.praktikums_typ.capitalize %>
<% else %>
<%= entry.praktikums_typ&.capitalize %>
<% end %>
</td>
<td>
@ -351,7 +359,13 @@
<td class="text-end">
<div class="d-flex justify-content-between gap-2">
<%= link_to 'Bearbeiten', edit_entry_path(entry), class: 'btn btn-sm btn-outline-primary' %>
<%= link_to 'Löschen', entry_path(entry), class: 'btn btn-sm btn-outline-danger open-delete-modal' %>
<button
type="button"
class="btn btn-sm btn-outline-danger open-delete-modal"
data-delete-url="<%= entry_path(entry) %>"
>
Löschen
</button>
</div>
</td>
</tr>

41
app/views/layouts/application.html.erb

@ -23,36 +23,29 @@
<script>
document.addEventListener('DOMContentLoaded', function () {
const modalElement = document.getElementById('deleteConfirmModal');
const modalInstance = bootstrap.Modal.getOrCreateInstance(modalElement);
(() => {
if (window.entryDeleteModalInitialized) return;
window.entryDeleteModalInitialized = true;
document.querySelectorAll('.open-delete-modal').forEach(button => {
button.addEventListener('click', function (e) {
e.preventDefault();
const targetUrl = this.getAttribute('href');
document.getElementById('modal-delete-form').setAttribute('action', targetUrl);
document.addEventListener("click", (event) => {
const button = event.target.closest(".open-delete-modal");
if (!button) return;
// Entferne diese Zeile:
// modalElement.removeAttribute("aria-hidden");
event.preventDefault();
modalInstance.show();
});
});
const deleteUrl = button.dataset.deleteUrl;
const form = document.getElementById("modal-delete-form");
const modalElement = document.getElementById("deleteConfirmModal");
modalElement.addEventListener('hidden.bs.modal', function () {
// Entferne überschüssige Klassen & Styles, falls Bootstrap sie hängen lässt
document.body.classList.remove('modal-open');
document.body.style.overflow = '';
document.body.style.paddingRight = '';
// Entferne eventuell verbliebene Backdrops
const backdrops = document.querySelectorAll('.modal-backdrop');
backdrops.forEach(b => b.parentNode.removeChild(b));
});
if (!deleteUrl || !form || !modalElement) return;
form.setAttribute("action", deleteUrl);
});
const modal = bootstrap.Modal.getOrCreateInstance(modalElement);
modal.show();
});
})();
</script>

8
config/environments/development.rb

@ -22,8 +22,12 @@ Rails.application.configure do
if Rails.root.join("tmp/caching-dev.txt").exist?
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true
config.cache_store = :memory_store
config.cache_store = :redis_cache_store, {
url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0"),
namespace: "myapp:dev:cache",
expires_in: 1.hour
}
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
}

4
config/environments/production.rb

@ -65,7 +65,9 @@ Rails.application.configure do
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
config.cache_store = :redis_cache_store, {
url: ENV.fetch("REDIS_URL", "redis://redis:6379/0")
}
# Use a real queuing backend for Active Job (and separate queues per environment).
# config.active_job.queue_adapter = :resque

38
docker-compose-dev.yml

@ -0,0 +1,38 @@
version: "3.3"
services:
db:
image: postgres:17
restart: unless-stopped
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: praktikum
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- '35432:35432'
healthcheck:
test: [ "CMD", "pg_isready", "-q" ]
timeout: 45s
interval: 10s
retries: 10
command: -p 35432
networks:
- praktikum-network
redis:
image: 'redis'
command: redis-server
volumes:
- 'redis:/data'
networks:
- praktikum-network
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- '6379:6379'
volumes:
pgdata:
redis:
networks:
praktikum-network:
driver: bridge

12
docker-compose.yml

@ -19,6 +19,17 @@ services:
command: -p 35432
networks:
- praktikum-network
redis:
image: 'redis'
command: redis-server
volumes:
- 'redis:/data'
networks:
- praktikum-network
environment:
- ALLOW_EMPTY_PASSWORD=yes
ports:
- '6379:6379'
web:
build: .
restart: unless-stopped
@ -38,6 +49,7 @@ services:
- praktikum-network
volumes:
pgdata:
redis:
networks:
praktikum-network:
driver: bridge
Loading…
Cancel
Save