diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/javascripts/agents.coffee | 3 | ||||
| -rw-r--r-- | app/assets/stylesheets/agents.scss | 3 | ||||
| -rw-r--r-- | app/controllers/agents_controller.rb | 74 | ||||
| -rw-r--r-- | app/controllers/events_controller.rb | 12 | ||||
| -rw-r--r-- | app/helpers/agents_helper.rb | 2 | ||||
| -rw-r--r-- | app/models/agent.rb | 3 | ||||
| -rw-r--r-- | app/models/event.rb | 1 | ||||
| -rw-r--r-- | app/views/agents/_form.html.erb | 21 | ||||
| -rw-r--r-- | app/views/agents/edit.html.erb | 6 | ||||
| -rw-r--r-- | app/views/agents/index.html.erb | 28 | ||||
| -rw-r--r-- | app/views/agents/index.json.jbuilder | 4 | ||||
| -rw-r--r-- | app/views/agents/new.html.erb | 5 | ||||
| -rw-r--r-- | app/views/agents/show.html.erb | 9 | ||||
| -rw-r--r-- | app/views/agents/show.json.jbuilder | 1 | ||||
| -rw-r--r-- | app/views/events/_form.html.erb | 2 | ||||
| -rw-r--r-- | app/views/events/index.html.erb | 4 | ||||
| -rw-r--r-- | app/views/events/new.html.erb | 2 | ||||
| -rw-r--r-- | app/workers/event_intake.rb (renamed from app/workers/events_worker.rb) | 2 |
18 files changed, 175 insertions, 7 deletions
diff --git a/app/assets/javascripts/agents.coffee b/app/assets/javascripts/agents.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/agents.coffee @@ -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/ diff --git a/app/assets/stylesheets/agents.scss b/app/assets/stylesheets/agents.scss new file mode 100644 index 0000000..e5f96f6 --- /dev/null +++ b/app/assets/stylesheets/agents.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Agents controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb new file mode 100644 index 0000000..a76a7ae --- /dev/null +++ b/app/controllers/agents_controller.rb @@ -0,0 +1,74 @@ +class AgentsController < ApplicationController + before_action :set_agent, only: [:show, :edit, :update, :destroy] + + # GET /agents + # GET /agents.json + def index + @agents = Agent.all + end + + # GET /agents/1 + # GET /agents/1.json + def show + end + + # GET /agents/new + def new + @agent = Agent.new + end + + # GET /agents/1/edit + def edit + end + + # POST /agents + # POST /agents.json + def create + @agent = Agent.new(agent_params) + + respond_to do |format| + if @agent.save + format.html { redirect_to @agent, notice: 'Agent was successfully created.' } + format.json { render :show, status: :created, location: @agent } + else + format.html { render :new } + format.json { render json: @agent.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /agents/1 + # PATCH/PUT /agents/1.json + def update + respond_to do |format| + if @agent.update(agent_params) + format.html { redirect_to @agent, notice: 'Agent was successfully updated.' } + format.json { render :show, status: :ok, location: @agent } + else + format.html { render :edit } + format.json { render json: @agent.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /agents/1 + # DELETE /agents/1.json + def destroy + @agent.destroy + respond_to do |format| + format.html { redirect_to agents_url, notice: 'Agent was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_agent + @agent = Agent.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def agent_params + params.require(:agent).permit(:hostname) + end +end diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 96a51f0..6a8fe42 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -1,4 +1,6 @@ class EventsController < ApplicationController + before_action :load_agent + def index @events = Event.all end @@ -8,8 +10,8 @@ class EventsController < ApplicationController end def create - Publisher.publish("events", event_params) - redirect_to events_path, notice: 'Event was successfully created.' + Publisher.publish("events", event_params.merge({agent_id: @agent.id})) + redirect_to agent_events_path, notice: 'Event was successfully created.' end def destroy @@ -18,7 +20,13 @@ class EventsController < ApplicationController redirect_to events_url, notice: 'Event was successfully destroyed.' end + private + def event_params params.require(:event).permit(:name, :data) end + + def load_agent + @agent = Agent.find(params[:agent_id]) + end end diff --git a/app/helpers/agents_helper.rb b/app/helpers/agents_helper.rb new file mode 100644 index 0000000..7e54438 --- /dev/null +++ b/app/helpers/agents_helper.rb @@ -0,0 +1,2 @@ +module AgentsHelper +end diff --git a/app/models/agent.rb b/app/models/agent.rb new file mode 100644 index 0000000..e5832da --- /dev/null +++ b/app/models/agent.rb @@ -0,0 +1,3 @@ +class Agent < ActiveRecord::Base + has_many :events +end diff --git a/app/models/event.rb b/app/models/event.rb index 3a829fd..3e55383 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,2 +1,3 @@ class Event < ActiveRecord::Base + belongs_to :agent end diff --git a/app/views/agents/_form.html.erb b/app/views/agents/_form.html.erb new file mode 100644 index 0000000..fe9d10e --- /dev/null +++ b/app/views/agents/_form.html.erb @@ -0,0 +1,21 @@ +<%= form_for(@agent) do |f| %> + <% if @agent.errors.any? %> + <div id="error_explanation"> + <h2><%= pluralize(@agent.errors.count, "error") %> prohibited this agent from being saved:</h2> + + <ul> + <% @agent.errors.full_messages.each do |message| %> + <li><%= message %></li> + <% end %> + </ul> + </div> + <% end %> + + <div class="field"> + <%= f.label :hostname %><br> + <%= f.text_field :hostname %> + </div> + <div class="actions"> + <%= f.submit %> + </div> +<% end %> diff --git a/app/views/agents/edit.html.erb b/app/views/agents/edit.html.erb new file mode 100644 index 0000000..bed9b23 --- /dev/null +++ b/app/views/agents/edit.html.erb @@ -0,0 +1,6 @@ +<h1>Editing Agent</h1> + +<%= render 'form' %> + +<%= link_to 'Show', @agent %> | +<%= link_to 'Back', agents_path %> diff --git a/app/views/agents/index.html.erb b/app/views/agents/index.html.erb new file mode 100644 index 0000000..48a36e2 --- /dev/null +++ b/app/views/agents/index.html.erb @@ -0,0 +1,28 @@ +<p id="notice"><%= notice %></p> + +<h1>Listing Agents</h1> + +<table> + <thead> + <tr> + <th>Hostname</th> + <th colspan="4"></th> + </tr> + </thead> + + <tbody> + <% @agents.each do |agent| %> + <tr> + <td><%= agent.hostname %></td> + <td><%= link_to 'Events', agent_events_path(agent) %></td> + <td><%= link_to 'Show', agent %></td> + <td><%= link_to 'Edit', edit_agent_path(agent) %></td> + <td><%= link_to 'Destroy', agent, method: :delete, data: { confirm: 'Are you sure?' } %></td> + </tr> + <% end %> + </tbody> +</table> + +<br> + +<%= link_to 'New Agent', new_agent_path %> diff --git a/app/views/agents/index.json.jbuilder b/app/views/agents/index.json.jbuilder new file mode 100644 index 0000000..65f6f60 --- /dev/null +++ b/app/views/agents/index.json.jbuilder @@ -0,0 +1,4 @@ +json.array!(@agents) do |agent| + json.extract! agent, :id, :hostname + json.url agent_url(agent, format: :json) +end diff --git a/app/views/agents/new.html.erb b/app/views/agents/new.html.erb new file mode 100644 index 0000000..782236f --- /dev/null +++ b/app/views/agents/new.html.erb @@ -0,0 +1,5 @@ +<h1>New Agent</h1> + +<%= render 'form' %> + +<%= link_to 'Back', agents_path %> diff --git a/app/views/agents/show.html.erb b/app/views/agents/show.html.erb new file mode 100644 index 0000000..0e7a061 --- /dev/null +++ b/app/views/agents/show.html.erb @@ -0,0 +1,9 @@ +<p id="notice"><%= notice %></p> + +<p> + <strong>Hostname:</strong> + <%= @agent.hostname %> +</p> + +<%= link_to 'Edit', edit_agent_path(@agent) %> | +<%= link_to 'Back', agents_path %> diff --git a/app/views/agents/show.json.jbuilder b/app/views/agents/show.json.jbuilder new file mode 100644 index 0000000..f156cb0 --- /dev/null +++ b/app/views/agents/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @agent, :id, :hostname, :created_at, :updated_at diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb index a803510..2215f6c 100644 --- a/app/views/events/_form.html.erb +++ b/app/views/events/_form.html.erb @@ -1,4 +1,4 @@ -<%= form_for(@event) do |f| %> +<%= form_for([@agent, @event]) do |f| %> <% if @event.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@event.errors.count, "error") %> prohibited this event from being saved:</h2> diff --git a/app/views/events/index.html.erb b/app/views/events/index.html.erb index 02fb2cb..bf0480c 100644 --- a/app/views/events/index.html.erb +++ b/app/views/events/index.html.erb @@ -18,7 +18,7 @@ <td><%= event.name %></td> <td><%= event.data %></td> <td><%= event.created_at %></td> - <td><%= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' } %></td> + <td><%= link_to 'Destroy', [@agent, event], method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </tbody> @@ -26,4 +26,4 @@ <br> -<%= link_to 'New Event', new_event_path %> +<%= link_to 'New Event', new_agent_event_path(@agent) %> diff --git a/app/views/events/new.html.erb b/app/views/events/new.html.erb index 86707c1..1c0b206 100644 --- a/app/views/events/new.html.erb +++ b/app/views/events/new.html.erb @@ -2,4 +2,4 @@ <%= render 'form' %> -<%= link_to 'Back', events_path %> +<%= link_to 'Back', agent_events_path(@agent) %> diff --git a/app/workers/events_worker.rb b/app/workers/event_intake.rb index dc85009..7e70497 100644 --- a/app/workers/events_worker.rb +++ b/app/workers/event_intake.rb @@ -1,6 +1,6 @@ require 'json' -class EventsWorker +class EventIntake include Sneakers::Worker from_queue "worker.events" |
