Skip to content

Commit

Permalink
Copy other sites
Browse files Browse the repository at this point in the history
  • Loading branch information
naofumi committed Sep 8, 2024
1 parent 04c11c2 commit f9e8e5c
Show file tree
Hide file tree
Showing 54 changed files with 754 additions and 34 deletions.
1 change: 1 addition & 0 deletions .idea/tailwind_rails.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"

# Ordering of SQL relations
gem "acts_as_list"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ GEM
minitest (>= 5.1)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
acts_as_list (1.2.2)
activerecord (>= 6.1)
activesupport (>= 6.1)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
Expand Down Expand Up @@ -313,6 +316,7 @@ PLATFORMS
x86_64-linux-musl

DEPENDENCIES
acts_as_list
bootsnap
brakeman
capybara
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
70 changes: 70 additions & 0 deletions app/controllers/features_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class FeaturesController < ApplicationController
before_action :set_feature, only: %i[ show edit update destroy ]

# GET /features or /features.json
def index
@features = Feature.all
end

# GET /features/1 or /features/1.json
def show
end

# GET /features/new
def new
@feature = Feature.new
end

# GET /features/1/edit
def edit
end

# POST /features or /features.json
def create
@feature = Feature.new(feature_params)

respond_to do |format|
if @feature.save
format.html { redirect_to feature_url(@feature), notice: "Feature was successfully created." }
format.json { render :show, status: :created, location: @feature }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @feature.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /features/1 or /features/1.json
def update
respond_to do |format|
if @feature.update(feature_params)
format.html { redirect_to feature_url(@feature), notice: "Feature was successfully updated." }
format.json { render :show, status: :ok, location: @feature }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @feature.errors, status: :unprocessable_entity }
end
end
end

# DELETE /features/1 or /features/1.json
def destroy
@feature.destroy!

respond_to do |format|
format.html { redirect_to features_url, notice: "Feature was successfully destroyed." }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_feature
@feature = Feature.find(params[:id])
end

# Only allow a list of trusted parameters through.
def feature_params
params.require(:feature).permit(:tagline, :descrption, :category, :image_path, :position, :hotel_id)
end
end
11 changes: 0 additions & 11 deletions app/controllers/hotels/descriptions_controller.rb

This file was deleted.

16 changes: 16 additions & 0 deletions app/controllers/hotels/features_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Hotels::FeaturesController < HotelBaseController
before_action :set_hotel
def index
@features = @hotel.topic_features.order(:position)
end

def room
@features = @hotel.room_features.order(:position)
end

private

def set_hotel
@hotel = Hotel.find(params[:hotel_id])
end
end
19 changes: 19 additions & 0 deletions app/controllers/iphones_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class IphonesController < ApplicationController
layout "iphone"
before_action :set_iphone
def show
end

def create
@iphone.model = params[:model] if params[:model]
@iphone.color = params[:color] if params[:color]
redirect_to iphone_path
end

private

def set_iphone
session[:iphone] ||= {}
@iphone = Iphone.new(session[:iphone])
end
end
2 changes: 2 additions & 0 deletions app/helpers/features_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module FeaturesHelper
end
20 changes: 20 additions & 0 deletions app/javascript/controllers/image_switcher_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Controller } from "@hotwired/stimulus"

// Connects to data-controller="image-switcher"
export default class extends Controller {
static values = {iphone: Object}
static targets = ["colorText"]

connect() {
}

setColorTitle(event) {
const colorName = event.params.colorName
this.colorTextTargets.forEach(target => target.textContent = colorName)
}

resetColorTitle(event) {
this.colorTextTargets.forEach(target => target.textContent = this.iphoneValue.color_name)
}

}
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ application.register("hamburger", HamburgerController)
import HelloController from "./hello_controller"
application.register("hello", HelloController)

import ImageSwitcherController from "./image_switcher_controller"
application.register("image-switcher", ImageSwitcherController)

import NavbarController from "./navbar_controller"
application.register("navbar", NavbarController)

Expand Down
4 changes: 4 additions & 0 deletions app/models/feature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Feature < ApplicationRecord
belongs_to :hotel
enum :category, [ :topic, :room, :restaurant, :service, :basic_info ]
end
3 changes: 3 additions & 0 deletions app/models/hotel.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class Hotel < ApplicationRecord
has_many :features
has_many :topic_features, -> { where(category: :topic) }, class_name: "Feature"
has_many :room_features, -> { where(category: :room) }, class_name: "Feature"
end
43 changes: 43 additions & 0 deletions app/models/iphone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Iphone
def initialize(iphone_session)
@iphone_session = iphone_session
end

def model=(string)
@iphone_session['model'] = string

Check failure on line 7 in app/models/iphone.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
end

def model
@iphone_session['model'] || "6-1inch"

