Compare commits

...

5 Commits

Author SHA1 Message Date
CI
ce8e6fbfb0 chore: release version v1.11.3 2024-10-16 05:51:27 +00:00
Dmitry Popov
a20eaed76b Merge branch 'main' of github.com:wanderer-industries/wanderer 2024-10-16 09:50:49 +04:00
Dmitry Popov
419af72028 chore: release version v1.11.1 2024-10-16 09:50:45 +04:00
CI
8e499522f6 chore: release version v1.11.2 2024-10-15 22:13:53 +00:00
Dmitry Popov
84321b847e chore: release version v1.11.1 2024-10-16 02:13:18 +04:00
6 changed files with 205 additions and 162 deletions

View File

@@ -2,6 +2,16 @@
<!-- changelog -->
## [v1.11.3](https://github.com/wanderer-industries/wanderer/compare/v1.11.2...v1.11.3) (2024-10-16)
## [v1.11.2](https://github.com/wanderer-industries/wanderer/compare/v1.11.1...v1.11.2) (2024-10-15)
## [v1.11.1](https://github.com/wanderer-industries/wanderer/compare/v1.11.0...v1.11.1) (2024-10-14)

View File

@@ -15,10 +15,23 @@ defmodule WandererApp.MapRepo do
end
end
def get_by_slug_with_permissions(map_slug, current_user),
do:
map_slug
|> WandererApp.Api.Map.get_map_by_slug()
|> load_user_permissions(current_user)
def load_relationships(map, []), do: {:ok, map}
def load_relationships(map, relationships), do: map |> Ash.load(relationships)
defp load_user_permissions({:ok, map}, current_user),
do:
map
|> Ash.load([:acls, :user_permissions], actor: current_user)
defp load_user_permissions(error, _current_user), do: error
def update_hubs(map_id, hubs) do
map_id
|> WandererApp.Api.Map.by_id()
@@ -36,7 +49,9 @@ defmodule WandererApp.MapRepo do
map
|> WandererApp.Api.Map.update_options(%{options: Jason.encode!(options)})
def options_to_form_data(%{options: options} = _map_options) when not is_nil(options), do: {:ok, Jason.decode!(options)}
def options_to_form_data(%{options: options} = _map_options) when not is_nil(options),
do: {:ok, Jason.decode!(options)}
def options_to_form_data(_), do: {:ok, @default_map_options}
def options_to_form_data!(options) do

View File

@@ -38,7 +38,9 @@ defmodule WandererApp.MapSystemRepo do
end
def cleanup_labels(%{labels: labels} = system, opts) do
store_custom_labels? = Keyword.get(opts, :store_custom_labels, "false") |> String.to_existing_atom()
store_custom_labels? =
Keyword.get(opts, :store_custom_labels, "false") |> String.to_existing_atom()
labels = get_filtered_labels(labels, store_custom_labels?)
system
@@ -54,10 +56,12 @@ defmodule WandererApp.MapSystemRepo do
%{"customLabel" => customLabel} = labels when is_binary(customLabel) ->
%{"customLabel" => customLabel, "labels" => []}
|> Jason.encode!()
_ ->
nil
end
end
def get_filtered_labels(_, _store_custom_labels), do: nil
def update_name(system, update),

View File

@@ -62,6 +62,7 @@ defmodule WandererAppWeb do
use Phoenix.LiveView, @opts
unquote(html_helpers())
defguard is_connected?(socket) when socket.transport_pid != nil
end
end

View File

