Initial commit

This commit is contained in:
Senad Uka
2020-05-31 22:38:19 +02:00
commit 858fafc3c5
1280 changed files with 65918 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
<tr id="<%= dom_id(account) %>">
<td>
<%= account.name %>
</td>
<td>
<%= account.plan_name %>
</td>
<td>
<%= account.projects.size %>
</td>
<td>
<%= number_with_delimiter convert_duration(account.current_month_video_duration_total, from: :seconds, to: :minutes).round %> minutes
</td>
<td>
<%= number_with_delimiter convert_duration(account.video_duration_total, from: :seconds, to: :minutes).round %> minutes
</td>
<td>
<%= number_to_human_size account.storage_total %>
</td>
<td>
<%= time_ago_in_words(account.created_at) %> ago
</td>
<td>
<div class="btn-group">
<%= button_tag "Manage", class: "btn btn-light btn-sm dropdown-toggle border", data: { toggle: "dropdown", boundary: "window" }, aria: { haspopup: true, expanded: false } %>
<div class="dropdown-menu dropdown-menu-right">
<%= link_to fa_icon("arrow-right", text: "Overview"), admin_account_path(account), class: "dropdown-item" %>
<%= link_to fa_icon("pencil", text: "Edit"), edit_admin_account_path(account), class: "dropdown-item" %>
<%= link_to fa_icon("arrow-right", text: "Account Managers"), account_auths_path({ account_id: account.id}), class: "dropdown-item" %>
</div>
</div>
</td>
</tr>

View File

@@ -0,0 +1,14 @@
<%= errors_summary_for account %>
<%= bootstrap_form_with model: [:admin, account], local: true do |form| %>
<%= field_set_tag content_tag(:span, "Account Details", class: "h6 text-muted text-uppercase") do %>
<%= form.text_field :name %>
<%= form.select :plan_uid, options_for_account_plan_select, { label: "Plan" }, class: "form-control custom-select" %>
<% end %>
<div class="row align-items-center text-center mt-4">
<%= link_to t("shared.cancel"), [:admin, :accounts], class: "col-3 text-reset" %>
<div class="col-9">
<%= form.button class: class_string("btn btn-block", ["btn-success", "btn-primary"] => account.new_record?), data: { disable_with: t("shared.disable_with") } %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,16 @@
<tr>
<td><%= user.email %></td>
<td><%= user.account_auths.map(&:role).join(',') %></td>
<td class="text-right">
<% if user != Current.user %>
<div class="btn-group">
<%= button_tag "Manage", class: "btn btn-light btn-sm dropdown-toggle border", data: { toggle: "dropdown", boundary: "window" }, aria: { haspopup: true, expanded: false } %>
<div class="dropdown-menu dropdown-menu-right">
<%= link_to fa_icon("user-secret", text: "Masquerade"), [:admin, user, :masquerade], method: :post, class: "dropdown-item" %>
<%= link_to fa_icon("pencil", text: "Edit"), [:edit, :admin, user], class: "dropdown-item" %>
<%= link_to fa_icon("trash", text: "Delete"), [:admin, user], class: "dropdown-item", remote: true, method: :delete, data: { confirm: "Are you sure?" } %>
</div>
</div>
<% end %>
</td>
</tr>

View File

@@ -0,0 +1,13 @@
<tr>
<td><%= video.project.name %></td>
<td><%= video.name %></td>
<td class="text-right">
<div class="btn-group">
<%= button_tag "Manage", class: "btn btn-light btn-sm dropdown-toggle border", data: { toggle: "dropdown", boundary: "window" }, aria: { haspopup: true, expanded: false } %>
<div class="dropdown-menu dropdown-menu-right">
<%= link_to fa_icon("sticky-note fw", text: "Analysis"), [video, :video_analyses, locale: I18n.locale], class: "dropdown-item" %>
<%= link_to fa_icon("tags fw", text: "Re-analyze"), [video, :video_analyses, locale: I18n.locale], method: "post", class: "dropdown-item" %>
</div>
</div>
</td>
</tr>

View File

@@ -0,0 +1,6 @@
<div class="card shadow-sm">
<%= card_header text: "Edit Account", close_action_path: [:admin, :accounts] %>
<div class="card-body">
<%= render "form", account: @account %>
</div>
</div>

View File

