initial data model implementation

This commit is contained in:
2026-01-22 13:47:01 +01:00
parent bf2f9e9af7
commit c2436fab13
101 changed files with 2667 additions and 0 deletions
View File
+10
View File
@@ -0,0 +1,10 @@
/*
* This is a manifest file that'll be compiled into application.css.
*
* With Propshaft, assets are served efficiently without preprocessing steps. You can still include
* application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
* cascading order, meaning styles declared later in the document or manifest will override earlier ones,
* depending on specificity.
*
* Consider organizing styles into separate files for maintainability.
*/
@@ -0,0 +1,7 @@
class ApplicationController < ActionController::Base
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
allow_browser versions: :modern
# Changes to the importmap will invalidate the etag for HTML responses
stale_when_importmap_changes
end
View File
+2
View File
@@ -0,0 +1,2 @@
module ApplicationHelper
end
+7
View File
@@ -0,0 +1,7 @@
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
end
+4
View File
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
end
+3
View File
@@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
+6
View File
@@ -0,0 +1,6 @@
class Comment < ApplicationRecord
belongs_to :user
belongs_to :commentable, polymorphic: true
validates :body, presence: true
end
View File
+19
View File
@@ -0,0 +1,19 @@
class Entry < ApplicationRecord
belongs_to :created_by, class_name: "User", optional: true
belongs_to :updated_by, class_name: "User", optional: true
has_many :suggested_meanings, dependent: :destroy
has_many :comments, as: :commentable, dependent: :destroy
has_many :entry_versions, dependent: :destroy
enum category: {
word: 0,
phrase: 1,
name: 2,
title: 3,
reference: 4,
other: 5
}
validates :category, presence: true
end
+6
View File
@@ -0,0 +1,6 @@
class EntryVersion < ApplicationRecord
belongs_to :entry
belongs_to :user
validates :changes_made, presence: true
end
+18
View File
@@ -0,0 +1,18 @@
class SuggestedMeaning < ApplicationRecord
belongs_to :entry
belongs_to :submitted_by, class_name: "User"
belongs_to :reviewed_by, class_name: "User", optional: true
belongs_to :language,
class_name: "SupportedLanguage",
foreign_key: :language_code,
primary_key: :code
enum status: {
pending: 0,
accepted: 1,
rejected: 2
}
validates :language_code, presence: true
validates :alternative_translation, presence: true
end
+10
View File
@@ -0,0 +1,10 @@
class SupportedLanguage < ApplicationRecord
has_many :suggested_meanings,
foreign_key: :language_code,
primary_key: :code,
dependent: :restrict_with_exception
validates :code, presence: true, uniqueness: true
validates :name, presence: true
validates :native_name, presence: true
end
+27
View File
@@ -0,0 +1,27 @@
class User < ApplicationRecord
has_secure_password
belongs_to :invited_by, class_name: "User", optional: true
has_many :invited_users, class_name: "User", foreign_key: :invited_by_id, dependent: :nullify
has_many :created_entries, class_name: "Entry", foreign_key: :created_by_id, dependent: :nullify
has_many :updated_entries, class_name: "Entry", foreign_key: :updated_by_id, dependent: :nullify
has_many :submitted_suggested_meanings,
class_name: "SuggestedMeaning",
foreign_key: :submitted_by_id,
dependent: :nullify
has_many :reviewed_suggested_meanings,
class_name: "SuggestedMeaning",
foreign_key: :reviewed_by_id,
dependent: :nullify
has_many :entry_versions, dependent: :nullify
has_many :comments, dependent: :nullify
enum role: {
contributor: 0,
reviewer: 1,
admin: 2
}
validates :email, presence: true, uniqueness: true
end
+28
View File
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title><%= content_for(:title) || "Sanasto Wiki" %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="application-name" content="Sanasto Wiki">
<meta name="mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= yield :head %>
<%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %>
<%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %>
<link rel="icon" href="/icon.png" type="image/png">
<link rel="icon" href="/icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/icon.png">
<%# Includes all stylesheet files in app/assets/stylesheets %>
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
</head>
<body>
<%= yield %>
</body>
</html>
+13
View File
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%= yield %>
</body>
</html>
+1
View File
@@ -0,0 +1 @@
<%= yield %>
+22
View File
@@ -0,0 +1,22 @@
{
"name": "SanastoWiki",
"icons": [
{
"src": "/icon.png",
"type": "image/png",
"sizes": "512x512"
},
{
"src": "/icon.png",
"type": "image/png",
"sizes": "512x512",
"purpose": "maskable"
}
],
"start_url": "/",
"display": "standalone",
"scope": "/",
"description": "SanastoWiki.",
"theme_color": "red",
"background_color": "red"
}
+26
View File
@@ -0,0 +1,26 @@
// Add a service worker for processing Web Push notifications:
//
// self.addEventListener("push", async (event) => {
// const { title, options } = await event.data.json()
// event.waitUntil(self.registration.showNotification(title, options))
// })
//
// self.addEventListener("notificationclick", function(event) {
// event.notification.close()
// event.waitUntil(
// clients.matchAll({ type: "window" }).then((clientList) => {
// for (let i = 0; i < clientList.length; i++) {
// let client = clientList[i]
// let clientPath = (new URL(client.url)).pathname
//
// if (clientPath == event.notification.data.path && "focus" in client) {
// return client.focus()
// }
// }
//
// if (clients.openWindow) {
// return clients.openWindow(event.notification.data.path)
// }
// })
// )
// })