add json export in settings

This commit is contained in:
shibao 2022-11-09 23:33:50 -05:00
parent e3ff04ced3
commit 53bb0ddb03
30 changed files with 385 additions and 75 deletions

View File

@ -11,6 +11,7 @@
- Make container show page filter used-up ammo
- Forgot to add the logo as the favicon whoops
- Add graph to range page
- Add JSON export of data
- Update project dependencies
# v0.5.4

View File

@ -9,6 +9,14 @@ defmodule Cannery.Accounts.User do
alias Ecto.{Changeset, UUID}
alias Cannery.{Accounts.User, Invites.Invite}
@derive {Jason.Encoder,
only: [
:id,
:email,
:confirmed_at,
:role,
:locale
]}
@derive {Inspect, except: [:password]}
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id

View File

@ -9,6 +9,14 @@ defmodule Cannery.ActivityLog.ShotGroup do
alias Cannery.{Accounts.User, ActivityLog.ShotGroup, Ammo.AmmoGroup, Repo}
alias Ecto.{Changeset, UUID}
@derive {Jason.Encoder,
only: [
:id,
:count,
:date,
:notes,
:ammo_group_id
]}
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "shot_groups" do

View File

@ -13,6 +13,16 @@ defmodule Cannery.Ammo.AmmoGroup do
alias Cannery.{Accounts.User, ActivityLog.ShotGroup, Containers.Container}
alias Ecto.{Changeset, UUID}
@derive {Jason.Encoder,
only: [
:id,
:count,
:notes,
:price_paid,
:staged,
:ammo_type_id,
:container_id
]}
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "ammo_groups" do

View File

@ -11,6 +11,31 @@ defmodule Cannery.Ammo.AmmoType do
alias Cannery.Ammo.{AmmoGroup, AmmoType}
alias Ecto.{Changeset, UUID}
@derive {Jason.Encoder,
only: [
:id,
:name,
:desc,
:bullet_type,
:bullet_core,
:cartridge,
:caliber,
:case_material,
:jacket_type,
:muzzle_velocity,
:powder_type,
:powder_grains_per_charge,
:grains,
:pressure,
:primer_type,
:firing_type,
:tracer,
:incendiary,
:blank,
:corrosive,
:manufacturer,
:upc
]}
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "ammo_types" do

View File

@ -9,6 +9,15 @@ defmodule Cannery.Containers.Container do
alias Cannery.Containers.{Container, ContainerTag}
alias Cannery.{Accounts.User, Ammo.AmmoGroup, Tags.Tag}
@derive {Jason.Encoder,
only: [
:id,
:name,
:desc,
:location,
:type,
:tags
]}
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "containers" do

View File

@ -9,6 +9,13 @@ defmodule Cannery.Tags.Tag do
alias Ecto.{Changeset, UUID}
alias Cannery.{Accounts.User, Tags.Tag}
@derive {Jason.Encoder,
only: [
:id,
:name,
:bg_color,
:text_color
]}
@primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id
schema "tags" do

View File

@ -0,0 +1,65 @@
defmodule CanneryWeb.ExportController do
use CanneryWeb, :controller
alias Cannery.{ActivityLog, Ammo, Containers}
def export(%{assigns: %{current_user: current_user}} = conn, %{"mode" => "json"}) do
ammo_types =
Ammo.list_ammo_types(current_user)
|> Enum.map(fn ammo_type ->
average_cost = ammo_type |> Ammo.get_average_cost_for_ammo_type!(current_user)
round_count = ammo_type |> Ammo.get_round_count_for_ammo_type(current_user)
used_count = ammo_type |> Ammo.get_used_count_for_ammo_type(current_user)
ammo_group_count = ammo_type |> Ammo.get_ammo_groups_count_for_type(current_user, true)
ammo_type
|> Jason.encode!()
|> Jason.decode!()
|> Map.merge(%{
"average_cost" => average_cost,
"round_count" => round_count,
"used_count" => used_count,
"ammo_group_count" => ammo_group_count
})
end)
ammo_groups =
Ammo.list_ammo_groups(current_user, true)
|> Enum.map(fn ammo_group ->
used_count = ammo_group |> Ammo.get_used_count()
percentage_remaining = ammo_group |> Ammo.get_percentage_remaining()
ammo_group
|> Jason.encode!()
|> Jason.decode!()
|> Map.merge(%{
"used_count" => used_count,
"percentage_remaining" => percentage_remaining
})
end)
shot_groups = ActivityLog.list_shot_groups(current_user)
containers =
Containers.list_containers(current_user)
|> Enum.map(fn container ->
ammo_group_count = container |> Containers.get_container_ammo_group_count!()
round_count = container |> Containers.get_container_rounds!()
container
|> Jason.encode!()
|> Jason.decode!()
|> Map.merge(%{
"ammo_group_count" => ammo_group_count,
"round_count" => round_count
})
end)
json(conn, %{
user: current_user,
ammo_types: ammo_types,
ammo_groups: ammo_groups,
shot_groups: shot_groups,
containers: containers
})
end
end

View File

@ -138,7 +138,7 @@ defmodule CanneryWeb.HomeLive do
target="_blank"
rel="noopener noreferrer"
>
<p>0.5.5</p>
<p>0.6.0</p>
<i class="fas fa-md fa-info-circle"></i>
</.link>
</li>

View File

@ -60,6 +60,7 @@ defmodule CanneryWeb.Router do
put "/users/settings", UserSettingsController, :update
delete "/users/settings/:id", UserSettingsController, :delete
get "/users/settings/confirm_email/:token", UserSettingsController, :confirm_email
get "/export/:mode", ExportController, :export
live "/tags", TagLive.Index, :index
live "/tags/new", TagLive.Index, :new

View File

@ -139,12 +139,22 @@
<hr class="hr" />
<div class="flex justify-center items-center">
<.link
href={Routes.export_path(@conn, :export, :json)}
class="mx-4 my-2 btn btn-primary"
target="_blank"
>
<%= dgettext("actions", "Export Data as JSON") %>
</.link>
<.link
href={Routes.user_settings_path(@conn, :delete, @current_user)}
method={:delete}
class="btn btn-alert"
class="mx-4 my-2 btn btn-alert"
data-confirm={dgettext("prompts", "Are you sure you want to delete your account?")}
>
<%= dgettext("actions", "Delete User") %>
</.link>
</div>
</div>

View File

@ -48,7 +48,7 @@ msgstr ""
msgid "Create Invite"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#: lib/cannery_web/templates/user_settings/edit.html.heex:157
#, elixir-autogen, elixir-format
msgid "Delete User"
msgstr ""
@ -248,3 +248,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Unstage from range"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#, elixir-autogen, elixir-format
msgid "Export Data as JSON"
msgstr ""

View File

@ -61,7 +61,7 @@ msgstr "Passwort ändern"
msgid "Create Invite"
msgstr "Einladung erstellen"
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#: lib/cannery_web/templates/user_settings/edit.html.heex:157
#, elixir-autogen, elixir-format
msgid "Delete User"
msgstr "Benutzer löschen"
@ -261,3 +261,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Unstage from range"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#, elixir-autogen, elixir-format
msgid "Export Data as JSON"
msgstr ""

View File

