aboutsummaryrefslogtreecommitdiff
path: root/shardweb/lib/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'shardweb/lib/controllers')
-rw-r--r--shardweb/lib/controllers/chat_controller.ex8
-rw-r--r--shardweb/lib/controllers/directory_controller.ex63
-rw-r--r--shardweb/lib/controllers/identity_controller.ex4
3 files changed, 58 insertions, 17 deletions
diff --git a/shardweb/lib/controllers/chat_controller.ex b/shardweb/lib/controllers/chat_controller.ex
index 080ee61..1ca66d4 100644
--- a/shardweb/lib/controllers/chat_controller.ex
+++ b/shardweb/lib/controllers/chat_controller.ex
@@ -4,11 +4,13 @@ defmodule ShardWeb.ChatController do
def chat(conn, %{"chan" => chan}) do
conn = put_gon(conn, chat_channel: "chat:" <> chan)
- shard = %SApp.Chat.Manifest{channel: chan} |> SData.term_hash
+ manifest = %SApp.Chat.Manifest{channel: chan}
+ shard = manifest |> SData.term_hash
render conn, "chat.html",
public: true,
shard: shard,
+ manifest: manifest,
chan: chan
end
@@ -37,10 +39,12 @@ defmodule ShardWeb.ChatController do
|> Enum.map(&SApp.Identity.get_nick/1)
|> Enum.join(", ")
- shard = [conn.assigns.pk | pk_list] |> SApp.Chat.PrivChat.Manifest.new |> SData.term_hash
+ manifest = [conn.assigns.pk | pk_list] |> SApp.Chat.PrivChat.Manifest.new
+ shard = manifest |> SData.term_hash
render conn, "chat.html",
public: false,
+ manifest: manifest,
shard: shard,
nicks: name
else
diff --git a/shardweb/lib/controllers/directory_controller.ex b/shardweb/lib/controllers/directory_controller.ex
index 1e3a0b0..10fdec2 100644
--- a/shardweb/lib/controllers/directory_controller.ex
+++ b/shardweb/lib/controllers/directory_controller.ex
@@ -1,29 +1,64 @@
defmodule ShardWeb.DirectoryController do
use ShardWeb, :controller
- def view_pub(conn, %{"owner" => owner, "name" => name}) do
- owner = Base.decode16! owner
- shard = %SApp.Directory.Manifest{public: true, owner: owner, name: name}
- pid = Shard.Manager.find_or_start shard
+ def view_pub(conn, args) do
+ view(conn, true, args)
+ end
- render conn, "view.html",
- public: true,
- shard: shard,
- pid: pid,
- owner: owner,
- name: name
+ def view_priv(conn, args) do
+ view(conn, false, args)
end
- def view_priv(conn, %{"owner" => owner, "name" => name}) do
+ def view(conn, public, %{"owner" => owner, "name" => name}=args) do
owner = Base.decode16! owner
- shard = %SApp.Directory.Manifest{public: false, owner: owner, name: name}
- pid = Shard.Manager.find_or_start shard
+ manifest = %SApp.Directory.Manifest{public: public, owner: owner, name: name}
+ shard = SData.term_hash manifest
+ pid = Shard.Manager.find_or_start manifest
render conn, "view.html",
- public: false,
+ public: public,
shard: shard,
+ manifest: manifest,
pid: pid,
owner: owner,
name: name
end
+
+ def dir_add(conn, %{"dir_name" => dir_name, "dir_public" => dir_public, "add_name" => add_name, "add_uri" => add_uri, "add_stored" => add_stored}) do
+ dir_public = (dir_public == "true")
+
+ manifest = %SApp.Directory.Manifest{public: dir_public, owner: conn.assigns.pk, name: dir_name}
+ shard = SData.term_hash manifest
+ pid = Shard.Manager.find_or_start manifest
+
+ item_manifest = ShardURI.to_manifest(add_uri)
+ SApp.Directory.add_item(pid, add_name, item_manifest, (add_stored == "yes"))
+
+ redirect conn, to: directory_path(conn, (if dir_public do :view_pub else :view_priv end), conn.assigns.pk|>Base.encode16, dir_name)
+ end
+
+ def dir_rm(conn, %{"dir_name" => dir_name, "dir_public" => dir_public, "item_name" => rm_name}) do
+ dir_public = (dir_public == "true")
+
+ manifest = %SApp.Directory.Manifest{public: dir_public, owner: conn.assigns.pk, name: dir_name}
+ shard = SData.term_hash manifest
+ pid = Shard.Manager.find_or_start manifest
+
+ SApp.Directory.rm_item(pid, rm_name)
+
+ redirect conn, to: directory_path(conn, (if dir_public do :view_pub else :view_priv end), conn.assigns.pk|>Base.encode16, dir_name)
+ end
+
+ def dir_set_stored(conn, %{"dir_name" => dir_name, "dir_public" => dir_public, "item_name" => item_name, "item_stored" => item_stored}) do
+ dir_public = (dir_public == "true")
+ item_stored = (item_stored == "true")
+
+ manifest = %SApp.Directory.Manifest{public: dir_public, owner: conn.assigns.pk, name: dir_name}
+ shard = SData.term_hash manifest
+ pid = Shard.Manager.find_or_start manifest
+
+ SApp.Directory.set_stored(pid, item_name, item_stored)
+
+ redirect conn, to: directory_path(conn, (if dir_public do :view_pub else :view_priv end), conn.assigns.pk|>Base.encode16, dir_name)
+ end
end
diff --git a/shardweb/lib/controllers/identity_controller.ex b/shardweb/lib/controllers/identity_controller.ex
index 962a888..7452453 100644
--- a/shardweb/lib/controllers/identity_controller.ex
+++ b/shardweb/lib/controllers/identity_controller.ex
@@ -11,7 +11,8 @@ defmodule ShardWeb.IdentityController do
def view(conn, %{"pk" => pk}) do
{:ok, pk} = Base.decode16(pk)
- shard = %SApp.Identity.Manifest{pk: pk} |> SData.term_hash
+ manifest = %SApp.Identity.Manifest{pk: pk}
+ shard = manifest |> SData.term_hash
pid = Shard.Manager.find_proc shard
if pid == nil do
@@ -21,6 +22,7 @@ defmodule ShardWeb.IdentityController do
view_pk: pk,
view_nick: SApp.Identity.get_nick(pk),
shard: shard,
+ manifest: manifest,
pid: pid
end
end