feat(vereinfacht): add client, sync flash and SyncContact change
- Application: create SyncFlash ETS table on start - Vereinfacht: Client, SyncFlash, sync_member, format_error, sync_members_without_contact - SyncContact change on Member create_member and update_member - Member: attribute vereinfacht_contact_id, internal action set_vereinfacht_contact_id
This commit is contained in:
parent
b775f5f5c4
commit
3a61699dd2
7 changed files with 551 additions and 1 deletions
44
lib/mv/vereinfacht/sync_flash.ex
Normal file
44
lib/mv/vereinfacht/sync_flash.ex
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
defmodule Mv.Vereinfacht.SyncFlash do
|
||||
@moduledoc """
|
||||
Short-lived store for Vereinfacht sync results so the UI can show them after save.
|
||||
|
||||
The SyncContact change runs in after_transaction and cannot access the LiveView
|
||||
socket. This module stores a message keyed by member_id; the form LiveView
|
||||
calls `take/1` after a successful save and displays the message in flash.
|
||||
"""
|
||||
@table :vereinfacht_sync_flash
|
||||
|
||||
@doc """
|
||||
Stores a sync result for the given member. Overwrites any previous message.
|
||||
|
||||
- `:ok` - Sync succeeded (optional user message).
|
||||
- `:warning` - Sync failed; message should be shown as a warning.
|
||||
"""
|
||||
@spec store(String.t(), :ok | :warning, String.t()) :: :ok
|
||||
def store(member_id, kind, message) when is_binary(member_id) do
|
||||
:ets.insert(@table, {member_id, {kind, message}})
|
||||
:ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
Takes and removes the stored sync message for the given member.
|
||||
|
||||
Returns `{kind, message}` if present, otherwise `nil`.
|
||||
"""
|
||||
@spec take(String.t()) :: {:ok | :warning, String.t()} | nil
|
||||
def take(member_id) when is_binary(member_id) do
|
||||
case :ets.take(@table, member_id) do
|
||||
[{^member_id, value}] -> value
|
||||
[] -> nil
|
||||
end
|
||||
end
|
||||
|
||||
@doc false
|
||||
def create_table! do
|
||||
if :ets.whereis(@table) == :undefined do
|
||||
:ets.new(@table, [:set, :public, :named_table])
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue