add uuid check
This commit is contained in:
@@ -238,6 +238,48 @@ $(document).on('turbolinks:load', function() {
|
||||
|
||||
};
|
||||
|
||||
var observeExportStartButtons = function(){
|
||||
$('.export-start').on('click', function(e){
|
||||
e.preventDefault();
|
||||
$('#export-modal').modal({
|
||||
height: 250
|
||||
});
|
||||
$('#export-modal').modal('show');
|
||||
exportExerciseStart($(this).attr('data-exercise-id'));
|
||||
});
|
||||
}
|
||||
|
||||
var exportExerciseStart = function(exerciseID) {
|
||||
var $exerciseDiv = $('#export-exercise');
|
||||
// var accountLinkID = $exerciseDiv.attr('data-account-link');
|
||||
var $messageDiv = $exerciseDiv.children('.export-message');
|
||||
var $actionsDiv = $exerciseDiv.children('.export-exercise-actions');
|
||||
|
||||
$messageDiv.html('requesting status');
|
||||
$actionsDiv.html('spinning');
|
||||
|
||||
return $.ajax({
|
||||
type: 'POST',
|
||||
url: '/exercises/' + exerciseID + '/export_external_check',
|
||||
// data: {
|
||||
// account_link: accountLinkID
|
||||
// },
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.error) {
|
||||
$messageDiv.html(response.error);
|
||||
$actionsDiv.html('Retry?');
|
||||
}
|
||||
$messageDiv.html(response.message);
|
||||
return $actionsDiv.html(response.actions);
|
||||
},
|
||||
error: function(a, b, c) {
|
||||
return alert('error:' + c);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
var overrideTextareaTabBehavior = function() {
|
||||
$('.form-group textarea[name$="[content]"]').on('keydown', function(event) {
|
||||
if (event.which === TAB_KEY_CODE) {
|
||||
@@ -293,6 +335,7 @@ $(document).on('turbolinks:load', function() {
|
||||
// ignore tags table since it is in the dom before other tables
|
||||
if ($('table:not(#tags-table)').isPresent()) {
|
||||
enableBatchUpdate();
|
||||
observeExportStartButtons();
|
||||
} else if ($('.edit_exercise, .new_exercise').isPresent()) {
|
||||
execution_environments = $('form').data('execution-environments');
|
||||
file_types = $('form').data('file-types');
|
||||
@@ -303,6 +346,7 @@ $(document).on('turbolinks:load', function() {
|
||||
observeExecutionEnvironment();
|
||||
observeUnpublishedState();
|
||||
overrideTextareaTabBehavior();
|
||||
|
||||
} else if ($('#files.jstree').isPresent()) {
|
||||
var fileTypeSelect = $('#code_ocean_file_file_type_id');
|
||||
fileTypeSelect.on("change", function() {updateFileTemplates(fileTypeSelect.val())});
|
||||
|
@@ -176,3 +176,30 @@ a.file-heading {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#export-modal {
|
||||
.modal-content {
|
||||
min-height: unset;
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
#export-exercise{
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.export-message {
|
||||
flex-grow: 1;
|
||||
font-size: 12px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
.export-exercise-actions {
|
||||
max-width: 110px;
|
||||
min-width: 110px;
|
||||
}
|
||||
|
||||
.export-button {
|
||||
font-size: 12px;
|
||||
width: 100%;
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ class ExercisesController < ApplicationController
|
||||
|
||||
before_action :handle_file_uploads, only: [:create, :update]
|
||||
before_action :set_execution_environments, only: [:create, :edit, :new, :update]
|
||||
before_action :set_exercise_and_authorize, only: MEMBER_ACTIONS + [:push_proforma_xml, :clone, :implement, :working_times, :intervention, :search, :run, :statistics, :submit, :reload, :feedback, :study_group_dashboard]
|
||||
before_action :set_exercise_and_authorize, only: MEMBER_ACTIONS + [:push_proforma_xml, :clone, :implement, :working_times, :intervention, :search, :run, :statistics, :submit, :reload, :feedback, :study_group_dashboard, :export_external_check]
|
||||
before_action :set_external_user_and_authorize, only: [:statistics]
|
||||
before_action :set_file_types, only: [:create, :edit, :new, :update]
|
||||
before_action :set_course_token, only: [:implement]
|
||||
@@ -119,6 +119,48 @@ class ExercisesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def export_external_check
|
||||
@codeharbor_link = current_user.codeharbor_link
|
||||
url = 'http://localhost:3001/import_uuid_check'
|
||||
|
||||
conn = Faraday.new(url: url) do |faraday|
|
||||
faraday.options[:open_timeout] = 5
|
||||
faraday.options[:timeout] = 5
|
||||
|
||||
faraday.adapter Faraday.default_adapter
|
||||
end
|
||||
|
||||
error = false
|
||||
response_hash = {}
|
||||
message = ''
|
||||
begin
|
||||
response = conn.post do |req|
|
||||
req.headers['Content-Type'] = 'application/json'
|
||||
req.headers['Authorization'] = 'Bearer ' + @codeharbor_link.api_key
|
||||
req.body = {uuid: @exercise.uuid}.to_json
|
||||
end
|
||||
response_hash = JSON.parse(response.body, symbolize_names: true)
|
||||
message = response_hash[:message]
|
||||
rescue Faraday::ClientError
|
||||
message = 'an error occured'
|
||||
error = true
|
||||
end
|
||||
|
||||
render json: {
|
||||
message: message,
|
||||
actions: render_to_string(
|
||||
partial: 'export_actions',
|
||||
locals: {
|
||||
exercise: @exercise,
|
||||
exercise_found: response_hash[:exercise_found],
|
||||
update_right: response_hash[:update_right],
|
||||
error: error
|
||||
}
|
||||
)
|
||||
|
||||
}, status: 200
|
||||
end
|
||||
|
||||
def import_uuid_check
|
||||
user = user_for_oauth2_request
|
||||
return render json: {}, status: 401 if user.nil?
|
||||
|
@@ -7,7 +7,7 @@ class ExercisePolicy < AdminOrAuthorPolicy
|
||||
define_method(action) { admin? || teacher? }
|
||||
end
|
||||
|
||||
[:clone?, :destroy?, :edit?, :statistics?, :update?, :feedback?, :push_proforma_xml?].each do |action|
|
||||
[:clone?, :destroy?, :edit?, :statistics?, :update?, :feedback?, :push_proforma_xml?, :export_external_check?].each do |action|
|
||||
define_method(action) { admin? || author? }
|
||||
end
|
||||
|
||||
|
20
app/views/exercises/_export_actions.html.slim
Normal file
20
app/views/exercises/_export_actions.html.slim
Normal file
@@ -0,0 +1,20 @@
|
||||
- if error
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-button', onclick: "exportExerciseStart(#{exercise.id})" do
|
||||
i.fa.fa-refresh.confirm-icon
|
||||
= ' Retry'
|
||||
- else
|
||||
- if exercise_found
|
||||
- if update_right
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-action export-button', data: {'export-type' => 'export'} do
|
||||
i.fa.fa-check.confirm-icon
|
||||
= ' Overwrite'
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-action export-button', data: {'export-type' => 'create_new'} do
|
||||
i.fa.fa-check.confirm-icon-alt
|
||||
= ' Create new'
|
||||
- else
|
||||
= button_tag type: 'button', class:'btn btn-primary pull-right export-action export-button', data: {'export-type' => 'export'} do
|
||||
i.fa.fa-check.confirm-icon
|
||||
= ' Export'
|
||||
= button_tag type: 'submit', class:'btn btn-secondary pull-right export-button', data: {dismiss: 'modal'} do
|
||||
i.fa.fa-remove.abort-icon
|
||||
= ' Abort'
|
5
app/views/exercises/_export_dialogcontent.html.slim
Normal file
5
app/views/exercises/_export_dialogcontent.html.slim
Normal file
@@ -0,0 +1,5 @@
|
||||
#export-exercise
|
||||
.export-message
|
||||
= 'This should not be seen'
|
||||
.export-exercise-actions
|
||||
= 'This neither'
|
@@ -46,7 +46,9 @@ h1 = Exercise.model_name.human(count: 2)
|
||||
li = link_to(t('activerecord.models.user_exercise_feedback.other'), feedback_exercise_path(exercise), class: 'dropdown-item') if policy(exercise).feedback?
|
||||
li = link_to(t('shared.destroy'), exercise, data: {confirm: t('shared.confirm_destroy')}, method: :delete, class: 'dropdown-item') if policy(exercise).destroy?
|
||||
li = link_to(t('.clone'), clone_exercise_path(exercise), data: {confirm: t('shared.confirm_destroy')}, method: :post, class: 'dropdown-item') if policy(exercise).clone?
|
||||
li = link_to(t('exercises.export_codeharbor.label'), push_proforma_xml_exercise_path(exercise), method: :post, class: 'dropdown-item') if policy(exercise).push_proforma_xml?
|
||||
li = link_to(t('exercises.export_codeharbor.label'), '', class: 'dropdown-item export-start', data: {'exercise-id' => exercise.id}) if policy(exercise).push_proforma_xml?
|
||||
|
||||
= render('shared/pagination', collection: @exercises)
|
||||
p = render('shared/new_button', model: Exercise)
|
||||
|
||||
= render('shared/modal', id: 'export-modal', title: t('exercises.export_codeharbor.dialogtitle'), template: 'exercises/_export_dialogcontent')
|
||||
|
Reference in New Issue
Block a user