diff options
author | Alex Auvolat <alex@adnab.me> | 2018-11-06 11:57:09 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2018-11-06 11:57:09 +0100 |
commit | c4f6cbab20b0b1d08755073d93365e5bd00dc755 (patch) | |
tree | 384dd05c59a810d503790a2af1b5c49e1aed5ccf /shardweb | |
parent | 0e5b82f3348508eb7f4291a08722522a49edd752 (diff) | |
download | shard-c4f6cbab20b0b1d08755073d93365e5bd00dc755.tar.gz shard-c4f6cbab20b0b1d08755073d93365e5bd00dc755.zip |
Shard deletion ; update README and TODO
Diffstat (limited to 'shardweb')
-rw-r--r-- | shardweb/lib/controllers/directory_controller.ex | 6 | ||||
-rw-r--r-- | shardweb/lib/controllers/page_controller.ex | 8 | ||||
-rw-r--r-- | shardweb/lib/router.ex | 1 | ||||
-rw-r--r-- | shardweb/lib/templates/page/shard_list.html.eex | 15 |
4 files changed, 24 insertions, 6 deletions
diff --git a/shardweb/lib/controllers/directory_controller.ex b/shardweb/lib/controllers/directory_controller.ex index d1b7136..ecb9c97 100644 --- a/shardweb/lib/controllers/directory_controller.ex +++ b/shardweb/lib/controllers/directory_controller.ex @@ -9,7 +9,7 @@ defmodule ShardWeb.DirectoryController do view(conn, false, args) end - def view(conn, public, %{"owner" => owner, "name" => name}=args) do + def view(conn, public, %{"owner" => owner, "name" => name}) do owner = Base.decode16! owner manifest = %SApp.Directory.Manifest{public: public, owner: owner, name: name} shard = SData.term_hash manifest @@ -28,7 +28,6 @@ defmodule ShardWeb.DirectoryController 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) @@ -41,7 +40,6 @@ defmodule ShardWeb.DirectoryController 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) @@ -54,7 +52,6 @@ defmodule ShardWeb.DirectoryController do 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) @@ -68,7 +65,6 @@ defmodule ShardWeb.DirectoryController 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 {:ok, file_manifest, _file_pid} = SApp.File.create(path, mime_type) diff --git a/shardweb/lib/controllers/page_controller.ex b/shardweb/lib/controllers/page_controller.ex index 5c90416..baf72b9 100644 --- a/shardweb/lib/controllers/page_controller.ex +++ b/shardweb/lib/controllers/page_controller.ex @@ -9,6 +9,14 @@ defmodule ShardWeb.PageController do render conn, "shard_list.html" end + def shard_action(conn, %{"shard_id" => shard_id, "action" => action}) do + shard_id = Base.decode16! shard_id + case action do + "delete" -> Shard.Manager.delete(shard_id) + end + redirect conn, to: page_path(conn, :shard_list) + end + def add_peer(conn, _params) do try do ip = conn.params["ip"] diff --git a/shardweb/lib/router.ex b/shardweb/lib/router.ex index a6a61f9..0b1f686 100644 --- a/shardweb/lib/router.ex +++ b/shardweb/lib/router.ex @@ -19,6 +19,7 @@ defmodule ShardWeb.Router do pipe_through :browser # Use the default browser stack get "/", PageController, :shard_list + post "/", PageController, :shard_action get "/peers", PageController, :peer_list post "/peer/add", PageController, :add_peer diff --git a/shardweb/lib/templates/page/shard_list.html.eex b/shardweb/lib/templates/page/shard_list.html.eex index 3fffef7..79fd794 100644 --- a/shardweb/lib/templates/page/shard_list.html.eex +++ b/shardweb/lib/templates/page/shard_list.html.eex @@ -23,9 +23,10 @@ <tr> <th></th> <th>Shard</th> + <th></th> <th>URI</th> </tr> - <%= for {_id, manifest, why_have_it} <- shard_list() do %> + <%= for {id, manifest, why_have_it} <- shard_list() do %> <tr> <td> <%= case why_have_it do %> @@ -37,6 +38,18 @@ <td> <%= render "shard_entry.html", conn: @conn, manifest: manifest, pk: @pk %> </td> + <td> + <%= case why_have_it do %> + <% {:cached, _} -> %> + <%= form_for @conn, page_path(@conn, :shard_action), [class: "form-inline", style: "display: inline", onsubmit: "return confirm('Delete this shard and all its data?');"], fn f -> %> + <%= hidden_input f, :shard_id, value: id |> Base.encode16 %> + <%= hidden_input f, :action, value: "delete" %> + <%= submit "Delete", [class: "btn btn-xs btn-danger"] %> + <% end %> + <% _ -> %> + <% end %> + + </td> <td><small class="shard_uri"><%= manifest |> ShardURI.from_manifest %></small></td> </tr> <% end %> |