# HG changeset patch # User Chris Cannam # Date 1311972048 -3600 # Node ID a1e091bee818ffe5699ac43839798c76035bc705 # Parent 168714032c7e4a7ad7f91f35bfe1fdec6c99f33a# Parent 56ad0c490f5e65dc5514b53031d92531bff4daa0 Merge from branch "feature_36" diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb --- a/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/controllers/publications_controller.rb Fri Jul 29 21:40:48 2011 +0100 @@ -3,33 +3,29 @@ class PublicationsController < ApplicationController unloadable - # before_filter :find_project_by_project_id, :except => [:autocomplete_for_project, :add_author, :sort_authors, :autocomplete_for_author] + # before_filter :find_project, :except => [:autocomplete_for_project, :add_author, :sort_authors, :autocomplete_for_author] def new - @publication = Publication.new + find_project_by_project_id + @publication = Publication.new # we'll always want a new publication to have its bibtex entry - # @publication.build_bibtex_entry + @publication.build_bibtex_entry # and at least one author # @publication.authorships.build.build_author @project_id = params[:project_id] - @current_user = User.current + @current_user = User.current end - def create + def create + find_project_by_project_id + @publication = Publication.new(params[:publication]) - - logger.error { "PUBLICATION CREATE ACTION" } - logger.error { params[:publication] } - - @project = Project.find(params[:project_id]) - logger.error { "PARAMS publication" } - logger.error { params[:publication] } - + # @project = Project.find(params[:project_id]) @publication.projects << @project if @publication.save @@ -41,8 +37,13 @@ end def index - @project = Project.find(params[:project_id]) - @publications = Publication.find :all, :joins => :projects, :conditions => ["project_id = ?", @project.id] + if !params[:project_id].nil? + find_project_by_project_id + @project = Project.find(params[:project_id]) + @publications = Publication.find :all, :joins => :projects, :conditions => ["project_id = ?", @project.id] + else + @publications = Publication.find :all + end end def new_from_bibfile @@ -67,15 +68,26 @@ end end - def edit + def edit + find_project_by_project_id unless params[:project_id].nil? + @publication = Publication.find(params[:id]) + @selected_bibtex_entry_type_id = @publication.bibtex_entry.entry_type end def update @publication = Publication.find(params[:id]) + + logger.error { "INSIDE THE UPDATE ACTION IN THE PUBLICATION CONTROLLER" } + if @publication.update_attributes(params[:publication]) flash[:notice] = "Successfully updated Publication." - redirect_to @publication + + if !params[:project_id].nil? + redirect_to :action => :show, :id => @publication, :project_id => params[:project_id] + else + redirect_to :action => :show, :id => @publication + end else render :action => 'edit' end @@ -85,18 +97,13 @@ find_project_by_project_id unless params[:project_id].nil? @publication = Publication.find(params[:id]) - + if @publication.nil? @publications = Publication.all - render "index", :alert => 'Your Publications was not found!' + render "index", :alert => 'The publication was not found!' else @authors = @publication.authors @bibtext_entry = @publication.bibtex_entry - - respond_to do |format| - format.html - format.xml {render :xml => @publication} - end end end @@ -230,18 +237,6 @@ end + private - - private - - # TODO: luisf. - only here for debugging purposes - # Find project of id params[:project_id] - def find_project_by_project_id - - logger.error { "FIND PROJECT BY PROJECT ID" } - - @project = Project.find(params[:project_id]) - rescue ActiveRecord::RecordNotFound - render_404 - end end diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/helpers/authors_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/authors_helper.rb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/authors_helper.rb Fri Jul 29 21:40:48 2011 +0100 @@ -1,2 +1,20 @@ module AuthorsHelper + unloadable + + def render_author_publications(author) + s = "" + pubs = [] + + author.publications.each do |pub| + pubs << link_to(pub.title, pub) + end + + if pubs.size < 3 + s << '' << pubs.join(', ') << '' + else + s << pubs.join(', ') + end + s + end + end diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb --- a/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/helpers/publications_helper.rb Fri Jul 29 21:40:48 2011 +0100 @@ -61,6 +61,38 @@ str = "#{sanitized_object_name(object_name.to_s)}_#{sanitized_method_name(method_name.to_s)}" str.to_sym end + + def render_projects_list(publication) + s = "" + projs = [] + + publication.projects.each do |proj| + projs << link_to_project(proj) + end + + if projs.size < 3 + s << '' << projs.join(', ') << '' + else + s << projs.join(', ') + end + s + end + + def show_bibtex_fields(bibtex_entry) + s = "" + bibtex_entry.attributes.each do |field| + if field[1] != nil + s << "

" + field[0].titleize + "

