From 71b07fe1928b04a218e062f01cca720863b9eeb9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=81ukasz=20Rekucki?= Date: Thu, 24 Sep 2009 17:30:21 +0200 Subject: [PATCH 1/1] Redmine locale fix. Some RAL tweaks. Added line numbers to code-mirror. --- apps/api/handlers.py | 17 +++-- apps/api/tests/data/testone/.hg/dirstate | Bin 98 -> 98 bytes apps/toolbar/templates/toolbar/toolbar.html | 2 +- lib/wlrepo/__init__.py | 27 +++++-- lib/wlrepo/backend_mercurial.py | 63 ++++++++++------- lib/wlrepo/tests/test_mercurial.py | 6 +- project/settings.py | 1 + project/static/css/master.css | 11 +++ project/static/css/toolbar.css | 65 ++--------------- project/static/js/editor.js | 6 +- .../static/js/lib/codemirror/codemirror.js | 66 +++++++++++++++--- project/templates/base.html | 4 +- .../templates/explorer/panels/xmleditor.html | 7 +- project/urls.py | 7 +- .../controllers/publications_controller.rb | 40 +++++------ .../app/views/issues/_issue_form_pub.html.erb | 2 +- .../app/views/issues/_issue_view_pub.erb | 2 +- redmine/redmine_publications/init.rb | 4 ++ .../lib/redmine_publications/change_patch.rb | 38 ++++++++++ .../lib/redmine_publications/issue_patch.rb | 66 +++++++++--------- redmine/redmine_publications/locales/en.yml | 3 + redmine/redmine_publications/locales/pl.yml | 3 + 22 files changed, 269 insertions(+), 171 deletions(-) create mode 100644 redmine/redmine_publications/lib/redmine_publications/change_patch.rb create mode 100644 redmine/redmine_publications/locales/en.yml create mode 100644 redmine/redmine_publications/locales/pl.yml diff --git a/apps/api/handlers.py b/apps/api/handlers.py index 2f2bea12..9a54ce8c 100644 --- a/apps/api/handlers.py +++ b/apps/api/handlers.py @@ -64,6 +64,7 @@ class LibraryHandler(BaseHandler): if form.cleaned_data['generate_dc']: data = librarian.wrap_text(data, unicode(date.today())) + # TODO: what if the file exists ? doc = cab.create(form.cleaned_data['bookname'], initial_data=data) return { @@ -124,6 +125,9 @@ class DocumentHandler(BaseHandler): shared = lib.main_cabinet.retrieve(docid) + is_shared = document.ancestorof(shared) + # is_uptodate = is_shared or shared.ancestorof(document) + result = { 'name': document.name, 'size': document.size, @@ -132,12 +136,12 @@ class DocumentHandler(BaseHandler): 'parts_url': reverse('docparts_view', args=[docid]), 'latest_rev': document.shelf(), 'latest_shared_rev': shared.shelf(), - #'shared': lib.isparentof(document, shared), - #'up_to_date': lib.isparentof(shared, document), + 'shared': is_shared, + # 'up_to_date': is_uptodate, } - if request.GET.get('with_part', 'no') == 'yes': - result['parts'] = document.parts() + #if request.GET.get('with_part', 'no') == 'yes': + # result['parts'] = document.parts() return result @@ -150,7 +154,9 @@ class DocumentTextHandler(BaseHandler): def read(self, request, docid): """Read document as raw text""" lib = MercurialLibrary(path=settings.REPOSITORY_PATH) - try: + try: + # latest rev + # comment return lib.document(docid, request.user.username).read() except CabinetNotFound: return rc.NOT_HERE @@ -158,6 +164,7 @@ class DocumentTextHandler(BaseHandler): def update(self, request, docid): lib = MercurialLibrary(path=settings.REPOSITORY_PATH) try: + # check latest REV data = request.PUT['contents'] lib.document(docid, request.user.username).write(data) return rc.ALL_OK diff --git a/apps/api/tests/data/testone/.hg/dirstate b/apps/api/tests/data/testone/.hg/dirstate index 121c27127f7b2aa0705c976f05f59841959e4758..e146f1842b996ac8c6412bdd935029415f11d903 100644 GIT binary patch delta 55 zcmYdFnqXig; -
+

{% for group in toolbar_groups %}