@@ -0,0 +1,39 @@
<div class="d-flex flex-row-reverse justify-content-between align-items-right mb-3">
<%= bootstrap_form_with url: admin_accounts_path, method: :get, remote: true, layout: :inline, id: "search" do |form| %>
<%= form.search_field :query, hide_label: true, placeholder: t(".actions.search"), class: "rounded-pill-right", value: params[:query], prepend: form.button(fa_icon("search"), id: "search-button", class: "btn btn-light border rounded-pill-left") %>
<% end%>
<% if policy(Account).new? %>
<%= link_to fa_icon("plus", text: "New Account"), [:new, :admin, :account], class: "btn btn-primary mb-3" %>
<% end %>
</div>
<div class="border bg-white rounded shadow-sm pb-3 table-responsive">
<table class="table table-striped tr-px-4 align-all-middle">
<thead class="thead-light">
<tr>
<th>Name</th>
<th>Plan</th>
<th># Projects</th>
<th>Monthly Video Upload Minutes</th>
<th>Total Video Upload Minutes</th>
<th>Total Storage</th>
<th>Created At</th>
<th></th>
</tr>
</thead>
<tbody id="accounts">
<% if @accounts.any? %>
<%= render @accounts %>
<% else %>
<tr>
<td colspan="6" class="py-4 text-center text-muted"><%= t(".empty") %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div id="accounts_pagination" class="mt-3">
<%= will_paginate @accounts %>
</div>

View File

@@ -0,0 +1,3 @@
$("#accounts").html("<%= j render @accounts %>");
$("form input[type='search']").val("<%= params[:query] %>");
$("#accounts_pagination").html("<%= j will_paginate @accounts %>");

View File

@@ -0,0 +1,6 @@
<div class="card shadow-sm">
<%= card_header text: "New Account", close_action_path: [:admin, :accounts] %>
<div class="card-body">
<%= render "form", account: @account %>
</div>
</div>

View File

@@ -0,0 +1,38 @@
<div class="card shadow-sm">
<%= card_header text: @account.name, close_action_path: [:admin, :accounts] %>
<div class="card-body">
<%= card_field_set_tag "Account Details" do %>
<dl class="row">
<dt class="col-sm-2">Plan</dt>
<dd class="col-sm-10"><%= @account.plan_name %></dd>
<dt class="col-sm-2">Users</dt>
<dd class="col-sm-10"><%= @account.users.size %></dd>
<dt class="col-sm-2">Created at</dt>
<dd class="col-sm-10"><%= time_ago_in_words(@account.created_at) %> ago</dd>
</dl>
<% end %>
<%= card_field_set_tag "Videos" do %>
<%= bootstrap_form_with url: [:admin, @account], method: :get, remote: true, layout: :inline, id: "search" do |form| %>
<%= form.search_field :query, hide_label: true, placeholder: t("shared.search"), class: "rounded-pill-right", value: params[:query], prepend: form.button(fa_icon("search"), id: "search-button", class: "btn btn-light border rounded-pill-left") %>
<% end%>
<div class="table-responsive-sm">
<table class="table table-striped tr-px-4 align-all-middle">
<thead class="thead-light">
<tr>
<th>Project</th>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody id="videos">
<%= render partial: "admin/accounts/video", collection: @videos %>
</tbody>
</table>
</div>
<div id="videos_pagiantion">
<%= will_paginate @videos %>
</div>
<% end %>
</div>
</div>

View File

@@ -0,0 +1,2 @@
$("#videos").html("<%= j render partial: "admin/accounts/video", collection: @videos %>");
$("#videos_pagination").html("<%= j will_paginate @videos %>");

View File

@@ -0,0 +1,36 @@
<header class="container-fluid bg-light border-bottom py-3 sticky-top">
<div class="row align-items-center">
<div class="col-4">
<%= link_to signed_in_root_path, class: "navbar-brand" do %>
<%= suite_wordmark %>
<% end %>
<%= link_to fa_icon("arrow-circle-left", text: "Back To Account"), :projects, class: "text-reset text-decoration-none" %>
</div>
<div class="col-4 text-center">
<h1 class="h4 m-0">Admin</h1>
</div>
<div class="col-4 text-right">
<div class="btn-group">
<%= link_to :profile, class: "text-decoration-none text-reset dropdown-toggle", data: { toggle: "dropdown" } do %>
<span class="mr-2"><%= get_name_or_email(Current.user) %></span>
<%= image_or_text_avatar(Current.user) %>
<% end %>
<div class="dropdown-menu">
<% if Current.user.admin? %>
<%= link_to "BIG Admin", [:admin, :signed_in_root], class: "dropdown-item" %>
<% end %>
<%= link_to "Profile Settings", profile_path, class: "dropdown-item" %>
<% # TODO: Use null object pattern %>
<% if Current.account && Current.user.account_manager?(Current.account) %>
<%= link_to "Account Settings", [:account_auths], class: "dropdown-item" %>
<% end %>
<%= link_to t(".sign_out"), :session, method: :delete, class: "dropdown-item" %>
</div>
</div>
</div>
</div>
</header>

View File

@@ -0,0 +1,20 @@
<aside class="bg-dark text-white p-4 rounded">
<nav>
<ul class="nav nav-pills nav-pills-dark flex-column">
<li class="nav-item">
<%= link_to fa_icon("globe fw", text: "Accounts"), [:admin, :accounts], class: class_string("nav-link", "active" => controller_name == "accounts") %>
</li>
<li class="nav-item">
<%= link_to fa_icon("users fw", text: "Users"), [:admin, :users], class: class_string("nav-link", "active" => controller_name == "users") %>
</li>
<li class="nav-item">
<%= link_to fa_icon("bug fw", text: "Errors"), "https://sentry.io/bigmedia/", class: "nav-link", target: :_blank %>
</li>
<% if ENV["REDIS_URL"] %>
<li class="nav-item">
<%= link_to fa_icon("cogs fw", text: "Background Queue"), [:admin, :background_queue], class: "nav-link" %>
</li>
<% end %>
</ul>
</nav>
</aside>

View File

@@ -0,0 +1,24 @@
<%= errors_summary_for user %>
<%= bootstrap_form_with model: [:admin, user], local: true, html: { autocorrect: :off, autocapitalize: :none, autocomplete: :off, spellcheck: false } do |form| %>
<%= form.email_field :email %>
<%# autocomplete: 'new-password' prevent the existing password value from showing up %>
<%= form.password_field :password, autocomplete: "new-password" %>
<% if user.new_record? %>
<%= form.collection_select :account_id, accounts, :id, :name, { prompt: "Select an Account", required: true }, class: "form-control custom-select" %>
<%= form.select :role, options_for_role_select, {}, class: "form-control custom-select" %>
<% end %>
<div class="mb-4">
<%= form.check_box :admin, label: "Admin User" %>
<div class="help-block text-muted"><%= fa_icon :warning, text: "This option grants access to the Admin dashboard. This should only be for trusted BiG employees." %></div>
</div>
<div class="row align-items-center text-center mt-4">
<%= link_to t("shared.cancel"), [:admin, :users], class: "col-3 text-reset" %>
<div class="col-9">
<%= form.button class: class_string("btn btn-block", ["btn-success", "btn-primary"] => user.new_record?), data: { disable_with: t("shared.disable_with") } %>
</div>
</div>
<% end %>

View File

@@ -0,0 +1,32 @@
<tr id="<%= dom_id(user) %>">
<td>
<%= user.email %>
</td>
<td>
<%= user.first_name %>
</td>
<td>
<%= user.last_name %>
</td>
<td>
<%= user.account_auths.map(&:role).compact.join(",") %>
</td>
<td>
<%= user.accounts.map(&:name).join(",") %>
</td>
<td>
<%= time_ago_in_words(user.created_at) %> ago
</td>
<td class="text-right">
<% if user != Current.user %>
<div class="btn-group">
<%= button_tag "Manage", class: "btn btn-light btn-sm dropdown-toggle border", data: { toggle: "dropdown", boundary: "window" }, aria: { haspopup: true, expanded: false } %>
<div class="dropdown-menu dropdown-menu-right">
<%= link_to fa_icon("user-secret", text: "Masquerade"), [:admin, user, :masquerade], method: :post, class: "dropdown-item" %>
<%= link_to fa_icon("pencil", text: "Edit"), [:edit, :admin, user], class: "dropdown-item" %>
<%= link_to fa_icon("trash", text: "Delete"), [:admin, user], class: "dropdown-item", remote: true, method: :delete, data: { confirm: "Are you sure?" } %>
</div>
</div>
<% end %>
</td>
</tr>

View File

@@ -0,0 +1,6 @@
<div class="card shadow-sm">
<%= card_header text: "Edit User", close_action_path: [:admin, :users] %>
<div class="card-body">
<%= render "form", user: @user, accounts: @accounts %>
</div>
</div>

View File

@@ -0,0 +1,34 @@
<div class="d-flex flex-row justify-content-between align-items-center mb-3">
<% if policy(User).new? %>
<%= link_to fa_icon("plus", text: t(".actions.new")), [:new, :admin, :user], class: "btn btn-primary mb-3" %>
<% end %>
<%= bootstrap_form_with url: admin_users_path, method: :get, remote: true, layout: :inline, id: "search" do |form| %>
<%= form.search_field :query, hide_label: true, placeholder: t(".actions.search"), class: "rounded-pill-right", value: params[:query], prepend: form.button(fa_icon("search"), class: "btn btn-light border rounded-pill-left") %>
<% end %>
</div>
<div class="border bg-white rounded shadow-sm pb-3 table-responsive">
<table class="table table-striped tr-px-4 align-all-middle">
<thead class="thead-light">
<tr>
<th>Email</th>
<th>First Name</th>
<th>Last Name</th>
<th>Role</th>
<th>Account Name</th>
<th>Created At</th>
<th></th>
</tr>
</thead>
<tbody id="users">
<% if @users.any? %>
<%= render @users %>
<% else %>
<tr>
<td colspan="5" class="py-4 text-center text-muted"><%= t(".empty") %></td>
</tr>
<% end %>
</tbody>
</table>
</div>

View File

@@ -0,0 +1,2 @@
$("#users").html("<%= j render(@users) %>");
$("form input[type='search']").val("<%= params[:query] %>");

View File

@@ -0,0 +1,6 @@
<div class="card shadow-sm">
<%= card_header text: "New User", close_action_path: [:admin, :users] %>
<div class="card-body">
<%= render "form", user: @user, accounts: @accounts %>
</div>
</div>