diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml
index aef3108..c07f0ea 100644
--- a/.idea/dataSources.local.xml
+++ b/.idea/dataSources.local.xml
@@ -1,6 +1,6 @@
-
+
no-auth
diff --git a/.idea/terminator.iml b/.idea/terminator.iml
index 1baa936..88aba9c 100644
--- a/.idea/terminator.iml
+++ b/.idea/terminator.iml
@@ -35,6 +35,7 @@
+
@@ -49,6 +50,7 @@
+
@@ -62,6 +64,7 @@
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index bf84577..f860d4e 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,44 +5,24 @@
-
+
-
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
+
-
-
-
-
+
+
-
-
-
-
@@ -77,24 +57,25 @@
- {
+ "keyToString": {
+ "ASKED_ADD_EXTERNAL_FILES": "true",
+ "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "Rails.terminator.executor": "Run",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "git-widget-placeholder": "master",
+ "last_opened_file_path": "/home/hamo/projects/kbr4/terminator/app/views/layouts",
+ "list.type.of.created.stylesheet": "CSS",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "ruby.structure.view.model.defaults.configured": "true",
+ "settings.editor.selected.configurable": "org.jetbrains.plugins.ruby.settings.RubyActiveModuleSdkConfigurable",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
@@ -186,7 +167,7 @@
-
+
@@ -209,7 +190,9 @@
-
+
+
+
@@ -217,6 +200,6 @@
-
+
\ No newline at end of file
diff --git a/Gemfile b/Gemfile
index 610affc..13879d0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -46,6 +46,7 @@ gem "bootsnap", require: false
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
# gem "image_processing", "~> 1.2"
+gem "active_model_serializers"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
diff --git a/Gemfile.lock b/Gemfile.lock
index 780eed7..4bfc577 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -50,6 +50,11 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
+ active_model_serializers (0.10.14)
+ actionpack (>= 4.1)
+ activemodel (>= 4.1)
+ case_transform (>= 0.2)
+ jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (7.1.3.3)
activesupport (= 7.1.3.3)
globalid (>= 0.3.6)
@@ -93,6 +98,8 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
+ case_transform (0.2)
+ activesupport
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crass (1.0.6)
@@ -117,6 +124,7 @@ GEM
jbuilder (2.12.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
+ jsonapi-renderer (0.2.2)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
@@ -244,6 +252,7 @@ PLATFORMS
x86_64-linux
DEPENDENCIES
+ active_model_serializers
bcrypt (~> 3.1.7)
bootsnap
capybara
diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css
index 556795a..16f48d0 100644
--- a/app/assets/stylesheets/application.tailwind.css
+++ b/app/assets/stylesheets/application.tailwind.css
@@ -18,4 +18,7 @@ body {
toastui-calendar-time {
height: 100% !important;
-}
\ No newline at end of file
+}
+
+.toastui-calendar-timegrid { height: 100%; }
+.toastui-calendar-panel.toastui-calendar-time { overflow-y: inherit; }
\ No newline at end of file
diff --git a/app/controllers/reservations_controller.rb b/app/controllers/reservations_controller.rb
index 8a52fcb..c9bfab0 100644
--- a/app/controllers/reservations_controller.rb
+++ b/app/controllers/reservations_controller.rb
@@ -6,7 +6,8 @@ class ReservationsController < ApplicationController
# GET /reservations or /reservations.json
def index
- @reservations = Reservation.all
+ @reservations = Reservation.all.includes(:team, :customer).where(company: @company)
+ @reservations = ActiveModelSerializers::SerializableResource.new(@reservations).as_json
end
# GET /reservations/1 or /reservations/1.json
@@ -16,7 +17,7 @@ class ReservationsController < ApplicationController
# GET /reservations/new
def new
@reservation = Reservation.new
- @reservation.place = @company.places.first
+ @reservation.team = @company.teams.first
end
# GET /reservations/1/edit
@@ -70,7 +71,7 @@ class ReservationsController < ApplicationController
# Only allow a list of trusted parameters through.
def reservation_params
- params.require(:reservation).permit(:company_id, :customer_id, :place_id, :title, :description, :start_time, :end_time)
+ params.require(:reservation).permit(:company_id, :customer_id, :team_id, :title, :description, :start_time, :end_time)
end
def determine_layout
diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb
index 8b6868d..979aff7 100644
--- a/app/controllers/teams_controller.rb
+++ b/app/controllers/teams_controller.rb
@@ -22,6 +22,7 @@ class TeamsController < ApplicationController
# POST /teams or /teams.json
def create
@team = Team.new(team_params)
+ @team.company = Company.first
respond_to do |format|
if @team.save
@@ -36,6 +37,7 @@ class TeamsController < ApplicationController
# PATCH/PUT /teams/1 or /teams/1.json
def update
+ @team.company = Company.first
respond_to do |format|
if @team.update(team_params)
format.html { redirect_to team_url(@team), notice: "Team was successfully updated." }
@@ -65,6 +67,6 @@ class TeamsController < ApplicationController
# Only allow a list of trusted parameters through.
def team_params
- params.fetch(:team, {})
+ params.require(:team).permit(:name)
end
end
diff --git a/app/javascript/controllers/main_calendar_controller.js b/app/javascript/controllers/main_calendar_controller.js
index 7930548..8f88137 100644
--- a/app/javascript/controllers/main_calendar_controller.js
+++ b/app/javascript/controllers/main_calendar_controller.js
@@ -3,14 +3,20 @@ import {Controller} from "@hotwired/stimulus"
export default class extends Controller {
connect() {
- const calendar = new tui.Calendar(this.element, {
+ const calendar = new tui.Calendar(document.getElementById('main-calendar'), {
defaultView: 'week',
usageStatistics: false,
week: {
taskView: false,
- eventView: true,
- milestone: false,
- scheduleView: ['time'], // This will hide the all-day section
+ scheduleView: false,
+ eventView: ['time'],
+ hourStart: 4,
+ hourEnd: 21,
+ },
+ template: {
+ timegridDisplayPrimaryTime({time}) {
+ return `${time.getHours()} sati`;
+ }
},
calendars: [
{
@@ -21,6 +27,27 @@ export default class extends Controller {
],
});
+ this.calendar = calendar;
+ this.getCalendardata();
calendar.render();
}
+
+ getCalendardata() {
+ var reservations = JSON.parse(document.querySelector("#main-calendar").dataset.reservations);
+ window.reservations = reservations;
+ reservations.forEach(reservation => {
+ this.calendar.createSchedules([
+ {
+ id: reservation.id,
+ calendarId: 'cal1',
+ title: reservation.customer,
+ category: 'time',
+ dueDateClass: reservation.dueDateClass,
+ location: reservation.team.name,
+ start: reservation.start_time,
+ end: reservation.end_time
+ }
+ ])
+ });
+ }
}
diff --git a/app/models/reservation.rb b/app/models/reservation.rb
index 93c1b16..98514c9 100644
--- a/app/models/reservation.rb
+++ b/app/models/reservation.rb
@@ -1,9 +1,9 @@
class Reservation < ApplicationRecord
belongs_to :company
belongs_to :customer
- belongs_to :place
+ belongs_to :team
validates :company_id, presence: true
validates :customer_id, presence: true
- validates :place_id, presence: true
+ validates :team_id, presence: true
end
diff --git a/app/models/team.rb b/app/models/team.rb
index 48a6c83..f16ec40 100644
--- a/app/models/team.rb
+++ b/app/models/team.rb
@@ -1,2 +1,7 @@
class Team < ApplicationRecord
+ belongs_to :company
+ has_many :reservations, dependent: :destroy
+
+ validates :name, presence: true
+ validates :company_id, presence: true
end
diff --git a/app/serializers/reservatiopn_serializer.rb b/app/serializers/reservatiopn_serializer.rb
new file mode 100644
index 0000000..fb3ceac
--- /dev/null
+++ b/app/serializers/reservatiopn_serializer.rb
@@ -0,0 +1,6 @@
+class ReservationSerializer < ActiveModel::Serializer
+ attributes :id, :company_id, :customer_id, :team_id, :title, :description, :start_time, :end_time
+
+ belongs_to :team
+ belongs_to :customer
+end
\ No newline at end of file
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 47200c9..b84b013 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -14,7 +14,7 @@
-
+
<%= yield %>
diff --git a/app/views/reservations/_form.html.erb b/app/views/reservations/_form.html.erb
index 02a8941..cf213bd 100644
--- a/app/views/reservations/_form.html.erb
+++ b/app/views/reservations/_form.html.erb
@@ -13,23 +13,14 @@
<%= form.label :customer_id %>
- <%= form.collection_select :customer_id, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ <%= form.collection_select :customer_id, @company.customers, :id, :name, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
<%= form.label :team_id %>
- <%= form.collection_select :place_id, @company.teams, :id, :name, prompt: "Select a Team", class:"block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+ <%= form.collection_select :team_id, @company.teams, :id, :name, prompt: "Select a Team", class:"block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
-
- <%= form.label :title %>
- <%= form.text_field :title, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
-
-
-
- <%= form.label :description %>
- <%= form.text_area :description, rows: 4, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
-
<%= form.label :start_time %>`
diff --git a/app/views/reservations/_reservation.html.erb b/app/views/reservations/_reservation.html.erb
index 1187b42..2e8c2a1 100644
--- a/app/views/reservations/_reservation.html.erb
+++ b/app/views/reservations/_reservation.html.erb
@@ -10,18 +10,8 @@
- Place:
- <%= reservation.place_id %>
-
-
-
- Title:
- <%= reservation.title %>
-
-
-
- Description:
- <%= reservation.description %>
+ Team:
+ <%= reservation.team.name %>
diff --git a/app/views/reservations/index.html.erb b/app/views/reservations/index.html.erb
index 5bda4cf..71eb358 100644
--- a/app/views/reservations/index.html.erb
+++ b/app/views/reservations/index.html.erb
@@ -10,8 +10,7 @@
<%= link_to "New reservation", new_reservation_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
-
-
-
+
+ <%= tag.div nil, data: {reservations: @reservations.to_json}, id: "main-calendar"%>
diff --git a/app/views/teams/_form.html.erb b/app/views/teams/_form.html.erb
index 9f26ef4..6bd390e 100644
--- a/app/views/teams/_form.html.erb
+++ b/app/views/teams/_form.html.erb
@@ -2,7 +2,6 @@
<% if team.errors.any? %>
<%= pluralize(team.errors.count, "error") %> prohibited this team from being saved:
-
<% team.errors.each do |error| %>
- <%= error.full_message %>
@@ -11,6 +10,11 @@
<% end %>
+
+ <%= form.label :name %>
+ <%= form.text_field :name, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
+
+
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
diff --git a/db/migrate/20240810054948_create_teams.rb b/db/migrate/20240810054948_create_teams.rb
index fbbdd6d..acce0a4 100644
--- a/db/migrate/20240810054948_create_teams.rb
+++ b/db/migrate/20240810054948_create_teams.rb
@@ -1,7 +1,8 @@
class CreateTeams < ActiveRecord::Migration[7.1]
def change
create_table :teams do |t|
-
+ t.string :name
+ t.references :company, null: false, foreign_key: true
t.timestamps
end
end
diff --git a/db/migrate/20240818063444_change_place_to_team_in_reservations.rb b/db/migrate/20240818063444_change_place_to_team_in_reservations.rb
new file mode 100644
index 0000000..3a6ac6e
--- /dev/null
+++ b/db/migrate/20240818063444_change_place_to_team_in_reservations.rb
@@ -0,0 +1,6 @@
+class ChangePlaceToTeamInReservations < ActiveRecord::Migration[7.1]
+ def change
+ remove_reference :reservations, :place, foreign_key: true
+ add_reference :reservations, :team, null: false, foreign_key: true
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index eff72c7..0828cb4 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.1].define(version: 2024_08_10_054948) do
+ActiveRecord::Schema[7.1].define(version: 2024_08_18_063444) do
create_table "companies", force: :cascade do |t|
t.string "name"
t.string "id_number"
@@ -47,23 +47,27 @@ ActiveRecord::Schema[7.1].define(version: 2024_08_10_054948) do
create_table "reservations", force: :cascade do |t|
t.integer "company_id", null: false
t.integer "customer_id", null: false
- t.integer "place_id", null: false
t.datetime "start_time"
t.datetime "end_time"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.integer "team_id", null: false
t.index ["company_id"], name: "index_reservations_on_company_id"
t.index ["customer_id"], name: "index_reservations_on_customer_id"
- t.index ["place_id"], name: "index_reservations_on_place_id"
+ t.index ["team_id"], name: "index_reservations_on_team_id"
end
create_table "teams", force: :cascade do |t|
+ t.string "name"
+ t.integer "company_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
+ t.index ["company_id"], name: "index_teams_on_company_id"
end
add_foreign_key "places", "companies"
add_foreign_key "reservations", "companies"
add_foreign_key "reservations", "customers"
- add_foreign_key "reservations", "places"
+ add_foreign_key "reservations", "teams"
+ add_foreign_key "teams", "companies"
end