Skip to content
Browse files

Merge branch 'archive_artefacts'

  • Loading branch information...
2 parents cddaf70 + 688241f commit 9df463d05e82658f9cd3740e008ae1d6fe7b01c2 Mazz committed Sep 4, 2012
View
2 Gemfile
@@ -34,7 +34,7 @@ gem 'lograge'
if ENV['CONTENT_MODELS_DEV']
gem "govuk_content_models", path: '../govuk_content_models'
else
- gem "govuk_content_models", "1.4.0"
+ gem "govuk_content_models", "1.7.1"
end
if ENV['BUNDLE_DEV']
View
10 Gemfile.lock
@@ -118,15 +118,15 @@ GEM
json
gherkin (2.11.1)
json (>= 1.4.6)
- govspeak (0.8.18)
+ govspeak (1.0.0)
htmlentities (~> 4)
kramdown (~> 0.13.3)
- govuk_content_models (1.4.0)
+ govuk_content_models (1.7.1)
bson_ext
differ
gds-api-adapters
gds-sso (>= 0.7, < 2.0)
- govspeak (~> 0.8.15)
+ govspeak (>= 0.8.15, < 2.0.0)
mongoid (~> 2.4.10)
omniauth-oauth2 (~> 1.0)
plek (>= 0.1.22, < 0.4)
@@ -142,7 +142,7 @@ GEM
jwt (0.1.5)
multi_json (>= 1.0)
kgio (2.7.4)
- kramdown (0.13.7)
+ kramdown (0.13.8)
launchy (2.1.2)
addressable (~> 2.3)
libv8 (3.3.10.4)
@@ -317,7 +317,7 @@ DEPENDENCIES
gds-sso (~> 1.2.0)
gds-warmup-controller (= 0.1.0)
gelf
- govuk_content_models (= 1.4.0)
+ govuk_content_models (= 1.7.1)
launchy
lograge
minitest
View
4 app/assets/stylesheets/application.css
@@ -53,4 +53,8 @@ table thead tr .header.headerSortDown {
background: url(desc.gif) no-repeat right 75%;
}
+table#artefact-list tr.archived {
+ opacity: 0.5;
+}
+
/* end of tablesorter styling */
View
3 app/controllers/artefacts_controller.rb
@@ -72,7 +72,8 @@ def destroy
@artefact = Artefact.from_param(params[:id])
@artefact.update_attributes_as(action_user, state: "archived")
respond_with(@artefact) do |format|
- format.html { head 200 }
+ format.json { head 200 }
+ format.html { redirect_to artefacts_path }
end
end
View
12 app/observers/remove_related_artefacts_observer.rb
@@ -0,0 +1,12 @@
+class RemoveRelatedArtefactsObserver < Mongoid::Observer
+ observe :artefact
+
+ def after_save(artefact)
+ if artefact.state == 'archived'
+ Artefact.where(:related_artefact_ids.in => [artefact.id]).each do | a |
+ a.related_artefact_ids.delete(artefact.id)
+ a.save
+ end
+ end
+ end
+end
View
8 app/views/artefacts/_archive.html.erb
@@ -0,0 +1,8 @@
+<div class="well">
+ <div class="alert alert-error">
+ <h4>Careful!</h4>
+ This will remove this content from the website. Once you've unpublished you can't change your mind.
+ </div>
+ <%= button_to('Archive', artefact_path(artefact), :method => "delete",
+ :class => "btn btn-danger") %>
+</div>
View
106 app/views/artefacts/_form.html.erb
@@ -12,74 +12,80 @@
</div>
<% end %>
-<div class="well">
- <%= 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.live? }, :hint => "A valid slug might look like this: i-am-a-good-slug-with-no-spaces" %>
- <%= f.input :need_id, :input_html => { :class => "span6", :disabled => f.object.persisted? } %>
- <% if ! artefact.new_record? && ! artefact.business_proposition %>
- <%= link_to "View in Need-O-Tron", need_url(f.object), :rel => 'external', :class => "btn btn-primary" %>
- <% end %>
- <%= link_to "View on site", published_url(f.object), :rel => 'external', :class => "btn btn-primary" unless f.object.new_record? %>
+ <% if artefact.archived? %>
+ <div class="alert alert-error">
+ <h2>Stop! You can't edit this artefact because it has been archived.</h2>
+ </div>
+ <% else %>
+ <div class="well">
+ <%= 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.live? }, :hint => "A valid slug might look like this: i-am-a-good-slug-with-no-spaces" %>
+ <%= f.input :need_id, :input_html => { :class => "span6", :disabled => f.object.persisted? } %>
+ <% if ! artefact.new_record? && ! artefact.business_proposition %>
+ <%= link_to "View in Need-O-Tron", need_url(f.object), :rel => 'external', :class => "btn btn-primary" %>
+ <% end %>
+ <%= link_to "View on site", published_url(f.object), :rel => 'external', :class => "btn btn-primary" unless f.object.new_record? %>
- <hr>
+ <hr>
- <%= f.input :business_proposition, :label => 'Is this business content?', :as => :boolean %>
+ <%= f.input :business_proposition, :label => 'Is this business content?', :as => :boolean %>
- <hr>
- <input type="hidden" name="artefact[sections][]" value="" />
- <% if artefact.new_record? %>
- <%= f.input :kind, :collection => Artefact::FORMATS.map { |s| [s.humanize, s]}, :as => :select, :class => "span6", :prompt => "Select a kind" %>
- <% end %>
+ <hr>
+ <input type="hidden" name="artefact[sections][]" value="" />
+ <% if artefact.new_record? %>
+ <%= f.input :kind, :collection => Artefact::FORMATS.map { |s| [s.humanize, s]}, :as => :select, :class => "span6", :prompt => "Select a kind" %>
+ <% end %>
- <label for="artefact[sections][]">Sections</label>
- <p>The first section will be the primary section the content lives in. This will form the content breadcrumb.</p>
- <% if artefact.section_ids.length > 0 %>
- <% artefact.section_ids.each do | section_id | %>
- <%= render :partial => 'artefact_section', :locals => {:section_id => section_id, :tag_collection => tag_collection} %>
+ <label for="artefact[sections][]">Sections</label>
+ <p>The first section will be the primary section the content lives in. This will form the content breadcrumb.</p>
+ <% if artefact.section_ids.length > 0 %>
+ <% artefact.section_ids.each do | section_id | %>
+ <%= render :partial => 'artefact_section', :locals => {:section_id => section_id, :tag_collection => tag_collection} %>
+ <% end %>
+ <% else %>
+ <%= render :partial => 'artefact_section', :locals => {:section_id => nil, :tag_collection => tag_collection} %>
<% end %>
- <% else %>
- <%= render :partial => 'artefact_section', :locals => {:section_id => nil, :tag_collection => tag_collection} %>
- <% end %>
- <button id="add-section" class="btn btn-success">Add another section</button>
- <% end %>
+ <button id="add-section" class="btn btn-success">Add another section</button>
+ <% end %>
- <hr>
+ <hr>
- <%= f.inputs do %>
- <input name="artefact[related_artefact_ids][]" type="hidden" value="">
- <%= 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 %>
+ <%= f.inputs do %>
+ <input name="artefact[related_artefact_ids][]" type="hidden" value="">
+ <%= 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 %>
- <hr>
+ <hr>
- <%= f.input :legacy_source_ids, :label => "Legacy sources", :collection => options_for_tags_of_type('legacy_source'), :input_html => { :multiple => true, :class => "span6 chzn-select" } %>
+ <%= f.input :legacy_source_ids, :label => "Legacy sources", :collection => options_for_tags_of_type('legacy_source'), :input_html => { :multiple => true, :class => "span6 chzn-select" } %>
- <hr>
+ <hr>
- <%= f.inputs do %>
+ <%= f.inputs do %>
- <%= f.input :department, :label => "Writing team", :input_html => { :disabled => f.object.persisted?, :class => "span6"} %>
- <%= f.input :fact_checkers, :input_html => { :disabled => f.object.persisted?, :class => "span6"} %>
- <%= f.input :contact, :as => :hidden, :collection => Contact.in_alphabetical_order %>
+ <%= f.input :department, :label => "Writing team", :input_html => { :disabled => f.object.persisted?, :class => "span6"} %>
+ <%= f.input :fact_checkers, :input_html => { :disabled => f.object.persisted?, :class => "span6"} %>
+ <%= f.input :contact, :as => :hidden, :collection => Contact.in_alphabetical_order %>
- <% end %>
+ <% end %>
- <% if artefact.new_record? %>
- <%= f.input :owning_app, :as => :hidden, :input_html => {:value => "publisher"} %>
- <% end %>
+ <% if artefact.new_record? %>
+ <%= f.input :owning_app, :as => :hidden, :input_html => {:value => "publisher"} %>
+ <% end %>
- <hr>
+ <hr>
- <% if f.object.persisted? %>
- <%= f.submit :value => "Save and continue editing", :class => "btn" %>
+ <% if f.object.persisted? %>
+ <%= f.submit :value => "Save and continue editing", :class => "btn" %>
+ <% end %>
+ <%= f.submit :value => "Save and go to item", :class => "btn btn-success" %>
<% end %>
- <%= f.submit :value => "Save and go to item", :class => "btn btn-success" %>
- <% end %>
-</div>
+ </div>
+<% end %>
<%= content_for :extra_javascript do %>
<%= javascript_include_tag('chosen.jquery.min.js', 'artefacts') %>
View
8 app/views/artefacts/edit.html.erb
@@ -6,6 +6,9 @@
<ul class="nav nav-tabs">
<li class="active"><a href="#edit" data-toggle="tab">Edit</a></li>
<li><a href="#history" data-toggle="tab">History</a></li>
+ <% if @artefact.state != "archived" %>
+ <li><a href="#archive" data-toggle="tab">Archive</a></li>
+ <% end %>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="edit">
@@ -14,5 +17,10 @@
<div class="tab-pane" id="history">
<%= render 'history', actions: @actions %>
</div>
+ <% if @artefact.state != "archived" %>
+ <div class="tab-pane" id="archive">
+ <%= render 'archive', artefact: @artefact %>
+ </div>
+ <% end %>
</div>
</div>
View
2 app/views/artefacts/index.html.erb
@@ -35,7 +35,7 @@
</thead>
<tbody>
<% @artefacts.each do |artefact| %>
- <tr>
+ <tr class="<%= artefact.state %>">
<td><%= artefact.need_id %></td>
<td><%= link_to artefact.name, edit_artefact_path(artefact.id) %></td>
<td class="icon">
View
4 config/application.rb
@@ -59,5 +59,9 @@ class Application < Rails::Application
# Disable Rack::Cache.
config.action_dispatch.rack_cache = nil
+
+ # Upon archiving an artefact we want this observer to run to remove
+ # any related items that also point to that artefact.
+ config.mongoid.observers << :remove_related_artefacts_observer
end
end
View
4 test/functional/artefacts_controller_test.rb
@@ -278,13 +278,13 @@ class ArtefactsControllerTest < ActionController::TestCase
name: "Whatever",
need_id: 1
)
- delete :destroy, id: artefact.id, "CONTENT_TYPE" => "application/json"
+ delete :destroy, id: artefact.id, format: "json"
assert_equal 200, response.status
assert_equal "archived", artefact.reload.state
end
should "return a 404" do
- delete :destroy, id: "4567", "CONTENT_TYPE" => "application/json"
+ delete :destroy, id: "4567", format: "json"
assert_equal 404, response.status
end
end

0 comments on commit 9df463d

Please sign in to comment.
Something went wrong with that request. Please try again.