Permalink
Browse files

Merge commit 'ab908b268cb06ac17aba98cf8be2fb95d1af0cd3' into HEAD

  • Loading branch information...
2 parents 99f0963 + ab908b2 commit cd4d7c7869574753a513f8b6efcbbb65bd085794 Jenkins committed May 18, 2012
View
@@ -28,12 +28,12 @@ gem 'rails', '~> 3.1.1'
gem 'colorize', '~> 0.5.8'
-gem "mongoid", "~> 2.3"
+gem "mongoid", "~> 2.4.2"
gem "mongo", "1.5.2"
gem "bson_ext", "1.5.2"
gem "bson", "1.5.2"
-gem "govuk_content_models", "0.0.1"
+gem "govuk_content_models", "0.0.5"
if ENV['BUNDLE_DEV']
gem 'gds-sso', :path => '../gds-sso'
View
@@ -54,7 +54,7 @@ GEM
activesupport (= 3.1.3)
activesupport (3.1.3)
multi_json (~> 1.0)
- addressable (2.2.7)
+ addressable (2.2.8)
ansi (1.4.1)
arel (2.2.3)
aws-ses (0.4.4)
@@ -94,6 +94,7 @@ GEM
nokogiri (>= 1.5.0)
database_cleaner (0.7.1)
diff-lcs (1.1.3)
+ differ (0.1.2)
erubis (2.7.0)
exception_notification (2.5.2)
actionmailer (>= 3.0.4)
@@ -114,7 +115,7 @@ GEM
lrucache (~> 0.1.1)
null_logger
plek
- gds-sso (0.5.2)
+ gds-sso (0.5.4)
oa-core (~> 0.3.2)
oa-oauth (~> 0.3.2)
oauth2 (= 0.5.2)
@@ -128,14 +129,17 @@ GEM
json
gherkin (2.7.3)
json (>= 1.4.6)
- govuk_content_models (0.0.1)
+ govuk_content_models (0.0.5)
bson_ext
- gds-api-adapters (~> 0.0.47)
+ differ
+ gds-api-adapters
+ gds-sso
mongoid (~> 2.4.10)
- plek (~> 0.1.21)
+ plek (~> 0.1.22)
+ state_machine
hike (1.2.1)
i18n (0.6.0)
- json (1.6.6)
+ json (1.7.3)
launchy (2.0.5)
addressable (~> 2.2.6)
libv8 (3.3.10.4)
@@ -184,7 +188,7 @@ GEM
oauth2 (0.5.2)
faraday (~> 0.7)
multi_json (~> 1.0)
- plek (0.1.21)
+ plek (0.1.22)
builder
polyglot (0.3.3)
rack (1.3.5)
@@ -228,13 +232,14 @@ GEM
simplecov-html (0.4.5)
simplecov-rcov (0.2.3)
simplecov (>= 0.4.1)
- sprockets (2.0.3)
+ sprockets (2.0.4)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.5)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
+ state_machine (1.1.2)
stomp (1.2.0)
term-ansicolor (1.0.7)
test-unit (2.4.5)
@@ -286,13 +291,13 @@ DEPENDENCIES
gds-sso (~> 0.5)
gds-warmup-controller
gelf
- govuk_content_models (= 0.0.1)
+ govuk_content_models (= 0.0.5)
launchy
marples (~> 1.0)
minitest
mocha
mongo (= 1.5.2)
- mongoid (~> 2.3)
+ mongoid (~> 2.4.2)
nokogiri
null_logger
plek (~> 0)
@@ -19,7 +19,7 @@ $(function() {
// no_results_text: "No results matched"
// });
- $('select#artefact_section').chosen({
+ $('select#artefact_sections').chosen({
allow_single_deselect: true,
no_results_text: "Section not found"
});

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -28,7 +28,7 @@ def create
end
def update
- parameters_to_use = params[:artefact] || params.slice(*Artefact.fields.keys)
+ parameters_to_use = extract_parameters(params)
saved = @artefact.update_attributes(parameters_to_use)
flash[:notice] = saved ? 'Panopticon item updated' : 'Failed to save item'
@@ -53,6 +53,19 @@ def find_artefact
end
def build_artefact
- @artefact = Artefact.new(params[:artefact] || params.slice(*Artefact.fields.keys))
+ @artefact = Artefact.new(extract_parameters(params))
end
+
+ def extract_parameters(params)
+ fields_to_update = Artefact.fields.keys + ['sections']
+ parameters_to_use = params[:artefact] || params.slice(*fields_to_update)
+
+ # Strip out the empty submit option for sections
+ ['sections'].each do |param|
+ param_value = parameters_to_use[param]
+ param_value.reject! &:blank? if param_value
+ end
+ parameters_to_use
+ end
+
end
@@ -0,0 +1,23 @@
+module SectionsHelper
+
+ def all_sections(options = {})
+ section_tags = TagRepository.load_all(:type => 'section')
+
+ title_counts = Hash.new(0)
+ section_tags.each { |tag| title_counts[tag.title] += 1 }
+
+ sections = section_tags.map do |tag|
+ # Annotate tags, where necessary, with their IDs
+ if title_counts[tag.title] > 1
+ display_name = "#{tag.title} [#{tag.tag_id}]"
+ else
+ display_name = tag.title
+ end
+ [display_name, tag.tag_id]
+ end
+
+ return sections unless options[:except]
+ sections.reject { |s| s[1] == options[:except] }
+ end
+
+end
@@ -13,7 +13,7 @@
<% end %>
<div class="well">
- <%= semantic_form_for(artefact, :html => { :class => '' }) do |f| %>
+ <%= semantic_form_for(artefact, :html => { :class => '', :id => 'edit_artefact'}) do |f| %>
<%= f.inputs do %>
<%= f.input :name, :input_html => { :class => "span6" } %>
<%= f.input :slug, :input_html => { :class => "span6", :disabled => f.object.persisted? } %>
@@ -25,21 +25,23 @@
<hr>
- <%= f.input :business_proposition, :label => 'Business Content?', :as => :boolean %>
+ <%= f.input :business_proposition, :label => 'Is this business content?', :as => :boolean %>
<hr>
<% if artefact.new_record? %>
<%= f.input :kind, :collection => Artefact::FORMATS.map { |s| [s.humanize, s]}, :as => :select, :class => "span6", :prompt => "Select a kind" %>
<% end %>
- <%= f.input :section, :as => :select, :collection => Section.all.map { |s| [s.to_s, s.slug] }, :prompt => "Select a section" %>
+ <%= f.input :primary_section, :as => :select, :collection => all_sections, :input_html => { :multiple => false, :class => "span6 chzn-select" }, :hint => "This is the primary section the content will live in. This will form the content breadcrumb." %>
+ <input name="artefact[sections][]" type="hidden" value="">
+ <%= f.input :sections, :as => :select, :collection => all_sections(:except=> artefact.primary_section), :input_html => { :multiple => true, :class => "span6 chzn-select" }, :hint => "Pick some extra sections that the content will also appear in." %>
<% end %>
<hr>
<%= f.inputs do %>
<input name="artefact[related_artefact_ids][]" type="hidden" value="">
- <%= f.input :related_artefacts, :collection => Artefact.in_alphabetical_order, :input_html => { :multiple => true, :class => "span6 chzn-select" } %>
+ <%= f.input :related_artefacts, :label => "Related content", :collection => Artefact.in_alphabetical_order, :input_html => { :multiple => true, :class => "span6 chzn-select" }, :hint => "Start typing in to search for and select related links to be associated with this." %>
<%= f.input :relatedness_done, :label => "Is relatedness done?", :as => :boolean %>
<% end %>
@@ -58,8 +60,7 @@
<% end %>
<hr>
-
- <%= f.input :tags, :input_html => {:class => "span6"} %>
+ <%= f.input :tags, :label => "Keyword tags", :input_html => {:class => "span6"}, :hint => "Comma seperated keyword tags." %>
<% if f.object.persisted? %>
<%= f.submit :value => "Save and continue editing", :class => "btn" %>
@@ -70,6 +71,26 @@
<%= content_for :extra_javascript do %>
<%= javascript_include_tag('chosen.jquery.min.js', 'artefacts') %>
- <script type="text/javascript"> $(".chzn-select").chosen(); </script>
+ <script type="text/javascript">
+ $(".chzn-select").chosen();
+
+ // Need to prevent our selected primary section from appearing in the sections box
+ var current_primary_section = $("select#artefact_primary_section option:selected").clone();
+ // onchange event listener of chosen we want to append/remove some section options
+ $("#artefact_primary_section").chosen().change(function() {
+ var new_primary_section = $("select#artefact_primary_section option:selected").clone();
+ new_primary_section.removeAttr('selected');
+ $("select#artefact_sections").find("option[value='" + new_primary_section.val() + "']").remove();
+
+ if (current_primary_section.val() != "") {
+ current_primary_section.removeAttr('selected');
+ $("select#artefact_sections").append(current_primary_section);
+ }
+ current_primary_section = new_primary_section;
+
+ // this trigger will cause chosen to update its own lists
+ $("select#artefact_sections").trigger("liszt:updated");
+ });
+ </script>
<% end %>
<% content_for :extra_headers, stylesheet_link_tag('chosen') %>
View
@@ -64,3 +64,18 @@ Feature: Editing artefacts
# Then I should be redirected to Publisher
# And the API should say that the artefact does not have the contact
# And the rest of the system should be notified that the artefact has been updated
+
+ Scenario: Add a section
+ Given an artefact exists
+ And a section exists
+ When I add the section to the artefact
+ Then I should be redirected to Publisher
+ And the API should say that the artefact has the section
+
+ Scenario: Remove a section
+ Given an artefact exists
+ And a section exists
+ And the artefact has the section
+ When I remove the section from the artefact
+ Then I should be redirected to Publisher
+ And the API should say that the artefact does not have the section
@@ -22,3 +22,11 @@
Then /^the API should say that the artefact does not have the contact$/ do
check_artefact_does_not_have_contact_in_api @artefact, @contact
end
+
+Then /^the API should say that the artefact has the section$/ do
+ check_artefact_has_tag_in_api @artefact, @section.tag_id
+end
+
+Then /^the API should say that the artefact does not have the section$/ do
+ check_artefact_does_not_have_tag_in_api @artefact, @section.tag_id
+end
@@ -88,6 +88,10 @@
flush_notifications
end
+Given /^a section exists$/ do
+ @section = create_section
+end
+
When /^I add the contact to the artefact$/ do
visit edit_artefact_path(@artefact)
select_contact @contact
@@ -99,12 +103,28 @@
flush_notifications
end
+Given /^the artefact has the section$/ do
+ add_section @artefact, @section
+end
+
When /^I remove the contact from the artefact$/ do
visit edit_artefact_path(@artefact)
unselect_contact @contact
submit_artefact_form
end
+When /^I add the section to the artefact$/ do
+ visit edit_artefact_path(@artefact)
+ select_section @section
+ submit_artefact_form
+end
+
+When /^I remove the section from the artefact$/ do
+ visit edit_artefact_path(@artefact)
+ unselect_section @section
+ submit_artefact_form
+end
+
When /^I visit the homepage$/ do
visit root_path
end
View
@@ -7,6 +7,10 @@ def related_artefact_ids_from_api(artefact)
artefact_data_from_api(artefact)[:related_items].map { |related_item| related_item[:artefact][:id] }
end
+def tag_ids_from_api(artefact)
+ artefact_data_from_api(artefact)[:tag_ids].map { |tag| tag['id'] }
+end
+
def contact_id_from_api(artefact)
artefact_data_from_api(artefact)[:contact].try(:[], :id)
end
@@ -41,3 +45,11 @@ def check_artefact_has_contact_in_api(artefact, contact)
def check_artefact_does_not_have_contact_in_api(artefact, contact)
assert_not_equal contact_id_from_api(artefact), contact.id.to_s
end
+
+def check_artefact_has_tag_in_api(artefact, tag_id)
+ assert_include tag_ids_from_api(artefact), tag_id
+end
+
+def check_artefact_does_not_have_tag_in_api(artefact, tag_id)
+ assert_not_include tag_ids_from_api(artefact), tag_id
+end
@@ -31,11 +31,11 @@ def add_related_artefacts(artefact, related_artefacts)
end
def select_related_artefact(artefact)
- select artefact.name, :from => 'Related artefacts'
+ select artefact.name, :from => 'Related content'
end
def unselect_related_artefact(artefact)
- unselect artefact.name, :from => 'Related artefacts'
+ unselect artefact.name, :from => 'Related content'
end
def select_related_artefacts(artefacts)
@@ -0,0 +1,16 @@
+def create_section
+ TagRepository.put :tag_id => 'crime', :tag_type => 'section', :title => 'Crime'
+ return TagRepository.load 'crime'
+end
+
+def select_section(section)
+ select section.title, :from => 'Sections'
+end
+
+def unselect_section(section)
+ unselect section.title, :from => 'Sections'
+end
+
+def add_section(artefact, section)
+ artefact.sections += [section.tag_id]
+end
Oops, something went wrong.

0 comments on commit cd4d7c7

Please sign in to comment.