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