+++ /dev/null
-= publications
-
-Description goes here
+++ /dev/null
-class PublicationsController < ApplicationController
- unloadable
-
- # 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])
- repo = Repository.find(:first, :conditions => ['project_id = ?', Setting.plugin_redmine_publications[:project]] )
-
- Rails.logger.info('[INFO] Importing changes from ' << repo.url)
- Rails.logger.info('[INFO] Change list: ' << repo.changes.find(:all).inspect )
-
- @repo_status = []
- repo.changes.find(:all).each do |change|
- Rails.logger.info('[INFO] Importing change ' << change.path)
- match = change.path.match(regexp)
- if match
- Publication.find_or_create_by_name(:name => match[1],
- :source_file => change.path, :repository_id => repo.id)
- @repo_status += [{:path => change.path, :match => match[1], :matched => true}]
- else
- @repo_status += [{:path => change.path, :match => nil, :matched => false}]
- end
- end
-
- respond_to do |format|
- format.html
- format.xml { render :xml => @repo_status}
- format.json { render :json => @repo_status }
- end
- end
-
- def issues
- @publication = Publication.find_by_name(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 |fmt|
- fmt.json { render :json => @issues, :callback => params[:callback] }
- end
- end
-
- private
-
- def find_project
- @project = Project.find(params[:project_id])
- end
-
-end
+++ /dev/null
-module PublicationsHelper
-end
+++ /dev/null
-class IssuePublication < ActiveRecord::Base
- belongs_to :publication
- belongs_to :issue
-end
+++ /dev/null
-class Publication < ActiveRecord::Base
- has_many :issues, :through => :issuepublications
- belongs_to :repository
-end
+++ /dev/null
-<div>
-<p><label for="issue_source_files"><%= l(:field_publications) %>:</label>
-<input type='text' id='publications' name="publications" size="50"
- value='<%= @issue.publication_names.join(', ') %>' />
-</div>
+++ /dev/null
-<tr>
- <td><b><%= l(:field_publications) %>:</b></td>
- <td>
-<% @issue.publication_names.each do |pub| %>
- <a href="<%= Setting.plugin_redmine_publications[:editorurl].sub(':pubid', pub) %>"><%= pub %></a><br />
-<% end %>
- </td>
-</tr>
+++ /dev/null
-<h2>Publikacje</h2>
-<p><a href="/publications/refresh">Odśwież listę publikacji</a></p>
-<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
-<table>
-<tr><th>Ścieżka zasobu</th><th>Rozpoznano</th><th>ID zasobu</th></tr>
-<% @repo_status.each do |status| %>
-<tr>
-<td><%= status[:path] %></td>
-<td><%= (status[:matched] && 'Tak') || 'Nie' %></td>
-<td><%= status[:match] || '' %></td>
-</tr>
-<% end %>
-</table>
+++ /dev/null
-<% @project = Project.find(:first, :conditions => ["id = ?", @settings[:project]]) %>
-<fieldset>
-<p>
- <label for="settings[project]">Użyj w projektcie: </label>
- <%= collection_select(:project, :id, Project.all, :id, :name, {}, {:name => "settings[project]"}) %>
-</p>
-
-<p>
- <label for="settings[pattern]">Filtr publikacji: </label>
- <%= text_field_tag 'settings[pattern]', @settings[:pattern] || '' %>
-</p>
-
-<p>
- <label for="settings[editorurl]">Docelowy URL: </label>
- <%= text_field_tag 'settings[editorurl]', @settings[:editorurl] || '' %>
-</p>
-
-</fieldset>
+++ /dev/null
-class CreatePublications < ActiveRecord::Migration
- def self.up
- create_table :publications do |t|
- t.column :source_file, :string, :null => false
- end
- end
-
- def self.down
- drop_table :publications
- end
-end
+++ /dev/null
-class CreateIssuePublications < ActiveRecord::Migration
- def self.up
- create_table :issue_publications do |t|
- t.column :publication_id, :integer, :null => false
- t.column :issue_id, :integer, :null => false
- end
- end
-
- def self.down
- drop_table :issue_publications
- end
-end
+++ /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
+++ /dev/null
-require 'redmine'
-
-# Patches to the Redmine core.
-require 'dispatcher'
-
-Dispatcher.to_prepare :redmine_publications do
- require_dependency 'issue'
-
- #Guards against including the module multiple time (like in tests)
- # and registering multiple callbacks
- unless Issue.included_modules.include? RedminePublications::IssuePatch
- Issue.send(:include, RedminePublications::IssuePatch)
- end
-
- unless Change.included_modules.include? RedminePublications::ChangePatch
- Change.send(:include, RedminePublications::ChangePatch)
- end
-end
-
-require_dependency 'issue_publication_hook'
-
-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.9'
-
- # permission :view_issues_for_publication, :publications => :issues
-
- settings :partial => 'settings/publications_settings',
- :default => { :project => '0', :pattern => '[^\$].xml', :editorurl => 'http://localhost/:pubid'}
-
- menu :application_menu, :publications, { :controller => 'publications', :action => 'index' }, :caption => 'Publikacje'
-
-# requires_redmine :version_or_higher => '0.8.0'
-
-end
-
+++ /dev/null
-# English strings go here
-my_label: "My label"
+++ /dev/null
-# Provides a link to the document on the platform
-class IssuesPublicationHook < Redmine::Hook::ViewListener
-
- def self.render_on(hook, options={})
- define_method hook do |context|
- if !options.include?(:if) || evaluate_if_option(options[:if], context)
- context[:controller].send(:render_to_string, {:locals => context}.merge(options))
- end
- end
- end
-
- private
-
- def evaluate_if_option(if_option, context)
- case if_option
- when Symbol
- send(if_option, context)
- when Method, Proc
- if_option.call(context)
- end
- end
-
- def is_pticket?(context)
- context[:issue].project_id == Setting.plugin_redmine_publications[:project].to_i
- end
-
- public
-
- render_on :view_issues_show_details_bottom, :partial => 'issue_view_pub', :if => :is_pticket?
- render_on :view_issues_form_details_bottom, :partial => 'issue_form_pub', :if => :is_pticket?
-
- # names = context[:issue].publication_names {|name| "<span>" + name + "</span>"}
- # result << names.join(', ')
-
- def controller_issues_edit_before_save(context)
- if is_pticket?context
- old_value = context[:issue].publication_names
- new_value = context[:params][:publications].split(',').map { |n| n.strip }
- context[:journal].details << JournalDetail.new(
- :property => 'attr', :prop_key => "publications",
- :old_value => old_value.join(', '),
- :value => new_value.join(', ') ) unless new_value==old_value
- context[:issue].publication_names = new_value
- end
- end
-
-
- def controller_issues_new_after_save(context)
- if is_pticket?context
- value = context[:params][:publications].split(',').map { |n| n.strip }
- context[:issue].publication_names = value
- context[:issue].save
- end
- end
-end
+++ /dev/null
-module RedminePublications
- # Patches Redmine's Issues dynamically. Adds a +after_save+ filter.
-
- module ChangePatch
- def self.included(base) # :nodoc:
- base.extend(ClassMethods)
-
- base.send(:include, InstanceMethods)
-
- # Same as typing in the class
- base.class_eval do
- unloadable # Send unloadable so it will not be unloaded in development
- after_save :update_publication
- end
-
- end
-
- module ClassMethods
- end
-
- module InstanceMethods
-
- def update_publication
- if (self.action == 'A') and (self.changeset.repository.project_id == Setting.plugin_redmine_publications[:project].to_i)
- regexp = Regexp.new(Setting.plugin_redmine_publications[:pattern])
- match = self.path.match(regexp)
- if match
- Rails.logger.info('[INFO] Adding publication: "' << match[1])
- Publication.find_or_create_by_name(:name => match[1],
- :source_file => self.path, :repository_id => self.changeset.repository.id )
- end
- end
- end
-
- end
-
- end
-
-
-end
+++ /dev/null
-module RedminePublications
- # Patches Redmine's Issues dynamically. Adds a +after_save+ filter.
-
- module IssuePatch
- def self.included(base) # :nodoc:
- base.extend(ClassMethods)
-
- base.send(:include, InstanceMethods)
-
- # Same as typing in the class
- base.class_eval do
- unloadable # Send unloadable so it will not be unloaded in development
-
- validate :check_relations
- after_save :update_relations
- end
-
- end
-
- module ClassMethods
- end
-
- module InstanceMethods
-
- def publication_names
- if not @pubnames
- self.publications.map { |pub| pub.name }
- else
- @pubnames
- end
- end
-
- def publication_names=(value)
- @pubnames = value.sort!
- end
-
- def publications
- Publication.all(
- :joins =>
- "JOIN issue_publications ON (issue_publications.publication_id = publications.id)",
- :conditions =>
- ["issue_publications.issue_id = ? ", self.id] )
- end
-
- 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
- old = self.publications
- current_names = self.publication_names
- Rails.logger.info('[INFO] Updating relations: old= ' << old.inspect << ' current=' << current_names.inspect)
-
- # delete unused relations
- 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
-
- 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
+++ /dev/null
-## YAML Template.
-en:
- field_publications: Publications
+++ /dev/null
-## YAML Template.
-pl:
- field_publications: Publikacje
+++ /dev/null
-connect 'publications/:action',
- :controller => 'publications',
- :format => 'html'
-
-connect 'publications/:action.:format',
- :controller => 'publications'
-
-connect 'publications/:action/:pub',
- :controller => 'publications', :format => 'json',
- :pub => /[^\/?]+/
+++ /dev/null
-# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
-one:
- id: 1
- source_file: One
-two:
- id: 2
- source_file: Two
+++ /dev/null
-require File.dirname(__FILE__) + '/../test_helper'
-
-class MicrorestControllerTest < ActionController::TestCase
- # Replace this with your real tests.
- def test_truth
- assert true
- end
-end
+++ /dev/null
-# Load the normal Rails helper
-require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
-
-# Ensure that we are using the temporary fixture path
-Engines::Testing.set_fixture_path
+++ /dev/null
-require File.dirname(__FILE__) + '/../test_helper'
-
-class PublicationTest < Test::Unit::TestCase
- fixtures :publications
-
- # Replace this with your real tests.
- def test_truth
- assert true
- end
-end