Browse Source

Add site views

master
Norore 2 years ago
parent
commit
f1e6decb90
10 changed files with 104 additions and 0 deletions
  1. +3
    -0
      app/assets/javascripts/sites.coffee
  2. +20
    -0
      app/assets/stylesheets/sites.sass
  3. +9
    -0
      app/controllers/sites_controller.rb
  4. +2
    -0
      app/helpers/sites_helper.rb
  5. +3
    -0
      app/views/application/_headers.erb
  6. +23
    -0
      app/views/sites/index.html.erb
  7. +37
    -0
      app/views/sites/show.html.erb
  8. +1
    -0
      config/routes.rb
  9. +5
    -0
      spec/controllers/sites_controller_spec.rb
  10. +1
    -0
      spec/helpers/sites_helper_spec.rb

+ 3
- 0
app/assets/javascripts/sites.coffee View File

@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

+ 20
- 0
app/assets/stylesheets/sites.sass View File

@@ -0,0 +1,20 @@
// Place all the styles related to the sites controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

@import "knacss"

div::before
content: "· "

.yellow
background-color: yellow

.orange
background-color: $orange-500

.red
background-color: $red-500

.blue
background-color: $blue-500

+ 9
- 0
app/controllers/sites_controller.rb View File

@@ -0,0 +1,9 @@
class SitesController < ApplicationController
def index
@sites = Site.all.distinct.order(:group_id, :url)
end

def show
@site = Site.find params[:id]
end
end

+ 2
- 0
app/helpers/sites_helper.rb View File

@@ -0,0 +1,2 @@
module SitesHelper
end

+ 3
- 0
app/views/application/_headers.erb View File

@@ -5,6 +5,9 @@
<li>
<%= link_to 'Changes', diffs_path %>
</li>
<li>
<%= link_to 'Sites', sites_path %>
</li>
</ul>
</nav>
</header>

+ 23
- 0
app/views/sites/index.html.erb View File

@@ -0,0 +1,23 @@
<% last = nil
@sites.each do |site|
if last != site.group_id
last = site.group_id %>
<h3><%= site.group&.name || :nogroup %></h3>
<% end %>
<% changed_at = site.changed_at&.to_date
colorclass = case
when changed_at.nil?
nil
when changed_at > 1.day.ago.to_date
:red
when changed_at > 2.days.ago.to_date
:orange
when changed_at > 7.days.ago.to_date
:yellow
end
classes = (%i[mls].concat([colorclass])).compact %>
<%= content_tag(:div, class: classes) do
concat link_to (site.name || site.url), site
concat " (last changed: #{l changed_at})" if changed_at
end %>
<% end %>

+ 37
- 0
app/views/sites/show.html.erb View File

@@ -0,0 +1,37 @@
<h3><%= link_to (@site.name || @site.url), @site.url %></h3>

<div class="alert">
<strong>group:</strong> <%= @site.group&.name || :none %><br>
<strong>template:</strong> <%= @site.template&.name || :none %><br>
<strong>last_error:</strong> <%= @site&.last_error %><br>
<strong>checked_at:</strong> <%= l @site.checked_at, format: :long if @site.checked_at %><br>
<strong>changed_at:</strong> <%= l @site.changed_at, format: :long if @site.changed_at %><br>
</div>

<%= link_to (:back), sites_path %>

<% @site.diffs.each do |diff| %>
<ul class="unstyled mts">
<li><%= l diff.created_at, format: :long %>
<ul class="unstyled mll mbs">
<% diff.content.each do |chunk| %>
<li>
<%=
target = chunk['target']
if target
target = Target.from_h target
content_tag :h4, target
end
%>
<%=
chunk = chunk['diff']
raw Diffy::Diff.load(chunk).to_s :html
%>
</li>
<% end %>
</ul>
</li>
</ul>
<% end %>

<%= link_to (:back), sites_path %>

+ 1
- 0
config/routes.rb View File

@@ -1,3 +1,4 @@
Rails.application.routes.draw do
resources :diffs, only: %i[index show]
resources :sites, only: %i[index show]
end

+ 5
- 0
spec/controllers/sites_controller_spec.rb View File

@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe SitesController, type: :controller do

end

+ 1
- 0
spec/helpers/sites_helper_spec.rb View File

@@ -11,4 +11,5 @@ require 'rails_helper'
# end
# end
RSpec.describe SitesHelper, type: :helper do
pending "add some examples to (or delete) #{__FILE__}"
end

Loading…
Cancel
Save