@ -121,22 +121,22 @@ msgstr "Sie sind nicht berechtigt, diese Seite aufzurufen"
msgid "You are not authorized to view this page."
msgstr "Sie sind nicht berechtigt, diese Seite aufzurufen."
#: lib/cannery/accounts/user.ex:130
#: lib/cannery/accounts/user.ex:138
#, elixir-autogen, elixir-format
msgid "did not change"
msgstr "hat sich nicht geändert"
#: lib/cannery/accounts/user.ex:151
#: lib/cannery/accounts/user.ex:159
#, elixir-autogen, elixir-format
msgid "does not match password"
msgstr "Passwort stimmt nicht überein"
#: lib/cannery/accounts/user.ex:188
#: lib/cannery/accounts/user.ex:196
#, elixir-autogen, elixir-format
msgid "is not valid"
msgstr "ist nicht gültig"
#: lib/cannery/accounts/user.ex:84
#: lib/cannery/accounts/user.ex:92
#, elixir-autogen, elixir-format
msgid "must have the @ sign and no spaces"
msgstr "Muss ein @ Zeichen und keine Leerzeichen haben"
@ -151,13 +151,13 @@ msgstr "Tag nicht gefunden"
msgid "Tag could not be added"
msgstr "Tag konnte nicht hinzugefügt werden"
#: lib/cannery/activity_log/shot_group.ex:115
#: lib/cannery/activity_log/shot_group.ex:123
#, elixir-autogen, elixir-format
msgid "Count must be at least 1"
msgstr "Anzahl muss mindestens 1 sein"
#: lib/cannery/activity_log/shot_group.ex:74
#: lib/cannery/activity_log/shot_group.ex:111
#: lib/cannery/activity_log/shot_group.ex:82
#: lib/cannery/activity_log/shot_group.ex:119
#, elixir-autogen, elixir-format
msgid "Count must be less than %{count}"
msgstr "Anzahl muss weniger als %{count} betragen"
@ -192,12 +192,12 @@ msgstr ""
msgid "Invalid multiplier"
msgstr ""
#: lib/cannery/ammo/ammo_group.ex:84
#: lib/cannery/ammo/ammo_group.ex:94
#, elixir-autogen, elixir-format
msgid "Please select an ammo type and container"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:69
#: lib/cannery/activity_log/shot_group.ex:77
#, elixir-autogen, elixir-format
msgid "Please select a valid user and ammo group"
msgstr ""

View File

@ -105,7 +105,7 @@ msgstr "Sind Sie sicher, dass sie die Einladung für %{name} löschen möchten?"
msgid "Are you sure you want to delete this ammo?"
msgstr "Sind Sie sicher, dass sie diese Munition löschen möchten?"
#: lib/cannery_web/templates/user_settings/edit.html.heex:146
#: lib/cannery_web/templates/user_settings/edit.html.heex:155
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete your account?"
msgstr "Sind Sie sicher, dass sie Ihren Account löschen möchten?"

View File

@ -49,7 +49,7 @@ msgstr ""
msgid "Create Invite"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#: lib/cannery_web/templates/user_settings/edit.html.heex:157
#, elixir-autogen, elixir-format
msgid "Delete User"
msgstr ""
@ -249,3 +249,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Unstage from range"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#, elixir-autogen, elixir-format
msgid "Export Data as JSON"
msgstr ""

View File

@ -107,23 +107,23 @@ msgstr ""
msgid "You are not authorized to view this page."
msgstr ""
#: lib/cannery/accounts/user.ex:130
#: lib/cannery/accounts/user.ex:138
#, elixir-autogen, elixir-format
msgid "did not change"
msgstr ""
#: lib/cannery/accounts/user.ex:151
#: lib/cannery/accounts/user.ex:159
#, elixir-autogen, elixir-format
msgid "does not match password"
msgstr ""
## From Ecto.Changeset.put_change/3
#: lib/cannery/accounts/user.ex:188
#: lib/cannery/accounts/user.ex:196
#, elixir-autogen, elixir-format, fuzzy
msgid "is not valid"
msgstr ""
#: lib/cannery/accounts/user.ex:84
#: lib/cannery/accounts/user.ex:92
#, elixir-autogen, elixir-format
msgid "must have the @ sign and no spaces"
msgstr ""
@ -138,13 +138,13 @@ msgstr ""
msgid "Tag could not be added"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:115
#: lib/cannery/activity_log/shot_group.ex:123
#, elixir-autogen, elixir-format
msgid "Count must be at least 1"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:74
#: lib/cannery/activity_log/shot_group.ex:111
#: lib/cannery/activity_log/shot_group.ex:82
#: lib/cannery/activity_log/shot_group.ex:119
#, elixir-autogen, elixir-format
msgid "Count must be less than %{count}"
msgstr ""
@ -175,12 +175,12 @@ msgstr ""
msgid "Invalid multiplier"
msgstr ""
#: lib/cannery/ammo/ammo_group.ex:84
#: lib/cannery/ammo/ammo_group.ex:94
#, elixir-autogen, elixir-format
msgid "Please select an ammo type and container"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:69
#: lib/cannery/activity_log/shot_group.ex:77
#, elixir-autogen, elixir-format
msgid "Please select a valid user and ammo group"
msgstr ""

