Skip to content

Commit

Permalink
Rename some functions and change default values
Browse files Browse the repository at this point in the history
  • Loading branch information
the-last-pastafarian committed Nov 6, 2024
1 parent f51591b commit 01e0f48
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
7 changes: 2 additions & 5 deletions server/lib/field_hub/couch_service.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ defmodule FieldHub.CouchService do
@moduledoc """
Bundles functions for directly interacting with the CouchDB.
"""
alias Cachex
alias ExJsonSchema
alias ElixirLS
require Logger

@doc """
Expand Down Expand Up @@ -347,7 +344,7 @@ defmodule FieldHub.CouchService do
- `project_identifier` - The name of the project.
## Example
iex> get_n_last_changes("project_a",1)
iex> get_last_n_changes("project_a",1)
[
%{
"changes" => [%{"rev" => "2-4f773e67d44d4bc99008713d9f9d164f"}],
Expand All @@ -374,7 +371,7 @@ defmodule FieldHub.CouchService do
]
"""
def get_n_last_changes(project_identifier, n) do
def get_last_n_changes(project_identifier, n) do
HTTPoison.get!(
"#{base_url()}/#{project_identifier}/_changes?descending=true&limit=100&include_docs=true",
get_user_credentials()
Expand Down
4 changes: 2 additions & 2 deletions server/lib/field_hub/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ defmodule FieldHub.Project do
name: "development"
}
"""
def evaluate_project(project_identifier, nb_changes_to_display \\ 2) do
def evaluate_project(project_identifier, n_changes_to_display \\ 2) do
project_identifier
|> evaluate_database()
|> case do
Expand All @@ -201,7 +201,7 @@ defmodule FieldHub.Project do
db_statistics ->
file_statistics = evaluate_file_store(project_identifier)

changes = CouchService.get_n_last_changes(project_identifier, nb_changes_to_display)
changes = CouchService.get_last_n_changes(project_identifier, n_changes_to_display)

db_statistics =
db_statistics
Expand Down
8 changes: 4 additions & 4 deletions server/lib/field_hub_web/live/project_show_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule FieldHubWeb.ProjectShowLive do
|> assign(:confirm_project_name, "")
|> assign(:delete_files, false)
|> assign(:hide_cache_cleared_message, true)
|> assign(:nb_changes_to_display, 2)
|> assign(:n_changes_to_display, 5)
|> read_project_doc()
}

Expand All @@ -62,7 +62,7 @@ defmodule FieldHubWeb.ProjectShowLive do

def handle_info(
:update_overview,
%{assigns: %{project: project, nb_changes_to_display: number_of_changes}} = socket
%{assigns: %{project: project, n_changes_to_display: number_of_changes}} = socket
) do
# Evaluate the project asynchronously. Once the task finishes, it will get picked up
# by another handle_info/2 below.
Expand Down Expand Up @@ -135,15 +135,15 @@ defmodule FieldHubWeb.ProjectShowLive do
{:noreply, assign(socket, :new_password, password)}
end

def handle_event("last_changes", %{"n-last-changes" => n} = _values, socket) do
def handle_event("change_count_select", %{"n-last-changes" => n} = _values, socket) do
{n_integer, _remainder} = Integer.parse(n)

stats = Project.evaluate_project(socket.assigns.project, n_integer)

socket =
socket
|> assign(:stats, stats)
|> assign(:nb_changes_to_display, n_integer)
|> assign(:n_changes_to_display, n_integer)

{:noreply, socket}
end
Expand Down
8 changes: 4 additions & 4 deletions server/lib/field_hub_web/live/project_show_live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
<section>
<tr >
<td valign="top" class="column-last-changes-slider">
<form id="last_changes_form" phx-change="last_changes">
Show the <%= @nb_changes_to_display %><br /> last changes
<form id="last_changes_form" phx-change="change_count_select">
Show the <%= @n_changes_to_display %><br /> last changes
<div class="slider-container">
<input
type="range"
min="2"
max= "50"
value= {@nb_changes_to_display}
max= "100"
value= {@n_changes_to_display}
class="slider"
name="n-last-changes"
>
Expand Down
6 changes: 3 additions & 3 deletions server/test/field_hub/couch_service_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,18 @@ defmodule FieldHub.CouchServiceTest do
] = CouchService.get_docs_by_category(@project, ["Image", "Drawing"]) |> Enum.to_list()
end

test "get_n_last_changes/1 returns the correct amount of changes last changes" do
test "get_last_n_changes/1 returns the correct amount of changes last changes" do
assert [
%{"changes" => [%{"rev" => _}], "id" => _, "seq" => _, "doc" => _},
%{"changes" => [%{"rev" => _}], "id" => _, "seq" => _, "doc" => _},
%{"changes" => [%{"rev" => _}], "id" => _, "seq" => _, "doc" => _},
%{"changes" => [%{"rev" => _}], "id" => _, "seq" => _, "doc" => _},
%{"changes" => [%{"rev" => _}], "id" => _, "seq" => _, "doc" => _}
] = CouchService.get_n_last_changes(@project, 5)
] = CouchService.get_last_n_changes(@project, 5)

assert [
%{"changes" => [%{"rev" => _}], "id" => _, "seq" => _, "doc" => _},
%{"changes" => [%{"rev" => _}], "id" => _, "seq" => _, "doc" => _}
] = CouchService.get_n_last_changes(@project, 2)
] = CouchService.get_last_n_changes(@project, 2)
end
end

0 comments on commit 01e0f48

Please sign in to comment.