mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 09:23:58 +08:00
Add external_protocols#index action
This commit is contained in:
parent
2a61075156
commit
f7c6f78925
5 changed files with 55 additions and 7 deletions
|
@ -1,3 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ExternalProtocolsController < ApplicationController
|
||||
before_action :load_vars
|
||||
before_action :check_import_permissions, only: [:create]
|
||||
|
@ -5,15 +7,20 @@ class ExternalProtocolsController < ApplicationController
|
|||
# GET
|
||||
def index
|
||||
# list_protocols = SearchService.call(index_params)
|
||||
succeed = false
|
||||
list_protocols = [
|
||||
succeed = true
|
||||
protocols = [
|
||||
{ name: 'Protocol1' },
|
||||
{ name: 'Protocol2' },
|
||||
{ name: 'Protocol3' }
|
||||
]
|
||||
|
||||
if succeed
|
||||
render json: list_protocols
|
||||
render json: {
|
||||
html: render_to_string(
|
||||
partial: 'protocol_importers/list_of_protocol_cards.html.erb',
|
||||
locals: { protocols: protocols }
|
||||
)
|
||||
}
|
||||
else
|
||||
render json: {
|
||||
errors: { protocol: 'error_placeholder' }
|
||||
|
@ -70,6 +77,10 @@ class ExternalProtocolsController < ApplicationController
|
|||
params.permit(:protocol_source, :key, :page_id, :page_size, :order_field, :order_dir)
|
||||
end
|
||||
|
||||
def show_params
|
||||
params.permit(:protocol_source, :protocol_id)
|
||||
end
|
||||
|
||||
def new_params
|
||||
params.permit(:protocol_source, :protocol_client_id)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<% protocols.each do |protocol| %>
|
||||
<%= render partial: 'protocol_importers/protocol_card',
|
||||
locals: { protocol: protocol } %>
|
||||
<hr>
|
||||
<% end %>
|
3
app/views/protocol_importers/_protocol_card.html.erb
Normal file
3
app/views/protocol_importers/_protocol_card.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div class='protocol-card'>
|
||||
<h2><%= protocol[:name] %></h2>
|
||||
</div>
|
|
@ -206,12 +206,15 @@ Rails.application.routes.draw do
|
|||
get 'atwho_my_modules', to: 'at_who#my_modules'
|
||||
get 'atwho_menu_items', to: 'at_who#menu_items'
|
||||
end
|
||||
|
||||
# External protocols routes
|
||||
get 'list_external_protocol', to: 'external_protocols#index'
|
||||
get 'build_external_protocol', to: 'external_protocols#new'
|
||||
post 'import_external_protocol', to: 'external_protocols#create'
|
||||
|
||||
match '*path',
|
||||
to: 'teams#routing_error',
|
||||
via: [:get, :post, :put, :patch]
|
||||
|
||||
get 'build_external_protocol', to: 'external_protocols#new'
|
||||
post 'import_external_protocol', to: 'external_protocols#create'
|
||||
end
|
||||
|
||||
get 'projects/archive', to: 'projects#archive', as: 'projects_archive'
|
||||
|
|
|
@ -9,6 +9,33 @@ describe ExternalProtocolsController, type: :controller do
|
|||
let(:team) { create :team, created_by: user }
|
||||
let!(:user_team) { create :user_team, :admin, user: user, team: team }
|
||||
|
||||
describe 'GET index' do
|
||||
let(:params) do
|
||||
{
|
||||
team_id: team.id,
|
||||
key: 'search_string',
|
||||
protocol_source: 'protocolsio/v3',
|
||||
page_id: 1,
|
||||
page_size: 10,
|
||||
order_field: 'activity',
|
||||
order_dir: 'desc'
|
||||
}
|
||||
end
|
||||
|
||||
let(:action) { get :index, params: params }
|
||||
|
||||
it 'returns JSON, 200 response when protocol parsing was valid' do
|
||||
action
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.content_type).to eq 'application/json'
|
||||
end
|
||||
|
||||
it 'contains html key in the response' do
|
||||
action
|
||||
expect(JSON.parse(response.body)).to have_key('html')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET new' do
|
||||
let(:params) do
|
||||
{
|
||||
|
@ -50,7 +77,6 @@ describe ExternalProtocolsController, type: :controller do
|
|||
expect(response).to have_http_status(:bad_request)
|
||||
expect(response.content_type).to eq 'application/json'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'POST create' do
|
||||
|
|
Loading…
Reference in a new issue