-
class PublicationsController < ApplicationController
unloadable
- @@source_file_field_id = 1
+# before_filter :authorize, :only => [:issues]
+
+ def index
+ @publications = Publication.all
+ respond_to do |format|
+ format.html
+ format.xml { render :xml => @publications }
+ format.json { render :json => @publications }
+ end
+ end
+
+ def refresh
+ regexp = Regexp.new(Setting.plugin_redmine_publications['pattern'])
+ Repository.all.each do |repo|
+ repo.entries.each do |entry|
+ match = entry.path.match(regexp)
+ if match
+ Publication.find_or_create_by_name(:name => match[1],
+ :source_file => entry.path, :repository_id => repo.id)
+ end
+ end
+ end
+ end
def issues
- logger.info "Searching for issues with document name = " + params[:pub] + "."
- joins = "JOIN issue_publications ON (issues.id = issue_publications.issue_id) JOIN publications ON (issue_publications.publication_id = publications.id)"
+ @publication = Publication.find_by_name(params[:pub])
- conditions = ['publications.source_file = ? ', params[:pub] ]
+ joins = "JOIN issue_publications ON (issues.id = issue_publications.issue_id)"
+ conditions = ['issue_publications.publication_id = ? ', @publication.id ]
@issues = Issue.all(:joins => joins, :conditions => conditions)
respond_to do |format|
format.html
render :text => ""
end
+ private
+
+ def find_project
+ @project = Project.find(params[:project_id])
+ end
+
end
class Publication < ActiveRecord::Base
has_many :issues, :through => :issuepublications
+ belongs_to :repository
end
<div>
-<p><label for="issue_source_files">Source File(s)</label>
-<input type='text'
- id='issue_source_files' name="issue_source_files"
- value='<%= @issue.source_files.join(' ') %>' />
+<p><label for="issue_source_files">Publication(s)</label>
+<input type='text' id='publications' name="publications" size="50"
+ value='<%= @issue.publication_names.join(', ') %>' />
</div>
-<h2>Microrest#related-issues</h2>
-<%= @issues %>
-
-
+<h2>Publikacje</h2>
+<ol>
+<% @publications.each do |pub| %>
+ <li><a href="/publications/issues/<%= pub.name %>"><%= pub.name %></a></li>
+<% end %>
+</ol>
--- /dev/null
+<h2>Issues for publication: <%= @publication.name %></h2>
+<% @issues.each do |issue| %>
+<p><%= issue.subject %></p>
+<% end %>
--- /dev/null
+<% @tracker = Tracker.find(settings['tracker']) %>
+
+<fieldset>
+<p>
+ <label for="settings[tracker]">Typ zagadnienia: </label>
+ <%= collection_select(:tracker, :id, Tracker.all, :id, :name, {}, {:name => "settings[tracker]"}) %>
+</p>
+
+<p>
+ <label for="settings[pattern]">Filtr publikacji: </label>
+ <%= text_field_tag 'settings[pattern]', @settings['pattern'] %>
+</p>
+</fieldset>
--- /dev/null
+class PublicationsAddRepoId < ActiveRecord::Migration
+ def self.up
+ add_column :publications, :repository_id, :integer, :null => false, :default => 0
+ end
+
+ def self.down
+ end
+end
--- /dev/null
+class PublicationsAddName < ActiveRecord::Migration
+ def self.up
+ add_column :publications, :name, :string
+ end
+
+ def self.down
+ end
+end
# Patches to the Redmine core.
require 'dispatcher'
-Dispatcher.to_prepare :redmine_kanban do
+Dispatcher.to_prepare :redmine_publications do
require_dependency 'issue'
# Guards against including the module multiple time (like in tests)
# and registering multiple callbacks
require_dependency 'issue_publication_hook'
-Redmine::Plugin.register :redmine_publicatons do
+Redmine::Plugin.register :redmine_publications do
name 'Publications managment plugin'
author 'Łukasz Rekucki'
description 'This plugn helps manage issues related to a publication.'
- version '0.0.3'
+ version '0.0.9'
+ # permission :view_issues_for_publication, :publications => :issues
+
+ settings :partial => 'settings/publications_settings',
+ :default => { :tracker => '1', :pattern => '.*/[a-z_].xml'}
+
+ menu :application_menu, :publications, { :controller => 'publications', :action => 'index' }, :caption => 'Publikacje'
requires_redmine :version_or_higher => '0.8.0'
# Provides a link to the document on the platform
class IssuesPublicationHook < Redmine::Hook::ViewListener
+
def view_issues_show_details_bottom(context)
- result = "<tr><td><b>Source File(s):</b></td><td>"
- names = context[:issue].source_files.map {|name| "<span>" + name + "</span>"}
- result << names.join(', ')
- result + "</td></tr>"
+ # TODO: złapać wyjątek konwersji
+ if context[:issue].tracker_id == Setting.plugin_redmine_publications['tracker'].to_i
+ result = "<tr><td><b>Publication(s):</b></td><td>"
+ names = context[:issue].publication_names {|name| "<span>" + name + "</span>"}
+ result << names.join(', ')
+ result << "</td></tr>"
+ end
end
def controller_issues_edit_before_save(context)
- pub_field = context[:params][:issue_source_files]
- context[:issue].source_files = pub_field
+ if context[:issue].tracker_id == Setting.plugin_redmine_publications['tracker'].to_i
+ pub_field = context[:params][:publications]
+ context[:issue].publication_names = pub_field.split(',').map { |n| n.strip }
+ end
end
render_on :view_issues_form_details_bottom, :partial => 'issue_form_pub'
base.class_eval do
unloadable # Send unloadable so it will not be unloaded in development
+ validate :check_relations
after_save :update_relations
- # after_destroy :check_relations
# Add visible to Redmine 0.8.x
unless respond_to?(:visible)
end
module InstanceMethods
- def source_files
- if not @source_files
- @source_files = self.lookup_source_files.map { |pub| pub.source_file }
- end
- @source_files
+
+ def publication_names
+ if not @pubnames
+ self.publications.map { |pub| pub.name }
+ else
+ @pubnames
+ end
end
- def source_files=(value)
- @source_files = value
+ def publication_names=(value)
+ @pubnames = value.sort!
end
- def lookup_source_files
+ def publications
Publication.all(
:joins =>
"JOIN issue_publications ON (issue_publications.publication_id = publications.id)",
:conditions =>
- [" issue_publications.issue_id = ? ", self.id] )
+ ["issue_publications.issue_id = ? ", self.id] )
end
-
- def update_relations
+
+ def check_relations
+ current_names = self.publication_names
+ non_existant = []
+
+ pubs = Publication.find_all_by_name(current_names).map {|i| i.name}
+ missing = current_names.select {|name| not pubs.include?name }
+
+ if not missing.empty?
+ errors.add("publications", "Missing publication(s): " + missing.join(', '))
+ end
+ end
+
+ def update_relations
self.reload
- current_assocs = self.lookup_source_files
- new_assocs_names = self.source_files.split(' ')
+ old = self.publications
+ current_names = self.publication_names
# delete unused relations
- deleted = current_assocs.select { |v| not (new_assocs_names.include?(v.source_file)) }
- deleted.each { |pub| IssuePublication.delete_all(
- :contitions => ["issue_publications.issue_id = ? AND issue_publicatons.publication_id = ?",
- self.id, pub.id]) }
+ deleted = old.select { |v| not (current_names.include?(v.name)) }
+ deleted.each do |pub|
+ IssuePublication.delete_all(["issue_publications.issue_id = ? AND issue_publications.publication_id = ?", self.id, pub.id])
+ end
- new_assocs_names.each do |name|
- pub = Publication.find_or_create_by_source_file(name)
- IssuePublication.find_or_create_by_publication_id_and_issue_id(pub.id, self.id)
+ current_names.each do |name|
+ pub = Publication.find_by_name(name)
+ IssuePublication.find_or_create_by_publication_id_and_issue_id(pub.id, self.id)
end
return true
- end
+ end
end
end
-connect 'publications/:pub',
+connect 'publications/:action',
:controller => 'publications',
- :action => 'redirect_to_platform'
+ :format => 'html'
+
+connect 'publications/:action.:format',
+ :controller => 'publications'
-connect 'publications/:pub/:action',
+connect 'publications/:action/:pub',
:controller => 'publications',
:format => 'html'
-connect 'publications/:pub/:action.:format',
+connect 'publications/:action/:pub.:format',
:controller => 'publications'