Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into feat/skills-show-new-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro Dias Batista authored Dec 13, 2023
2 parents cb10f59 + 15bceee commit 6039894
Show file tree
Hide file tree
Showing 27 changed files with 744 additions and 64 deletions.
63 changes: 63 additions & 0 deletions app/controllers/new_admin/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,77 @@ def show
@repository = Repository.find(params[:id]).decorate
end

def new
@repository = Repository.new
end

def create
@repository = Repository.new(repository_params)

if @repository.save
redirect_on_success new_admin_repositories_path, message_scope: 'create'
else
render_on_failure :new
end
end

def edit
@repository = Repository.find(params[:id])
end

def update
@repository = Repository.find(params[:id])

@repository.attributes = repository_params

if @repository.save
redirect_on_success new_admin_show_repository_path(id: @repository.id), message_scope: 'update'
else
render_on_failure :edit
end
end

def destroy
@repository = Repository.find(params[:id])

if @repository.destroy
redirect_on_success new_admin_repositories_path, message_scope: "destroy"
else
render_on_failure :index
end
end

private

def repositories
NewAdmin::RepositoryQuery.new(**filter_params).call
end

def repository_params
params.require(:repository).permit(:link, :language, :description, :highlight)
end

def filter_params
params.permit(:repository_name_search, languages: []).to_h.symbolize_keys
end

def redirect_on_success(url, message_scope:)
flash[:notice] = I18n.t(:notice, scope: "flash.actions.#{message_scope}",
resource_name: Repository.model_name.human)
redirect_to url
end

def render_on_failure(template)
flash.now[:alert] = @repository.errors.full_messages.to_sentence
render template, status: :unprocessable_entity
end

def errors
@repository.errors.full_messages.join('. ')
end

def error_message
I18n.t(:errors, scope: :flash, errors:)
end
end
end
33 changes: 29 additions & 4 deletions app/controllers/new_admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ def index
@users = paginate_record(users)
end

def new
@user = User.new
end

def create
@user = User.new(user_params)

if @user.save
redirect_on_success new_admin_users_path, message_scope: 'create'
else
render_on_failure :new
end
end

def show
@punches = filter_punches_by_date(params[:id], params[:from], params[:to])
end
Expand All @@ -23,10 +37,10 @@ def update
@user.attributes = user_params

if @user.save
redirect_to new_admin_admin_user_path(@user)
redirect_to new_admin_show_user_path(@user)
else
flash_errors('update')
redirect_to edit_new_admin_admin_user_path(@user)
redirect_to edit_new_admin_user_path(@user)
end
end

Expand Down Expand Up @@ -60,14 +74,14 @@ def find_english_evaluations(id)
def filters
params.permit(
:active,
:contract_type,
:name,
:backend_level,
:contract_type,
:email,
:frontend_level,
:is_admin,
:is_allocated,
:is_office_head,
:name,
:office_id,
skill_ids: []
)
Expand Down Expand Up @@ -105,5 +119,16 @@ def alert_message(scope)
def error_message
I18n.t(:errors, scope: "flash", errors:)
end

def redirect_on_success(url, message_scope:)
flash[:notice] = I18n.t(:notice, scope: "flash.actions.#{message_scope}",
resource_name: User.model_name.human)
redirect_to url
end

def render_on_failure(template)
flash.now[:alert] = @user.errors.full_messages.to_sentence
render template, status: :unprocessable_entity
end
end
end
3 changes: 1 addition & 2 deletions app/views/application/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
</li>
</ul>
</li>