View File

@ -91,7 +91,7 @@ msgstr ""
msgid "Are you sure you want to delete this ammo?"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:146
#: lib/cannery_web/templates/user_settings/edit.html.heex:155
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete your account?"
msgstr ""

View File

@ -107,22 +107,22 @@ msgstr ""
msgid "You are not authorized to view this page."
msgstr ""
#: lib/cannery/accounts/user.ex:130
#: lib/cannery/accounts/user.ex:138
#, elixir-autogen, elixir-format
msgid "did not change"
msgstr ""
#: lib/cannery/accounts/user.ex:151
#: lib/cannery/accounts/user.ex:159
#, elixir-autogen, elixir-format
msgid "does not match password"
msgstr ""
#: lib/cannery/accounts/user.ex:188
#: lib/cannery/accounts/user.ex:196
#, elixir-autogen, elixir-format
msgid "is not valid"
msgstr ""
#: lib/cannery/accounts/user.ex:84
#: lib/cannery/accounts/user.ex:92
#, elixir-autogen, elixir-format
msgid "must have the @ sign and no spaces"
msgstr ""
@ -137,13 +137,13 @@ msgstr ""
msgid "Tag could not be added"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:115
#: lib/cannery/activity_log/shot_group.ex:123
#, elixir-autogen, elixir-format
msgid "Count must be at least 1"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:74
#: lib/cannery/activity_log/shot_group.ex:111
#: lib/cannery/activity_log/shot_group.ex:82
#: lib/cannery/activity_log/shot_group.ex:119
#, elixir-autogen, elixir-format
msgid "Count must be less than %{count}"
msgstr ""
@ -174,12 +174,12 @@ msgstr ""
msgid "Invalid multiplier"
msgstr ""
#: lib/cannery/ammo/ammo_group.ex:84
#: lib/cannery/ammo/ammo_group.ex:94
#, elixir-autogen, elixir-format
msgid "Please select an ammo type and container"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:69
#: lib/cannery/activity_log/shot_group.ex:77
#, elixir-autogen, elixir-format
msgid "Please select a valid user and ammo group"
msgstr ""

View File

@ -61,7 +61,7 @@ msgstr "Cambiar contraseña"
msgid "Create Invite"
msgstr "Crear Invitación"
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#: lib/cannery_web/templates/user_settings/edit.html.heex:157
#, elixir-autogen, elixir-format
msgid "Delete User"
msgstr "Eliminar cuenta de Usuario"
@ -261,3 +261,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Unstage from range"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#, elixir-autogen, elixir-format
msgid "Export Data as JSON"
msgstr ""

View File

@ -123,22 +123,22 @@ msgstr ""
msgid "You are not authorized to view this page."
msgstr ""
#: lib/cannery/accounts/user.ex:130
#: lib/cannery/accounts/user.ex:138
#, elixir-autogen, elixir-format
msgid "did not change"
msgstr ""
#: lib/cannery/accounts/user.ex:151
#: lib/cannery/accounts/user.ex:159
#, elixir-autogen, elixir-format
msgid "does not match password"
msgstr ""
#: lib/cannery/accounts/user.ex:188
#: lib/cannery/accounts/user.ex:196
#, elixir-autogen, elixir-format
msgid "is not valid"
msgstr ""
#: lib/cannery/accounts/user.ex:84
#: lib/cannery/accounts/user.ex:92
#, elixir-autogen, elixir-format
msgid "must have the @ sign and no spaces"
msgstr ""
@ -153,13 +153,13 @@ msgstr ""
msgid "Tag could not be added"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:115
#: lib/cannery/activity_log/shot_group.ex:123
#, elixir-autogen, elixir-format
msgid "Count must be at least 1"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:74
#: lib/cannery/activity_log/shot_group.ex:111
#: lib/cannery/activity_log/shot_group.ex:82
#: lib/cannery/activity_log/shot_group.ex:119
#, elixir-autogen, elixir-format
msgid "Count must be less than %{count}"
msgstr ""
@ -190,12 +190,12 @@ msgstr ""
msgid "Invalid multiplier"
msgstr ""
#: lib/cannery/ammo/ammo_group.ex:84
#: lib/cannery/ammo/ammo_group.ex:94
#, elixir-autogen, elixir-format
msgid "Please select an ammo type and container"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:69
#: lib/cannery/activity_log/shot_group.ex:77
#, elixir-autogen, elixir-format
msgid "Please select a valid user and ammo group"
msgstr ""

