Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add success/error messages and improved redirections for most actions #1811

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ def edit

def create
@collection = Collection.create(collection_params)
redirect_to collections_path
redirect_to collections_path, notice: t(".success")
end

def update
@collection.update(collection_params)
redirect_to collections_path
redirect_to collections_path, notice: t(".success")
end

def destroy
@collection.destroy
redirect_to collections_path
redirect_to collections_path, notice: t(".success")
end

private
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/creators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ def edit

def create
@creator = Creator.create(creator_params)
redirect_to creators_path
redirect_to creators_path, notice: t(".success")
end

def update
@creator.update(creator_params)
redirect_to creators_path
redirect_to creators_path, notice: t(".success")
end

def destroy
@creator.destroy
redirect_to creators_path
redirect_to creators_path, notice: t(".success")
end

private
Expand Down
17 changes: 11 additions & 6 deletions app/controllers/libraries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def create
@library.tag_regex = params[:tag_regex]
if @library.valid?
Scan::DetectFilesystemChangesJob.perform_later(@library.id)
redirect_to @library
redirect_to @library, notice: t(".success")
else
flash.now[:alert] = t(".failure")
render :new
end
end
Expand All @@ -40,13 +41,17 @@ def update
@library.update(library_params)
uptags = library_params[:tag_regex].reject(&:empty?)
@library.tag_regex = uptags
@library.save
redirect_to models_path
if @library.save
redirect_to models_path, notice: t(".success")
else
flash.now[:alert] = t(".failure")
render :edit
end
end

def scan
Scan::DetectFilesystemChangesJob.perform_later(@library.id)
redirect_to @library
redirect_back_or_to @library, notice: t(".success")
end

def scan_all
Expand All @@ -57,13 +62,13 @@ def scan_all
Scan::DetectFilesystemChangesJob.perform_later(library.id)
end
end
redirect_to models_path
redirect_back_or_to models_path, notice: t(".success")
end

def destroy
authorize @library
@library.destroy
redirect_to libraries_path
redirect_to libraries_path, notice: t(".success")
end

private
Expand Down
13 changes: 8 additions & 5 deletions app/controllers/model_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ def show
end

def update
@file.update(file_params)
@file.set_printed_by_user(current_user, params[:model_file][:printed] === "1")
redirect_to [@library, @model, @file]
if @file.update(file_params)
@file.set_printed_by_user(current_user, params[:model_file][:printed] === "1")
redirect_back_or_to [@library, @model, @file], notice: t(".success")
else
redirect_back_or_to [@library, @model, @file], alert: t(".failure")
end
end

def bulk_edit
Expand All @@ -42,13 +45,13 @@ def bulk_update
end
end
end
redirect_to library_model_path(@library, @model)
redirect_back_or_to library_model_path(@library, @model), notice: t(".success")
end

def destroy
authorize @file
@file.delete_from_disk_and_destroy
redirect_to library_model_path(@library, @model)
redirect_back_or_to library_model_path(@library, @model), notice: t(".success")
end

private
Expand Down
11 changes: 6 additions & 5 deletions app/controllers/models_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ def edit

def update
if @model.update(model_params)
redirect_to [@model.library, @model]
redirect_to [@model.library, @model], notice: t(".success")
else
edit # Load creators and collections
flash.now[:alert] = t(".failure")
render :edit
end
end
Expand All @@ -52,13 +53,13 @@ def merge
if params[:target] && (target = (@model.parents.find { |x| x.id == params[:target].to_i }))
@model.merge_into! target
Scan::CheckModelIntegrityJob.perform_later(target.id)
redirect_to [@library, target]
redirect_to [@library, target], notice: t(".success")
elsif params[:all] && @model.contains_other_models?
@model.contained_models.each do |child|
child.merge_into! @model
end
Scan::CheckModelIntegrityJob.perform_later(@model.id)
redirect_to [@library, @model]
redirect_to [@library, @model], notice: t(".success")
else
render status: :bad_request
end
Expand Down Expand Up @@ -88,13 +89,13 @@ def bulk_update
end
end
end
redirect_to edit_models_path(@filters)
redirect_back_or_to edit_models_path(@filters), notice: t(".success")
end

def destroy
authorize @model
@model.delete_from_disk_and_destroy
redirect_to library_path(@library)
redirect_back_or_to library_path(@library), notice: t(".success")
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ def index
def update
@problem = Problem.unscoped.find(params[:id])
@problem.update!(permitted_params)
flash[:notice] = t(
notice = t(
(@problem.ignored ? ".ignored" : ".unignored"),
name: @problem.problematic.name,
message: t("problems.%{type}_%{category}.title" % {type: @problem.problematic_type.underscore, category: @problem.category})
)
redirect_to problems_path
redirect_back_or_to problems_path, notice: notice
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def update
update_folder_settings(params[:folders])
update_tagging_settings(params[:model_tags])
end
redirect_to user_settings_path(@user)
redirect_to user_settings_path(@user), notice: t(".success")
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def create
if params[:post][:scan_after_upload] == "1"
Scan::DetectFilesystemChangesJob.perform_later(library.id)
end
redirect_to libraries_path
redirect_to libraries_path, notice: t(".success")
end

private
Expand Down
48 changes: 48 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,24 @@ en:
collections:
collection:
no_preview: no preview availiable
create:
success: New collection details saved.
destroy:
success: Collection deleted!
general:
edit: Edit Collection
new: New Collection
index:
view_unassigned_models: View unassigned
update:
success: Collection details saved.
creators:
create:
success: New creator details saved.
destroy:
success: Creator deleted!
update:
success: Creator details saved.
general:
delete: Delete
edit: Edit
Expand All @@ -47,8 +60,20 @@ en:
danger: Danger
info: Info
libraries:
create:
failure: An error occurred, and the library could not be saved.
success: New library created!
destroy:
success: Library deleted!
general:
new: New Library
scan:
success: Library scan started.
scan_all:
success: Scan started for all libraries.
update:
failure: An error occurred, and the library could not be saved.
success: Library details saved.
licenses:
CC-BY-40: Creative Commons Attribution
CC-BY-NC-40: Creative Commons Attribution NonCommercial
Expand All @@ -60,6 +85,24 @@ en:
CC0-10: Creative Commons Zero
LicenseRef-Commercial: Commercial; private use only
MIT: MIT
model_files:
bulk_update:
success: Files updated successfully.
destroy:
success: File deleted!
update:
failure: An error occurred and file details could not be saved.
success: File details saved.
models:
bulk_update:
success: Models updated successfully.
destroy:
success: Model deleted!
merge:
success: Models merged successfully.
update:
failure: An error occurred and the model details could not be saved.
success: Model details saved.
problems:
categories:
duplicate: Duplicate files
Expand Down Expand Up @@ -124,13 +167,18 @@ en:
under_512: Up to 512 MB
under_64: Up to 64 MB
under_8: Up to 8 MB
update:
success: Settings saved.
sites:
cgtrader: CGTrader
comicsgamesandthings: Comics, Games, and Things
cults3d: Cults3D
myminifactory: MyMiniFactory
theminiindex: The Mini Index
thingiverse: Thingiverse
uploads:
create:
success: File(s) uploaded successfully.
views:
pagination:
first: "« First"
Expand Down
1 change: 1 addition & 0 deletions content/VanDAM
Loading