Skip to content

Commit

Permalink
Move all logic from profile show to accounts show (close openware#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpetrusenko committed May 8, 2018
1 parent 033bea0 commit 592a5d4
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 78 deletions.
8 changes: 8 additions & 0 deletions app/controllers/admin/accounts_controller.rb
Expand Up @@ -6,6 +6,14 @@ def index
@accounts = Account.page(params[:page])
end

def show
@account = Account.find(params[:id])
@profile = @account.profile
@documents = @account.documents
@labels = @account.labels
@phones = @account.phones
end

def edit
@account = Account.find(params[:id])
@roles = %w[admin compliance member]
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/admin/labels_controller.rb
Expand Up @@ -13,7 +13,7 @@ def create
@label = @account.labels.new(label_params)

if @label.save
redirect_to admin_profile_path(@account.profile), notice: 'Label was successfully created.'
redirect_to admin_account_path(@account), notice: 'Label was successfully created.'
else
render :new
end
Expand All @@ -24,15 +24,15 @@ def edit

def update
if @label.update(label_params)
redirect_to admin_profile_path(@account.profile), notice: 'Label was successfully updated.'
redirect_to admin_account_path(@account), notice: 'Label was successfully updated.'
else
render :edit
end
end

def destroy
@label.destroy!
redirect_to admin_profile_path(@account.profile), notice: 'Label was successfully destroyed.'
redirect_to admin_account_path(@account), notice: 'Label was successfully destroyed.'
end

private
Expand Down
16 changes: 3 additions & 13 deletions app/controllers/admin/profiles_controller.rb
Expand Up @@ -2,23 +2,13 @@

module Admin
class ProfilesController < ModuleController
def index
params[:filter] = params[:filter] || 'pending'
@profiles = Profile.all
@profiles = @profiles.where(state: params[:filter]) if params[:filter].present?
@profiles = @profiles.page(params[:page])
end

def show
@profile = Profile.find(params[:id])
@documents = @profile.account.documents
@labels = @profile.account.labels
end
def edit
end

def change_state
@profile = Profile.find(params[:id])
if @profile.update(state: params[:state])
redirect_to admin_profile_path(@profile), notice: 'Profile was successfully updated.'
redirect_to admin_account_path(@profile.account), notice: 'Profile was successfully updated.'
else
redirect_to admin_profiles_path
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/accounts/index.html.erb
Expand Up @@ -20,7 +20,7 @@
<% @accounts.each do |account| %>
<tr class=<%= 'table-danger' if account.unlock_token? %>>
<td><%= account.id %></td>
<td><%= account.email %></td>
<td><%= link_to account.email, admin_account_path(account.id) %></td>
<td><span class=" badge <%= badge_by_role(account.role) %>"> <%= account.role %> </span></td>
<td><%= account.level %></td>
<td><%= label_tags(account) %></td>
Expand Down
@@ -1,10 +1,17 @@
<div class="container">
<h1>Profile</h1>
<h4 class="text-center"> Profile </h4>
<ul class="list-group">
<li class="list-group-item">
<b> E-mail: </b>
<%= @profile.account.email%>
</li>
<b> E-mail: </b>
<%= @account.email%>
</li >

<li class="list-group-item">
<b>Phones:</b>
<% @phones.each do |phone| %>
<%= phone.number%>
<% end %>
</li >

<li class="list-group-item">
<b> First Name: </b>
Expand Down Expand Up @@ -36,21 +43,46 @@
<%= @profile.country%>
</li>

<li class="list-group-item">
<li class="list-group-item">
<b> State: </b>
<div class="dropdown show">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<%= @profile.state.upcase_first %>
</a>
<div class="dropdown-menu">
<% Profile::STATES.each do |state|%>
<%= link_to(state.upcase_first, change_state_admin_profile_path(@profile, state: state), method: :put, class: 'dropdown-item') unless @profile.state == state%>
<%= link_to(state.upcase_first, change_state_admin_profile_path(@account.profile, state: state), method: :put, class: 'dropdown-item') unless @account.profile.state == state%>
<% end %>
</div>
</div>
</li>
<li class="list-group-item">
<%= link_to 'Edit', edit_admin_profile_path(@account.profile), class: 'btn btn-primary btn-sm' %>
</li>
</ul>
<br>
<h4 class="text-center"> Phones </h4>
<table class="table table-bordered table-striped table-hover table-sm text-center">
<thead>
<tr>
<th>ID</th>
<th>Country</th>
<th>Number</th>
<th>Vlidated at</th>
</tr>
</thead>
<tbody>
<% @phones.each do |phone| %>
<tr>
<td><%= phone.id %></td>
<td><%= phone.country %></td>
<td><%= phone.number %></td>
<td><%= phone.validated_at %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<h4 class="text-center"> Documents </h4>
<table class="table table-bordered table-striped table-hover table-sm text-center">
<thead>
Expand All @@ -77,7 +109,7 @@
</tbody>
</table>
<br>
<%= link_to 'New Label', new_admin_account_label_path(@profile.account_id), class: 'btn btn-success' %>
<%= link_to 'New Label', new_admin_account_label_path(@account.id), class: 'btn btn-success' %>
<br>
<h4 class="text-center"> Labels </h4>
<table class="table table-bordered table-striped table-hover table-sm text-center">
Expand All @@ -96,8 +128,8 @@
<td><%= label.key %></td>
<td><%= label.value %></td>
<td><%= label.scope %></td>
<td><%= link_to 'Edit', edit_admin_account_label_path(id: label.id, account_id: @profile.account_id), class: 'btn btn-primary btn-sm' %></td>
<td><%= link_to 'Delete', admin_account_label_path(id: label.id, account_id: @profile.account_id), class: 'btn btn-danger btn-sm', method: :delete, data: {confirm: 'Are you sure?'} %></td>
<td><%= link_to 'Edit', edit_admin_account_label_path(id: label.id, account_id: @account.id), class: 'btn btn-primary btn-sm' %></td>
<td><%= link_to 'Delete', admin_account_label_path(id: label.id, account_id: @account.id), class: 'btn btn-danger btn-sm', method: :delete, data: {confirm: 'Are you sure?'} %></td>
</tr>
<% end %>
</tbody>
Expand Down
30 changes: 30 additions & 0 deletions app/views/admin/profiles/_form.html.erb
@@ -0,0 +1,30 @@
<%= form_with(model: [:admin, @account, @label], local: true) do |form| %>
<% if label.errors.any? %>
<div class="alert alert-danger">
<h2><%= pluralize(@label.errors.count, "error") %> prohibited this label from being saved:</h2>
<ul>
<% @label.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<%= form.label :key, class: 'control-label'%>
<%= form.text_field :key, class: 'form-control col-sm-10'%>
<br>

<%= form.label :value, class: 'control-label'%>
<%= form.text_field :value, class: 'form-control col-sm-10'%>
<br>

<%= form.label :scope, class: 'control-label'%>
<%= form.select :scope, Label::SCOPES , class: 'form-control col-sm-10'%>
<br>

<%= form.submit 'Submit', class: 'btn btn-primary' %>

<br>
<br>

<% end %>
5 changes: 5 additions & 0 deletions app/views/admin/profiles/edit.html.erb
@@ -0,0 +1,5 @@
<div class="container">
<h1>Editing label</h1>
<%= render 'form', label: @label %>
<br>
</div>
44 changes: 0 additions & 44 deletions app/views/admin/profiles/index.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/views/admin/shared/_navigation.html.erb
Expand Up @@ -9,12 +9,6 @@
</li>
<% end %>
<% if can? :read, Profile %>
<li class="nav-item <%= 'active' if params[:controller].match?(/profiles/) %>">
<%= link_to 'Profiles', admin_profiles_path, class: 'nav-link' %>
</li>
<% end %>
<% if current_account.role.admin? %>
<li class="nav-item <%= 'active' if params[:controller].match?(/application/) %>" >
<%= link_to 'Applications', oauth_applications_path, class: 'nav-link' %>
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Expand Up @@ -24,11 +24,11 @@

namespace :admin do
get '/', to: 'accounts#index', as: :accounts
resources :accounts, except: %i[new create show] do
resources :accounts, except: %i[new create] do
resources :labels, except: %i[index show]
end
resources :websites
resources :profiles, only: %i[index show] do
resources :profiles, only: %i[edit] do
put :change_state, on: :member
end
end
Expand Down

0 comments on commit 592a5d4

Please sign in to comment.