aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-10-12 14:40:21 +0200
committerAlex Auvolat <alex@adnab.me>2018-10-12 14:40:21 +0200
commit1e91dc596fd2f7fdd96b7fd2fc50724f93e46529 (patch)
tree067d56e6fb9e215cc76dea5c9c82e61ef369d90e
parentd15d5fbfc5133a9d0f0d99dbbfc023849f61cc37 (diff)
downloadshard-1e91dc596fd2f7fdd96b7fd2fc50724f93e46529.tar.gz
shard-1e91dc596fd2f7fdd96b7fd2fc50724f93e46529.zip
Move and reorganize some stuff
-rw-r--r--shardweb/config/dev.exs4
-rw-r--r--shardweb/lib/channels/chat_channel.ex (renamed from shardweb/lib/shard_web/channels/room_channel.ex)2
-rw-r--r--shardweb/lib/channels/user_socket.ex (renamed from shardweb/lib/shard_web/channels/user_socket.ex)2
-rw-r--r--shardweb/lib/controllers/chat_controller.ex13
-rw-r--r--shardweb/lib/controllers/identity_controller.ex (renamed from shardweb/lib/shard_web/controllers/identity_controller.ex)8
-rw-r--r--shardweb/lib/controllers/page_controller.ex (renamed from shardweb/lib/shard_web/controllers/page_controller.ex)8
-rw-r--r--shardweb/lib/endpoint.ex (renamed from shardweb/lib/shard_web/endpoint.ex)0
-rw-r--r--shardweb/lib/gettext.ex (renamed from shardweb/lib/shard_web/gettext.ex)0
-rw-r--r--shardweb/lib/router.ex (renamed from shardweb/lib/shard_web/router.ex)9
-rw-r--r--shardweb/lib/shard_web.ex2
-rw-r--r--shardweb/lib/shard_web/controllers/room_controller.ex9
-rw-r--r--shardweb/lib/shard_web/views/identity_view.ex11
-rw-r--r--shardweb/lib/shard_web/views/room_view.ex3
-rw-r--r--shardweb/lib/templates/chat/chat.html.eex (renamed from shardweb/lib/shard_web/templates/room/show.html.eex)1
-rw-r--r--shardweb/lib/templates/identity/list.html.eex32
-rw-r--r--shardweb/lib/templates/identity/self.html.eex (renamed from shardweb/lib/shard_web/templates/identity/view.html.eex)0
-rw-r--r--shardweb/lib/templates/layout/app.html.eex (renamed from shardweb/lib/shard_web/templates/layout/app.html.eex)17
-rw-r--r--shardweb/lib/templates/layout/flashes.html.eex (renamed from shardweb/lib/shard_web/templates/layout/flashes.html.eex)0
-rw-r--r--shardweb/lib/templates/page/peer_list.html.eex (renamed from shardweb/lib/shard_web/templates/page/index.html.eex)0
-rw-r--r--shardweb/lib/templates/page/shard_list.html.eex46
-rw-r--r--shardweb/lib/views/chat_view.ex3
-rw-r--r--shardweb/lib/views/error_helpers.ex (renamed from shardweb/lib/shard_web/views/error_helpers.ex)0
-rw-r--r--shardweb/lib/views/error_view.ex (renamed from shardweb/lib/shard_web/views/error_view.ex)0
-rw-r--r--shardweb/lib/views/identity_view.ex21
-rw-r--r--shardweb/lib/views/layout_view.ex (renamed from shardweb/lib/shard_web/views/layout_view.ex)0
-rw-r--r--shardweb/lib/views/page_view.ex (renamed from shardweb/lib/shard_web/views/page_view.ex)4
26 files changed, 153 insertions, 42 deletions
diff --git a/shardweb/config/dev.exs b/shardweb/config/dev.exs
index f5d95e9..a7d4356 100644
--- a/shardweb/config/dev.exs
+++ b/shardweb/config/dev.exs
@@ -36,8 +36,8 @@ config :shardweb, ShardWeb.Endpoint,
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{priv/gettext/.*(po)$},
- ~r{lib/shard_web/views/.*(ex)$},
- ~r{lib/shard_web/templates/.*(eex)$}
+ ~r{lib/views/.*(ex)$},
+ ~r{lib/templates/.*(eex)$}
]
]
diff --git a/shardweb/lib/shard_web/channels/room_channel.ex b/shardweb/lib/channels/chat_channel.ex
index 7c3a16c..3e51c3a 100644
--- a/shardweb/lib/shard_web/channels/room_channel.ex
+++ b/shardweb/lib/channels/chat_channel.ex
@@ -1,4 +1,4 @@
-defmodule ShardWeb.RoomChannel do
+defmodule ShardWeb.ChatChannel do
use ShardWeb, :channel
require Logger
diff --git a/shardweb/lib/shard_web/channels/user_socket.ex b/shardweb/lib/channels/user_socket.ex
index a3aa1a5..b4136bd 100644
--- a/shardweb/lib/shard_web/channels/user_socket.ex
+++ b/shardweb/lib/channels/user_socket.ex
@@ -4,7 +4,7 @@ defmodule ShardWeb.UserSocket do
require Logger
## Channels
- channel "room:*", ShardWeb.RoomChannel
+ channel "room:*", ShardWeb.ChatChannel
## Transports
transport :websocket, Phoenix.Transports.WebSocket
diff --git a/shardweb/lib/controllers/chat_controller.ex b/shardweb/lib/controllers/chat_controller.ex
new file mode 100644
index 0000000..45b7d34
--- /dev/null
+++ b/shardweb/lib/controllers/chat_controller.ex
@@ -0,0 +1,13 @@
+defmodule ShardWeb.ChatController do
+ use ShardWeb, :controller
+
+ def chat(conn, %{"room" => room}) do
+ conn = put_gon(conn, chat_room: room)
+ render conn, "chat.html",
+ room: room
+ end
+
+ def privchat(_conn, %{"pk" => _pk}) do
+ # TODO
+ end
+end
diff --git a/shardweb/lib/shard_web/controllers/identity_controller.ex b/shardweb/lib/controllers/identity_controller.ex
index a4f54e7..fdaefd0 100644
--- a/shardweb/lib/shard_web/controllers/identity_controller.ex
+++ b/shardweb/lib/controllers/identity_controller.ex
@@ -1,8 +1,12 @@
defmodule ShardWeb.IdentityController do
use ShardWeb, :controller
- def view(conn, _params) do
- render conn, "view.html"
+ def list(conn, _params) do
+ render conn, "list.html"
+ end
+
+ def self(conn, _params) do
+ render conn, "self.html"
end
def update(conn, params) do
diff --git a/shardweb/lib/shard_web/controllers/page_controller.ex b/shardweb/lib/controllers/page_controller.ex
index 261b5d6..ebe2099 100644
--- a/shardweb/lib/shard_web/controllers/page_controller.ex
+++ b/shardweb/lib/controllers/page_controller.ex
@@ -1,8 +1,12 @@
defmodule ShardWeb.PageController do
use ShardWeb, :controller
- def index(conn, _params) do
- render conn, "index.html"
+ def peer_list(conn, _params) do
+ render conn, "peer_list.html"
+ end
+
+ def shard_list(conn, _params) do
+ render conn, "shard_list.html"
end
def add_peer(conn, _params) do
diff --git a/shardweb/lib/shard_web/endpoint.ex b/shardweb/lib/endpoint.ex
index fb8a48f..fb8a48f 100644
--- a/shardweb/lib/shard_web/endpoint.ex
+++ b/shardweb/lib/endpoint.ex
diff --git a/shardweb/lib/shard_web/gettext.ex b/shardweb/lib/gettext.ex
index e74cd43..e74cd43 100644
--- a/shardweb/lib/shard_web/gettext.ex
+++ b/shardweb/lib/gettext.ex
diff --git a/shardweb/lib/shard_web/router.ex b/shardweb/lib/router.ex
index 4311a29..43de0da 100644
--- a/shardweb/lib/shard_web/router.ex
+++ b/shardweb/lib/router.ex
@@ -18,15 +18,18 @@ defmodule ShardWeb.Router do
scope "/", ShardWeb do
pipe_through :browser # Use the default browser stack
- get "/", PageController, :index
+ get "/", PageController, :peer_list
post "/peer/add", PageController, :add_peer
+ get "/dashboard", PageController, :shard_list
- get "/identity", IdentityController, :view
+ get "/people", IdentityController, :list
+ get "/identity", IdentityController, :self
post "/identity", IdentityController, :update
post "/identity/switch", IdentityController, :switch
post "/identity/create", IdentityController, :create
- get "/room/:room", RoomController, :show
+ get "/chat/:room", ChatController, :chat
+ get "/pm/:pk", ChatController, :privchat
end
# Other scopes may use custom stacks.
diff --git a/shardweb/lib/shard_web.ex b/shardweb/lib/shard_web.ex
index 049da29..417e47b 100644
--- a/shardweb/lib/shard_web.ex
+++ b/shardweb/lib/shard_web.ex
@@ -29,7 +29,7 @@ defmodule ShardWeb do
def view do
quote do
- use Phoenix.View, root: "lib/shard_web/templates",
+ use Phoenix.View, root: "lib/templates",
namespace: ShardWeb
# Import convenience functions from controllers
diff --git a/shardweb/lib/shard_web/controllers/room_controller.ex b/shardweb/lib/shard_web/controllers/room_controller.ex
deleted file mode 100644
index d24649b..0000000
--- a/shardweb/lib/shard_web/controllers/room_controller.ex
+++ /dev/null
@@ -1,9 +0,0 @@
-defmodule ShardWeb.RoomController do
- use ShardWeb, :controller
-
- def show(conn, %{"room" => room}) do
- conn = put_gon(conn, chat_room: room)
- render conn, "show.html",
- room: room
- end
-end
diff --git a/shardweb/lib/shard_web/views/identity_view.ex b/shardweb/lib/shard_web/views/identity_view.ex
deleted file mode 100644
index 63d5a50..0000000
--- a/shardweb/lib/shard_web/views/identity_view.ex
+++ /dev/null
@@ -1,11 +0,0 @@
-defmodule ShardWeb.IdentityView do
- use ShardWeb, :view
-
- def identity_list do
- Shard.Keys.list_identities
- end
-
- def get_nick(pk) do
- SApp.Identity.get_nick pk
- end
-end
diff --git a/shardweb/lib/shard_web/views/room_view.ex b/shardweb/lib/shard_web/views/room_view.ex
deleted file mode 100644
index ebc2a60..0000000
--- a/shardweb/lib/shard_web/views/room_view.ex
+++ /dev/null
@@ -1,3 +0,0 @@
-defmodule ShardWeb.RoomView do
- use ShardWeb, :view
-end
diff --git a/shardweb/lib/shard_web/templates/room/show.html.eex b/shardweb/lib/templates/chat/chat.html.eex
index 75960b4..86c2fb6 100644
--- a/shardweb/lib/shard_web/templates/room/show.html.eex
+++ b/shardweb/lib/templates/chat/chat.html.eex
@@ -3,6 +3,7 @@
<div class="col-lg-12">
<h1 class="page-header">
#<%= @room %>
+ <small>public chat room</small>
</h1>
<ol class="breadcrumb">
diff --git a/shardweb/lib/templates/identity/list.html.eex b/shardweb/lib/templates/identity/list.html.eex
new file mode 100644
index 0000000..1354264
--- /dev/null
+++ b/shardweb/lib/templates/identity/list.html.eex
@@ -0,0 +1,32 @@
+<!-- Page Heading -->
+<div class="row">
+ <div class="col-lg-12">
+ <h1 class="page-header">
+ People on the network
+
+ </h1>
+ <ol class="breadcrumb">
+ <li class="active">
+ <i class="fa fa-users"></i> People
+ </li>
+ </ol>
+ </div>
+</div>
+<!-- /.row -->
+
+<%= render ShardWeb.LayoutView, "flashes.html", assigns %>
+
+
+<table class="table table-striped">
+ <tr>
+ <th>User name</th>
+ <th>Public key</th>
+ </tr>
+ <%= for {_id, manifest, pid} <- people_list() do %>
+ <tr>
+ <td><i class="fa fa-user"></i> <%= GenServer.call(pid, :get_info).nick %> </td>
+ <td><small><%= manifest.pk |> Base.encode16 %></small></td>
+ </tr>
+ <% end %>
+</table>
+
diff --git a/shardweb/lib/shard_web/templates/identity/view.html.eex b/shardweb/lib/templates/identity/self.html.eex
index 5e57e02..5e57e02 100644
--- a/shardweb/lib/shard_web/templates/identity/view.html.eex
+++ b/shardweb/lib/templates/identity/self.html.eex
diff --git a/shardweb/lib/shard_web/templates/layout/app.html.eex b/shardweb/lib/templates/layout/app.html.eex
index e0cb9dc..5a087f2 100644
--- a/shardweb/lib/shard_web/templates/layout/app.html.eex
+++ b/shardweb/lib/templates/layout/app.html.eex
@@ -47,7 +47,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
- <a class="navbar-brand" href="<%= page_path(@conn, :index) %>">Shard</a>
+ <a class="navbar-brand" href="<%= page_path(@conn, :peer_list) %>">Shard</a>
</div>
<!-- Top Menu Items -->
<ul class="nav navbar-right top-nav">
@@ -135,7 +135,7 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> <%= @nick %> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
- <a href="<%= identity_path(@conn, :view) %>"><i class="fa fa-fw fa-user"></i> Profile</a>
+ <a href="<%= identity_path(@conn, :self) %>"><i class="fa fa-fw fa-user"></i> Profile</a>
</li>
<li class="divider"></li>
<li>
@@ -154,7 +154,7 @@
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="<%= if @view_module == ShardWeb.IdentityView do "active" else "" end %>">
- <a href="<%= identity_path(@conn, :view) %>"><i class="fa fa-fw fa-user"></i> <%= @nick %></a>
+ <a href="<%= identity_path(@conn, :self) %>"><i class="fa fa-fw fa-user"></i> <%= @nick %></a>
</li>
<li class="<%= if @view_module == ShardWeb.RoomView do "active" else "" end %>">
<a href="javascript:;" data-toggle="collapse" data-target="#demo"><i class="fa fa-fw fa-comments"></i> Chat rooms <i class="fa fa-fw fa-caret-down"></i></a>
@@ -163,7 +163,7 @@
<%= for {_, %SApp.Chat.Manifest{channel: name}, _} <- shard_list() do %>
<li class="<%= if @view_module == ShardWeb.RoomView and @room == name do "custom_active" else "" end %>">
- <a href="<%= room_path(@conn, :show, name) %>">#<%= name %></a>
+ <a href="<%= chat_path(@conn, :chat, name) %>">#<%= name %></a>
</li>
<% end %>
<li>
@@ -173,14 +173,17 @@
</ul>
</li>
- <li class="<%= if @view_module == ShardWeb.PageView and @view_template == "index.html" do "active" else "" end %>">
- <a href="<%= page_path(@conn, :index) %>"><i class="fa fa-fw fa-globe"></i> Peer list</a>
+ <li>
+ <a href="<%= identity_path(@conn, :list) %>"><i class="fa fa-fw fa-users"></i> People</a>
+ </li>
+ <li class="<%= if @view_module == ShardWeb.PageView and @view_template == "peer_list.html" do "active" else "" end %>">
+ <a href="<%= page_path(@conn, :peer_list) %>"><i class="fa fa-fw fa-globe"></i> Peer list</a>
</li>
<li>
<a href="#"><i class="fa fa-fw fa-gear"></i> Settings</a>
</li>
<li>
- <a href="#"><i class="fa fa-fw fa-dashboard"></i> Dashboard</a>
+ <a href="<%= page_path(@conn, :shard_list) %>"><i class="fa fa-fw fa-dashboard"></i> Dashboard</a>
</li>
</ul>
</div>
diff --git a/shardweb/lib/shard_web/templates/layout/flashes.html.eex b/shardweb/lib/templates/layout/flashes.html.eex
index 5371f43..5371f43 100644
--- a/shardweb/lib/shard_web/templates/layout/flashes.html.eex
+++ b/shardweb/lib/templates/layout/flashes.html.eex
diff --git a/shardweb/lib/shard_web/templates/page/index.html.eex b/shardweb/lib/templates/page/peer_list.html.eex
index f385528..f385528 100644
--- a/shardweb/lib/shard_web/templates/page/index.html.eex
+++ b/shardweb/lib/templates/page/peer_list.html.eex
diff --git a/shardweb/lib/templates/page/shard_list.html.eex b/shardweb/lib/templates/page/shard_list.html.eex
new file mode 100644
index 0000000..a0648d3
--- /dev/null
+++ b/shardweb/lib/templates/page/shard_list.html.eex
@@ -0,0 +1,46 @@
+<!-- Page Heading -->
+<div class="row">
+ <div class="col-lg-12">
+ <h1 class="page-header">
+ Shard list
+
+ </h1>
+ <ol class="breadcrumb">
+ <li>
+ <i class="fa fa-dashboard"></i> Dashboard
+ </li>
+ <li class="active">
+ <i class="fa fa-table"></i> Shard list
+ </li>
+ </ol>
+ </div>
+</div>
+<!-- /.row -->
+
+<%= render ShardWeb.LayoutView, "flashes.html", assigns %>
+
+<table class="table table-striped">
+ <tr>
+ <th>Shard</th>
+ <th>Id</th>
+ <th>Pid</th>
+ </tr>
+ <%= for {id, manifest, pid} <- shard_list() do %>
+ <tr>
+ <td>
+ <%= case manifest do %>
+ <% %SApp.Identity.Manifest{pk: pk} -> %><i class="fa fa-user"></i>
+ <%= GenServer.call(pid, :get_info).nick %>
+ <small><%= Shard.Keys.pk_display pk %></small>
+ <% %SApp.Chat.Manifest{channel: chan} -> %><i class="fa fa-comments"></i> #<%= chan %>
+ <% %SApp.Chat.PrivChat.Manifest{pk_list: pk_list} -> %><i class="fa fa-comment"></i>
+ <%= pk_list |> Enum.map(&SApp.Identity.get_nick/1) |> Enum.join(", ") %>
+ <% x -> %> <%= inspect x %>
+ <% end %>
+ </td>
+ <td><small><%= id |> Base.encode16 %></small></td>
+ <td><%= inspect(pid) %></td>
+ </tr>
+ <% end %>
+</table>
+
diff --git a/shardweb/lib/views/chat_view.ex b/shardweb/lib/views/chat_view.ex
new file mode 100644
index 0000000..fd39956
--- /dev/null
+++ b/shardweb/lib/views/chat_view.ex
@@ -0,0 +1,3 @@
+defmodule ShardWeb.ChatView do
+ use ShardWeb, :view
+end
diff --git a/shardweb/lib/shard_web/views/error_helpers.ex b/shardweb/lib/views/error_helpers.ex
index f476548..f476548 100644
--- a/shardweb/lib/shard_web/views/error_helpers.ex
+++ b/shardweb/lib/views/error_helpers.ex
diff --git a/shardweb/lib/shard_web/views/error_view.ex b/shardweb/lib/views/error_view.ex
index a4b6eed..a4b6eed 100644
--- a/shardweb/lib/shard_web/views/error_view.ex
+++ b/shardweb/lib/views/error_view.ex
diff --git a/shardweb/lib/views/identity_view.ex b/shardweb/lib/views/identity_view.ex
new file mode 100644
index 0000000..1844ce8
--- /dev/null
+++ b/shardweb/lib/views/identity_view.ex
@@ -0,0 +1,21 @@
+defmodule ShardWeb.IdentityView do
+ use ShardWeb, :view
+
+ def identity_list do
+ Shard.Keys.list_identities
+ end
+
+ def get_nick(pk) do
+ SApp.Identity.get_nick pk
+ end
+
+ def people_list do
+ Shard.Manager.list_shards
+ |> Enum.filter(fn {_, manifest, _} ->
+ case manifest do
+ %SApp.Identity.Manifest{} -> true
+ _ -> false
+ end
+ end)
+ end
+end
diff --git a/shardweb/lib/shard_web/views/layout_view.ex b/shardweb/lib/views/layout_view.ex
index 2b12323..2b12323 100644
--- a/shardweb/lib/shard_web/views/layout_view.ex
+++ b/shardweb/lib/views/layout_view.ex
diff --git a/shardweb/lib/shard_web/views/page_view.ex b/shardweb/lib/views/page_view.ex
index 6bd8e4b..eb88617 100644
--- a/shardweb/lib/shard_web/views/page_view.ex
+++ b/shardweb/lib/views/page_view.ex
@@ -11,4 +11,8 @@ defmodule ShardWeb.PageView do
|> Base.encode16
|> String.downcase
end
+
+ def shard_list do
+ Shard.Manager.list_shards
+ end
end