aboutsummaryrefslogtreecommitdiff
path: root/shardweb/lib/templates/directory/view.html.eex
blob: 7b9be38f03c16a4c04bb6205e0f698dd4d028561 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!-- Page Heading -->
<div class="row">
  <div class="col-lg-12">
    <h1 class="page-header">
      <%= @name %>
      <small class="shard_uri"><%= @manifest |> ShardURI.from_manifest %></small>

    </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 %>
        <%= if @public do %>
          (public)
        <% else %>
          (private)
        <% end %>
      </li>
    </ol>
  </div>
</div>
<!-- /.row -->

<%= render ShardWeb.LayoutView, "flashes.html", assigns %>

<table class="table table-striped">
  <tr>
    <th>Name</th>
    <th>Shard</th>
    <th style="width: 150px"></th>
    <th>URI</th>
  </tr>
  <%= for {name, {manifest, stored}} <- dir_contents(@conn, @manifest) do %>
    <tr>
      <td>
        <%= if stored do %>
          <i class="fa fa-save"></i>
        <% else %>
          <i class="fa fa-link"></i>
        <% end %>
        <strong><%= name %></strong>
      </td>
      <td>
        <%= render ShardWeb.PageView, "shard_entry.html", conn: @conn, manifest: manifest, pk: @pk %>
      </td>
      <td>
        <%= form_for @conn, directory_path(@conn, :dir_rm), [class: "form-inline", style: "display: inline", onsubmit: "return confirm('Remove this item?');"], fn f -> %>
          <%= hidden_input f, :dir_name, value: @name %>
          <%= hidden_input f, :dir_public, value: @public %>
          <%= hidden_input f, :item_name, value: name %>
          <%= submit "Remove", [class: "btn btn-xs btn-danger"] %>
        <% end %>
        <%= form_for @conn, directory_path(@conn, :dir_set_stored), [class: "form-inline", style: "display: inline"], fn f -> %>
          <%= hidden_input f, :dir_name, value: @name %>
          <%= hidden_input f, :dir_public, value: @public %>
          <%= hidden_input f, :item_name, value: name %>
          <%= hidden_input f, :item_stored, value: (if stored do "false" else "true" end) %>
          <%= if stored do %>
            <%= submit "Don't store", [class: "btn btn-xs btn-warning"] %>
          <% else %>
            <%= submit "Store", [class: "btn btn-xs btn-success"] %>
          <% end %>
        <% end %>
      </td>
      <td><small class="shard_uri"><%= manifest |> ShardURI.from_manifest %></small></td>
    </tr>
  <% end %>
</table>

<%= if @owner == @pk do %>
  <%= if @public do %>
    <fieldset><legend>Upload file</legend>
      <%= form_for @conn, directory_path(@conn, :dir_upload), [multipart: true, class: "form-horizontal"], fn f -> %>
        <%= hidden_input f, :dir_name, value: @name %>
        <%= hidden_input f, :dir_public, value: @public %>
        <div class="form-group">
          <%= label :file, "File:", class: ["col-sm-2 control-label"] %>
          <div class="col-sm-10">
            <%= file_input f, :file, [class: "form-control"] %>
          </div>
        </div>
        <div class="form-group">
          <%= label :upload_name, "Save as (optionnal):", class: ["col-sm-2 control-label"] %>
          <div class="col-sm-10">
            <%= text_input f, :upload_name, [class: "form-control", value: ""] %>
          </div>
        </div>
        <div class="form-group">
          <div class="col-sm-offset-2 col-sm-10">
            <%= submit "Upload file", [class: "btn btn-primary"] %>
          </div>
        </div>
      <% end %>
    </fieldset>
  <% else %>
    <p>Warning: file upload in private directories does not keeps file private (yeah WTF right?), so we don't let you do that.</p>
  <% end %>

  <fieldset><legend>Add existing item</legend>
    <%= form_for @conn, directory_path(@conn, :dir_add), [class: "form-horizontal"], fn f -> %>
      <%= hidden_input f, :dir_name, value: @name %>
      <%= hidden_input f, :dir_public, value: @public %>
      <div class="form-group">
        <%= label :add_name, "Name:", class: ["col-sm-2 control-label"] %>
        <div class="col-sm-10">
          <%= text_input f, :add_name, [class: "form-control", value: ""] %>
        </div>
      </div>
      <div class="form-group">
        <%= label :add_uri, "URI:", class: ["col-sm-2 control-label"] %>
        <div class="col-sm-10">
          <%= text_input f, :add_uri, [class: "form-control", placeholder: "example: shard:identity:xxx"] %>
        </div>
      </div>
      <div class="form-group">
        <label class="col-sm-2 control-label">Stored?</label>
        <div class="col-sm-10">
          <div class="radio">
            <label><%= radio_button f, :add_stored, "yes" %>Stored <i class="fa fa-save"></i></label>
          </div>
          <div class="radio">
            <label><%= radio_button f, :add_stored, "no", [checked: true] %>Linked <i class="fa fa-link"></i></label>
          </div>
        </div>
      </div>

      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <%= submit "Add", [class: "btn btn-primary"] %>
        </div>
      </div>
    <% end %>
  </fieldset>
<% end %>