Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sj develop #129

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gem 'rubyzip', '1.3.0'
gem 'slim-rails'
gem 'simple_form'
gem 'bootstrap-sass'
gem 'bootstrap_form'
gem 'bootstrap-datepicker-rails'
gem 'sassc-rails'
gem 'uglifier'
Expand Down
8 changes: 6 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ GEM
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
arel (9.0.0)
autoprefixer-rails (9.7.3)
autoprefixer-rails (9.8.6.3)
execjs
bcrypt (3.1.13)
bootstrap-datepicker-rails (1.8.0.1)
railties (>= 3.0)
bootstrap-sass (3.4.1)
autoprefixer-rails (>= 5.2.1)
sassc (>= 2.0.0)
bootstrap_form (4.5.0)
actionpack (>= 5.2)
activemodel (>= 5.2)
builder (3.2.3)
bullet (6.0.2)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -281,6 +284,7 @@ DEPENDENCIES
axlsx!
bootstrap-datepicker-rails
bootstrap-sass
bootstrap_form
bullet
byebug
cancancan
Expand Down Expand Up @@ -316,4 +320,4 @@ DEPENDENCIES
whenever

BUNDLED WITH
2.0.2
2.1.4
Binary file added app/assets/images/blank_user.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/small-logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/user2-160x160.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/javascripts/admin/companies.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
Empty file.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ input[type=radio]:not(old){
border-radius : 0.125em;
background : rgb(105, 188, 228);
}
}
}
75 changes: 75 additions & 0 deletions app/controllers/admin/companies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
module Admin
class CompaniesController < AdminController
before_action :set_company, only: [:show, :edit, :update, :destroy]

respond_to :html

PER_PAGE = 20

def index
@q = Company.all.ransack(params[:q])
@q.sorts = 'created_at desc' if @q.sorts.empty?
@companies = @q.result

@companies = @companies.offset(params.dig(:page, :offset)) if params.dig(:page, :offset).present?
@companies = @companies.limit((params.dig(:page, :limit) || ENV['ITEMS_PER_PAGE']).to_i)

respond_to do |f|
f.partial { render partial: 'table' }
f.html
end
end

def show
render_modal('show', {:class=>'right'})
end

def new
@company = Company.new
end

def edit
end

def create
@company = Company.new(company_params)
if @company.save
flash[:notice] = "Company Created Successfully"
redirect_to admin_companies_path
else
render 'new'
end
end

def update
if @company.update_attributes(company_params)
flash[:notice] = "Company Updated Successfully"
redirect_to admin_companies_path
else
render 'edit'
end
end

def destroy
@company.destroy
respond_with(@company)
end

private
def set_company
@company = Company.find(params[:id])
end

def company_params
params.require(:company).permit(
:name,
:logo,
:favicon,
:domain,
:description,
:from,
:reply_to
)
end
end
end
29 changes: 29 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class AdminController < ActionController::Base

before_action :authorized_admin!

layout 'application'

def render_modal(partial, options = {backdrop: true, keyboard: true})
render partial: 'shared/modal', locals: { partial: partial, options: options}
end

def xhr_redirect_to(args)
@args = args
flash.keep
render 'shared/xhr_redirect_to'
end

def authorized_admin!
unless current_user.is_admin?
flash[:error] = 'You are not authorized to access this page'
respond_to do |format|
format.html do
redirect_to '/'
end
end
end
end


end
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ def deep_strip_params!(hash)
end
end
end

def after_sign_in_path_for(resource)
if current_user.present? && current_user.is_admin?
admin_companies_path
end
end


end
2 changes: 2 additions & 0 deletions app/helpers/admin/companies_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::CompaniesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module AdminHelper
end
17 changes: 17 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,21 @@ def last_page?(collection)
def employees_path
'/people?page[limit]=10000&page[offset]=0&q[sorts][]=status&q[sorts][]=name&q[status_in][]=Hired&q[status_in][]=Past+employee'
end

def flash_messages
flash.each do |msg_type, message|
concat(content_tag(:div, message, id: 'flash', class: "alert alert-#{bootstrap_class_for(msg_type)} alert-dismissible text-center", role: 'alert') do
concat(content_tag(:button, class: 'close', data: { dismiss: 'alert' }) do
concat content_tag(:span, '&times;'.html_safe, 'aria-hidden' => true)
concat content_tag(:span, 'Close', class: 'sr-only')
end)
concat message
end)
end
nil
end

def bootstrap_class_for flash_type
{ success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type] || flash_type.to_s
end
end
12 changes: 12 additions & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Company < ActiveRecord::Base

belongs_to :status

attachment :logo
attachment :favicon


validates :name, :domain, presence: true


end
11 changes: 11 additions & 0 deletions app/models/role.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Role < ActiveRecord::Base

def self.admin
all.find_by(name: 'admin')
end

def is_admin?
name == 'admin'
end

end
10 changes: 10 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ class User < ActiveRecord::Base
include ChangesTracker

devise :database_authenticatable, :recoverable, :validatable

belongs_to :role, optional: true

delegate :is_admin?, to: :role, allow_nil: true


def is_user?
role.nil?
end