<li class="px-6 py-3 text-sm font-semibold cursor-pointer">
<button
data-menu="submenu"
Expand All @@ -109,7 +108,7 @@
<li class="my-2">
<%=
link_to I18n.t('users.title'),
new_admin_admin_user_index_path,
new_admin_users_path,
class: "block w-full hover:text-gray-800 dark:hover:text-gray-200"
%>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<% allocations.each do |allocation| %>
<tr class="text-gray-700 dark:text-gray-400">
<td class="px-4 py-3">
<%= link_to new_admin_admin_user_path(allocation.user), class: "inline-flex items-center w-full text-sm font-semibold transition-colors duration-150" do %>
<%= link_to new_admin_show_user_path(allocation.user), class: "inline-flex items-center w-full text-sm font-semibold transition-colors duration-150" do %>
<div class="flex items-center text-sm underline hover:text-white">
<p class="text-sm text-gray-600 dark:text-gray-400 dark:hover:text-gray-200">
<%= allocation.user.first_and_last_name %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="flex items-center">
<% contribution.users.each do |user| %>
<div><%= link_to user.first_and_last_name,
new_admin_admin_user_path(id: user.id),
new_admin_show_user_path(id: user.id),
class: 'font-semibold transition-colors duration-150 underline dark:hover:text-white hover:text-gray-900' %>
</div>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/new_admin/evaluations/_evaluations_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<div class="flex items-center">
<%=
link_to evaluation[:evaluator],
new_admin_admin_user_path(evaluation[:evaluator_id]),
new_admin_show_user_path(evaluation[:evaluator_id]),
class: "font-semibold transition-colors duration-150 underline dark:hover:text-white hover:text-gray-900"
%>
</div>
Expand All @@ -26,7 +26,7 @@
<div class="flex items-center">
<%=
link_to evaluation[:evaluated],
new_admin_admin_user_path(evaluation[:evaluated_id]),
new_admin_show_user_path(evaluation[:evaluated_id]),
class: "font-semibold transition-colors duration-150 underline dark:hover:text-white hover:text-gray-900"
%>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/new_admin/evaluations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<p class="text-sm text-gray-600 dark:text-gray-400 font-semibold">
<%=
link_to @evaluation.evaluator.name,
new_admin_admin_user_path(@evaluation.evaluator),
new_admin_show_user_path(@evaluation.evaluator),
class: 'font-semibold transition-colors duration-150 underline dark:hover:text-white hover:text-gray-900'
%>
</p>
Expand All @@ -67,7 +67,7 @@
<p class="text-sm text-gray-600 dark:text-gray-400 font-semibold">
<%=
link_to @evaluation.evaluated.name,
new_admin_admin_user_path(@evaluation.evaluated),
new_admin_show_user_path(@evaluation.evaluated),
class: 'font-semibold transition-colors duration-150 underline dark:hover:text-white hover:text-gray-900'
%>
</p>
Expand Down
71 changes: 71 additions & 0 deletions app/views/new_admin/repositories/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<%= form_with model: repository, url: url do |form| %>
<div class="w-full overflow-hidden rounded-lg ring-1 ring-black ring-opacity-5">
<div class="w-full overflow-x-auto">
<table class="w-full whitespace-no-wrap" id="form_repository">
<thead>
<tr class="text-xs font-semibold tracking-wide text-left text-gray-500 uppercase border-b dark:border-gray-700 bg-gray-50 dark:text-white dark:bg-slate-700">
<th colspan="100%" class="px-4 py-3"><%= t 'repositories.new' %></th>
</tr>
</thead>

<tbody class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800">
<tr class="text-gray-700 dark:text-gray-300">
<th class="w-1/12">
<div class="ml-3 text-xs font-semibold tracking-wide text-left text-gray-500 uppercase ">
<%= Repository.human_attribute_name('link') %>
</div>
</th>
<td class="px-4 py-3">
<div class="flex items-center">
<%= form.text_field :link, class: "bg-gray-100 font-semibold rounded-lg text-gray-600 dark:text-gray-400 h-8 dark:bg-slate-700" %>
</div>
</td>
</tr>

<tr class="text-gray-700 dark:text-gray-300">
<th class="w-1/12">
<div class="ml-3 text-xs font-semibold tracking-wide text-left text-gray-500 uppercase ">
<%= Repository.human_attribute_name('description') %>
</div>
</th>
<td class="px-4 py-3">
<div class="flex items-center">
<%= form.text_area :description, class: "bg-gray-100 font-semibold rounded-lg text-gray-600 dark:text-gray-400 h-8 dark:bg-slate-700 w-1/2 h-1/4" %>
</div>
</td>
</tr>

<tr class="text-gray-700 dark:text-gray-300">
<th class="w-1/12">
<div class="ml-3 text-xs font-semibold tracking-wide text-left text-gray-500 uppercase ">
<%= Repository.human_attribute_name('language') %>
</div>
</th>
<td class="px-4 py-3">
<div class="flex items-center">
<%= form.text_field :language, class: "bg-gray-100 font-semibold rounded-lg text-gray-600 dark:text-gray-400 h-8 dark:bg-slate-700" %>
</div>
</td>
</tr>

<tr class="text-gray-700 dark:text-gray-300">
<th class="w-1/12">
<div class="ml-3 text-xs font-semibold tracking-wide text-left text-gray-500 uppercase ">
<%= Repository.human_attribute_name('highlight') %>
</div>
</th>
<td class="px-4 py-3">
<div class="flex items-center">
<%= form.check_box :highlight, { checked: repository.highlight? }, 'true', 'false' %>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>