" + + if field[0] == "entry_type" + s << bibtex_entry.entry_type_name.capitalize + else + s << bibtex_entry.attributes[field[0]].to_s + end + end + end + s + end end diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb --- a/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry.rb Fri Jul 29 21:40:48 2011 +0100 @@ -1,4 +1,14 @@ class BibtexEntry < ActiveRecord::Base + unloadable + belongs_to :publication + validates_presence_of :entry_type + + def entry_type_name + entry_type = self.entry_type + BibtexEntryType.find(entry_type).name + end + + end diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb Fri Jul 29 21:40:48 2011 +0100 @@ -0,0 +1,2 @@ +class BibtexEntryType < ActiveRecord::Base +end diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/authors/index.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/authors/index.html.erb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/authors/index.html.erb Fri Jul 29 21:40:48 2011 +0100 @@ -1,5 +1,26 @@

Authors#index

-<% @authors.each do |author| %> -

<%= author.name %> - <%= author.publications.first.title%>

-<% end %> \ No newline at end of file + + + + + + + + + <% @authors.each do |author|%> + + + + + + <% end %> + +
<%=l(:field_author_name)%><%=l(:field_author_username)%><%=l(:field_author_publications)%>
+ <%= h author.name %> + + <%= link_to author.user unless author.user.nil? %> + + <%= render_author_publications(author) %> +
+ diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/projects/show.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/projects/show.rhtml Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/projects/show.rhtml Fri Jul 29 21:40:48 2011 +0100 @@ -2,6 +2,9 @@ <% if User.current.allowed_to?(:add_subprojects, @project) %> <%= link_to l(:label_subproject_new), {:controller => 'projects', :action => 'new', :parent_id => @project}, :class => 'icon icon-add' %> <% end %> + + <%= link_to l(:label_add_publication_to_project), {:controller => 'publications', :action => 'new', :project_id => @project}, :class => 'icon icon-add' %> +

<%=l(:label_overview)%>

diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml --- a/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_authorship_fields.rhtml Fri Jul 29 21:40:48 2011 +0100 @@ -1,6 +1,5 @@

- <%= f.label :name_on_paper, l("name") %> <%= f.text_field :name_on_paper %>
<%= h l("text_author_name_on_paper") %>
@@ -15,12 +14,10 @@ <% end %>

- <%= f.label :institution, l("institution") %> - <%= f.text_field :institution %>
+ <%= f.text_field :institution, :size => 60 %>
<%= h l("text_author_institution") %>
- <%= f.label :email, l("email") %> - <%= f.text_field :email %>
+ <%= f.text_field :email, :size => 60 %>
<%= h l("text_author_email") %>
<%= f.hidden_field :user_id %> diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_bibtex_fields.html.erb Fri Jul 29 21:40:48 2011 +0100 @@ -1,18 +1,26 @@ +
+ + +

+ <%= f.collection_select(:entry_type, BibtexEntryType.find(:all), :id, :name, {:selected => @selected_bibtex_entry_type_id, :prompt => true}) %> +

- <%= f.label :year, l(:year) %> <%= f.text_field :year %> + <%= f.text_field :year, :size => 60 %>

- <%= f.label :chapter, l(:chapter) %> <%= f.text_field :chapter %> + <%= f.text_field :chapter, :size => 60 %>

- <%= f.label :editor, l(:editor) %> <%= f.text_field :editor %> + <%= f.text_field :editor, :size => 60 %>

- <%= f.label :booktitle, l(:booktitle) %> <%= f.text_field :booktitle %> + <%= f.text_field :booktitle,:size => 60 %>

- <%= f.label :publisher, l(:publisher) %> <%= f.text_field :publisher %> + <%= f.text_field :publisher,:size => 60 %>

- <%= f.label :pages, l(:pages) %> <%= f.text_field :pages %> + <%= f.text_field :pages, :size => 60 %>

+ +
\ No newline at end of file diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_edit.html.erb Wed Jul 27 12:23:57 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -<% content_for :header_tags do %> - <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> -<% end %> - -<% form_for @publication, :url => { :project_id => @project_id, :action => :create } do |f| -%> - <%= f.error_messages %> -

- <%= f.label :title, l(:title) %>
- <%= f.text_field :title %> -

- -

<%= l(:authors) %>

- <% f.fields_for :authorships do |builder| %> - <%= render "authorship_fields", :f => builder %> - <% end %> - -

<%= link_to_add_fields l(:label_add_another_author), f, :authorships %>

- -

Other Details

- <% f.fields_for :bibtex_entry do |builder| -%> - <%= render :partial => 'bibtex_fields', :locals => { :f => builder} %> - <%- end -%> - - <%= f.submit %> -<% end -%> diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_form.html.erb Fri Jul 29 21:40:48 2011 +0100 @@ -0,0 +1,30 @@ + +
+ <%= f.error_messages %> +

