Skip to content

Commit

Permalink
58 log changes before revert 'contexts' model
Browse files Browse the repository at this point in the history
58 finalising this for now

58 finalising this for now

58 finalising this for now

62 simplify data model

62 simplify data model
  • Loading branch information
ferrisoxide committed Jul 8, 2024
1 parent c6d75bc commit 976111d
Show file tree
Hide file tree
Showing 63 changed files with 508 additions and 745 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ GEM
pundit (2.3.2)
activesupport (>= 3.0.0)
racc (1.8.0)
rack (3.1.3)
rack (3.1.6)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ApplicationController < ActionController::Base
helper_method :breadcrumbs

def pundit_user
UserContext.new(user: current_user, workspace: @checklist, checklist: @checklist, true_user:)
UserContext.new(user: current_user, true_user:)
end

alias user_context pundit_user
Expand Down
1 change: 0 additions & 1 deletion app/controllers/checklist_instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def destroy
private

def add_base_breadcrumbs
add_breadcrumb(@checklist.container.name, @checklist.container) if @checklist.container
add_breadcrumb(@checklist.title, @checklist.becomes(Checklist))
add_breadcrumb(@checklist.instance_model_name.titleize.pluralize, @checklist.becomes(Checklist))
end
Expand Down
54 changes: 5 additions & 49 deletions app/controllers/checklists_controller.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# frozen_string_literal: true

# ChecklistsController
class ChecklistsController < ApplicationController # rubocop:disable Metrics/ClassLength
class ChecklistsController < ApplicationController
before_action :load_checklist, only: %i[show edit update details]
before_action :load_container, only: %i[new create]
before_action :set_session_view
before_action :load_view, only: %i[show]

around_action :use_logidze_responsible, only: %i[create update]

after_action :load_group

def index = @checklists = policy_scope(Checklist)

def show
add_breadcrumb(@checklist.container.name, @checklist.container) if @checklist.container

if @checklist.is_a?(Checklists::Concurrent)
add_breadcrumb(@checklist.title, @checklist.becomes(Checklist))
add_breadcrumb(@checklist.instance_model_name.titleize.pluralize)
Expand All @@ -25,27 +20,24 @@ def show
end

def new
@checklist = Checklist.new(container: @container)
@checklist = Checklist.new(owner: current_user)

add_breadcrumb(@checklist.container.name, @checklist.container) if @checklist.container
add_breadcrumb('New Checklist')
end

def create
@checklist = build_new_checklist(@container)
@checklist = build_new_checklist

if @checklist.save
redirect_to edit_checklist_path(id: @checklist.id)
else
add_breadcrumb(@checklist.container.name, @checklist.container) if @checklist.container
add_breadcrumb('New Checklist')

render :new
end
end

def edit
add_breadcrumb(@checklist.container.name, @checklist.container)
add_breadcrumb(@checklist.title)
end

Expand All @@ -57,8 +49,6 @@ def update

# Move to a new controller
def details
add_breadcrumb(@checklist.container.name, @checklist.container) if @checklist.container

if @checklist.is_a?(Checklists::Concurrent)
add_breadcrumb(@checklist.title, @checklist.becomes(Checklist))
add_breadcrumb(@checklist.instance_model_name.titleize.pluralize)
Expand All @@ -71,11 +61,11 @@ def details

private

def build_new_checklist(container)
def build_new_checklist
checklist_type = sanitize_checklist_type(params[:checklist][:type])
checklist_klass = checklist_type.constantize

checklist_klass.new(container:).tap do |checklist|
checklist_klass.new(owner: current_user).tap do |checklist|
checklist.update(params_for_checklist)
end
end
Expand All @@ -97,18 +87,6 @@ def build_new_checklist(container)
data_entry_radio_secondary_color
].freeze

CONTAINER_TYPES = {
library: Library,
workspace: Workspace
}.freeze

def find_container(type, id)
klass = CONTAINER_TYPES[type.downcase.to_sym]
raise "Unknown container type: #{type}" unless klass

klass.find(id)
end

def params_for_checklist
params.require(required_param_key).permit(*BASE_PARAMS)
end
Expand All @@ -119,14 +97,6 @@ def params_for_checklist_data_entry_radio_additional_states
.permit(data_entry_radio_additional_states: %i[text color])
end

def params_for_container
if params[:container_type].present? && params[:container_id].present?
params.fetch(:container_type, :container_id)
else
params.fetch(:checklist).permit(:container_type, :container_id)
end
end

def required_param_key
@checklist.present? ? @checklist.class.name.parameterize.gsub('-', '_').to_sym : :checklist
end
Expand All @@ -144,20 +114,6 @@ def load_checklist
authorize @checklist
end

def load_container
@container = find_container(*params_for_container.values_at(:container_type, :container_id))
authorize @container, :create_checklist?
end

def load_group
case @container || @checklist&.container
when Library
group :library
when Workspace
group :workspace
end
end

def load_view
@view = (params[:view] || session[:view] || 'grid').to_sym
end
Expand Down
18 changes: 4 additions & 14 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@
# and the dashboard (when a user is signed in).
class HomeController < ApplicationController
skip_before_action :authenticate_user!, raise: false
before_action :load_workspace, only: :index

group :workspace

# def index = render(template, layout:)
before_action :load_breadcrumbs

def index
if user_signed_in?
redirect_to personal_workspaces_path
else
render 'landing_page', layout: 'landing_page'
end
render template, layout:
end

private
Expand All @@ -28,9 +20,7 @@ def layout
user_signed_in? ? 'application' : 'landing_page'
end

def load_workspace
return unless user_signed_in?

@checklists = current_user.checklists
def load_breadcrumbs
add_breadcrumb('Dashboard') if user_signed_in?
end
end
7 changes: 6 additions & 1 deletion app/controllers/workspaces_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# WorkspacesController
class WorkspacesController < ApplicationController
before_action :set_workspace, only: %i[show edit update]
before_action :set_workspace, only: %i[show edit update settings]

group :workspace

Expand Down Expand Up @@ -34,6 +34,11 @@ def personal
render :show
end

def settings
add_breadcrumb(@workspace.name, @workspace)
add_breadcrumb('Admin')
end

private

def set_workspace
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def render_icon(icon, classes: '')
render "layouts/shared/icons/#{icon}", classes:
end

def render_sidebar_item(title:, path:, icon:, active_group:, classes: '')
def render_sidebar_item(title:, path:, icon:, active_group:, classes: '', count: nil) # rubocop:disable Metrics/ParameterLists
active = active_group == controller.active_group

render 'layouts/shared/sidebar_item', title:, path:, icon:, active:, classes:
render 'layouts/shared/sidebar_item', title:, path:, icon:, active:, classes:, count:
end

def render_navbar_item(title:, path:, icon:, active_group:, classes: '')
Expand Down
3 changes: 2 additions & 1 deletion app/javascript/controllers/checklist_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class extends Controller {
}

toggle(event) {

debugger

let checked = event.target.checked
let csrfToken = document.querySelector('meta[name="csrf-token"]').content
Expand All @@ -29,6 +29,7 @@ export default class extends Controller {
let dataEntryComments = this.dataEntryCommentsValue

if (dataEntryComments == 'required') {
debugger
event.preventDefault();

let cancelDialogButtons = this.commentsDialogCancelButtonTargets
Expand Down
28 changes: 12 additions & 16 deletions app/models/checklist.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# frozen_string_literal: true

# Base class for all checklists.

# == Schema Information
#
# Table name: checklists
#
# id :uuid not null, primary key
# assignee_type :string
# container_type :string
# content :text
# data_entry_checkbox_checked_color :string default("green"), not null
# data_entry_comments :string default("disabled"), not null
# data_entry_comments :string default(NULL), not null
# data_entry_input_type :string default("checkbox"), not null
# data_entry_radio_additional_states :jsonb
# data_entry_radio_primary_color :string default("green"), not null
Expand All @@ -19,39 +20,34 @@
# instance_model_name :string default("Instance"), not null
# log_data :jsonb
# metadata :jsonb
# owner_type :string
# status :string
# title :string
# type :string
# created_at :datetime not null
# updated_at :datetime not null
# assignee_id :uuid
# container_id :uuid
# created_by_id :uuid
# owner_id :uuid
#
# Indexes
#
# index_checklists_on_assignee (assignee_type,assignee_id)
# index_checklists_on_container (container_type,container_id)
# index_checklists_on_created_by_id (created_by_id)
# index_checklists_on_status (status)
# index_checklists_on_title (title)
# index_checklists_on_type (type)
#
# Foreign Keys
#
# fk_rails_... (created_by_id => users.id)
# index_checklists_on_assignee (assignee_type,assignee_id)
# index_checklists_on_owner (owner_type,owner_id)
# index_checklists_on_status (status)
# index_checklists_on_title (title)
# index_checklists_on_type (type)
#
class Checklist < ApplicationRecord
include ActionView::Helpers::SanitizeHelper

has_logidze

string_enum :status, %i[draft published ready in_progress complete archived], default: :draft
string_enum :data_entry_comments, %i[disallowed allowed prompt required], default: :disabled
string_enum :data_entry_comments, %i[disallowed allowed prompt required], default: :disallowed

belongs_to :created_by, class_name: 'User', optional: true
belongs_to :assignee, polymorphic: true, optional: true
belongs_to :container, polymorphic: true, optional: true
belongs_to :owner, polymorphic: true

has_many :checklist_instances, dependent: :destroy

Expand Down
22 changes: 8 additions & 14 deletions app/models/checklists/concurrent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
#
# id :uuid not null, primary key
# assignee_type :string
# container_type :string
# content :text
# data_entry_checkbox_checked_color :string default("green"), not null
# data_entry_comments :string default("disabled"), not null
# data_entry_comments :string default(NULL), not null
# data_entry_input_type :string default("checkbox"), not null
# data_entry_radio_additional_states :jsonb
# data_entry_radio_primary_color :string default("green"), not null
Expand All @@ -19,27 +18,22 @@
# instance_model_name :string default("Instance"), not null
# log_data :jsonb
# metadata :jsonb
# owner_type :string
# status :string
# title :string
# type :string
# created_at :datetime not null
# updated_at :datetime not null
# assignee_id :uuid
# container_id :uuid
# created_by_id :uuid
# owner_id :uuid
#
# Indexes
#
# index_checklists_on_assignee (assignee_type,assignee_id)
# index_checklists_on_container (container_type,container_id)
# index_checklists_on_created_by_id (created_by_id)
# index_checklists_on_status (status)
# index_checklists_on_title (title)
# index_checklists_on_type (type)
#
# Foreign Keys
#
# fk_rails_... (created_by_id => users.id)
# index_checklists_on_assignee (assignee_type,assignee_id)
# index_checklists_on_owner (owner_type,owner_id)
# index_checklists_on_status (status)
# index_checklists_on_title (title)
# index_checklists_on_type (type)
#
module Checklists
# Checklist model for concurrent checklists.
Expand Down
Loading

0 comments on commit 976111d

Please sign in to comment.