changeset 445:77f88379115a feature_36

Merged my forks. More work in the controllers and views of the publications model.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 08 Jun 2011 11:35:04 +0100
parents b461f84ed41a (diff) 948400933de8 (current diff)
children 995d4c99843d
files vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb vendor/plugins/redmine_bibliography/app/models/author.rb vendor/plugins/redmine_bibliography/app/models/publication.rb vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb
diffstat 9 files changed, 74 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Fri Jun 03 18:16:34 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb	Wed Jun 08 11:35:04 2011 +0100
@@ -5,19 +5,34 @@
   unloadable
 
   def new
-    # we always try to create at least one publication
-    @publication = Publication.new
-
+    @publication = Publication.new      
+    
+    # we'll always want a new publication to have its bibtex entry
+    @publication.build_bibtex_entry
+    
     # the step we're at in the form
     @publication.current_step = session[:publication_step]
 
     @new_publications = []
     session[:publications] ||= {}
-      
   end
 
   def create
     @publication = Publication.new(params[:publication])
+
+    if @publication.save
+      flash[:notice] = "Successfully created publication."
+      redirect_to @publication
+    else
+      render :action => 'new'
+    end
+  end
+
+  def index
+    @publications = Publication.find(:all)
+  end
+
+  def new_from_bibfile
     @publication.current_step = session[:publication_step]
     
     # contents of the paste text area
@@ -38,37 +53,21 @@
     end
 
     session[:publication_step] = @publication.current_step
-
-    if @publication.new_record?
-      render "new"
-    else
-      session[:publication_step] = session[:publication_params] = nil
-      flash[:notice] = "New publication saved!"
-      redirect_to @publication
-    end
+    
   end
 
-  def index
-    @publications = Publication.find(:all)
-  end
 
-  def edit
+  def edit    
     @publication = Publication.find(params[:id])
   end
 
-  def update
-    
-    logger.error "------>>>> NO UPDATE"
-    
+  def update    
     @publication = Publication.find(params[:id])
-    
-    logger.error @publication
-    
+        
     if @publication.update_attributes(params[:publication])
       flash[:notice] = "Successfully updated Publication."
-      redirect_to :action => :show, :id => @publication.id
     else
-      render :action => 'edit' 
+      flash[:notice] = "Could not Update Publication."
     end
     
   end
@@ -153,10 +152,10 @@
       end
 
       author.authorships.create!(
-      :publication => @publication,
-      :institution => institution,
-      :email => email,
-      :order => idx)
+        :publication => @publication,
+        :institution => institution,
+        :email => email,
+        :order => idx)
 
     end
   end
@@ -166,6 +165,11 @@
 
   end
 
+  def import
+    @publication = Publication.new
+    
+    
+  end
 
   def review_new_entries
 
--- a/vendor/plugins/redmine_bibliography/app/models/author.rb	Fri Jun 03 18:16:34 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/author.rb	Wed Jun 08 11:35:04 2011 +0100
@@ -2,6 +2,6 @@
   has_many :authorships
   has_many :publications, :through => :authorships
 
-  belongs_to :user
+  # belongs_to :user
   
 end
--- a/vendor/plugins/redmine_bibliography/app/models/publication.rb	Fri Jun 03 18:16:34 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/models/publication.rb	Wed Jun 08 11:35:04 2011 +0100
@@ -2,15 +2,18 @@
 
 class Publication < ActiveRecord::Base
   unloadable
-
-
+  
   has_many :authorships
   has_many :authors, :through => :authorships
-  has_one :bibtex_entry
+  has_one :bibtex_entry, :dependent => :destroy
 
   validates_presence_of :title
+
+  accepts_nested_attributes_for :authorships
+  accepts_nested_attributes_for :authors, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
+#  accepts_nested_attributes_for :bibtex_entry, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true 
   
-  accepts_nested_attributes_for :authors, :bibtex_entry
+  
   
   attr_writer :current_step
 
--- a/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb	Fri Jun 03 18:16:34 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb	Wed Jun 08 11:35:04 2011 +0100
@@ -1,39 +1,35 @@
-
-<% form_for @publication, :url => {:action => :update }, :id => 13 do |f| -%>
+<% form_for @publication do |f| -%>
   <%= f.error_messages %>
   <p>
     <%= f.label :title, l(:title) %>  <%= f.text_field :title %>  
   </p>
   
-
-  <h3><%= l(:authors) -%></h3>
+  <h3><%= l(:authors) %></h3>
   
