Skip to content

Commit

Permalink
New observable objects added (Version)
Browse files Browse the repository at this point in the history
  • Loading branch information
anteo committed Dec 19, 2015
1 parent 7f343f9 commit 84552f3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ This plug-in is compatible with Redmine 2.x.x, 3.x.x

== Changelog

[0.1.6] * New observable objects added (TimeEntry)
[0.1.6] * New observable objects added (TimeEntry, Version)
* Bug fixes
[0.1.5] * New observable objects added (Project, Wiki Content, Attachment, Issue Attachments, Project Attachments, Wiki Page Attachments)
* Ability to hook before_destroy and after_destroy events
Expand Down
6 changes: 3 additions & 3 deletions app/models/custom_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ def initialize(message)

class CustomWorkflow < ActiveRecord::Base
OBSERVABLES = [:issue, :issue_attachments, :user, :attachment, :group, :group_users, :project, :project_attachments,
:wiki_content, :wiki_page_attachments, :time_entry, :shared]
PROJECT_OBSERVABLES = [:issue, :issue_attachments, :project, :project_attachments, :wiki_content, :wiki_page_attachments, :time_entry]
:wiki_content, :wiki_page_attachments, :time_entry, :version, :shared]
PROJECT_OBSERVABLES = [:issue, :issue_attachments, :project, :project_attachments, :wiki_content, :wiki_page_attachments, :time_entry, :version]
COLLECTION_OBSERVABLES = [:group_users, :issue_attachments, :project_attachments, :wiki_page_attachments]
SINGLE_OBSERVABLES = [:issue, :user, :group, :attachment, :project, :wiki_content, :time_entry]
SINGLE_OBSERVABLES = [:issue, :user, :group, :attachment, :project, :wiki_content, :time_entry, :version]

attr_protected :id
has_and_belongs_to_many :projects
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ en:
text_custom_workflow_wiki_content_code_note: Scripts are executed in the context of Wiki Content object when project object changes (destroys). Use methods and properties of the project directly (or through "self")
text_custom_workflow_wiki_page_attachments_code_note: These scripts are executed when a file being added to wiki page/removed from wiki page. Use variables @page and @attachment to access appropriate objects in your scripts.
text_custom_workflow_time_entry_code_note: Scripts are executed in the context of TimeEntry object when time enty object changes (destroys). Use methods and properties of the time entry directly (or through "self")
text_custom_workflow_version_code_note: Scripts are executed in the context of Version object when version object changes (destroys). Use methods and properties of the version directly (or through "self")

text_no_enabled_projects: No projects
text_custom_workflow_author: Will be included in exported XML
Expand All @@ -81,3 +82,4 @@ en:
custom_workflow_observable_wiki_page_attachments: "Wiki Page Attachments"
custom_workflow_observable_group_users: "Group Users"
custom_workflow_observable_time_entry: "Time Entry"
custom_workflow_observable_version: "Version"
2 changes: 2 additions & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ ru:
text_custom_workflow_wiki_content_code_note: Эти сценарии исполняются в контексте объекта Wiki содержания когда объект Wiki содержания изменяется (удаляется). Используйте методы и свойства объекта содержания Wiki (WikiContent) напрямую или через ключевое слово self.
text_custom_workflow_wiki_page_attachments_code_note: Эти сценарии выполняются когда файл загружается на Wiki страницу/удаляется с Wiki страницы. Используйте переменные @page и @attachment для доступа к соответствующим объектам из Ваших сценариев.
text_custom_workflow_time_entry_code_note: Эти сценарии исполняются в контексте объекта затраченного времени когда объект изменяется (удаляется). Используйте методы и свойства объекта затраченного времени (TimeEntry) напрямую или через ключевое слово self.
text_custom_workflow_version_code_note: Эти сценарии исполняются в контексте объекта версии когда объект изменяется (удаляется). Используйте методы и свойства объекта версии (Version) напрямую или через ключевое слово self.

text_no_enabled_projects: Нет проектов
text_custom_workflow_author: Будет использован в XML файле при экспорте
Expand All @@ -81,3 +82,4 @@ ru:
custom_workflow_observable_wiki_page_attachments: "Вложения страниц Wiki"
custom_workflow_observable_group_users: "Пользователи группы"
custom_workflow_observable_time_entry: "Затраченное время"
custom_workflow_observable_version: "Версия"
3 changes: 3 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
unless TimeEntry.include?(RedmineCustomWorkflows::TimeEntryPatch)
TimeEntry.send(:include, RedmineCustomWorkflows::TimeEntryPatch)
end
unless Version.include?(RedmineCustomWorkflows::VersionPatch)
Version.send(:include, RedmineCustomWorkflows::VersionPatch)
end
unless WikiContent.include?(RedmineCustomWorkflows::WikiContentPatch)
WikiContent.send(:include, RedmineCustomWorkflows::WikiContentPatch)
end
Expand Down
38 changes: 38 additions & 0 deletions lib/redmine_custom_workflows/version_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module RedmineCustomWorkflows
module VersionPatch

def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
before_save :before_save_custom_workflows
after_save :after_save_custom_workflows
before_destroy :before_destroy_custom_workflows
after_destroy :after_destroy_custom_workflows
end
end

module InstanceMethods
def before_save_custom_workflows
@version = self
@saved_attributes = attributes.dup
CustomWorkflow.run_shared_code(self)
CustomWorkflow.run_custom_workflows(:version, self, :before_save)
errors.empty? && (@saved_attributes == attributes || valid?)
ensure
@saved_attributes = nil
end

def after_save_custom_workflows
CustomWorkflow.run_custom_workflows(:version, self, :after_save)
end

def before_destroy_custom_workflows
CustomWorkflow.run_custom_workflows(:version, self, :before_destroy)
end

def after_destroy_custom_workflows
CustomWorkflow.run_custom_workflows(:version, self, :after_destroy)
end
end
end
end

0 comments on commit 84552f3

Please sign in to comment.