links added and other stuff

This commit is contained in:
Wojciech Todryk 2012-02-04 00:45:28 +01:00
parent eb455e704a
commit f0dcdc3985
28 changed files with 384 additions and 10 deletions

View file

@ -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

View file

@ -115,14 +115,23 @@ class MessagesOpsController < ApplicationController
flash[:warning] = t(:no_selected,:scope=>:folder) flash[:warning] = t(:no_selected,:scope=>:folder)
else else
dest_folder = @current_user.folders.find(params[:folder][:target]) dest_folder = @current_user.folders.find(params[:folder][:target])
logger.info "DEST: "+dest_folder.inspect
params["uids"].each do |uid| 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) @mailbox.move_message(uid,dest_folder.full_name)
message = @current_folder.messages.find_by_uid(uid) 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) message.change_folder(dest_folder)
logger.info "UPDATE_DEST_BEFORE2: "+dest_folder.inspect
end end
logger.info "UPDATE_DEST_BEFORE: "+dest_folder.inspect
@mailbox.expunge @mailbox.expunge
dest_folder.update_stats dest_folder.update_stats
logger.info "UPDATE_DEST: "+dest_folder.inspect
@current_folder.update_stats @current_folder.update_stats
logger.info "UPDATE_CUT: "+@current_folder.inspect
end end
end end

View file

@ -269,7 +269,8 @@ def main_navigation(active)
s += "<li class=\"#{@compose_tab}\">#{link_to( t(:compose,:scope=>:compose), compose_path )}</li>" s += "<li class=\"#{@compose_tab}\">#{link_to( t(:compose,:scope=>:compose), compose_path )}</li>"
s += "<li class=\"#{@folders_tab}\">#{link_to( t(:folders,:scope=>:folder), folders_path )}</li>" s += "<li class=\"#{@folders_tab}\">#{link_to( t(:folders,:scope=>:folder), folders_path )}</li>"
s += "<li class=\"#{@contacts_tab}\">#{link_to( t(:contacts,:scope=>:contact), contacts_path )}</li>" s += "<li class=\"#{@contacts_tab}\">#{link_to( t(:contacts,:scope=>:contact), contacts_path )}</li>"
s += "<li class=\"last #{@prefs_tab}\">#{link_to( t(:prefs,:scope=>:prefs), prefs_look_path )}</li>" s += "<li class=\"#{@prefs_tab}\">#{link_to( t(:prefs,:scope=>:prefs), prefs_look_path )}</li>"
s += "<li class=\"last #{@links_tab}\">#{link_to( t(:links,:scope=>:link), links_path )}</li>"
s += "</ul>" s += "</ul>"
end end

17
app/helpers/links_helper.rb Executable file
View file

@ -0,0 +1,17 @@
module LinksHelper
def links_table_header
html = ""
$defaults["links_table_fields"].each do |f|
html << "<th>"
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 << "</th>"
end
html
end
end

View file

@ -38,8 +38,11 @@ class Folder < ActiveRecord::Base
end end
def update_stats def update_stats
logger.info "MESS_BEFORE: "+messages.inspect
unseen = messages.where(:unseen => true).count unseen = messages.where(:unseen => true).count
total = messages.count total = messages.count
logger.info "MESS: "+messages.inspect
logger.info "MESS: #{unseen} #{total}"
update_attributes(:unseen => unseen, :total => total) update_attributes(:unseen => unseen, :total => total)
end end

19
app/models/link.rb Normal file
View file

@ -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

View file

@ -11,6 +11,7 @@ class User < ActiveRecord::Base
has_many :folders, :dependent => :destroy has_many :folders, :dependent => :destroy
has_many :messages, :dependent => :destroy has_many :messages, :dependent => :destroy
has_many :contacts, :dependent => :destroy has_many :contacts, :dependent => :destroy
has_many :links, :dependent => :destroy
def set_cached_password(session,password) def set_cached_password(session,password)
if $defaults['session_encryption'] if $defaults['session_encryption']

View file

