From b3141348b058898d1b8afb3347b194d9ba999daa Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 24 Mar 2017 14:42:10 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=89=93=E5=BC=80=E8=AE=BE=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 20 ++++++++--- .../_myshixun_extend_repository.html.erb | 4 +-- app/views/games/_myshixun_repository.html.erb | 4 +-- app/views/games/file_edit.html.erb | 33 ------------------- .../20170324054735_add_path_to_games.rb | 5 +++ db/schema.rb | 3 +- 6 files changed, 27 insertions(+), 42 deletions(-) delete mode 100644 app/views/games/file_edit.html.erb create mode 100644 db/migrate/20170324054735_add_path_to_games.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 6f2f62143..bbb6c285b 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -17,10 +17,20 @@ class GamesController < ApplicationController end # mushixun的版本库必须创建时就创建 + # 首次进入版本库自动打开文件 + # path:"" && path: @game.path def show + game_path = @game.path @rev = @rev.nil? ? "master" : @rev @git_url = git_repository_url(@myshixun, "Myshixun") - @entries = @repository.entries(@path, @rev) + # 默认打开文件 + if @path == "" && !game_path.nil? && !@repository.cat(game_path, @rev).blank? + @path = game_path + @file_open = true + @content = @repository.cat(@path, @rev) + else + @entries = @repository.entries(@path, @rev) + end @latest_output = @game.latest_output.try(:out_put) outputs = @game.outputs @had_done = 1 if (@myshixun.games.count == @game.stage && @game.status ==2) @@ -33,6 +43,8 @@ class GamesController < ApplicationController format.html format.js end + rescue + end # 代码预览 @@ -47,9 +59,9 @@ class GamesController < ApplicationController def file_edit entry_and_raw(false) @content = @repository.cat(@path, @rev).rstrip - respond_to do |format| - format.js - end + # respond_to do |format| + # format.js + # end end def file_update diff --git a/app/views/games/_myshixun_extend_repository.html.erb b/app/views/games/_myshixun_extend_repository.html.erb index 84a876b94..bc936059a 100644 --- a/app/views/games/_myshixun_extend_repository.html.erb +++ b/app/views/games/_myshixun_extend_repository.html.erb @@ -1,7 +1,7 @@

<%= render :partial => 'myshixun_breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>