Check failure on line 11 in app/models/iphone.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
end

def color=(string)
@iphone_session['color'] = string

Check failure on line 15 in app/models/iphone.rb

View workflow job for this annotation

GitHub Actions / lint

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
end

def color
@iphone_session["color"] || "naturaltitanium"
end

def color_name
color_name_for_value(color)
end

def color_name_for_value(value)
table = {
"naturaltitanium" => "Color – Natural Titanium",
"bluetitanium" => "Color – Blue Titanium",
"whitetitanium" => "Color – White Titanium",
"blacktitanium" => "Color – Black Titanium",

Check failure on line 31 in app/models/iphone.rb

View workflow job for this annotation

GitHub Actions / lint

Style/TrailingCommaInHashLiteral: Avoid comma after the last item of a hash.
}
table[value]
end

def image_path
"iphone_images/iphone-15-pro-finish-select-202309-#{model}-#{color}.webp"
end

def to_hash
{model:, color:, color_name:}

Check failure on line 41 in app/models/iphone.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideHashLiteralBraces: Space inside { missing.

Check failure on line 41 in app/models/iphone.rb

View workflow job for this annotation

GitHub Actions / lint

Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
end
end
32 changes: 32 additions & 0 deletions app/views/features/_feature.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div id="<%= dom_id feature %>">
<p>
<strong>Tagline:</strong>
<%= feature.tagline %>
</p>

<p>
<strong>Descrption:</strong>
<%= feature.descrption %>
</p>

<p>
<strong>Category:</strong>
<%= feature.category %>
</p>

<p>
<strong>Image path:</strong>
<%= feature.image_path %>
</p>

<p>
<strong>Position:</strong>
<%= feature.position %>
</p>

<p>
<strong>Hotel:</strong>
<%= feature.hotel_id %>
</p>

</div>
2 changes: 2 additions & 0 deletions app/views/features/_feature.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.extract! feature, :id, :tagline, :descrption, :category, :image_path, :position, :hotel_id, :created_at, :updated_at
json.url feature_url(feature, format: :json)
47 changes: 47 additions & 0 deletions app/views/features/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<%= form_with(model: feature) do |form| %>
<% if feature.errors.any? %>
<div style="color: red">
<h2><%= pluralize(feature.errors.count, "error") %> prohibited this feature from being saved:</h2>

<ul>
<% feature.errors.each do |error| %>
<li><%= error.full_message %></li>
<% end %>
</ul>
</div>
<% end %>

<div>
<%= form.label :tagline, style: "display: block" %>
<%= form.text_field :tagline %>
</div>

<div>
<%= form.label :descrption, style: "display: block" %>
<%= form.text_field :descrption %>
</div>

<div>
<%= form.label :category, style: "display: block" %>
<%= form.text_field :category %>
</div>

<div>
<%= form.label :image_path, style: "display: block" %>
<%= form.text_field :image_path %>
</div>

<div>
<%= form.label :position, style: "display: block" %>
<%= form.number_field :position %>
</div>

<div>
<%= form.label :hotel_id, style: "display: block" %>
<%= form.text_field :hotel_id %>
</div>

<div>
<%= form.submit %>
</div>
<% end %>
12 changes: 12 additions & 0 deletions app/views/features/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<% content_for :title, "Editing feature" %>

<h1>Editing feature</h1>

<%= render "form", feature: @feature %>

<br>

<div>
<%= link_to "Show this feature", @feature %> |
<%= link_to "Back to features", features_path %>
</div>
16 changes: 16 additions & 0 deletions app/views/features/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<p style="color: green"><%= notice %></p>

<% content_for :title, "Features" %>

<h1>Features</h1>

<div id="features">
<% @features.each do |feature| %>
<%= render feature %>
<p>
<%= link_to "Show this feature", feature %>
</p>
<% end %>
</div>

<%= link_to "New feature", new_feature_path %>
1 change: 1 addition & 0 deletions app/views/features/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @features, partial: "features/feature", as: :feature
11 changes: 11 additions & 0 deletions app/views/features/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<% content_for :title, "New feature" %>

<h1>New feature</h1>

<%= render "form", feature: @feature %>

<br>

<div>
<%= link_to "Back to features", features_path %>
</div>
10 changes: 10 additions & 0 deletions app/views/features/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p style="color: green"><%= notice %></p>

<%= render @feature %>

<div>
<%= link_to "Edit this feature", edit_feature_path(@feature) %> |
<%= link_to "Back to features", features_path %>

<%= button_to "Destroy this feature", @feature, method: :delete %>
</div>
1 change: 1 addition & 0 deletions app/views/features/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.partial! "features/feature", feature: @feature
Loading

0 comments on commit f9e8e5c

Please sign in to comment.