@ -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_table_fields: [nick, first_name, last_name, email, info]
contacts_per_page: 25 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] servers_table_fields: [name, port, use_ssl, use_tls, for_imap, for_smtp, auth]
msgs_per_page: 20 msgs_per_page: 20

View file

@ -18,7 +18,12 @@ pl:
models: models:
contact: Kontakt contact: Kontakt
server: Serwer server: Serwer
link: Sznurek
attributes: attributes:
link:
name: Nazwa
url: Adres
info: Informacje
contact: contact:
nick: Pseudonim nick: Pseudonim
first_name: Imię first_name: Imię
@ -74,6 +79,14 @@ pl:
were_imported: Kontakty zostały zaimportowane were_imported: Kontakty zostały zaimportowane
format_error: Nieprawidłowy format kontaktu 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:
prefs: Ustawienia prefs: Ustawienia
look: Wygląd look: Wygląd

View file

@ -17,6 +17,15 @@ Mailr::Application.routes.draw do
resources :contacts resources :contacts
namespace :links do
post "ops"
get "export"
end
#match "/external" => "contacts#external", :as => :contacts_external
resources :links
namespace :folders do namespace :folders do
post "create" post "create"
post "delete" post "delete"

View file

@ -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

View file

@ -17,7 +17,7 @@ class IMAPMailbox
@folders = {} @folders = {}
@connected = false @connected = false
@logger = logger @logger = logger
Net::IMAP.debug = debug Net::IMAP.debug = true
end end
def connect(server,username,password) def connect(server,username,password)

15
test/fixtures/links.yml vendored Normal file
View file

@ -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

8
test/unit/link_test.rb Normal file
View file

@ -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

View file

@ -406,6 +406,10 @@ th a.header {
background: none repeat scroll 0 0 #EFF3E4; background: none repeat scroll 0 0 #EFF3E4;
} }
.table tr.unseen {
font-weight: bold;
}
.table td { .table td {
border-bottom: 1px solid #F0F0EE; border-bottom: 1px solid #F0F0EE;
} }

View file

@ -3,9 +3,9 @@
<% end %> <% end %>
<div id="box"> <div id="box">
<div id="box2">
<div class="block block-login"> <div class="block block-login">
<div id="logo"><a href="/"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a> <div id="logo"><a href="/"><img src="<%= current_theme_image_path('logo_small.png')%>" alt="Mailr"/></a></div>
</div>
<h2><%= @title %></h2> <h2><%= @title %></h2>
<div class="content"> <div class="content">
<div class="flash"><div class="message error"><p><%= @error %></p></div></div> <div class="flash"><div class="message error"><p><%= @error %></p></div></div>

View file

@ -28,6 +28,7 @@ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
</div> </div>
<div id="main"> <div id="main">
<%= render :partial=>'layouts/flash', :object => flash %> <%= render :partial=>'layouts/flash', :object => flash %>
<%= calendar_window(:title=>t(:calendar,:scope=>:common)) %>
<%= yield %> <%= yield %>
</div> </div>
</div> </div>

View file

@ -0,0 +1,7 @@
<div class="params">
<%= 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) %>
</div>
<%= raw single_action('save','common','save.png') %>

View file

@ -0,0 +1,5 @@
<td><%= check_box_tag "ids[]", link.id %></td>
<td nowrap="nowrap"><%= link_to link.name,edit_link_path(link) %></td>
<td nowrap="nowrap"><%= link_to link.url,"http://"+link.url %></td>
<td colspan="2" nowrap="nowrap"><%= link.info %></td>

View file

@ -0,0 +1,25 @@
<div class="inner">
<div class="actions-bar">
<span class="other_info"> <%= t(:total_entries,:scope=>:link) %>: <%= @links.total_entries %></span>
<%= will_paginate @links %>
</div>
<table class="table">
<tbody>
<tr>
<th class="first"><input id="toggleall" class="checkbox toggle" type="checkbox" name="allbox"/></th>
<%= raw links_table_header %>
<th class="last"></th>
</tr>
<% trclass = :even %>
<% @links.each do |c| %>
<tr class="<%= trclass.to_s %>">
<%= render :partial => 'link', :object => c %>
</tr>
<% trclass == :even ? trclass = :odd : trclass = :even %>
<% end %>
</tbody>
</table>
<div class="actions-bar">
<%= will_paginate @links %>
</div>
</div>