- <% if params[:action] == "entry" %> + <% if params[:action] == "entry" || @file_open %> <% end %> @@ -9,7 +9,7 @@
- <% if params[:action] == "entry" %> + <% if params[:action] == "entry" || @file_open %>
<%= render :partial => 'common/extend_file', :locals => {:filename => @path, :content => @content, :extend => true} %>
diff --git a/app/views/games/_myshixun_repository.html.erb b/app/views/games/_myshixun_repository.html.erb index b2de9c953..05ca3098a 100644 --- a/app/views/games/_myshixun_repository.html.erb +++ b/app/views/games/_myshixun_repository.html.erb @@ -3,7 +3,7 @@ <%= render :partial => 'myshixun_breadcrumbs', :locals => {:path => @path, :kind => 'dir', :revision => @rev} %>
- <% if params[:action] == "entry" %> + <% if params[:action] == "entry" || @file_open %> @@ -12,7 +12,7 @@
- <% if params[:action] == "entry" %> + <% if params[:action] == "entry" || @file_open %>
<%= render :partial => 'common/file', :locals => {:filename => @path, :content => @content} %>
diff --git a/app/views/games/file_edit.html.erb b/app/views/games/file_edit.html.erb deleted file mode 100644 index 6d3edb6b2..000000000 --- a/app/views/games/file_edit.html.erb +++ /dev/null @@ -1,33 +0,0 @@ -<%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %> -<%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %> -<%= stylesheet_link_tag "/assets/codemirror/codemirror" %> -<%= form_tag(:controller => 'games', :action => 'file_update', :id => @game, :myshixun_id => @myshixun) do%> -
  • - - - -
  • -<% end %> - - \ No newline at end of file diff --git a/db/migrate/20170324054735_add_path_to_games.rb b/db/migrate/20170324054735_add_path_to_games.rb new file mode 100644 index 000000000..70fe56803 --- /dev/null +++ b/db/migrate/20170324054735_add_path_to_games.rb @@ -0,0 +1,5 @@ +class AddPathToGames < ActiveRecord::Migration + def change + add_column :games, :path, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 0e58e2a23..28a35d72a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20170323081518) do +ActiveRecord::Schema.define(:version => 20170324054735) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1091,6 +1091,7 @@ ActiveRecord::Schema.define(:version => 20170323081518) do t.text "answer" t.integer "score" t.integer "final_score", :default => 0 + t.string "path" end create_table "groups_users", :id => false, :force => true do |t| From 001a3796c74379be586b1cc78032f6cd4fd9e3b1 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 24 Mar 2017 15:05:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=A0=B9=E7=9B=AE=E5=BD=95=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E6=98=BE=E7=A4=BA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 3 ++- app/views/games/_myshixun_breadcrumbs.html.erb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index bbb6c285b..c20c44d6e 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -23,8 +23,9 @@ class GamesController < ApplicationController game_path = @game.path @rev = @rev.nil? ? "master" : @rev @git_url = git_repository_url(@myshixun, "Myshixun") + @type = params[:type] # 默认打开文件 - if @path == "" && !game_path.nil? && !@repository.cat(game_path, @rev).blank? + if @path == "" && !game_path.nil? && !@repository.cat(game_path, @rev).blank? && @type != "root" @path = game_path @file_open = true @content = @repository.cat(@path, @rev) diff --git a/app/views/games/_myshixun_breadcrumbs.html.erb b/app/views/games/_myshixun_breadcrumbs.html.erb index 5e9e01b87..a41bb3947 100644 --- a/app/views/games/_myshixun_breadcrumbs.html.erb +++ b/app/views/games/_myshixun_breadcrumbs.html.erb @@ -2,7 +2,7 @@ <% if @path.blank? %> <%= @repository.identifier %> <% else %> - <%= link_to "#{@repository.identifier.present? ? h(@repository.identifier) : 'root'}", myshixun_game_path(@game, :myshixun_id => @myshixun) %> + <%= link_to "#{@repository.identifier.present? ? h(@repository.identifier) : 'root'}", myshixun_game_path(@game, :myshixun_id => @myshixun, :type => "root"), :remote => true %> <% dirs = path.split('/') if 'file' == kind From 3231f96b5f8ccf3e68121200d214711f9f965090 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 24 Mar 2017 15:31:16 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E5=B1=95=E7=A4=BA=E4=BB=A3=E7=A0=81=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 6 +++--- lib/gitlab-cli/lib/gitlab/request.rb | 24 +++++++++++----------- lib/redmine/scm/adapters/gitlab_adapter.rb | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index c20c44d6e..b9faa41e9 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -20,7 +20,7 @@ class GamesController < ApplicationController # 首次进入版本库自动打开文件 # path:"" && path: @game.path def show - game_path = @game.path + game_path = (@game.path.blank? ? @game.path : @game.path.strip) @rev = @rev.nil? ? "master" : @rev @git_url = git_repository_url(@myshixun, "Myshixun") @type = params[:type] @@ -44,8 +44,8 @@ class GamesController < ApplicationController format.html format.js end - rescue - + rescue Exception => e + flash[:error] = e.message end # 代码预览 diff --git a/lib/gitlab-cli/lib/gitlab/request.rb b/lib/gitlab-cli/lib/gitlab/request.rb index e1bb1094f..f8e18e415 100644 --- a/lib/gitlab-cli/lib/gitlab/request.rb +++ b/lib/gitlab-cli/lib/gitlab/request.rb @@ -62,18 +62,18 @@ module Gitlab # Checks the response code for common errors. # Returns parsed response for successful requests. def validate(response) - case response.code - when 400; raise Error::BadRequest.new error_message(response) - when 401; raise Error::Unauthorized.new error_message(response) - when 403; raise Error::Forbidden.new error_message(response) - when 404; raise Error::NotFound.new error_message(response) - when 405; raise Error::MethodNotAllowed.new error_message(response) - when 406; raise Error::DataNotAccepted.new error_message(response) - when 409; raise Error::Conflict.new error_message(response) - when 500; raise Error::InternalServerError.new error_message(response) - when 502; raise Error::BadGateway.new error_message(response) - when 503; raise Error::ServiceUnavailable.new error_message(response) - end + # case response.code + # when 400; raise Error::BadRequest.new error_message(response) + # when 401; raise Error::Unauthorized.new error_message(response) + # when 403; raise Error::Forbidden.new error_message(response) + # when 404; raise Error::NotFound.new error_message(response) + # when 405; raise Error::MethodNotAllowed.new error_message(response) + # when 406; raise Error::DataNotAccepted.new error_message(response) + # when 409; raise Error::Conflict.new error_message(response) + # when 500; raise Error::InternalServerError.new error_message(response) + # when 502; raise Error::BadGateway.new error_message(response) + # when 503; raise Error::ServiceUnavailable.new error_message(response) + # end response.parsed_response end diff --git a/lib/redmine/scm/adapters/gitlab_adapter.rb b/lib/redmine/scm/adapters/gitlab_adapter.rb index 5d3a0fc01..9d8c773ef 100644 --- a/lib/redmine/scm/adapters/gitlab_adapter.rb +++ b/lib/redmine/scm/adapters/gitlab_adapter.rb @@ -261,7 +261,7 @@ module Redmine elsif @myshixun file = @g.files(@myshixun, path, identifier) end - cat = Base64.decode64 file.content + cat = Base64.decode64 file.content unless file.content.blank? rescue ScmCommandAborted nil end