diff --git a/Gemfile b/Gemfile index 7a859c6..8475b89 100644 --- a/Gemfile +++ b/Gemfile @@ -65,6 +65,7 @@ group :development do # Speed up commands on slow machines / big apps [https://github.com/rails/spring] # gem "spring" + gem 'annotate' end group :test do @@ -73,3 +74,5 @@ group :test do gem "selenium-webdriver" end + +gem "devise", "~> 4.9" diff --git a/Gemfile.lock b/Gemfile.lock index a6aad66..f58ae1f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,10 @@ GEM tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) + annotate (3.2.0) + activerecord (>= 3.2, < 8.0) + rake (>= 10.4, < 14.0) + bcrypt (3.1.19) bindex (0.8.1) bootsnap (1.16.0) msgpack (~> 1.2) @@ -89,6 +93,12 @@ GEM debug (1.8.0) irb (>= 1.5.0) reline (>= 0.3.1) + devise (4.9.3) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0) + responders + warden (~> 1.2.3) erubi (1.12.0) globalid (1.2.1) activesupport (>= 6.1) @@ -129,6 +139,7 @@ GEM nio4r (2.5.9) nokogiri (1.15.4-x86_64-linux) racc (~> 1.4) + orm_adapter (0.5.0) pg (1.5.4) psych (5.1.0) stringio @@ -173,6 +184,9 @@ GEM regexp_parser (2.8.1) reline (0.3.8) io-console (~> 0.5) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) rexml (3.2.6) rubyzip (2.3.2) selenium-webdriver (4.12.0) @@ -197,6 +211,8 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + warden (1.2.9) + rack (>= 2.0.9) web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -214,10 +230,12 @@ PLATFORMS x86_64-linux DEPENDENCIES + annotate bootsnap capybara cssbundling-rails debug + devise (~> 4.9) jbuilder jsbundling-rails pg (~> 1.1) diff --git a/app/controllers/bubbles_controller.rb b/app/controllers/bubbles_controller.rb new file mode 100644 index 0000000..7695138 --- /dev/null +++ b/app/controllers/bubbles_controller.rb @@ -0,0 +1,52 @@ +class BubblesController < ApplicationController + before_action :authenticate_user! + + def index + @bubbles = Bubble.all + end + + def new + @bubble = Bubble.new + end + + def create + if Bubble.new(allowed_params).save + redirect_to bubbles_path, flash: { success: "Créé" } + else + redirect_to new_bubble_path, flash: { error: "Pas créé" } + end + end + + def edit + @bubble = Bubble.find(params[:id]) + end + + def update + @bubble = Bubble.find(params[:id]) + if @bubble.update(allowed_params) + redirect_to bubbles_path, flash: { success: "Sauvegardé" } + else + redirect_to edit_bubble_path(@bubble), flash: { error: "Pas sauvegardé" } + end + end + + def confirm_destroy + @bubble = Bubble.find(params[:bubble_id]) + end + + def destroy + @bubble = Bubble.find(params[:id]) + if @bubble.destroy + redirect_to bubbles_path, flash: { success: "Supprimé" } + else + redirect_to bubbles_path, flash: { error: "Pas supprimé" } + end + end + + private + + def allowed_params + params.require(:bubble).permit(:name, :description, :color) + end + +end \ No newline at end of file diff --git a/app/controllers/hello_controller.rb b/app/controllers/hello_controller.rb deleted file mode 100644 index 5c4a601..0000000 --- a/app/controllers/hello_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class HelloController < ApplicationController - - def clara - @name = params[:name].blank? ? "beach" : params[:name] - end - -end diff --git a/app/controllers/profile_controller.rb b/app/controllers/profile_controller.rb new file mode 100644 index 0000000..ed0f94d --- /dev/null +++ b/app/controllers/profile_controller.rb @@ -0,0 +1,4 @@ +class ProfileController < ApplicationController + before_action :authenticate_user! + +end \ No newline at end of file diff --git a/app/models/application_record.rb b/app/models/application_record.rb index b63caeb..d6347d0 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ class ApplicationRecord < ActiveRecord::Base primary_abstract_class + default_scope { order(created_at: :asc) } + end diff --git a/app/models/bubble.rb b/app/models/bubble.rb new file mode 100644 index 0000000..1108d25 --- /dev/null +++ b/app/models/bubble.rb @@ -0,0 +1,14 @@ +# == Schema Information +# +# Table name: bubbles +# +# id :uuid not null, primary key +# color :string default("#0000ff"), not null +# description :text default(""), not null +# name :string not null +# created_at :datetime not null +# updated_at :datetime not null +# +class Bubble < ApplicationRecord + validates :name, presence: true, allow_blank: false +end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..fedf1d8 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,24 @@ +# == Schema Information +# +# Table name: users +# +# id :uuid not null, primary key +# email :string default(""), not null +# encrypted_password :string default(""), not null +# remember_created_at :datetime +# reset_password_sent_at :datetime +# reset_password_token :string +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_users_on_email (email) UNIQUE +# index_users_on_reset_password_token (reset_password_token) UNIQUE +# +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :validatable +end diff --git a/app/views/bubbles/confirm_destroy.html.erb b/app/views/bubbles/confirm_destroy.html.erb new file mode 100644 index 0000000..79ab57e --- /dev/null +++ b/app/views/bubbles/confirm_destroy.html.erb @@ -0,0 +1,3 @@ +Êtes-vous sûr de vouloir supprimer la bulle <%= @bubble.name %> ? + +<%= link_to "Supprimer", bubble_path(@bubble), data: { "turbo-method": :delete } %> diff --git a/app/views/bubbles/edit.html.erb b/app/views/bubbles/edit.html.erb new file mode 100644 index 0000000..ee433e7 --- /dev/null +++ b/app/views/bubbles/edit.html.erb @@ -0,0 +1 @@ +<%= render partial: "bubbles/shared/form", locals: { bubble: @bubble } %> \ No newline at end of file diff --git a/app/views/bubbles/index.html.erb b/app/views/bubbles/index.html.erb new file mode 100644 index 0000000..2e8ea97 --- /dev/null +++ b/app/views/bubbles/index.html.erb @@ -0,0 +1,19 @@ +<%= link_to "Créer une bulle", new_bubble_path %> + +
Nom | +Description | +Actions | +
---|---|---|
<%= bubble.name %> | +<%= bubble.description %> | ++ <%= link_to "Éditer", edit_bubble_path(bubble) %> + <%= link_to "Supprimer", bubble_confirm_destroy_path(bubble) %> + | +