-  <% f.fields_for :authors do |author| %>
+  <%- f.fields_for :authors do |author| -%>
     <p>
       <%= author.label :name, l("name") %> <%= author.text_field :name %>            
     </p>
-    
-  <% end %>
+  <%- end -%>
   
-  
-  <% f.fields_for @publication.bibtex_entry do |b| -%>
+  <% f.fields_for :bibtex_entry do |bib| -%>
     <p> 
-      <%= b.label :year, l(:year) %>  <%= b.text_field :year %>  
+      <%= bib.label :year, l(:year) %>  <%= bib.text_field :year %>  
     </p>
     <p> 
-      <%= b.label :chapter, l(:chapter) %>  <%= b.text_field :chapter %>  
+      <%= bib.label :chapter, l(:chapter) %>  <%= bib.text_field :chapter %>  
     </p>
     <p>  
-      <%= b.label :editor, l(:editor) %>  <%= b.text_field :editor %>  
+      <%= bib.label :editor, l(:editor) %>  <%= bib.text_field :editor %>  
     </p>
     <p> 
-      <%= b.label :booktitle, l(:booktitle) %>  <%= b.text_field :booktitle %>  
+      <%= bib.label :booktitle, l(:booktitle) %>  <%= bib.text_field :booktitle %>  
     </p>
     <p> 
-      <%= b.label :publisher, l(:publisher) %>  <%= b.text_field :publisher %>  
+      <%= bib.label :publisher, l(:publisher) %>  <%= bib.text_field :publisher %>  
     </p>
     <p> 
-      <%= b.label :pages, l(:pages) %>  <%= b.text_field :pages %>  
+      <%= bib.label :pages, l(:pages) %>  <%= bib.text_field :pages %>  
     </p>
   <% end -%>
 
--- a/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Fri Jun 03 18:16:34 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb	Wed Jun 08 11:35:04 2011 +0100
@@ -2,7 +2,6 @@
 
 <%= render :partial => 'edit' %>
 
-
 <p>
   <%= link_to :show %></p>
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/import.html.erb	Wed Jun 08 11:35:04 2011 +0100
@@ -0,0 +1,12 @@
+<h1>New Publication</h1>
+
+<% form_for @publication, :url => { :action => "create" } do |f| %>
+  <% f.error_messages %>
+
+  <%= render :partial  => "#{@publication.current_step}_bibtex_step", :locals => { :f => f }  %>
+
+  <p><%= f.submit "Submit" %></p>
+  <p><%= f.submit "Back", :name => "back_button" unless @publication.first_step? %></p>
+  
+<% end %>
+
--- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Fri Jun 03 18:16:34 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb	Wed Jun 08 11:35:04 2011 +0100
@@ -1,12 +1,3 @@
 <h1>New Publication</h1>
 
-<% form_for @publication, :url => { :action => "create" } do |f| %>
-  <% f.error_messages %>
-
-  <%= render :partial  => "#{@publication.current_step}_bibtex_step", :locals => { :f => f }  %>
-
-  <p><%= f.submit "Submit" %></p>
-  <p><%= f.submit "Back", :name => "back_button" unless @publication.first_step? %></p>
-  
-<% end %>
-
+<%= render :partial => 'edit' %>
--- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Fri Jun 03 18:16:34 2011 +0100
+++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb	Wed Jun 08 11:35:04 2011 +0100
@@ -1,20 +1,21 @@
 <h2>Publication Details</h2>
 <h4>Title</h4>
-<%= @publication.title %>
+<%= h @publication.title %>
 
 <h4>Authors</h4>
 <% @publication.authors.each do |author| %>
-<%= author.name  %> <br />
+<%= h author.name  %> <br />
 <% end %>
 <br />
 
+<%- if @publication.bibtex_entry != nil -%>
 <% @publication.bibtex_entry.attributes.each do |field| %>
   <% if field[1] != nil %>
     <h4><%= field[0] %></h4>
     <%= @publication.bibtex_entry.attributes[field[0]] unless field[1] == nil %>
     <br />
-  <% end %>
-<% end %>
+  <%- end -%>
+<%- end -%>
+<%- end -%>
 
 
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/plugins/redmine_bibliography/config/routes.rb	Wed Jun 08 11:35:04 2011 +0100
@@ -0,0 +1,3 @@
+ActionController::Routing::Routes.draw do |map|
+  map.resources :publications
+end
\ No newline at end of file