diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb deleted file mode 100644 index 57060720..00000000 --- a/app/controllers/assignments_controller.rb +++ /dev/null @@ -1,71 +0,0 @@ -class AssignmentsController < ApplicationController - before_action :require_user! - before_action :set_assignment, only: %i[ show edit update destroy ] - - # GET /assignments or /assignments.json - def index - @assignments = Assignment.all - end - - # GET /assignments/1 or /assignments/1.json - def show - end - - # GET /assignments/new - def new - @assignment = Assignment.new - end - - # GET /assignments/1/edit - def edit - end - - # POST /assignments or /assignments.json - def create - @assignment = Assignment.new(assignment_params) - - respond_to do |format| - if @assignment.save - format.html { redirect_to assignment_url(@assignment), notice: "Assignment was successfully created." } - format.json { render :show, status: :created, location: @assignment } - else - format.html { render :new, status: :unprocessable_entity } - format.json { render json: @assignment.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /assignments/1 or /assignments/1.json - def update - respond_to do |format| - if @assignment.update(assignment_params) - format.html { redirect_to assignment_url(@assignment), notice: "Assignment was successfully updated." } - format.json { render :show, status: :ok, location: @assignment } - else - format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @assignment.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /assignments/1 or /assignments/1.json - def destroy - @assignment.destroy! - - respond_to do |format| - format.html { redirect_to assignments_url, notice: "Assignment was successfully destroyed." } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_assignment - @assignment = Assignment.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def assignment_params - params.require(:assignment).permit(:user_id, :project_id, :status) - end -end diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb deleted file mode 100644 index 44fed292..00000000 --- a/app/controllers/clients_controller.rb +++ /dev/null @@ -1,55 +0,0 @@ -class ClientsController < ApplicationController - before_action :require_user! - before_action :set_client, only: %i[ show edit update toggle_archived ] - - def index - @clients = current_company.clients.all - end - - def show - end - - def new - @client = Client.new - end - - def edit - end - - def create - @client = current_company.clients.new(create_client_params) - - if @client.save - redirect_to client_url(@client), notice: "Client was successfully created." - else - render :new, status: :unprocessable_entity - end - end - - def update - if @client.update(update_client_params) - redirect_to client_url(@client), notice: "Client was successfully updated." - else - render :edit, status: :unprocessable_entity - end - end - - def toggle_archived - @client.toggle_archived! - - redirect_to clients_url, notice: "Client status was successfully updated." - end - - private - def set_client - @client = current_company.clients.find(params[:id]) - end - - def create_client_params - params.require(:client).permit(:name, :description) - end - - def update_client_params - params.require(:client).permit(:name, :description, :status, :avatar) - end -end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb deleted file mode 100644 index 86526afe..00000000 --- a/app/controllers/projects_controller.rb +++ /dev/null @@ -1,54 +0,0 @@ -class ProjectsController < ApplicationController - before_action :require_user! - before_action :set_project, only: %i[ show edit update ] - - def index - @projects = Project.includes(:company). all - end - - def show - end - - def new - @client = Client.find_by(id: params[:client_id]) # optional - @project = Project.new( - client_id: params[:client_id], - - # TODO: make these configurable? - status: Project::UNCONFIRMED, - payment_frequency: Project::MONTHLY - ) - end - - def edit - end - - def create - @project = Project.new(project_params) - - if @project.save - redirect_to project_url(@project), notice: "Project was successfully created." - else - render :new, status: :unprocessable_entity - end - end - - def update - if @project.update(project_params) - redirect_to project_url(@project), notice: "Project was successfully updated." - else - render :edit, status: :unprocessable_entity - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_project - @project = Project.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def project_params - params.require(:project).permit(:client_id, :name, :status, :cost, :payment_frequency) - end -end diff --git a/app/controllers/settings/users_controller.rb b/app/controllers/settings/users_controller.rb index 1c4a863e..9b851ce6 100644 --- a/app/controllers/settings/users_controller.rb +++ b/app/controllers/settings/users_controller.rb @@ -45,7 +45,11 @@ def create rescue ActiveRecord::RecordInvalid @user = @command.user @user.valid? - render :new + + respond_to do |format| + format.html { render :new } + format.turbo_stream + end end end diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index a0bb8666..81918f84 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -6,11 +6,24 @@ def show end def update - if current_company.update(update_params) - flash[:success] = "Company updated successfully" + # handle avatar changes first + if update_params[:avatar].present? + current_company.assign_attributes(avatar: update_params[:avatar]) + current_company.attachment_changes.any? && current_company.save + end + + current_company.assign_attributes(update_params.except(:avatar)) + + if current_company.save + flash[:success] = "Updates saved!" redirect_to settings_path else - render :show + flash.now[:error] = "Some information couldn't be saved." + + respond_to do |format| + format.turbo_stream + format.html { render :show } + end end end diff --git a/app/controllers/users/profile_controller.rb b/app/controllers/users/profile_controller.rb index 9b21bb15..6ab0a24f 100644 --- a/app/controllers/users/profile_controller.rb +++ b/app/controllers/users/profile_controller.rb @@ -4,11 +4,24 @@ def show end def update - if current_user.update(user_params) - flash[:notice] = 'Your profile was updated successfully' + # handle avatar changes first + if user_params[:avatar].present? + current_user.assign_attributes(avatar: user_params[:avatar]) + current_user.attachment_changes.any? && current_user.save + end + + current_user.assign_attributes(user_params.except(:avatar)) + + if current_user.save + flash[:success] = 'Your profile was updated successfully' redirect_to users_profile_path else - render :show + flash.now[:error] = 'There was a problem updating your profile' + + respond_to do |format| + format.turbo_stream + format.html { render :show } + end end end diff --git a/app/helpers/assignments_helper.rb b/app/helpers/assignments_helper.rb deleted file mode 100644 index 6f7c33b9..00000000 --- a/app/helpers/assignments_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module AssignmentsHelper -end diff --git a/app/helpers/clients_helper.rb b/app/helpers/clients_helper.rb deleted file mode 100644 index 90159068..00000000 --- a/app/helpers/clients_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ClientsHelper -end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb deleted file mode 100644 index db5c5ce1..00000000 --- a/app/helpers/projects_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ProjectsHelper -end diff --git a/app/models/company.rb b/app/models/company.rb index 4f6dce53..c2fb1530 100644 --- a/app/models/company.rb +++ b/app/models/company.rb @@ -39,4 +39,17 @@ def can_access?(user:) membership = memberships.find_by(user: user) membership.present? && membership.active? end + + def restore_avatar + if avatar.attached? && avatar.changed? + original_picture = avatar.attachment_was + if original_picture + # Detach the current attachment + avatar.detach + + # Reattach the original attachment + avatar.attach(original_picture) + end + end + end end diff --git a/app/views/assignments/_assignment.html.erb b/app/views/assignments/_assignment.html.erb deleted file mode 100644 index 55b7ec96..00000000 --- a/app/views/assignments/_assignment.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
- User: - <%= assignment.user_id %> -
- -- Project: - <%= assignment.project_id %> -
- -- Status: - <%= assignment.status %> -
- - <% if action_name != "show" %> - <%= link_to "Show this assignment", assignment, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - <%= link_to "Edit this assignment", edit_assignment_path(assignment), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> -<%= notice %>
- <% end %> - -<%= notice %>
- <% end %> - - <%= render @assignment %> - - <%= link_to "Edit this assignment", edit_assignment_path(@assignment), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -