diff --git a/app/assets/javascripts/licenses.js.coffee b/app/assets/javascripts/licenses.js.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/licenses.js.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/licenses.css.scss b/app/assets/stylesheets/licenses.css.scss new file mode 100644 index 00000000..9adc9967 --- /dev/null +++ b/app/assets/stylesheets/licenses.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the licenses 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/application_controller.rb b/app/controllers/application_controller.rb index dd4cd0b1..34bd1cb7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,11 +7,18 @@ class ApplicationController < ActionController::Base before_filter :fetch_categories def fetch_categories - @categories = Rails.cache.fetch([:categories, :list], expires_in: 5.minutes) do + @categories = Rails.cache.fetch([I18n.locale, :categories, :list], expires_in: 5.minutes) do Category.order("name ASC").load end end + before_filter :fetch_licenses + def fetch_licenses + @licenses = Rails.cache.fetch([I18n.locale, :licenses, :list], expires_in: 5.minutes) do + License.order("id ASC").load + end + end + before_filter :google_analytics_identification def google_analytics_identification if $gabba.present? diff --git a/app/controllers/licenses_controller.rb b/app/controllers/licenses_controller.rb new file mode 100644 index 00000000..f9bdca63 --- /dev/null +++ b/app/controllers/licenses_controller.rb @@ -0,0 +1,12 @@ +class LicensesController < ApplicationController + respond_to :html + + def show + @license = License.friendly.find(params[:id]) + authorize! :read, @license + + respond_with @license do |f| + f.html { redirect_to license_photographs_path(@license) } + end + end +end diff --git a/app/controllers/photographs_controller.rb b/app/controllers/photographs_controller.rb index 901ea0de..7377527d 100644 --- a/app/controllers/photographs_controller.rb +++ b/app/controllers/photographs_controller.rb @@ -9,7 +9,7 @@ class PhotographsController < ApplicationController before_filter :set_parents def set_parents if params[:collection_id].present? - @collection = Collection.find(params[:collection_id]) + @collection = Collection.friendly.find(params[:collection_id]) authorize! :read, @collection end @@ -25,22 +25,31 @@ def set_parents end if params[:category_id].present? - @category = Category.find(params[:category_id]) + @category = Category.friendly.find(params[:category_id]) + end + + if params[:license_id].present? + @license = License.friendly.find(params[:license_id]) end end def index - if @collection.present? + case + when @collection.present? @photographs = @collection.photographs set_title(@collection.name) hide_filters! - elsif @user.present? + when @user.present? @photographs = @user.photographs set_title(@user.name) hide_filters! - elsif @category.present? + when @category.present? @photographs = @category.photographs set_title(@category.name) + when @license.present? + @photographs = @license.photographs + set_title(@license.name) + hide_filters! else @photographs = Photograph.all end diff --git a/app/helpers/licenses_helper.rb b/app/helpers/licenses_helper.rb new file mode 100644 index 00000000..8937fda9 --- /dev/null +++ b/app/helpers/licenses_helper.rb @@ -0,0 +1,2 @@ +module LicensesHelper +end diff --git a/app/models/ability.rb b/app/models/ability.rb index ba665aff..be65eec9 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -6,6 +6,7 @@ def initialize(user) alias_action :create, :read, :update, :destroy, to: :crud can :read, Category + can :read, License can :read, Photograph do |photograph| photograph.visible? end diff --git a/app/models/license.rb b/app/models/license.rb index fd71dc91..0e842286 100644 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,3 +1,9 @@ class License < ActiveRecord::Base + extend FriendlyId + has_many :photographs + + friendly_id :code, use: [:slugged, :finders] + + validates :name, :code, presence: true end diff --git a/app/views/shared/_nav.html.slim b/app/views/shared/_nav.html.slim index 0c079c7a..09a1436e 100644 --- a/app/views/shared/_nav.html.slim +++ b/app/views/shared/_nav.html.slim @@ -54,6 +54,19 @@ nav id="layout-nav" class="top-bar" = link_to category.name, category_path(category.slug), active_on: category_photographs_path(category.slug), \ active_wrapper: :li + - if @licenses.present? + div class="row" + div class="large-12 columns" + label= t("nav.license") + + div class="row" + - @licenses.each_slice((@licenses.size / 2) + 1) do |licenses| + div class="large-6 columns" + ul class="sub-nav" + - licenses.each do |license| + = link_to license.code, license_path(license), active_on: license_photographs_path(license), \ + active_wrapper: :li + = link_to t("nav.recommended"), recommended_photographs_path, active_on: true, \ active_wrapper: :li diff --git a/config/locales/en.yml b/config/locales/en.yml index 97bf0e8a..6272d3f8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -77,6 +77,7 @@ en: dashboard: "Dashboard" seeking_feedback: "Photographs seeking feedback" about: "About" + license: "Explore by License" beta_notes: title: "This is an early stage beta!" diff --git a/config/routes.rb b/config/routes.rb index a0f0c90e..1c6e39de 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -49,6 +49,10 @@ resources :collections, only: [:index] end + resources :licenses, only: [:show] do + resources :photographs, only: [:index] + end + resources :notifications, only: [:index, :show] do collection do get :mark_all_as_read diff --git a/db/migrate/20131103133641_add_slug_to_licenses.rb b/db/migrate/20131103133641_add_slug_to_licenses.rb new file mode 100644 index 00000000..2a35ea1a --- /dev/null +++ b/db/migrate/20131103133641_add_slug_to_licenses.rb @@ -0,0 +1,6 @@ +class AddSlugToLicenses < ActiveRecord::Migration + def change + add_column :licenses, :slug, :string + add_index :licenses, :slug + end +end diff --git a/db/structure.sql b/db/structure.sql index a7d2ede1..b46d446d 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -388,7 +388,8 @@ CREATE TABLE licenses ( name character varying(255), code character varying(255), created_at timestamp without time zone, - updated_at timestamp without time zone + updated_at timestamp without time zone, + slug character varying(255) ); @@ -1201,6 +1202,13 @@ CREATE INDEX index_followings_on_followee_id ON followings USING btree (followee CREATE INDEX index_followings_on_follower_id ON followings USING btree (follower_id); +-- +-- Name: index_licenses_on_slug; Type: INDEX; Schema: public; Owner: -; Tablespace: +-- + +CREATE INDEX index_licenses_on_slug ON licenses USING btree (slug); + + -- -- Name: index_metadata_on_photograph_id; Type: INDEX; Schema: public; Owner: -; Tablespace: -- @@ -1567,3 +1575,5 @@ INSERT INTO schema_migrations (version) VALUES ('20130826172509'); INSERT INTO schema_migrations (version) VALUES ('20130830080641'); INSERT INTO schema_migrations (version) VALUES ('20131022130051'); + +INSERT INTO schema_migrations (version) VALUES ('20131103133641'); diff --git a/lib/tasks/iso.rake b/lib/tasks/iso.rake index 1ad24488..3b033341 100644 --- a/lib/tasks/iso.rake +++ b/lib/tasks/iso.rake @@ -1,7 +1,7 @@ namespace :iso do namespace :maintenance do - task :create_stories => :environment do - Notification.find_each(&:create_story) + task :repair_licenses => :environment do + License.find_each(&:save) end task :repair_image_permissions => :environment do diff --git a/spec/controllers/licenses_controller_spec.rb b/spec/controllers/licenses_controller_spec.rb new file mode 100644 index 00000000..433094bf --- /dev/null +++ b/spec/controllers/licenses_controller_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe LicensesController do + describe "GET show" do + let(:license) { License.make } + + before { License.stub_chain(:friendly, :find) { license } } + before { get :show, id: 1 } + + it "redirects to photographs path" do + response.should redirect_to license_photographs_path(license) + end + end +end diff --git a/spec/helpers/licenses_helper_spec.rb b/spec/helpers/licenses_helper_spec.rb new file mode 100644 index 00000000..832b7963 --- /dev/null +++ b/spec/helpers/licenses_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the LicensesHelper. For example: +# +# describe LicensesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe LicensesHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/support/blueprints.rb b/spec/support/blueprints.rb index 895948f4..126a676c 100644 --- a/spec/support/blueprints.rb +++ b/spec/support/blueprints.rb @@ -34,6 +34,12 @@ follower end +License.blueprint do + name { "Attribution" } + code { "CC-BY" } + slug { "cc-by" } +end + Metadata.blueprint do photograph title { Faker::Lorem.sentence }