mirror of
https://github.com/czhu12/canine.git
synced 2025-12-30 07:39:43 -06:00
added logs for projects and add ons
This commit is contained in:
9
app/controllers/add_ons/base_controller.rb
Normal file
9
app/controllers/add_ons/base_controller.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class AddOns::BaseController < ApplicationController
|
||||
before_action :set_add_on
|
||||
|
||||
private
|
||||
|
||||
def set_add_on
|
||||
@add_on = AddOn.find(params[:add_on_id])
|
||||
end
|
||||
end
|
||||
17
app/controllers/add_ons/logs_controller.rb
Normal file
17
app/controllers/add_ons/logs_controller.rb
Normal file
@@ -0,0 +1,17 @@
|
||||
class AddOns::LogsController < AddOns::BaseController
|
||||
def index
|
||||
@pods = get_pods_for_add_on(@add_on)
|
||||
end
|
||||
|
||||
def show
|
||||
client = K8::Client.new(@add_on.cluster.kubeconfig)
|
||||
@logs = client.get_pod_log(params[:id], @add_on.name)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_pods_for_add_on(add_on)
|
||||
client = K8::Client.new(add_on.cluster.kubeconfig).client
|
||||
client.get_pods(namespace: add_on.name)
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
class AddOnsController < ApplicationController
|
||||
include StorageHelper
|
||||
before_action :set_add_on, only: [ :show, :edit, :update, :destroy, :logs ]
|
||||
before_action :set_add_on, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /add_ons
|
||||
def index
|
||||
@@ -22,9 +22,6 @@ class AddOnsController < ApplicationController
|
||||
# authorize @add_on
|
||||
end
|
||||
|
||||
def logs
|
||||
end
|
||||
|
||||
# GET /add_ons/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class StaticController < ApplicationController
|
||||
layout "homepage"
|
||||
def index
|
||||
end
|
||||
end
|
||||
|
||||
11
app/javascript/controllers/logs_controller.js
Normal file
11
app/javascript/controllers/logs_controller.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["container"]
|
||||
|
||||
connect() {
|
||||
// Scroll to the bottom of the container
|
||||
this.containerTarget.scrollTop = this.containerTarget.scrollHeight;
|
||||
console.log("Logs controller connected")
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
Info
|
||||
</div>
|
||||
<% end %>
|
||||
<%= link_to logs_add_on_url(add_on), class: "tab hover:bg-base-content/15 #{'tab-active' if current_page?(logs_add_on_url(add_on))}" do %>
|
||||
<%= link_to add_on_logs_url(add_on), class: "tab hover:bg-base-content/15 #{'tab-active' if current_page?(add_on_logs_url(add_on))}" do %>
|
||||
<div class="flex items-center gap-2">
|
||||
Logs
|
||||
</div>
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<%= add_on_layout(@add_on) do %>
|
||||
<%= render "log_outputs/logs", loggable: @add_on %>
|
||||
<% end %>
|
||||
47
app/views/add_ons/logs/index.html.erb
Normal file
47
app/views/add_ons/logs/index.html.erb
Normal file
@@ -0,0 +1,47 @@
|
||||
<%= add_on_layout(@add_on) do %>
|
||||
<%= turbo_frame_tag "pod_logs" do %>
|
||||
<% if @pods.empty? %>
|
||||
<div>
|
||||
<p class="text-gray-500">Nothing running in this namespace</p>
|
||||
</div>
|
||||
<% else %>
|
||||
<table class="table mt-2 rounded-box" data-component="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<span class="text-sm font-medium text-base-content/80">Pod Name</span>
|
||||
</th>
|
||||
<th>
|
||||
<span class="text-sm font-medium text-base-content/80">
|
||||
Status
|
||||
</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @pods.each do |pod| %>
|
||||
<tr class="cursor-pointer hover:bg-base-200/40">
|
||||
<td>
|
||||
<div class="flex items-center space-x-3 truncate">
|
||||
<div class="font-medium">
|
||||
<%= pod.metadata.name %>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="font-medium">
|
||||
<%= pod.status.phase %>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="font-medium">
|
||||
<%= link_to "Show Logs", add_on_log_path(@add_on, pod.metadata.name) %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
3
app/views/add_ons/logs/show.html.erb
Normal file
3
app/views/add_ons/logs/show.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<%= add_on_layout(@add_on) do %>
|
||||
<%= render "log_outputs/pod_logs", logs: @logs, back_path: add_on_logs_path(@add_on) %>
|
||||
<% end %>
|
||||
11
app/views/log_outputs/_pod_logs.html.erb
Normal file
11
app/views/log_outputs/_pod_logs.html.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<%= turbo_frame_tag "pod_logs" do %>
|
||||
<%= link_to back_path, class: "btn btn-ghost btn-sm" do %>
|
||||
<iconify-icon icon="lucide:chevron-left"></iconify-icon> Back
|
||||
<% end %>
|
||||
<h4 class="text-md font-medium mb-2"><%= params[:id] %></h4>
|
||||
<div class="bg-gray-900 text-gray-100 rounded-lg shadow-lg" data-controller="logs">
|
||||
<div class="overflow-auto h-96 bg-gray-800 p-2 rounded" data-logs-target="container">
|
||||
<pre class="text-sm font-mono whitespace-pre-wrap"><%= ansi_to_tailwind(logs).html_safe || "No logs yet..." %></pre>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1,11 +1,3 @@
|
||||
<%= turbo_frame_tag "pod_logs" do %>
|
||||
<div class="flex">
|
||||
<%= link_to "Back", project_logs_path(@project), class: "btn btn-sm btn-outline" %>
|
||||
<h4 class="text-md font-medium mb-2"><%= params[:id] %></h4>
|
||||
</div>
|
||||
<div class="bg-gray-900 text-gray-100 rounded-lg shadow-lg" data-controller="logs">
|
||||
<div class="overflow-auto h-96 bg-gray-800 p-2 rounded" data-logs-target="container">
|
||||
<pre class="text-sm font-mono whitespace-pre-wrap"><%= ansi_to_tailwind(@logs).html_safe || "No logs yet..." %></pre>
|
||||
</div>
|
||||
</div>
|
||||
<%= project_layout(@project) do %>
|
||||
<%= render "log_outputs/pod_logs", logs: @logs, back_path: project_logs_path(@project) %>
|
||||
<% end %>
|
||||
@@ -15,9 +15,7 @@ Rails.application.routes.draw do
|
||||
# get "/dashboard", to: "dashboard#show", as: :user_root
|
||||
end
|
||||
resources :add_ons do
|
||||
member do
|
||||
get :logs, to: "add_ons#logs"
|
||||
end
|
||||
resources :logs, only: %i[index show], module: :add_ons
|
||||
end
|
||||
|
||||
resources :projects do
|
||||
|
||||
Reference in New Issue
Block a user