@@ -4,57 +4,14 @@ defmodule WandererAppWeb.MapLive do
require Logger
@impl true
def mount(params, _session, socket) do
def mount(params, _session, socket) when is_connected?(socket) do
socket =
with %{"slug" => map_slug} <- params do
socket
|> _init_state(map_slug)
else
_ ->
# redirect back to main
socket
|> assign(
map_loaded?: false,
maps_loading: false,
selected_subscription: nil,
maps: [],
map: nil,
map_id: nil,
map_slug: nil,
user_permissions: nil,
form: to_form(%{"map_slug" => nil})
)
end
{:ok, socket |> assign(server_online: false)}
end
defp _init_state(socket, map_slug) do
current_user = socket.assigns.current_user
ErrorTracker.set_context(%{user_id: current_user.id})
Task.async(fn -> _get_available_maps(current_user) end)
map_slug
|> WandererApp.Api.Map.get_map_by_slug()
|> _load_user_permissions(current_user)
|> case do
{:ok,
%{
id: map_id,
deleted: false
} = map} ->
Process.send_after(self(), {:init_map, map}, 10)
Process.send_after(self(), {:load_map, map_slug}, Enum.random(10..200))
socket
|> assign(
map: map,
map_id: map_id,
map_loaded?: false,
maps_loading: true,
maps: [],
user_permissions: nil,
selected_subscription: nil,
map_slug: map_slug,
form: to_form(%{"map_slug" => map_slug})
)
@@ -63,26 +20,42 @@ defmodule WandererAppWeb.MapLive do
attr: "data-loading",
timeout: 2000
})
else
_ ->
# redirect back to main
socket
|> assign(
maps_loading: false,
map_id: nil,
map_slug: nil,
form: to_form(%{"map_slug" => nil})
)
end
{:ok,
%{
deleted: true
} = _map} ->
socket
|> put_flash(
:error,
"Map was deleted by owner or administrator."
)
|> push_navigate(to: ~p"/maps")
{:ok,
socket
|> assign(
map_loaded?: false,
maps: [],
server_online: false,
selected_subscription: nil,
user_permissions: nil
)}
end
{:error, _} ->
socket
|> put_flash(
:error,
"Something went wrong. Please try one more time or submit an issue."
)
|> push_navigate(to: ~p"/maps")
end
@impl true
def mount(_params, _session, socket) do
{:ok,
socket
|> assign(
maps_loading: false,
map_loaded?: false,
maps: [],
server_online: false,
selected_subscription: nil,
user_permissions: nil,
form: to_form(%{"map_slug" => nil})
)}
end
@impl true
@@ -90,18 +63,6 @@ defmodule WandererAppWeb.MapLive do
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
end
defp apply_action(socket, :index, _params) do
socket
|> assign(:active_page, :map)
end
defp apply_action(socket, :add_system, _params) do
socket
|> assign(:active_page, :map)
|> assign(:page_title, "Add System")
|> assign(:add_system_form, to_form(%{"system_id" => nil}))
end
@impl true
def handle_info(
%{event: :map_started},
@@ -435,7 +396,49 @@ defmodule WandererAppWeb.MapLive do
{:noreply, socket}
end
def handle_info({:init_map, map}, %{assigns: %{current_user: current_user}} = socket) do
def handle_info({:load_map, map_slug}, %{assigns: %{current_user: current_user}} = socket) do
ErrorTracker.set_context(%{user_id: current_user.id})
Task.async(fn -> _get_available_maps(current_user) end)
map_slug
|> WandererApp.MapRepo.get_by_slug_with_permissions(current_user)
|> case do
{:ok,
%{
id: map_id,
deleted: false
} = map} ->
Process.send_after(self(), {:init_map, map}, 10)
{:noreply, socket}
{:ok,
%{
deleted: true
} = _map} ->
{:noreply,
socket
|> put_flash(
:error,
"Map was deleted by owner or administrator."
)
|> push_navigate(to: ~p"/maps")}
{:error, _} ->
{:noreply,
socket
|> put_flash(
:error,
"Something went wrong. Please try one more time or submit an issue."
)
|> push_navigate(to: ~p"/maps")}
end
end
def handle_info(
{:init_map, map},
%{assigns: %{current_user: current_user, map_slug: map_slug}} = socket
) do
with %{
id: map_id,
deleted: false,
@@ -473,38 +476,36 @@ defmodule WandererAppWeb.MapLive do
cond do
(only_tracked_characters and can_track? and all_character_tracked?) or
(not only_tracked_characters and can_view?) ->
Process.send_after(
self(),
{:map_init,
%{
map_id: map_id,
page_title: map_name,
user_permissions: user_permissions,
tracked_character_ids: tracked_character_ids
}},
10
)
Phoenix.PubSub.subscribe(WandererApp.PubSub, map_id)
{:ok, ui_loaded} = WandererApp.Cache.get_and_remove("map_#{map_slug}:ui_loaded", false)
if ui_loaded do
maybe_start_map(map_id)
end
{:noreply,
socket
|> assign(
map_id: map_id,
page_title: map_name,
user_permissions: user_permissions,
tracked_character_ids: tracked_character_ids,
only_tracked_characters: only_tracked_characters
)}
only_tracked_characters and can_track? and not all_character_tracked? ->
Process.send_after(self(), :not_all_characters_tracked, 10)
{:noreply, socket}
true ->
Process.send_after(self(), :no_permissions, 10)
{:noreply, socket}
end
else
_ ->
Process.send_after(self(), :no_access, 10)
{:noreply, socket}
end
{:noreply, socket}
end
def handle_info({:map_init, %{map_id: map_id} = initial_data}, socket) do
Phoenix.PubSub.subscribe(WandererApp.PubSub, map_id)
{:noreply,
socket
|> assign(initial_data)}
end
def handle_info(
@@ -553,38 +554,16 @@ defmodule WandererAppWeb.MapLive do
end
end)
Process.send_after(
self(),
{:map_loaded,
%{
map_id: map_id,
initial_data: initial_data
}},
10
)
{:noreply,
socket
|> assign(
map_user_settings: map_user_settings,
user_characters: user_character_eve_ids,
has_tracked_characters?: _has_tracked_characters?(user_character_eve_ids)
)}
end
def handle_info(
{:map_loaded,
%{
map_id: map_id,
initial_data: initial_data
} = _loaded_data},
socket
) do
map_characters = map_id |> WandererApp.Map.list_characters()
{:noreply,
socket
|> assign(map_loaded?: true)
|> assign(
map_loaded?: true,
map_user_settings: map_user_settings,
user_characters: user_character_eve_ids,
has_tracked_characters?: _has_tracked_characters?(user_character_eve_ids)
)
|> push_map_event(
"init",
initial_data |> Map.put(:characters, map_characters |> Enum.map(&map_ui_character/1))
@@ -671,13 +650,15 @@ defmodule WandererAppWeb.MapLive do
def handle_info(_event, socket), do: {:noreply, socket}
@impl true
def handle_event("ui_loaded", _body, %{assigns: %{map_id: map_id}} = socket) do
{:ok, map_started} = WandererApp.Cache.lookup("map_#{map_id}:started", false)
def handle_event("ui_loaded", _body, %{assigns: %{map_slug: map_slug} = assigns} = socket) do
assigns
|> Map.get(:map_id)
|> case do
map_id when not is_nil(map_id) ->
maybe_start_map(map_id)
if map_started do
Process.send_after(self(), %{event: :map_started}, 10)
else
WandererApp.Map.Manager.start_map(map_id)
_ ->
WandererApp.Cache.insert("map_#{map_slug}:ui_loaded", true)
end
{:noreply, socket}
@@ -1428,14 +1409,18 @@ defmodule WandererAppWeb.MapLive do
end
@impl true
def handle_event("add_character", _, %{assigns: assigns} = socket) do
def handle_event(
"add_character",
_,
%{assigns: %{current_user: current_user, map_id: map_id, user_permissions: user_permissions}} = socket
) do
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: assigns.map_id}) do
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: map_id}) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
end
case assigns.user_permissions.track_character do
case user_permissions.track_character do
true ->
{:noreply,
socket
@@ -1444,10 +1429,14 @@ defmodule WandererAppWeb.MapLive do
character_settings: character_settings
)
|> assign_async(:characters, fn ->
WandererApp.Maps.load_characters(
assigns.map |> Ash.load!(:acls),
{:ok, map} =
map_id
|> WandererApp.MapRepo.get([:acls])
map
|> WandererApp.Maps.load_characters(
character_settings,
assigns.current_user.id
current_user.id
)
end)}
@@ -1467,24 +1456,33 @@ defmodule WandererAppWeb.MapLive do
end
@impl true
def handle_event("toggle_track", %{"character-id" => character_id}, socket) do
map = socket.assigns.map
character_settings = socket.assigns.character_settings
def handle_event(
"toggle_track",
%{"character-id" => character_id},
%{
assigns: %{
map_id: map_id,
map_slug: map_slug,
character_settings: character_settings,
current_user: current_user,
only_tracked_characters: only_tracked_characters
}
} = socket
) do
socket =
case character_settings |> Enum.find(&(&1.character_id == character_id)) do
nil ->
{:ok, map_character_settings} =
WandererApp.Api.MapCharacterSettings.create(%{
character_id: character_id,
map_id: map.id,
map_id: map_id,
tracked: true
})
character = map_character_settings |> Ash.load!(:character) |> Map.get(:character)
:ok = _track_characters([character], map.id, true)
:ok = _add_characters([character], map.id, true)
:ok = _track_characters([character], map_id, true)
:ok = _add_characters([character], map_id, true)
socket
@@ -1497,16 +1495,16 @@ defmodule WandererAppWeb.MapLive do
character = map_character_settings |> Ash.load!(:character) |> Map.get(:character)
:ok = _untrack_characters([character], map.id)
:ok = _remove_characters([character], map.id)
:ok = _untrack_characters([character], map_id)
:ok = _remove_characters([character], map_id)
if map.only_tracked_characters do
if only_tracked_characters do
socket
|> put_flash(
:error,
"You should enable tracking for all characters that have access to this map first!"
)
|> push_navigate(to: ~p"/tracking/#{map.slug}")
|> push_navigate(to: ~p"/tracking/#{map_slug}")
else
socket
end
@@ -1518,8 +1516,8 @@ defmodule WandererAppWeb.MapLive do
character = map_character_settings |> Ash.load!(:character) |> Map.get(:character)
:ok = _track_characters([character], map.id, true)
:ok = _add_characters([character], map.id, true)
:ok = _track_characters([character], map_id, true)
:ok = _add_characters([character], map_id, true)
socket
end
@@ -1527,12 +1525,12 @@ defmodule WandererAppWeb.MapLive do
%{result: characters} = socket.assigns.characters
{:ok, map_characters} = _get_tracked_map_characters(map.id, socket.assigns.current_user)
{:ok, map_characters} = _get_tracked_map_characters(map_id, current_user)
user_character_eve_ids = map_characters |> Enum.map(& &1.eve_id)
{:ok, character_settings} =
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: map.id}) do
case WandererApp.Api.MapCharacterSettings.read_by_map(%{map_id: map_id}) do
{:ok, settings} -> {:ok, settings}
_ -> {:ok, []}
end
@@ -1704,6 +1702,28 @@ defmodule WandererAppWeb.MapLive do
{:noreply, socket}
end
defp apply_action(socket, :index, _params) do
socket
|> assign(:active_page, :map)
end
defp apply_action(socket, :add_system, _params) do
socket
|> assign(:active_page, :map)
|> assign(:page_title, "Add System")
|> assign(:add_system_form, to_form(%{"system_id" => nil}))
end
defp maybe_start_map(map_id) do
{:ok, map_started} = WandererApp.Cache.lookup("map_#{map_id}:started", false)
if map_started do
Process.send_after(self(), %{event: :map_started}, 10)
else
WandererApp.Map.Manager.start_map(map_id)
end
end
defp on_map_started(
map_id,
current_user,
@@ -1831,13 +1851,6 @@ defmodule WandererAppWeb.MapLive do
end
end
defp _load_user_permissions({:ok, map}, current_user) do
map
|> Ash.load([:acls, :user_permissions], actor: current_user)
end
defp _load_user_permissions(error, _current_user), do: error
defp _get_map_data(map_id, include_static_data? \\ true) do
{:ok, hubs} = map_id |> WandererApp.Map.list_hubs()
{:ok, connections} = map_id |> WandererApp.Map.list_connections()

View File

@@ -2,7 +2,7 @@ defmodule WandererApp.MixProject do
use Mix.Project
@source_url "https://github.com/wanderer-industries/wanderer"
@version "1.11.1"
@version "1.11.3"
def project do
[