View File

@ -105,7 +105,7 @@ msgstr "Está seguro que quiere eliminar la invitación para %{name}?"
msgid "Are you sure you want to delete this ammo?"
msgstr "Está seguro que desea eliminar esta munición?"
#: lib/cannery_web/templates/user_settings/edit.html.heex:146
#: lib/cannery_web/templates/user_settings/edit.html.heex:155
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete your account?"
msgstr "Está seguro que desea eliminar su cuenta?"

View File

@ -61,7 +61,7 @@ msgstr "Changer le mot de passe"
msgid "Create Invite"
msgstr "Créer une invitation"
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#: lib/cannery_web/templates/user_settings/edit.html.heex:157
#, elixir-autogen, elixir-format
msgid "Delete User"
msgstr "Supprimer utilisateur"
@ -261,3 +261,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Unstage from range"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#, elixir-autogen, elixir-format
msgid "Export Data as JSON"
msgstr ""

View File

@ -122,22 +122,22 @@ msgstr "Vous nêtes pas autorisé·e à voir cette page"
msgid "You are not authorized to view this page."
msgstr "Vous nêtes pas autorisé·e à voir cette page."
#: lib/cannery/accounts/user.ex:130
#: lib/cannery/accounts/user.ex:138
#, elixir-autogen, elixir-format
msgid "did not change"
msgstr "est inchangé"
#: lib/cannery/accounts/user.ex:151
#: lib/cannery/accounts/user.ex:159
#, elixir-autogen, elixir-format
msgid "does not match password"
msgstr "le mot de passe ne correspond pas"
#: lib/cannery/accounts/user.ex:188
#: lib/cannery/accounts/user.ex:196
#, elixir-autogen, elixir-format
msgid "is not valid"
msgstr "nest pas valide"
#: lib/cannery/accounts/user.ex:84
#: lib/cannery/accounts/user.ex:92
#, elixir-autogen, elixir-format
msgid "must have the @ sign and no spaces"
msgstr "doit contenir le symbole @ et aucune espace"
@ -152,13 +152,13 @@ msgstr "Tag pas trouvé"
msgid "Tag could not be added"
msgstr "Le tag na pas pu être ajouté"
#: lib/cannery/activity_log/shot_group.ex:115
#: lib/cannery/activity_log/shot_group.ex:123
#, elixir-autogen, elixir-format
msgid "Count must be at least 1"
msgstr "Le nombre doit être au moins égal à 1"
#: lib/cannery/activity_log/shot_group.ex:74
#: lib/cannery/activity_log/shot_group.ex:111
#: lib/cannery/activity_log/shot_group.ex:82
#: lib/cannery/activity_log/shot_group.ex:119
#, elixir-autogen, elixir-format
msgid "Count must be less than %{count}"
msgstr "La quantité doit être inférieur à %{count}"
@ -191,12 +191,12 @@ msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}"
msgid "Invalid multiplier"
msgstr "Multiplicateur invalide"
#: lib/cannery/ammo/ammo_group.ex:84
#: lib/cannery/ammo/ammo_group.ex:94
#, elixir-autogen, elixir-format
msgid "Please select an ammo type and container"
msgstr "Veuillez choisir un type de munitions et un conteneur"
#: lib/cannery/activity_log/shot_group.ex:69
#: lib/cannery/activity_log/shot_group.ex:77
#, elixir-autogen, elixir-format
msgid "Please select a valid user and ammo group"
msgstr "Veuillez choisir un utilisateur valide et un groupe de munitions"

