Skip to content

Commit 919100a

Browse files
Add monitors simple dashboard and complete the CRUD operations of monitors
1 parent d9066a0 commit 919100a

6 files changed

Lines changed: 45 additions & 15 deletions

File tree

app/controllers/monitors_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class MonitorsController < ApplicationController
22
before_action :authenticate_user!
3-
before_action :set_monitor, only: [:edit]
3+
before_action :set_monitor, only: [:edit, :show, :update, :destroy]
44

55

66
def index
@@ -28,16 +28,16 @@ def edit
2828
end
2929

3030
def update
31+
@pulse = current_user.pulses.find(params[:id])
3132
@pulse.update(monitor_params)
32-
redirect_to @pulse
33+
redirect_to monitors_path
3334
end
3435

3536
def destroy
3637
@pulse.destroy
3738
redirect_to monitors_path
3839
end
3940

40-
4141
private
4242

4343
def monitor_params

app/models/pulse.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
class Pulse < ApplicationRecord
22
belongs_to :user
33
# has_one :status_page
4+
validates :url, :pulse_type, :pulse_interval, presence: true
45
end

app/views/monitors/_form.html.erb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
<%= render "partials/sidebar" %>
33

44
<div class="flex justify-center flex-1 p-8">
5-
<div class="max-w-xl h-fit bg-white border border-secondary/10 rounded-lg p-6">
5+
<div class="max-w-xl h-fit bg-white border border-secondary/10 p-6">
66

7-
<h2 class="text-xl font-semibold mb-6">Create Monitor</h2>
7+
<h2 class="text-xl font-semibold mb-6"><%= @pulse.persisted? ? "Update Monitor" : "Create Monitor" %></h2>
88

9-
<%= form_with model: @pulse, url: monitors_path, class: "space-y-6" do |f| %>
9+
<%= form_with model: @pulse, url: @pulse.persisted? ? monitor_path(@pulse) : monitors_path, class: "space-y-6" do |f| %>
1010

1111
<!-- Website URL -->
1212
<div>
1313
<%= f.label :url, "Website URL", class: "block text-sm font-medium text-gray-700 mb-1" %>
1414
<%= f.text_field :url,
1515
placeholder: "https://example.com",
16-
class: "w-full border border-secondary/10 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-secondary/20" %>
16+
class: "w-full border border-secondary/10 rounded-md px-3 py-2 focus:outline-none focus:ring-2 focus:ring-secondary/20", required: true %>
1717
<p class="text-xs text-gray-500 mt-1">
1818
Enter the full URL you want to monitor.
1919
</p>
@@ -60,8 +60,8 @@
6060

6161
<!-- Submit -->
6262
<div class="pt-4">
63-
<%= f.submit "Create Monitor",
64-
class: "bg-black text-white px-5 py-2 rounded-md hover:bg-gray-800 transition cursor-pointer" %>
63+
<%= f.submit (@pulse.persisted? ? "Update Monitor" : "Create Monitor"),
64+
class: "inline-flex items-center bg-secondary hover:bg-black border-0 py-2 px-4 focus:outline-none text-white font-bold mt-4 md:mt-0 cursor-pointer" %>
6565
</div>
6666

6767
<% end %>

app/views/monitors/edit.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= render "form" %>
1+
<%= render "form", pulse: @pulse %>

app/views/monitors/index.html.erb

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@
33

44
<div class="flex-1 p-6">
55

6+
<section class="text-gray-600 body-font pb-4">
7+
<div class="flex flex-wrap -m-4">
8+
<div class="xl:w-1/4 md:w-1/2 p-4">
9+
<div class="bg-background/50 border border-secondary/10 p-6">
10+
<h3 class="tracking-widest text-indigo-500 text-xs font-medium title-font">SUBTITLE</h3>
11+
<h2 class="text-lg text-gray-900 font-medium title-font mb-4">Chichen Itza</h2>
12+
</div>
13+
</div>
14+
<div class="xl:w-1/4 md:w-1/2 p-4">
15+
<div class="bg-background/50 border border-secondary/10 p-6">
16+
<h3 class="tracking-widest text-indigo-500 text-xs font-medium title-font">SUBTITLE</h3>
17+
<h2 class="text-lg text-gray-900 font-medium title-font mb-4">Chichen Itza</h2>
18+
</div>
19+
</div>
20+
<div class="xl:w-1/4 md:w-1/2 p-4">
21+
<div class="bg-background/50 border border-secondary/10 p-6">
22+
<h3 class="tracking-widest text-indigo-500 text-xs font-medium title-font">SUBTITLE</h3>
23+
<h2 class="text-lg text-gray-900 font-medium title-font mb-4">Chichen Itza</h2>
24+
</div>
25+
</div>
26+
<div class="xl:w-1/4 md:w-1/2 p-4">
27+
<div class="bg-background/50 border border-secondary/10 p-6">
28+
<h3 class="tracking-widest text-indigo-500 text-xs font-medium title-font">SUBTITLE</h3>
29+
<h2 class="text-lg text-gray-900 font-medium title-font mb-4">Chichen Itza</h2>
30+
</div>
31+
</div>
32+
</div>
33+
</section>
34+
635
<!-- Top Bar -->
736
<div class="flex flex-wrap flex-col md:flex-row items-center justify-between mb-6 gap-4">
837

@@ -11,7 +40,7 @@
1140
<input
1241
type="text"
1342
placeholder="Search by URL"
14-
class="w-full border border-secondary/10 rounded-md px-3 py-2 focus:ring-2 focus:ring-secondary/10 focus:outline-none"
43+
class="w-full border border-secondary/10 px-3 py-2 focus:ring-2 focus:ring-secondary/10 focus:outline-none"
1544
>
1645
</div>
1746

@@ -21,12 +50,12 @@
2150

2251

2352
<!-- Monitors Table -->
24-
<div class="bg-white border border-secondary/10 rounded-lg overflow-hidden">
53+
<div class="bg-white border border-secondary/10 overflow-hidden">
2554

2655
<table class="w-full text-sm">
2756

2857
<!-- Table Header -->
29-
<thead class="bg-gray-50 border-b border-secondary/10 text-gray-600">
58+
<thead class="bg-background border-b border-secondary/10 text-gray-600">
3059
<tr>
3160
<th class="text-left px-6 py-3 font-medium">Monitor</th>
3261
<th class="text-left px-6 py-3 font-medium">Type</th>
@@ -42,7 +71,7 @@
4271
<% if @pulses.any? %>
4372
<% @pulses.each do |pulse| %>
4473

45-
<tr class="hover:bg-gray-50 transition">
74+
<tr class="hover:bg-background/40 transition">
4675

4776
<!-- URL -->
4877
<td class="px-6 py-4">

app/views/monitors/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= render "form" %>
1+
<%= render "form", pulse: @pulse %>

0 commit comments

Comments
 (0)