diff options
author | Alex Auvolat <alex@adnab.me> | 2018-11-02 11:22:28 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-11-02 11:22:28 +0100 |
commit | 3baa53f1da7f581619b066832b8303efbe9a46ba (patch) | |
tree | d6b49bd09fa915b93e13f3a03febc7fb1b38e9a4 /shardweb | |
parent | 80200dc43f271938fb14ec4eb4712e8dd7375aeb (diff) | |
download | shard-3baa53f1da7f581619b066832b8303efbe9a46ba.tar.gz shard-3baa53f1da7f581619b066832b8303efbe9a46ba.zip |
Remove friends list ; add some links
Diffstat (limited to 'shardweb')
-rw-r--r-- | shardweb/.gitignore | 5 | ||||
-rw-r--r-- | shardweb/assets/js/app.js | 6 | ||||
-rw-r--r-- | shardweb/config/config.exs | 6 | ||||
-rw-r--r-- | shardweb/lib/channels/chat_channel.ex | 10 | ||||
-rw-r--r-- | shardweb/lib/controllers/identity_controller.ex | 34 | ||||
-rw-r--r-- | shardweb/lib/router.ex | 1 | ||||
-rw-r--r-- | shardweb/lib/templates/directory/view.html.eex | 9 | ||||
-rw-r--r-- | shardweb/lib/templates/identity/view.html.eex | 12 | ||||
-rw-r--r-- | shardweb/lib/templates/layout/app.html.eex | 4 | ||||
-rw-r--r-- | shardweb/lib/templates/page/shard_entry.html.eex | 4 | ||||
-rw-r--r-- | shardweb/lib/templates/page/shard_list.html.eex | 2 | ||||
-rw-r--r-- | shardweb/lib/views/identity_view.ex | 5 | ||||
-rw-r--r-- | shardweb/mix.exs | 3 | ||||
-rw-r--r-- | shardweb/mix.lock | 1 |
14 files changed, 37 insertions, 65 deletions
diff --git a/shardweb/.gitignore b/shardweb/.gitignore index d5be28f..bae7727 100644 --- a/shardweb/.gitignore +++ b/shardweb/.gitignore @@ -13,6 +13,9 @@ npm-debug.log # Static artifacts /assets/node_modules +# Auto-generated by phoenix-jsroutes +/assets/js/phoenix-jsroutes.js + # Since we are building assets from assets/, # we ignore priv/static. You may want to comment # this depending on your deployment strategy. @@ -24,4 +27,4 @@ npm-debug.log # Alternatively, you may comment the line below and commit the # secrets files as long as you replace their contents by environment # variables. -/config/*.secret.exs
\ No newline at end of file +/config/*.secret.exs diff --git a/shardweb/assets/js/app.js b/shardweb/assets/js/app.js index 3adae5a..1e5ea62 100644 --- a/shardweb/assets/js/app.js +++ b/shardweb/assets/js/app.js @@ -20,6 +20,8 @@ import "phoenix_html" import socket from "./socket" +import routes from './phoenix-jsroutes' + var chat_channel = window.Gon.getAsset('chat_channel'); if (chat_channel != undefined) { @@ -28,9 +30,9 @@ if (chat_channel != undefined) channel.on('shout', function (payload) { // listen to the 'shout' event var li = document.createElement("li"); // creaet new list item DOM element var name = payload.name || 'guest'; // get name from payload or set default - li.innerHTML = '<b><' + name + '</b> <small>' + payload.pk16 + '</small><b>></b> ' + payload.message; // set li contents + li.innerHTML = '<b><' + name + '</b> <a href="' + routes.identityView(payload.fullpk) + '"><small>' + payload.pk16 + '</small></a><b>></b> ' + payload.message; // set li contents - console.log(ul.scrollTop + ' ' + ul.scrollHeight + ' ' + ul.clientHeight); + // console.log(ul.scrollTop + ' ' + ul.scrollHeight + ' ' + ul.clientHeight); var must_scroll = (ul.scrollTop >= ul.scrollHeight - ul.clientHeight - 10); ul.appendChild(li); // append to list diff --git a/shardweb/config/config.exs b/shardweb/config/config.exs index a905175..0e38936 100644 --- a/shardweb/config/config.exs +++ b/shardweb/config/config.exs @@ -5,6 +5,11 @@ # is restricted to this project. use Mix.Config +# Make phx.routes and jsroutes work +config :shardweb, namespace: ShardWeb + +config :shardweb, :jsroutes, output_folder: "assets/js" + # Configures the endpoint config :shardweb, ShardWeb.Endpoint, url: [host: "localhost"], @@ -13,6 +18,7 @@ config :shardweb, ShardWeb.Endpoint, pubsub: [name: ShardWeb.PubSub, adapter: Phoenix.PubSub.PG2] + # Configures Elixir's Logger config :logger, :console, format: "$time $metadata[$level] $message\n", diff --git a/shardweb/lib/channels/chat_channel.ex b/shardweb/lib/channels/chat_channel.ex index 25f1d09..7c8f1f9 100644 --- a/shardweb/lib/channels/chat_channel.ex +++ b/shardweb/lib/channels/chat_channel.ex @@ -44,6 +44,7 @@ defmodule ShardWeb.ChatChannel do push(socket, "shout", %{ name: nick, pk16: Shard.Keys.pk_display(pk), + fullpk: Base.encode16(pk), message: msg, }) end) @@ -55,9 +56,11 @@ defmodule ShardWeb.ChatChannel do {_ts, msg} = SData.term_unbin msgbin nick = SApp.Identity.get_nick pk Logger.info("#{inspect self()} :chat_recv #{inspect msg}") - push socket, "shout", %{"name" => nick, - "pk16" => Shard.Keys.pk_display(pk), - "message" => msg} + push socket, "shout", %{ + name: nick, + pk16: Shard.Keys.pk_display(pk), + fullpk: Base.encode16(pk), + message: msg} SApp.Chat.mark_read(socket.assigns.pid) {:noreply, socket} end @@ -80,6 +83,7 @@ defmodule ShardWeb.ChatChannel do nick = SApp.Identity.get_nick pk payload = Map.put(payload, "name", nick) payload = Map.put(payload, "pk16", Shard.Keys.pk_display pk) + payload = Map.put(payload, "fullpk", Base.encode16 pk) SApp.Chat.chat_send(socket.assigns.pid, pk, payload["message"]) broadcast socket, "shout", payload diff --git a/shardweb/lib/controllers/identity_controller.ex b/shardweb/lib/controllers/identity_controller.ex index d1c6886..962a888 100644 --- a/shardweb/lib/controllers/identity_controller.ex +++ b/shardweb/lib/controllers/identity_controller.ex @@ -25,40 +25,6 @@ defmodule ShardWeb.IdentityController do end end - def view_post(conn, opts) do - IO.puts(inspect opts) - {:ok, pk} = Base.decode16(opts["pk"]) - manifest = %SApp.Identity.Manifest{pk: pk} - nick = SApp.Identity.get_nick pk - shard = manifest |> SData.term_hash - pid = Shard.Manager.find_proc shard - - if opts["add_friend"] == "true" do - friend_list = SApp.Directory.friends_dir(conn.assigns.pk) - name = nick <> " " <> Shard.Keys.pk_display(pk) - SApp.Directory.add_file(friend_list, name, manifest) - end - - if opts["rm_friend"] == "true" do - friend_list = SApp.Directory.friends_dir(conn.assigns.pk) - name = SApp.Directory.find(friend_list, manifest) - if name != nil do - SApp.Directory.rm_file(friend_list, name) - end - end - - if pid == nil do - render conn, ShardWeb.ErrorView, "404.html" - else - render conn, "view.html", - view_pk: pk, - view_nick: SApp.Identity.get_nick(pk), - shard: shard, - pid: pid - end - #TODO - end - def update(conn, params) do pid = SApp.Identity.find_proc(conn.assigns.pk) info = SApp.Identity.get_info(pid) diff --git a/shardweb/lib/router.ex b/shardweb/lib/router.ex index eb1868f..61f8209 100644 --- a/shardweb/lib/router.ex +++ b/shardweb/lib/router.ex @@ -24,7 +24,6 @@ defmodule ShardWeb.Router do get "/people", IdentityController, :list get "/people/:pk", IdentityController, :view - post "/people/:pk", IdentityController, :view_post get "/identity", IdentityController, :self post "/identity", IdentityController, :update post "/identity/switch", IdentityController, :switch diff --git a/shardweb/lib/templates/directory/view.html.eex b/shardweb/lib/templates/directory/view.html.eex index b981391..43ded97 100644 --- a/shardweb/lib/templates/directory/view.html.eex +++ b/shardweb/lib/templates/directory/view.html.eex @@ -7,6 +7,15 @@ </h1> <ol class="breadcrumb"> + <li> + <i class="fa fa-users"></i> Users + </li> + <li> + <i class="fa fa-user"></i> <%= @owner |> SApp.Identity.get_nick %> + <a href="<%= identity_path(@conn, :view, @owner |> Base.encode16) %>"> + <small><%= @owner |> Shard.Keys.pk_display %></small> + </a> + </li> <li class="active"> <i class="fa fa-folder"></i> <%= @name %> </li> diff --git a/shardweb/lib/templates/identity/view.html.eex b/shardweb/lib/templates/identity/view.html.eex index 6cb1bde..3fb5a3f 100644 --- a/shardweb/lib/templates/identity/view.html.eex +++ b/shardweb/lib/templates/identity/view.html.eex @@ -18,16 +18,8 @@ <%= render ShardWeb.LayoutView, "flashes.html", assigns %> -<%= if is_friend(@conn, @view_pk) do %> - <%= form_for @conn, identity_path(@conn, :view_post, @view_pk|>Base.encode16()), [class: "form-inline"], fn f -> %> - <%= hidden_input f, :rm_friend, value: "true" %> - <%= submit "Remove from friends", [class: "btn btn-sm btn-danger"] %> - <% end %> -<% else %> - <%= form_for @conn, identity_path(@conn, :view_post, @view_pk|>Base.encode16()), [class: "form-inline"], fn f -> %> - <%= hidden_input f, :add_friend, value: "true" %> - <%= submit "Add to friends", [class: "btn btn-sm btn-success"] %> - <% end %> +<%= if @view_pk != @pk do %> + <a class="btn btn-s btn-primary" href="<%= chat_path(@conn, :privchat, @pk |> Base.encode16) %>"><i class="fa fa-comments"></i> PM</a> <% end %> <pre> diff --git a/shardweb/lib/templates/layout/app.html.eex b/shardweb/lib/templates/layout/app.html.eex index 71a08f9..1310131 100644 --- a/shardweb/lib/templates/layout/app.html.eex +++ b/shardweb/lib/templates/layout/app.html.eex @@ -150,10 +150,6 @@ </ul> </li> - - <li class="<%= if @view_module == ShardWeb.DirectoryView and @view_template == "view.html" and not @public and @name == "friends" do "active" else "" end %>"> - <a href="<%= directory_path(@conn, :view_priv, @pk|>Base.encode16(), "friends") %>"><i class="fa fa-fw fa-heart"></i> Friends</a> - </li> <li class="<%= if (@view_module == ShardWeb.IdentityView and @view_template == "list.html") or (@view_module == ShardWeb.ChatView and @view_template == "chat.html" and not @public) do "active" else "" end %>"> <a href="<%= identity_path(@conn, :list) %>"><i class="fa fa-fw fa-users"></i> Everyone<i class="fa fa-fw fa-caret-down"></i></a> diff --git a/shardweb/lib/templates/page/shard_entry.html.eex b/shardweb/lib/templates/page/shard_entry.html.eex index 8a55b3a..d99fc34 100644 --- a/shardweb/lib/templates/page/shard_entry.html.eex +++ b/shardweb/lib/templates/page/shard_entry.html.eex @@ -18,9 +18,7 @@ <% %SApp.Directory.Manifest{owner: owner, public: public, name: name} -> %><i class="fa fa-folder"></i> <%= SApp.Identity.get_nick(owner) %> - <a href="<%= identity_path(@conn, :view, owner|>Base.encode16) %>"> - <small><%= Shard.Keys.pk_display owner %></small> - </a> + <small><%= Shard.Keys.pk_display owner %></small> / <a href="<%= directory_path(@conn, (if public do :view_pub else :view_priv end), owner|>Base.encode16(), name) %>"><%= name %></a> <%= if public do %><i class="fa fa-globe"></i><% else %><i class="fa fa-lock"></i><% end %> diff --git a/shardweb/lib/templates/page/shard_list.html.eex b/shardweb/lib/templates/page/shard_list.html.eex index 53f6264..dd846d8 100644 --- a/shardweb/lib/templates/page/shard_list.html.eex +++ b/shardweb/lib/templates/page/shard_list.html.eex @@ -35,7 +35,7 @@ <% end %> </td> <td> - <%= render "shard_entry.html", conn: @conn, manifest: manifest %> + <%= render "shard_entry.html", conn: @conn, manifest: manifest, pk: @pk %> </td> <td><small><%= id |> Base.encode16 %></small></td> </tr> diff --git a/shardweb/lib/views/identity_view.ex b/shardweb/lib/views/identity_view.ex index 86423b2..1844ce8 100644 --- a/shardweb/lib/views/identity_view.ex +++ b/shardweb/lib/views/identity_view.ex @@ -18,9 +18,4 @@ defmodule ShardWeb.IdentityView do end end) end - - def is_friend(conn, pk) do - fd = SApp.Directory.friends_dir(conn.assigns.pk) - SApp.Directory.find(fd, %SApp.Identity.Manifest{pk: pk}) != nil - end end diff --git a/shardweb/mix.exs b/shardweb/mix.exs index 809043d..7e4b0b2 100644 --- a/shardweb/mix.exs +++ b/shardweb/mix.exs @@ -7,7 +7,7 @@ defmodule ShardWeb.Mixfile do version: "0.0.1", elixir: "~> 1.4", elixirc_paths: elixirc_paths(Mix.env), - compilers: [:phoenix, :gettext] ++ Mix.compilers, + compilers: [:phoenix, :gettext] ++ Mix.compilers ++ [:jsroutes], start_permanent: Mix.env == :prod, deps: deps() ] @@ -36,6 +36,7 @@ defmodule ShardWeb.Mixfile do {:phoenix_pubsub, "~> 1.0"}, {:phoenix_html, "~> 2.10"}, {:phoenix_live_reload, "~> 1.0", only: :dev}, + {:phoenix_jsroutes, "~> 0.0.4"}, {:gettext, "~> 0.11"}, {:cowboy, "~> 1.0"}, {:phoenix_gon, "~> 0.4.0"}, diff --git a/shardweb/mix.lock b/shardweb/mix.lock index 506f863..71267a0 100644 --- a/shardweb/mix.lock +++ b/shardweb/mix.lock @@ -9,6 +9,7 @@ "phoenix": {:hex, :phoenix, "1.3.4", "aaa1b55e5523083a877bcbe9886d9ee180bf2c8754905323493c2ac325903dc5", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "phoenix_gon": {:hex, :phoenix_gon, "0.4.0", "ff67988ccd412f1cc04f095c8f0553915a4c8d2b50959db773b9da9f0cf23cb3", [:mix], [{:phoenix_html, "~> 2.7", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "phoenix_html": {:hex, :phoenix_html, "2.12.0", "1fb3c2e48b4b66d75564d8d63df6d53655469216d6b553e7e14ced2b46f97622", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix_jsroutes": {:hex, :phoenix_jsroutes, "0.0.4", "35622303a552de775f5f5d3d002972e99caf15d27fb230ff72f869db881cfd5b", [:mix], [], "hexpm"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.1.5", "8d4c9b1ef9ca82deee6deb5a038d6d8d7b34b9bb909d99784a49332e0d15b3dc", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.0", "d55e25ff1ff8ea2f9964638366dfd6e361c52dedfd50019353598d11d4441d14", [:mix], [], "hexpm"}, "plug": {:hex, :plug, "1.6.2", "e06a7bd2bb6de5145da0dd950070110dce88045351224bd98e84edfdaaf5ffee", [:mix], [{:cowboy, "~> 1.0.1 or ~> 1.1 or ~> 2.4", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"}, |