View File

@ -106,7 +106,7 @@ msgstr "Êtes-vous certain·e de supprimer linvitation pour %{name}?"
msgid "Are you sure you want to delete this ammo?"
msgstr "Êtes-vous certain·e de supprimer cette munition?"
#: lib/cannery_web/templates/user_settings/edit.html.heex:146
#: lib/cannery_web/templates/user_settings/edit.html.heex:155
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete your account?"
msgstr "Êtes-vous certain·e de supprimer votre compte?"

View File

@ -59,7 +59,7 @@ msgstr ""
msgid "Create Invite"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#: lib/cannery_web/templates/user_settings/edit.html.heex:157
#, elixir-autogen, elixir-format
msgid "Delete User"
msgstr ""
@ -259,3 +259,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Unstage from range"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:148
#, elixir-autogen, elixir-format
msgid "Export Data as JSON"
msgstr ""

View File

@ -123,22 +123,22 @@ msgstr "Níl cead agaibh féachaint ar an leathanach seo"
msgid "You are not authorized to view this page."
msgstr "Níl cead agaibh féachaint ar an leathanach seo."
#: lib/cannery/accounts/user.ex:130
#: lib/cannery/accounts/user.ex:138
#, elixir-autogen, elixir-format
msgid "did not change"
msgstr "Níor athraigh sé"
#: lib/cannery/accounts/user.ex:151
#: lib/cannery/accounts/user.ex:159
#, elixir-autogen, elixir-format
msgid "does not match password"
msgstr ""
#: lib/cannery/accounts/user.ex:188
#: lib/cannery/accounts/user.ex:196
#, elixir-autogen, elixir-format
msgid "is not valid"
msgstr ""
#: lib/cannery/accounts/user.ex:84
#: lib/cannery/accounts/user.ex:92
#, elixir-autogen, elixir-format
msgid "must have the @ sign and no spaces"
msgstr ""
@ -153,13 +153,13 @@ msgstr ""
msgid "Tag could not be added"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:115
#: lib/cannery/activity_log/shot_group.ex:123
#, elixir-autogen, elixir-format
msgid "Count must be at least 1"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:74
#: lib/cannery/activity_log/shot_group.ex:111
#: lib/cannery/activity_log/shot_group.ex:82
#: lib/cannery/activity_log/shot_group.ex:119
#, elixir-autogen, elixir-format
msgid "Count must be less than %{count}"
msgstr ""
@ -190,12 +190,12 @@ msgstr ""
msgid "Invalid multiplier"
msgstr ""
#: lib/cannery/ammo/ammo_group.ex:84
#: lib/cannery/ammo/ammo_group.ex:94
#, elixir-autogen, elixir-format
msgid "Please select an ammo type and container"
msgstr ""
#: lib/cannery/activity_log/shot_group.ex:69
#: lib/cannery/activity_log/shot_group.ex:77
#, elixir-autogen, elixir-format
msgid "Please select a valid user and ammo group"
msgstr ""

View File

@ -101,7 +101,7 @@ msgstr ""
msgid "Are you sure you want to delete this ammo?"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:146
#: lib/cannery_web/templates/user_settings/edit.html.heex:155
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete your account?"
msgstr ""

View File

@ -90,7 +90,7 @@ msgstr ""
msgid "Are you sure you want to delete this ammo?"
msgstr ""
#: lib/cannery_web/templates/user_settings/edit.html.heex:146
#: lib/cannery_web/templates/user_settings/edit.html.heex:155
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete your account?"
msgstr ""

View File

