Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
BethFrank committed Oct 22, 2014
2 parents bd7c61e + be58f04 commit 6fd07c6
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 203 deletions.
4 changes: 4 additions & 0 deletions app/assets/stylesheets/feedback.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
color: silver;
}

.disabled {
color: silver;
}

.mx-spinner {
position: absolute;
background-image: image-url('spinner.gif');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ module DataControllerConfiguration::SharedDataControllerConfiguration
included do
include DataControllerConfiguration
before_action :require_sign_in
before_filter :set_is_shared_data_model
end

protected

def set_is_shared_data_model
@is_shared_data_model = true
end

end
61 changes: 3 additions & 58 deletions app/controllers/geographic_areas_controller.rb
Original file line number Diff line number Diff line change
@@ -1,74 +1,20 @@
class GeographicAreasController < ApplicationController
include DataControllerConfiguration::SharedDataControllerConfiguration
before_filter :require_administrator_sign_in, only: [:edit, :update, :destroy]

before_action :set_geographic_area, only: [:show, :edit, :update, :destroy]
before_action :disable_turbolinks, only: [:show]
before_action :set_geographic_area, only: [:show]
before_action :disable_turbolinks, only: [:show, :list, :index]

# GET /geographic_areas
# GET /geographic_areas.json
def index
# @@all_the_stuff = GeographicArea.all.pain
@geographic_areas = GeographicArea.limit(30).offset(@geo_area_offset)
# @recent_objects = GeographicArea.recent_in_time(1.year).order(updated_at: :desc).limit(10)
@recent_objects = GeographicArea.order(updated_at: :desc).limit(10)
@recent_objects = GeographicArea.updated_in_last(2.months).order(updated_at: :desc).limit(10)
end

# GET /geographic_areas/1
# GET /geographic_areas/1.json
def show
end

# GET /geographic_areas/new
def new
@geographic_area = GeographicArea.new
end

# GET /geographic_areas/1/edit
def edit
end

# POST /geographic_areas
# POST /geographic_areas.json
def create
@geographic_area = GeographicArea.new(geographic_area_params)

respond_to do |format|
if @geographic_area.save
format.html { redirect_to @geographic_area, notice: 'Geographic area was successfully created.' }
format.json { render action: 'show', status: :created, location: @geographic_area }
else
format.html { render action: 'new' }
format.json { render json: @geographic_area.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /geographic_areas/1
# PATCH/PUT /geographic_areas/1.json
def update
respond_to do |format|
if @geographic_area.update(geographic_area_params)
format.html { redirect_to @geographic_area, notice: 'Geographic area was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @geographic_area.errors, status: :unprocessable_entity }
end
end
end

# DELETE /geographic_areas/1
# DELETE /geographic_areas/1.json
def destroy
@geographic_area.destroy
respond_to do |format|
format.html { redirect_to geographic_areas_url }
format.json { head :no_content }
end
end

# triggered by "list" link on index page
def list
@geographic_areas = GeographicArea.order(:id).page(params[:page])
end
Expand Down Expand Up @@ -104,7 +50,6 @@ def disable_turbolinks
@no_turbolinks = true
end


# Use callbacks to share common setup or constraints between actions.
def set_geographic_area
@geographic_area = GeographicArea.find(params[:id])
Expand Down
15 changes: 11 additions & 4 deletions app/helpers/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,22 @@ def edit_object_path(object)
end

def edit_object_link(object)
link_to('Edit', edit_object_path(object.becomes(object.class.base_class)))
if @is_shared_data_model
content_tag(:span, 'Edit', class: :disabled)
else
link_to('Edit', edit_object_path(object.becomes(object.class.base_class)))
end
end

def destroy_object_link(object)
link_to('Destroy', object.becomes(object.class.base_class), method: :delete, data: { confirm: 'Are you sure?' })
if @is_shared_data_model
content_tag(:span, 'Destroy', class: :disabled)
else
link_to('Destroy', object.becomes(object.class.base_class), method: :delete, data: { confirm: 'Are you sure?' })
end
end


def batch_preview_model_path
def batch_preview_model_path
send("batch_preview_#{controller_name.to_s.pluralize}_path")
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/geographic_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#
class GeographicArea < ActiveRecord::Base
include Housekeeping::Users
include Housekeeping::Timestamps

include Shared::IsData

# TODO: Investigate how to do this unconditionally. Use rake NO_GEO_NESTING=1 ... to run incompatible tasks.
Expand Down
2 changes: 1 addition & 1 deletion app/views/geographic_areas/index.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= render partial: '/shared/data/index' -%>
<%= render partial: '/shared/data/simple_index' -%>
6 changes: 0 additions & 6 deletions app/views/geographic_areas/list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

<%= paginate @geographic_areas %> <%= page_entries_info @geographic_areas %>

<!-- todo @mjy list needs culling -->

<table>
<thead>
<tr>
Expand All @@ -21,8 +19,6 @@
<th>Last modified</th>
<th>Updated by</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

Expand All @@ -43,8 +39,6 @@
<td><%= geographic_area.updated_at %></td>
<td><%= object_tag(geographic_area.updater) %></td>
<td><%= link_to 'Show', geographic_area %></td>
<td><%= link_to 'Edit', edit_geographic_area_path(geographic_area) %></td>
<td><%= link_to 'Destroy', geographic_area, method: :delete, data: {confirm: 'Are you sure?'} %></td>
</tr>
<% end %>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion app/views/geographic_areas/show.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= render(partial: 'shared/data/show', locals: {object: @geographic_area}) -%>
<%= render(partial: 'shared/shared_data/application_defined/show', locals: {object: @geographic_area}) -%>
53 changes: 53 additions & 0 deletions app/views/shared/shared_data/application_defined/_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<div class="flexbox">
<div class="item item1">
<h2> <%= model_name_title -%></h2>

<div>id: <%= object.id -%></div>
<%= forward_back_links(object) -%> <br>
<%= pin_item_to_pinboard_link(object, sessions_current_user) -%>
<br>
<%= add_alternate_value_link(object: object, user: sessions_current_user) -%>
<br>
<%= papertrail_link(object) -%>
</div>

<div class="item item2">
<h2> <%= object_tag(object) -%> </h2>
<%= render object_attributes_partial_path(object.becomes(object.class.base_class)) %>
<%= render partial: '/shared/data/show/housekeeping', locals: {object: object} -%>
<%= render(partial: '/shared/data/show/soft_validation', locals: {object: object}) if object.class.respond_to?(:soft_validates?) -%>
</div>

<div class="item item3">
<h2> Related data </h2>

<h3> Has many </h3>
<% object.class.reflect_on_all_associations(:has_many).sort { |a, b| a.name <=> b.name }.each do |r| -%>
<%= r.name.to_s.humanize -%>
<% if object.respond_to?(r.name) -%>
<%= object.send(r.name.to_s).count -%>
<% else %>
<mark> requires method rename!</mark>
<% end %>
<br>
<% end %>
<h3> Has one </h3>
<% object.class.reflect_on_all_associations(:has_one).sort { |a, b| a.name <=> b.name }.each do |r| -%>
<%= r.name.to_s.humanize -%>
<%= content_tag(:strong, object_tag(object.send(r.name.to_s))) -%>
<br>
<% end %>
<h3> Belongs to </h3>
<% object.class.reflect_on_all_associations(:belongs_to).sort { |a, b| a.name <=> b.name }.each do |r| -%>
<%= r.name.to_s.humanize -%>
<%= content_tag(:strong, object_tag(object.send(r.name.to_s))) -%>
<br>
<% end %>


</div>
</div>




53 changes: 53 additions & 0 deletions app/views/shared/shared_data/user_defined/_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<div class="flexbox">
<div class="item item1">
<h2> <%= model_name_title -%></h2>

<div>id: <%= object.id -%></div>
<%= forward_back_links(object) -%> <br>
<%= pin_item_to_pinboard_link(object, sessions_current_user) -%>
<br>
<%= add_alternate_value_link(object: object, user: sessions_current_user) -%>
<br>
<%= papertrail_link(object) -%>
</div>

<div class="item item2">
<h2> <%= object_tag(object) -%> </h2>
<%= render object_attributes_partial_path(object.becomes(object.class.base_class)) %>
<%= render partial: '/shared/data/show/housekeeping', locals: {object: object} -%>
<%= render(partial: '/shared/data/show/soft_validation', locals: {object: object}) if object.class.respond_to?(:soft_validates?) -%>
</div>

<div class="item item3">
<h2> Related data </h2>

<h3> Has many </h3>
<% object.class.reflect_on_all_associations(:has_many).sort { |a, b| a.name <=> b.name }.each do |r| -%>
<%= r.name.to_s.humanize -%>
<% if object.respond_to?(r.name) -%>
<%= object.send(r.name.to_s).count -%>
<% else %>
<mark> requires method rename!</mark>
<% end %>
<br>
<% end %>
<h3> Has one </h3>
<% object.class.reflect_on_all_associations(:has_one).sort { |a, b| a.name <=> b.name }.each do |r| -%>
<%= r.name.to_s.humanize -%>
<%= content_tag(:strong, object_tag(object.send(r.name.to_s))) -%>
<br>
<% end %>
<h3> Belongs to </h3>
<% object.class.reflect_on_all_associations(:belongs_to).sort { |a, b| a.name <=> b.name }.each do |r| -%>
<%= r.name.to_s.humanize -%>
<%= content_tag(:strong, object_tag(object.send(r.name.to_s))) -%>
<br>
<% end %>


</div>
</div>




7 changes: 3 additions & 4 deletions lib/housekeeping/timestamps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Housekeeping::Timestamps
extend ActiveSupport::Concern

included do

end

module ClassMethods
Expand All @@ -26,13 +25,13 @@ def updated_today

# Otu.created_in_last(2.weeks)
def created_in_last(time)
where(created_at: time..Time.now )
where(created_at: time.ago..Time.now )
end

# Otu.created_in_last(1.month)
def updated_in_last(time)
where(updated_at: time..Time.now)
where(updated_at: time.ago..Time.now)
end
end

end

Loading

0 comments on commit 6fd07c6

Please sign in to comment.