+ <%= f.text_field :title, :required => true, :size => 60 %> +

+ +

<%= l(:authors) %>

+ <% f.fields_for :authorships do |builder| %> + <%= render "authorship_fields", :f => builder %> + <% end %> + +

<%= link_to_add_fields l(:label_add_another_author), f, :authorships %>

+ +
+ +
+

Other Details

+ <% f.fields_for :bibtex_entry do |builder| -%> + <%= render :partial => 'bibtex_fields', :locals => { :f => builder} %> + <%- end -%> +
+ +<% content_for :sidebar do %> + + placeholder + +<% end %> + + diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/publications/_list_projects.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/_list_projects.html.erb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/_list_projects.html.erb Fri Jul 29 21:40:48 2011 +0100 @@ -1,3 +1,1 @@ -<% @publication.projects.each do |proj| %> - <%= link_to_project proj %> -<% end %> \ No newline at end of file +<%= render_projects_list(@publication) %> \ No newline at end of file diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/edit.html.erb Fri Jul 29 21:40:48 2011 +0100 @@ -1,8 +1,15 @@ -

Publications#edit

+<% content_for :header_tags do %> + <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> +<% end %> -<%= render :partial => 'edit' %> +

<%=l(:label_publication_show)%>

+<% form_for @publication, :url => { :project_id => @project_id, :action => :update }, :builder => TabularFormBuilder do |f| -%> + <%= render :partial => 'form', :locals => { :f => f } %> + + <%= f.submit %> +<% end %>

- <%= link_to "Show", @publication %> | - <%= link_to "View All", publications_path %> + <%= link_to l(:label_publication_show), { :controller => "publications", :action => "show", :id => @publication, :project_id => @project } %> | + <%= link_to l(:label_publication_index), { :controller => "publications", :action => "index", :project_id => @project } %>

diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/new.html.erb Fri Jul 29 21:40:48 2011 +0100 @@ -1,9 +1,10 @@ -

New Publication

+<% content_for :header_tags do %> + <%= javascript_include_tag 'authors', :plugin => 'redmine_bibliography' %> +<% end %> -
- <%= render :partial => 'edit' %> -
+

<%=l(:label_publication_new)%>

-
- -
\ No newline at end of file +<% form_for @publication, :url => { :project_id => @project_id, :action => :create }, :builder => TabularFormBuilder do |f| -%> + <%= render :partial => 'form', :locals => { :f => f } %> + <%= f.submit %> +<% end %> \ No newline at end of file diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb --- a/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/app/views/publications/show.html.erb Fri Jul 29 21:40:48 2011 +0100 @@ -1,4 +1,4 @@ -

Publication Details

+

<%=l(:label_publication_show)%>

Title

@@ -18,17 +18,11 @@
<%- if @publication.bibtex_entry != nil -%> -<% @publication.bibtex_entry.attributes.each do |field| %> - <% if field[1] != nil %> -

<%= field[0] %>

- <%= @publication.bibtex_entry.attributes[field[0]] unless field[1] == nil %> -
- <%- end -%> -<%- end -%> + <%= show_bibtex_fields(@publication.bibtex_entry) %> <%- end -%>

- <%= link_to "Edit", edit_publication_path(@publication) %> | + <%= link_to l(:label_publication_edit), { :controller => "publications", :action => "edit", :id => @publication, :project_id => @project } %> | <%= link_to "Destroy", @publication, :confirm => 'Are you sure?', :method => :delete %> | <%= link_to "View All", publications_path %>

@@ -38,13 +32,10 @@ <% projects = Project.active.find(:all, :limit => 100, :order => 'name ASC') - @publication.projects %>
- - -

List of Projects

+ +

<%=l(:label_publication_project_index)%>

<%= render :partial => 'list_projects' %>

