Skip to content

Commit

Permalink
Rename Groups to Contexts coyote-team#114
Browse files Browse the repository at this point in the history
  • Loading branch information
subelsky committed Jul 27, 2017
1 parent 2c9c93e commit 64c640f
Show file tree
Hide file tree
Showing 38 changed files with 285 additions and 266 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ For use on [nomnoml](http://www.nomnoml.com/)
[User | id: int | first_name: string | last_name: string | email: string | admin: bool ]
[Image | id: int |url : string | canonical_id: string | priority: boolean | title: text | page_urls: text]
[Tag | id: int | title: string]
[Group | id: int | title: string]
[Context | id: int | title: string]
[Description | id: int | locale:str(en) | text: text | license:str(cc0-1.0)]
[Website | id: int | url: string | title: string | strategy: string ]
[Status | id: int | title: string | description: text]
Expand All @@ -149,7 +149,7 @@ For use on [nomnoml](http://www.nomnoml.com/)
[Description]->[Metum]
[Description]->[Status]
[Image]->[Group]
[Image]->[Context]
[Image]->[Website]
[Image] +-> 0..* [Description]
[Image] +-> 0..* [Tag]
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/coyote_bookmarklet.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
"path" : imgObj.src,
"title": imgObj.alt,
"website_id" : coyote.website_id,
"group_id" : "1",
"context_id" : "1",
"canonical_id" : canonical_id,
"page_urls": [ coyote.href ]
}
Expand Down
81 changes: 81 additions & 0 deletions app/controllers/contexts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Handles requests for Context information
# @see Context
class ContextsController < ApplicationController
# NOTE currently there are no controls for who can access Contexts, see https://github.com/coyote-team/coyote/issues/116
before_action :set_context, only: %i[show edit update destroy]
before_filter :get_contexts, only: %i[index]

helper_method :context, :contexts, :users

def_param_group :context do
param :context, Hash do
param :title, String, required: true
param :created_at, DateTime
param :updated_at, DateTime
end
end

# GET /contexts
api :GET, "contexts", "Get an index of contexts"
def index
end

# GET /contexts/1
api :GET, "contexts/:id", "Get a context"
def show
end

# GET /contexts/new
def new
self.context = Context.new
end

# GET /contexts/1/edit
def edit
end

# POST /contexts
api :POST, "contexts/:id", "Create a context"
param_group :context
def create
self.context = Context.new(context_params)

if context.save
redirect_to context, notice: 'Context was successfully created.'
else
render :new
end
end

# PATCH/PUT /contexts/1
api :PUT, "contexts/:id", "Update a context"
param_group :context
def update
if context.update(context_params)
redirect_to context, notice: 'Context was successfully updated.'
else
render :edit
end
end

# DELETE /contexts/1
api :DELETE, "contexts/:id", "Delete a context"
def destroy
context.destroy
redirect_to contexts_url, notice: 'Context was successfully destroyed.'
end

private

attr_accessor :user, :context, :contexts

# Use callbacks to share common setup or constraints between actions.
def set_context
self.context = Context.find(params[:id])
end

# Only allow a trusted parameter "white list" through.
def context_params
params.require(:context).permit(:title)
end
end
76 changes: 0 additions & 76 deletions app/controllers/groups_controller.rb

This file was deleted.

56 changes: 28 additions & 28 deletions app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ class ImagesController < ApplicationController
before_action :set_image, only: [:show, :edit, :update, :destroy, :toggle]
before_action :clear_search, only: [:index]
before_action :get_users, only: [:index, :show], unless: -> { request.xhr? }
before_action :get_groups, only: [:index], unless: -> { request.xhr? }
before_action :get_contexts, only: [:index], unless: -> { request.xhr? }

before_action :admin, only: [:edit, :update, :destroy, :toggle]
before_action :users, only: [:create]

helper_method :contexts

respond_to :html, :json

def_param_group :image do
param :image, Hash do
param :canonical_id, String , required: true
param :path, String , required: true
param :path, String , required: true
param :website_id, Integer, required: true
param :group_id, Integer, required: true
param :context_id, Integer, required: true
param :page_urls, Array
param :priority, [true, false, "1", "0", 1, 0]
param :created_at, DateTime
Expand Down Expand Up @@ -113,7 +115,7 @@ def index
"long": "A long detailed description.",
"path": "55917aaa613430007400000a.jpg?sha=72066b7eb6b6152ed511d52b099365afcd8b23e5",
"url": "http://coyote.mcachicago.org/images/1"
"group_id": 2,
"context_id": 2,
"website_id": 1,
"page_urls": ["http://url1withimage.com/", "http://url2withimage.com/"],
"title": "This is also called a caption",
Expand Down Expand Up @@ -251,18 +253,16 @@ def titles
url += "ids[]=" + i + "&"
end

#request
Rails.logger.info "grabbing images json at #{url}"

begin
content = open(url, { "Content-Type" => "application/json", ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE, read_timeout: 10}).read
#parse
begin
images_received = JSON.parse(content)

#match ids, add titles to image cache, and set titles
canonical_ids.each do |id|
i = images_received.find{|i| i["id"].to_s == id.to_s}
#puts i
i = images_received.find { |ir| ir["id"].to_s == id.to_s}
if i
title = Rails.cache.fetch([id, 'title'].hash, expires_in: 1.minute) do
i["title"]
Expand All @@ -288,34 +288,34 @@ def titles
render :json => ids_titles.to_json
end

def toggle
def toggle
@image.toggle!(params[:column].to_sym)
render nothing: true
end

private
# Use callbacks to share common setup or constraints between actions.
def set_image
@image = Image.find(params[:id])
end
# Use callbacks to share common setup or constraints between actions.
def set_image
@image = Image.find(params[:id])
end

# Only allow a trusted parameter "white list" through.
def image_params
params.require(:image).permit(:path, :group_id, :website_id, :canonical_id, :title, :priority, :page_urls, :tag_list => [])
end
# Only allow a trusted parameter "white list" through.
def image_params
params.require(:image).permit(:path,:context_id,:website_id,:canonical_id,:title,:priority,:page_urls,tag_list: [])
end

def search_params
params[:q]
end

def clear_search
if params[:search_cancel]
params.delete(:search_cancel)
if(!search_params.nil?)
search_params.each do |key, param|
search_params[key] = nil
end
def search_params
params[:q]
end

def clear_search
if params[:search_cancel]
params.delete(:search_cancel)
if(!search_params.nil?)
search_params.each do |key, param|
search_params[key] = nil
end
end
end
end
end
22 changes: 22 additions & 0 deletions app/models/context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# == Schema Information
#
# Table name: contexts
#
# id :integer not null, primary key
# title :string
# created_at :datetime
# updated_at :datetime
#

# Context represents the situation in which a subject is being considered. The Context determines what strategy we use to present a description of a subject.
# Examples of contexts include Web, Exhibitions, Poetry, Digital Interactive, Mobile, Audio Tour
# @see https://github.com/coyote-team/coyote/issues/112
class Context < ActiveRecord::Base
validates_presence_of :title
has_many :images, :dependent => :nullify

# @return [String] title of this context
def to_s
title
end
end
18 changes: 0 additions & 18 deletions app/models/group.rb

This file was deleted.

10 changes: 5 additions & 5 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# id :integer not null, primary key
# path :string
# website_id :integer not null
# group_id :integer not null
# context_id :integer not null
# created_at :datetime
# updated_at :datetime
# canonical_id :string
Expand All @@ -20,7 +20,7 @@
#
# Indexes
#
# index_images_on_group_id (group_id)
# index_images_on_context_id (context_id)
# index_images_on_website_id (website_id)
#

Expand All @@ -31,7 +31,7 @@ class Image < ActiveRecord::Base
before_validation :update_status_code

belongs_to :website, touch: true
belongs_to :group, touch: true
belongs_to :context, touch: true

has_many :descriptions, dependent: :destroy
has_associated_audits
Expand All @@ -40,8 +40,8 @@ class Image < ActiveRecord::Base

validates :path, :presence => true, :uniqueness => {:scope => :website_id}
validates :canonical_id, :presence => true, :uniqueness => {:scope => :website_id}
validates_associated :website, :group
validates_presence_of :website, :group
validates_associated :website, :context
validates_presence_of :website, :context

default_scope {order('priority DESC, created_at DESC')}

Expand Down
2 changes: 1 addition & 1 deletion app/views/application/_nav.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-if admin?
%h2.sr-only Navigation
%ul.nav.navbar-nav
- models = [ "images", "descriptions", "assignments", "users", "groups", "websites" ]
- models = [ "images", "descriptions", "assignments", "users", "contexts", "websites" ]
- models.each do |m|
%li{ class: active_controller_check(m)}<
= link_to m.capitalize, send("#{m}_path")
Expand Down
2 changes: 1 addition & 1 deletion app/views/assignments/_list.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.group
.contexts
-if title
%h4<
Assigned Users:
Expand Down
Loading

0 comments on commit 64c640f

Please sign in to comment.