end
42 changes: 42 additions & 0 deletions app/views/admin/companies/_form.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
= simple_form_for [:admin, @company], html: { class: 'form' } do |f|
.form-group
label.control-label
| Name
span.text-danger *
= f.input :name, label: false
.form-group
label.control-label
| Domain
span.text-danger *
= f.input :domain, label: false
.form-group
label.control-label From
= f.input :from, label: false
.form-group
label.control-label Reply To
= f.input :reply_to, label: false
.form-group
label.col-sm-12.control-label for="exampleInputFile" Upload Icon:
.col-sm-10
= image_tag "blank_user.jpg", class: "edit-profile-img img-circle", alt: "Company Icon"
= f.file_field :icon, :class => 'form-control', hide_label: true
p.help-block Jpg, Png Format allowed max size 500 KB
.form-group
label.col-sm-12.control-label for="exampleInputFile" Upload Icon:
.col-sm-10
= image_tag "blank_user.jpg", class: "edit-profile-img img-circle", alt: "Company Icon"
= f.file_field :icon, :class => 'form-control', hide_label: true
p.help-block Jpg, Png Format allowed max size 500 KB
hr
.col-md-12
.form-group
= f.text_area :description, class: "form-control", placeholder: "Description"
div align="center"
.col-md-12
.form-group
= button_tag type: "submit", class: "btn btn-primary", data: {disable_with: "Please Wait..."} do
= fa_icon "floppy-o"
| Save
= link_to admin_companies_path, class: "btn btn-danger" do
= fa_icon "close"
| Cancel
3 changes: 3 additions & 0 deletions app/views/admin/companies/edit.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h2.title Edit Company

= render 'form'
23 changes: 23 additions & 0 deletions app/views/admin/companies/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
h2.title
| Actions &nbsp;
a.btn.btn-default.btn-pill href="companies/new"
i.fa.fa-plus
| &nbsp; Add New Company

table.table.pretty-table
thead
th = sort_link @q, :name, 'Name'
th = sort_link @q, :domain
th colspan="2" Actions
tbody.js-loadable-list
- if @companies.empty?
span class='js-page-last'
- @companies.each_with_index do |company, index|
tr class=('js-page-last' if (index == @companies.size - 1) && last_page?(@companies))
td = company.name
td = company.domain
td colspan="2"
a href="#{edit_admin_company_path(company)}" class="btn btn-sm btn-info btn-pill"
i.fa.fa-pencil
| &nbsp;Edit
= render 'shared/load_button', collection: @companies
3 changes: 3 additions & 0 deletions app/views/admin/companies/new.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h2.title New Company

= render 'form'
18 changes: 18 additions & 0 deletions app/views/layouts/_admin_sidebar.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
nav.main-header.navbar.navbar-expand.navbar-white.navbar-light
ul.navbar-nav.ml-auto
li.nav-item
a.nav-link.pt-0 data-slide="true" data-widget="control-sidebar"
.user-panel.d-flex
.image
= image_tag "user2-160x160.jpg", class: 'img-circle'
.info
= current_user.email
= fa_icon('angle-down')
aside.control-sidebar.control-sidebar-dark
div
ul.profile-menu
li
= link_to destroy_user_session_path, method: :delete, class: '' do
i.icon.ion-md-lock.ct-logout-icon.fa.fa-lock
| Logout

3 changes: 3 additions & 0 deletions app/views/layouts/_modal.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.modal.fade#modal-window
.modal-dialog.modal-lg
.modal-content
7 changes: 4 additions & 3 deletions app/views/layouts/application.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ html lang="en" class='fluid'
- if current_user
.dashboard
.side-panel
= render 'shared/navigation'
- if current_user.is_admin?
= render 'shared/admin_navigation'
- else
= render 'shared/navigation'
.content
.container-fluid
- flash.each do |key, value|
div class="#{flash_class(key)} alert-dismissable"
= value

= yield

- else
.login
.login-form
= yield

= javascript_include_tag 'application'
13 changes: 13 additions & 0 deletions app/views/shared/_admin_navigation.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- if current_user
.logo
a href="/"
| HRMS
a.btn.btn-small href="#{destroy_user_session_path}" data-method='delete'
i.fa.fa-sign-out
| Sign out
ul.navigation-links
li.divider
li.item role="presentation" class="#{active_class('admin/companies') unless active_class(admin_companies_path).present?}"
a href="#{admin_companies_path}"
i.fa.fa-users
| &nbsp; Company
7 changes: 7 additions & 0 deletions app/views/shared/_modal.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(function() {
var $modal = $('#modal-window')
$modal.find(".modal-content").html("<%= j (render partial) %>");
$modal.removeClass('right');
$modal.addClass("<%= options[:class] %>")
$modal.modal();
})()
7 changes: 7 additions & 0 deletions app/views/shared/xhr_redirect_to.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$(document).ajaxStop(function() {
$('input[type=submit]').attr('disabled', true);
});
validNavigation = true;
var redirectUrl;
redirectUrl = '<%= @args[:redirect_to] %>';
window.location.href = redirectUrl.length ? redirectUrl : window.location.href;
Loading