Compare commits

...

155 Commits
0.2.0 ... 0.5.5

Author SHA1 Message Date
b6e0a543ec mix format 2022-07-05 01:13:38 -04:00
cf75007e4d add logo as favicon 2022-07-05 01:09:47 -04:00
1583ad3503 remove logo from readme lol 2022-07-04 21:55:57 -04:00
2af9c7a4f9 update screenshot lol 2022-07-04 21:52:08 -04:00
7e7d6258d5 add note about creating unlimited invites 2022-07-04 21:47:31 -04:00
f246b9db93 prompt to create first ammo type before trying to create first ammo 2022-07-04 21:41:07 -04:00
5836a82ff7 add note about ammo when deleting ammo type 2022-07-04 21:40:07 -04:00
7464947497 use initial ammo group form component select state 2022-07-04 21:22:59 -04:00
3adb8c9aae pass invite token in properly 2022-07-04 21:16:09 -04:00
dce04e4d7f harden invite changesets 2022-07-04 21:09:55 -04:00
ee6266be3f harden tag changesets 2022-07-04 21:06:35 -04:00
36f56528ee use container changeset helper 2022-07-04 20:52:21 -04:00
76bbab1de9 add logo contribution 2022-07-04 20:47:12 -04:00
6c09261368 use changeset helper 2022-07-04 20:39:21 -04:00
3593334c85 fix container changeset 2022-07-04 20:30:05 -04:00
57b5cb432d fix container tag changeset 2022-07-04 20:25:55 -04:00
5b5fd7173b fix ammo type changesets 2022-07-04 20:22:39 -04:00
41bcc2f456 add logo 😄 2022-07-04 20:19:03 -04:00
947659b207 fix ammo_group changesets 2022-07-04 20:06:41 -04:00
9ebca20dc6 add error case for create_changeset 2022-07-04 20:06:31 -04:00
3cbd62e84c fix shotgroup changesets 2022-07-01 21:39:08 -04:00
67010640f0 remove unchangeable requirements 2022-07-01 19:53:44 -04:00
5fd46c326f update gettext 2022-07-01 19:16:59 -04:00
8c62a39c97 bump to 0.5.4 2022-07-01 19:16:31 -04:00
9a1a104c6d add pack and round count to containers 2022-07-01 19:13:54 -04:00
11b1ae9980 update paths 2022-07-01 00:33:32 -04:00
948fa929ec rename "Ammo Details" to "View in Catalog" 2022-07-01 00:27:51 -04:00
268085e761 update changelog 2022-07-01 00:25:38 -04:00
a1efd7cc60 improve ammo group wording 2022-07-01 00:23:04 -04:00
2db9ab968f rename ammo types page to catalog 2022-07-01 00:20:50 -04:00
7863b06215 update changelog 2022-05-21 17:19:15 -04:00
eb8cae27c0 gettext merge 2022-05-21 17:16:13 -04:00
ecca9ee4a9 Translated using Weblate (French)
Currently translated at 100.0% (157 of 157 strings)

Translation: cannery/default
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/default/fr/
2022-05-21 19:47:00 +00:00
a0c4f20afd Added translation using Weblate (Spanish) 2022-05-21 19:45:00 +00:00
0e46a05360 Added translation using Weblate (Spanish) 2022-05-21 19:44:59 +00:00
1062d97f79 Added translation using Weblate (Spanish) 2022-05-21 19:44:57 +00:00
1b5df8c56c Added translation using Weblate (Spanish) 2022-05-21 19:44:57 +00:00
da5c136313 Added translation using Weblate (Spanish) 2022-05-21 19:44:56 +00:00
ef206d273f Added translation using Weblate (Spanish) 2022-05-21 19:44:55 +00:00
ef513a8108 Translated using Weblate (French)
Currently translated at 100.0% (35 of 35 strings)

Translation: cannery/actions
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/actions/fr/
2022-05-18 18:51:25 +00:00
ed1765c652 Translated using Weblate (French)
Currently translated at 100.0% (46 of 46 strings)

Translation: cannery/prompts
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/prompts/fr/
2022-05-18 18:51:25 +00:00
541e6a4612 Translated using Weblate (French)
Currently translated at 100.0% (157 of 157 strings)

Translation: cannery/default
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/default/fr/
2022-05-18 18:51:24 +00:00
43589a88c3 Translated using Weblate (German)
Currently translated at 100.0% (35 of 35 strings)

Translation: cannery/actions
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/actions/de/
2022-05-12 20:28:57 +00:00
15a6e75e7d Translated using Weblate (German)
Currently translated at 100.0% (46 of 46 strings)

Translation: cannery/prompts
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/prompts/de/
2022-05-12 20:28:57 +00:00
2681a37fad Translated using Weblate (German)
Currently translated at 100.0% (157 of 157 strings)

Translation: cannery/default
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/default/de/
2022-05-12 20:28:57 +00:00
d086c4c813 update to fa 6.1.1 2022-05-06 23:51:53 -04:00
f49fe21da5 remove invalid opts 2022-05-06 23:36:42 -04:00
717c898d48 update deps 2022-05-06 23:36:39 -04:00
085411132d fix button text wrapping 2022-05-06 20:30:52 -04:00
c8a6a9d81e fix gettext command 2022-05-06 00:55:47 -04:00
a0389db9ef run npm audit 2022-05-06 00:03:57 -04:00
e6e4db7410 add involvement links 2022-05-05 23:59:31 -04:00
78542a533a bump version 2022-05-05 23:45:03 -04:00
46665dce88 add changes to changelog 2022-05-05 23:44:32 -04:00
4b420f313c add locale as per user setting 2022-05-05 23:26:29 -04:00
42b4d0758f add gettext changes 2022-05-05 23:02:06 -04:00
901c2a948f add created at date to ammo types 2022-05-05 21:43:49 -04:00
6fe5a29ebd add registered on date to user card 2022-05-05 21:43:13 -04:00
ce7223597c add created date to ammo groups 2022-05-05 21:43:03 -04:00
4791a2849e add locale options to guides 2022-04-24 20:20:07 -04:00
7edc9642d4 add french translation 2022-04-24 20:19:20 -04:00
2ae0c3133c Translated using Weblate (French)
Currently translated at 100.0% (146 of 146 strings)

Translation: cannery/default
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/default/fr/
2022-04-25 00:12:41 +00:00
f284773f68 Translated using Weblate (French)
Currently translated at 100.0% (30 of 30 strings)

Translation: cannery/errors
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/errors/fr/
2022-04-24 08:27:09 +00:00
d35a81ef39 Translated using Weblate (French)
Currently translated at 100.0% (33 of 33 strings)

Translation: cannery/actions
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/actions/fr/
2022-04-24 08:27:09 +00:00
4c3ebaec53 Translated using Weblate (French)
Currently translated at 100.0% (44 of 44 strings)

Translation: cannery/prompts
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/prompts/fr/
2022-04-24 08:27:09 +00:00
a13a57c6ee Translated using Weblate (French)
Currently translated at 98.6% (144 of 146 strings)

Translation: cannery/default
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/default/fr/
2022-04-24 08:27:09 +00:00
8c7b9f9a9b Translated using Weblate (French)
Currently translated at 86.6% (26 of 30 strings)

Translation: cannery/errors
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/errors/fr/
2022-04-23 07:52:35 +00:00
7b7604f48f Translated using Weblate (French)
Currently translated at 100.0% (15 of 15 strings)

Translation: cannery/emails
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/emails/fr/
2022-04-22 18:37:17 +00:00
b1b52b9edc Translated using Weblate (French)
Currently translated at 69.6% (23 of 33 strings)

Translation: cannery/actions
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/actions/fr/
2022-04-22 18:37:17 +00:00
3fcea8e679 Translated using Weblate (French)
Currently translated at 76.6% (23 of 30 strings)

Translation: cannery/errors
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/errors/fr/
2022-04-22 18:37:17 +00:00
98ec324a2c Translated using Weblate (French)
Currently translated at 54.5% (24 of 44 strings)

Translation: cannery/prompts
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/prompts/fr/
2022-04-22 18:37:17 +00:00
0868789811 Translated using Weblate (French)
Currently translated at 16.4% (24 of 146 strings)

Translation: cannery/default
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/default/fr/
2022-04-22 18:37:17 +00:00
87c62f9ef8 Added translation using Weblate (French) 2022-04-20 18:02:37 +00:00
0919ee2a72 Added translation using Weblate (French) 2022-04-20 18:02:36 +00:00
0b910af077 Added translation using Weblate (French) 2022-04-20 18:02:35 +00:00
cb81eb4116 Added translation using Weblate (French) 2022-04-20 18:02:35 +00:00
b1d7cfe591 Added translation using Weblate (French) 2022-04-20 18:02:33 +00:00
1431b92e42 Added translation using Weblate (French) 2022-04-20 18:02:33 +00:00
c555022ea7 use elixir 1.13.4 2022-04-19 20:23:31 -04:00
0917aff37b run mix format 2022-04-19 20:08:12 -04:00
7f9e6f9eff fix tests 2022-04-19 20:08:10 -04:00
9e754fe630 Show average price per round on ammo type table 2022-04-19 19:42:48 -04:00
45d905b384 Fix bug with average price per round calculation 2022-04-19 19:42:48 -04:00
3297130890 Fix not being able to edit ammo group when fully used up 2022-04-19 19:42:48 -04:00
d27b54386d remove unneeded formatter dep 2022-04-19 19:42:48 -04:00
ebf32c49bf add translation properly 2022-04-19 18:16:06 -04:00
119f2af6bb Translated using Weblate (German)
Currently translated at 100.0% (15 of 15 strings)

Translation: cannery/emails
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/emails/de/
2022-04-19 21:44:13 +00:00
9db6b2c316 Translated using Weblate (German)
Currently translated at 100.0% (33 of 33 strings)

Translation: cannery/actions
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/actions/de/
2022-04-19 21:32:54 +00:00
22281486e0 Translated using Weblate (German)
Currently translated at 100.0% (30 of 30 strings)

Translation: cannery/errors
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/errors/de/
2022-04-19 21:32:54 +00:00
1b7546aede Translated using Weblate (German)
Currently translated at 100.0% (146 of 146 strings)

Translation: cannery/default
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/default/de/
2022-04-19 21:32:54 +00:00
e153893a5b Translated using Weblate (German)
Currently translated at 100.0% (44 of 44 strings)

Translation: cannery/prompts
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/prompts/de/
2022-04-19 21:32:53 +00:00
2f7c17aad3 Translated using Weblate (German)
Currently translated at 100.0% (15 of 15 strings)

Translation: cannery/emails
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/emails/de/
2022-04-19 21:32:53 +00:00
664c65d136 Translated using Weblate (German)
Currently translated at 96.6% (29 of 30 strings)

Translation: cannery/errors
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/errors/de/
2022-04-19 21:32:22 +00:00
ef76eb002d Translated using Weblate (German)
Currently translated at 96.6% (29 of 30 strings)

Translation: cannery/errors
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/errors/de/
2022-04-19 21:32:22 +00:00
5b40ac4137 Translated using Weblate (German)
Currently translated at 98.6% (144 of 146 strings)

Translation: cannery/default
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/default/de/
2022-04-19 21:30:00 +00:00
ed20cdd858 Translated using Weblate (German)
Currently translated at 96.9% (32 of 33 strings)

Translation: cannery/actions
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/actions/de/
2022-04-19 21:29:42 +00:00
1e0ec82f3e Translated using Weblate (German)
Currently translated at 83.3% (25 of 30 strings)

Translation: cannery/errors
Translate-URL: https://weblate.bubbletea.dev/projects/cannery/errors/de/
2022-04-19 21:18:06 +00:00
d07ac801aa Added translation using Weblate (German) 2022-04-19 19:32:18 +00:00
420e7c2d71 Added translation using Weblate (German) 2022-04-19 19:32:16 +00:00
40877d1ac0 Added translation using Weblate (German) 2022-04-19 19:32:15 +00:00
1dd30e6a5b Added translation using Weblate (German) 2022-04-19 19:32:15 +00:00
eedaf33e25 Added translation using Weblate (German) 2022-04-19 19:32:14 +00:00
b0a100cd6c Added translation using Weblate (German) 2022-04-19 19:32:14 +00:00
6455e2710d bump version 2022-03-28 23:58:16 -04:00
6523b28aa2 update translations 2022-03-28 23:57:08 -04:00
bad1a23dfe fix ammo group overflow 2022-03-28 23:56:56 -04:00
e0ddefe1d7 fix tag and container overflow 2022-03-28 23:56:45 -04:00
5d6ecba9f7 display inline block, add min width to buttons and links 2022-03-28 23:56:15 -04:00
a2d1ff9b89 fix credo 2022-03-28 23:05:12 -04:00
34288a0070 make drone cache persistent 2022-03-04 23:36:19 -05:00
f9b08222e1 bump version 2022-03-04 23:19:11 -05:00
c0179f48bd mix format 2022-03-04 23:17:53 -05:00
8bb4aab49c Fix ammo group create form error bug 2022-03-04 23:16:37 -05:00
9f2cc54738 fix maintain attrs hook 2022-03-04 22:56:52 -05:00
0309e9d714 fix credo 2022-03-04 22:28:05 -05:00
af4af84515 use table component for shot group table 2022-03-04 22:06:01 -05:00
ec6946068e fix view helpers display bug 2022-03-04 22:05:08 -05:00
f120e54c3e use table component for ammo group show table 2022-03-04 21:57:22 -05:00
3d115c6383 fixup! use table component for move ammo group component 2022-03-04 21:56:48 -05:00
1d4622a285 fixup! use table component for ammo group table 2022-03-04 21:09:05 -05:00
d9e7948bb0 fixup! use new table component for ammo type index table 2022-03-04 21:07:32 -05:00
da8c788992 use table component for move ammo group component 2022-03-04 20:53:18 -05:00
bd20820361 use table component for ammo group table 2022-03-04 20:00:09 -05:00
d0ee81093a use new table component for ammo type index table 2022-03-04 18:28:10 -05:00
6080fdbe64 add table component 2022-03-04 18:26:57 -05:00
f42aaf9099 fix bug with move ammo group component 2022-03-04 00:06:08 -05:00
a6aa6f3386 fix elements flashing black 2022-02-26 00:16:36 -05:00
8405513337 add link to changelog 2022-02-24 20:42:27 -05:00
d0857eccc1 remove "listing" from titles 2022-02-24 00:52:46 -05:00
4c9e707181 merge translations 2022-02-24 00:30:23 -05:00
e6a4fbcfb5 bump version 2022-02-24 00:18:33 -05:00
a6b2c6181e add multiple ammo groups at one time 2022-02-24 00:17:23 -05:00
d79d0fa179 use today's date when adding new shot groups 2022-02-23 20:52:12 -05:00
46387e8d7a update changelog 2022-02-23 20:47:23 -05:00
dccea1b9de edit and delete shot groups from ammo group page 2022-02-23 20:45:58 -05:00
5ca21c64fd fix text styling 2022-02-23 20:35:18 -05:00
9773ccc6ff add prompt to create container before creating ammo group 2022-02-23 20:34:07 -05:00
9cd2bc574b conditionally load containers list 2022-02-23 19:51:07 -05:00
ee28de1178 fix not showing 0 if ammo type with 0 rounds 2022-02-23 19:41:21 -05:00
91cf9d0eb5 bump version 2022-02-20 20:43:04 -05:00
3ce8eda712 mix format 2022-02-20 20:40:24 -05:00
1a78e88b34 add page titles to registration and setting pages 2022-02-20 20:39:27 -05:00
968abd04ee fix grids having uneven margins in phone mode 2022-02-20 20:28:42 -05:00
dc209fa192 fix modals with overflowing content 2022-02-20 20:28:34 -05:00
a80df49fdd bump version 2022-02-20 15:20:09 -05:00
92d1d21d00 add changelog 2022-02-20 15:17:38 -05:00
917f627933 add back modal click-away 2022-02-20 15:17:12 -05:00
4946a6b119 fixes template error on modal refreshes 2022-02-20 15:01:15 -05:00
9f784c3190 fix closing modal without triggering reload 2022-02-20 15:00:53 -05:00
aa08e212ee fix loading and reconnecting pages 2022-02-19 21:29:36 -05:00
80ad939aab fix docker image tag for latest builds 2022-02-19 21:29:29 -05:00
08c9cddc78 fix user card confirmation time spacing 2022-02-19 19:54:52 -05:00
e6285c282b add version tags 2022-02-19 19:38:29 -05:00
61829fc042 fix grid spacing in mobile mode 2022-02-19 18:08:46 -05:00
e2f8fd3ee5 fix checkbox spacing 2022-02-19 18:06:42 -05:00
146 changed files with 14079 additions and 8003 deletions

View File

@ -157,17 +157,17 @@
#
# Controversial and experimental checks (opt-in, just replace `false` with `[]`)
#
{Credo.Check.Consistency.MultiAliasImportRequireUse, false},
{Credo.Check.Consistency.UnusedVariableNames, false},
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, [force: :meaningful]},
{Credo.Check.Design.DuplicatedCode, false},
{Credo.Check.Readability.AliasAs, false},
{Credo.Check.Readability.BlockPipe, false},
{Credo.Check.Readability.ImplTrue, false},
{Credo.Check.Readability.MultiAlias, false},
{Credo.Check.Readability.SeparateAliasRequire, false},
{Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SinglePipe, false},
{Credo.Check.Readability.Specs, false},
{Credo.Check.Readability.StrictModuleLayout, false},
{Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.WithCustomTaggedTuple, false},
{Credo.Check.Refactor.ABCSize, false},
{Credo.Check.Refactor.AppendSingleItem, false},
@ -176,9 +176,9 @@
{Credo.Check.Refactor.NegatedIsNil, false},
{Credo.Check.Refactor.PipeChainStart, false},
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}
{Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, []},
{Credo.Check.Warning.UnsafeToAtom, []}
#
# Custom checks can be created using `mix credo.gen.check`.

View File

@ -16,30 +16,48 @@ steps:
- assets/node_modules/
- name: test
image: bitwalker/alpine-elixir-phoenix:1.13
image: elixir:1.13.4-alpine
environment:
TEST_DATABASE_URL: ecto://postgres:postgres@database/cannery_test
HOST: testing.example.tld
commands:
- apk add --no-cache build-base npm git python3
- mix local.rebar --force
- mix local.hex --force
- mix deps.get
- npm install --prefix assets
- mix deps.compile
- npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
- npm run --prefix ./assets deploy
- mix do phx.digest, gettext.extract
- mix test
- name: build and publish
- name: build and publish stable
image: plugins/docker
settings:
repo: shibaobun/cannery
tags: latest
username:
from_secret: docker_username
password:
from_secret: docker_password
tags: latest
when:
branch:
- stable
- name: build and publish tagged version
image: plugins/docker
settings:
repo: shibaobun/cannery
username:
from_secret: docker_username
password:
from_secret: docker_password
tags:
- ${DRONE_TAG}
when:
event:
- tag
- name: rebuild-cache
image: drillster/drone-volume-cache
volumes:
@ -63,7 +81,7 @@ services:
volumes:
- name: cache
host:
path: /tmp/drone-cache
path: /run/media/default/ssdsrv/gitea/drone-cache
- name: docker_sock
host:
path: /var/run/docker.sock

View File

@ -2,5 +2,5 @@
import_deps: [:ecto, :phoenix],
inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
subdirectories: ["priv/*/migrations"],
plugins: [HeexFormatter]
plugins: [Phoenix.LiveView.HTMLFormatter]
]

View File

@ -1,3 +1,3 @@
elixir 1.13.2-otp-24
elixir 1.13.4-otp-24
erlang 24.2
nodejs 16.13.2

View File