{% block maincontent %} {% endblock %}
- {% block extrabody %} {% endblock %} + {% block extrabody %}{% endblock %} diff --git a/project/templates/explorer/panels/xmleditor.html b/project/templates/explorer/panels/xmleditor.html index 4ec75d2a..74a68776 100644 --- a/project/templates/explorer/panels/xmleditor.html +++ b/project/templates/explorer/panels/xmleditor.html @@ -17,8 +17,11 @@ panel_hooks = { var texteditor = CodeMirror.fromTextArea(textareaId, { parserfile: 'parsexml.js', path: "{{STATIC_URL}}js/lib/codemirror/", + width: 'auto', stylesheet: "{{STATIC_URL}}css/xmlcolors.css", parserConfig: {useHTMLKludges: false}, + textWrapping: false, + lineNumbers: true, onChange: function() { self.fireEvent('contentChanged'); }, @@ -33,7 +36,9 @@ panel_hooks = { } }) - $(texteditor.frame).css({width: '100%', height: '100%'}); + $('.CodeMirror-content-wrapper').css({ + width: '100%', height: '100%' }); + this.texteditor = texteditor; self._endload(); }, diff --git a/project/urls.py b/project/urls.py index 2c1fab7b..c8896314 100644 --- a/project/urls.py +++ b/project/urls.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from django.conf.urls.defaults import * from django.contrib import admin from django.conf import settings @@ -42,7 +44,10 @@ urlpatterns = patterns('', url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'redirect_field_name': 'next'}), url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}), - # Our uber-restful api + # Prototypes + url(r'^wysiwyg-proto/', include('wysiwyg.urls')), + + # Our über-restful api url(r'^api/', include('api.urls') ), ) diff --git a/redmine/redmine_publications/app/controllers/publications_controller.rb b/redmine/redmine_publications/app/controllers/publications_controller.rb index 6c1e7345..ebf735b9 100644 --- a/redmine/redmine_publications/app/controllers/publications_controller.rb +++ b/redmine/redmine_publications/app/controllers/publications_controller.rb @@ -19,28 +19,28 @@ class PublicationsController < ApplicationController Publication.delete_all() repos = Repository.all if repos - repos.each do |repo| - repo_status = [] - if repo.entries - 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) - repo_status += [{:path => entry.path, :match => match[1], :matched => true}] - else - repo_status += [{:path => entry.path, :match =>nil, :matched => false}] + repos.each do |repo| + repo_status = [] + if repo.entries + 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) + repo_status += [{:path => entry.path, :match => match[1], :matched => true}] + else + repo_status += [{:path => entry.path, :match =>nil, :matched => false}] + end + end + @match_status += [{:repo => repo, :status => repo_status}] end end - @match_status += [{:repo => repo, :status => repo_status}] - end - end - respond_to do |format| - format.html - format.xml { render :xml => @match_status} - format.json { render :json => @match_status } - end + respond_to do |format| + format.html + format.xml { render :xml => @match_status} + format.json { render :json => @match_status } + end end end @@ -52,7 +52,7 @@ class PublicationsController < ApplicationController @issues = Issue.all(:joins => joins, :conditions => conditions) respond_to do |fmt| - fmt.json { render :json => @issues, :callback => params[:callback] } + fmt.json { render :json => @issues, :callback => params[:callback] } end end diff --git a/redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb b/redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb index f0f7a1a0..ebb903c0 100644 --- a/redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb +++ b/redmine/redmine_publications/app/views/issues/_issue_form_pub.html.erb @@ -1,5 +1,5 @@
-

+

' />

diff --git a/redmine/redmine_publications/app/views/issues/_issue_view_pub.erb b/redmine/redmine_publications/app/views/issues/_issue_view_pub.erb index 26ce997b..a22c78be 100644 --- a/redmine/redmine_publications/app/views/issues/_issue_view_pub.erb +++ b/redmine/redmine_publications/app/views/issues/_issue_view_pub.erb @@ -1,5 +1,5 @@ - Publication(s) + <%= l(:field_publications) %>: <% @issue.publication_names.each do |pub| %> <%= pub %>
diff --git a/redmine/redmine_publications/init.rb b/redmine/redmine_publications/init.rb index 0aa6f07d..4298f606 100644 --- a/redmine/redmine_publications/init.rb +++ b/redmine/redmine_publications/init.rb @@ -11,6 +11,10 @@ Dispatcher.to_prepare :redmine_publications do 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' diff --git a/redmine/redmine_publications/lib/redmine_publications/change_patch.rb b/redmine/redmine_publications/lib/redmine_publications/change_patch.rb new file mode 100644 index 00000000..41ea9596 --- /dev/null +++ b/redmine/redmine_publications/lib/redmine_publications/change_patch.rb @@ -0,0 +1,38 @@ +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' + regexp = Regexp.new(Setting.plugin_redmine_publications[:pattern]) + match = self.path.match(regexp) + 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 diff --git a/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb b/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb index c1087999..bd1f73eb 100644 --- a/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb +++ b/redmine/redmine_publications/lib/redmine_publications/issue_patch.rb @@ -11,8 +11,8 @@ module RedminePublications base.class_eval do unloadable # Send unloadable so it will not be unloaded in development - validate :check_relations - after_save :update_relations + validate :check_relations + after_save :update_relations end end @@ -23,55 +23,55 @@ module RedminePublications module InstanceMethods def publication_names - if not @pubnames - self.publications.map { |pub| pub.name } + if not @pubnames + self.publications.map { |pub| pub.name } else - @pubnames - end + @pubnames + end end def publication_names=(value) - @pubnames = value.sort! + @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] ) + :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 = [] + 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 } + 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 + 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) + 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 + # 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 + 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 diff --git a/redmine/redmine_publications/locales/en.yml b/redmine/redmine_publications/locales/en.yml new file mode 100644 index 00000000..3932ef20 --- /dev/null +++ b/redmine/redmine_publications/locales/en.yml @@ -0,0 +1,3 @@ +## YAML Template. +en: + field_publications: Publications diff --git a/redmine/redmine_publications/locales/pl.yml b/redmine/redmine_publications/locales/pl.yml new file mode 100644 index 00000000..2bf07833 --- /dev/null +++ b/redmine/redmine_publications/locales/pl.yml @@ -0,0 +1,3 @@ +## YAML Template. +pl: + field_publications: Publikacje -- 2.20.1