├── app ├── views │ └── admin │ │ └── fees │ │ ├── index.html.erb │ │ ├── show.html.erb │ │ ├── _fees.html.erb │ │ ├── _fee.html.erb │ │ ├── _actions.html.erb │ │ └── _records.html.erb ├── controllers │ ├── fees_controller.rb │ └── admin │ │ └── fees_controller.rb └── models │ └── fee.rb ├── lib ├── generators │ └── refinerycms_fees_generator.rb ├── tasks │ └── fees.rake └── refinerycms-fees.rb ├── readme.md ├── db ├── seeds │ └── fees.rb └── migrate │ └── create_fees.rb ├── config ├── routes.rb └── locales │ └── en.yml ├── features ├── support │ └── paths.rb ├── step_definitions │ └── fee_steps.rb └── manage_fees.feature ├── refinerycms-fees.gemspec └── spec └── models └── fee_spec.rb /app/views/admin/fees/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | <%= render :partial => 'records' %> 3 |
4 | -------------------------------------------------------------------------------- /lib/generators/refinerycms_fees_generator.rb: -------------------------------------------------------------------------------- 1 | class RefinerycmsFees < Refinery::Generators::EngineInstaller 2 | 3 | source_root File.expand_path('../../../', __FILE__) 4 | engine_name "fees" 5 | 6 | end 7 | -------------------------------------------------------------------------------- /app/views/admin/fees/show.html.erb: -------------------------------------------------------------------------------- 1 | <% content_for :body_content_left do %> 2 |
3 | <%= collection_select :fee, :user_id, User.where('progressbar_uid IS NOT NULL'), :id, :identifications %> 4 |
5 | <% end %> 6 | 7 | <%= render :partial => "/shared/content_page" %> 8 | -------------------------------------------------------------------------------- /lib/tasks/fees.rake: -------------------------------------------------------------------------------- 1 | namespace :refinery do 2 | 3 | namespace :fees do 4 | 5 | # call this task my running: rake refinery:fees:my_task 6 | # desc "Description of my task below" 7 | # task :my_task => :environment do 8 | # # add your logic here 9 | # end 10 | 11 | end 12 | 13 | end -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Fees engine for Refinery CMS. 2 | 3 | ## How to build this engine as a gem 4 | 5 | cd vendor/engines/fees 6 | gem build refinerycms-fees.gemspec 7 | gem install refinerycms-fees.gem 8 | 9 | # Sign up for a http://rubygems.org/ account and publish the gem 10 | gem push refinerycms-fees.gem -------------------------------------------------------------------------------- /db/seeds/fees.rb: -------------------------------------------------------------------------------- 1 | if defined?(User) 2 | User.all.each do |user| 3 | if !user.progressbar_uid.nil? 4 | if user.plugins.where(:name => 'fees').blank? 5 | user.plugins.create(:name => 'fees', 6 | :position => (user.plugins.maximum(:position) || -1) +1) 7 | end 8 | end 9 | end 10 | end -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | ::Refinery::Application.routes.draw do 2 | get '/fees/create', :to => 'fees#create' 3 | 4 | scope(:path => 'refinery', :as => 'admin', :module => 'admin') do 5 | resources :fees do 6 | collection do 7 | get :pair 8 | get :paired 9 | get :unpaired 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /features/support/paths.rb: -------------------------------------------------------------------------------- 1 | module NavigationHelpers 2 | module Refinery 3 | module Fees 4 | def path_to(page_name) 5 | case page_name 6 | when /the list of fees/ 7 | admin_fees_path 8 | 9 | when /the new fee form/ 10 | new_admin_fee_path 11 | else 12 | nil 13 | end 14 | end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /app/views/admin/fees/_fees.html.erb: -------------------------------------------------------------------------------- 1 | <%= will_paginate @fees %> 2 | 3 | 4 | 5 | 6 | <% if params[:action] == 'unpaired' %> 7 | 8 | <% end %> 9 | 10 | 11 | 12 | 13 | 14 | <%= render :partial => 'fee', :collection => @fees %> 15 | 16 |
From AccountVSMonth / YearAmount
-------------------------------------------------------------------------------- /refinerycms-fees.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.platform = Gem::Platform::RUBY 3 | s.name = 'refinerycms-fees' 4 | s.authors = 'nospam.keram@gmail.com' 5 | s.version = '1.0' 6 | s.description = 'Ruby on Rails Fees engine for Refinery CMS' 7 | s.date = '2011-07-18' 8 | s.summary = 'Fees engine for Refinery CMS' 9 | s.require_paths = %w(lib) 10 | s.files = Dir['lib/**/*', 'config/**/*', 'app/**/*'] 11 | end 12 | -------------------------------------------------------------------------------- /app/controllers/fees_controller.rb: -------------------------------------------------------------------------------- 1 | class FeesController < ApplicationController 2 | 3 | def index 4 | render :text => 0 5 | end 6 | 7 | def create 8 | response = {'status' => false} 9 | fp = params[:fee] 10 | fp[:user] = User.find_by_progressbar_uid(fp[:vs].to_i) 11 | 12 | fee = Fee.new(fp) 13 | 14 | if fee.valid? 15 | response['status'] = fee.save! 16 | else 17 | response['errors'] = fee.errors 18 | end 19 | 20 | render :text => response.to_json 21 | end 22 | 23 | end 24 | -------------------------------------------------------------------------------- /app/views/admin/fees/_fee.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | <%#= link_to fee.from_account, admin_fee_url(fee) %> 4 | <%= fee.from_account %><%= ", #{fee.message.truncate(50)} " unless fee.message.nil? %> 5 | <%= " - #{fee.user.username}" unless fee.user.nil? %> 6 | 7 | <% if params[:action] == 'unpaired' %> 8 | 9 | <%= text_field "fee[#{fee.id}]", :vs, :size => 6, :maxlength => 7 %> 10 | 11 | <% end %> 12 | <%= fee.month %> / <%= fee.year %> 13 | 14 | <%= fee.amount %> <%= fee.currency %> 15 | 16 | 17 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | en: 2 | shared: 3 | admin: 4 | image_picker: 5 | image: image 6 | plugins: 7 | fees: 8 | title: Fees 9 | admin: 10 | fees: 11 | actions: 12 | create_new: Add New Fee 13 | reorder: Reorder Fees 14 | reorder_done: Done Reordering Fees 15 | records: 16 | title: Fees 17 | sorry_no_results: Sorry! There are no results found. 18 | no_items_yet: There are no Fees yet. 19 | fee: 20 | view_live_html: View this fee live
(opens in a new window) 21 | edit: Edit this fee 22 | delete: Remove this fee forever 23 | fees: 24 | show: 25 | other: Other Fees 26 | -------------------------------------------------------------------------------- /app/views/admin/fees/_actions.html.erb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/models/fee_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Fee do 4 | 5 | def reset_fee(options = {}) 6 | @valid_attributes = { 7 | :id => 1, 8 | :from_account => "RSpec is great for testing too" 9 | } 10 | 11 | @fee.destroy! if @fee 12 | @fee = Fee.create!(@valid_attributes.update(options)) 13 | end 14 | 15 | before(:each) do 16 | reset_fee 17 | end 18 | 19 | context "validations" do 20 | 21 | it "rejects empty from" do 22 | Fee.new(@valid_attributes.merge(:from_account => "")).should_not be_valid 23 | end 24 | 25 | it "rejects non unique from" do 26 | # as one gets created before each spec by reset_fee 27 | Fee.new(@valid_attributes).should_not be_valid 28 | end 29 | 30 | end 31 | 32 | end -------------------------------------------------------------------------------- /db/migrate/create_fees.rb: -------------------------------------------------------------------------------- 1 | class CreateFees < ActiveRecord::Migration 2 | def self.up 3 | create_table :fees do |t| 4 | t.string :from_account, :null => false 5 | t.integer :vs, :null => false 6 | t.decimal :amount, :precision => 8, :scale => 2, :null => false 7 | t.string :currency, :null => false, :default => 'eur' 8 | t.integer :month, :null => false 9 | t.integer :year, :null => false 10 | t.string :stamp, :null => false 11 | t.text :message 12 | 13 | t.references :user 14 | 15 | t.timestamps 16 | end 17 | 18 | add_index :fees, :id 19 | add_index :fees, :stamp 20 | end 21 | 22 | def self.down 23 | UserPlugin.destroy_all({:name => "fees"}) 24 | 25 | drop_table :fees 26 | 27 | end 28 | end -------------------------------------------------------------------------------- /app/models/fee.rb: -------------------------------------------------------------------------------- 1 | class Fee < ActiveRecord::Base 2 | acts_as_indexed :fields => [:from_account, :message] 3 | 4 | belongs_to :user 5 | 6 | validates :from_account, :presence => true 7 | validates :vs, :presence => true, :numericality => { :only_integer => true } 8 | validates :amount, :presence => true 9 | validates :month, :presence => true, :numericality => { :only_integer => true } 10 | validates :year, :presence => true, :numericality => { :only_integer => true } 11 | validates :stamp, :presence => true, :uniqueness => true 12 | 13 | validates_associated :user 14 | 15 | scope :unpaired, :conditions => {:user_id => nil} 16 | scope :paired, :conditions => 'user_id IS NOT NULL' 17 | 18 | def self.search(search, page, user) 19 | paginate :per_page => 20, :page => page, 20 | :conditions => ['user_id = ? AND (from_account like ? OR message like ?)', user.id, "%#{search}%", "%#{search}%"], 21 | :order => 'year DESC, month DESC' 22 | end 23 | 24 | def self.mine(page, user) 25 | paginate :per_page => 20, :page => page, 26 | :conditions => ['user_id = ?', user.id], 27 | :order => 'year DESC, month DESC' 28 | end 29 | 30 | def self.latest(number = 7) 31 | limit(number) 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/refinerycms-fees.rb: -------------------------------------------------------------------------------- 1 | require 'refinerycms-base' 2 | 3 | module Refinery 4 | module Fees 5 | class Engine < Rails::Engine 6 | initializer "static assets" do |app| 7 | app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public" 8 | end 9 | 10 | config.to_prepare do 11 | User.module_eval do 12 | has_many :fees 13 | 14 | def identifications 15 | fees = Fee.where(:vs => self.progressbar_uid) 16 | acc = [] 17 | # fees.each do |f| acc << f.from_account 18 | fees.each do |f| 19 | acc << f.from_account 20 | end 21 | # bank_accounts = Fee.where(:vs => self.progressbar_uid).collect {|f| "#{f[:from_account]}"}.join(' - ') 22 | "#{self.progressbar_uid} - #{self.username} - #{self.progressbar_screenname.to_s} - #{acc.uniq.join(' - ').to_s}" 23 | end 24 | end 25 | end 26 | 27 | 28 | config.after_initialize do 29 | Refinery::Plugin.register do |plugin| 30 | plugin.name = 'fees' 31 | plugin.activity = { 32 | :class => Fee, 33 | :title => 'from_account' 34 | } 35 | end 36 | end 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /app/views/admin/fees/_records.html.erb: -------------------------------------------------------------------------------- 1 | <% if searching? %> 2 |