<div class="flex mt-4">
<%= form.submit t('form.button.submit'), class: "px-4 py-2 cursor-pointer font-semibold text-sm text-white transition-colors duration-150 rounded-lg bg-primary-600 hover:bg-primary-700" %>
</div>
<% end %>
19 changes: 9 additions & 10 deletions app/views/new_admin/repositories/_repositories_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
<%= link_to new_admin_show_repository_path(id: repository.id), class: "flex items-center justify-between px-2 py-2 text-sm font-medium leading-5 rounded-lg text-primary-600 dark:text-gray-400 hover:text-primary-400 hover:dark:text-gray-300 focus:outline-none focus:ring-gray" do %>
<%= heroicon 'magnifying-glass', variant: :mini, options: { class: "w-5 h-5" } %>
<% end %>
<button
class="flex items-center justify-between px-2 py-2 text-sm font-medium leading-5 rounded-lg text-primary-600 dark:text-gray-400 hover:text-primary-400 hover:dark:text-gray-300 focus:outline-none focus:ring-gray"
aria-label="Edit">
<%= heroicon 'pencil', variant: :solid, options: { class: "w-5 h-5" } %>
</button>
<button
class="flex items-center justify-between px-2 py-2 text-sm font-medium leading-5 rounded-lg text-primary-600 dark:text-gray-400 hover:text-primary-400 hover:dark:text-gray-300 focus:outline-none focus:ring-gray"
aria-label="Delete">
<%= heroicon 'trash', variant: :mini, options: { class: "w-5 h-5" } %>
</button>
<%= link_to edit_new_admin_repository_path(id: repository.id), class: "flex items-center justify-between px-2 py-2 text-sm font-medium leading-5 rounded-lg text-primary-600 dark:text-gray-400 hover:text-primary-400 hover:dark:text-gray-300 focus:outline-none focus:ring-gray" do %>
<%= heroicon 'pencil', variant: :solid, options: { class: "w-5 h-5" } %>
<% end %>
<%= link_to new_admin_destroy_repository_path(id: repository.id),
class: "flex items-center justify-between px-2 py-2 text-sm font-medium leading-5 rounded-lg text-primary-600 dark:text-gray-400 hover:text-primary-400 hover:dark:text-gray-300 focus:outline-none focus:ring-gray",
method: :delete,
data: { confirm: t('delete_confirmation') } do %>
<%= heroicon 'trash', variant: :mini, options: { class: "w-5 h-5" } %>
<% end %>
</div>
</td>
</tr>
Expand Down
7 changes: 7 additions & 0 deletions app/views/new_admin/repositories/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% content_for :page_title do %>
<%= t 'helpers.edit' %>
<% end %>

<div data-tab-id="edit_repository">
<%= render 'form', repository: @repository, url: new_admin_update_repository_path %>
</div>
2 changes: 1 addition & 1 deletion app/views/new_admin/repositories/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div class="flex justify-end">
<div class="mx-2 mb-4">
<%= link_to new_admin_repositories_url do %>
<%= link_to new_new_admin_repository_path do %>
<button class="px-4 py-2 text-sm text-white transition-colors font-semibold duration-150 border border-transparent rounded-lg bg-primary-600 hover:bg-primary-700">
<%= t 'repositories.new' %>
</button>
Expand Down
7 changes: 7 additions & 0 deletions app/views/new_admin/repositories/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% content_for :page_title do %>
<%= t 'repositories.new' %>
<% end %>

<div class="space-y-6">
<%= render 'form', repository: @repository, url: new_admin_repositories_path %>
</div>
16 changes: 10 additions & 6 deletions app/views/new_admin/repositories/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
<div data-tab-id="repository" class="space-y-6">
<div id="repository_actions" class="flex items-center justify-end">
<div class="mx-2">
<button class="px-4 py-2 text-sm text-white transition-colors font-semibold duration-150 border border-transparent rounded-lg bg-primary-600 hover:bg-primary-700">
<%= t '.edit' %>
</button>
<%= link_to edit_new_admin_repository_path(id: @repository.id) do %>
<button class="px-4 py-2 text-sm text-white transition-colors font-semibold duration-150 border border-transparent rounded-lg bg-primary-600 hover:bg-primary-700">
<%= t 'helpers.edit' %>
</button>
<% end %>
</div>

<div class="mx-2">
<button class="px-4 py-2 text-sm text-white transition-colors font-semibold duration-150 border border-transparent rounded-lg bg-primary-600 hover:bg-primary-700">
<%= t '.destroy' %>
</button>
<%= link_to new_admin_destroy_repository_path(id: @repository.id), method: :delete, data: { confirm: t('delete_confirmation') } do %>
<button class="px-4 py-2 text-sm text-white transition-colors font-semibold duration-150 border border-transparent rounded-lg bg-primary-600 hover:bg-primary-700">
<%= t 'helpers.destroy' %>
</button>
<% end %>
</div>
</div>
<table class="w-full whitespace-nowrap">
Expand Down
4 changes: 2 additions & 2 deletions app/views/new_admin/users/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</th>
<td class="px-4 py-3">
<div class="flex items-center text-sm">
<%= link_to edit_new_admin_admin_user_path(@user) do %>
<%= link_to edit_new_admin_user_path(@user) do %>
<p class="flex text-sm text-gray-600 dark:text-gray-400 font-semibold">
<%= user.first_and_last_name %>
<svg
Expand Down Expand Up @@ -254,7 +254,7 @@
<% if user.mentor %>
<div class="flex items-center text-sm">
<p class="text-sm text-gray-600 dark:text-gray-400">
<%= link_to new_admin_admin_user_path(user.mentor_id), class: "inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 underline hover:no-underline dark:hover:text-gray-200" do %>
<%= link_to new_admin_show_user_path(user.mentor_id), class: "inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 underline hover:no-underline dark:hover:text-gray-200" do %>
<%= user.mentor_name %>
<% end %>
</p>
Expand Down
Loading

0 comments on commit 6039894

Please sign in to comment.