Skip to content

Commit

Permalink
More performance work. Add pagination in a bunch of places. Fix vario…
Browse files Browse the repository at this point in the history
…us minor bugs.
  • Loading branch information
Axel Liljencrantz committed Aug 13, 2010
1 parent 1f05ed6 commit 5204097
Show file tree
Hide file tree
Showing 31 changed files with 522 additions and 200 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
/*.patch
!.gitignore
/doc/plugins
Gemfile.lock

4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ gem 'rails', '3.0.0.rc'
# postgresql
gem 'pg'

gem 'will_paginate', :git => 'git://github.com/mislav/will_paginate.git', :branch => 'rails3'

gem 'ruby_parser'
gem "machinist"
gem "faker"
gem "devise", "1.1.rc2"
gem "devise", "~>1.1"
gem "warden"
gem "declarative_authorization", :git => "http://github.com/stffn/declarative_authorization.git"

Expand Down
19 changes: 19 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


Statistik:

Før alla stængda perioder:
* # open bills
* # bills
* # journal entries
* Før alla konto/unit/project kombos med transaktioner:
* debet
* kredit

Bættra på bulkinsættning:

* Ordrer
* Fakturor



3 changes: 1 addition & 2 deletions app/controllers/admin/companies_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Admin::CompaniesController < Admin::BaseController


before_filter :find_company, :only => [:show, :edit, :update, :destroy]

def find_company
Expand All @@ -13,7 +12,7 @@ def find_company
# GET /companies
# GET /companies.xml
def index
@companies = Company.order("name").includes(:assignments).includes(:address)
@companies = Company.order("name").includes(:assignments).includes(:address).paginate({:page => params[:page]})
@companies.each do
|c|
if !c.address
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def show
end

def index
@users = User.order(:email).includes(:companies)
@users = User.order(:email).includes(:companies).paginate({:page => params[:page]})

respond_to do |format|
format.html # index.html.erb
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ def permission_denied
redirect_to root_url
end

def user_property name, default
fn = controller_name + "." + action_name + "." + name.to_s
foo = params[name] || current_user.get_property( fn ) || default
current_user.set_property( fn, foo)
end


end
8 changes: 6 additions & 2 deletions app/controllers/journals_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class JournalsController < ApplicationController

include PeriodController

before_filter :find_units_all, :only => [:new, :edit]
before_filter :find_projects_all, :only => [:new, :edit]
before_filter :find_accounts_all, :only => [:new, :edit]
Expand All @@ -7,13 +10,14 @@ class JournalsController < ApplicationController
# GET /journals
# GET /journals.xml
def index
@journals = Journal.with_permissions_to(:index).order("number, journal_date desc, journal_type")
@journals = period_filter(Journal.with_permissions_to(:index).order("number, journal_date desc, journal_type")).paginate({:page => params[:page]})

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @journals }
end
end


# GET /journals/1
# GET /journals/1.xml
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/paychecks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class PaychecksController < ApplicationController

include PeriodController

before_filter :setup_form
before_filter :employee_required, :except => [:index]

Expand All @@ -11,9 +14,10 @@ def setup_form
@units = current_user.current_company.units
@projects = current_user.current_company.projects
@employees = current_user.current_company.employees
@paychecks = current_user.current_company.paychecks
@paychecks = period_filter(current_user.current_company.paychecks.includes(:period).includes(:employee))
@units = current_user.current_company.units
@projects = current_user.current_company.projects

# @periods = current_user.current_company.periods.select {|p| p.open?}
end

Expand Down
6 changes: 6 additions & 0 deletions app/models/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Company < ActiveRecord::Base
attr_accessor :template_company_id
after_create :init_from_template, :if => proc { !self.template_company_id.blank? }

self.per_page = 50

# hmm.. no idea what validations make sense atm
#validates :organization_number, :format => {:with => /^(NO|no)?[\d]{9,}(MVA|mva)?$/}

Expand Down Expand Up @@ -116,4 +118,8 @@ def paychecks
r
end

def to_s
name
end

end
2 changes: 2 additions & 0 deletions app/models/journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class Journal < ActiveRecord::Base
belongs_to :bill
belongs_to :period

self.per_page = 200

def open?
return (not self.closed)
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/paycheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ class Paycheck < ActiveRecord::Base
has_many :paycheck_lines
accepts_nested_attributes_for :paycheck_lines



end
3 changes: 3 additions & 0 deletions app/models/property.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Property < ActiveRecord::Base
belongs_to :model
end
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require 'digest/sha1'

class User < ActiveRecord::Base

include ::PropertyModel

has_many :companies, :through => :assignments, :uniq => true, :order => "companies.name"
belongs_to :current_company, :class_name => 'Company'

Expand All @@ -16,6 +19,8 @@ class User < ActiveRecord::Base
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :assignments_attributes

self.per_page = 20

# return array of roles for self.current_company
def role_symbols
return @symbols if defined? @symbols
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/companies/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<h1><%= t(:listing_companies, :scope => :companies) -%></h1>

<%= will_paginate @companies %>

<table class='striped'>
<tr>
<th><%= t(:name, :scope => :companies) -%></th>
Expand Down
10 changes: 5 additions & 5 deletions app/views/admin/companies/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<p>
<b><%= t(:users, :scope => :companies) -%>:</b>
<%= @company.users.collect {|u| u.email}.join ", " %>
</p>
<ul>
<% @company.users.each do |c| %>
<li><%= link_to c.email, admin_user_path(c)%> </li>
<% end %>
</ul>

<p>
<b><%= t(:accounts, :scope => :companies) -%>:</b>
<%= @company.accounts.map {|a| "#{a.number} - #{a.name}"}.join(", ") %>
</p>

<p>
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<h1><%= t(:listing_users, :scope => :users) -%></h1>

<%= will_paginate @users %>

<table class='striped'>
<tr>
<th><%= t(:email, :scope => :users) -%></th>
Expand Down
6 changes: 5 additions & 1 deletion app/views/admin/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

<p>
<b><%= t(:companies, :scope => :users) -%>:</b>
<%= @user.companies.collect{|c| link_to c.name, admin_company_path(c)}.join(", ") %>
<ul>
<% @user.companies.each do |c| %>
<li><%= link_to c.name, admin_company_path(c)%> </li>
<% end %>
</ul>
</p>

<%= link_to t(:edit, :scope => :users), edit_admin_user_path(@user) %> |
Expand Down
1 change: 0 additions & 1 deletion app/views/journals/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
<%= t(:text, :scope => :journals) %>
</th>
<th>

</th>
</tr>
</thead>
Expand Down
21 changes: 17 additions & 4 deletions app/views/journals/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<h1><%= t(:listing_journals, :scope => :journals) -%></h1>

<%= render :partial => "shared/period_picker" %>
<%= will_paginate @companies %>

<table class='striped'>
<tr>
<th><%= t(:type, :scope => :journals) -%></th>
Expand All @@ -8,18 +11,27 @@
<th></th>
</tr>

<%
show_text = t("global.show")
edit_text = t("global.edit")
destroy_text = t("global.destroy")

def url_gen(object); "/#{object.class.name.tableize}/#{object.id}"; end

%>
<% for journal in @journals %>
<tr>
<td><%= journal.journal_type %></td>
<td><%= journal.number %></td>
<td><%= journal.journal_date ? l(journal.journal_date) : "" %></td>
<td>
<%= link_to t("global.show"), journal %>

<%= link_to show_text, url_gen(journal) %>
<% if permitted_to? :edit, journal %>
<%= link_to t("global.edit"), edit_journal_path(journal) %>
<%= link_to edit_text, url_gen(journal)+"/edit" %>
<% end %>
<% if permitted_to? :delete, journal %>
<%= link_to t("global.destroy"), journal, :confirm => 'Are you sure?', :method => :delete %>
<%= link_to destroy_text, url_gen(journal), :confirm => 'Are you sure?', :method => :delete %>
<% elsif not journal.bill.nil? %>
<%= link_to 'Show bill', :controller => "bills", :action => "show", :id => journal.bill.id %>
<% if permitted_to? :edit, journal.bill %>
Expand All @@ -28,7 +40,8 @@
<% if permitted_to? :delete, journal.bill %>
<%= link_to 'Destroy bill', journal.bill, :confirm => 'Are you sure?', :method => :delete %>
<% end %>
<% end %>
<% end %>

</td>
</tr>
<% end %>
Expand Down
5 changes: 4 additions & 1 deletion app/views/paychecks/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<% end %>
</table>

<%= render :partial => "shared/period_picker" %>


<table>
<tr>
Expand All @@ -29,7 +31,8 @@
<td>
<%= link_to t('global.show'), paycheck %>
<%= link_to t('global.edit'), edit_paycheck_path(paycheck) %>
<%= link_to t('global.destroy'), paycheck, :confirm => t('global.confirm'), :method => :delete %> </td>
<%= link_to t('global.destroy'), paycheck, :confirm => t('global.confirm'), :method => :delete %>
</td>
</tr>
<% end %>

Expand Down
16 changes: 16 additions & 0 deletions app/views/shared/_period_picker.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class='period_picker'>
<%= form_tag "", :method => :get do %>
<div class='first'>
<%= label :first_period, t('period_picker.first_period') %>
<%= select_tag 'first_period', options_for_select(current_user.current_company.periods.map {|e| e.to_s}, first_period) %>
</div>
<div class='last'>

<%= label :first_period, t('period_picker.last_period') %>
<%= select_tag 'last_period', options_for_select(current_user.current_company.periods.map {|e| e.to_s}, last_period) %>
</div>
<%= submit_tag t('global.filter') %>
<% end %>
</div>


1 change: 1 addition & 0 deletions config/initializers/periods.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'period_controller'
3 changes: 3 additions & 0 deletions config/initializers/properties.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


require 'property_model'
11 changes: 11 additions & 0 deletions config/initializers/timer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

def print_time name, &block
print "#{name}..."
a = Time.now
foo = yield block
b = Time.now
print " Used #{b-a} seconds.\n"
return foo
end


5 changes: 4 additions & 1 deletion config/locales/nb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
one: Periode
other: Perioder
save: Lagre
filter: Kjempefiltrer
admin:
companies:
select_template_company: Bruk som mal
Expand Down Expand Up @@ -362,6 +363,8 @@
units:
header_edit: Kjemperedigerer avdelning
header_index: Kjempelister avdelninger

period_picker:
first_period: Fra
last_period: Til


17 changes: 17 additions & 0 deletions db/migrate/20100729115340_create_properties.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateProperties < ActiveRecord::Migration
def self.up
create_table :properties do |t|
t.string :key, :null => false
t.text :value, :null => false
t.string :model_name
t.integer :model_id
end
add_index :properties, [:key], {:name => 'properties_key'}
add_index :properties, [:model_id], {:name => 'properties_model_id'}
add_index :properties, [:key, :model_name, :model_id], {:unique => true}
end

def self.down
drop_table :properties
end
end
24 changes: 24 additions & 0 deletions db/migrate/20100730090140_add_misc_indices.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class AddMiscIndices < ActiveRecord::Migration
def self.up
add_index :periods, :company_id, {:name => 'periods_company_idx'}
add_index :journals, :period_id, {:name => 'journals_period_idx'}
add_index :bills, :period_id, {:name => 'bills_period_idx'}
add_index :bills, :company_id, {:name => 'bills_company_idx'}

add_index :journals, [:company_id, :number, :journal_type], {:name => 'journals_misc_idx'}
execute "cluster journals_misc_idx on journals"

execute "create index journals_bill_idx on journals (bill_id) where bill_id is not null;"
end

def self.down
remove_index 'periods', 'periods_company_idx'
remove_index 'journals', 'journals_period_idx'
remove_index 'bills', 'bills_period_idx'
remove_index 'bills', 'bills_company_idx'

remove_index 'journals', 'journals_misc_idx'

execute "drop index journals_bill_idx"
end
end
Loading

0 comments on commit 5204097

Please sign in to comment.