15 changed files with 523 additions and 126 deletions
@ -0,0 +1,21 @@ |
|||||
|
# All Administrate controllers inherit from this |
||||
|
# `Administrate::ApplicationController`, making it the ideal place to put |
||||
|
# authentication logic or other before_actions. |
||||
|
# |
||||
|
# If you want to add pagination or other controller-level concerns, |
||||
|
# you're free to overwrite the RESTful controller actions. |
||||
|
module Admin |
||||
|
class ApplicationController < Administrate::ApplicationController |
||||
|
before_action :authenticate_admin |
||||
|
|
||||
|
def authenticate_admin |
||||
|
redirect_to root_path, alert: "Kein Zugriff!" unless current_user.email =="christoph@marzell.net" |
||||
|
end |
||||
|
|
||||
|
# Override this value to specify the number of elements to display at a time |
||||
|
# on index pages. Defaults to 20. |
||||
|
# def records_per_page |
||||
|
# params[:per_page] || 20 |
||||
|
# end |
||||
|
end |
||||
|
end |
||||
@ -0,0 +1,46 @@ |
|||||
|
module Admin |
||||
|
class EntriesController < Admin::ApplicationController |
||||
|
# Overwrite any of the RESTful controller actions to implement custom behavior |
||||
|
# For example, you may want to send an email after a foo is updated. |
||||
|
# |
||||
|
# def update |
||||
|
# super |
||||
|
# send_foo_updated_email(requested_resource) |
||||
|
# end |
||||
|
|
||||
|
# Override this method to specify custom lookup behavior. |
||||
|
# This will be used to set the resource for the `show`, `edit`, and `update` |
||||
|
# actions. |
||||
|
# |
||||
|
# def find_resource(param) |
||||
|
# Foo.find_by!(slug: param) |
||||
|
# end |
||||
|
|
||||
|
# The result of this lookup will be available as `requested_resource` |
||||
|
|
||||
|
# Override this if you have certain roles that require a subset |
||||
|
# this will be used to set the records shown on the `index` action. |
||||
|
# |
||||
|
# def scoped_resource |
||||
|
# if current_user.super_admin? |
||||
|
# resource_class |
||||
|
# else |
||||
|
# resource_class.with_less_stuff |
||||
|
# end |
||||
|
# end |
||||
|
|
||||
|
# Override `resource_params` if you want to transform the submitted |
||||
|
# data before it's persisted. For example, the following would turn all |
||||
|
# empty values into nil values. It uses other APIs such as `resource_class` |
||||
|
# and `dashboard`: |
||||
|
# |
||||
|
# def resource_params |
||||
|
# params.require(resource_class.model_name.param_key). |
||||
|
# permit(dashboard.permitted_attributes(action_name)). |
||||
|
# transform_values { |value| value == "" ? nil : value } |
||||
|
# end |
||||
|
|
||||
|
# See https://administrate-demo.herokuapp.com/customizing_controller_actions |
||||
|
# for more information |
||||
|
end |
||||
|
end |
||||
@ -0,0 +1,46 @@ |
|||||
|
module Admin |
||||
|
class UsersController < Admin::ApplicationController |
||||
|
# Overwrite any of the RESTful controller actions to implement custom behavior |
||||
|
# For example, you may want to send an email after a foo is updated. |
||||
|
# |
||||
|
# def update |
||||
|
# super |
||||
|
# send_foo_updated_email(requested_resource) |
||||
|
# end |
||||
|
|
||||
|
# Override this method to specify custom lookup behavior. |
||||
|
# This will be used to set the resource for the `show`, `edit`, and `update` |
||||
|
# actions. |
||||
|
# |
||||
|
# def find_resource(param) |
||||
|
# Foo.find_by!(slug: param) |
||||
|
# end |
||||
|
|
||||
|
# The result of this lookup will be available as `requested_resource` |
||||
|
|
||||
|
# Override this if you have certain roles that require a subset |
||||
|
# this will be used to set the records shown on the `index` action. |
||||
|
# |
||||
|
# def scoped_resource |
||||
|
# if current_user.super_admin? |
||||
|
# resource_class |
||||
|
# else |
||||
|
# resource_class.with_less_stuff |
||||
|
# end |
||||
|
# end |
||||
|
|
||||
|
# Override `resource_params` if you want to transform the submitted |
||||
|
# data before it's persisted. For example, the following would turn all |
||||
|
# empty values into nil values. It uses other APIs such as `resource_class` |
||||
|
# and `dashboard`: |
||||
|
# |
||||
|
# def resource_params |
||||
|
# params.require(resource_class.model_name.param_key). |
||||
|
# permit(dashboard.permitted_attributes(action_name)). |
||||
|
# transform_values { |value| value == "" ? nil : value } |
||||
|
# end |
||||
|
|
||||
|
# See https://administrate-demo.herokuapp.com/customizing_controller_actions |
||||
|
# for more information |
||||
|
end |
||||
|
end |
||||
@ -0,0 +1,81 @@ |
|||||
|
require "administrate/base_dashboard" |
||||
|
|
||||
|
class EntryDashboard < Administrate::BaseDashboard |
||||
|
# ATTRIBUTE_TYPES |
||||
|
# a hash that describes the type of each of the model's fields. |
||||
|
# |
||||
|
# Each different type represents an Administrate::Field object, |
||||
|
# which determines how the attribute is displayed |
||||
|
# on pages throughout the dashboard. |
||||
|
ATTRIBUTE_TYPES = { |
||||
|
id: Field::Number, |
||||
|
date: Field::Date, |
||||
|
distance_km: Field::Number, |
||||
|
entry_art: Field::String, |
||||
|
hours: Field::Number, |
||||
|
minutes: Field::Number, |
||||
|
praktikums_typ: Field::String, |
||||
|
user: Field::BelongsTo, |
||||
|
created_at: Field::DateTime, |
||||
|
updated_at: Field::DateTime, |
||||
|
}.freeze |
||||
|
|
||||
|
# COLLECTION_ATTRIBUTES |
||||
|
# an array of attributes that will be displayed on the model's index page. |
||||
|
# |
||||
|
# By default, it's limited to four items to reduce clutter on index pages. |
||||
|
# Feel free to add, remove, or rearrange items. |
||||
|
COLLECTION_ATTRIBUTES = %i[ |
||||
|
id |
||||
|
date |
||||
|
distance_km |
||||
|
entry_art |
||||
|
].freeze |
||||
|
|
||||
|
# SHOW_PAGE_ATTRIBUTES |
||||
|
# an array of attributes that will be displayed on the model's show page. |
||||
|
SHOW_PAGE_ATTRIBUTES = %i[ |
||||
|
id |
||||
|
date |
||||
|
distance_km |
||||
|
entry_art |
||||
|
hours |
||||
|
minutes |
||||
|
praktikums_typ |
||||
|
user |
||||
|
created_at |
||||
|
updated_at |
||||
|
].freeze |
||||
|
|
||||
|
# FORM_ATTRIBUTES |
||||
|
# an array of attributes that will be displayed |
||||
|
# on the model's form (`new` and `edit`) pages. |
||||
|
FORM_ATTRIBUTES = %i[ |
||||
|
date |
||||
|
distance_km |
||||
|
entry_art |
||||
|
hours |
||||
|
minutes |
||||
|
praktikums_typ |
||||
|
user |
||||
|
].freeze |
||||
|
|
||||
|
# COLLECTION_FILTERS |
||||
|
# a hash that defines filters that can be used while searching via the search |
||||
|
# field of the dashboard. |
||||
|
# |
||||
|
# For example to add an option to search for open resources by typing "open:" |
||||
|
# in the search field: |
||||
|
# |
||||
|
# COLLECTION_FILTERS = { |
||||
|
# open: ->(resources) { resources.where(open: true) } |
||||
|
# }.freeze |
||||
|
COLLECTION_FILTERS = {}.freeze |
||||
|
|
||||
|
# Overwrite this method to customize how entries are displayed |
||||
|
# across all pages of the admin dashboard. |
||||
|
# |
||||
|
# def display_resource(entry) |
||||
|
# "Entry ##{entry.id}" |
||||
|
# end |
||||
|
end |
||||
@ -0,0 +1,90 @@ |
|||||
|
require "administrate/base_dashboard" |
||||
|
|
||||
|
class UserDashboard < Administrate::BaseDashboard |
||||
|
# ATTRIBUTE_TYPES |
||||
|
# a hash that describes the type of each of the model's fields. |
||||
|
# |
||||
|
# Each different type represents an Administrate::Field object, |
||||
|
# which determines how the attribute is displayed |
||||
|
# on pages throughout the dashboard. |
||||
|
ATTRIBUTE_TYPES = { |
||||
|
id: Field::Number, |
||||
|
email: Field::String, |
||||
|
encrypted_password: Field::String, |
||||
|
entries: Field::HasMany, |
||||
|
remember_created_at: Field::DateTime, |
||||
|
required_hours_matrix: Field::String.with_options(searchable: false), |
||||
|
reset_password_sent_at: Field::DateTime, |
||||
|
reset_password_token: Field::String, |
||||
|
total_required_hours: Field::Number, |
||||
|
weekly_target_hours: Field::Number, |
||||
|
weekly_target_matrix: Field::String.with_options(searchable: false), |
||||
|
created_at: Field::DateTime, |
||||
|
updated_at: Field::DateTime, |
||||
|
}.freeze |
||||
|
|
||||
|
# COLLECTION_ATTRIBUTES |
||||
|
# an array of attributes that will be displayed on the model's index page. |
||||
|
# |
||||
|
# By default, it's limited to four items to reduce clutter on index pages. |
||||
|
# Feel free to add, remove, or rearrange items. |
||||
|
COLLECTION_ATTRIBUTES = %i[ |
||||
|
id |
||||
|
email |
||||
|
encrypted_password |
||||
|
entries |
||||
|
].freeze |
||||
|
|
||||
|
# SHOW_PAGE_ATTRIBUTES |
||||
|
# an array of attributes that will be displayed on the model's show page. |
||||
|
SHOW_PAGE_ATTRIBUTES = %i[ |
||||
|
id |
||||
|
email |
||||
|
encrypted_password |
||||
|
entries |
||||
|
remember_created_at |
||||
|
required_hours_matrix |
||||
|
reset_password_sent_at |
||||
|
reset_password_token |
||||
|
total_required_hours |
||||
|
weekly_target_hours |
||||
|
weekly_target_matrix |
||||
|
created_at |
||||
|
updated_at |
||||
|
].freeze |
||||
|
|
||||
|
# FORM_ATTRIBUTES |
||||
|
# an array of attributes that will be displayed |
||||
|
# on the model's form (`new` and `edit`) pages. |
||||
|
FORM_ATTRIBUTES = %i[ |
||||
|
email |
||||
|
encrypted_password |
||||
|
entries |
||||
|
remember_created_at |
||||
|
required_hours_matrix |
||||
|
reset_password_sent_at |
||||
|
reset_password_token |
||||
|
total_required_hours |
||||
|
weekly_target_hours |
||||
|
weekly_target_matrix |
||||
|
].freeze |
||||
|
|
||||
|
# COLLECTION_FILTERS |
||||
|
# a hash that defines filters that can be used while searching via the search |
||||
|
# field of the dashboard. |
||||
|
# |
||||
|
# For example to add an option to search for open resources by typing "open:" |
||||
|
# in the search field: |
||||
|
# |
||||
|
# COLLECTION_FILTERS = { |
||||
|
# open: ->(resources) { resources.where(open: true) } |
||||
|
# }.freeze |
||||
|
COLLECTION_FILTERS = {}.freeze |
||||
|
|
||||
|
# Overwrite this method to customize how users are displayed |
||||
|
# across all pages of the admin dashboard. |
||||
|
# |
||||
|
# def display_resource(user) |
||||
|
# "User ##{user.id}" |
||||
|
# end |
||||
|
end |
||||
@ -1,36 +1,53 @@ |
|||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> |
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/themes/material_blue.css"> |
|
||||
<!-- Bootstrap CSS (optional, falls noch nicht eingebunden) --> |
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> |
|
||||
|
<head> |
||||
|
<meta charset="utf-8"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
|
<title>Praktikumsuhr</title> |
||||
|
|
||||
<!-- Bootstrap Bundle JS (inkl. Popper & Modal Support) --> |
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" defer></script> |
|
||||
|
<!-- Bootstrap CSS --> |
||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"> |
||||
|
|
||||
|
<!-- Flatpickr Theme --> |
||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/themes/material_blue.css"> |
||||
|
|
||||
|
<!-- Custom Styles (optional) --> |
||||
|
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> |
||||
|
|
||||
|
<!-- JS: Bootstrap Bundle (inkl. Popper) --> |
||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" defer></script> |
||||
|
|
||||
|
|
||||
|
<!-- Flatpickr JS --> |
||||
|
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script> |
||||
|
|
||||
|
<!-- JS: Flatpickr Init --> |
||||
|
<script defer> |
||||
|
document.addEventListener("DOMContentLoaded", function () { |
||||
|
flatpickr(".flatpickr", { |
||||
|
altInput: true, |
||||
|
altFormat: "d.m.Y", |
||||
|
dateFormat: "Y-m-d" |
||||
|
}); |
||||
|
}); |
||||
|
</script> |
||||
|
|
||||
|
<!-- JavaScript from Rails --> |
||||
|
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> |
||||
|
</head> |
||||
|
|
||||
<%= javascript_include_tag "application.js", "data-turbo-track": "reload", defer: true %> |
|
||||
|
|
||||
|
|
||||
<body class="container mt-4"> |
<body class="container mt-4"> |
||||
<% if notice %><div class="alert alert-success"><%= notice %></div><% end %> |
<% if notice %><div class="alert alert-success"><%= notice %></div><% end %> |
||||
<% if alert %><div class="alert alert-danger"><%= alert %></div><% end %> |
<% if alert %><div class="alert alert-danger"><%= alert %></div><% end %> |
||||
|
|
||||
<!-- Flatpickr JS --> |
|
||||
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script> |
|
||||
<% if user_signed_in? %> |
<% if user_signed_in? %> |
||||
<p class="text-end"> |
<p class="text-end"> |
||||
Eingeloggt als <%= current_user.email %> | |
Eingeloggt als <%= current_user.email %> | |
||||
<%= link_to "Profil", edit_user_registration_path %> | |
<%= link_to "Profil", edit_user_registration_path %> | |
||||
|
<%= link_to "Admin", admin_root_path %> | |
||||
<%= link_to "Logout", destroy_user_session_path, method: :delete, data: { turbo: false } %> |
<%= link_to "Logout", destroy_user_session_path, method: :delete, data: { turbo: false } %> |
||||
</p> |
</p> |
||||
<% end %> |
<% end %> |
||||
|
|
||||
<%= yield %> |
<%= yield %> |
||||
</body> |
</body> |
||||
<script> |
|
||||
document.addEventListener("DOMContentLoaded", function() { |
|
||||
flatpickr(".flatpickr", { |
|
||||
altInput: true, |
|
||||
altFormat: "d.m.Y", |
|
||||
dateFormat: "Y-m-d" |
|
||||
}); |
|
||||
}); |
|
||||
</script> |
|
||||
Loading…
Reference in new issue