@ -1,7 +1,75 @@
# 0.3.0
-
# v0.5.5
- Forgot to add the logo as the favicon whoops
# 0.2.0
# v0.5.4
- Rename "Ammo" tab to "Catalog", and "Manage" tab is now "Ammo"
- Ammo groups are now just referred to as Ammo or "Packs"
- URL paths now reflect new names
- Add pack and round count to container information
- Add cute logo >:3 Thank you [kalli](https://twitter.com/t0kkuro)!
- Add note about deleting an ammo type deleting all ammo of that type as well
- Prompt to create first ammo type before trying to create first ammo
- Add note about creating unlimited invites
- Update screenshot lol
# v0.5.3
- Update French translation: Thank you [duponin](https://udongein.xyz/users/duponin)!
- Update German translation: Thank you [Kaia](https://shitposter.club/users/kaia)!
# v0.5.2
- Add "Added on" date to ammo groups
- Add "Added on" date to ammo types
- Add "Registered on" date to user information
- Add language in user settings. The `LOCALE` environment variable will continue
to set the default locale for the application.
- Add involvement links to home page
- Fix button text-wrapping
- Update dependencies
# v0.5.1
- Add French translation: Thank you [duponin](https://udongein.xyz/users/duponin)!
# v0.5.0
- Add German translation: Thank you [Kaia](https://shitposter.club/users/kaia)!
- Fix not being able to edit ammo group when fully used up
- Fix bug with average price per round calculation
- Show average price per round on ammo type table
- Use Elixir v1.13.4
# v0.4.1
- Fix button and tag text wrapping
- Code quality fixes
# v0.4.0
- Make tables sortable
- Add link to changelog from version number
- Fix some elements flashing with black background
- Fix bug with moving ammo group to new container
- Fix bug with no error showing up for create ammo group form
# v0.3.0
- Fix ammo type counts not showing when count is 0
- Add prompt to create first container before first ammo group
- Edit and delete shot groups from ammo group show page
- Use today's date when adding new shot groups
- Create multiple ammo groups at one time
# v0.2.3
- Fix modals with overflowing forms
- Fix grids having uneven margins in phone mode
- Add page titles to registration and setting pages
# v0.2.2
- Fix loading and reconnecting pages not being fixed
- Fix closing modal in some cases not triggering a page reload
- Fix error when display container and tag edit routes from a fresh reload
# v0.2.1
- Fix checkbox spacing for mobile view
- Fix spacing with form elements in mobile view
- Fix user card spacing
# v0.2.0
- Add or remove tags from containers list and details page
- Show tags on containers
- Add "Cannery" to page titles
@ -11,5 +79,5 @@
- Show shot history for an ammo group
- Show ammo round totals and total shot for ammo types
# 0.1.0
# v0.1.0
- Initial release!

View File

@ -63,8 +63,7 @@ And as always, thank you!
[`phx_gen_auth`](https://hexdocs.pm/phx_gen_auth/).
- `Dockerfile` and example `docker-compose.yml`
- Automatic migrations in `MIX_ENV=prod` or Docker image
- JS linting with [standard.js](https://standardjs.com), HEEx linting with
[heex_formatter](https://github.com/feliperenan/heex_formatter)
- JS linting with [standard.js](https://standardjs.com)
## Docs
@ -109,7 +108,8 @@ In `dev` mode, Cannery will listen for these environment variables at runtime.
Defaults to `false`.
- `POOL_SIZE`: Controls the pool size to use with PostgreSQL. Defaults to `10`.
- `REGISTRATION`: Controls if user sign-up should be invite only or set to public. Set to `public` to enable public registration. Defaults to `invite`.
- `LOCALE`: Sets a custom locale. Defaults to `en_US`.
- `LOCALE`: Sets a custom default locale. Defaults to `en_US`.
- Available options: `en_US`, `de`, and `fr`
## `MIX_ENV=test`
@ -141,3 +141,6 @@ In `prod` mode (or in the Docker container), Cannery will listen for the same en
Thank you so much for your contributions!
- shibao (https://misskey.bubbletea.dev/@shibao)
- kaia (https://shitposter.club/users/kaia)
- duponin (https://udongein.xyz/users/duponin)
- kalli (https://twitter.com/t0kkuro)

View File

@ -1,4 +1,4 @@
FROM elixir:1.13-alpine AS build
FROM elixir:1.13.4-alpine AS build
# install build dependencies
RUN apk add --no-cache build-base npm git python3

View File

@ -1,6 +1,6 @@
# Cannery
![screenshot](https://gitea.bubbletea.dev/shibao/cannery/raw/branch/stable/home.png)
![old screenshot](https://gitea.bubbletea.dev/shibao/cannery/raw/branch/stable/home.png)
The self-hosted firearm tracker website.
@ -63,7 +63,8 @@ You can use the following environment variables to configure Cannery in
with `docker run -it shibaobun/cannery mix phx.gen.secret` and set for server to start.
- `REGISTRATION`: Controls if user sign-up should be invite only or set to
public. Set to `public` to enable public registration. Defaults to `invite`.
- `LOCALE`: Sets a custom locale. Defaults to `en_US`.
- `LOCALE`: Sets a custom default locale. Defaults to `en_US`
- Available options: `en_US`, `de`, and `fr`
- `SMTP_HOST`: The url for your SMTP email provider. Must be set
- `SMTP_PORT`: The port for your SMTP relay. Defaults to `587`.
- `SMTP_USERNAME`: The username for your SMTP relay. Must be set!

View File

@ -17,8 +17,7 @@
-o-transform: scale(1.5);
transform: scale(1.5);
padding: 10px;
margin-left: auto;
margin-right: auto;
margin: 1em auto;
}
.title {
@ -26,6 +25,7 @@
}
.btn {
@apply inline-block break-words min-w-4;
@apply focus:outline-none px-4 py-2 rounded-lg;
@apply shadow-sm focus:shadow-lg;
@apply transition-all duration-300 ease-in-out;
@ -52,6 +52,7 @@
}
.link {
@apply inline-block break-all min-w-4;
@apply hover:underline;
@apply transition-colors duration-500 ease-in-out;
}

View File

@ -2,7 +2,10 @@
// update. https://github.com/phoenixframework/phoenix_live_view/issues/1011
export default {
attrs () { return this.el.getAttribute('data-attrs').split(', ') },
attrs () {
const attrs = this.el.getAttribute('data-attrs')
if (attrs) { return attrs.split(', ') } else { return [] }
},
beforeUpdate () { this.prevAttrs = this.attrs().map(name => [name, this.el.getAttribute(name)]) },
updated () { this.prevAttrs.forEach(([name, val]) => this.el.setAttribute(name, val)) }
}

11731
assets/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -9,36 +9,33 @@
"test": "standard"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^5.15.4",
"alpinejs": "^3.9.0",
"@fortawesome/fontawesome-free": "^6.1.1",
"alpinejs": "^3.10.2",
"phoenix": "file:../deps/phoenix",
"phoenix_html": "file:../deps/phoenix_html",
"phoenix_live_view": "file:../deps/phoenix_live_view",
"topbar": "^0.1.4"
"topbar": "^1.0.1"
},
"devDependencies": {
"@babel/core": "^7.15.0",
"@babel/preset-env": "^7.15.0",
"autoprefixer": "^10.2.6",
"babel-loader": "^8.2.2",
"copy-webpack-plugin": "^9.0.0",
"css-loader": "^5.2.7",
"css-minimizer-webpack-plugin": "^3.0.1",
"@babel/core": "^7.17.10",
"@babel/preset-env": "^7.17.10",
"autoprefixer": "^10.4.7",
"babel-loader": "^8.2.5",
"copy-webpack-plugin": "^10.2.4",
"css-loader": "^6.7.1",
"css-minimizer-webpack-plugin": "^3.4.1",
"file-loader": "^6.2.0",
"hard-source-webpack-plugin": "^0.13.1",
"mini-css-extract-plugin": "^1.6.0",
"node-sass": "^7.0.1",
"postcss": "^8.3.6",
"postcss-import": "^14.0.2",
"postcss-loader": "^6.1.1",
"postcss-preset-env": "^7.3.1",
"sass-loader": "^12.1.0",
"standard": "^16.0.4",
"style-loader": "^3.2.1",
"tailwindcss": "^2.2.7",
"terser-webpack-plugin": "^5.1.3",
"webpack": "^5.67.0",
"webpack-cli": "^4.8.0",
"webpack-dev-server": "^4.7.4"
"mini-css-extract-plugin": "^2.6.0",
"postcss": "^8.4.13",
"postcss-import": "^14.1.0",
"postcss-loader": "^6.2.1",
"postcss-preset-env": "^7.5.0",
"sass-loader": "^12.6.0",
"standard": "^17.0.0",
"tailwindcss": "^3.0.24",
"terser-webpack-plugin": "^5.3.1",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.9.0"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 516 KiB

View File

@ -1,24 +1,18 @@
const colors = require('tailwindcss/colors')
module.exports = {
purge: [
'../lib/**/*.ex',
'../lib/**/*.heex',
'../lib/**/*.leex',
'../lib/**/*.eex',
content: [
'../lib/**/*.{ex,heex,leex,eex}',
'./js/**/*.js'
],
darkMode: 'media',
theme: {
colors: {
transparent: 'transparent',
current: 'currentColor',
primary: colors.gray,
black: colors.black,
white: colors.white,
gray: colors.trueGray,
gray: colors.neutral,
indigo: colors.indigo,
red: colors.rose,
yellow: colors.amber
@ -28,13 +22,21 @@ module.exports = {
128: '32rem',
192: '48rem',
256: '64rem'
}
}
},
variants: {
extend: {
backgroundColor: ['active'],
borderColor: ['active']
minWidth: {
4: '1rem',
8: '2rem',
12: '3rem',
16: '4rem',
20: '8rem'
},
maxWidth: {
4: '1rem',
8: '2rem',
12: '3rem',
16: '4rem',
20: '8rem'
}
}
},
plugins: []

View File

@ -44,19 +44,14 @@ module.exports = (env, options) => {
},
{
test: /\.(woff(2)?|ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
outputPath: '../fonts'
}
type: 'asset/resource',
generator: { filename: 'fonts/[name][ext]' }
}
]
},
plugins: [
new MiniCssExtractPlugin({ filename: '../css/app.css' }),
new CopyWebpackPlugin({
patterns: [{ from: 'static/', to: '../' }]
})
new CopyWebpackPlugin({ patterns: [{ from: 'static/', to: '../' }] })
]
}
}

View File

@ -14,8 +14,8 @@ end
config :cannery, CanneryWeb.ViewHelpers, shibao_mode: System.get_env("SHIBAO_MODE") == "true"
# Set locale
Gettext.put_locale(System.get_env("LOCALE") || "en_US")
# Set default locale
config :gettext, :default_locale, System.get_env("LOCALE") || "en_US"
maybe_ipv6 = if System.get_env("ECTO_IPV6") == "true", do: [:inet6], else: []

BIN
home.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

After

Width:  |  Height:  |  Size: 113 KiB

View File

@ -196,7 +196,7 @@ defmodule Cannery.Accounts do
{:ok, _} <- Repo.transaction(user_email_multi(user, email, context)) do
:ok
else
_ -> :error
_error_tuple -> :error
end
end
@ -265,10 +265,39 @@ defmodule Cannery.Accounts do
|> Repo.transaction()
|> case do
{:ok, %{user: user}} -> {:ok, user}
{:error, :user, changeset, _} -> {:error, changeset}
{:error, :user, changeset, _changes_so_far} -> {:error, changeset}
end
end
@doc """
Returns an `%Changeset{}` for changing the user locale.
## Examples
iex> change_user_locale(user)
%Changeset{data: %User{}}
"""
@spec change_user_locale(User.t()) :: Changeset.t(User.t())
def change_user_locale(%{locale: locale} = user), do: User.locale_changeset(user, locale)
@doc """
Updates the user locale.
## Examples
iex> update_user_locale(user, "valid locale")
{:ok, %User{}}
iex> update_user_password(user, "invalid locale")
{:error, %Changeset{}}
"""
@spec update_user_locale(User.t(), locale :: String.t()) ::
{:ok, User.t()} | {:error, Changeset.t(User.t())}
def update_user_locale(user, locale),
do: user |> User.locale_changeset(locale) |> Repo.update()
@doc """
Deletes a user. must be performed by an admin or the same user!
@ -372,7 +401,7 @@ defmodule Cannery.Accounts do
{:ok, %{user: user}} <- Repo.transaction(confirm_user_multi(user)) do
{:ok, user}
else
_ -> :error
_error_tuple -> :error
end
end
@ -420,7 +449,7 @@ defmodule Cannery.Accounts do
%User{} = user <- Repo.one(query) do
user
else
_ -> nil
_error_tuple -> nil
end
end
@ -444,7 +473,7 @@ defmodule Cannery.Accounts do
|> Repo.transaction()
|> case do
{:ok, %{user: user}} -> {:ok, user}
{:error, :user, changeset, _} -> {:error, changeset}
{:error, :user, changeset, _changes_so_far} -> {:error, changeset}
end
end
end

View File

@ -18,6 +18,7 @@ defmodule Cannery.Accounts.User do
field :hashed_password, :string
field :confirmed_at, :naive_datetime
field :role, Ecto.Enum, values: [:admin, :user], default: :user
field :locale, :string
has_many :invites, Invite, on_delete: :delete_all
@ -31,6 +32,7 @@ defmodule Cannery.Accounts.User do
hashed_password: String.t(),
confirmed_at: NaiveDateTime.t(),
role: atom(),
locale: String.t() | nil,
invites: [Invite.t()],
inserted_at: NaiveDateTime.t(),
updated_at: NaiveDateTime.t()
@ -60,7 +62,7 @@ defmodule Cannery.Accounts.User do
Changeset.t(t() | new_user())
def registration_changeset(user, attrs, opts \\ []) do
user
|> cast(attrs, [:email, :password, :role])
|> cast(attrs, [:email, :password, :role, :locale])
|> validate_email()
|> validate_password(opts)
end
@ -171,7 +173,7 @@ defmodule Cannery.Accounts.User do
Bcrypt.verify_pass(password, hashed_password)
end
def valid_password?(_, _) do
def valid_password?(_invalid_user, _invalid_password) do
Bcrypt.no_user_verify()
false
end
@ -185,4 +187,14 @@ defmodule Cannery.Accounts.User do
do: changeset,
else: changeset |> add_error(:current_password, dgettext("errors", "is not valid"))
end
@doc """
A changeset for changing the user's locale
"""
@spec locale_changeset(t() | Changeset.t(t()), locale :: String.t() | nil) :: Changeset.t(t())
def locale_changeset(user_or_changeset, locale) do
user_or_changeset
|> cast(%{"locale" => locale}, [:locale])
|> validate_required(:locale)
end
end

View File

@ -4,8 +4,7 @@ defmodule Cannery.ActivityLog do
"""
import Ecto.Query, warn: false
import CanneryWeb.Gettext
alias Cannery.{Accounts.User, ActivityLog.ShotGroup, Ammo, Ammo.AmmoGroup, Repo}
alias Cannery.{Accounts.User, ActivityLog.ShotGroup, Ammo.AmmoGroup, Repo}
alias Ecto.{Changeset, Multi}
@doc """
@ -60,25 +59,24 @@ defmodule Cannery.ActivityLog do
"""
@spec create_shot_group(attrs :: map(), User.t(), AmmoGroup.t()) ::
{:ok, ShotGroup.t()} | {:error, Changeset.t(ShotGroup.t()) | nil}
def create_shot_group(
attrs,
%User{id: user_id},
%AmmoGroup{id: ammo_group_id, count: ammo_group_count, user_id: user_id} = ammo_group
) do
attrs = attrs |> Map.merge(%{"user_id" => user_id, "ammo_group_id" => ammo_group_id})
changeset = %ShotGroup{} |> ShotGroup.create_changeset(attrs)
shot_group_count = changeset |> Changeset.get_field(:count)
if shot_group_count > ammo_group_count do
error = dgettext("errors", "Count must be less than %{count}", count: ammo_group_count)
changeset = changeset |> Changeset.add_error(:count, error)
{:error, changeset}
else
def create_shot_group(attrs, user, ammo_group) do
Multi.new()
|> Multi.insert(:create_shot_group, changeset)
|> Multi.insert(
:create_shot_group,
%ShotGroup{} |> ShotGroup.create_changeset(user, ammo_group, attrs)
)
|> Multi.run(
:ammo_group,
fn repo, %{create_shot_group: %{ammo_group_id: ammo_group_id, user_id: user_id}} ->
{:ok,
repo.one(from ag in AmmoGroup, where: ag.id == ^ammo_group_id and ag.user_id == ^user_id)}
end
)
|> Multi.update(
:update_ammo_group,
fn %{create_shot_group: %{count: shot_group_count}, ammo_group: %{count: ammo_group_count}} ->
ammo_group |> AmmoGroup.range_changeset(%{"count" => ammo_group_count - shot_group_count})
end
)
|> Repo.transaction()
|> case do
@ -87,7 +85,6 @@ defmodule Cannery.ActivityLog do
{:error, _other_transaction, _value, _changes_so_far} -> {:error, nil}
end
end
end
@doc """
Updates a shot_group.
@ -104,35 +101,32 @@ defmodule Cannery.ActivityLog do
@spec update_shot_group(ShotGroup.t(), attrs :: map(), User.t()) ::
{:ok, ShotGroup.t()} | {:error, Changeset.t(ShotGroup.t()) | nil}
def update_shot_group(
%ShotGroup{count: count, user_id: user_id, ammo_group_id: ammo_group_id} = shot_group,
%ShotGroup{count: count, user_id: user_id} = shot_group,
attrs,
%User{id: user_id} = user
) do
%{count: ammo_group_count, user_id: ^user_id} =
ammo_group = ammo_group_id |> Ammo.get_ammo_group!(user)
changeset = shot_group |> ShotGroup.update_changeset(attrs)
new_shot_group_count = changeset |> Changeset.get_field(:count)
shot_diff_to_add = new_shot_group_count - count
cond do
shot_diff_to_add > ammo_group_count ->
error = dgettext("errors", "Count must be less than %{count}", count: ammo_group_count)
changeset = changeset |> Changeset.add_error(:count, error)
{:error, changeset}
new_shot_group_count <= 0 ->
error = dgettext("errors", "Count must be at least 1")
changeset = changeset |> Changeset.add_error(:count, error)
{:error, changeset}
true ->
Multi.new()
|> Multi.update(:update_shot_group, changeset)
|> Multi.update(
:update_shot_group,
shot_group |> ShotGroup.update_changeset(user, attrs)
)
|> Multi.run(
:ammo_group,
fn repo, %{update_shot_group: %{ammo_group_id: ammo_group_id, user_id: user_id}} ->
{:ok,
repo.one(from ag in AmmoGroup, where: ag.id == ^ammo_group_id and ag.user_id == ^user_id)}
end
)
|> Multi.update(
:update_ammo_group,
ammo_group
|> AmmoGroup.range_changeset(%{"count" => ammo_group_count - shot_diff_to_add})
fn %{
update_shot_group: %{count: new_count},
ammo_group: %{count: ammo_group_count} = ammo_group
} ->
shot_diff_to_add = new_count - count
new_ammo_group_count = ammo_group_count - shot_diff_to_add
ammo_group |> AmmoGroup.range_changeset(%{"count" => new_ammo_group_count})
end
)
|> Repo.transaction()
|> case do
@ -141,7 +135,6 @@ defmodule Cannery.ActivityLog do
{:error, _other_transaction, _value, _changes_so_far} -> {:error, nil}
end
end
end
@doc """
Deletes a shot_group.
@ -158,18 +151,27 @@ defmodule Cannery.ActivityLog do
@spec delete_shot_group(ShotGroup.t(), User.t()) ::
{:ok, ShotGroup.t()} | {:error, Changeset.t(ShotGroup.t())}
def delete_shot_group(
%ShotGroup{count: count, user_id: user_id, ammo_group_id: ammo_group_id} = shot_group,
%User{id: user_id} = user
%ShotGroup{user_id: user_id} = shot_group,
%User{id: user_id}
) do
%{count: ammo_group_count, user_id: ^user_id} =
ammo_group = ammo_group_id |> Ammo.get_ammo_group!(user)
Multi.new()
|> Multi.delete(:delete_shot_group, shot_group)
|> Multi.run(
:ammo_group,
fn repo, %{delete_shot_group: %{ammo_group_id: ammo_group_id, user_id: user_id}} ->
{:ok,
repo.one(from ag in AmmoGroup, where: ag.id == ^ammo_group_id and ag.user_id == ^user_id)}
end
)
|> Multi.update(
:update_ammo_group,
ammo_group
|> AmmoGroup.range_changeset(%{"count" => ammo_group_count + count})
fn %{
delete_shot_group: %{count: count},
ammo_group: %{count: ammo_group_count} = ammo_group
} ->
new_ammo_group_count = ammo_group_count + count
ammo_group |> AmmoGroup.range_changeset(%{"count" => new_ammo_group_count})
end
)
|> Repo.transaction()
|> case do
@ -178,21 +180,4 @@ defmodule Cannery.ActivityLog do
{:error, _other_transaction, _value, _changes_so_far} -> {:error, nil}
end
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking shot_group changes.
## Examples
iex> change_shot_group(shot_group)
%Ecto.Changeset{data: %ShotGroup{}}
"""
@spec change_shot_group(ShotGroup.t() | ShotGroup.new_shot_group()) ::
Changeset.t(ShotGroup.t() | ShotGroup.new_shot_group())
@spec change_shot_group(ShotGroup.t() | ShotGroup.new_shot_group(), attrs :: map()) ::
Changeset.t(ShotGroup.t() | ShotGroup.new_shot_group())
def change_shot_group(%ShotGroup{} = shot_group, attrs \\ %{}) do
shot_group |> ShotGroup.update_changeset(attrs)
end
end

View File

@ -4,8 +4,9 @@ defmodule Cannery.ActivityLog.ShotGroup do
"""
use Ecto.Schema
import CanneryWeb.Gettext
import Ecto.Changeset
alias Cannery.{Accounts.User, ActivityLog.ShotGroup, Ammo.AmmoGroup}
alias Cannery.{Accounts.User, ActivityLog.ShotGroup, Ammo.AmmoGroup, Repo}
alias Ecto.{Changeset, UUID}
@primary_key {:id, :binary_id, autogenerate: true}
@ -37,21 +38,84 @@ defmodule Cannery.ActivityLog.ShotGroup do
@type id :: UUID.t()
@doc false
@spec create_changeset(new_shot_group(), attrs :: map()) :: Changeset.t(new_shot_group())
def create_changeset(shot_group, attrs) do
@spec create_changeset(
new_shot_group(),
User.t() | any(),
AmmoGroup.t() | any(),
attrs :: map()
) ::
Changeset.t(new_shot_group())
def create_changeset(
shot_group,
%User{id: user_id},
%AmmoGroup{id: ammo_group_id, user_id: user_id} = ammo_group,
attrs
)
when not (user_id |> is_nil()) and not (ammo_group_id |> is_nil()) do
shot_group
|> cast(attrs, [:count, :notes, :date, :ammo_group_id, :user_id])
|> change(user_id: user_id)
|> change(ammo_group_id: ammo_group_id)
|> cast(attrs, [:count, :notes, :date])
|> validate_number(:count, greater_than: 0)
|> validate_create_shot_group_count(ammo_group)
|> validate_required([:count, :ammo_group_id, :user_id])
end
def create_changeset(shot_group, _invalid_user, _invalid_ammo_group, attrs) do
shot_group
|> cast(attrs, [:count, :notes, :date])
|> validate_number(:count, greater_than: 0)
|> validate_required([:count, :ammo_group_id, :user_id])
|> add_error(:invalid, dgettext("errors", "Please select a valid user and ammo group"))
end
defp validate_create_shot_group_count(changeset, %AmmoGroup{count: ammo_group_count}) do
if changeset |> Changeset.get_field(:count) > ammo_group_count do
error = dgettext("errors", "Count must be less than %{count}", count: ammo_group_count)
changeset |> Changeset.add_error(:count, error)
else
changeset
end
end
@doc false
@spec update_changeset(t() | new_shot_group(), attrs :: map()) ::
@spec update_changeset(t() | new_shot_group(), User.t(), attrs :: map()) ::
Changeset.t(t() | new_shot_group())
def update_changeset(shot_group, attrs) do
def update_changeset(
%ShotGroup{user_id: user_id} = shot_group,
%User{id: user_id} = user,
attrs
)
when not (user_id |> is_nil()) do
shot_group
|> cast(attrs, [:count, :notes, :date])
|> validate_number(:count, greater_than: 0)
|> validate_required([:count])
|> validate_update_shot_group_count(shot_group, user)
end
defp validate_update_shot_group_count(
changeset,
%ShotGroup{count: count} = shot_group,
%User{id: user_id}
)
when not (user_id |> is_nil()) do
%{ammo_group: %AmmoGroup{count: ammo_group_count, user_id: ^user_id}} =
shot_group |> Repo.preload(:ammo_group)
new_shot_group_count = changeset |> Changeset.get_field(:count)
shot_diff_to_add = new_shot_group_count - count
cond do
shot_diff_to_add > ammo_group_count ->
error = dgettext("errors", "Count must be less than %{count}", count: ammo_group_count)
changeset |> Changeset.add_error(:count, error)
new_shot_group_count <= 0 ->
changeset |> Changeset.add_error(:count, dgettext("errors", "Count must be at least 1"))
true ->
changeset
end
end
end

View File

@ -3,11 +3,15 @@ defmodule Cannery.Ammo do
The Ammo context.
"""
import CanneryWeb.Gettext
import Ecto.Query, warn: false
alias Cannery.{Accounts.User, Containers, Repo}
alias Cannery.ActivityLog.ShotGroup
alias Cannery.Ammo.{AmmoGroup, AmmoType}
alias Ecto.Changeset
@ammo_group_create_limit 10_000
@doc """
Returns the list of ammo_types.
@ -21,6 +25,25 @@ defmodule Cannery.Ammo do
def list_ammo_types(%User{id: user_id}),
do: Repo.all(from at in AmmoType, where: at.user_id == ^user_id, order_by: at.name)
@doc """
Returns a count of ammo_types.
## Examples
iex> get_ammo_types_count!(%User{id: 123})
3
"""
@spec get_ammo_types_count!(User.t()) :: integer()
def get_ammo_types_count!(%User{id: user_id}) do
Repo.one(
from at in AmmoType,
where: at.user_id == ^user_id,
select: count(at.id),
distinct: true
)
end
@doc """
Gets a single ammo_type.
@ -42,28 +65,31 @@ defmodule Cannery.Ammo do
@doc """
Gets the average cost of a single ammo type
Raises `Ecto.NoResultsError` if the Ammo type does not exist.
## Examples
iex> get_ammo_type!(123, %User{id: 123})
%AmmoType{}
iex> get_ammo_type!(456, %User{id: 123})
** (Ecto.NoResultsError)
iex> get_average_cost_for_ammo_type!(%AmmoType{id: 123}, %User{id: 123})
1.50
"""
@spec get_average_cost_for_ammo_type!(AmmoType.t(), User.t()) :: float()
@spec get_average_cost_for_ammo_type!(AmmoType.t(), User.t()) :: float() | nil
def get_average_cost_for_ammo_type!(
%AmmoType{id: ammo_type_id, user_id: user_id},
%User{id: user_id}
) do
sg_total_query =
from sg in ShotGroup,
where: not (sg.count |> is_nil()),
group_by: sg.ammo_group_id,
select: %{ammo_group_id: sg.ammo_group_id, total: sum(sg.count)}
Repo.one!(
from ag in AmmoGroup,
left_join: sg in assoc(ag, :shot_groups),
as: :ammo_group,
left_join: sg_query in subquery(sg_total_query),
on: ag.id == sg_query.ammo_group_id,
where: ag.ammo_type_id == ^ammo_type_id,
where: not (ag.price_paid |> is_nil()),
select: sum(ag.price_paid) / (sum(ag.count) + sum(sg.count))
select: sum(ag.price_paid) / sum(ag.count + coalesce(sg_query.total, 0))
)
end
@ -90,7 +116,7 @@ defmodule Cannery.Ammo do
from ag in AmmoGroup,
where: ag.ammo_type_id == ^ammo_type_id,
select: sum(ag.count)
)
) || 0
end
@doc """
@ -117,7 +143,7 @@ defmodule Cannery.Ammo do
left_join: sg in assoc(ag, :shot_groups),
where: ag.ammo_type_id == ^ammo_type_id,
select: sum(sg.count)
)
) || 0
end
@doc """
@ -134,11 +160,8 @@ defmodule Cannery.Ammo do
"""
@spec create_ammo_type(attrs :: map(), User.t()) ::
{:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.new_ammo_type())}
def create_ammo_type(attrs \\ %{}, %User{id: user_id}) do
%AmmoType{}
|> AmmoType.create_changeset(attrs |> Map.put("user_id", user_id))
|> Repo.insert()
end
def create_ammo_type(attrs \\ %{}, %User{} = user),
do: %AmmoType{} |> AmmoType.create_changeset(user, attrs) |> Repo.insert()
@doc """
Updates a ammo_type.
@ -187,22 +210,6 @@ defmodule Cannery.Ammo do
def delete_ammo_type!(%AmmoType{user_id: user_id} = ammo_type, %User{id: user_id}),
do: ammo_type |> Repo.delete!()
@doc """
Returns an `%Changeset{}` for tracking ammo_type changes.
## Examples
iex> change_ammo_type(ammo_type)
%Changeset{data: %AmmoType{}}
"""
@spec change_ammo_type(AmmoType.t() | AmmoType.new_ammo_type()) ::
Changeset.t(AmmoType.t() | AmmoType.new_ammo_type())
@spec change_ammo_type(AmmoType.t() | AmmoType.new_ammo_type(), attrs :: map()) ::
Changeset.t(AmmoType.t() | AmmoType.new_ammo_type())
def change_ammo_type(%AmmoType{} = ammo_type, attrs \\ %{}),
do: AmmoType.update_changeset(ammo_type, attrs)
@doc """
Returns the list of ammo_groups for a user and type.
@ -306,7 +313,7 @@ defmodule Cannery.Ammo do
def get_used_count(%AmmoGroup{} = ammo_group) do
ammo_group
|> Repo.preload(:shot_groups)
|> Map.get(:shot_groups)
|> Map.fetch!(:shot_groups)
|> Enum.map(fn %{count: count} -> count end)
|> Enum.sum()
end
@ -327,36 +334,83 @@ defmodule Cannery.Ammo do
end
@doc """
Creates a ammo_group.
Creates multiple ammo_groups at once.
## Examples
iex> create_ammo_group(%{field: value}, %User{id: 123})
{:ok, %AmmoGroup{}}
iex> create_ammo_groups(%{field: value}, 3, %User{id: 123})
{:ok, {3, [%AmmoGroup{}]}}
iex> create_ammo_group(%{field: bad_value}, %User{id: 123})
iex> create_ammo_groups(%{field: bad_value}, 3, %User{id: 123})
{:error, %Changeset{}}
"""
@spec create_ammo_group(attrs :: map(), User.t()) ::
{:ok, AmmoGroup.t()} | {:error, Changeset.t(AmmoGroup.new_ammo_group())}
def create_ammo_group(
@spec create_ammo_groups(attrs :: map(), multiplier :: non_neg_integer(), User.t()) ::
{:ok, {count :: non_neg_integer(), [AmmoGroup.t()] | nil}}
| {:error, Changeset.t(AmmoGroup.new_ammo_group())}
def create_ammo_groups(
%{"ammo_type_id" => ammo_type_id, "container_id" => container_id} = attrs,
%User{id: user_id} = user
) do
# validate ammo type and container ids belong to user
_valid_ammo_type = get_ammo_type!(ammo_type_id, user)
_valid_container = Containers.get_container!(container_id, user)
multiplier,
%User{} = user
)
when multiplier >= 1 and multiplier <= @ammo_group_create_limit and
not (ammo_type_id |> is_nil()) and not (container_id |> is_nil()) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)
changesets =
Enum.map(1..multiplier, fn _count ->
%AmmoGroup{}
|> AmmoGroup.create_changeset(attrs |> Map.put("user_id", user_id))
|> Repo.insert()
|> AmmoGroup.create_changeset(
get_ammo_type!(ammo_type_id, user),
Containers.get_container!(container_id, user),
user,
attrs
)
end)
if changesets |> Enum.all?(fn %{valid?: valid} -> valid end) do
{count, inserted_ammo_groups} =
Repo.insert_all(
AmmoGroup,
changesets
|> Enum.map(fn changeset ->
changeset
|> Map.get(:changes)
|> Map.merge(%{inserted_at: now, updated_at: now})
end),
returning: true
)
{:ok, {count, inserted_ammo_groups}}
else
changesets
|> Enum.reject(fn %{valid?: valid} -> valid end)
|> List.first()
|> Changeset.apply_action(:insert)
end
end
def create_ammo_group(invalid_attrs, _user) do
def create_ammo_groups(
%{"ammo_type_id" => ammo_type_id, "container_id" => container_id} = attrs,
_multiplier,
user
)
when not (ammo_type_id |> is_nil()) and not (container_id |> is_nil()) do
changeset =
%AmmoGroup{}
|> AmmoGroup.create_changeset(invalid_attrs |> Map.put("user_id", "-1"))
|> Repo.insert()
|> AmmoGroup.create_changeset(
get_ammo_type!(ammo_type_id, user),
Containers.get_container!(container_id, user),
user,
attrs
)
|> Changeset.add_error(:multiplier, dgettext("errors", "Invalid multiplier"))
{:error, changeset}
end
def create_ammo_groups(invalid_attrs, _multiplier, user) do
{:error, %AmmoGroup{} |> AmmoGroup.create_changeset(nil, nil, user, invalid_attrs)}
end
@doc """
@ -405,18 +459,4 @@ defmodule Cannery.Ammo do
@spec delete_ammo_group!(AmmoGroup.t(), User.t()) :: AmmoGroup.t()
def delete_ammo_group!(%AmmoGroup{user_id: user_id} = ammo_group, %User{id: user_id}),
do: ammo_group |> Repo.delete!()
@doc """
Returns an `%Changeset{}` for tracking ammo_group changes.
## Examples
iex> change_ammo_group(ammo_group)
%Changeset{data: %AmmoGroup{}}
"""
@spec change_ammo_group(AmmoGroup.t()) :: Changeset.t(AmmoGroup.t())
@spec change_ammo_group(AmmoGroup.t(), attrs :: map()) :: Changeset.t(AmmoGroup.t())
def change_ammo_group(%AmmoGroup{} = ammo_group, attrs \\ %{}),
do: AmmoGroup.update_changeset(ammo_group, attrs)
end

View File

@ -7,6 +7,7 @@ defmodule Cannery.Ammo.AmmoGroup do
"""
use Ecto.Schema
import CanneryWeb.Gettext
import Ecto.Changeset
alias Cannery.Ammo.{AmmoGroup, AmmoType}
alias Cannery.{Accounts.User, ActivityLog.ShotGroup, Containers.Container}
@ -48,22 +49,49 @@ defmodule Cannery.Ammo.AmmoGroup do
@type id :: UUID.t()
@doc false
@spec create_changeset(new_ammo_group(), attrs :: map()) :: Changeset.t(new_ammo_group())
def create_changeset(ammo_group, attrs) do
@spec create_changeset(
new_ammo_group(),
AmmoType.t() | nil,
Container.t() | nil,
User.t(),
attrs :: map()
) :: Changeset.t(new_ammo_group())
def create_changeset(
ammo_group,
%AmmoType{id: ammo_type_id},
%Container{id: container_id, user_id: user_id},
%User{id: user_id},
attrs
)
when not (ammo_type_id |> is_nil()) and not (container_id |> is_nil()) and
not (user_id |> is_nil()) do
ammo_group
|> cast(attrs, [:count, :price_paid, :notes, :staged, :ammo_type_id, :container_id, :user_id])
|> change(ammo_type_id: ammo_type_id)
|> change(user_id: user_id)
|> change(container_id: container_id)
|> cast(attrs, [:count, :price_paid, :notes, :staged])
|> validate_number(:count, greater_than: 0)
|> validate_required([:count, :staged, :ammo_type_id, :container_id, :user_id])
end
@doc """
Invalid changeset, used to prompt user to select ammo type and container
"""
def create_changeset(ammo_group, _invalid_ammo_type, _invalid_container, _invalid_user, attrs) do
ammo_group
|> cast(attrs, [:ammo_type_id, :container_id])
|> validate_required([:ammo_type_id, :container_id])
|> add_error(:invalid, dgettext("errors", "Please select an ammo type and container"))
end
@doc false
@spec update_changeset(t() | new_ammo_group(), attrs :: map()) ::
Changeset.t(t() | new_ammo_group())
def update_changeset(ammo_group, attrs) do
ammo_group
|> cast(attrs, [:count, :price_paid, :notes, :staged, :ammo_type_id, :container_id])
|> validate_number(:count, greater_than: 0)
|> validate_required([:count, :staged, :ammo_type_id, :container_id, :user_id])
|> cast(attrs, [:count, :price_paid, :notes, :staged])
|> validate_number(:count, greater_than_or_equal_to: 0)
|> validate_required([:count, :staged])
end
@doc """
@ -75,6 +103,6 @@ defmodule Cannery.Ammo.AmmoGroup do
def range_changeset(ammo_group, attrs) do
ammo_group
|> cast(attrs, [:count, :staged])
|> validate_required([:count, :staged, :ammo_type_id, :container_id, :user_id])
|> validate_required([:count, :staged])
end
end

View File

@ -31,10 +31,10 @@ defmodule Cannery.Ammo.AmmoType do
field :pressure, :string
field :primer_type, :string
field :firing_type, :string
field :tracer, :boolean, null: false, default: false
field :incendiary, :boolean, null: false, default: false
field :blank, :boolean, null: false, default: false
field :corrosive, :boolean, null: false, default: false
field :tracer, :boolean, default: false
field :incendiary, :boolean, default: false
field :blank, :boolean, default: false
field :corrosive, :boolean, default: false
field :manufacturer, :string
field :upc, :string
@ -105,10 +105,12 @@ defmodule Cannery.Ammo.AmmoType do
]
@doc false
@spec create_changeset(new_ammo_type(), attrs :: map()) :: Changeset.t(new_ammo_type())
def create_changeset(ammo_type, attrs) do
@spec create_changeset(new_ammo_type(), User.t(), attrs :: map()) ::
Changeset.t(new_ammo_type())
def create_changeset(ammo_type, %User{id: user_id}, attrs) do
ammo_type
|> cast(attrs, [:user_id | changeset_fields()])
|> change(user_id: user_id)
|> cast(attrs, changeset_fields())
|> validate_required([:name, :user_id])
end
@ -118,6 +120,6 @@ defmodule Cannery.Ammo.AmmoType do
def update_changeset(ammo_type, attrs) do
ammo_type
|> cast(attrs, changeset_fields())
|> validate_required([:name, :user_id])
|> validate_required(:name)
end
end

View File

@ -30,6 +30,25 @@ defmodule Cannery.Containers do
)
end
@doc """
Returns a count of containers.
## Examples
iex> get_containers_count!(%User{id: 123})
3
"""
@spec get_containers_count!(User.t()) :: integer()
def get_containers_count!(%User{id: user_id}) do
Repo.one(
from c in Container,
where: c.user_id == ^user_id,
select: count(c.id),
distinct: true
)
end
@doc """
Gets a single container.
@ -71,9 +90,8 @@ defmodule Cannery.Containers do
"""
@spec create_container(attrs :: map(), User.t()) ::
{:ok, Container.t()} | {:error, Changeset.t(Container.new_container())}
def create_container(attrs, %User{id: user_id}) do
attrs = attrs |> Map.put("user_id", user_id)
%Container{} |> Container.create_changeset(attrs) |> Repo.insert()
def create_container(attrs, %User{} = user) do
%Container{} |> Container.create_changeset(user, attrs) |> Repo.insert()
end
@doc """
@ -122,7 +140,7 @@ defmodule Cannery.Containers do
error = dgettext("errors", "Container must be empty before deleting")
container
|> change_container()
|> Container.update_changeset(%{})
|> Changeset.add_error(:ammo_groups, error)
|> Changeset.apply_action(:delete)
end
@ -143,25 +161,6 @@ defmodule Cannery.Containers do
container
end
@doc """
Returns an `%Changeset{}` for tracking container changes.
## Examples
iex> change_container(container)
%Changeset{data: %Container{}}
iex> change_container(%Changeset{})
%Changeset{data: %Container{}}
"""
@spec change_container(Container.t() | Container.new_container()) ::
Changeset.t(Container.t() | Container.new_container())
@spec change_container(Container.t() | Container.new_container(), attrs :: map()) ::
Changeset.t(Container.t() | Container.new_container())
def change_container(container, attrs \\ %{}),
do: container |> Container.update_changeset(attrs)
@doc """
Adds a tag to a container
@ -173,14 +172,11 @@ defmodule Cannery.Containers do
"""
@spec add_tag!(Container.t(), Tag.t(), User.t()) :: ContainerTag.t()
def add_tag!(
%Container{id: container_id, user_id: user_id},
%Tag{id: tag_id, user_id: user_id},
%Container{user_id: user_id} = container,
%Tag{user_id: user_id} = tag,
%User{id: user_id}
) do
%ContainerTag{}
|> ContainerTag.changeset(%{"container_id" => container_id, "tag_id" => tag_id})
|> Repo.insert!()
end
),
do: %ContainerTag{} |> ContainerTag.create_changeset(tag, container) |> Repo.insert!()
@doc """
Removes a tag from a container
@ -207,6 +203,18 @@ defmodule Cannery.Containers do
if count == 0, do: raise("could not delete container tag"), else: count
end
@doc """
Returns number of rounds in container. If data is already preloaded, then
there will be no db hit.
"""
@spec get_container_ammo_group_count!(Container.t()) :: non_neg_integer()
def get_container_ammo_group_count!(%Container{} = container) do
container
|> Repo.preload(:ammo_groups)
|> Map.fetch!(:ammo_groups)
|> Enum.count()
end
@doc """
Returns number of rounds in container. If data is already preloaded, then
there will be no db hit.
@ -215,7 +223,7 @@ defmodule Cannery.Containers do
def get_container_rounds!(%Container{} = container) do
container
|> Repo.preload(:ammo_groups)
|> Map.get(:ammo_groups)
|> Map.fetch!(:ammo_groups)
|> Enum.map(fn %{count: count} -> count end)
|> Enum.sum()
end

View File

@ -42,10 +42,12 @@ defmodule Cannery.Containers.Container do
@type id :: UUID.t()
@doc false
@spec create_changeset(new_container(), attrs :: map()) :: Changeset.t(new_container())
def create_changeset(container, attrs) do
@spec create_changeset(new_container(), User.t(), attrs :: map()) ::
Changeset.t(new_container())
def create_changeset(container, %User{id: user_id}, attrs) do
container
|> cast(attrs, [:name, :desc, :type, :location, :user_id])
|> change(user_id: user_id)
|> cast(attrs, [:name, :desc, :type, :location])
|> validate_required([:name, :type, :user_id])
end
@ -55,6 +57,6 @@ defmodule Cannery.Containers.Container do
def update_changeset(container, attrs) do
container
|> cast(attrs, [:name, :desc, :type, :location])
|> validate_required([:name, :type, :user_id])
|> validate_required([:name, :type])
end
end

View File

@ -31,10 +31,16 @@ defmodule Cannery.Containers.ContainerTag do
@type id :: UUID.t()
@doc false
@spec changeset(new_container_tag(), attrs :: map()) :: Changeset.t(new_container_tag())
def changeset(container_tag, attrs) do
@spec create_changeset(new_container_tag(), Tag.t(), Container.t()) ::
Changeset.t(new_container_tag())
def create_changeset(
container_tag,
%Tag{id: tag_id, user_id: user_id},
%Container{id: container_id, user_id: user_id}
) do
container_tag
|> cast(attrs, [:tag_id, :container_id])
|> change(tag_id: tag_id)
|> change(container_id: container_id)
|> validate_required([:tag_id, :container_id])
end
end

View File

@ -100,15 +100,13 @@ defmodule Cannery.Invites do
"""
@spec create_invite(User.t(), attrs :: map()) ::
{:ok, Invite.t()} | {:error, Changeset.t(Invite.new_invite())}
def create_invite(%User{id: user_id, role: :admin}, attrs) do
def create_invite(%User{role: :admin} = user, attrs) do
token =
:crypto.strong_rand_bytes(@invite_token_length)
|> Base.url_encode64()
|> binary_part(0, @invite_token_length)
attrs = attrs |> Map.merge(%{"user_id" => user_id, "token" => token})
%Invite{} |> Invite.create_changeset(attrs) |> Repo.insert()
%Invite{} |> Invite.create_changeset(user, token, attrs) |> Repo.insert()
end
@doc """
@ -155,19 +153,4 @@ defmodule Cannery.Invites do
"""
@spec delete_invite!(Invite.t(), User.t()) :: Invite.t()
def delete_invite!(invite, %User{role: :admin}), do: invite |> Repo.delete!()
@doc """
Returns an `%Changeset{}` for tracking invite changes.
## Examples
iex> change_invite(invite)
%Changeset{data: %Invite{}}
"""
@spec change_invite(Invite.t() | Invite.new_invite()) ::
Changeset.t(Invite.t() | Invite.new_invite())
@spec change_invite(Invite.t() | Invite.new_invite(), attrs :: map()) ::
Changeset.t(Invite.t() | Invite.new_invite())
def change_invite(invite, attrs \\ %{}), do: invite |> Invite.update_changeset(attrs)
end

View File

@ -38,10 +38,12 @@ defmodule Cannery.Invites.Invite do
@type id :: UUID.t()
@doc false
@spec create_changeset(new_invite(), attrs :: map()) :: Changeset.t(new_invite())
def create_changeset(invite, attrs) do
@spec create_changeset(new_invite(), User.t(), token :: binary(), attrs :: map()) ::
Changeset.t(new_invite())
def create_changeset(invite, %User{id: user_id}, token, attrs) do
invite
|> cast(attrs, [:name, :token, :uses_left, :disabled_at, :user_id])
|> change(token: token, user_id: user_id)
|> cast(attrs, [:name, :uses_left, :disabled_at])
|> validate_required([:name, :token, :user_id])
|> validate_number(:uses_left, greater_than_or_equal_to: 0)
end
@ -51,7 +53,7 @@ defmodule Cannery.Invites.Invite do
def update_changeset(invite, attrs) do
invite
|> cast(attrs, [:name, :uses_left, :disabled_at])
|> validate_required([:name, :token, :user_id])
|> validate_required([:name])
|> validate_number(:uses_left, greater_than_or_equal_to: 0)
end
end

View File

@ -9,7 +9,7 @@ defmodule Cannery.Release do
def rollback(repo, version) do
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
{:ok, _fun, _opts} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end
defp load_app do
@ -20,7 +20,7 @@ defmodule Cannery.Release do
load_app()
for repo <- Application.fetch_env!(@app, :ecto_repos) do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
{:ok, _fun, _opts} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end
end

View File

@ -6,11 +6,11 @@ defmodule Cannery.Repo.Migrator do
use GenServer
require Logger
def start_link(_) do
def start_link(_opts) do
GenServer.start_link(__MODULE__, [], [])
end
def init(_) do
def init(_opts) do
migrate!()
{:ok, nil}
end

View File

@ -74,8 +74,8 @@ defmodule Cannery.Tags do
"""
@spec create_tag(attrs :: map(), User.t()) ::
{:ok, Tag.t()} | {:error, Changeset.t(Tag.new_tag())}
def create_tag(attrs, %User{id: user_id}),
do: %Tag{} |> Tag.create_changeset(attrs |> Map.put("user_id", user_id)) |> Repo.insert()
def create_tag(attrs, %User{} = user),
do: %Tag{} |> Tag.create_changeset(user, attrs) |> Repo.insert()
@doc """
Updates a tag.
@ -121,20 +121,6 @@ defmodule Cannery.Tags do
@spec delete_tag!(Tag.t(), User.t()) :: Tag.t()
def delete_tag!(%Tag{user_id: user_id} = tag, %User{id: user_id}), do: tag |> Repo.delete!()
@doc """
Returns an `%Changeset{}` for tracking tag changes.
## Examples
iex> change_tag(tag)
%Changeset{data: %Tag{}}
"""
@spec change_tag(Tag.t() | Tag.new_tag()) :: Changeset.t(Tag.t() | Tag.new_tag())
@spec change_tag(Tag.t() | Tag.new_tag(), attrs :: map()) ::
Changeset.t(Tag.t() | Tag.new_tag())
def change_tag(tag, attrs \\ %{}), do: Tag.update_changeset(tag, attrs)
@doc """
Get a random tag bg_color in `#ffffff` hex format

View File

@ -35,10 +35,11 @@ defmodule Cannery.Tags.Tag do
@type id() :: UUID.t()
@doc false
@spec create_changeset(new_tag(), attrs :: map()) :: Changeset.t(new_tag())
def create_changeset(tag, attrs) do
@spec create_changeset(new_tag(), User.t(), attrs :: map()) :: Changeset.t(new_tag())
def create_changeset(tag, %User{id: user_id}, attrs) do
tag
|> cast(attrs, [:name, :bg_color, :text_color, :user_id])
|> change(user_id: user_id)
|> cast(attrs, [:name, :bg_color, :text_color])
|> validate_required([:name, :bg_color, :text_color, :user_id])
end
@ -47,6 +48,6 @@ defmodule Cannery.Tags.Tag do
def update_changeset(tag, attrs) do
tag
|> cast(attrs, [:name, :bg_color, :text_color])
|> validate_required([:name, :bg_color, :text_color, :user_id])
|> validate_required([:name, :bg_color, :text_color])
end
end

View File

@ -47,6 +47,7 @@ defmodule CanneryWeb do
use Phoenix.LiveView,
layout: {CanneryWeb.LayoutView, "live.html"}
on_mount CanneryWeb.InitAssigns
unquote(view_helpers())
end
end
@ -71,6 +72,7 @@ defmodule CanneryWeb do
quote do
use Phoenix.Router
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
@ -79,7 +81,9 @@ defmodule CanneryWeb do
def channel do
quote do
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
use Phoenix.Channel
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import CanneryWeb.Gettext
end
end
@ -87,14 +91,18 @@ defmodule CanneryWeb do
defp view_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
use Phoenix.HTML
# Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc)
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import Phoenix.LiveView.Helpers
# Import basic rendering functionality (render, render_layout, etc)
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import Phoenix.View
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
import CanneryWeb.{ErrorHelpers, Gettext, LiveHelpers, ViewHelpers}
alias CanneryWeb.Router.Helpers, as: Routes
end

View File

@ -16,9 +16,10 @@ defmodule CanneryWeb.Components.AddShotGroupComponent do
},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{ammo_group: _ammo_group, current_user: _current_user} = assigns, socket) do
def update(%{ammo_group: ammo_group, current_user: current_user} = assigns, socket) do
changeset =
%ShotGroup{date: NaiveDateTime.utc_now(), count: 1} |> ActivityLog.change_shot_group()
%ShotGroup{date: NaiveDateTime.utc_now(), count: 1}
|> ShotGroup.create_changeset(current_user, ammo_group, %{})
{:ok, socket |> assign(assigns) |> assign(:changeset, changeset)}
end
@ -27,21 +28,13 @@ defmodule CanneryWeb.Components.AddShotGroupComponent do
def handle_event(
"validate",
%{"shot_group" => shot_group_params},
%{
assigns: %{
ammo_group: %AmmoGroup{id: ammo_group_id} = ammo_group,
current_user: %User{id: user_id}
}
} = socket
%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket
) do
shot_group_params =
shot_group_params
|> process_params(ammo_group)
|> Map.merge(%{"ammo_group_id" => ammo_group_id, "user_id" => user_id})
params = shot_group_params |> process_params(ammo_group)
changeset =
%ShotGroup{}
|> ActivityLog.change_shot_group(shot_group_params)
|> ShotGroup.create_changeset(current_user, ammo_group, params)
|> Map.put(:action, :validate)
{:noreply, socket |> assign(:changeset, changeset)}
@ -51,17 +44,12 @@ defmodule CanneryWeb.Components.AddShotGroupComponent do
"save",
%{"shot_group" => shot_group_params},
%{
assigns: %{
ammo_group: %{id: ammo_group_id} = ammo_group,
current_user: %{id: user_id} = current_user,
return_to: return_to
}
assigns: %{ammo_group: ammo_group, current_user: current_user, return_to: return_to}
} = socket
) do
socket =
shot_group_params
|> process_params(ammo_group)
|> Map.merge(%{"ammo_group_id" => ammo_group_id, "user_id" => user_id})
|> ActivityLog.create_shot_group(current_user, ammo_group)
|> case do
{:ok, _shot_group} ->

View File

@ -7,7 +7,7 @@
let={f}
for={@changeset}
id="shot-group-form"
class="flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
@ -36,7 +36,11 @@
<%= error_tag(f, :notes, "col-span-3") %>
<%= label(f, :date, gettext("Date (UTC)"), class: "title text-lg text-primary-600") %>
<%= date_input(f, :date, class: "input input-primary col-span-2") %>
<%= date_input(f, :date,
class: "input input-primary col-span-2",
phx_update: "ignore",
value: Date.utc_today()
) %>
<%= error_tag(f, :notes, "col-span-3") %>
<%= submit(dgettext("actions", "Save"),

View File

@ -37,6 +37,11 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
</span>
<% end %>
<span class="rounded-lg title text-lg">
<%= gettext("Added on:") %>
<%= @ammo_group.inserted_at |> display_datetime() %>
</span>
<%= if @ammo_group.price_paid do %>
<span class="rounded-lg title text-lg">
<%= gettext("Price paid:") %>

View File

@ -14,11 +14,11 @@ defmodule CanneryWeb.Components.ContainerCard do
~H"""
<div
id={"container-#{@container.id}"}
class="mx-4 my-2 px-8 py-4 flex flex-col justify-center items-center space-y-4
class="overflow-hidden max-w-full mx-4 my-2 px-8 py-4 flex flex-col justify-center items-center space-y-4
border border-gray-400 rounded-lg shadow-lg hover:shadow-md
transition-all duration-300 ease-in-out"
>
<div class="mb-4 flex flex-col justify-center items-center space-y-2">
<div class="max-w-full mb-4 flex flex-col justify-center items-center space-y-2">
<%= live_redirect to: Routes.container_show_path(Endpoint, :show, @container),
class: "link" do %>
<h1 class="px-4 py-2 rounded-lg title text-xl">
@ -45,7 +45,12 @@ defmodule CanneryWeb.Components.ContainerCard do
</span>
<% end %>
<%= if @container.ammo_groups do %>
<%= unless @container.ammo_groups |> Enum.empty?() do %>
<span class="rounded-lg title text-lg">
<%= gettext("Packs:") %>
<%= @container |> Containers.get_container_ammo_group_count!() %>
</span>
<span class="rounded-lg title text-lg">
<%= gettext("Rounds:") %>
<%= @container |> Containers.get_container_rounds!() %>

View File

@ -8,11 +8,9 @@ defmodule CanneryWeb.Components.InviteCard do
def invite_card(assigns) do
~H"""
<div
class="mx-4 my-2 px-8 py-4 flex flex-col justify-center items-center space-y-4
<div class="mx-4 my-2 px-8 py-4 flex flex-col justify-center items-center space-y-4
border border-gray-400 rounded-lg shadow-lg hover:shadow-md
transition-all duration-300 ease-in-out"
>
transition-all duration-300 ease-in-out">
<h1 class="title text-xl">
<%= @invite.name %>
</h1>

View File

@ -4,7 +4,8 @@ defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
"""
use CanneryWeb, :live_component
alias Cannery.{Accounts.User, Ammo, Ammo.AmmoGroup, Containers}
alias Cannery.{Accounts.User, Ammo, Ammo.AmmoGroup, Containers, Containers.Container}
alias CanneryWeb.Endpoint
alias Phoenix.LiveView.Socket
@impl true
@ -21,13 +22,18 @@ defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
assigns,
socket
) do
changeset = Ammo.change_ammo_group(ammo_group)
changeset = ammo_group |> AmmoGroup.update_changeset(%{})
containers =
Containers.list_containers(current_user)
|> Enum.reject(fn %{id: id} -> id == container_id end)
{:ok, socket |> assign(assigns) |> assign(changeset: changeset, containers: containers)}
socket =
socket
|> assign(assigns)
|> assign(changeset: changeset, containers: containers)
{:ok, socket}
end
@impl true
@ -54,4 +60,76 @@ defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
{:noreply, socket}
end
@impl true
def render(%{containers: containers} = assigns) do
columns = [
%{label: gettext("Container"), key: "name"},
%{label: gettext("Type"), key: "type"},
%{label: gettext("Location"), key: "location"},
%{label: nil, key: "actions", sortable: false}
]
rows = containers |> get_rows_for_containers(assigns, columns)
assigns = assigns |> Map.merge(%{columns: columns, rows: rows})
~H"""
<div class="w-full flex flex-col space-y-8 justify-center items-center">
<h2 class="mb-8 text-center title text-xl text-primary-600">
<%= gettext("Move ammo") %>
</h2>
<%= if @containers |> Enum.empty?() do %>
<h2 class="title text-xl text-primary-600">
<%= gettext("No other containers") %>
<%= display_emoji("😔") %>
</h2>
<%= live_patch(dgettext("actions", "Add another container!"),
to: Routes.container_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<% else %>
<.live_component
module={CanneryWeb.Components.TableComponent}
id="move_ammo_group_table"
columns={@columns}
rows={@rows}
/>
<% end %>
</div>
"""
end
@spec get_rows_for_containers([Container.t()], map(), [map()]) :: [map()]
defp get_rows_for_containers(containers, assigns, columns) do
containers
|> Enum.map(fn container ->
columns
|> Enum.into(%{}, fn %{key: key} -> {key, get_row_value_by_key(key, container, assigns)} end)
end)
end
@spec get_row_value_by_key(String.t(), Container.t(), map()) :: any()
defp get_row_value_by_key("actions", container, assigns) do
assigns = assigns |> Map.put(:container, container)
~H"""
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<button
type="button"
class="btn btn-primary"
phx-click="move"
phx-target={@myself}
phx-value-container_id={container.id}
>
<%= dgettext("actions", "Select") %>
</button>
</div>
"""
end
defp get_row_value_by_key(key, container, _assigns),
do: container |> Map.get(key |> String.to_existing_atom())
end

View File

@ -1,70 +0,0 @@
<div class="w-full flex flex-col space-y-8 justify-center items-center">
<h2 class="mb-8 text-center title text-xl text-primary-600">
<%= gettext("Move ammo") %>
</h2>
<%= if @containers |> Enum.empty?() do %>
<h2 class="title text-xl text-primary-600">
<%= gettext("No other containers") %>
<%= display_emoji("😔") %>
</h2>
<%= live_patch(dgettext("actions", "Add another container!"),
to: Routes.container_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<% else %>
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
<table class="min-w-full table-auto text-center bg-white">
<thead class="border-b border-primary-600">
<tr>
<th class="p-2">
<%= gettext("Container") %>
</th>
<th class="p-2">
<%= gettext("Type") %>
</th>
<th class="p-2">
<%= gettext("Location") %>
</th>
<th class="p-2"></th>
</tr>
</thead>
<tbody id="containers">
<%= for container <- @containers do %>
<tr id={"container-#{container.id}"}>
<td class="p-2">
<%= container.name %>
</td>
<td class="p-2">
<%= container.type %>
</td>
<td class="p-2">
<%= container.location %>
</td>
<td class="p-2">
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<button
type="button"
class="btn btn-primary"
phx-click="move"
phx-target={@myself}
phx-value-container_id={container.id}
>
<%= dgettext("actions", "Select") %>
</button>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
</div>

View File

@ -0,0 +1,87 @@
defmodule CanneryWeb.Components.TableComponent do
@moduledoc """
Livecomponent that presents a resortable table
It takes the following required assigns:
- `:columns`: An array of maps containing the following keys
- `:label`: A gettext'd or otherwise user-facing string label for the
column. Can be nil
- `:key`: A string key used for sorting
- `:class`: Extra classes to be applied to the column element, if desired.
Optional
- `:sortable`: If false, will prevent the user from sorting with it.
Optional
- `:values`: An array of maps containing data for each row. Each map is
string-keyed with the associated column key to the following values:
- A single element, like string, integer or Phoenix.LiveView.Rendered
object, like returned from the ~H sigil
- A tuple, containing a custom value used for sorting, and the displayed
content.
"""
use CanneryWeb, :live_component
alias Phoenix.LiveView.Socket
@impl true
@spec update(
%{
required(:columns) =>
list(%{
required(:label) => String.t() | nil,
required(:key) => String.t() | nil,
optional(:class) => String.t(),
optional(:sortable) => false
}),
required(:rows) =>
list(%{
(key :: String.t()) => any() | {custom_sort_value :: String.t(), value :: any()}
}),
optional(any()) => any()
},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{columns: columns, rows: rows} = assigns, socket) do
initial_key = columns |> List.first() |> Map.get(:key)
rows = rows |> Enum.sort_by(fn row -> row |> Map.get(initial_key) end, :asc)
socket =
socket
|> assign(assigns)
|> assign(columns: columns, rows: rows, last_sort_key: initial_key, sort_mode: :asc)
{:ok, socket}
end
@impl true
def handle_event(
"sort_by",
%{"sort-key" => key},
%{assigns: %{rows: rows, last_sort_key: key, sort_mode: sort_mode}} = socket
) do
sort_mode = if sort_mode == :asc, do: :desc, else: :asc
rows = rows |> sort_by_custom_sort_value_or_value(key, sort_mode)
{:noreply, socket |> assign(sort_mode: sort_mode, rows: rows)}
end
def handle_event(
"sort_by",
%{"sort-key" => key},
%{assigns: %{rows: rows}} = socket
) do
rows = rows |> sort_by_custom_sort_value_or_value(key, :asc)
{:noreply, socket |> assign(last_sort_key: key, sort_mode: :asc, rows: rows)}
end
defp sort_by_custom_sort_value_or_value(rows, key, sort_mode) do
rows
|> Enum.sort_by(
fn row ->
case row |> Map.get(key) do
{custom_sort_key, _value} -> custom_sort_key
value -> value
end
end,
sort_mode
)
end
end

View File

@ -0,0 +1,52 @@
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
<table class="min-w-full table-auto text-center bg-white">
<thead class="border-b border-primary-600">
<tr>
<%= for %{key: key, label: label} = column <- @columns do %>
<%= if column |> Map.get(:sortable, true) do %>
<th class={"p-2 #{column[:class]}"}>
<span
class="cursor-pointer"
phx-click="sort_by"
phx-value-sort-key={key}
phx-target={@myself}
>
<span class="underline"><%= label %></span>
<%= if @last_sort_key == key do %>
<%= case @sort_mode do %>
<% :asc -> %>
<i class="fas fa-sm fa-chevron-down"></i>
<% :desc -> %>
<i class="fas fa-sm fa-chevron-up"></i>
<% end %>
<% else %>
<i class="fas fa-sm fa-chevron-up opacity-0"></i>
<% end %>
</span>
</th>
<% else %>
<th class={"p-2 #{column[:class]}"}>
<%= label %>
</th>
<% end %>
<% end %>
</tr>
</thead>
<tbody>
<%= for values <- @rows do %>
<tr>
<%= for %{key: key} = value <- @columns do %>
<td class={"p-2 #{value[:class]}"}>
<%= case values |> Map.get(key) do %>
<% {_custom_sort_value, value} -> %>
<%= value %>
<% value -> %>
<%= value %>
<% end %>
</td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
</div>

View File

@ -22,7 +22,7 @@ defmodule CanneryWeb.Components.TagCard do
def simple_tag_card(assigns) do
~H"""
<h1
class="mx-2 my-1 px-4 py-2 rounded-lg title text-xl"
class="inline-block break-all mx-2 my-1 px-4 py-2 rounded-lg title text-xl"
style={"color: #{@tag.text_color}; background-color: #{@tag.bg_color}"}
>
<%= @tag.name %>

View File

@ -16,10 +16,16 @@ defmodule CanneryWeb.Components.Topbar do
<nav role="navigation" class="mb-8 px-8 py-4 w-full bg-primary-400">
<div class="flex flex-col sm:flex-row justify-between items-center">
<div class="mb-4 sm:mb-0 sm:mr-8 flex flex-row justify-start items-center space-x-2">
<%= live_redirect("Cannery",
to: Routes.live_path(Endpoint, HomeLive),
class: "mx-2 my-1 leading-5 text-xl text-white hover:underline"
) %>
<%= live_redirect to: Routes.live_path(Endpoint, HomeLive),
class: "inline mx-2 my-1 leading-5 text-xl text-white"
do %>
<img
src={Routes.static_path(Endpoint, "/images/cannery.svg")}
alt={gettext("Cannery logo")}
class="inline-block h-8 mx-1"
/>
<h1 class="inline hover:underline">Cannery</h1>
<% end %>
<%= if @title_content do %>
<span class="mx-2 my-1">
@ -31,10 +37,8 @@ defmodule CanneryWeb.Components.Topbar do
<hr class="mb-2 sm:hidden hr-light" />
<ul
class="flex flex-row flex-wrap justify-center items-center
text-lg text-white text-ellipsis"
>
<ul class="flex flex-row flex-wrap justify-center items-center
text-lg text-white text-ellipsis">
<%= if @current_user do %>
<li class="mx-2 my-1">
<%= live_redirect(gettext("Tags"),
@ -49,13 +53,13 @@ defmodule CanneryWeb.Components.Topbar do
) %>
</li>
<li class="mx-2 my-1">
<%= live_redirect(gettext("Ammo"),
<%= live_redirect(gettext("Catalog"),
to: Routes.ammo_type_index_path(Endpoint, :index),
class: "text-primary-600 text-white hover:underline"
) %>
</li>
<li class="mx-2 my-1">
<%= live_redirect(gettext("Manage"),
<%= live_redirect(gettext("Ammo"),
to: Routes.ammo_group_index_path(Endpoint, :index),
class: "text-primary-600 text-white hover:underline"
) %>
@ -91,7 +95,7 @@ defmodule CanneryWeb.Components.Topbar do
<li class="mx-2 my-1">
<%= live_redirect to: Routes.live_dashboard_path(Endpoint, :home),
class: "text-primary-600 text-white hover:underline" do %>
<i class="fas fa-tachometer-alt"></i>
<i class="fas fa-gauge"></i>
<% end %>
</li>
<% end %>

View File

@ -9,7 +9,7 @@ defmodule CanneryWeb.Components.UserCard do
~H"""
<div
id={"user-#{@user.id}"}
class="mx-4 my-2 px-8 py-4 flex flex-col justify-center items-center
class="mx-4 my-2 px-8 py-4 flex flex-col justify-center items-center text-center
border border-gray-400 rounded-lg shadow-lg hover:shadow-md
transition-all duration-300 ease-in-out"
>
@ -18,11 +18,18 @@ defmodule CanneryWeb.Components.UserCard do
</h1>
<h3 class="px-4 py-2 rounded-lg title text-lg">
<p>
<%= if @user.confirmed_at |> is_nil() do %>
Email unconfirmed
<% else %>
User was confirmed at <%= @user.confirmed_at |> display_datetime() %>
<% end %>
</p>
<p>
<%= gettext("User registered on") %>
<%= @user.inserted_at |> display_datetime() %>
</p>
</h3>
<%= if @inner_block do %>

View File

@ -1,10 +1,11 @@
defmodule CanneryWeb.UserConfirmationController do
use CanneryWeb, :controller
import CanneryWeb.Gettext
alias Cannery.Accounts
def new(conn, _params) do
render(conn, "new.html")
render(conn, "new.html", page_title: gettext("Confirm your account"))
end
def create(conn, %{"user" => %{"email" => email}}) do

View File

@ -29,8 +29,11 @@ defmodule CanneryWeb.UserRegistrationController do
# renders new user registration page
defp render_new(conn, invite \\ nil) do
changeset = Accounts.change_user_registration(%User{})
conn |> render("new.html", changeset: changeset, invite: invite)
render(conn, "new.html",
changeset: Accounts.change_user_registration(%User{}),
invite: invite,
page_title: gettext("Register")
)
end
def create(conn, %{"user" => %{"invite_token" => invite_token}} = attrs) do

View File

@ -6,7 +6,7 @@ defmodule CanneryWeb.UserResetPasswordController do
plug :get_user_by_reset_password_token when action in [:edit, :update]
def new(conn, _params) do
render(conn, "new.html")
render(conn, "new.html", page_title: gettext("Forgot your password?"))
end
def create(conn, %{"user" => %{"email" => email}}) do
@ -31,7 +31,10 @@ defmodule CanneryWeb.UserResetPasswordController do
end
def edit(conn, _params) do
render(conn, "edit.html", changeset: Accounts.change_user_password(conn.assigns.user))
render(conn, "edit.html",
changeset: Accounts.change_user_password(conn.assigns.user),
page_title: gettext("Reset your password")
)
end
# Do not log in the user after reset password to avoid a

View File

@ -5,7 +5,7 @@ defmodule CanneryWeb.UserSessionController do
alias CanneryWeb.UserAuth
def new(conn, _params) do
render(conn, "new.html", error_message: nil)
render(conn, "new.html", error_message: nil, page_title: gettext("Log in"))
end
def create(conn, %{"user" => user_params}) do

View File

@ -1,19 +1,20 @@
defmodule CanneryWeb.UserSettingsController do
use CanneryWeb, :controller
import CanneryWeb.Gettext
alias Cannery.Accounts
alias CanneryWeb.{HomeLive, UserAuth}
plug :assign_email_and_password_changesets
def edit(conn, _params) do
render(conn, "edit.html")
render(conn, "edit.html", page_title: gettext("Settings"))
end
def update(conn, %{"action" => "update_email"} = params) do
%{"current_password" => password, "user" => user_params} = params
user = conn.assigns.current_user
def update(%{assigns: %{current_user: user}} = conn, %{
"action" => "update_email",
"current_password" => password,
"user" => user_params
}) do
case Accounts.apply_user_email(user, password, user_params) do
{:ok, applied_user} ->
Accounts.deliver_update_email_instructions(
@ -33,14 +34,15 @@ defmodule CanneryWeb.UserSettingsController do
|> redirect(to: Routes.user_settings_path(conn, :edit))
{:error, changeset} ->
render(conn, "edit.html", email_changeset: changeset)
conn |> render("edit.html", email_changeset: changeset)
end
end
def update(conn, %{"action" => "update_password"} = params) do
%{"current_password" => password, "user" => user_params} = params
user = conn.assigns.current_user
def update(%{assigns: %{current_user: user}} = conn, %{
"action" => "update_password",
"current_password" => password,
"user" => user_params
}) do
case Accounts.update_user_password(user, password, user_params) do
{:ok, user} ->
conn
@ -49,12 +51,27 @@ defmodule CanneryWeb.UserSettingsController do
|> UserAuth.log_in_user(user)
{:error, changeset} ->
render(conn, "edit.html", password_changeset: changeset)
conn |> render("edit.html", password_changeset: changeset)
end
end
def confirm_email(conn, %{"token" => token}) do
case Accounts.update_user_email(conn.assigns.current_user, token) do
def update(
%{assigns: %{current_user: user}} = conn,
%{"action" => "update_locale", "user" => %{"locale" => locale}}
) do
case Accounts.update_user_locale(user, locale) do
{:ok, _user} ->
conn
|> put_flash(:info, dgettext("prompts", "Language updated successfully."))
|> redirect(to: Routes.user_settings_path(conn, :edit))
{:error, changeset} ->
conn |> render("edit.html", locale_changeset: changeset)
end
end
def confirm_email(%{assigns: %{current_user: user}} = conn, %{"token" => token}) do
case Accounts.update_user_email(user, token) do
:ok ->
conn
|> put_flash(:info, dgettext("prompts", "Email changed successfully."))
@ -84,11 +101,10 @@ defmodule CanneryWeb.UserSettingsController do
end
end
defp assign_email_and_password_changesets(conn, _opts) do
user = conn.assigns.current_user
defp assign_email_and_password_changesets(%{assigns: %{current_user: user}} = conn, _opts) do
conn
|> assign(:email_changeset, Accounts.change_user_email(user))
|> assign(:password_changeset, Accounts.change_user_password(user))
|> assign(:locale_changeset, Accounts.change_user_locale(user))
end
end

View File

@ -9,6 +9,8 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
alias Ecto.Changeset
alias Phoenix.LiveView.Socket
@ammo_group_create_limit 10_000
@impl true
@spec update(
%{:ammo_group => AmmoGroup.t(), :current_user => User.t(), optional(any) => any},
@ -19,21 +21,30 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
end
@spec update(Socket.t()) :: {:ok, Socket.t()}
def update(%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket) do
changeset = Ammo.change_ammo_group(ammo_group)
containers = Containers.list_containers(current_user)
ammo_types = Ammo.list_ammo_types(current_user)
{:ok, socket |> assign(changeset: changeset, containers: containers, ammo_types: ammo_types)}
def update(%{assigns: %{current_user: current_user}} = socket) do
%{assigns: %{ammo_types: ammo_types, containers: containers}} =
socket =
socket
|> assign(:ammo_group_create_limit, @ammo_group_create_limit)
|> assign(:ammo_types, Ammo.list_ammo_types(current_user))
|> assign_new(:containers, fn -> Containers.list_containers(current_user) end)
params =
if ammo_types |> List.first() |> is_nil(),
do: %{},
else: %{} |> Map.put("ammo_type_id", ammo_types |> List.first() |> Map.get(:id))
params =
if containers |> List.first() |> is_nil(),
do: params,
else: params |> Map.put("container_id", containers |> List.first() |> Map.get(:id))
{:ok, socket |> assign_changeset(params)}
end
@impl true
def handle_event(
"validate",
%{"ammo_group" => ammo_group_params},
%{assigns: %{ammo_group: ammo_group}} = socket
) do
socket = socket |> assign(:changeset, ammo_group |> Ammo.change_ammo_group(ammo_group_params))
{:noreply, socket}
def handle_event("validate", %{"ammo_group" => ammo_group_params}, socket) do
{:noreply, socket |> assign_changeset(ammo_group_params)}
end
def handle_event(
@ -57,6 +68,44 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
# Save Helpers
defp assign_changeset(
%{assigns: %{action: action, ammo_group: ammo_group, current_user: user}} = socket,
ammo_group_params
) do
changeset_action =
case action do
:new -> :insert
:edit -> :update
end
changeset =
case action do
:new ->
ammo_type =
if ammo_group_params |> Map.has_key?("ammo_type_id"),
do: ammo_group_params |> Map.get("ammo_type_id") |> Ammo.get_ammo_type!(user),
else: nil
container =
if ammo_group_params |> Map.has_key?("container_id"),
do: ammo_group_params |> Map.get("container_id") |> Containers.get_container!(user),
else: nil
ammo_group |> AmmoGroup.create_changeset(ammo_type, container, user, ammo_group_params)
:edit ->
ammo_group |> AmmoGroup.update_changeset(ammo_group_params)
end
changeset =
case changeset |> Changeset.apply_action(changeset_action) do
{:ok, _data} -> changeset
{:error, changeset} -> changeset
end
socket |> assign(:changeset, changeset)
end
defp save_ammo_group(
%{assigns: %{ammo_group: ammo_group, current_user: current_user, return_to: return_to}} =
socket,
@ -66,7 +115,7 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
socket =
case Ammo.update_ammo_group(ammo_group, ammo_group_params, current_user) do
{:ok, _ammo_group} ->
prompt = dgettext("prompts", "Ammo group updated successfully")
prompt = dgettext("prompts", "Ammo updated successfully")
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
{:error, %Changeset{} = changeset} ->
@ -77,20 +126,65 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
end
defp save_ammo_group(
%{assigns: %{current_user: current_user, return_to: return_to}} = socket,
%{assigns: %{changeset: changeset}} = socket,
:new,
ammo_group_params
%{"multiplier" => multiplier_str} = ammo_group_params
) do
socket =
case Ammo.create_ammo_group(ammo_group_params, current_user) do
{:ok, _ammo_group} ->
prompt = dgettext("prompts", "Ammo group created successfully")
case multiplier_str |> Integer.parse() do
{multiplier, _remainder}
when multiplier >= 1 and multiplier <= @ammo_group_create_limit ->
socket |> create_multiple(ammo_group_params, multiplier)
{multiplier, _remainder} ->
error_msg =
dgettext(
"errors",
"Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}",
max: @ammo_group_create_limit,
multiplier: multiplier
)
{:error, changeset} =
changeset
|> Changeset.add_error(:multiplier, error_msg)
|> Changeset.apply_action(:insert)
socket |> assign(:changeset, changeset)
:error ->
error_msg = dgettext("errors", "Could not parse number of copies")
{:error, changeset} =
changeset
|> Changeset.add_error(:multiplier, error_msg)
|> Changeset.apply_action(:insert)
socket |> assign(:changeset, changeset)
end
{:noreply, socket}
end
defp create_multiple(
%{assigns: %{current_user: current_user, return_to: return_to}} = socket,
ammo_group_params,
multiplier
) do
case Ammo.create_ammo_groups(ammo_group_params, multiplier, current_user) do
{:ok, {count, _ammo_groups}} ->
prompt =
dngettext(
"prompts",
"Ammo added successfully",
"Ammo added successfully",
count
)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(changeset: changeset)
end
{:noreply, socket}
end
end

View File

@ -10,7 +10,7 @@
phx-target={@myself}
phx-change="validate"
phx-submit="save"
class="flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<%= if @changeset.action && not @changeset.valid? do %>
<div class="invalid-feedback col-span-3 text-center">
@ -18,42 +18,62 @@
</div>
<% end %>
<%= label(f, :ammo_type_id, gettext("Ammo type"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :ammo_type_id, gettext("Ammo type"), class: "title text-lg text-primary-600") %>
<%= select(f, :ammo_type_id, ammo_type_options(@ammo_types),
class: "text-center col-span-2 input input-primary"
) %>
<%= error_tag(f, :ammo_type_id, "col-span-3 text-center") %>
<%= label(f, :count, gettext("Count"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :count, gettext("Count"), class: "title text-lg text-primary-600") %>
<%= number_input(f, :count,
class: "text-center col-span-2 input input-primary",
min: 1
min: 0
) %>
<%= error_tag(f, :count, "col-span-3 text-center") %>
<%= label(f, :price_paid, gettext("Price paid"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :price_paid, gettext("Price paid"), class: "title text-lg text-primary-600") %>
<%= number_input(f, :price_paid,
step: "0.01",
step: 0.01,
class: "text-center col-span-2 input input-primary"
) %>
<%= error_tag(f, :price_paid, "col-span-3 text-center") %>
<%= label(f, :notes, gettext("Notes"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :notes, gettext("Notes"), class: "title text-lg text-primary-600") %>
<%= textarea(f, :notes,
class: "text-center col-span-2 input input-primary",
phx_hook: "MaintainAttrs"
) %>
<%= error_tag(f, :notes, "col-span-3 text-center") %>
<%= label(f, :container, gettext("Container"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :container, gettext("Container"), class: "title text-lg text-primary-600") %>
<%= select(f, :container_id, container_options(@containers),
class: "text-center col-span-2 input input-primary"
) %>
<%= error_tag(f, :container_id, "col-span-3 text-center") %>
<%= case @action do %>
<% :new -> %>
<hr class="hr col-span-3" />
<%= label(f, :multiplier, gettext("Copies"), class: "title text-lg text-primary-600") %>
<%= number_input(f, :multiplier,
max: @ammo_group_create_limit,
class: "text-center input input-primary",
value: 1,
phx_update: "ignore"
) %>
<%= submit(dgettext("actions", "Create"),
phx_disable_with: dgettext("prompts", "Creating..."),
class: "mx-auto btn btn-primary"
) %>
<%= error_tag(f, :multiplier, "col-span-3 text-center") %>
<% :edit -> %>
<%= submit(dgettext("actions", "Save"),
phx_disable_with: dgettext("prompts", "Saving..."),
class: "mx-auto col-span-3 btn btn-primary"
) %>
<% end %>
</.form>
</div>

View File

@ -4,12 +4,12 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
"""
use CanneryWeb, :live_view
alias Cannery.{Ammo, Ammo.AmmoGroup, Repo}
alias Cannery.{Ammo, Ammo.AmmoGroup, Containers, Repo}
alias CanneryWeb.Endpoint
@impl true
def mount(_params, session, socket) do
{:ok, socket |> assign_defaults(session) |> display_ammo_groups()}
def mount(_params, _session, socket) do
{:ok, socket |> display_ammo_groups()}
end
@impl true
@ -17,9 +17,11 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
{:noreply, apply_action(socket, live_action, params)}
end
defp apply_action(%{assigns: %{current_user: current_user}} = socket, :add_shot_group, %{
"id" => id
}) do
defp apply_action(
%{assigns: %{current_user: current_user}} = socket,
:add_shot_group,
%{"id" => id}
) do
socket
|> assign(:page_title, gettext("Record shots"))
|> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user))
@ -72,6 +74,138 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do
ammo_groups = Ammo.list_ammo_groups(current_user) |> Repo.preload([:ammo_type, :container])
socket |> assign(:ammo_groups, ammo_groups)
ammo_types_count = Ammo.get_ammo_types_count!(current_user)
containers_count = Containers.get_containers_count!(current_user)
columns = [
%{label: gettext("Ammo type"), key: "ammo_type"},
%{label: gettext("Count"), key: "count"},
%{label: gettext("Price paid"), key: "price_paid"},
%{label: gettext("% left"), key: "remaining"},
%{label: gettext("Range"), key: "range"},
%{label: gettext("Container"), key: "container"},
%{label: gettext("Added on"), key: "added_on"},
%{label: nil, key: "actions", sortable: false}
]
rows =
ammo_groups
|> Enum.map(fn ammo_group -> ammo_group |> get_row_data_for_ammo_group(columns) end)
socket
|> assign(
ammo_groups: ammo_groups,
ammo_types_count: ammo_types_count,
containers_count: containers_count,
columns: columns,
rows: rows
)
end
@spec get_row_data_for_ammo_group(AmmoGroup.t(), [map()]) :: [map()]
defp get_row_data_for_ammo_group(ammo_group, columns) do
ammo_group = ammo_group |> Repo.preload([:ammo_type, :container])
columns
|> Enum.into(%{}, fn %{key: key} -> {key, get_value_for_key(key, ammo_group)} end)
end
@spec get_value_for_key(String.t(), AmmoGroup.t()) :: any()
defp get_value_for_key("ammo_type", %{ammo_type: ammo_type}) do
{ammo_type.name,
live_patch(ammo_type.name,
to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
class: "link"
)}
end
defp get_value_for_key("price_paid", %{price_paid: nil}), do: {"a", nil}
defp get_value_for_key("price_paid", %{price_paid: price_paid}),
do: gettext("$%{amount}", amount: price_paid |> :erlang.float_to_binary(decimals: 2))
defp get_value_for_key("added_on", %{inserted_at: inserted_at}) do
assigns = %{inserted_at: inserted_at}
{inserted_at,
~H"""
<%= @inserted_at |> display_datetime() %>
"""}
end
defp get_value_for_key("range", %{staged: staged} = ammo_group) do
assigns = %{ammo_group: ammo_group}
{staged,
~H"""
<div class="min-w-20 py-2 px-4 h-full flex flex-col justify-center items-center">
<button
type="button"
class="mx-2 my-1 btn btn-primary"
phx-click="toggle_staged"
phx-value-ammo_group_id={ammo_group.id}
>
<%= if ammo_group.staged, do: gettext("Unstage"), else: gettext("Stage") %>
</button>
<%= live_patch(dgettext("actions", "Record shots"),
to: Routes.ammo_group_index_path(Endpoint, :add_shot_group, ammo_group),
class: "mx-2 my-1 btn btn-primary"
) %>
</div>
"""}
end
defp get_value_for_key("remaining", ammo_group),
do: "#{ammo_group |> Ammo.get_percentage_remaining()}%"
defp get_value_for_key("actions", ammo_group) do
assigns = %{ammo_group: ammo_group}
~H"""
<div class="py-2 px-4 h-full space-x-4 flex justify-center items-center">
<%= live_redirect to: Routes.ammo_group_show_path(Endpoint, :show, ammo_group),
class: "text-primary-600 link",
data: [qa: "view-#{ammo_group.id}"] do %>
<i class="fa-fw fa-lg fas fa-eye"></i>
<% end %>
<%= live_patch to: Routes.ammo_group_index_path(Endpoint, :edit, ammo_group),
class: "text-primary-600 link",
data: [qa: "edit-#{ammo_group.id}"] do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: ammo_group.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this ammo?"),
qa: "delete-#{ammo_group.id}"
] do %>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</div>
"""
end
defp get_value_for_key("container", %{container: nil}), do: {nil, nil}
defp get_value_for_key("container", %{container: %{name: container_name}} = ammo_group) do
assigns = %{ammo_group: ammo_group}
{container_name,
~H"""
<div class="min-w-20 py-2 px-4 h-full space-x-4 flex justify-center items-center">
<%= live_patch(@ammo_group.container.name,
to: Routes.ammo_group_index_path(Endpoint, :move, @ammo_group),
class: "btn btn-primary"
) %>
</div>
"""}
end
defp get_value_for_key(key, ammo_group),
do: ammo_group |> Map.get(key |> String.to_existing_atom())
end

View File

@ -8,127 +8,51 @@
<%= gettext("No Ammo") %>
<%= display_emoji("😔") %>
</h2>
<% end %>
<%= cond do %>
<% @containers_count == 0 -> %>
<div class="flex justify-center items-center">
<h2 class="m-2 title text-md text-primary-600">
<%= dgettext("prompts", "You'll need to") %>
</h2>
<%= live_patch(dgettext("actions", "add a container first"),
to: Routes.container_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
</div>
<% @ammo_types_count == 0 -> %>
<div class="flex justify-center items-center">
<h2 class="m-2 title text-md text-primary-600">
<%= dgettext("prompts", "You'll need to") %>
</h2>
<%= live_patch(dgettext("actions", "add an ammo type first"),
to: Routes.ammo_type_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
</div>
<% @ammo_groups |> Enum.empty?() -> %>
<%= live_patch(dgettext("actions", "Add your first box!"),
to: Routes.ammo_group_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<% else %>
<%= live_patch(dgettext("actions", "New Ammo group"),
<% true -> %>
<%= live_patch(dgettext("actions", "Add Ammo"),
to: Routes.ammo_group_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
<table class="min-w-full table-auto text-center bg-white">
<thead class="border-b border-primary-600">
<tr>
<th class="p-2">
<%= gettext("Ammo type") %>
</th>
<th class="p-2">
<%= gettext("Count") %>
</th>
<th class="p-2">
<%= gettext("Price paid") %>
</th>
<th class="p-2">
<%= gettext("% left") %>
</th>
<th class="p-2">
<%= gettext("Range") %>
</th>
<th class="p-2">
<%= gettext("Container") %>
</th>
<th class="p-2"></th>
</tr>
</thead>
<tbody id="ammo_groups">
<%= for ammo_group <- @ammo_groups do %>
<tr id={"ammo_group-#{ammo_group.id}"}>
<td class="p-2">
<%= live_patch(ammo_group.ammo_type.name,
to: Routes.ammo_type_show_path(Endpoint, :show, ammo_group.ammo_type),
class: "link"
) %>
</td>
<td class="p-2">
<%= ammo_group.count %>
</td>
<td class="p-2">
<%= if ammo_group.price_paid do %>
<%= gettext("$%{amount}",
amount: ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2)
) %>
<% end %>
</td>
<td class="p-2">
<%= "#{ammo_group |> Ammo.get_percentage_remaining()}%" %>
</td>
<td class="p-2">
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<button
type="button"
class="btn btn-primary"
phx-click="toggle_staged"
phx-value-ammo_group_id={ammo_group.id}
>
<%= if ammo_group.staged, do: gettext("Unstage"), else: gettext("Stage") %>
</button>
<%= live_patch(dgettext("actions", "Record shots"),
to: Routes.ammo_group_index_path(Endpoint, :add_shot_group, ammo_group),
class: "btn btn-primary"
) %>
</div>
</td>
<td class="p-2">
<%= if ammo_group.container do %>
<%= live_patch(ammo_group.container.name,
to: Routes.ammo_group_index_path(Endpoint, :move, ammo_group),
class: "btn btn-primary"
) %>
<% end %>
</td>
<td class="p-2">
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_redirect to: Routes.ammo_group_show_path(Endpoint, :show, ammo_group),
class: "text-primary-600 link",
data: [qa: "view-#{ammo_group.id}"] do %>
<i class="fa-fw fa-lg fas fa-eye"></i>
<% end %>
<%= live_patch to: Routes.ammo_group_index_path(Endpoint, :edit, ammo_group),
class: "text-primary-600 link",
data: [qa: "edit-#{ammo_group.id}"] do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: ammo_group.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this ammo?"),
qa: "delete-#{ammo_group.id}"
] do %>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<%= unless @ammo_groups |> Enum.empty?() do %>
<.live_component
module={CanneryWeb.Components.TableComponent}
id="ammo_groups_index_table"
action={@live_action}
columns={@columns}
rows={@rows}
/>
<% end %>
</div>
@ -170,4 +94,5 @@
/>
</.modal>
<% true -> %>
<%= nil %>
<% end %>

View File

@ -5,33 +5,49 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
use CanneryWeb, :live_view
import CanneryWeb.Components.ContainerCard
alias Cannery.{Ammo, Repo}
alias Cannery.{ActivityLog, ActivityLog.ShotGroup, Ammo, Ammo.AmmoGroup, Repo}
alias CanneryWeb.Endpoint
alias Phoenix.LiveView.Socket
@impl true
def mount(_params, session, socket) do
{:ok, socket |> assign_defaults(session)}
end
def mount(_params, _session, socket), do: {:ok, socket}
@impl true
def handle_params(
%{"id" => id},
%{"id" => id, "shot_group_id" => shot_group_id},
_url,
%{assigns: %{live_action: live_action, current_user: current_user}} = socket
) do
ammo_group = Ammo.get_ammo_group!(id, current_user) |> Repo.preload([:container, :ammo_type])
{:noreply, socket |> assign(page_title: page_title(live_action), ammo_group: ammo_group)}
shot_group = ActivityLog.get_shot_group!(shot_group_id, current_user)
socket =
socket
|> assign(page_title: page_title(live_action), shot_group: shot_group)
|> display_ammo_group(id)
{:noreply, socket}
end
@impl true
def handle_params(%{"id" => id}, _url, %{assigns: %{live_action: live_action}} = socket) do
{:noreply, socket |> assign(page_title: page_title(live_action)) |> display_ammo_group(id)}
end
defp page_title(:add_shot_group), do: gettext("Record Shots")
defp page_title(:edit_shot_group), do: gettext("Edit Shot Records")
defp page_title(:move), do: gettext("Move Ammo")
defp page_title(:show), do: gettext("Show Ammo")
defp page_title(:edit), do: gettext("Edit Ammo")
@impl true
def handle_event(
"delete",
_,
_params,
%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket
) do
ammo_group |> Ammo.delete_ammo_group!(current_user)
prompt = dgettext("prompts", "Ammo group deleted succesfully")
prompt = dgettext("prompts", "Ammo deleted succesfully")
redirect_to = Routes.ammo_group_index_path(socket, :index)
{:noreply, socket |> put_flash(:info, prompt) |> push_redirect(to: redirect_to)}
@ -40,17 +56,90 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
@impl true
def handle_event(
"toggle_staged",
_,
_params,
%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket
) do
{:ok, ammo_group} =
ammo_group |> Ammo.update_ammo_group(%{"staged" => !ammo_group.staged}, current_user)
{:noreply, socket |> assign(ammo_group: ammo_group)}
{:noreply, socket |> display_ammo_group(ammo_group)}
end
defp page_title(:add_shot_group), do: gettext("Add Shot group")
defp page_title(:move), do: gettext("Move Ammo group")
defp page_title(:show), do: gettext("Show Ammo group")
defp page_title(:edit), do: gettext("Edit Ammo group")
@impl true
def handle_event(
"delete_shot_group",
%{"id" => id},
%{assigns: %{ammo_group: ammo_group, current_user: current_user}} = socket
) do
{:ok, _} =
ActivityLog.get_shot_group!(id, current_user)
|> ActivityLog.delete_shot_group(current_user)
prompt = dgettext("prompts", "Shot records deleted succesfully")
{:noreply, socket |> put_flash(:info, prompt) |> display_ammo_group(ammo_group)}
end
@spec display_ammo_group(Socket.t(), AmmoGroup.t() | AmmoGroup.id()) :: Socket.t()
defp display_ammo_group(socket, %AmmoGroup{} = ammo_group) do
ammo_group = ammo_group |> Repo.preload([:container, :ammo_type, :shot_groups], force: true)
columns = [
%{label: gettext("Rounds shot"), key: "count"},
%{label: gettext("Notes"), key: "notes"},
%{label: gettext("Date"), key: "date"},
%{label: nil, key: "actions", sortable: false}
]
rows =
ammo_group.shot_groups
|> Enum.map(fn shot_group ->
ammo_group |> get_table_row_for_shot_group(shot_group, columns)
end)
socket |> assign(ammo_group: ammo_group, columns: columns, rows: rows)
end
defp display_ammo_group(%{assigns: %{current_user: current_user}} = socket, id),
do: display_ammo_group(socket, Ammo.get_ammo_group!(id, current_user))
@spec get_table_row_for_shot_group(AmmoGroup.t(), ShotGroup.t(), [map()]) :: [map()]
defp get_table_row_for_shot_group(ammo_group, %{date: date} = shot_group, columns) do
assigns = %{ammo_group: ammo_group, shot_group: shot_group}
columns
|> Enum.into(%{}, fn %{key: key} ->
value =
case key do
"date" ->
{date, date |> display_date()}
"actions" ->
~H"""
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_patch to: Routes.ammo_group_show_path(Endpoint, :edit_shot_group, @ammo_group, shot_group),
class: "text-primary-600 link",
data: [qa: "edit-#{shot_group.id}"] do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete_shot_group",
phx_value_id: shot_group.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this shot record?"),
qa: "delete-#{shot_group.id}"
] do %>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</div>
"""
key ->
shot_group |> Map.get(key |> String.to_existing_atom())
end
{key, value}
end)
end
end

View File

@ -26,6 +26,11 @@
</span>
<% end %>
<span class="rounded-lg title text-lg">
<%= gettext("Added on:") %>
<%= @ammo_group.inserted_at |> display_datetime() %>
</span>
<%= if @ammo_group.price_paid do %>
<span class="rounded-lg title text-lg">
<%= gettext("Original cost:") %>
@ -47,7 +52,7 @@
<div class="flex flex-col justify-center items-center">
<div class="flex flex-wrap justify-center items-center text-primary-600">
<%= live_patch(dgettext("actions", "Ammo Details"),
<%= live_patch(dgettext("actions", "View in Catalog"),
to: Routes.ammo_type_show_path(Endpoint, :show, @ammo_group.ammo_type),
class: "mx-4 my-2 btn btn-primary",
data: [qa: "details"]
@ -100,7 +105,7 @@
<.container_card container={@ammo_group.container} />
<% else %>
<%= gettext("This ammo group is not in a container") %>
<%= gettext("This ammo is not in a container") %>
<% end %>
</div>
@ -111,38 +116,12 @@
<%= gettext("Rounds used") %>
</h1>
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
<table class="min-w-full table-auto text-center bg-white">
<thead class="border-b border-primary-600">
<tr>
<th class="p-2">
<%= gettext("Rounds shot") %>
</th>
<th class="p-2">
<%= gettext("Notes") %>
</th>
<th class="p-2">
<%= gettext("Date") %>
</th>
</tr>
</thead>
<tbody id="shot_groups">
<%= for shot_group <- @ammo_group.shot_groups do %>
<tr id={"shot_group-#{shot_group.id}"}>
<td class="p-2">
<%= shot_group.count %>
</td>
<td class="p-2">
<%= shot_group.notes %>
</td>
<td class="p-2">
<%= shot_group.date |> display_date() %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<.live_component
module={CanneryWeb.Components.TableComponent}
id="ammo_group_shot_groups_table"
columns={@columns}
rows={@rows}
/>
<% end %>
</div>
@ -159,6 +138,18 @@
current_user={@current_user}
/>
</.modal>
<% :edit_shot_group -> %>
<.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}>
<.live_component
module={CanneryWeb.RangeLive.FormComponent}
id={@shot_group.id}
title={@page_title}
action={@live_action}
shot_group={@shot_group}
return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}
current_user={@current_user}
/>
</.modal>
<% :add_shot_group -> %>
<.modal return_to={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}>
<.live_component

View File

@ -13,17 +13,13 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
%{:ammo_type => AmmoType.t(), :current_user => User.t(), optional(any) => any},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{ammo_type: ammo_type, current_user: _current_user} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign(:changeset, Ammo.change_ammo_type(ammo_type))}
def update(%{current_user: _current_user} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign_changeset(%{})}
end
@impl true
def handle_event(
"validate",
%{"ammo_type" => ammo_type_params},
%{assigns: %{ammo_type: ammo_type}} = socket
) do
{:noreply, socket |> assign(:changeset, ammo_type |> Ammo.change_ammo_type(ammo_type_params))}
def handle_event("validate", %{"ammo_type" => ammo_type_params}, socket) do
{:noreply, socket |> assign_changeset(ammo_type_params)}
end
def handle_event(
@ -34,6 +30,31 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
save_ammo_type(socket, action, ammo_type_params)
end
defp assign_changeset(
%{assigns: %{action: action, ammo_type: ammo_type, current_user: user}} = socket,
ammo_type_params
) do
changeset_action =
case action do
:new -> :insert
:edit -> :update
end
changeset =
case action do
:new -> ammo_type |> AmmoType.create_changeset(user, ammo_type_params)
:edit -> ammo_type |> AmmoType.update_changeset(ammo_type_params)
end
changeset =
case changeset |> Changeset.apply_action(changeset_action) do
{:ok, _data} -> changeset
{:error, changeset} -> changeset
end
socket |> assign(changeset: changeset)
end
defp save_ammo_type(
%{assigns: %{ammo_type: ammo_type, current_user: current_user, return_to: return_to}} =
socket,

View File

@ -9,7 +9,7 @@
phx-target={@myself}
phx-change="validate"
phx-submit="save"
class="flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<%= if @changeset.action && not @changeset.valid? do %>
<div class="invalid-feedback col-span-3 text-center">
@ -17,11 +17,11 @@
</div>
<% end %>
<%= label(f, :name, gettext("Name"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :name, gettext("Name"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :name, class: "text-center col-span-2 input input-primary") %>
<%= error_tag(f, :name, "col-span-3 text-center") %>
<%= label(f, :desc, gettext("Description"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :desc, gettext("Description"), class: "title text-lg text-primary-600") %>
<%= textarea(f, :desc,
class: "text-center col-span-2 input input-primary",
phx_hook: "MaintainAttrs"
@ -34,50 +34,42 @@
>
<%= gettext("Example bullet type abbreviations") %>
</a>
<%= label(f, :bullet_type, gettext("Bullet type"),
class: "mr-4 title text-lg text-primary-600"
) %>
<%= label(f, :bullet_type, gettext("Bullet type"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :bullet_type,
class: "text-center col-span-2 input input-primary",
placeholder: gettext("FMJ")
) %>
<%= error_tag(f, :bullet_type, "col-span-3 text-center") %>
<%= label(f, :bullet_core, gettext("Bullet core"),
class: "mr-4 title text-lg text-primary-600"
) %>
<%= label(f, :bullet_core, gettext("Bullet core"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :bullet_core,
class: "text-center col-span-2 input input-primary",
placeholder: gettext("Steel")
) %>
<%= error_tag(f, :bullet_core, "col-span-3 text-center") %>
<%= label(f, :cartridge, gettext("Cartridge"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :cartridge, gettext("Cartridge"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :cartridge,
class: "text-center col-span-2 input input-primary",
placeholder: "5.56x46mm NATO"
) %>
<%= error_tag(f, :cartridge, "col-span-3 text-center") %>
<%= label(f, :caliber, gettext("Caliber"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :caliber, gettext("Caliber"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :caliber,
class: "text-center col-span-2 input input-primary",
placeholder: ".223"
) %>
<%= error_tag(f, :caliber, "col-span-3 text-center") %>
<%= label(f, :case_material, gettext("Case material"),
class: "mr-4 title text-lg text-primary-600"
) %>
<%= label(f, :case_material, gettext("Case material"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :case_material,
class: "text-center col-span-2 input input-primary",
placeholder: gettext("Brass")
) %>
<%= error_tag(f, :case_material, "col-span-3 text-center") %>
<%= label(f, :jacket_type, gettext("Jacket type"),
class: "mr-4 title text-lg text-primary-600"
) %>
<%= label(f, :jacket_type, gettext("Jacket type"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :jacket_type,
class: "text-center col-span-2 input input-primary",
placeholder: gettext("Bimetal")
@ -85,7 +77,7 @@
<%= error_tag(f, :case_material, "col-span-3 text-center") %>
<%= label(f, :muzzle_velocity, gettext("Muzzle velocity"),
class: "mr-4 title text-lg text-primary-600"
class: "title text-lg text-primary-600"
) %>
<%= number_input(f, :muzzle_velocity,
step: "1",
@ -94,14 +86,12 @@
) %>
<%= error_tag(f, :muzzle_velocity, "col-span-3 text-center") %>
<%= label(f, :powder_type, gettext("Powder type"),
class: "mr-4 title text-lg text-primary-600"
) %>
<%= label(f, :powder_type, gettext("Powder type"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :powder_type, class: "text-center col-span-2 input input-primary") %>
<%= error_tag(f, :powder_type, "col-span-3 text-center") %>
<%= label(f, :powder_grains_per_charge, gettext("Powder grains per charge"),
class: "mr-4 title text-lg text-primary-600"
class: "title text-lg text-primary-600"
) %>
<%= number_input(f, :powder_grains_per_charge,
step: "1",
@ -110,7 +100,7 @@
) %>
<%= error_tag(f, :powder_grains_per_charge, "col-span-3 text-center") %>
<%= label(f, :grains, gettext("Grains"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :grains, gettext("Grains"), class: "title text-lg text-primary-600") %>
<%= number_input(f, :grains,
step: "1",
class: "text-center col-span-2 input input-primary",
@ -118,54 +108,48 @@
) %>
<%= error_tag(f, :grains, "col-span-3 text-center") %>
<%= label(f, :pressure, gettext("Pressure"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :pressure, gettext("Pressure"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :pressure,
class: "text-center col-span-2 input input-primary",
placeholder: "+P"
) %>
<%= error_tag(f, :pressure, "col-span-3 text-center") %>
<%= label(f, :primer_type, gettext("Primer type"),
class: "mr-4 title text-lg text-primary-600"
) %>
<%= label(f, :primer_type, gettext("Primer type"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :primer_type,
class: "text-center col-span-2 input input-primary",
placeholder: "Boxer"
) %>
<%= error_tag(f, :primer_type, "col-span-3 text-center") %>
<%= label(f, :firing_type, gettext("Firing type"),
class: "mr-4 title text-lg text-primary-600"
) %>
<%= label(f, :firing_type, gettext("Firing type"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :firing_type,
class: "text-center col-span-2 input input-primary",
placeholder: "Centerfire"
) %>
<%= error_tag(f, :firing_type, "col-span-3 text-center") %>
<%= label(f, :tracer, gettext("Tracer"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :tracer, gettext("Tracer"), class: "title text-lg text-primary-600") %>
<%= checkbox(f, :tracer, class: "text-center col-span-2 checkbox") %>
<%= error_tag(f, :tracer, "col-span-3 text-center") %>
<%= label(f, :incendiary, gettext("Incendiary"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :incendiary, gettext("Incendiary"), class: "title text-lg text-primary-600") %>
<%= checkbox(f, :incendiary, class: "text-center col-span-2 checkbox") %>
<%= error_tag(f, :incendiary, "col-span-3 text-center") %>
<%= label(f, :blank, gettext("Blank"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :blank, gettext("Blank"), class: "title text-lg text-primary-600") %>
<%= checkbox(f, :blank, class: "text-center col-span-2 checkbox") %>
<%= error_tag(f, :blank, "col-span-3 text-center") %>
<%= label(f, :corrosive, gettext("Corrosive"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :corrosive, gettext("Corrosive"), class: "title text-lg text-primary-600") %>
<%= checkbox(f, :corrosive, class: "text-center col-span-2 checkbox") %>
<%= error_tag(f, :corrosive, "col-span-3 text-center") %>
<%= label(f, :manufacturer, gettext("Manufacturer"),
class: "mr-4 title text-lg text-primary-600"
) %>
<%= label(f, :manufacturer, gettext("Manufacturer"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :manufacturer, class: "text-center col-span-2 input input-primary") %>
<%= error_tag(f, :manufacturer, "col-span-3 text-center") %>
<%= label(f, :upc, gettext("UPC"), class: "mr-4 title text-lg text-primary-600") %>
<%= label(f, :upc, gettext("UPC"), class: "title text-lg text-primary-600") %>
<%= text_input(f, :upc, class: "text-center col-span-2 input input-primary") %>
<%= error_tag(f, :upc, "col-span-3 text-center") %>

View File

@ -9,8 +9,8 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
alias CanneryWeb.Endpoint
@impl true
def mount(_params, session, socket) do
{:ok, socket |> assign_defaults(session) |> list_ammo_types()}
def mount(_params, _session, socket) do
{:ok, socket |> list_ammo_types()}
end
@impl true
@ -31,7 +31,7 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
end
defp apply_action(socket, :index, _params) do
socket |> assign(:page_title, gettext("Listing Ammo types")) |> assign(:ammo_type, nil)
socket |> assign(:page_title, gettext("Ammo types")) |> assign(:ammo_type, nil)
end
@impl true
@ -46,37 +46,108 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
defp list_ammo_types(%{assigns: %{current_user: current_user}} = socket) do
ammo_types = Ammo.list_ammo_types(current_user)
columns_to_display =
columns =
[
{gettext("Name"), :name, :string},
{gettext("Bullet type"), :bullet_type, :string},
{gettext("Bullet core"), :bullet_core, :string},
{gettext("Cartridge"), :cartridge, :string},
{gettext("Caliber"), :caliber, :string},
{gettext("Case material"), :case_material, :string},
{gettext("Jacket type"), :jacket_type, :string},
{gettext("Muzzle velocity"), :muzzle_velocity, :string},
{gettext("Powder type"), :powder_type, :string},
{gettext("Powder grains per charge"), :powder_grains_per_charge, :string},
{gettext("Grains"), :grains, :string},
{gettext("Pressure"), :pressure, :string},
{gettext("Primer type"), :primer_type, :string},
{gettext("Firing type"), :firing_type, :string},
{gettext("Tracer"), :tracer, :boolean},
{gettext("Incendiary"), :incendiary, :boolean},
{gettext("Blank"), :blank, :boolean},
{gettext("Corrosive"), :corrosive, :boolean},
{gettext("Manufacturer"), :manufacturer, :string},
{gettext("UPC"), :upc, :string}
%{label: gettext("Name"), key: "name", type: :string},
%{label: gettext("Bullet type"), key: "bullet_type", type: :string},
%{label: gettext("Bullet core"), key: "bullet_core", type: :string},
%{label: gettext("Cartridge"), key: "cartridge", type: :string},
%{label: gettext("Caliber"), key: "caliber", type: :string},
%{label: gettext("Case material"), key: "case_material", type: :string},
%{label: gettext("Jacket type"), key: "jacket_type", type: :string},
%{label: gettext("Muzzle velocity"), key: "muzzle_velocity", type: :string},
%{label: gettext("Powder type"), key: "powder_type", type: :string},
%{
label: gettext("Powder grains per charge"),
key: "powder_grains_per_charge",
type: :string
},
%{label: gettext("Grains"), key: "grains", type: :string},
%{label: gettext("Pressure"), key: "pressure", type: :string},
%{label: gettext("Primer type"), key: "primer_type", type: :string},
%{label: gettext("Firing type"), key: "firing_type", type: :string},
%{label: gettext("Tracer"), key: "tracer", type: :boolean},
%{label: gettext("Incendiary"), key: "incendiary", type: :boolean},
%{label: gettext("Blank"), key: "blank", type: :boolean},
%{label: gettext("Corrosive"), key: "corrosive", type: :boolean},
%{label: gettext("Manufacturer"), key: "manufacturer", type: :string},
%{label: gettext("UPC"), key: "upc", type: :string}
]
|> Enum.filter(fn {_label, field, type} ->
|> Enum.filter(fn %{key: key, type: type} ->
# remove columns if all values match defaults
default_value = if type == :boolean, do: false, else: nil
ammo_types
|> Enum.any?(fn ammo_type -> not (ammo_type |> Map.get(field) == default_value) end)
|> Enum.any?(fn ammo_type ->
not (ammo_type |> Map.get(key |> String.to_existing_atom()) == default_value)
end)
end)
|> Kernel.++([
%{label: gettext("Total # of rounds"), key: "round_count", type: :round_count},
%{label: gettext("Average Price paid"), key: "avg_price_paid", type: :avg_price_paid},
%{label: nil, key: "actions", type: :actions, sortable: false}
])
socket |> assign(ammo_types: ammo_types, columns_to_display: columns_to_display)
rows =
ammo_types
|> Enum.map(fn ammo_type -> ammo_type |> get_ammo_type_values(columns, current_user) end)
socket |> assign(columns: columns, rows: rows)
end
defp get_ammo_type_values(ammo_type, columns, current_user) do
columns
|> Enum.into(%{}, fn %{key: key, type: type} ->
{key, get_ammo_type_value(type, key, ammo_type, current_user)}
end)
end
defp get_ammo_type_value(:boolean, key, ammo_type, _current_user),
do: ammo_type |> Map.get(key |> String.to_existing_atom()) |> humanize()
defp get_ammo_type_value(:round_count, _key, ammo_type, current_user),
do: ammo_type |> Ammo.get_round_count_for_ammo_type(current_user)
defp get_ammo_type_value(:avg_price_paid, _key, ammo_type, current_user) do
case ammo_type |> Ammo.get_average_cost_for_ammo_type!(current_user) do
nil -> gettext("No cost information")
count -> gettext("$%{amount}", amount: count |> :erlang.float_to_binary(decimals: 2))
end
end
defp get_ammo_type_value(:actions, _key, ammo_type, _current_user) do
assigns = %{ammo_type: ammo_type}
~H"""
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_redirect to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
class: "text-primary-600 link",
data: [qa: "view-#{ammo_type.id}"] do %>
<i class="fa-fw fa-lg fas fa-eye"></i>
<% end %>
<%= live_patch to: Routes.ammo_type_index_path(Endpoint, :edit, ammo_type),
class: "text-primary-600 link",
data: [qa: "edit-#{ammo_type.id}"] do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: ammo_type.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!", name: ammo_type.name),
qa: "delete-#{ammo_type.id}"
] do %>
<i class="fa-lg fas fa-trash"></i>
<% end %>
</div>
"""
end
defp get_ammo_type_value(nil, _key, _ammo_type, _current_user), do: nil
defp get_ammo_type_value(_other, key, ammo_type, _current_user),
do: ammo_type |> Map.get(key |> String.to_existing_atom())
end

View File

@ -1,9 +1,9 @@
<div class="flex flex-col space-y-8 justify-center items-center">
<h1 class="title text-2xl title-primary-500">
<%= gettext("Ammo Types") %>
<%= gettext("Catalog") %>
</h1>
<%= if @ammo_types |> Enum.empty?() do %>
<%= if @rows |> Enum.empty?() do %>
<h2 class="title text-xl text-primary-600">
<%= gettext("No Ammo Types") %>
<%= display_emoji("😔") %>
@ -19,71 +19,13 @@
class: "btn btn-primary"
) %>
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
<table class="min-w-full table-auto text-center bg-white">
<thead class="border-b border-primary-600">
<tr>
<%= for {field_name, _field, _type} <- @columns_to_display do %>
<th class="p-2">
<%= field_name %>
</th>
<% end %>
<th class="p-2">
<%= gettext("Total # of rounds") %>
</th>
<th class="p-2"></th>
</tr>
</thead>
<tbody>
<%= for ammo_type <- @ammo_types do %>
<tr id={"ammo_type-#{ammo_type.id}"}>
<%= for {_label, field, type} <- @columns_to_display do %>
<td class="p-2">
<%= case type do %>
<% :boolean -> %>
<%= ammo_type |> Map.get(field) |> humanize() %>
<% _other -> %>
<%= ammo_type |> Map.get(field) %>
<% end %>
</td>
<% end %>
<td class="p-2">
<%= ammo_type |> Ammo.get_round_count_for_ammo_type(@current_user) %>
</td>
<td class="p-2">
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_redirect to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
class: "text-primary-600 link",
data: [qa: "view-#{ammo_type.id}"] do %>
<i class="fa-fw fa-lg fas fa-eye"></i>
<% end %>
<%= live_patch to: Routes.ammo_type_index_path(Endpoint, :edit, ammo_type),
class: "text-primary-600 link",
data: [qa: "edit-#{ammo_type.id}"] do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: ammo_type.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this ammo?"),
qa: "delete-#{ammo_type.id}"
] do %>
<i class="fa-lg fas fa-trash"></i>
<% end %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<.live_component
module={CanneryWeb.Components.TableComponent}
id="ammo_types_index_table"
action={@live_action}
columns={@columns}
rows={@rows}
/>
<% end %>
</div>

View File

@ -9,12 +9,10 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
alias CanneryWeb.Endpoint
@impl true
def mount(_params, session, socket) do
{:ok, socket |> assign_defaults(session)}
end
def mount(_params, _session, socket), do: {:ok, socket}
@impl true
def handle_params(%{"id" => id}, _, %{assigns: %{current_user: current_user}} = socket) do
def handle_params(%{"id" => id}, _params, %{assigns: %{current_user: current_user}} = socket) do
ammo_type = Ammo.get_ammo_type!(id, current_user)
socket =
@ -32,7 +30,7 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
@impl true
def handle_event(
"delete",
_,
_params,
%{assigns: %{ammo_type: ammo_type, current_user: current_user}} = socket
) do
%{name: ammo_type_name} = ammo_type |> Ammo.delete_ammo_type!(current_user)

View File

@ -5,11 +5,9 @@
</h1>
<%= if @ammo_type.desc do %>
<span
class="max-w-2xl w-full px-8 py-4 rounded-lg
<span class="max-w-2xl w-full px-8 py-4 rounded-lg
text-center title text-lg
border border-primary-600"
>
border border-primary-600">
<%= @ammo_type.desc %>
</span>
<% end %>
@ -26,7 +24,7 @@
phx_click: "delete",
data: [
confirm:
dgettext("prompts", "Are you sure you want to delete %{name}?", name: @ammo_type.name),
dgettext("prompts", "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!", name: @ammo_type.name),
qa: "delete"
] do %>
<i class="fa-fw fa-lg fas fa-trash"></i>
@ -89,6 +87,14 @@
<%= @ammo_type |> Ammo.get_used_count_for_ammo_type(@current_user) %>
</span>
<h3 class="title text-lg">
<%= gettext("Added on:") %>
</h3>
<span class="text-primary-600">
<%= @ammo_type.inserted_at |> display_datetime() %>
</span>
<%= if @avg_cost_per_round do %>
<h3 class="title text-lg">
<%= gettext("Average Price paid") %>:
@ -100,9 +106,8 @@
) %>
</span>
<% else %>
<h3 class="title text-lg col-span-2">
<h3 class="mx-8 my-4 title text-lg text-primary-600 col-span-2">
<%= gettext("No cost information") %>
<%= display_emoji("😔") %>
</h3>
<% end %>
</div>
@ -111,8 +116,10 @@
<div>
<%= if @ammo_groups |> Enum.empty?() do %>
<h2 class="mx-8 my-4 title text-lg text-primary-600">
<%= gettext("No ammo for this type") %>
<%= display_emoji("😔") %>
</h2>
<% else %>
<div class="flex flex-wrap justify-center items-center">
<%= for ammo_group <- @ammo_groups do %>

View File

@ -40,7 +40,7 @@
let={f}
for={:tag}
id="add-tag-to-container-form"
class="flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
phx-target={@myself}
phx-submit="save"
>

View File

@ -13,18 +13,13 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
%{:container => Container.t(), :current_user => User.t(), optional(any) => any},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{container: container} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign(:changeset, Containers.change_container(container))}
def update(%{container: _container} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign_changeset(%{})}
end
@impl true
def handle_event(
"validate",
%{"container" => container_params},
%{assigns: %{container: container}} = socket
) do
changeset = container |> Containers.change_container(container_params)
{:noreply, socket |> assign(:changeset, changeset)}
def handle_event("validate", %{"container" => container_params}, socket) do
{:noreply, socket |> assign_changeset(container_params)}
end
def handle_event(
@ -35,6 +30,31 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
save_container(socket, action, container_params)
end
defp assign_changeset(
%{assigns: %{action: action, container: container, current_user: user}} = socket,
container_params
) do
changeset_action =
case action do
:new -> :insert
:edit -> :update
end
changeset =
case action do
:new -> container |> Container.create_changeset(user, container_params)
:edit -> container |> Container.update_changeset(container_params)
end
changeset =
case changeset |> Changeset.apply_action(changeset_action) do
{:ok, _data} -> changeset
{:error, changeset} -> changeset
end
socket |> assign(:changeset, changeset)
end
defp save_container(
%{assigns: %{container: container, current_user: current_user, return_to: return_to}} =
socket,

View File

@ -6,7 +6,7 @@
let={f}
for={@changeset}
id="container-form"
class="flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
phx-target={@myself}
phx-change="validate"
phx-submit="save"

View File

@ -10,13 +10,11 @@ defmodule CanneryWeb.ContainerLive.Index do
alias Ecto.Changeset
@impl true
def mount(_params, session, socket) do
{:ok, socket |> assign_defaults(session)}
end
def mount(_params, _session, socket), do: {:ok, socket}
@impl true
def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do
{:noreply, apply_action(socket, live_action, params)}
{:noreply, apply_action(socket, live_action, params) |> display_containers()}
end
defp apply_action(%{assigns: %{current_user: current_user}} = socket, :edit, %{"id" => id}) do
@ -35,7 +33,7 @@ defmodule CanneryWeb.ContainerLive.Index do
defp apply_action(socket, :index, _params) do
socket
|> assign(:page_title, gettext("Listing Containers"))
|> assign(:page_title, gettext("Containers"))
|> assign(:container, nil)
|> display_containers()
end

View File

@ -20,7 +20,7 @@
) %>
<% end %>
<div class="flex flex-row flex-wrap justify-center items-center">
<div class="max-w-full flex flex-row flex-wrap justify-center items-center">
<%= for container <- @containers do %>
<.container_card container={container}>
<:tag_actions>

View File

@ -11,14 +11,12 @@ defmodule CanneryWeb.ContainerLive.Show do
alias Phoenix.LiveView.Socket
@impl true
def mount(_params, session, socket) do
{:ok, socket |> assign_defaults(session)}
end
def mount(_params, _session, socket), do: {:ok, socket}
@impl true
def handle_params(
%{"id" => id},
_,
_session,
%{assigns: %{current_user: current_user}} = socket
) do
{:noreply, socket |> render_container(id, current_user)}
@ -53,7 +51,7 @@ defmodule CanneryWeb.ContainerLive.Show do
@impl true
def handle_event(
"delete_container",
_,
_params,
%{assigns: %{container: container, current_user: current_user}} = socket
) do
socket =

View File

@ -22,6 +22,18 @@
</span>
<% end %>
<%= unless @container.ammo_groups |> Enum.empty?() do %>
<span class="rounded-lg title text-lg">
<%= gettext("Packs:") %>
<%= @container |> Containers.get_container_ammo_group_count!() %>
</span>
<span class="rounded-lg title text-lg">
<%= gettext("Rounds:") %>
<%= @container |> Containers.get_container_rounds!() %>
</span>
<% end %>
<div class="flex space-x-4 justify-center items-center text-primary-600">
<%= live_patch to: Routes.container_show_path(Endpoint, :edit, @container),
class: "text-primary-600 link",
@ -72,9 +84,11 @@
<hr class="mb-4 hr" />
<p>
<div>
<%= if @container.ammo_groups |> Enum.empty?() do %>
<%= gettext("No ammo groups in this container") %>
<h2 class="mx-8 my-4 title text-lg text-primary-600">
<%= gettext("No ammo in this container") %>
</h2>
<% else %>
<div class="flex flex-wrap justify-center items-center">
<%= for ammo_group <- @container.ammo_groups do %>
@ -82,7 +96,7 @@
<% end %>
</div>
<% end %>
</p>
</div>
</div>
<%= if @live_action in [:edit] do %>

View File

@ -5,16 +5,12 @@ defmodule CanneryWeb.HomeLive do
use CanneryWeb, :live_view
alias Cannery.Accounts
alias CanneryWeb.Endpoint
@impl true
def mount(_params, session, socket) do
def mount(_params, _session, socket) do
admins = Accounts.list_users_by_role(:admin)
socket =
socket
|> assign_defaults(session)
|> assign(page_title: "Home", query: "", results: %{}, admins: admins)
socket = socket |> assign(page_title: "Home", query: "", results: %{}, admins: admins)
{:ok, socket}
end
@ -29,7 +25,7 @@ defmodule CanneryWeb.HomeLive do
%{^query => vsn} ->
{:noreply, redirect(socket, external: "https://hexdocs.pm/#{query}/#{vsn}")}
_ ->
_no_query ->
{:noreply,
socket
|> put_flash(:error, "No dependencies found matching \"#{query}\"")
@ -40,9 +36,14 @@ defmodule CanneryWeb.HomeLive do
@impl true
def render(assigns) do
~H"""
<div
class="mx-auto px-8 sm:px-16 flex flex-col justify-center items-center text-center space-y-4 max-w-3xl"
>
<div class="mx-auto px-8 sm:px-16 flex flex-col justify-center items-center text-center space-y-4 max-w-3xl">
<img
src={Routes.static_path(Endpoint, "/images/cannery.svg")}
alt={gettext("Cannery logo")}
class="inline-block w-32 hover:-mt-2 hover:mb-2 transition-all duration-500 ease-in-out"
title={gettext("isn't he cute >:3")}
/>
<h1 class="title text-primary-600 text-2xl">
<%= gettext("Welcome to %{name}", name: "Cannery") %>
</h1>
@ -127,11 +128,51 @@ defmodule CanneryWeb.HomeLive do
</p>
</li>
<li class="flex flex-row justify-center space-x-2">
<li class="flex flex-row justify-center items-center space-x-2">
<b>Version:</b>
<p>
0.2.0
</p>
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://gitea.bubbletea.dev/shibao/cannery/src/branch/stable/CHANGELOG.md",
target: "_blank",
rel: "noopener noreferrer" do %>
<p>0.5.5</p>
<i class="fas fa-md fa-info-circle"></i>
<% end %>
</li>
</ul>
<hr class="hr" />
<ul class="flex flex-col space-y-2 text-center justify-center">
<h2 class="title text-primary-600 text-lg">
<%= gettext("Get involved!") %>
</h2>
<li class="flex flex-col justify-center space-x-2">
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://gitea.bubbletea.dev/shibao/cannery",
target: "_blank",
rel: "noopener noreferrer" do %>
<p><%= gettext("View the source code") %></p>
<i class="fas fa-md fa-code"></i>
<% end %>
</li>
<li class="flex flex-col justify-center space-x-2">
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://weblate.bubbletea.dev/engage/cannery",
target: "_blank",
rel: "noopener noreferrer" do %>
<p><%= gettext("Help translate") %></p>
<i class="fas fa-md fa-language"></i>
<% end %>
</li>
<li class="flex flex-col justify-center space-x-2">
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://gitea.bubbletea.dev/shibao/cannery/issues/new",
target: "_blank",
rel: "noopener noreferrer" do %>
<p><%= gettext("Report bugs or request features") %></p>
<i class="fas fa-md fa-spider"></i>
<% end %>
</li>
</ul>
</div>

View File

@ -0,0 +1,19 @@
defmodule CanneryWeb.InitAssigns do
@moduledoc """
Ensures common `assigns` are applied to all LiveViews attaching this hook.
"""
import Phoenix.LiveView
alias Cannery.Accounts
def on_mount(:default, _params, %{"locale" => locale, "user_token" => user_token}, socket) do
Gettext.put_locale(locale)
socket =
socket
|> assign_new(:current_user, fn -> Accounts.get_user_by_session_token(user_token) end)
{:cont, socket}
end
def on_mount(:default, _params, _session, socket), do: {:cont, socket}
end

View File

@ -13,23 +13,44 @@ defmodule CanneryWeb.InviteLive.FormComponent do
%{:invite => Invite.t(), :current_user => User.t(), optional(any) => any},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{invite: invite} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign(:changeset, Invites.change_invite(invite))}
def update(%{invite: _invite} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign_changeset(%{})}
end
@impl true
def handle_event(
"validate",
%{"invite" => invite_params},
%{assigns: %{invite: invite}} = socket
) do
{:noreply, socket |> assign(:changeset, invite |> Invites.change_invite(invite_params))}
def handle_event("validate", %{"invite" => invite_params}, socket) do
{:noreply, socket |> assign_changeset(invite_params)}
end
def handle_event("save", %{"invite" => invite_params}, %{assigns: %{action: action}} = socket) do
save_invite(socket, action, invite_params)
end
defp assign_changeset(
%{assigns: %{action: action, current_user: user, invite: invite}} = socket,
invite_params
) do
changeset_action =
case action do
:new -> :insert
:edit -> :update
end
changeset =
case action do
:new -> invite |> Invite.create_changeset(user, "example_token", invite_params)
:edit -> invite |> Invite.update_changeset(invite_params)
end
changeset =
case changeset |> Changeset.apply_action(changeset_action) do
{:ok, _data} -> changeset
{:error, changeset} -> changeset
end
socket |> assign(:changeset, changeset)
end
defp save_invite(
%{assigns: %{current_user: current_user, invite: invite, return_to: return_to}} = socket,
:edit,

View File

@ -6,7 +6,7 @@
let={f}
for={@changeset}
id="invite-form"
class="flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
@ -24,6 +24,9 @@
<%= label(f, :uses_left, gettext("Uses left"), class: "title text-lg text-primary-600") %>
<%= number_input(f, :uses_left, min: 0, class: "input input-primary col-span-2") %>
<%= error_tag(f, :uses_left, "col-span-3") %>
<span class="col-span-3 text-primary-400 italic text-center">
<%= gettext("Leave \"Uses left\" blank to make invite unlimited") %>
</span>
<%= submit(dgettext("actions", "Save"),
class: "mx-auto btn btn-primary col-span-3",

View File

@ -10,9 +10,7 @@ defmodule CanneryWeb.InviteLive.Index do
alias Phoenix.LiveView.JS
@impl true
def mount(_params, session, socket) do
%{assigns: %{current_user: current_user}} = socket = socket |> assign_defaults(session)
def mount(_params, _session, %{assigns: %{current_user: current_user}} = socket) do
socket =
if current_user |> Map.get(:role) == :admin do
socket |> display_invites()
@ -40,7 +38,7 @@ defmodule CanneryWeb.InviteLive.Index do
end
defp apply_action(socket, :index, _params) do
socket |> assign(page_title: gettext("Listing Invites"), invite: nil)
socket |> assign(page_title: gettext("Invites"), invite: nil)
end
@impl true
@ -119,7 +117,7 @@ defmodule CanneryWeb.InviteLive.Index do
end
@impl true
def handle_event("copy_to_clipboard", _, socket) do
def handle_event("copy_to_clipboard", _params, socket) do
prompt = dgettext("prompts", "Copied to clipboard")
{:noreply, socket |> put_flash(:info, prompt)}
end

View File

@ -3,20 +3,9 @@ defmodule CanneryWeb.LiveHelpers do
Contains common helper functions for liveviews
"""
import Phoenix.LiveView
import Phoenix.LiveView.Helpers
alias Cannery.Accounts
alias Phoenix.LiveView.JS
def assign_defaults(socket, %{"user_token" => user_token} = _session) do
socket
|> assign_new(:current_user, fn -> Accounts.get_user_by_session_token(user_token) end)
end
def assign_defaults(socket, _session) do
socket
end
@doc """
Renders a live component inside a modal.
@ -38,32 +27,43 @@ defmodule CanneryWeb.LiveHelpers do
"""
def modal(assigns) do
~H"""
<%= live_patch to: @return_to,
id: "modal-bg",
class:
"fade-in fixed z-10 left-0 top-0
w-full h-full overflow-hidden
p-8 flex flex-col justify-center items-center cursor-auto",
style: "background-color: rgba(0,0,0,0.4);",
phx_remove: hide_modal()
do %>
<span class="hidden"></span>
<% end %>
<div
id="modal"
class="fade-in fixed z-10 left-0 top-0
class="fixed z-10 left-0 top-0 pointer-events-none
w-full h-full overflow-hidden
p-8 flex flex-col justify-center items-center"
style="opacity: 1 !important; background-color: rgba(0,0,0,0.4);"
phx-remove={hide_modal()}
p-4 sm:p-8 flex flex-col justify-center items-center"
>
<div
id="modal-content"
class="fade-in-scale w-full max-w-3xl max-h-128 relative overflow-y-auto
class="fade-in-scale w-full max-w-3xl relative
pointer-events-auto overflow-hidden
px-8 py-4 sm:py-8 flex flex-col justify-center items-center
flex flex-col justify-start items-center
bg-white border-2 rounded-lg"
phx-click-away={hide_modal()}
phx-window-keydown={hide_modal()}
phx-key="escape"
>
<%= live_patch to: @return_to,
id: "close",
class:
"absolute top-8 right-10 text-gray-500 hover:text-gray-800 transition-all duration-500 ease-in-out",
phx_click: hide_modal() do %>
"absolute top-8 right-10
text-gray-500 hover:text-gray-800
transition-all duration-500 ease-in-out",
phx_remove: hide_modal() do %>
<i class="fa-fw fa-lg fas fa-times"></i>
<% end %>
<div class="w-full p-8 flex flex-col space-y-4 justify-start items-center">
<div class="overflow-x-hidden overflow-y-auto w-full p-8 flex flex-col space-y-4 justify-start items-center">
<%= render_slot(@inner_block) %>
</div>
</div>
@ -74,6 +74,7 @@ defmodule CanneryWeb.LiveHelpers do
def hide_modal(js \\ %JS{}) do
js
|> JS.hide(to: "#modal", transition: "fade-out")
|> JS.hide(to: "#modal-bg", transition: "fade-out")
|> JS.hide(to: "#modal-content", transition: "fade-out-scale")
end
end

View File

@ -1,6 +1,6 @@
defmodule CanneryWeb.RangeLive.FormComponent do
@moduledoc """
Livecomponent that can update or create a ShotGroup
Livecomponent that can update a ShotGroup
"""
use CanneryWeb, :live_component
@ -24,7 +24,7 @@ defmodule CanneryWeb.RangeLive.FormComponent do
} = assigns,
socket
) do
changeset = shot_group |> ActivityLog.change_shot_group()
changeset = shot_group |> ShotGroup.update_changeset(current_user, %{})
ammo_group = Ammo.get_ammo_group!(ammo_group_id, current_user)
{:ok, socket |> assign(assigns) |> assign(ammo_group: ammo_group, changeset: changeset)}
end
@ -33,11 +33,11 @@ defmodule CanneryWeb.RangeLive.FormComponent do
def handle_event(
"validate",
%{"shot_group" => shot_group_params},
%{assigns: %{shot_group: shot_group}} = socket
%{assigns: %{current_user: current_user, shot_group: shot_group}} = socket
) do
changeset =
shot_group
|> ActivityLog.change_shot_group(shot_group_params)
|> ShotGroup.update_changeset(current_user, shot_group_params)
|> Map.put(:action, :validate)
{:noreply, assign(socket, :changeset, changeset)}

View File

@ -7,7 +7,7 @@
let={f}
for={@changeset}
id="shot-group-form"
class="flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
phx-target={@myself}
phx-change="validate"
phx-submit="save"

View File

@ -10,9 +10,7 @@ defmodule CanneryWeb.RangeLive.Index do
alias Phoenix.LiveView.Socket
@impl true
def mount(_params, session, socket) do
{:ok, socket |> assign_defaults(session) |> display_shot_groups()}
end
def mount(_params, _session, socket), do: {:ok, socket |> display_shot_groups()}
@impl true
def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do
@ -25,7 +23,7 @@ defmodule CanneryWeb.RangeLive.Index do
%{"id" => id}
) do
socket
|> assign(:page_title, gettext("Record shots"))
|> assign(:page_title, gettext("Record Shots"))
|> assign(:ammo_group, Ammo.get_ammo_group!(id, current_user))
end
@ -67,7 +65,7 @@ defmodule CanneryWeb.RangeLive.Index do
{:ok, _ammo_group} =
ammo_group |> Ammo.update_ammo_group(%{"staged" => !ammo_group.staged}, current_user)
prompt = dgettext("prompts", "Ammo group unstaged succesfully")
prompt = dgettext("prompts", "Ammo unstaged succesfully")
{:noreply, socket |> put_flash(:info, prompt) |> display_shot_groups()}
end
@ -77,6 +75,69 @@ defmodule CanneryWeb.RangeLive.Index do
ActivityLog.list_shot_groups(current_user) |> Repo.preload(ammo_group: :ammo_type)
ammo_groups = Ammo.list_staged_ammo_groups(current_user)
socket |> assign(shot_groups: shot_groups, ammo_groups: ammo_groups)
columns = [
%{label: gettext("Ammo"), key: "name"},
%{label: gettext("Rounds shot"), key: "count"},
%{label: gettext("Notes"), key: "notes"},
%{label: gettext("Date"), key: "date"},
%{label: nil, key: "actions", sortable: false}
]
rows =
shot_groups
|> Enum.map(fn shot_group -> shot_group |> get_row_data_for_shot_group(columns) end)
socket
|> assign(ammo_groups: ammo_groups, columns: columns, rows: rows, shot_groups: shot_groups)
end
@spec get_row_data_for_shot_group(ShotGroup.t(), [map()]) :: [map()]
defp get_row_data_for_shot_group(%{date: date} = shot_group, columns) do
shot_group = shot_group |> Repo.preload(ammo_group: :ammo_type)
assigns = %{shot_group: shot_group}
columns
|> Enum.into(%{}, fn %{key: key} ->
value =
case key do
"name" ->
{shot_group.ammo_group.ammo_type.name,
live_patch(shot_group.ammo_group.ammo_type.name,
to: Routes.ammo_group_show_path(Endpoint, :show, shot_group.ammo_group),
class: "link"
)}
"date" ->
date |> display_date()
"actions" ->
~H"""
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_patch to: Routes.range_index_path(Endpoint, :edit, shot_group),
class: "text-primary-600 link",
data: [qa: "edit-#{shot_group.id}"] do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: shot_group.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this shot record?"),
qa: "delete-#{shot_group.id}"
] do %>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</div>
"""
key ->
shot_group |> Map.get(key |> String.to_existing_atom())
end
{key, value}
end)
end
end

View File

@ -53,70 +53,12 @@
<%= gettext("Shot log") %>
</h1>
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
<table class="min-w-full table-auto text-center bg-white">
<thead class="border-b border-primary-600">
<tr>
<th class="p-2">
<%= gettext("Ammo") %>
</th>
<th class="p-2">
<%= gettext("Rounds shot") %>
</th>
<th class="p-2">
<%= gettext("Notes") %>
</th>
<th class="p-2">
<%= gettext("Date") %>
</th>
<th class="p-2"></th>
</tr>
</thead>
<tbody id="shot_groups">
<%= for shot_group <- @shot_groups do %>
<tr id={"shot_group-#{shot_group.id}"}>
<td class="p-2">
<%= live_patch(shot_group.ammo_group.ammo_type.name,
to: Routes.ammo_group_show_path(Endpoint, :show, shot_group.ammo_group),
class: "link"
) %>
</td>
<td class="p-2">
<%= shot_group.count %>
</td>
<td class="p-2">
<%= shot_group.notes %>
</td>
<td class="p-2">
<%= shot_group.date |> display_date() %>
</td>
<td class="p-2 w-full h-full space-x-2 flex justify-center items-center">
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_patch to: Routes.range_index_path(Endpoint, :edit, shot_group),
class: "text-primary-600 link",
data: [qa: "edit-#{shot_group.id}"] do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: shot_group.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this shot record?"),
qa: "delete-#{shot_group.id}"
] do %>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<.live_component
module={CanneryWeb.Components.TableComponent}
id="shot_groups_index_table"
columns={@columns}
rows={@rows}
/>
<% end %>
</div>

View File

@ -12,19 +12,44 @@ defmodule CanneryWeb.TagLive.FormComponent do
@impl true
@spec update(%{:tag => Tag.t(), :current_user => User.t(), optional(any) => any}, Socket.t()) ::
{:ok, Socket.t()}
def update(%{tag: tag} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign(:changeset, Tags.change_tag(tag))}
def update(%{tag: _tag} = assigns, socket) do
{:ok, socket |> assign(assigns) |> assign_changeset(%{})}
end
@impl true
def handle_event("validate", %{"tag" => tag_params}, %{assigns: %{tag: tag}} = socket) do
{:noreply, socket |> assign(:changeset, tag |> Tags.change_tag(tag_params))}
def handle_event("validate", %{"tag" => tag_params}, socket) do
{:noreply, socket |> assign_changeset(tag_params)}
end
def handle_event("save", %{"tag" => tag_params}, %{assigns: %{action: action}} = socket) do
save_tag(socket, action, tag_params)
end
defp assign_changeset(
%{assigns: %{action: action, current_user: user, tag: tag}} = socket,
tag_params
) do
changeset_action =
case action do
:new -> :insert
:edit -> :update
end
changeset =
case action do
:new -> tag |> Tag.create_changeset(user, tag_params)
:edit -> tag |> Tag.update_changeset(tag_params)
end
changeset =
case changeset |> Changeset.apply_action(changeset_action) do
{:ok, _data} -> changeset
{:error, changeset} -> changeset
end
socket |> assign(:changeset, changeset)
end
@impl true
def render(assigns) do
~H"""
@ -36,7 +61,7 @@ defmodule CanneryWeb.TagLive.FormComponent do
let={f}
for={@changeset}
id="tag-form"
class="flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
phx-target={@myself}
phx-change="validate"
phx-submit="save"

View File

@ -9,13 +9,11 @@ defmodule CanneryWeb.TagLive.Index do
alias CanneryWeb.Endpoint
@impl true
def mount(_params, session, socket) do
{:ok, socket |> assign_defaults(session) |> display_tags()}
end
def mount(_params, _session, socket), do: {:ok, socket |> display_tags()}
@impl true
def handle_params(params, _url, %{assigns: %{live_action: live_action}} = socket) do
{:noreply, apply_action(socket, live_action, params)}
{:noreply, apply_action(socket, live_action, params) |> display_tags}
end
defp apply_action(%{assigns: %{current_user: current_user}} = socket, :edit, %{"id" => id}) do
@ -31,7 +29,7 @@ defmodule CanneryWeb.TagLive.Index do
end
defp apply_action(socket, :index, _params) do
socket |> assign(:page_title, gettext("Listing Tags")) |> assign(:tag, nil)
socket |> assign(:page_title, gettext("Tags")) |> assign(:tag, nil)
end
@impl true

View File

@ -11,6 +11,17 @@ defmodule CanneryWeb.Router do
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :fetch_current_user
plug :put_user_locale, default: Application.get_env(:gettext, :default_locale, "en_US")
end
defp put_user_locale(%{assigns: %{current_user: %{locale: locale}}} = conn, default: default) do
Gettext.put_locale(locale || default)
conn |> put_session(:locale, locale || default)
end
defp put_user_locale(conn, default: default) do
Gettext.put_locale(default)
conn |> put_session(:locale, default)
end
pipeline :require_admin do
@ -54,12 +65,12 @@ defmodule CanneryWeb.Router do
live "/tags/new", TagLive.Index, :new
live "/tags/:id/edit", TagLive.Index, :edit
live "/ammo_types", AmmoTypeLive.Index, :index
live "/ammo_types/new", AmmoTypeLive.Index, :new
live "/ammo_types/:id/edit", AmmoTypeLive.Index, :edit
live "/catalog", AmmoTypeLive.Index, :index
live "/catalog/new", AmmoTypeLive.Index, :new
live "/catalog/:id/edit", AmmoTypeLive.Index, :edit
live "/ammo_types/:id", AmmoTypeLive.Show, :show
live "/ammo_types/:id/show/edit", AmmoTypeLive.Show, :edit
live "/catalog/:id", AmmoTypeLive.Show, :show
live "/catalog/:id/show/edit", AmmoTypeLive.Show, :edit
live "/containers", ContainerLive.Index, :index
live "/containers/new", ContainerLive.Index, :new
@ -70,16 +81,17 @@ defmodule CanneryWeb.Router do
live "/containers/:id/show/edit", ContainerLive.Show, :edit
live "/containers/:id/show/edit_tags", ContainerLive.Show, :edit_tags
live "/ammo_groups", AmmoGroupLive.Index, :index
live "/ammo_groups/new", AmmoGroupLive.Index, :new
live "/ammo_groups/:id/edit", AmmoGroupLive.Index, :edit
live "/ammo_groups/:id/add_shot_group", AmmoGroupLive.Index, :add_shot_group
live "/ammo_groups/:id/move", AmmoGroupLive.Index, :move
live "/ammo", AmmoGroupLive.Index, :index
live "/ammo/new", AmmoGroupLive.Index, :new
live "/ammo/:id/edit", AmmoGroupLive.Index, :edit
live "/ammo/:id/add_shot_group", AmmoGroupLive.Index, :add_shot_group
live "/ammo/:id/move", AmmoGroupLive.Index, :move
live "/ammo_groups/:id", AmmoGroupLive.Show, :show
live "/ammo_groups/:id/show/edit", AmmoGroupLive.Show, :edit
live "/ammo_groups/:id/show/add_shot_group", AmmoGroupLive.Show, :add_shot_group
live "/ammo_groups/:id/show/move", AmmoGroupLive.Show, :move
live "/ammo/:id", AmmoGroupLive.Show, :show
live "/ammo/:id/show/edit", AmmoGroupLive.Show, :edit
live "/ammo/:id/show/add_shot_group", AmmoGroupLive.Show, :add_shot_group
live "/ammo/:id/show/move", AmmoGroupLive.Show, :move
live "/ammo/:id/show/:shot_group_id/edit", AmmoGroupLive.Show, :edit_shot_group
live "/range", RangeLive.Index, :index
live "/range/:id/edit", RangeLive.Index, :edit

View File

@ -8,7 +8,8 @@
<%= dgettext("errors", "Error") %>| Cannery
</title>
<link rel="stylesheet" href="/css/app.css" />
<script defer type="text/javascript" src="/js/app.js"></script>
<script defer type="text/javascript" src="/js/app.js">
</script>
</head>
<body class="pb-8 m-0 p-0 w-full h-full">
<header>
@ -16,9 +17,7 @@
</header>
<div class="pb-8 w-full flex flex-col justify-center items-center text-center">
<div
class="p-8 sm:p-16 w-full flex flex-col justify-center items-center space-y-4 max-w-3xl"
>
<div class="p-8 sm:p-16 w-full flex flex-col justify-center items-center space-y-4 max-w-3xl">
<h1 class="title text-primary-600 text-3xl">
<%= @error_string %>
</h1>

View File

@ -4,14 +4,10 @@
<%= @email.subject %>
</title>
</head>
<body
style="padding: 2em; color: rgb(31, 31, 31); background-color: rgb(220, 220, 228); font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; text-align: center;"
>
<body style="padding: 2em; color: rgb(31, 31, 31); background-color: rgb(220, 220, 228); font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif; text-align: center;">
<%= @inner_content %>
<hr
style="margin: 2em auto; border-width: 1px; border-color: rgb(212, 212, 216); width: 100%; max-width: 42rem;"
/>
<hr style="margin: 2em auto; border-width: 1px; border-color: rgb(212, 212, 216); width: 100%; max-width: 42rem;" />
<a style="color: rgb(31, 31, 31);" href={Routes.live_url(Endpoint, HomeLive)}>
<%= dgettext(

View File

@ -29,7 +29,7 @@
<div
id="loading"
class="absolute opacity-0 top-0 left-0 w-screen h-screen bg-white z-50
class="fixed opacity-0 top-0 left-0 w-screen h-screen bg-white z-50
flex flex-col justify-center items-center space-y-4
transition-opacity ease-in-out duration-500"
>
@ -37,12 +37,12 @@
<%= gettext("Loading...") %>
</h1>
<i class="fas fa-3x fa-spin fa-cog"></i>
<i class="fas fa-3x fa-spin fa-gear"></i>
</div>
<div
id="disconnect"
class="absolute opacity-0 top-0 left-0 w-screen h-screen bg-white z-50
class="fixed opacity-0 top-0 left-0 w-screen h-screen bg-white z-50
flex flex-col justify-center items-center space-y-4
transition-opacity ease-in-out duration-500"
>

View File

@ -1,15 +1,17 @@
<!DOCTYPE html>
<html lang="en" class="m-0 p-0 w-full h-full">
<html lang="en" class="m-0 p-0 w-full h-full bg-white">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<%= csrf_meta_tag() %>
<%= if(assigns |> Map.has_key?(:page_title),
do: "#{assigns.page_title} | Cannery",
else: "Cannery"
)
|> live_title_tag(suffix: "") %>
<link
rel="shortcut icon"
type="image/jpg"
href={Routes.static_path(@conn, "/images/cannery.svg")}
/>
<%= if(assigns |> Map.has_key?(:page_title), do: @page_title, else: "Cannery")
|> live_title_tag(suffix: " | Cannery") %>
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/css/app.css")} />
<script
defer
@ -20,7 +22,7 @@
</script>
</head>
<body class="m-0 p-0 w-full h-full">
<body class="m-0 p-0 w-full h-full bg-white">
<%= @inner_content %>
</body>
</html>

View File

@ -7,7 +7,7 @@
Routes.user_confirmation_path(@conn, :create),
[
class:
"flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
"flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
],
fn f -> %>
<%= label(f, :email, class: "title text-lg text-primary-600") %>

View File

@ -7,7 +7,7 @@
Routes.user_registration_path(@conn, :create),
[
class:
"flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
"flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
],
fn f -> %>
<%= if @changeset.action && not @changeset.valid? do %>
@ -30,6 +30,15 @@
<%= password_input(f, :password, required: true, class: "input input-primary col-span-2") %>
<%= error_tag(f, :password, "col-span-3") %>
<%= label(f, :locale, gettext("Language"), class: "title text-lg text-primary-600") %>
<%= select(
f,
:locale,
[{gettext("English"), "en_US"}, {gettext("German"), "de"}, {gettext("French"), "fr"}],
class: "input input-primary col-span-2"
) %>
<%= error_tag(f, :locale) %>
<%= submit(dgettext("actions", "Register"), class: "mx-auto btn btn-primary col-span-3") %>
<% end %>

View File

@ -7,7 +7,7 @@
Routes.user_reset_password_path(@conn, :update, @token),
[
class:
"flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
"flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
],
fn f -> %>
<%= if @changeset.action && not @changeset.valid? do %>

View File

@ -7,7 +7,7 @@
Routes.user_reset_password_path(@conn, :create),
[
class:
"flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
"flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
],
fn f -> %>
<%= label(f, :email, class: "title text-lg text-primary-600") %>

View File

@ -8,7 +8,7 @@
[
as: :user,
class:
"flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
"flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
],
fn f -> %>
<%= if @error_message do %>

View File

@ -1,17 +1,16 @@
<div class="mx-auto mb-8 max-w-2xl flex flex-col justify-center items-center space-y-4">
<div class="mx-auto mb-8 max-w-2xl flex flex-col justify-center items-center text-center space-y-4">
<h1 class="pb-4 title text-primary-600 text-xl">
<%= gettext("Settings") %>
</h1>
<hr class="hr" />
<%= form_for @email_changeset,
Routes.user_settings_path(@conn, :update),
[
class:
"pb-4 text-center flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
],
fn f -> %>
<.form
let={f}
for={@email_changeset}
action={Routes.user_settings_path(@conn, :update)}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<h3 class="title text-primary-600 text-lg col-span-3">
<%= dgettext("actions", "Change email") %>
</h3>
@ -45,17 +44,16 @@
<%= submit(dgettext("actions", "Change email"),
class: "mx-auto btn btn-primary col-span-3"
) %>
<% end %>
</.form>
<hr class="hr" />
<%= form_for @password_changeset,
Routes.user_settings_path(@conn, :update),
[
class:
"pb-4 text-center flex flex-col sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
],
fn f -> %>
<.form
let={f}
for={@password_changeset}
action={Routes.user_settings_path(@conn, :update)}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
>
<h3 class="title text-primary-600 text-lg col-span-3">
<%= dgettext("actions", "Change password") %>
</h3>
@ -101,8 +99,44 @@
<%= submit(dgettext("actions", "Change password"),
class: "mx-auto btn btn-primary col-span-3"
) %>
</.form>
<hr class="hr" />
<.form
let={f}
for={@locale_changeset}
action={Routes.user_settings_path(@conn, :update)}
class="flex flex-col space-y-4 justify-center items-center"
>
<h3 class="title text-primary-600 text-lg">
<%= dgettext("actions", "Change Language") %>
</h3>
<%= if @locale_changeset.action && not @locale_changeset.valid? do %>
<div class="alert alert-danger">
<p>
<%= dgettext("errors", "Oops, something went wrong! Please check the errors below.") %>
</p>
</div>
<% end %>
<%= hidden_input(f, :action, name: "action", value: "update_locale") %>
<%= select(
f,
:locale,
[{gettext("English"), "en_US"}, {gettext("German"), "de"}, {gettext("French"), "fr"}],
class: "mx-2 my-1 min-w-md input input-primary"
) %>
<%= error_tag(f, :locale) %>
<%= submit(dgettext("actions", "Change language"),
class: "whitespace-nowrap mx-auto btn btn-primary",
data: [qa: dgettext("prompts", "Are you sure you want to change your language?")]
) %>
</.form>
<hr class="hr" />
<%= link(dgettext("actions", "Delete User"),

View File

@ -2,7 +2,6 @@ defmodule CanneryWeb.EmailView do
@moduledoc """
A view for email-related helper functions
"""
alias CanneryWeb.{Endpoint, HomeLive}
use CanneryWeb, :view
alias CanneryWeb.{Endpoint, HomeLive}
end

View File

@ -8,7 +8,7 @@ defmodule CanneryWeb.ErrorView do
case error_path do
"404.html" -> dgettext("errors", "Not found")
"401.html" -> dgettext("errors", "Unauthorized")
_ -> dgettext("errors", "Internal Server Error")
_other_template -> dgettext("errors", "Internal Server Error")
end
render("error.html", %{error_string: error_string})

View File

@ -7,6 +7,8 @@ defmodule CanneryWeb.ViewHelpers do
import Phoenix.LiveView.Helpers
@id_length 16
@doc """
Returns a <time> element that renders the naivedatetime in the user's local
timezone with Alpine.js
@ -16,11 +18,12 @@ defmodule CanneryWeb.ViewHelpers do
def display_datetime(datetime) do
assigns = %{
id: :crypto.strong_rand_bytes(@id_length) |> Base.url_encode64(),
datetime: datetime |> DateTime.from_naive!("Etc/UTC") |> DateTime.to_iso8601(:extended)
}
~H"""
<time datetime={@datetime} x-data={"{
<time id={@id} datetime={@datetime} x-data={"{
date:
Intl.DateTimeFormat([], {dateStyle: 'short', timeStyle: 'long'})
.format(new Date(\"#{@datetime}\"))
@ -38,10 +41,13 @@ defmodule CanneryWeb.ViewHelpers do
def display_date(nil), do: ""
def display_date(date) do
assigns = %{date: date |> Date.to_iso8601(:extended)}
assigns = %{
id: :crypto.strong_rand_bytes(@id_length) |> Base.url_encode64(),
date: date |> Date.to_iso8601(:extended)
}
~H"""
<time datetime={@date} x-data={"{
<time id={@id} datetime={@date} x-data={"{
date:
Intl.DateTimeFormat([], {timeZone: 'Etc/UTC', dateStyle: 'short'}).format(new Date(\"#{@date}\"))
}"} x-text="date">

23
mix.exs
View File

@ -4,8 +4,8 @@ defmodule Cannery.MixProject do
def project do
[
app: :cannery,
version: "0.2.0",
elixir: "~> 1.12",
version: "0.5.5",
elixir: "1.13.4",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
@ -13,6 +13,7 @@ defmodule Cannery.MixProject do
deps: deps(),
dialyzer: [plt_add_apps: [:ex_unit]],
consolidate_protocols: Mix.env() not in [:dev, :test],
preferred_cli_env: [test: :test],
# ExDoc
name: "Cannery",
source_url: "https://gitea.bubbletea.dev/shibao/cannery",
@ -49,14 +50,14 @@ defmodule Cannery.MixProject do
{:bcrypt_elixir, "~> 2.0"},
{:phoenix, "~> 1.6"},
{:phoenix_ecto, "~> 4.4"},
{:ecto_sql, "~> 3.6"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 3.0"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.17"},
{:phoenix_view, "~> 1.1"},
{:floki, ">= 0.30.0", only: :test},
{:phoenix_live_dashboard, "~> 0.6"},
{:ecto_sql, "~> 3.6"},
{:postgrex, ">= 0.0.0"},
{:floki, ">= 0.30.0", only: :test},
# {:esbuild, "~> 0.3", runtime: Mix.env() == :dev},
{:ex_doc, "~> 0.27", only: :dev, runtime: false},
{:swoosh, "~> 1.6"},
@ -70,8 +71,7 @@ defmodule Cannery.MixProject do
{:plug_cowboy, "~> 2.5"},
{:ecto_psql_extras, "~> 0.6"},
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:heex_formatter, github: "feliperenan/heex_formatter"}
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false}
]
end
@ -86,12 +86,19 @@ defmodule Cannery.MixProject do
setup: ["deps.get", "compile", "ecto.setup", "cmd npm install --prefix assets"],
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
format: ["cmd npm run format --prefix assets", "format", "gettext.extract"],
format: [
"cmd npm run format --prefix assets",
"format",
"gettext.extract --merge",
"gettext.merge --no-fuzzy priv/gettext"
],
test: [
"cmd npm run test --prefix assets",
"dialyzer",
"credo --strict",
"format --check-formatted",
"gettext.extract --check-up-to-date",
"ecto.drop --quiet",
"ecto.create --quiet",
"ecto.migrate --quiet",
"test"

View File

@ -7,49 +7,50 @@
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
"credo": {:hex, :credo, "1.6.3", "0a9f8925dbc8f940031b789f4623fc9a0eea99d3eed600fe831e403eb96c6a83", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1167cde00e6661d740fc54da2ee268e35d3982f027399b64d3e2e83af57a1180"},
"db_connection": {:hex, :db_connection, "2.4.1", "6411f6e23f1a8b68a82fa3a36366d4881f21f47fc79a9efb8c615e62050219da", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ea36d226ec5999781a9a8ad64e5d8c4454ecedc7a4d643e4832bf08efca01f00"},
"credo": {:hex, :credo, "1.6.4", "ddd474afb6e8c240313f3a7b0d025cc3213f0d171879429bf8535d7021d9ad78", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "c28f910b61e1ff829bffa056ef7293a8db50e87f2c57a9b5c3f57eee124536b7"},
"db_connection": {:hex, :db_connection, "2.4.2", "f92e79aff2375299a16bcb069a14ee8615c3414863a6fef93156aee8e86c2ff3", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4fe53ca91b99f55ea249693a0229356a08f4d1a7931d8ffa79289b145fe83668"},
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.19", "de0d033d5ff9fc396a24eadc2fcf2afa3d120841eb3f1004d138cbf9273210e8", [:mix], [], "hexpm", "527ab6630b5c75c3a3960b75844c314ec305c76d9899bb30f71cb85952a9dc45"},
"ecto": {:hex, :ecto, "3.7.1", "a20598862351b29f80f285b21ec5297da1181c0442687f9b8329f0445d228892", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d36e5b39fc479e654cffd4dbe1865d9716e4a9b6311faff799b6f90ab81b8638"},
"earmark_parser": {:hex, :earmark_parser, "1.4.25", "2024618731c55ebfcc5439d756852ec4e85978a39d0d58593763924d9a15916f", [:mix], [], "hexpm", "56749c5e1c59447f7b7a23ddb235e4b3defe276afc220a6227237f3efe83f51e"},
"ecto": {:hex, :ecto, "3.8.2", "7b9aca632f9da80ffed525354e4de466a66e042abcbc8509b6b600072c8d8ee0", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "afe2912cc23f61a6a8466c158331d54e0f427029dd97ca936644bc116d6599b3"},
"ecto_psql_extras": {:hex, :ecto_psql_extras, "0.7.4", "5d43fd088d39a158c860b17e8d210669587f63ec89ea122a4654861c8c6e2db4", [:mix], [{:ecto_sql, "~> 3.4", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.15.7", [hex: :postgrex, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.1.1", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "311db02f1b772e3d0dc7f56a05044b5e1499d78ed6abf38885e1ca70059449e5"},
"ecto_sql": {:hex, :ecto_sql, "3.7.2", "55c60aa3a06168912abf145c6df38b0295c34118c3624cf7a6977cd6ce043081", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.7.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0 or ~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3c218ea62f305dcaef0b915fb56583195e7b91c91dcfb006ba1f669bfacbff2a"},
"ecto_sql": {:hex, :ecto_sql, "3.8.1", "1acaaba32ca0551fd19e492fc7c80414e72fc1a7140fc9395aaa53c2e8629798", [:mix], [{:db_connection, "~> 2.5 or ~> 2.4.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.8.1", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 0.16.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ba7fc75882edce6f2ceca047315d5db27ead773cafea47f1724e35f1e7964525"},
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"esbuild": {:hex, :esbuild, "0.4.0", "9f17db148aead4cf1e6e6a584214357287a93407b5fb51a031f122b61385d4c2", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "b61e4e6b92ffe45e4ee4755a22de6211a67c67987dc02afb35a425a0add1d447"},
"ex_doc": {:hex, :ex_doc, "0.28.0", "7eaf526dd8c80ae8c04d52ac8801594426ae322b52a6156cd038f30bafa8226f", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e55cdadf69a5d1f4cfd8477122ebac5e1fadd433a8c1022dafc5025e48db0131"},
"ex_doc": {:hex, :ex_doc, "0.28.4", "001a0ea6beac2f810f1abc3dbf4b123e9593eaa5f00dd13ded024eae7c523298", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bf85d003dd34911d89c8ddb8bda1a958af3471a274a4c2150a9c01c78ac3f8ed"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"floki": {:hex, :floki, "0.32.0", "f915dc15258bc997d49be1f5ef7d3992f8834d6f5695270acad17b41f5bcc8e2", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "1c5a91cae1fd8931c26a4826b5e2372c284813904c8bacb468b5de39c7ececbd"},
"gen_smtp": {:hex, :gen_smtp, "1.1.1", "bf9303c31735100631b1d708d629e4c65944319d1143b5c9952054f4a1311d85", [:rebar3], [{:hut, "1.3.0", [hex: :hut, repo: "hexpm", optional: false]}, {:ranch, ">= 1.7.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "51bc50cc017efd4a4248cbc39ea30fb60efa7d4a49688986fafad84434ff9ab7"},
"floki": {:hex, :floki, "0.32.1", "dfe3b8db3b793939c264e6f785bca01753d17318d144bd44b407fb3493acaa87", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "d4b91c713e4a784a3f7b1e3cc016eefc619f6b1c3898464222867cafd3c681a3"},
"gen_smtp": {:hex, :gen_smtp, "1.2.0", "9cfc75c72a8821588b9b9fe947ae5ab2aed95a052b81237e0928633a13276fd3", [:rebar3], [{:ranch, ">= 1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "5ee0375680bca8f20c4d85f58c2894441443a743355430ff33a783fe03296779"},
"gettext": {:hex, :gettext, "0.19.1", "564953fd21f29358e68b91634799d9d26989f8d039d7512622efb3c3b1c97892", [:mix], [], "hexpm", "10c656c0912b8299adba9b061c06947511e3f109ab0d18b44a866a4498e77222"},
"heex_formatter": {:git, "https://github.com/feliperenan/heex_formatter.git", "dfefc9ae267fb0874c287ceb6c47dda106c59552", []},
"html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
"hut": {:hex, :hut, "1.3.0", "71f2f054e657c03f959cf1acc43f436ea87580696528ca2a55c8afb1b06c85e7", [:"erlang.mk", :rebar, :rebar3], [], "hexpm", "7e15d28555d8a1f2b5a3a931ec120af0753e4853a4c66053db354f35bf9ab563"},
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.2", "b99ca56bbce410e9d5ee4f9155a212e942e224e259c7ebbf8f2c86ac21d4fa3c", [:mix], [], "hexpm", "98d51bd64d5f6a2a9c6bb7586ee8129e27dfaab1140b5a4753f24dac0ba27d2f"},
"oban": {:hex, :oban, "2.11.0", "5cc4800829b995bfa1c3841d8b0c1037b4a6444b2a76896edd2215c4c4d047a8", [:mix], [{:ecto_sql, "~> 3.6", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4ec90805d04562e83cc798f3ecd514d24f4479a14883e1e8973d5123ec087e35"},
"phoenix": {:hex, :phoenix, "1.6.6", "281c8ce8dccc9f60607346b72cdfc597c3dde134dd9df28dff08282f0b751754", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "807bd646e64cd9dc83db016199715faba72758e6db1de0707eef0a2da4924364"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"oban": {:hex, :oban, "2.12.0", "bd5a283770c6ab1284aad81e5566cfb89f4119b08f52508d92d73551283c8789", [:mix], [{:ecto_sql, "~> 3.6", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.16", [hex: :postgrex, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1557b7b046b13c0b5360f55a9fb7e56975f6b5f8247e56f2c54575bd95435ca0"},
"phoenix": {:hex, :phoenix, "1.6.8", "9a34e5f4dd3ba959176c199fd5b2277b02e64005462428b71cf6ce9cb5e09cb4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9f4d616aeb9c5e019bddfc1f9078b8c06f852ffa838e67f925559cc0993e9f71"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"},
"phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"},
"phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.6.4", "d7ff34b2c8dd5fa950748496697da01ae1b6b259891ce1103e300bdc7abfbb99", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.3", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.17.1", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "ce2505256ab459663258ecba4158af130e6b7a5b85783fe442541fbb1236e1b2"},
"phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.6.5", "1495bb014be12c9a9252eca04b9af54246f6b5c1e4cd1f30210cd00ec540cf8e", [:mix], [{:ecto, "~> 3.6.2 or ~> 3.7", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_mysql_extras, "~> 0.3", [hex: :ecto_mysql_extras, repo: "hexpm", optional: true]}, {:ecto_psql_extras, "~> 0.7", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.17.7", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "ef4fa50dd78364409039c99cf6f98ab5209b4c5f8796c17f4db118324f0db852"},
"phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"},
"phoenix_live_view": {:hex, :phoenix_live_view, "0.17.7", "05a42377075868a678d446361effba80cefef19ab98941c01a7a4c7560b29121", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.9 or ~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "25eaf41028eb351b90d4f69671874643a09944098fefd0d01d442f40a6091b6f"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
"phoenix_live_view": {:hex, :phoenix_live_view, "0.17.9", "36b5aa812bc3ccd64c9630f6b3234d9ea21105493237e927aae19d0ba758f0db", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6.0", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.1", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f7ebc3e0ba0c5f6b6996ed6c901ddbfdaba59a6d09b569e7cb2f2f7d693b4455"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"},
"phoenix_swoosh": {:hex, :phoenix_swoosh, "1.0.1", "0db6eb6405a6b06cae4fdf4144659b3f4fee4553e2856fe8a53ba12e9fb21a74", [:mix], [{:finch, "~> 0.8", [hex: :finch, repo: "hexpm", optional: true]}, {:hackney, "~> 1.10", [hex: :hackney, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.6", [hex: :phoenix, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:swoosh, "~> 1.5", [hex: :swoosh, repo: "hexpm", optional: false]}], "hexpm", "e34890004baec08f0fa12bd8c77bf64bfb4156b84a07fb79da9322fa94bc3781"},
"phoenix_view": {:hex, :phoenix_view, "1.1.2", "1b82764a065fb41051637872c7bd07ed2fdb6f5c3bd89684d4dca6e10115c95a", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "7ae90ad27b09091266f6adbb61e1d2516a7c3d7062c6789d46a7554ec40f3a56"},
"plug": {:hex, :plug, "1.13.3", "93b299039c21a8b82cc904d13812bce4ced45cf69153e8d35ca16ffb3e8c5d98", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "98c8003e4faf7b74a9ac41bee99e328b08f069bf932747d4a7532e97ae837a17"},
"plug": {:hex, :plug, "1.13.6", "187beb6b67c6cec50503e940f0434ea4692b19384d47e5fdfd701e93cadb4cc2", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "02b9c6b9955bce92c829f31d6284bf53c591ca63c4fb9ff81dfd0418667a34ff"},
"plug_cowboy": {:hex, :plug_cowboy, "2.5.2", "62894ccd601cf9597e2c23911ff12798a8a18d237e9739f58a6b04e4988899fe", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "ea6e87f774c8608d60c8d34022a7d073bd7680a0a013f049fc62bf35efea1044"},
"plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
"postgrex": {:hex, :postgrex, "0.16.1", "f94628a32c571266f53cd1e5fca705e626e2417bf1eee6f868985d14e874160a", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "6b225df32c857b9430619dbe30200a7ae664e23415a771ae9209396ee8eeee64"},
"postgrex": {:hex, :postgrex, "0.16.3", "fac79a81a9a234b11c44235a4494d8565303fa4b9147acf57e48978a074971db", [:mix], [{:connection, "~> 1.1", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "aeaae1d2d1322da4e5fe90d241b0a564ce03a3add09d7270fb85362166194590"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"swoosh": {:hex, :swoosh, "1.6.3", "598d3f07641004bedb3eede40057760ae18be1073cff72f079ca1e1fc9cd97b9", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "81ff9d7c7c4005a57465a7eb712edd71db51829aef94c8a34c30c5b9e9964adf"},
"set_locale": {:hex, :set_locale, "0.2.9", "33350ba3c66f1c560dffc43019eea4b573f91c5cbe3e461fe0e5395d2d6ba2c3", [:mix], [{:gettext, "~>0.14", [hex: :gettext, repo: "hexpm", optional: false]}, {:phoenix, ">1.3.0", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "e46348b64b7c5d725d0c90a6524942a19b65e6ce27372ddf9a727dfb64ba236c"},
"swoosh": {:hex, :swoosh, "1.6.6", "6018c6f4659ac0b4f30684982993b7812b2bb97436d39f76fcfa8c9e3ae74f85", [:mix], [{:cowboy, "~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:ex_aws, "~> 2.1", [hex: :ex_aws, repo: "hexpm", optional: true]}, {:finch, "~> 0.6", [hex: :finch, repo: "hexpm", optional: true]}, {:gen_smtp, "~> 0.13 or ~> 1.0", [hex: :gen_smtp, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mail, "~> 0.2", [hex: :mail, repo: "hexpm", optional: true]}, {:mime, "~> 1.1 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_cowboy, ">= 1.0.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.2 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e92c7206efd442f08484993676ab072afab2f2bb1e87e604230bb1183c5980de"},
"table_rex": {:hex, :table_rex, "3.1.1", "0c67164d1714b5e806d5067c1e96ff098ba7ae79413cc075973e17c38a587caa", [:mix], [], "hexpm", "678a23aba4d670419c23c17790f9dcd635a4a89022040df7d5d772cb21012490"},
"telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"},
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
"telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"},
}

View File

@ -11,12 +11,13 @@ msgid ""
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/index.ex:42
#: lib/cannery_web/live/ammo_group_live/index.ex:44
#: lib/cannery_web/live/ammo_group_live/index.html.heex:42
msgid "Add Ammo"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/index.html.heex:12
#: lib/cannery_web/live/ammo_group_live/index.html.heex:37
msgid "Add your first box!"
msgstr ""
@ -31,14 +32,14 @@ msgid "Add your first type!"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/templates/user_settings/edit.html.heex:16
#: lib/cannery_web/templates/user_settings/edit.html.heex:45
#: lib/cannery_web/templates/user_settings/edit.html.heex:15
#: lib/cannery_web/templates/user_settings/edit.html.heex:44
msgid "Change email"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/templates/user_settings/edit.html.heex:60
#: lib/cannery_web/templates/user_settings/edit.html.heex:101
#: lib/cannery_web/templates/user_settings/edit.html.heex:58
#: lib/cannery_web/templates/user_settings/edit.html.heex:99
msgid "Change password"
msgstr ""
@ -48,12 +49,12 @@ msgid "Create Invite"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/templates/user_settings/edit.html.heex:108
#: lib/cannery_web/templates/user_settings/edit.html.heex:142
msgid "Delete User"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/templates/user_registration/new.html.heex:43
#: lib/cannery_web/templates/user_registration/new.html.heex:52
#: lib/cannery_web/templates/user_reset_password/new.html.heex:3
#: lib/cannery_web/templates/user_session/new.html.heex:45
msgid "Forgot your password?"
@ -65,9 +66,9 @@ msgid "Invite someone new!"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/components/topbar.ex:108
#: lib/cannery_web/components/topbar.ex:112
#: lib/cannery_web/templates/user_confirmation/new.html.heex:30
#: lib/cannery_web/templates/user_registration/new.html.heex:39
#: lib/cannery_web/templates/user_registration/new.html.heex:48
#: lib/cannery_web/templates/user_reset_password/edit.html.heex:48
#: lib/cannery_web/templates/user_reset_password/new.html.heex:30
#: lib/cannery_web/templates/user_session/new.html.heex:3
@ -80,11 +81,6 @@ msgstr ""
msgid "Make your first tag!"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/index.html.heex:17
msgid "New Ammo group"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_type_live/index.html.heex:17
msgid "New Ammo type"
@ -101,10 +97,10 @@ msgid "New Tag"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/components/topbar.ex:101
#: lib/cannery_web/components/topbar.ex:105
#: lib/cannery_web/templates/user_confirmation/new.html.heex:25
#: lib/cannery_web/templates/user_registration/new.html.heex:3
#: lib/cannery_web/templates/user_registration/new.html.heex:33
#: lib/cannery_web/templates/user_registration/new.html.heex:42
#: lib/cannery_web/templates/user_reset_password/edit.html.heex:43
#: lib/cannery_web/templates/user_reset_password/new.html.heex:25
#: lib/cannery_web/templates/user_session/new.html.heex:40
@ -124,13 +120,13 @@ msgid "Reset password"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/components/add_shot_group_component.html.heex:42
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:54
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:172
#: lib/cannery_web/components/add_shot_group_component.html.heex:46
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:73
#: lib/cannery_web/live/ammo_type_live/form_component.html.heex:156
#: lib/cannery_web/live/container_live/form_component.html.heex:50
#: lib/cannery_web/live/invite_live/form_component.html.heex:28
#: lib/cannery_web/live/invite_live/form_component.html.heex:31
#: lib/cannery_web/live/range_live/form_component.html.heex:40
#: lib/cannery_web/live/tag_live/form_component.ex:66
#: lib/cannery_web/live/tag_live/form_component.ex:91
msgid "Save"
msgstr ""
@ -140,7 +136,7 @@ msgid "Send instructions to reset password"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/container_live/show.html.heex:53
#: lib/cannery_web/live/container_live/show.html.heex:65
msgid "Why not add one?"
msgstr ""
@ -160,29 +156,24 @@ msgid "Why not get some ready to shoot?"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/index.html.heex:85
#: lib/cannery_web/live/ammo_group_live/show.html.heex:86
#: lib/cannery_web/live/ammo_group_live/index.ex:151
#: lib/cannery_web/live/ammo_group_live/show.html.heex:91
#: lib/cannery_web/live/range_live/index.html.heex:36
msgid "Record shots"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/show.html.heex:50
msgid "Ammo Details"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/components/move_ammo_group_component.html.heex:12
#: lib/cannery_web/components/move_ammo_group_component.ex:89
msgid "Add another container!"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/show.html.heex:80
#: lib/cannery_web/live/ammo_group_live/show.html.heex:85
msgid "Move containers"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/components/move_ammo_group_component.html.heex:60
#: lib/cannery_web/components/move_ammo_group_component.ex:127
msgid "Select"
msgstr ""
@ -190,3 +181,33 @@ msgstr ""
#: lib/cannery_web/live/invite_live/index.html.heex:33
msgid "Copy to clipboard"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/index.html.heex:20
msgid "add a container first"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/form_component.html.heex:66
msgid "Create"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/templates/user_settings/edit.html.heex:113
msgid "Change Language"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/templates/user_settings/edit.html.heex:134
msgid "Change language"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/show.html.heex:55
msgid "View in Catalog"
msgstr ""
#, elixir-autogen, elixir-format
#: lib/cannery_web/live/ammo_group_live/index.html.heex:31
msgid "add an ammo type first"
msgstr ""

Some files were not shown because too many files have changed in this diff Show More