fix: more alignments still
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
defmodule BDS.Desktop.ShellData do
|
||||
@moduledoc false
|
||||
|
||||
alias BDS.Git
|
||||
alias BDS.I18n
|
||||
alias BDS.Projects
|
||||
alias BDS.UI.Dashboard
|
||||
@@ -100,6 +101,30 @@ defmodule BDS.Desktop.ShellData do
|
||||
)
|
||||
end
|
||||
|
||||
def git_badge_count(project_id, opts \\ [])
|
||||
|
||||
def git_badge_count(nil, _opts), do: 0
|
||||
def git_badge_count("default", _opts), do: 0
|
||||
|
||||
def git_badge_count(project_id, opts) when is_binary(project_id) do
|
||||
provider = Keyword.get(opts, :provider, git_remote_state_provider())
|
||||
|
||||
try do
|
||||
case provider.(project_id, []) do
|
||||
{:ok, %{behind: behind}} when is_integer(behind) and behind > 0 -> behind
|
||||
{:ok, %{behind: behind}} when is_binary(behind) -> parse_positive_count(behind)
|
||||
_other -> 0
|
||||
end
|
||||
rescue
|
||||
error in [DBConnection.OwnershipError, Exqlite.Error] ->
|
||||
if match?(%Exqlite.Error{}, error) and not String.contains?(Exception.message(error), "no such table") do
|
||||
reraise error, __STACKTRACE__
|
||||
end
|
||||
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def panel_tabs(workbench) do
|
||||
[:tasks, :output]
|
||||
|> maybe_add_panel_tab(workbench.editor_route, :post_links)
|
||||
@@ -108,6 +133,17 @@ defmodule BDS.Desktop.ShellData do
|
||||
|> Enum.uniq()
|
||||
end
|
||||
|
||||
defp git_remote_state_provider do
|
||||
Application.get_env(:bds, :git_remote_state_provider, &Git.remote_state/2)
|
||||
end
|
||||
|
||||
defp parse_positive_count(value) do
|
||||
case Integer.parse(value) do
|
||||
{count, _rest} when count > 0 -> count
|
||||
_other -> 0
|
||||
end
|
||||
end
|
||||
|
||||
def activity_icon(id) do
|
||||
case to_string(id) do
|
||||
"posts" -> ~s(<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8l-6-6zM6 20V4h7v5h5v11H6z"></path><path d="M8 12h8v2H8zm0 4h8v2H8z"></path></svg>)
|
||||
|
||||
@@ -394,11 +394,12 @@ defmodule BDS.Desktop.ShellLive do
|
||||
defp reload_shell(socket, workbench) do
|
||||
projects = ShellData.project_snapshot()
|
||||
dashboard = ShellData.dashboard(projects.active_project_id)
|
||||
git_badge_count = ShellData.git_badge_count(projects.active_project_id)
|
||||
active_view_id = Atom.to_string(workbench.active_view)
|
||||
sidebar_data = ShellData.sidebar_view(projects.active_project_id, active_view_id, current_sidebar_filters(socket, active_view_id))
|
||||
sidebar_data = merge_sidebar_ui_state(socket, active_view_id, sidebar_data)
|
||||
task_status = BDS.Tasks.status_snapshot()
|
||||
activity_buttons = Workbench.activity_buttons(workbench, 0)
|
||||
activity_buttons = Workbench.activity_buttons(workbench, git_badge_count)
|
||||
page_language = socket.assigns[:page_language] || ShellData.ui_language()
|
||||
offline_mode = Map.get(socket.assigns, :offline_mode, true)
|
||||
|
||||
|
||||
@@ -112,6 +112,9 @@
|
||||
aria-label={activity_label(button.label)}
|
||||
>
|
||||
<%= raw(ShellData.activity_icon(button.id)) %>
|
||||
<%= if button.badge do %>
|
||||
<span class="activity-bar-badge"><%= button.badge.display %></span>
|
||||
<% end %>
|
||||
</button>
|
||||
<% end %>
|
||||
</div>
|
||||
@@ -129,6 +132,9 @@
|
||||
aria-label={activity_label(button.label)}
|
||||
>
|
||||
<%= raw(ShellData.activity_icon(button.id)) %>
|
||||
<%= if button.badge do %>
|
||||
<span class="activity-bar-badge"><%= button.badge.display %></span>
|
||||
<% end %>
|
||||
</button>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -171,6 +171,26 @@ defmodule BDS.Git do
|
||||
end
|
||||
end
|
||||
|
||||
def remote_state(project_id, opts \\ []) when is_binary(project_id) and is_list(opts) do
|
||||
with {:ok, project_dir} <- project_dir(project_id),
|
||||
{:ok, local_branch} <- current_branch(project_dir, opts) do
|
||||
case upstream_branch(project_dir, opts) do
|
||||
{:ok, nil} ->
|
||||
{:ok, %{local_branch: local_branch, upstream_branch: nil, has_upstream: false, ahead: 0, behind: 0}}
|
||||
|
||||
{:ok, upstream_branch} ->
|
||||
{:ok,
|
||||
%{
|
||||
local_branch: local_branch,
|
||||
upstream_branch: upstream_branch,
|
||||
has_upstream: true,
|
||||
ahead: revision_count(project_dir, "#{upstream_branch}..HEAD", opts),
|
||||
behind: revision_count(project_dir, "HEAD..#{upstream_branch}", opts)
|
||||
}}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp project_dir(project_id) do
|
||||
case Projects.get_project(project_id) do
|
||||
nil -> {:error, :not_found}
|
||||
@@ -274,6 +294,13 @@ defmodule BDS.Git do
|
||||
]
|
||||
end
|
||||
|
||||
defp upstream_branch(project_dir, opts) do
|
||||
case run_git(project_dir, ["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{upstream}"], opts) do
|
||||
{:ok, output} -> {:ok, blank_to_nil(output)}
|
||||
{:error, {:git_failed, _message}} -> {:ok, nil}
|
||||
end
|
||||
end
|
||||
|
||||
defp parse_status(output) do
|
||||
output
|
||||
|> String.split("\n", trim: true)
|
||||
@@ -334,6 +361,20 @@ defmodule BDS.Git do
|
||||
end
|
||||
end
|
||||
|
||||
defp revision_count(project_dir, revision_range, opts) do
|
||||
case run_git(project_dir, ["rev-list", "--count", revision_range], opts) do
|
||||
{:ok, output} -> parse_count(output)
|
||||
{:error, {:git_failed, _message}} -> 0
|
||||
end
|
||||
end
|
||||
|
||||
defp parse_count(value) do
|
||||
case Integer.parse(to_string(value || "")) do
|
||||
{count, _rest} -> count
|
||||
:error -> 0
|
||||
end
|
||||
end
|
||||
|
||||
defp category_for_path("posts/" <> _rest), do: :posts
|
||||
defp category_for_path("scripts/" <> _rest), do: :scripts
|
||||
defp category_for_path("templates/" <> _rest), do: :templates
|
||||
|
||||
Reference in New Issue
Block a user