aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsobiemir <sobiemir@aculo.pl>2019-01-06 20:58:01 +0100
committersobiemir <sobiemir@aculo.pl>2019-01-06 20:58:01 +0100
commitdd0ceb1246b71afa50c91f7b585d7daf2ecae6d3 (patch)
tree517ff93d2ab3c6cb34c2aa45e0f4daee2ca6b61e
parent9f449998ae4514a9c78794e9c0ccf749aec125a1 (diff)
downloadredmine-revision-redirect-dd0ceb1246b71afa50c91f7b585d7daf2ecae6d3.tar.gz
redmine-revision-redirect-dd0ceb1246b71afa50c91f7b585d7daf2ecae6d3.zip
Add model controller and view for revision settings
-rw-r--r--README.rdoc2
-rw-r--r--app/controllers/RevisionRedirectsController.rb55
-rw-r--r--app/models/revision_redirect.rb2
-rw-r--r--app/views/projects/settings/_repositories.html.erb2
-rw-r--r--app/views/revision_redirects/edit.html.erb18
-rw-r--r--config/locales/en.yml6
-rw-r--r--config/routes.rb2
-rw-r--r--db/migrate/001_create_revision_redirects.rb15
8 files changed, 98 insertions, 4 deletions
diff --git a/README.rdoc b/README.rdoc
index 1e5d49d..211a19c 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -1,3 +1,3 @@
= redmine_revision_redirect
-This plugin allows to redirect revision links to external git website.
+Description goes here
diff --git a/app/controllers/RevisionRedirectsController.rb b/app/controllers/RevisionRedirectsController.rb
new file mode 100644
index 0000000..8f89fda
--- /dev/null
+++ b/app/controllers/RevisionRedirectsController.rb
@@ -0,0 +1,55 @@
+class RevisionRedirectsController < ApplicationController
+ before_action :find_repository_details, :only => [:edit, :update]
+
+ def edit
+ end
+
+ def update
+ end
+
+ def find_repository_details
+ @repository = Repository.find(params[:id])
+ @redirect = RevisionRedirect.where(repository_id: params[:id]).first
+
+ if not @redirect then
+ @redirect = RevisionRedirect.new({
+ revision_redirect: false,
+ diff_redirect: false,
+ repository_redirect: false,
+ commiter_email: false,
+ repository_id: params[:id],
+ revision_link: "",
+ diff_link: "",
+ repository_link: ""
+ })
+ end
+
+ @project = @repository.project
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
+ # def update
+ # project = Project.find(params[:id])
+ # if params[:repository_id].present?
+ # repository = project.repositories.find_by_identifier_param(params[:repository_id])
+ # else
+ # repository = project.repository
+ # end
+ # (render_404; return false) unless repository
+ # path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s
+ # rev = params[:rev].blank? ? repository.default_branch : params[:rev].to_s.strip
+ # rev_to = params[:rev_to]
+
+ # unless rev.to_s.match(REV_PARAM_RE) && rev_to.to_s.match(REV_PARAM_RE)
+ # if repository.branches.blank?
+ # raise InvalidRevisionParam
+ # end
+ # end
+ # rescue ActiveRecord::RecordNotFound
+ # render_404
+ # rescue InvalidRevisionParam
+ # show_error_not_found
+ # end
+
+end
diff --git a/app/models/revision_redirect.rb b/app/models/revision_redirect.rb
new file mode 100644
index 0000000..7f7b76e
--- /dev/null
+++ b/app/models/revision_redirect.rb
@@ -0,0 +1,2 @@
+class RevisionRedirect < ActiveRecord::Base
+end
diff --git a/app/views/projects/settings/_repositories.html.erb b/app/views/projects/settings/_repositories.html.erb
index 8be80cb..60b59b7 100644
--- a/app/views/projects/settings/_repositories.html.erb
+++ b/app/views/projects/settings/_repositories.html.erb
@@ -30,7 +30,7 @@
:class => 'icon icon-user') %>
<%= link_to(l(:button_edit), edit_repository_path(repository),
:class => 'icon icon-edit') %>
- <%= link_to(l(:rrr_button_redirect), edit_repository_path(repository),
+ <%= link_to(l(:rrr_button_redirect), edit_revision_redirect_path(repository),
:class => 'icon icon-shared') %>
<%= delete_link repository_path(repository) %>
<% end %>
diff --git a/app/views/revision_redirects/edit.html.erb b/app/views/revision_redirects/edit.html.erb
new file mode 100644
index 0000000..f50ce08
--- /dev/null
+++ b/app/views/revision_redirects/edit.html.erb
@@ -0,0 +1,18 @@
+<h2><%= l(:rrr_label_redirect) %></h2>
+
+<%= labelled_form_for :redirect, @redirect, :url => revision_redirect_path(@repository), :html => {:method => :put, :id => 'revision-redirect-form'} do |f| %>
+
+ <%= error_messages_for 'redirect' %>
+
+ <div class="box tabular">
+ <p><%= f.check_box :revision_redirect, :label => :rrr_field_revision_redirect %></p>
+ <p><%= f.check_box :diff_redirect, :label => :rrr_field_diff_redirect %></p>
+ <p><%= f.check_box :repository_redirect, :label => :rrr_field_repository_redirect %></p>
+ </div>
+
+ <p>
+ <%= submit_tag(@redirect.new_record? ? l(:button_create) : l(:button_save)) %>
+ <%= link_to l(:button_cancel), settings_project_path(@project, :tab => 'repositories') %>
+ </p>
+
+<% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 46c1f56..bdf8c14 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1,4 +1,6 @@
-# English strings go here for Rails i18n
en:
rrr_button_redirect: "Redirects"
- # my_label: "My label"
+ rrr_label_redirect: "Repository redirects"
+ rrr_field_revision_redirect: "Revision redirect"
+ rrr_field_diff_redirect: "Diff redirect"
+ rrr_field_repository_redirect: "Repository redirect"
diff --git a/config/routes.rb b/config/routes.rb
index 1803173..30f8f9c 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,2 +1,4 @@
# Plugin's routes
# See: http://guides.rubyonrails.org/routing.html
+
+resources :revision_redirects, only: [:edit, :update]
diff --git a/db/migrate/001_create_revision_redirects.rb b/db/migrate/001_create_revision_redirects.rb
new file mode 100644
index 0000000..b2135a2
--- /dev/null
+++ b/db/migrate/001_create_revision_redirects.rb
@@ -0,0 +1,15 @@
+class CreateRevisionRedirects < ActiveRecord::Migration[5.2]
+ def change
+ create_table :revision_redirects do |t|
+ t.boolean :revision_redirect
+ t.boolean :diff_redirect
+ t.boolean :repository_redirect
+ t.string :revision_link
+ t.string :diff_link
+ t.string :repository_link
+ t.integer :repository_id
+ t.boolean :commiter_email
+ end
+ add_index :revision_redirects, :repository_id
+ end
+end