From 460c2f8a533daa6c9f90cfcb14257707aa124a42 Mon Sep 17 00:00:00 2001 From: guange Date: Wed, 11 Dec 2019 20:29:56 +0800 Subject: [PATCH] refactor jupyter interface --- app/controllers/games_controller.rb | 9 +------- app/controllers/jupyters_controller.rb | 32 ++++++++++++++++++++++++-- app/controllers/shixuns_controller.rb | 5 ---- app/views/games/show.json.jbuilder | 5 +--- app/views/shixuns/show.json.jbuilder | 2 -- config/routes.rb | 11 ++++----- 6 files changed, 36 insertions(+), 28 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 48fae1cc7..7f4226050 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -10,14 +10,7 @@ class GamesController < ApplicationController include GamesHelper include ApplicationHelper - include JupyterService - - helper_method :jupyter_url_with_game, :jupyter_port_with_game - - - def update_jupyter - jupyter_save_with_game(@game, params[:jupyter_port]) - end + def show diff --git a/app/controllers/jupyters_controller.rb b/app/controllers/jupyters_controller.rb index 5d3f05cb4..1eefd3d53 100644 --- a/app/controllers/jupyters_controller.rb +++ b/app/controllers/jupyters_controller.rb @@ -1,10 +1,38 @@ require 'net/http' class JupytersController < ApplicationController - include JupyterService + + before_action :shixun, only: [:open, :open1, :test, :save] + + def save_with_tpi + game = Game.find_by(identifier: params[:identifier]) + jupyter_save_with_game(game, params[:jupyter_port]) + render json: {status: 0} + end + + def save_with_tpm + shixun = Shixun.find_by(identifier: params[:identifier]) + jupyter_save_with_shixun(shixun, params[:jupyter_port]) + render json: {status: 0} + end + + def get_info_with_tpi + game = Game.find_by(identifier: params[:identifier]) + url = jupyter_url_with_game(game) + port = jupyter_port_with_game(game) + render json: {status: 0, url: url, port: port} + end + + def get_info_with_tpm + shixun = Shixun.find_by(identifier: params[:identifier]) + url = jupyter_url_with_shixun(shixun) + port = jupyter_port_with_shixun(shixun) + render json: {status: 0, url: url, port: port} + end + - before_action :shixun + private def open #打开tpm - juypter接口 diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index bd6d50d8c..48f05cac5 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -3,7 +3,6 @@ class ShixunsController < ApplicationController include ApplicationHelper include ElasticsearchAble include CoursesHelper - include JupyterService before_action :require_login, :check_auth, except: [:download_file, :index, :menus, :show, :show_right, :ranking_list, :discusses, :collaborators, :fork_list, :propaedeutics] @@ -25,10 +24,6 @@ class ShixunsController < ApplicationController before_action :special_allowed, only: [:send_to_course, :search_user_courses] - - - helper_method :jupyter_url_with_shixun, :jupyter_port_with_shixun - ## 获取课程列表 def index @shixuns = current_laboratory.shixuns.unhidden diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder index f3964bc09..3c7aa3e0c 100644 --- a/app/views/games/show.json.jbuilder +++ b/app/views/games/show.json.jbuilder @@ -19,7 +19,4 @@ else json.has_answer @has_answer json.choose_test_cases @choose_test_cases json.chooses @chooses -end - -json.jupyter_url jupyter_url_with_game(@game) -json.jupyter_port jupyter_port_with_game(@game) \ No newline at end of file +end \ No newline at end of file diff --git a/app/views/shixuns/show.json.jbuilder b/app/views/shixuns/show.json.jbuilder index 93647cda7..4a0c3ebd6 100644 --- a/app/views/shixuns/show.json.jbuilder +++ b/app/views/shixuns/show.json.jbuilder @@ -3,5 +3,3 @@ json.identity User.current.shixun_identity(@shixun) json.power @power json.partial! 'shixuns/top', locals: { shixun: @shixun, current_myshixun: @current_myshixun } json.secret_repository @shixun.shixun_secret_repository.present? -json.jupyter_url jupyter_url_with_shixun(@shixun) -json.jupyter_port jupyter_port_with_shixun(@shixun) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3dadc7c36..7f4fd95bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,10 +11,10 @@ Rails.application.routes.draw do resources :jupyters do collection do - get :open - get :open1 - get :test - get :save + get :save_with_tpi + get :save_with_tpm + get :get_info_with_tpi + get :get_info_with_tpm end end @@ -219,8 +219,6 @@ Rails.application.routes.draw do get :unlock_choose_answer get :get_choose_answer - post :update_jupyter - end collection do get :challenges @@ -244,7 +242,6 @@ Rails.application.routes.draw do end member do - post :update_jupyter post :copy get :propaedeutics get :show_right