View file

@ -0,0 +1,3 @@
<div id="ops" class="ops">
<%= raw group_action(@buttons) %>
</div>

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,30 @@
<% content_for :sidebar do %>
<%= content_for_sidebar %>
<% end %>
<% content_for :title do %>
- <%= t(:links,:scope=>:link) %>
<% end %>
<div class="block" id="block-tables">
<div class="secondary-navigation">
<%= raw main_navigation(:links) %>
</div>
<div class="content">
<div class="inner">
<div class="actions-bar wat-cf">
<div class="header_info"><%= t(:modifying,:scope=>:link) %></div>
</div>
<%= form_for(@link) do |f| %>
<div class="columns wat-cf">
<div class="column left">
<%= render :partial => 'left' %>
</div>
<div class="column right">
<%= render :partial => 'right' %>
</div>
</div>
<% end %>
</div>
</div>
</div>

View file

@ -0,0 +1,26 @@
<% content_for :sidebar do %>
<%= content_for_sidebar %>
<% end %>
<% content_for :title do %>
- <%= t(:links,:scope=>:link) %>
<% end %>
<div class="block">
<div class="navigation-tabs clearfix">
<%= raw main_navigation(:links_tab) %>
</div>
<div class="content">
<%= form_tag(links_ops_path,{:name=>'links'})%>
<% if @links.size.zero? %>
<h3><%= t(:no_entries,:scope=>:link) %></h3>
<%= raw single_action('create_new','link','plus.png') %>
</form>
<% else %>
<%= render :partial => 'ops' %>
<%= render :partial => 'list' %>
</form>
<% end %>
</div>
</div>

View file

@ -0,0 +1,30 @@
<% content_for :sidebar do %>
<%= content_for_sidebar %>
<% end %>
<% content_for :title do %>
- <%= t(:links,:scope=>:link) %>
<% end %>
<div class="block" id="block-tables">
<div class="secondary-navigation">
<%= raw main_navigation(:links) %>
</div>
<div class="content">
<div class="inner">
<div class="actions-bar wat-cf">
<div class="header_info"><%= t(:creating_new,:scope=>:link) %> </div>
</div>
<%= form_for(@link) do |f| %>
<div class="columns wat-cf">
<div class="column left">
<%= render :partial => 'links/left' %>
</div>
<div class="column right">
<%= render :partial => 'links/right' %>
</div>
</div>
<% end %>
</div>
</div>
</div>

View file

@ -6,8 +6,6 @@
- <%= t(:compose,:scope=>:compose) %> - <%= t(:compose,:scope=>:compose) %>
<% end %> <% end %>
<%= calendar_window(:title=>t(:calendar,:scope=>:common)) %>
<div class="block"> <div class="block">
<div class="navigation-tabs clearfix"> <div class="navigation-tabs clearfix">
<%= raw main_navigation(:compose_tab) %> <%= raw main_navigation(:compose_tab) %>

View file

@ -6,8 +6,6 @@
- <%= t(:messages,:scope=>:message) %> - <%= t(:messages,:scope=>:message) %>
<% end %> <% end %>
<%= calendar_window(:title=>t(:calendar,:scope=>:common)) %>
<div class="block"> <div class="block">
<div class="navigation-tabs clearfix"> <div class="navigation-tabs clearfix">
<%= raw main_navigation(:messages_tab) %> <%= raw main_navigation(:messages_tab) %>

View file

@ -6,8 +6,6 @@
- <%= subject_formatter(@message,:show) %> - <%= subject_formatter(@message,:show) %>
<% end %> <% end %>
<%= calendar_window(:title=>t(:calendar,:scope=>:common)) %>
<div class="block"> <div class="block">
<div class="navigation-tabs clearfix"> <div class="navigation-tabs clearfix">
<%= raw main_navigation(:show) %> <%= raw main_navigation(:show) %>