basic homegrown admin

starting with users and basic (wrong) info
wip to remove administrate
This commit is contained in:
Torsten Ruger 2017-06-06 10:12:22 +03:00
parent 79218f213d
commit e51bcfec17
25 changed files with 194 additions and 431 deletions

View File

@ -20,6 +20,9 @@ gem 'simple_form'
gem 'animate-scss' , :github => "ejholmes/animate.scss"
gem "best_in_place"
gem 'rack-attack'
gem "ransack"
gem "will_paginate"
gem 'jquery-ui-rails'
#asynchronous sending
gem 'sucker_punch'
@ -28,9 +31,8 @@ gem "skylight"
gem 'rollbar'
group :development do
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'better_errors'
# gem 'better_errors'
gem 'capistrano', "3.8.1"
gem 'capistrano-bundler'
gem 'capistrano-rails'

View File

@ -68,12 +68,6 @@ GEM
best_in_place (3.1.1)
actionpack (>= 3.2)
railties (>= 3.2)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
rack (>= 0.9.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap (4.0.0.alpha5)
autoprefixer-rails (>= 6.0.3)
sass (>= 3.4.19)
@ -120,7 +114,6 @@ GEM
database_cleaner (1.6.1)
datetime_picker_rails (0.0.7)
momentjs-rails (>= 2.8.1)
debug_inspector (0.0.3)
devise (4.3.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
@ -181,11 +174,13 @@ GEM
nokogiri (>= 1.6.0)
ruby_parser (~> 3.5)
hub (1.12.4)
i18n (0.8.1)
i18n (0.8.4)
jquery-rails (4.3.1)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jquery-ui-rails (5.0.5)
railties (>= 3.2.16)
kaminari (1.0.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.0.1)
@ -214,7 +209,7 @@ GEM
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.1.0)
mini_portile2 (2.2.0)
minitest (5.10.2)
momentjs-rails (2.17.1)
railties (>= 3.1)
@ -226,8 +221,8 @@ GEM
net-ssh (4.1.0)
newrelic_rpm (4.1.0.333)
nio4r (2.0.0)
nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
normalize-rails (4.1.1)
notiffany (0.1.1)
nenv (~> 0.1)
@ -237,6 +232,8 @@ GEM
capybara (~> 2.1)
cliver (~> 0.3.1)
websocket-driver (>= 0.2.0)
polyamorous (1.3.1)
activerecord (>= 3.0)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
@ -275,6 +272,12 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (12.0.0)
ransack (1.8.2)
actionpack (>= 3.0)
activerecord (>= 3.0)
activesupport (>= 3.0)
i18n
polyamorous (~> 1.3)
rb-fchange (0.0.6)
ffi
rb-fsevent (0.9.8)
@ -367,15 +370,11 @@ GEM
execjs (>= 0.3.0, < 3)
warden (1.2.7)
rack (>= 1.0)
web-console (2.3.0)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket (1.2.4)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2)
will_paginate (3.1.5)
xpath (2.0.0)
nokogiri (~> 1.3)
@ -386,7 +385,6 @@ DEPENDENCIES
administrate
animate-scss!
best_in_place
better_errors
bootstrap (= 4.0.0.alpha5)
byebug
capistrano (= 3.8.1)
@ -410,6 +408,7 @@ DEPENDENCIES
html2haml
hub
jquery-rails
jquery-ui-rails
launchy
mysql2
newrelic_rpm
@ -419,6 +418,7 @@ DEPENDENCIES
rack-attack
rails (= 5.0.3)
rails_layout
ransack
rb-fchange
rb-fsevent
rb-inotify
@ -436,7 +436,7 @@ DEPENDENCIES
tether-rails
therubyracer
uglifier
web-console (~> 2.0)
will_paginate
BUNDLED WITH
1.14.6
1.15.1

View File

@ -0,0 +1,46 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
body
padding-top: 30px
@import bootstrap
.container-fluid
max-width: 90%
.alert
padding: 8px
radius: 6px
.alert-notice
background-color: #00FFEB
.alert-alert
background-color: #ff8080
.pagination
margin-top: 55px
ul.pagination
margin-bottom: 7px
ul.pagination li
font-size: 1.4rem
ul.pagination li a
background-color: rgba(255, 255, 255, 0.9)
.admin-table
font-size: 0.5rem
thead, tbody
vertical-align: top