- - <%= render :partial => 'add_project_form' %> - + <%= render :partial => 'add_project_form' %>
\ No newline at end of file diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/config/locales/en.yml --- a/vendor/plugins/redmine_bibliography/config/locales/en.yml Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/config/locales/en.yml Fri Jul 29 21:40:48 2011 +0100 @@ -9,7 +9,13 @@ field_publication_title: Title field_publication_authors: Authors - field_publication_projects: "Associated Projects" + field_publication_projects: "Associated Projects" + field_author_name: Author + field_author_username: "Associated User" + field_author_publications: "Publications by this Author" + + bibtex_entry: + entry_type: "Bibtex Entry Type" label_add_me_as_author: "Add me as an author" label_add_another_author: "Add another author" @@ -17,46 +23,52 @@ remove_author: "Remove this author" label_publications_plural: "Publications" - label_publication_new: "Add Publication" + label_publication_new: "Create New Publication" + label_add_publication_to_project: "Add Publication to this project" + label_publication_edit: "Edit Publication" + label_publication_show: "Publication Details" label_add_project_to_publication: "Add Project to Publication" label_project_search: "Search by name: " + label_publication_project_index: "Projects associated with this publication" + label_publication_index: "View all publications" text_author_email: "Author's email address as on the paper." text_author_institution: "Author's institution name as on paper." text_author_name_on_paper: "Name of the author as it appears on paper. (In case it applies, please use the autocomplete suggestions.)" # authorships model - institution: "Institution" - name_on_paper: "Name" - email: "Email Address" + field_institution: "Institution" + field_name_on_paper: "Name" + field_email: "Email Address" # bibtex_entries model - id: "id" - publication_id: "Publication_id" - entry_type: "Entry Type" - address: "Address" - annote: "Annote" - booktitle: "Book Title" - chapter: "Chapter" - crossref: "Cross Reference" - edition: "Edition" - editor: "Editor" - eprint: "eprint" - howpublished: "How was it Published" - journal: "Journal" - key: "Key" - month: "Month" - note: "Note" - number: "Number" - organization: "Organization" - pages: "Pages" - publisher: "Publisher" - school: "School" - series: "Series" - type: "Type" - url: "URL" - volume: "Volume" - year: "Year" + field_entry_type: "Entry Type" + field_id: "id" + field_publication_id: "Publication_id" + field_entry_type: "Entry Type" + field_address: "Address" + field_annote: "Annote" + field_booktitle: "Book Title" + field_chapter: "Chapter" + field_crossref: "Cross Reference" + field_edition: "Edition" + field_editor: "Editor" + field_eprint: "eprint" + field_howpublished: "How was it Published" + field_journal: "Journal" + field_key: "Key" + field_month: "Month" + field_note: "Note" + field_number: "Number" + field_organization: "Organization" + field_pages: "Pages" + field_publisher: "Publisher" + field_school: "School" + field_series: "Series" + field_type: "Type" + field_url: "URL" + field_volume: "Volume" + field_year: "Year" diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/db/migrate/004_create_bibtex_entries.rb --- a/vendor/plugins/redmine_bibliography/db/migrate/004_create_bibtex_entries.rb Wed Jul 27 12:23:57 2011 +0100 +++ b/vendor/plugins/redmine_bibliography/db/migrate/004_create_bibtex_entries.rb Fri Jul 29 21:40:48 2011 +0100 @@ -2,7 +2,7 @@ def self.up create_table :bibtex_entries do |t| t.column :publication_id, :integer - t.column :entry_type, :string + t.column :entry_type, :integer t.column :address, :string t.column :annote, :string t.column :booktitle, :string diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/db/migrate/006_create_bibtex_entry_types.rb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/db/migrate/006_create_bibtex_entry_types.rb Fri Jul 29 21:40:48 2011 +0100 @@ -0,0 +1,13 @@ +class CreateBibtexEntryTypes < ActiveRecord::Migration + def self.up + create_table :bibtex_entry_types do |t| + t.string :name + + t.timestamps + end + end + + def self.down + drop_table :bibtex_entry_types + end +end diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/db/seed_data/bibtex_entry_types_list.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/db/seed_data/bibtex_entry_types_list.txt Fri Jul 29 21:40:48 2011 +0100 @@ -0,0 +1,14 @@ +article +book +booklet +conference +inbook +incollection +inproceedings +manual +masterthesis +misc +phdthesis +proceedings +techreport +unpublished diff -r 168714032c7e -r a1e091bee818 vendor/plugins/redmine_bibliography/lib/tasks/seed_bibtex_entry_types.rake --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/plugins/redmine_bibliography/lib/tasks/seed_bibtex_entry_types.rake Fri Jul 29 21:40:48 2011 +0100 @@ -0,0 +1,20 @@ +namespace :redmine do + namespace :plugins do + namespace :redmine_bibliography do + + task :seed_bibtex_entry_types => :environment do + desc "Seeds the Bibtex Entry Types Table" + + quoted = ActiveRecord::Base.connection.quote_table_name('bibtex_entry_types') + ActiveRecord::Base.connection.execute("TRUNCATE #{quoted}") + + open(File.dirname(__FILE__) + "/../../db/seed_data/bibtex_entry_types_list.txt") do |bibtex_entry_types| + bibtex_entry_types.read.each_line do |bibtex_entry_type| + BibtexEntryType.create(:name => bibtex_entry_type.chomp) + end + end + end + + end + end +end