diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb new file mode 100755 index 0000000..ac11e1a --- /dev/null +++ b/app/controllers/links_controller.rb @@ -0,0 +1,133 @@ +require 'tempfile' + +class LinksController < ApplicationController + + before_filter :check_current_user,:selected_folder, :get_current_folders + + before_filter :get_links, :only => [:index] + + before_filter :prepare_ops_buttons, :only => [:index] + + #, :prepare_export_import_buttons,:only => [:index] + + theme :theme_resolver + + def index + + end + + def ops + if params["create_new"] + redirect_to(new_link_path) + return + end + if !params["ids"] + flash[:warning] = t(:no_selected,:scope=>:link) + else + if params["delete_selected"] + params["ids"].each do |id| + @current_user.links.find_by_id(id).destroy + end + end + end + redirect_to(links_path) + end + + #problem http://binary10ve.blogspot.com/2011/05/migrating-to-rails-3-got-stuck-with.html + #def destroy + # @current_user.contacts.find(params[:id]).destroy + # redirect_to(contacts_path) + #end + + def new + @link = Link.new + end + + def edit + @link = @current_user.links.find(params[:id]) + render 'edit' + end + + def create + @link = @current_user.links.build(params[:link]) + if @link.valid? + @link.save + flash[:notice] = t(:was_created,:scope=>:link) + redirect_to(links_path) + else + render 'new' + end + end + + def update + @link = @current_user.links.find(params[:id]) + if @link.update_attributes(params[:link]) + redirect_to(links_path) + else + render 'edit' + end + end + + def external + if params["export"] + redirect_to :action => 'export' + return + elsif params["import"] + begin + raise t(:no_file_chosen,:scope=>:common) if not params[:upload] + raise t(:no_tmp_dir,:scope=>:common) if not File.exists?($defaults["msg_upload_dir"]) + tmp_file = Tempfile.new($defaults["contact_tmp_filename"],$defaults["msg_upload_dir"]) + tmp_file.write(params[:upload][:datafile].read) + tmp_file.flush + tmp_file.rewind + tmp_file.readlines.each do |line| + next if line =~ /^#/ + Contact.import(@current_user,line) + end + rescue ActiveRecord::RecordInvalid => e + flash[:error] = {:title => e.to_s,:info => e.record.inspect + e.record.errors.inspect} + rescue Exception => e + flash[:error] = e.to_s + else + flash[:notice] = t(:were_imported,:scope=>:contact) + end + end + redirect_to :action => 'index' + end + + def export + contacts = @current_user.contacts + s = "" + contacts.each do |c| + s += c.export + "\r\n" + end + headers['Content-type'] = "text/csv" + headers['Content-Disposition'] = %(attachment; filename="contacts.csv") + render :text => s + end + + ####################################### protected section ################################ + + protected + + def prepare_ops_buttons + @buttons = [] + @buttons << {:text => 'create_new',:scope=> 'link', :image => 'plus.png'} + @buttons << {:text => 'delete_selected',:scope=>'link',:image => 'minus.png'} + end + + def prepare_export_import_buttons + @ei_buttons = [] + @ei_buttons << {:text => 'import',:scope=>'link',:image => 'right.png'} + @ei_buttons << {:text => 'export',:scope=>'link',:image => 'left.png'} + end + + ####################################### private section ################################## + + private + + def get_links + @links = Link.getPageForUser(@current_user,params[:page],params[:sort_field],params[:sort_dir]) + end + +end diff --git a/app/controllers/messages_ops_controller.rb b/app/controllers/messages_ops_controller.rb index 276de49..25b0513 100755 --- a/app/controllers/messages_ops_controller.rb +++ b/app/controllers/messages_ops_controller.rb @@ -115,14 +115,23 @@ class MessagesOpsController < ApplicationController flash[:warning] = t(:no_selected,:scope=>:folder) else dest_folder = @current_user.folders.find(params[:folder][:target]) + logger.info "DEST: "+dest_folder.inspect params["uids"].each do |uid| + logger.info "UID: "+uid + logger.info "DEST_FULL: "+dest_folder.full_name @mailbox.move_message(uid,dest_folder.full_name) message = @current_folder.messages.find_by_uid(uid) + logger.info "M: "+message.inspect + logger.info "UPDATE_DEST_BEFORE1: "+dest_folder.inspect message.change_folder(dest_folder) + logger.info "UPDATE_DEST_BEFORE2: "+dest_folder.inspect end + logger.info "UPDATE_DEST_BEFORE: "+dest_folder.inspect @mailbox.expunge dest_folder.update_stats + logger.info "UPDATE_DEST: "+dest_folder.inspect @current_folder.update_stats + logger.info "UPDATE_CUT: "+@current_folder.inspect end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b104f7d..87fe879 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -269,7 +269,8 @@ def main_navigation(active) s += "
  • #{link_to( t(:compose,:scope=>:compose), compose_path )}
  • " s += "
  • #{link_to( t(:folders,:scope=>:folder), folders_path )}
  • " s += "
  • #{link_to( t(:contacts,:scope=>:contact), contacts_path )}
  • " - s += "
  • #{link_to( t(:prefs,:scope=>:prefs), prefs_look_path )}
  • " + s += "
  • #{link_to( t(:prefs,:scope=>:prefs), prefs_look_path )}
  • " + s += "
  • #{link_to( t(:links,:scope=>:link), links_path )}
  • " s += "" end diff --git a/app/helpers/links_helper.rb b/app/helpers/links_helper.rb new file mode 100755 index 0000000..5df409d --- /dev/null +++ b/app/helpers/links_helper.rb @@ -0,0 +1,17 @@ +module LinksHelper + + def links_table_header + html = "" + $defaults["links_table_fields"].each do |f| + html << "" + if params[:sort_field] == f + params[:sort_dir].nil? ? dir = 'desc' : dir = nil + end + + html << link_to(Link.human_attribute_name(f), {:controller => 'links',:action => 'index',:sort_field => f,:sort_dir => dir}, {:class=>"header"}) + html << "" + end + html + end + +end diff --git a/app/models/folder.rb b/app/models/folder.rb index 00ace6c..7dddffa 100755 --- a/app/models/folder.rb +++ b/app/models/folder.rb @@ -38,8 +38,11 @@ class Folder < ActiveRecord::Base end def update_stats + logger.info "MESS_BEFORE: "+messages.inspect unseen = messages.where(:unseen => true).count total = messages.count + logger.info "MESS: "+messages.inspect + logger.info "MESS: #{unseen} #{total}" update_attributes(:unseen => unseen, :total => total) end diff --git a/app/models/link.rb b/app/models/link.rb new file mode 100644 index 0000000..30e75cb --- /dev/null +++ b/app/models/link.rb @@ -0,0 +1,19 @@ +class Link < ActiveRecord::Base + validates_length_of :name, :within => 5..30 + validates_length_of :url, :within => 5..150 + validates_length_of :info, :maximum => 50 + belongs_to :user + default_scope :order => 'name asc' + + def self.getPageForUser(user,page,sort_field,sort_dir) + + if sort_field + if Link.attribute_method?(sort_field) == true + order = sort_field + sort_dir == 'desc' ? order += ' desc' : sort_dir + end + end + + Link.paginate :page => page , :per_page => $defaults["links_per_page"], :conditions=> ['user_id = ?', user.id],:order => order + end +end diff --git a/app/models/user.rb b/app/models/user.rb index afc821c..1d4dac6 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,6 +11,7 @@ class User < ActiveRecord::Base has_many :folders, :dependent => :destroy has_many :messages, :dependent => :destroy has_many :contacts, :dependent => :destroy + has_many :links, :dependent => :destroy def set_cached_password(session,password) if $defaults['session_encryption'] diff --git a/config/defaults.yml b/config/defaults.yml index c34bb05..f20cb5a 100755 --- a/config/defaults.yml +++ b/config/defaults.yml @@ -13,6 +13,9 @@ msg_image_thumbnail_size: [128x128, 128x96, 192x192, 192x144, 256x256, 256x192] contacts_table_fields: [nick, first_name, last_name, email, info] contacts_per_page: 25 +links_table_fields: [name, url, info] +links_per_page: 30 + servers_table_fields: [name, port, use_ssl, use_tls, for_imap, for_smtp, auth] msgs_per_page: 20 diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 4f19ca4..f54c166 100755 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -18,7 +18,12 @@ pl: models: contact: Kontakt server: Serwer + link: Sznurek attributes: + link: + name: Nazwa + url: Adres + info: Informacje contact: nick: Pseudonim first_name: Imię @@ -74,6 +79,14 @@ pl: were_imported: Kontakty zostały zaimportowane format_error: Nieprawidłowy format kontaktu + link: + link: Sznurek + links: Sznurki + create_new: Utwórz nowy sznurek + no_entries: Brak sznurków + total_entries: Liczba sznurków + delete_selected: Usuń wybrane + prefs: prefs: Ustawienia look: Wygląd diff --git a/config/routes.rb b/config/routes.rb index 4e48332..fb486e6 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,15 @@ Mailr::Application.routes.draw do resources :contacts + namespace :links do + post "ops" + get "export" + end + #match "/external" => "contacts#external", :as => :contacts_external + + + resources :links + namespace :folders do post "create" post "delete" diff --git a/db/migrate/20120109191128_create_links.rb b/db/migrate/20120109191128_create_links.rb new file mode 100644 index 0000000..2d78a01 --- /dev/null +++ b/db/migrate/20120109191128_create_links.rb @@ -0,0 +1,17 @@ +class CreateLinks < ActiveRecord::Migration + def self.up + create_table :links do |t| + t.integer :user_id + t.integer :lgroup_id + t.string :name + t.string :url + t.string :info + + t.timestamps + end + end + + def self.down + drop_table :links + end +end diff --git a/lib/imap_mailbox.rb b/lib/imap_mailbox.rb index a589711..aa84eb9 100755 --- a/lib/imap_mailbox.rb +++ b/lib/imap_mailbox.rb @@ -17,7 +17,7 @@ class IMAPMailbox @folders = {} @connected = false @logger = logger - Net::IMAP.debug = debug + Net::IMAP.debug = true end def connect(server,username,password) diff --git a/test/fixtures/links.yml b/test/fixtures/links.yml new file mode 100644 index 0000000..f63b205 --- /dev/null +++ b/test/fixtures/links.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + user_id: 1 + lgroup_id: 1 + name: MyString + url: MyString + info: MyString + +two: + user_id: 1 + lgroup_id: 1 + name: MyString + url: MyString + info: MyString diff --git a/test/unit/link_test.rb b/test/unit/link_test.rb new file mode 100644 index 0000000..2595574 --- /dev/null +++ b/test/unit/link_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class LinkTest < ActiveSupport::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/themes/olive/stylesheets/olive.css b/themes/olive/stylesheets/olive.css index c362196..833e4bf 100755 --- a/themes/olive/stylesheets/olive.css +++ b/themes/olive/stylesheets/olive.css @@ -406,6 +406,10 @@ th a.header { background: none repeat scroll 0 0 #EFF3E4; } +.table tr.unseen { + font-weight: bold; +} + .table td { border-bottom: 1px solid #F0F0EE; } diff --git a/themes/olive/views/internal/error.html.erb b/themes/olive/views/internal/error.html.erb index fb2ff64..604b808 100755 --- a/themes/olive/views/internal/error.html.erb +++ b/themes/olive/views/internal/error.html.erb @@ -3,9 +3,9 @@ <% end %>
    +
    diff --git a/themes/olive/views/links/_left.html.erb b/themes/olive/views/links/_left.html.erb new file mode 100755 index 0000000..0984760 --- /dev/null +++ b/themes/olive/views/links/_left.html.erb @@ -0,0 +1,7 @@ + +
    +<%= raw form_field(@link,"name",nil,"Fajny sznurek",@link.name) %> +<%= raw form_field(@link,"url",nil,"http://aaa.com",@link.url) %> +<%= raw form_field(@link,"info",nil,t(:some_add_info,:scope=>:link),@link.info) %> +
    +<%= raw single_action('save','common','save.png') %> diff --git a/themes/olive/views/links/_link.html.erb b/themes/olive/views/links/_link.html.erb new file mode 100755 index 0000000..3fc981a --- /dev/null +++ b/themes/olive/views/links/_link.html.erb @@ -0,0 +1,5 @@ +<%= check_box_tag "ids[]", link.id %> +<%= link_to link.name,edit_link_path(link) %> +<%= link_to link.url,"http://"+link.url %> +<%= link.info %> + diff --git a/themes/olive/views/links/_list.html.erb b/themes/olive/views/links/_list.html.erb new file mode 100755 index 0000000..6c2cd1c --- /dev/null +++ b/themes/olive/views/links/_list.html.erb @@ -0,0 +1,25 @@ +
    +
    + <%= t(:total_entries,:scope=>:link) %>: <%= @links.total_entries %> +<%= will_paginate @links %> +
    + + + + +<%= raw links_table_header %> + + +<% trclass = :even %> +<% @links.each do |c| %> + +<%= render :partial => 'link', :object => c %> + +<% trclass == :even ? trclass = :odd : trclass = :even %> +<% end %> + +
    +
    +<%= will_paginate @links %> +
    +
    diff --git a/themes/olive/views/links/_ops.html.erb b/themes/olive/views/links/_ops.html.erb new file mode 100755 index 0000000..eba864f --- /dev/null +++ b/themes/olive/views/links/_ops.html.erb @@ -0,0 +1,3 @@ +
    +<%= raw group_action(@buttons) %> +
    diff --git a/themes/olive/views/links/_right.html.erb b/themes/olive/views/links/_right.html.erb new file mode 100755 index 0000000..8b13789 --- /dev/null +++ b/themes/olive/views/links/_right.html.erb @@ -0,0 +1 @@ + diff --git a/themes/olive/views/links/edit.html.erb b/themes/olive/views/links/edit.html.erb new file mode 100755 index 0000000..cbfc587 --- /dev/null +++ b/themes/olive/views/links/edit.html.erb @@ -0,0 +1,30 @@ +<% content_for :sidebar do %> +<%= content_for_sidebar %> +<% end %> + +<% content_for :title do %> +- <%= t(:links,:scope=>:link) %> +<% end %> + +
    +
    + <%= raw main_navigation(:links) %> +
    +
    +
    +
    +
    <%= t(:modifying,:scope=>:link) %>
    +
    + <%= form_for(@link) do |f| %> +
    +
    + <%= render :partial => 'left' %> +
    +
    + <%= render :partial => 'right' %> +
    +
    + <% end %> +
    +
    +
    diff --git a/themes/olive/views/links/index.html.erb b/themes/olive/views/links/index.html.erb new file mode 100755 index 0000000..3b4cb7a --- /dev/null +++ b/themes/olive/views/links/index.html.erb @@ -0,0 +1,26 @@ +<% content_for :sidebar do %> +<%= content_for_sidebar %> +<% end %> + +<% content_for :title do %> +- <%= t(:links,:scope=>:link) %> +<% end %> + +
    + +
    +<%= form_tag(links_ops_path,{:name=>'links'})%> +<% if @links.size.zero? %> +

    <%= t(:no_entries,:scope=>:link) %>

    +<%= raw single_action('create_new','link','plus.png') %> + +<% else %> +<%= render :partial => 'ops' %> +<%= render :partial => 'list' %> + +<% end %> +
    +
    + diff --git a/themes/olive/views/links/new.html.erb b/themes/olive/views/links/new.html.erb new file mode 100755 index 0000000..974529c --- /dev/null +++ b/themes/olive/views/links/new.html.erb @@ -0,0 +1,30 @@ +<% content_for :sidebar do %> +<%= content_for_sidebar %> +<% end %> + +<% content_for :title do %> +- <%= t(:links,:scope=>:link) %> +<% end %> + +
    +
    + <%= raw main_navigation(:links) %> +
    +
    +
    +
    +
    <%= t(:creating_new,:scope=>:link) %>
    +
    + <%= form_for(@link) do |f| %> +
    +
    + <%= render :partial => 'links/left' %> +
    +
    + <%= render :partial => 'links/right' %> +
    +
    + <% end %> +
    +
    +
    diff --git a/themes/olive/views/messages/compose.html.erb b/themes/olive/views/messages/compose.html.erb index e3fc91e..510cbbe 100755 --- a/themes/olive/views/messages/compose.html.erb +++ b/themes/olive/views/messages/compose.html.erb @@ -6,8 +6,6 @@ - <%= t(:compose,:scope=>:compose) %> <% end %> -<%= calendar_window(:title=>t(:calendar,:scope=>:common)) %> -