View File

@ -0,0 +1,19 @@
# All Administrate controllers inherit from this `Admin::ApplicationController`,
# making it the ideal place to put authentication logic or other
# before_filters.
#
# If you want to add pagination or other controller-level concerns,
# you're free to overwrite the RESTful controller actions.
module Admin
class AdminController < ApplicationController
layout "admin"
before_action :authenticate_admin
def authenticate_admin
user = current_user
if(user)
redirect_to "/" unless user.admin?
end
end
end
end

View File

@ -8,16 +8,6 @@ module Admin
class ApplicationController < Administrate::ApplicationController
before_filter :authenticate_admin
def authenticate_admin
user = current_user
if(user)
redirect_to "/" unless user.admin?
end
end
end
class AdminController < ApplicationController
before_filter :authenticate_admin
def authenticate_admin
user = current_user
if(user)

View File

@ -1,4 +1,15 @@
module Admin
class UsersController < Admin::ApplicationController #AdminController
class UsersController < AdminController
def index
@q = User.search params[:q]
@user_scope = @q.result(:distinct => true)
@users = @user_scope.paginate( :page => params[:page],:per_page => 20)
end
def show
@user = User.find(params[:id])
end
end
end

View File

@ -1,92 +0,0 @@
<%#
# Collection
This partial is used on the `index` and `show` pages
to display a collection of resources in an HTML table.
## Local variables:
- `collection_presenter`:
An instance of [Administrate::Page::Collection][1].
The table presenter uses `ResourceDashboard::COLLECTION_ATTRIBUTES` to determine
the columns displayed in the table
- `resources`:
An ActiveModel::Relation collection of resources to be displayed in the table.
By default, the number of resources is limited by pagination
or by a hard limit to prevent excessive page load times
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
%>
<table aria-labelledby="page-title">
<thead>
<tr>
<% collection_presenter.attribute_types.each do |attr_name, attr_type| %>
<th class="cell-label
cell-label--<%= attr_type.html_class %>
cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>
" scope="col">
<%= link_to(sanitized_order_params.merge(
collection_presenter.order_params_for(attr_name)
)) do %>
<%= t(
"helpers.label.#{resource_name}.#{attr_name}",
default: attr_name.to_s,
).titleize %>
<% if collection_presenter.ordered_by?(attr_name) %>
<span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
<%= svg_tag(
"administrate/sort_arrow.svg",
"sort_arrow",
width: "13",
height: "13"
) %>
</span>
<% end %>
<% end %>
</th>
<% end %>
<% [valid_action?(:edit), valid_action?(:destroy)].count(true).times do %>
<th scope="col"></th>
<% end %>
</tr>
</thead>
<tbody>
<% resources.each do |resource| %>
<tr class="js-table-row"
tabindex="0"
<%= %(role=link data-url=#{polymorphic_path([namespace, resource])}) if valid_action? :show -%>
>
<% collection_presenter.attributes_for(resource).each do |attribute| %>
<td class="cell-data cell-data--<%= attribute.html_class %>">
<a href="<%= polymorphic_path([namespace, resource]) -%>"
class="action-show"
>
<%= render_field attribute %>
</a>
</td>
<% end %>
<% if valid_action? :edit %>
<td><%= link_to(
t("administrate.actions.edit"),
[:edit, namespace, resource],
class: "action-edit",
) %></td>
<% end %>
<% if valid_action? :destroy %>
<td><%= link_to(
t("administrate.actions.destroy"),
[namespace, resource],
class: "text-color-red",
method: :delete,
data: { confirm: t("administrate.actions.confirm") }
) %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>

View File

@ -1,20 +0,0 @@
%table{"aria-labelledby" => "page-title"}
%thead
%tr
- collection_presenter.attribute_types.each do |attr_name, attr_type|
%th.cell-label.cell-label--
= attr_type.html_class
cell-label--#{collection_presenter.ordered_html_class(attr_name)}
" scope="col"&gt;
\#{link_to(sanitized_order_params.merge( collection_presenter.order_params_for(attr_name) )) do}
= t( |
helpers.label.#{resource_name}.#{attr_name}, |
default: attr_name.to_s, |
).titleize |
- if collection_presenter.ordered_by?(attr_name)
%span.cell-label__sort-indicator.cell-label__sort-indicator--
= collection_presenter.ordered_html_class(attr_name)
"&gt;
\#{svg_tag( administrate/sort_arrow.svg, sort_arrow, width: 13, height: 13 )}
- [valid_action?(:edit), valid_action?(:destroy)].count(true).times do
%th{:scope => "col"}

View File

@ -1,42 +0,0 @@
<%#
# Form Partial
This partial is rendered on a resource's `new` and `edit` pages,
and renders all form fields for a resource's editable attributes.
## Local variables:
- `page`:
An instance of [Administrate::Page::Form][1].
Contains helper methods to display a form,
and knows which attributes should be displayed in the resource's form.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
%>
<%= form_for([namespace, page.resource], html: { class: "form" }) do |f| %>
<% if page.resource.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(page.resource.errors.count, "error") %>
prohibited this <%= page.resource_name %> from being saved:
</h2>
<ul>
<% page.resource.errors.full_messages.each do |message| %>
<li class="flash-error"><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<% page.attributes.each do |attribute| -%>
<div class="field-unit field-unit--<%= attribute.html_class %>">
<%= render_field attribute, f: f %>
</div>
<% end -%>
<div class="form-actions">
<%= f.submit %>
</div>
<% end %>

View File

@ -1,14 +0,0 @@
= form_for([namespace, page.resource], html: { class: "form" }) do |f|
- if page.resource.errors.any?
#error_explanation
%h2
= pluralize(page.resource.errors.count, "error")
prohibited this #{page.resource_name} from being saved:
%ul
- page.resource.errors.full_messages.each do |message|
%li.flash-error= message
- page.attributes.each do |attribute|
%div{:class => "field-unit field-unit--#{attribute.html_class}"}
= render_field attribute, f: f
.form-actions
= f.submit

View File

@ -1,36 +0,0 @@
<%#
# Edit
This view is the template for the edit page.
It displays a header, and renders the `_form` partial to do the heavy lifting.
## Local variables:
- `page`:
An instance of [Administrate::Page::Form][1].
Contains helper methods to help display a form,
and knows which attributes should be displayed in the resource's form.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
%>
<% content_for(:title) { "#{t("administrate.actions.edit")} #{page.page_title}" } %>
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title">
<%= content_for(:title) %>
</h1>
<div>
<%= link_to(
"#{t("administrate.actions.show")} #{page.page_title}",
[namespace, page.resource],
class: "button",
) if valid_action? :show %>
</div>
</header>
<section class="main-content__body">
<%= render "form", page: page %>
</section>

View File

@ -1,13 +0,0 @@
%body
- content_for(:title) { "#{t("administrate.actions.edit")} #{page.page_title}" }
%header.main-content__header{:role => "banner"}
%h1.main-content__page-title
= content_for(:title)
%div
= link_to( |
"#{t("administrate.actions.show")} #{page.page_title}", |
[namespace, page.resource], |
class: "button", |
) if valid_action? :show |
%section.main-content__body
= render "form", page: page

View File

@ -1,53 +0,0 @@
<%#
# Index
This view is the template for the index page.
It is responsible for rendering the search bar, header and pagination.
It renders the `_table` partial to display details about the resources.
## Local variables:
- `page`:
An instance of [Administrate::Page::Collection][1].
Contains helper methods to help display a table,
and knows which attributes should be displayed in the resource's table.
- `resources`:
An instance of `ActiveRecord::Relation` containing the resources
that match the user's search criteria.
By default, these resources are passed to the table partial to be displayed.
- `search_term`:
A string containing the term the user has searched for, if any.
- `show_search_bar`:
A boolean that determines if the search bar should be shown.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
%>
<% content_for(:title) do %>
<%= display_resource_name(page.resource_name) %>
<% end %>
<% content_for(:search) do %>
<% if show_search_bar %>
<%= render "search", search_term: search_term %>
<% end %>
<% end %>
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title" id="page-title">
<%= content_for(:title) %>
</h1>
<div>
<%= link_to(
"#{t("administrate.actions.new")} #{page.resource_name.titleize.downcase}",
[:new, namespace, page.resource_path],
class: "button",
) if valid_action? :new %>
</div>
</header>
<section class="main-content__body main-content__body--flush">
<%= render "collection", collection_presenter: page, resources: resources %>
<%= paginate resources %>
</section>

View File

@ -1,18 +1,39 @@
%body
- content_for(:title) do
= display_resource_name(page.resource_name)
- content_for(:search) do
- if show_search_bar
= render "search", search_term: search_term
%header.main-content__header{:role => "banner"}
%h1#page-title.main-content__page-title
= content_for(:title)
.row.users_index_start
.col-md-9.users
.row
.col-md-10
%h2 Users
= paginate @users
.col-md-3
= #image_tag "users.jpg" , :class => "img-responsive"
.row
.col-md-9
%div
= link_to( |
"#{t("administrate.actions.new")} #{page.resource_name.titleize.downcase}", |
[:new, namespace, page.resource_path], |
class: "button", |
) if valid_action? :new |
%section.main-content__body.main-content__body--flush
= render "collection", collection_presenter: page, resources: resources
= paginate resources
%table.table.table-striped.table-bordered.table-condensed
%thead
%tr
%th=sort_link [:office,@q], :email
%th Street
%th City
%th Country
%th{:colspan => "2"}
%label.checkbox
= @user_scope.length.to_s + " Users"
%tbody
- @users.each do |user|
%tr{:class => "line-#{cycle("1","2")}"}
%td=user.email
%td=user.street
%td=user.city
%td=user.country
%td= link_to "Show" , admin_user_path(user), :title => t(:show)
= paginate @users
.col-md-3
= search_form_for [:admin , @q], :html => { :class => "form-horizontal" }, :method => :get do |f|
.form-group
= f.text_field :email_cont , :class => "form-control" , :placeholder => "Email"
.form-group
= f.text_field :street_cont ,:class => "form-control" , :placeholder => "Street"
= f.submit "Filter", :id => :filter , :class => "btn btn-success"
= link_to "Cancel", admin_users_path, :class => "btn btn-warning"
.users_index_end

View File

@ -1,32 +0,0 @@
<%#
# New
This view is the template for the "new resource" page.
It displays a header, and then renders the `_form` partial
to do the heavy lifting.
## Local variables:
- `page`:
An instance of [Administrate::Page::Form][1].
Contains helper methods to help display a form,
and knows which attributes should be displayed in the resource's form.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Form
%>
<% content_for(:title) { "#{t("administrate.actions.new")} #{page.resource_name.titleize}" } %>
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title">
<%= content_for(:title) %>
</h1>
<div>
<%= link_to t("administrate.actions.back"), :back, class: "button" %>
</div>
</header>
<section class="main-content__body">
<%= render "form", page: page %>
</section>

View File

@ -1,9 +0,0 @@
%body
- content_for(:title) { "#{t("administrate.actions.new")} #{page.resource_name.titleize}" }
%header.main-content__header{:role => "banner"}
%h1.main-content__page-title
= content_for(:title)
%div
= link_to t("administrate.actions.back"), :back, class: "button"
%section.main-content__body
= render "form", page: page

View File

@ -1,49 +0,0 @@
<%#
# Show
This view is the template for the show page.
It renders the attributes of a resource,
as well as a link to its edit page.
## Local variables:
- `page`:
An instance of [Administrate::Page::Show][1].
Contains methods for accessing the resource to be displayed on the page,
as well as helpers for describing how each attribute of the resource
should be displayed.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
%>
<% content_for(:title) { "#{t("administrate.actions.show")} #{page.page_title}" } %>
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title">
<%= content_for(:title) %>
</h1>
<div>
<%= link_to(
"#{t("administrate.actions.edit")} #{page.page_title}",
[:edit, namespace, page.resource],
class: "button",
) if valid_action? :edit %>
</div>
</header>
<section class="main-content__body">
<dl>
<% page.attributes.each do |attribute| %>
<dt class="attribute-label">
<%= t(
"helpers.label.#{resource_name}.#{attribute.name}",
default: attribute.name.titleize,
) %>
</dt>
<dd class="attribute-data attribute-data--<%=attribute.html_class%>"
><%= render_field attribute %></dd>
<% end %>
</dl>
</section>

View File

@ -1,20 +1,15 @@
%body
- content_for(:title) { "#{t("administrate.actions.show")} #{page.page_title}" }
%header.main-content__header{:role => "banner"}
%h1.main-content__page-title
= content_for(:title)
%div
= link_to( |
"#{t("administrate.actions.edit")} #{page.page_title}", |
[:edit, namespace, page.resource], |
class: "button", |
) if valid_action? :edit |
%section.main-content__body
%dl
- page.attributes.each do |attribute|
%dt.attribute-label
= t( |
"helpers.label.#{resource_name}.#{attribute.name}", |
default: attribute.name.titleize, |
) |
%dd{:class => "attribute-data attribute-data--#{attribute.html_class}"}= render_field attribute
%h2.users_show_start
= "User : " + @user.email
-if @user.admin?
(Admin)
%p
%b= "Name : " + @user.name.to_s
%p
%b= "Street : " + @user.street.to_s
%p
%b= "City : " + @user.city.to_s
%p
%b= "Country : " + @user.country.to_s
= link_to "Back", admin_users_path, :class => "btn btn-warning"
.users_show_end

View File

@ -1,4 +1,3 @@
%nav.navbar.navbar-fixed-top.navbar-light
%button.navbar-toggler.hidden-md-up{"aria-controls" => "navbarResponsive", "aria-expanded" => "false", "aria-label" => "Toggle navigation", "data-target" => "#navbarResponsive", "data-toggle" => "collapse", :type => "button"}
#navbarResponsive.collapse.navbar-toggleable-sm

View File

@ -0,0 +1,18 @@
!!!
%html{:lang => "en"}
%head
%meta{:charset => "utf-8"}
%title= content_for?(:title) ? content_for(:title) : "Admin"
= stylesheet_link_tag "admin" , :media => :all
= #javascript_include_tag "admin"
= csrf_meta_tags
%body{:style => ""}
.container-fluid
= render "layouts/admin/admin_menu"
= render "layouts/admin/messages"
= yield
.row
.col-md-12
%br

View File

@ -0,0 +1,11 @@
%nav.navbar.navbar-fixed-top.navbar-light
%button.navbar-toggler.hidden-md-up{"aria-controls" => "navbarResponsive", "aria-expanded" => "false", "aria-label" => "Toggle navigation", "data-target" => "#navbarResponsive", "data-toggle" => "collapse", :type => "button"}
#navbarResponsive.collapse.navbar-toggleable-sm
%a.navbar-brand{:href => page_path(:index) }
= #image_tag "logos/web_logo.png" , class: :desktop
%ul.nav.navbar-nav.float-sm-right
- { "Users" => admin_users_path , "Resumes" => admin_resumes_path ,
"Applies" => admin_applies_path , "Courses" => admin_courses_path }.each do | menu, slug|
%li.nav-item{class: (request.path == slug) && "active" }
=link_to menu , slug ,class: "nav-link"
%li.nav-item.nav-small= sign_out_link class: "nav-link"

View File

@ -0,0 +1,6 @@
- ( Rails::Engine.subclasses.map(&:instance) << Rails.application).each do |e|
- next unless e.respond_to? :office_assets
- asset = e.office_assets
- next if asset.blank?
= stylesheet_link_tag asset , :media => :all
= javascript_include_tag asset

View File

@ -0,0 +1,5 @@
- flash.each do |name, msg|
- if msg.is_a?(String)
%div{:class => "alert alert-#{name}"}
%button.close{"aria-hidden" => "true", "data-dismiss" => "alert", :type => "btn btn-primary"} &times;
%div= msg

View File

@ -8,7 +8,7 @@ Rails.application.config.assets.version = '1.0'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
Rails.application.config.assets.precompile += %w( )
Rails.application.config.assets.precompile += %w( admin.css )
Rails.application.config.assets.paths << Rails.root.join("app", "assets", "fonts")