mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-25 09:13:05 +08:00
Add error handling to create task modal
This commit is contained in:
parent
49afb5631d
commit
63a5459d21
7 changed files with 63 additions and 22 deletions
|
@ -10,6 +10,7 @@ var DasboardQuickStartWidget = (function() {
|
|||
function initNewTaskModal() {
|
||||
$('.quick-start-widget .new-task').click(() => {
|
||||
$('#create-task-modal').modal('show');
|
||||
$('#create-task-modal .select-block').attr('data-error', '');
|
||||
});
|
||||
|
||||
dropdownSelector.init(projectFilter, {
|
||||
|
@ -75,7 +76,7 @@ var DasboardQuickStartWidget = (function() {
|
|||
}
|
||||
});
|
||||
|
||||
$(createTaskButton).click(() => {
|
||||
$(createTaskButton).click((e) => {
|
||||
var params = {};
|
||||
if (dropdownSelector.getValues(projectFilter) === '0') {
|
||||
params.project = {
|
||||
|
@ -90,8 +91,15 @@ var DasboardQuickStartWidget = (function() {
|
|||
} else {
|
||||
params.experiment = { id: dropdownSelector.getValues(experimentFilter) };
|
||||
}
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
$('#create-task-modal .select-block').attr('data-error', '');
|
||||
$.post($(createTaskButton).data('ajaxUrl'), params, function(data) {
|
||||
window.location.href = data.my_module_path;
|
||||
}).error((response) => {
|
||||
var errorsObject = response.responseJSON.error_object;
|
||||
var errorsText = response.responseJSON.errors.name.join(' ');
|
||||
$(`#create-task-modal .select-block[data-error-object="${errorsObject}"]`).attr('data-error', errorsText);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -21,6 +21,12 @@
|
|||
margin-bottom: 5px;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
&::after {
|
||||
display: block;
|
||||
color: $brand-danger;
|
||||
content: attr(data-error);
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown-selector-container {
|
||||
|
@ -29,14 +35,18 @@
|
|||
}
|
||||
}
|
||||
|
||||
.new-projects-visibility {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.down-arrow {
|
||||
background-color: $color-white;
|
||||
box-shadow: -4px 4px 0 $color-black;
|
||||
display: inline-block;
|
||||
height: 38px;
|
||||
margin: 0 6px 24px 14px;
|
||||
margin: 0 11px 20px 14px;
|
||||
opacity: .2;
|
||||
width: 18px;
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.down-arrow::before {
|
||||
|
@ -45,14 +55,15 @@
|
|||
border-top: 6px solid transparent;
|
||||
content: "";
|
||||
height: 0;
|
||||
left: 40px;
|
||||
left: 46px;
|
||||
position: absolute;
|
||||
top: 185px;
|
||||
top: 36px;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.project-visibility-container {
|
||||
display: inline-block;
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
.project-visibility-title {
|
||||
|
@ -64,12 +75,13 @@
|
|||
|
||||
.sci-toggles-group {
|
||||
.sci-toggle-item {
|
||||
width: 143px;
|
||||
width: 130px;
|
||||
}
|
||||
|
||||
.sci-toggle-item-label {
|
||||
margin-left: -143px;
|
||||
width: 143px;
|
||||
margin-left: -130px;
|
||||
margin-bottom: 0;
|
||||
width: 130px;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,10 @@ module Dashboard
|
|||
my_module = CreateMyModuleService.new(current_user, current_team,
|
||||
project: @project || create_project_params,
|
||||
experiment: @experiment || create_experiment_params).call
|
||||
if my_module
|
||||
if my_module.errors.empty?
|
||||
render json: { my_module_path: protocols_my_module_path(my_module) }
|
||||
else
|
||||
render json: {}, status: :unprocessable_entity
|
||||
render json: { errors: my_module.errors, error_object: my_module.class.name }, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -8,19 +8,26 @@ class CreateExperimentService
|
|||
end
|
||||
|
||||
def call
|
||||
new_experiment = nil
|
||||
ActiveRecord::Base.transaction do
|
||||
unless @params[:project].class == Project
|
||||
@params[:project] = CreateProjectService.new(@user, @team, @params[:project]).call
|
||||
end
|
||||
raise ActiveRecord::Rollback unless @params[:project]
|
||||
unless @params[:project]&.errors&.empty?
|
||||
new_experiment = @params[:project]
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
||||
@params[:created_by] = @user
|
||||
@params[:last_modified_by] = @user
|
||||
|
||||
@experiment = @params[:project].experiments.create!(@params)
|
||||
create_experiment_activity
|
||||
@experiment
|
||||
@experiment = @params[:project].experiments.new(@params)
|
||||
|
||||
create_experiment_activity if @experiment.save
|
||||
|
||||
new_experiment = @experiment
|
||||
end
|
||||
new_experiment
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -9,12 +9,16 @@ class CreateMyModuleService
|
|||
end
|
||||
|
||||
def call
|
||||
new_my_module = nil
|
||||
ActiveRecord::Base.transaction do
|
||||
unless @params[:experiment].class == Experiment
|
||||
@params[:experiment][:project] = @params[:project]
|
||||
@params[:experiment] = CreateExperimentService.new(@user, @team, @params[:experiment]).call
|
||||
end
|
||||
raise ActiveRecord::Rollback unless @params[:experiment]
|
||||
unless @params[:experiment]&.errors&.empty?
|
||||
new_my_module = @params[:experiment]
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
||||
@my_module_params[:x] ||= 0
|
||||
@my_module_params[:y] ||= 0
|
||||
|
@ -29,8 +33,9 @@ class CreateMyModuleService
|
|||
@my_module.save!
|
||||
create_my_module_activity
|
||||
@params[:experiment].generate_workflow_img
|
||||
@my_module
|
||||
new_my_module = @my_module
|
||||
end
|
||||
new_my_module
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -8,15 +8,24 @@ class CreateProjectService
|
|||
end
|
||||
|
||||
def call
|
||||
new_project = nil
|
||||
ActiveRecord::Base.transaction do
|
||||
@params[:created_by] = @user
|
||||
@params[:last_modified_by] = @user
|
||||
|
||||
@project = @team.projects.create!(@params)
|
||||
@project.user_projects.create!(role: :owner, user: @user)
|
||||
create_project_activity
|
||||
@project
|
||||
@project = @team.projects.new(@params)
|
||||
|
||||
if @project.save
|
||||
@project.user_projects.create!(role: :owner, user: @user)
|
||||
create_project_activity
|
||||
new_project = @project
|
||||
else
|
||||
new_project = @project
|
||||
raise ActiveRecord::Rollback
|
||||
|
||||
end
|
||||
end
|
||||
new_project
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<div class="description">
|
||||
<%= t("dashboard.create_task_modal.description") %>
|
||||
</div>
|
||||
<div class="select-block">
|
||||
<div class="select-block" data-error-object="Project" data-error="">
|
||||
<label><%= t("dashboard.create_task_modal.project") %></label>
|
||||
<select class="project-filter"
|
||||
data-ajax-url="<%= dashboard_quick_start_project_filter_path %>"
|
||||
|
@ -33,7 +33,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="select-block">
|
||||
<div class="select-block" data-error-object="Experiment" data-error="">
|
||||
<label><%= t("dashboard.create_task_modal.experiment") %></label>
|
||||
<select class="experiment-filter"
|
||||
data-ajax-url="<%= dashboard_quick_start_experiment_filter_path %>"
|
||||
|
|
Loading…
Reference in a new issue