@ -0,0 +1,136 @@
defmodule CanneryWeb.ExportControllerTest do
@moduledoc """
Tests the export function
"""
use CanneryWeb.ConnCase
alias Cannery.{Ammo, Containers, Repo}
@moduletag :export_controller_test
setup %{conn: conn} do
current_user = user_fixture() |> confirm_user()
[
current_user: current_user,
conn: conn |> log_in_user(current_user)
]
end
defp add_data(%{current_user: current_user}) do
ammo_type = ammo_type_fixture(current_user)
container = container_fixture(current_user)
tag = tag_fixture(current_user)
Containers.add_tag!(container, tag, current_user)
{1, [ammo_group]} = ammo_group_fixture(ammo_type, container, current_user)
shot_group = shot_group_fixture(current_user, ammo_group)
ammo_group = ammo_group |> Repo.reload!()
%{
ammo_type: ammo_type,
ammo_group: ammo_group,
container: container,
shot_group: shot_group,
tag: tag
}
end
describe "Exports data" do
setup [:add_data]
test "in JSON", %{
conn: conn,
current_user: current_user,
container: container,
ammo_type: ammo_type,
ammo_group: ammo_group,
shot_group: shot_group,
tag: tag
} do
conn = get(conn, Routes.export_path(conn, :export, :json))
ideal_ammo_group = %{
"ammo_type_id" => ammo_group.ammo_type_id,
"container_id" => ammo_group.container_id,
"count" => ammo_group.count,
"id" => ammo_group.id,
"notes" => ammo_group.notes,
"price_paid" => ammo_group.price_paid,
"staged" => ammo_group.staged,
"used_count" => ammo_group |> Ammo.get_used_count(),
"percentage_remaining" => ammo_group |> Ammo.get_percentage_remaining()
}
ideal_ammo_type = %{
"blank" => ammo_type.blank,
"bullet_core" => ammo_type.bullet_core,
"bullet_type" => ammo_type.bullet_type,
"caliber" => ammo_type.caliber,
"cartridge" => ammo_type.cartridge,
"case_material" => ammo_type.case_material,
"corrosive" => ammo_type.corrosive,
"desc" => ammo_type.desc,
"firing_type" => ammo_type.firing_type,
"grains" => ammo_type.grains,
"id" => ammo_type.id,
"incendiary" => ammo_type.incendiary,
"jacket_type" => ammo_type.jacket_type,
"manufacturer" => ammo_type.manufacturer,
"muzzle_velocity" => ammo_type.muzzle_velocity,
"name" => ammo_type.name,
"powder_grains_per_charge" => ammo_type.powder_grains_per_charge,
"powder_type" => ammo_type.powder_type,
"pressure" => ammo_type.pressure,
"primer_type" => ammo_type.primer_type,
"tracer" => ammo_type.tracer,
"upc" => ammo_type.upc,
"average_cost" => ammo_type |> Ammo.get_average_cost_for_ammo_type!(current_user),
"round_count" => ammo_type |> Ammo.get_round_count_for_ammo_type(current_user),
"used_count" => ammo_type |> Ammo.get_used_count_for_ammo_type(current_user),
"ammo_group_count" => ammo_type |> Ammo.get_ammo_groups_count_for_type(current_user, true)
}
ideal_container = %{
"desc" => container.desc,
"id" => container.id,
"location" => container.location,
"name" => container.name,
"tags" => [
%{
"id" => tag.id,
"name" => tag.name,
"bg_color" => tag.bg_color,
"text_color" => tag.text_color
}
],
"type" => container.type,
"ammo_group_count" => container |> Containers.get_container_ammo_group_count!(),
"round_count" => container |> Containers.get_container_rounds!()
}
ideal_shot_group = %{
"ammo_group_id" => shot_group.ammo_group_id,
"count" => shot_group.count,
"date" => to_string(shot_group.date),
"id" => shot_group.id,
"notes" => shot_group.notes
}
ideal_user = %{
"confirmed_at" =>
current_user.confirmed_at |> Jason.encode!() |> String.replace(~r/\"/, ""),
"email" => current_user.email,
"id" => current_user.id,
"locale" => current_user.locale,
"role" => to_string(current_user.role)
}
json_resp = conn |> json_response(200)
assert %{"ammo_groups" => [^ideal_ammo_group]} = json_resp
assert %{"ammo_types" => [^ideal_ammo_type]} = json_resp
assert %{"containers" => [^ideal_container]} = json_resp
assert %{"shot_groups" => [^ideal_shot_group]} = json_resp
assert %{"user" => ^ideal_user} = json_resp
end
end
end