<%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %>

3 | <% end %> 4 | <% if @fees.any? %> 5 | <% if params[:action] == 'unpaired' %> 6 |
7 | <% end %> 8 |
9 | <%= render :partial => 'fees' %> 10 |
11 | <% if params[:action] == 'unpaired' %> 12 |
13 | <%= submit_tag 'pair' %> 14 |
15 |
16 | <% end %> 17 | <% if params[:action] == 'unpaired' %> 18 |
19 | <% User.where('progressbar_uid IS NOT NULL').each do |u| %> 20 | <%= u.identifications %>
21 | <% end %> 22 |
23 | <% end %> 24 | <% else %> 25 |

26 | <% unless searching? %> 27 | 28 | <%= t('.no_items_yet') %> 29 | 30 | <% else %> 31 | <%= t('no_results', :scope => 'shared.admin.search') %> 32 | <% end %> 33 |

34 | <% end %> 35 | 36 | -------------------------------------------------------------------------------- /features/step_definitions/fee_steps.rb: -------------------------------------------------------------------------------- 1 | Given /^I have no fees$/ do 2 | Fee.delete_all 3 | end 4 | 5 | Given /^I (only )?have fees titled "?([^\"]*)"?$/ do |only, titles| 6 | Fee.delete_all if only 7 | titles.split(', ').each do |title| 8 | Fee.create(:from_account => title) 9 | end 10 | end 11 | 12 | Then /^I should have ([0-9]+) fees?$/ do |count| 13 | Fee.count.should == count.to_i 14 | end 15 | 16 | #cucumber generated 17 | 18 | Given /^I am a logged in refinery user$/ do 19 | pending # express the regexp above with the code you wish you had 20 | end 21 | 22 | Given /^I have role member$/ do 23 | pending # express the regexp above with the code you wish you had 24 | end 25 | 26 | When /^I go to the list of fees$/ do 27 | pending # express the regexp above with the code you wish you had 28 | end 29 | 30 | Then /^I should see "([^"]*)"$/ do |arg1| 31 | pending # express the regexp above with the code you wish you had 32 | end 33 | 34 | When /^I follow "([^"]*)"$/ do |arg1| 35 | pending # express the regexp above with the code you wish you had 36 | end 37 | 38 | When /^I fill in "([^"]*)" with "([^"]*)"$/ do |arg1, arg2| 39 | pending # express the regexp above with the code you wish you had 40 | end 41 | 42 | When /^I press "([^"]*)"$/ do |arg1| 43 | pending # express the regexp above with the code you wish you had 44 | end -------------------------------------------------------------------------------- /features/manage_fees.feature: -------------------------------------------------------------------------------- 1 | @fees 2 | Feature: Fees 3 | In order to have membership fees 4 | As an member 5 | I want to see my fees 6 | 7 | Background: 8 | Given I am a logged in refinery user 9 | And I have role member 10 | And I have no fees 11 | 12 | @fees-list @list 13 | Scenario: Fees List 14 | Given I have fees titled UniqueTitleOne, UniqueTitleTwo 15 | When I go to the list of fees 16 | Then I should see "UniqueTitleOne" 17 | And I should see "UniqueTitleTwo" 18 | 19 | @fees-valid @valid 20 | Scenario: Create Valid Fee 21 | When I go to the list of fees 22 | And I follow "Add New Fee" 23 | And I fill in "From account" with "This is a test of the first string field" 24 | And I press "Save" 25 | Then I should see "'This is a test of the first string field' was successfully added." 26 | And I should have 1 fee 27 | 28 | @fees-invalid @invalid 29 | Scenario: Create Invalid Fee (without from) 30 | When I go to the list of fees 31 | And I follow "Add New Fee" 32 | And I press "Save" 33 | Then I should see "From can't be blank" 34 | And I should have 0 fees 35 | 36 | @fees-duplicate @duplicate 37 | Scenario: Create Duplicate Fee 38 | Given I only have fees titled UniqueTitleOne, UniqueTitleTwo 39 | When I go to the list of fees 40 | And I follow "Add New Fee" 41 | And I fill in "From" with "UniqueTitleTwo" 42 | And I press "Save" 43 | Then I should see "There were problems" 44 | And I should have 2 fees 45 | -------------------------------------------------------------------------------- /app/controllers/admin/fees_controller.rb: -------------------------------------------------------------------------------- 1 | module Admin 2 | class FeesController < Admin::BaseController 3 | crudify :fee, :xhr_paging => true 4 | 5 | layout proc{ |c| c.request.xhr? ? false : 'admin' } 6 | 7 | def index 8 | @fees = params[:search] ? Fee.search(params[:search], params[:page], current_user) : Fee.mine(params[:page], current_user) 9 | 10 | render(:partial => 'fees') if request.xhr? 11 | end 12 | 13 | def show 14 | @fee = Fee.find_by_id(params[:id]) 15 | @users = User.all 16 | end 17 | 18 | def pair 19 | unless current_user.has_role?(:superuser) 20 | flash[:error] = 'Bad, bad boy!' 21 | redirect_to :action => 'index' 22 | else 23 | if params[:fee] 24 | pfs = params[:fee] 25 | pfs.each do |id, vs| 26 | if params[:fee][id][:vs] 27 | fee = Fee.find(id) 28 | user = User.find_by_progressbar_uid(params[:fee][id][:vs]) 29 | unless user.nil? 30 | fee.update_attribute(:vs, user.progressbar_uid) 31 | fee.update_attribute(:user_id, user.id) 32 | end 33 | end 34 | end 35 | 36 | flash[:notice] = 'Fees was updated. Thank You!' 37 | end 38 | 39 | redirect_to :action => 'unpaired' 40 | end 41 | end 42 | 43 | def paired 44 | if current_user.has_role?(:superuser) 45 | @fees = Fee.paired 46 | @fees = @fees.paginate({:page => params[:page]}) 47 | 48 | render(request.xhr? ? {:partial => 'fees' } : {:action => 'index'}) 49 | else 50 | redirect_to :action => 'index' 51 | end 52 | end 53 | 54 | def unpaired 55 | if current_user.has_role?(:superuser) 56 | @fees = Fee.unpaired 57 | @fees = @fees.paginate({:page => params[:page]}) 58 | 59 | render(request.xhr? ? {:partial => 'fees' } : {:action => 'index'}) 60 | else 61 | redirect_to :action => 'index' 62 | end 63 | end 64 | end 65 | end --------------------------------------------------------------------------------