Skip to content

Commit

Permalink
Initial version of WG admin tools
Browse files Browse the repository at this point in the history
 - Added routes, controller, views, and templates for working groups,
   volunteers, wg chairs, and wg volunteers CRUD interfaces for use within the
   admin portion of the site.
 - Shortened/Renamed create/update/get/delete_working_group_* to create/update/get/delete_wg_*
 - Added created_by and updated_by columns on working groups, volunteers, working group
   volunteers to record the last person who modified a resource
 - Added the entire priv/plts dir to .gitignore
 - Added is_url?/1 to Erlef.Inputs
 - Added validate_email/2 and validate_url/2 to Erlef.Schema
 - Added Erlef.Context which includes helpers for context modules
 - Added audit/1 in ErlefWeb.controller/0 for extracting the member id
    from a conn in controllers
 - Added convention for requiring functions that mutate the database to
    be given an keyword list consisting of an audit k/v, where the value
    holds a member_id which can in turn be used to populate updated_by and
    created_by columns on a table.
 - Added Erlef.Admins.resource_counts/0 for fetching various resource
   counts from the database for use on the admin dashboard.
 - Shortened/Renamed create/update/get/delete_working_group_* to create/update/get/delete_wg_*
 - Renamed WorkingGroup.proposal and proposal_html to charter and
   charter_html
 - Removed all delete_* related functions in Erlef.Groups
 - Fixed up case form in Erlef.Agenda.get_combined/0
 - Bring in datatables and toast-ui-editor as static resources (assets/static)
 - Remove rogue body tag in admin layout
  • Loading branch information
starbelly committed Jan 18, 2021
1 parent 4939f70 commit 329b5f2
Show file tree
Hide file tree
Showing 48 changed files with 1,663 additions and 321 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ npm-debug.log
.env-local

# Ignore plts
/priv/plts/erlef.plt
/priv/plts/erlef.plt.hash
/priv/plts/
/priv/plts/

# Ignore editor files
*.swp
Expand Down
8 changes: 8 additions & 0 deletions assets/css/admin.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
@import "../node_modules/bootstrap/dist/css/bootstrap.css";
@import "../node_modules/admin-lte/dist/css/adminlte.css";
@import "../node_modules/@fortawesome/fontawesome-free/css/all.css";

span.help-block {
display: inline-block;
margin-top: 0.5em;
background-color: #ffc107;
border-radius: 0.3em;
padding: 0.3em;
}
31 changes: 31 additions & 0 deletions lib/erlef/admins.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,35 @@ defmodule Erlef.Admins do
|> Notifications.new(params)
|> Mailer.deliver()
end

def resource_counts() do
q = """
select
(select count(id) from volunteers),
(select count(id) from working_groups),
(select count(id) from sponsors),
(select count(id) from events where events.approved = false),
(select count(id) from member_email_requests where member_email_requests.status != 'complete')
"""

%{
rows: [
[
volunteer_count,
working_group_count,
sponsors_count,
unapproved_events_count,
outstanding_email_requests_count
]
]
} = Ecto.Adapters.SQL.query!(Erlef.Repo, q)

%{
volunteers_count: volunteer_count,
working_groups_count: working_group_count,
sponsors_count: sponsors_count,
unapproved_events_count: unapproved_events_count,
outstanding_email_requests_count: outstanding_email_requests_count
}
end
end
3 changes: 1 addition & 2 deletions lib/erlef/agenda.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ defmodule Erlef.Agenda do

[] ->
case get_calendars() do
{:error, _} = err -> err
ics -> {:ok, ics}
ics when is_binary(ics) -> {:ok, ics}
end
end
end
Expand Down
31 changes: 31 additions & 0 deletions lib/erlef/context.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule Erlef.Context do
@moduledoc """
Context module helpers
"""

def audit_attrs(:create, params, audit) do
case all_atoms_map?(params) do
true ->
params
|> Map.put(:created_by, audit.member_id)
|> Map.put(:updated_by, audit.member_id)

false ->
params
|> Map.put("created_by", audit.member_id)
|> Map.put("updated_by", audit.member_id)
end
end

def audit_attrs(:update, params, audit) do
case all_atoms_map?(params) do
true ->
Map.put(params, :updated_by, audit.member_id)

false ->
Map.put(params, "updated_by", audit.member_id)
end
end

def all_atoms_map?(map), do: Enum.all?(Map.keys(map), &is_atom/1)
end
Loading

0 comments on commit 329b5f2

Please sign in to comment.