This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from technologiestiftung/feat/games-resource
feat: creating games and dice in UI
- Loading branch information
Showing
22 changed files
with
233 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module DieHelper | ||
def valid_die_values | ||
values = [] | ||
Die.titles.keys.each_with_index do |title, index| | ||
values << {title: title, shortcode: Die::VALID_SHORTCODES[index]} | ||
end | ||
values | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
|
||
export default class extends Controller { | ||
remove(event) { | ||
event.preventDefault(); | ||
this.element.remove(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
class Game < ApplicationRecord | ||
has_many :dice, dependent: :destroy | ||
has_many :sides, through: :dice | ||
accepts_nested_attributes_for :dice | ||
|
||
validates :title, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<%= form_with(model: game, class: "grid gap-6 grid-cols-3 items-start") do |form| %> | ||
<div class="col-span-3 grid gap-y-1"> | ||
<%= form.label :title, "Titel des Spiels" %> | ||
<%= form.text_field :title, class: "w-full" %> | ||
<% if game.errors.key?(:title) %> | ||
<ul class="text-danger mt-1"> | ||
<% game.errors.full_messages_for(:title).each do |error_message| %> | ||
<%= tag.li class: "text-warning" do %> | ||
⚠ <%= error_message %> | ||
<% end %> | ||
<% end %> | ||
</ul> | ||
<% end %> | ||
</div> | ||
|
||
<% valid_die_values.each_with_index do |obj, index| %> | ||
<%= tag.div class: "grid gap-y-6" do %> | ||
<%= form.fields_for "dice_attributes[#{index + 1}]", Die.new do |die_form| %> | ||
<%= die_form.hidden_field :title, value: obj[:title] %> | ||
<%= die_form.hidden_field :shortcode, value: obj[:shortcode] %> | ||
|
||
<%= tag.div class: "scale-75" do %> | ||
<%= render DieComponent.new(theme: obj[:title]) do %> | ||
<%= obj[:title] %> | ||
<% end %> | ||
<% end %> | ||
|
||
<% 6.times do |index| %> | ||
<%= die_form.fields_for "sides_attributes[#{index + 1}]", Side.new do |sides_form| %> | ||
<%= tag.div class: "grid" do %> | ||
<%= sides_form.label :title, "Sichtbares Label", class: class_names("sr-only", {"not-sr-only": index == 0}) %> | ||
<%= sides_form.text_field :title, class: "w-full" %> | ||
<%= sides_form.hidden_field :shortcode, value: index + 1 %> | ||
<details class="pt-1 pb-3 px-3 open:bg-gray-100"> | ||
<summary class="text-gray-700">Abweichende Begriffe?</summary> | ||
<div class="mt-3"> | ||
<%= sides_form.text_field :variations, class: "w-full", aria_describedby: "variationsHint" %> | ||
<%= tag.span "Bitte separariert mit Semikolon (;)", id: "variationsHint", class: "text-sm" %> | ||
<%= tag.p "Nur nötig, wenn du andere Begriffe als das sichtbare Label für die Ideengenerierung benutzen willst.", class: "mt-2 text-sm" %> | ||
<%= tag.p "Beispiel 1: Das sichtbare Label ist \"?\", soll aber nicht zur Ideengenerierung benutzt werden. Dann trage unten bitte etwas ein wie z.B. \"Begriff A;Begriff B;Begriff C\" (ohne Anführungszeichen)", class: "mt-2 text-sm" %> | ||
<%= tag.p "Beispiel 2: Das sichtbare Label ist \"Berliner:innen\", du möchtest aber zusätzlich \"Berliner\" und \"Berlinerinnen\" als mögliche Option. Dann trage unten bitte ein: \"Berliner:innen;Berliner;Berlinerinnen\" (ohne Anführungszeichen)", class: "mt-2 text-sm" %> | ||
</div> | ||
</details> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
|
||
<div class="col-span-3 justify-self-end"> | ||
<%= form.submit "Spiel erstellen", class: "bg-gray-900 text-white p-3 uppercase font-bold cursor-pointer" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ | |
<% end %> | ||
<% end %> | ||
<% end %> | ||
<%= link_to "Neues Spiel anlegen", new_game_path, class: "underline" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<%= tag.div class: class_names("w-full max-w-screen-lg mx-auto", "px-8 pt-0", "grid gap-y-10") do %> | ||
<%= tag.div class: "flex gap-x-3 items-center" do %> | ||
<%= tag.h1 "Neues Spiel anlegen", class: "text-5xl font-bold" %> | ||
<%= tag.span "Beta", class: "h-min border-4 px-2 py-1 border-gray-900 font-bold uppercase" %> | ||
<% end %> | ||
<%= render "form", game: @game %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class MakeGameRequiredForDie < ActiveRecord::Migration[7.0] | ||
def change | ||
change_column_null :dice, :game_id, false | ||
remove_index :dice, :shortcode | ||
remove_index :dice, :game_id | ||
add_index :dice, [:shortcode, :game_id], unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ollers/raspi/shutdowns_controller_test.rb → test/controllers/raspi_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ five: | |
six: | ||
title: "medium" | ||
shortcode: "C" | ||
game: autumn | ||
game: autumn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters