Skip to content

Commit

Permalink
Add Quick Links and user projects table
Browse files Browse the repository at this point in the history
Each division now has a Quick Links section that should be only editable
by division administrators. I also added a table that shows the current
projects for the user.
  • Loading branch information
Novruu committed Nov 5, 2024
1 parent 1dcc82c commit d3185d0
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 53 deletions.
48 changes: 26 additions & 22 deletions app/assets/stylesheets/admin/dashboard_beta/_dashboard.scss
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
.admin-dashboard_beta {
.block {
div {
> div {
display: flex;
flex-direction: row;
gap: 14px;
height: 27.5vw;
overflow: hidden;
gap: 20px;
margin-bottom: 20px;

section {
width: 50%;
}
> section {
flex: 1;

section:last-child {
> .test-chart {
object-fit: contain;
height: 100%;
width: 100%;
display: block;
}

> a {
text-align: center;
display: block;
line-height: 30px;
}
}

> section:last-child {
.test-chart {
height: calc(100% - 30px);
}
}
}

> div {
margin-bottom: 14px;
}

section {
.test-chart {
object-fit: contain;
height: 100%;
width: 100%;
display: block;
> section.quick-notes {
> h2, > div {
width: calc(50% - 2.5px);
display: inline-block;
}

a {
text-align: center;
display: block;
line-height: 30px;
.col-sm-10 {
width: 100% !important;
}
}
}
Expand Down
44 changes: 38 additions & 6 deletions app/controllers/admin/dashboard_beta_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
class Admin::DashboardBetaController < Admin::AdminController
def dashboard
authorize :dashboard
@person = Person.find(current_user.profile_id)
end
class Admin::DashboardBetaController < Admin::AdminController

STATUS_FILTERS = %w(all active completed)

def dashboard
authorize :dashboard
@person = Person.find(current_user.profile_id)
@division = selected_division_or_root

prep_projects_grid_for_current_user
end

private

def prep_projects_grid_for_current_user
# Projects belonging to the current user
# 15 most recent projects, sorted by created date, then updated date
@recent_projects = @person.active_agent_projects

@recent_projects_grid = initialize_wice_grid(@recent_projects, @person.id)

@status_filter_options = STATUS_FILTERS.map { |f| [I18n.t("dashboard.status_options.#{f}"), f] }
end

private

def initialize_wice_grid(projects, person_id)
initialize_grid(
projects,
include: [:primary_agent, :secondary_agent],
order: "projects.order_by_agent",
custom_order: {
"projects.order_by_agent" => ->(_col) { Arel.sql(Project.dashboard_order(person_id)) },
},
name: "projects_person_#{person_id}",
enable_export_to_csv: false
)
end
end

2 changes: 1 addition & 1 deletion app/controllers/admin/divisions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def destroy
def prep_division_params(action)
permitted = [:name, :description, :logo, :logo_text, :membership_status, :short_name, :homepage, :logo_cache,
:default_currency_id, :qb_department_id, :public, :banner_fg_color, :banner_bg_color,
:accent_main_color, :accent_fg_color, :public_primary_color, :public_secondary_color, :public_accent_color, :notify_on_new_logs, locales: []]
:accent_main_color, :accent_fg_color, :public_primary_color, :public_secondary_color, :public_accent_color, :notify_on_new_logs, :quick_links, locales: []]
permitted << :parent_id if action == :create
params.require(:division).permit(permitted)
end
Expand Down
8 changes: 8 additions & 0 deletions app/policies/dashboard_beta_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class DashboardBetaPolicy < ApplicationPolicy
class Scope < DivisionOwnedScope
end

def dashboard?
true
end
end
24 changes: 24 additions & 0 deletions app/views/admin/dashboard_beta/_quicklinks_form.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
= simple_form_for([:admin, @division],
html: { \
class: 'form-horizontal organization-record',
},
wrapper: :horizontal_form_condensed,
defaults: { \
input_html: {class: 'form-element form-control'},
},
) do |f|

- form_identifier = 'division_quicklinks'
- popover_options = {placement: 'left'}

= error_notification(f)


= f.input :quick_links, label: false, hint: false, as: :summernote
.view-element = sanitize(@division.quick_links)
= f.input_field :quick_links, label: false, hint: false, as: :summernote

.actions.form-element
= f.submit class: 'update-action btn btn-primary'
= "Update Notes"
.clearfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
= define_grid(grid, hide_csv_button: true,
html: {class: 'rowlink table-hover', data: {link: @csv_mode ? nil : 'row'}}) do |g|

- g.row_attributes do |project|
- if project.primary_agent_id == person.id
- {class: 'bold'}

- g.blank_slate { grid.no_records_at_all = true; "" }

- g.column name: 'LID', attribute: 'id', filter: false, in_csv: false,
ordering: false do |project|
- if project.type == 'BasicProject'
- link_to(project.id, admin_basic_project_path(project.id))
- else
- link_to(project.id, admin_loan_path(project.id))

- g.column name: 'Project Name', attribute: 'name', filter: false, in_csv: false,
ordering: false do |project|
- project.name

- g.column name: t('common.role'), attribute: 'primary_agent_id', filter: false,
ordering: false do |project|
- if project.primary_agent_id == person.id
- t('common.first')
- else
- t('common.second')

- g.column name: t('activerecord.attributes.project.status'), attribute: 'status_value',
filter: false, ordering: false do |project|
- content_tag(:span, project.status,
class: "project-status #{project.status_value == 'completed' ? 'completed' : 'active'}")

- g.column name: 'Percentage of memo complete', attribute: 'name', filter: false, in_csv: false,
ordering: false do |project|
- "Sample percentage"

- g.column name: 'Next steps', attribute: 'name', filter: false, in_csv: false,
ordering: false do |project|
- "Sample steps"
44 changes: 21 additions & 23 deletions app/views/admin/dashboard_beta/dashboard.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@
section.section.active-loans
img.test-chart src="/assets/new_dashboard_sample_barchart.png"
a View repayment report
section.section.project-steward-data
table.table.table-bordered
tr
th LID
th Project Name
th Role
th Status
th Percentage of memo complete
th Next steps
tr
td 1
td Sample project
td Sample role
td Sample status
td 50%
td Sample steps
tr
td 2
td Sample project
td Sample role
td Sample status
td 50%
td Sample steps
section.section.recent-projects.projects-grid
= render partial: "recent_projects_grid_definition",
locals: {person: @person, grid: @recent_projects_grid}
- if @recent_projects_grid.no_records_at_all
= content_tag(:div, t('common.no_records'), class: 'no-records-msg')
- else
= render_index_grid(@recent_projects_grid)
section.section.quick-notes data-container='details' class=(@division.valid? ? 'show-view' : 'edit-view')
h2 Quick Links
.show-actions.hidden-print
a.edit-action.view-element
i.fa.fa-pencil.fa-large>
= t("common.edit")
a.show-action.form-element
= t("cancel_edit")
= render "admin/dashboard_beta/quicklinks_form", division: @division

javascript:
$(function() {
new MS.Views.ShowEditView({el: '.quick-notes'});
});
5 changes: 5 additions & 0 deletions db/migrate/20241105192112_add_quicklinks_to_divisions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddQuicklinksToDivisions < ActiveRecord::Migration[6.1]
def change
add_column :divisions, :quick_links, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_05_20_210320) do
ActiveRecord::Schema.define(version: 2024_11_05_192112) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -208,6 +208,7 @@
t.string "public_secondary_color"
t.string "qb_parent_class_id"
t.boolean "qb_read_only", default: true, null: false
t.string "quick_links"
t.string "short_name"
t.datetime "updated_at", null: false
t.index ["currency_id"], name: "index_divisions_on_currency_id"
Expand Down

0 comments on commit d3185d0

Please sign in to comment.