Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
13 collapse library and template checklists
Browse files Browse the repository at this point in the history
13 collapse library and template checklists
  • Loading branch information
ferrisoxide committed Apr 24, 2024
1 parent 908170b commit 479c7a2
Show file tree
Hide file tree
Showing 60 changed files with 550 additions and 686 deletions.
76 changes: 55 additions & 21 deletions app/controllers/library/checklists_controller.rb
Original file line number Diff line number Diff line change
@@ -1,54 +1,88 @@
# frozen_string_literal: true

module Library
# ChecklistsController
# Controller for library checklists
class ChecklistsController < ApplicationController
group :library

before_action :load_checklist, only: %i[show edit update copy_to_workspace publish]

def index
@checklists = Checklist.all
@checklists = policy_scope(Library::Checklist).all
authorize Library::Checklist
end

def show
@checklist = Checklist.find(params[:id])
end
def show; end

def new
@checklist = Checklist.new
@checklist = Library::Checklist.new
authorize @checklist
end

def create
@checklist = Checklist.new(checklist_params)
@checklist = Library::Checklist.new(checklist_params)
authorize @checklist

if @checklist.save
redirect_to library_checklists_path
redirect_to library_checklist_path(@checklist)
else
render :new
end
end

def edit
@checklist = Checklist.find(params[:id])
end
def edit; end

def update
@checklist = Checklist.find(params[:id])
if @checklist.update(checklist_params)
redirect_to library_checklists_path
@checklist.update(checklist_params)

redirect_to library_checklist_path(@checklist)
end

# NOTE: This is a custom action that is not part of the standard RESTful actions
def copy_to_workspace
workspace_checklist = build_workspace_checklist(@checklist)

if workspace_checklist.save
redirect_to workspace_checklist_path(workspace_checklist),
notice: 'Checklist successfully copied to your workspace'
else
render :edit
render :show, notice: 'Failed to copy checklist to workspace'
end
end

def destroy
@checklist = Checklist.find(params[:id])
@checklist.destroy
redirect_to library_checklists_path
# NOTE: This is a custom action that is not part of the standard RESTful actions
def publish
authorize @checklist

if @checklist.update(status: :published)
redirect_to library_checklist_path(@checklist), notice: 'Checklist published'
else
redirect_to library_checklist_path(@checklist), notice: 'Checklist failed to publish'
end
end

def checklist_params
params
.require(:library_checklist)
.permit(policy(Library::Checklist).permitted_attributes)
end

private

def checklist_params
params.require(:checklist).permit(:name, :description)
# TODO: Refactor this into an event object? In any case, change this use the new Workspace::Checklist model
# when it becomes available
def build_workspace_checklist(checklist)
Workspace::Checklist.new(
title: checklist.title,
content: checklist.content.body,
assignee: current_user,
created_by: checklist.created_by
)
end

def load_checklist
@checklist = Library::Checklist.find(params[:id])
authorize @checklist
end
end
end
88 changes: 0 additions & 88 deletions app/controllers/templates/checklists_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/workspace/checklists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def show
end

def edit
@checklist = Templates::Checklist.find(params[:id])
@checklist = Library::Checklist.find(params[:id])
end

def update
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/checklists_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# Helper methods for checklists
module ChecklistsHelper
STATUS_DOT_CLASSES = {
Templates::Checklist => {
Library::Checklist => {
draft: 'text-yellow-500 bg-yellow-100/10',
published: 'text-green-400 bg-green-400/10',
archived: 'text-red-400 bg-red-400/10'
},
Library::Checklist => {}
Workspace::Checklist => {}
}.freeze

def render_checklist_status_dot(checklist)
Expand Down
5 changes: 5 additions & 0 deletions app/helpers/library/checklists_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
module Library
# ChecklistsHelper
module ChecklistsHelper
def render_visibility_badge(checklist)
render partial: '/library/shared/visibilty_badge', locals: { text: checklist.public? ? 'Public' : 'Private' }
end
end
end

# app/views/library/shared/_visibilty_badge.erb
7 changes: 0 additions & 7 deletions app/helpers/templates/checklists_helper.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class extends Controller {
}

showPreviewPanel(event) {
this.showPanel(event, this.previewPanelTarget, [tthis.detailsPanelTarget]);
this.showPanel(event, this.previewPanelTarget, [this.detailsPanelTarget]);
}

showDetailsPanel(event) {
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

# Base mailer
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
default from: 'from@obsek.io'
layout 'mailer'
end
5 changes: 4 additions & 1 deletion app/models/checklist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
#
# @abstract
# @see Library::Checklist
# @see Templates::Checklist
# @see Library::Checklist
class Checklist < ApplicationRecord
has_markdown :content

string_enum :instance_model, %i[single longitudinal concurrent], default: :single

belongs_to :created_by, class_name: 'User', optional: true
belongs_to :assignee, polymorphic: true, optional: false

has_many :checklist_instances, dependent: :destroy

# Returns the single instance of the checklist.
Expand Down
3 changes: 3 additions & 0 deletions app/models/library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@

# Module containing library-related models, concerns and service classes
module Library
def self.table_name_prefix
'library_'
end
end
11 changes: 9 additions & 2 deletions app/models/library/checklist.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# frozen_string_literal: true

module Library
# Checklist belonging to a library
class Checklist < Checklist
# Checklist belonging to the library
class Checklist < ApplicationRecord
has_markdown :content

string_enum :status, %i[draft published archived], default: :draft

validates :title, presence: true

belongs_to :created_by, class_name: 'User', optional: true
end
end
8 changes: 0 additions & 8 deletions app/models/templates.rb

This file was deleted.

12 changes: 0 additions & 12 deletions app/models/templates/checklist.rb

This file was deleted.

Loading

0 comments on commit 479c7a2

Please sign in to comment.