This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
13 collapse library and template checklists
13 collapse library and template checklists
- Loading branch information
1 parent
908170b
commit 479c7a2
Showing
60 changed files
with
550 additions
and
686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.