folders devel ended

This commit is contained in:
Wojciech Todryk 2011-07-31 22:45:29 +02:00
parent 565654d2a5
commit 65472c55cc
18 changed files with 119 additions and 65 deletions

View file

@ -43,4 +43,9 @@ class ApplicationController < ActionController::Base
session[:selected_folder] ? @selected_folder = session[:selected_folder] : @selected_folder = $defaults['mailbox_inbox']
end
def get_current_folders
@folders_shown = @current_user.folders.shown.order("name asc")
@current_folder = @current_user.folders.current(@selected_folder)
end
end

View file

@ -1,21 +1,12 @@
require 'imap_session'
require 'imap_mailbox'
class ContactsController < ApplicationController
include ImapMailboxModule
include ImapSessionModule
before_filter :check_current_user,:selected_folder
before_filter :open_imap_session
after_filter :close_imap_session
before_filter :get_current_folders, :only => [:index]
theme :theme_resolver
def index
@folders = @current_user.folders.order("name asc")
@current_folder = @current_user.folders.current(@selected_folder)
flash[:notice] = 'Not implemented yet'
end

View file

@ -5,10 +5,10 @@ class FoldersController < ApplicationController
before_filter :check_current_user ,:selected_folder
before_filter :open_imap_session
after_filter :close_imap_session
before_filter :open_imap_session, :except => [:index,:refresh_status,:show_hide]
after_filter :close_imap_session, :except => [:index,:refresh_status,:show_hide]
before_filter :get_folders, :except => :manage
before_filter :get_folders
theme :theme_resolver
@ -36,7 +36,7 @@ class FoldersController < ApplicationController
render 'index'
return
end
redirect_to :action => 'manage', :flash => t(:folder_was_created), :type => :notice
redirect_to :action => 'refresh', :flash => t(:folder_was_created), :type => :notice
end
end
# FIXME if you delete folder you should change current folder because if you go to messages/index you got nil
@ -61,18 +61,26 @@ class FoldersController < ApplicationController
render 'index'
return
end
redirect_to :action => 'manage', :flash => t(:folder_was_deleted), :type => :notice
redirect_to :action => 'refresh', :flash => t(:folder_was_deleted), :type => :notice
end
end
def sub_un_scribe
redirect_to :action => 'manage'
def show_hide
@folders.each do |f|
logger.info f.inspect,"\n"
if params["folders_to_show"].include?(f.id.to_s)
f.shown = true
f.save
else
f.shown = false
f.save
end
end
redirect_to :action => 'index'
end
def manage
@current_user.folders.destroy_all
folders=@mailbox.folders
Folder.createBulk(@current_user,folders)
def refresh
Folder.refresh(@mailbox,@current_user)
if params[:flash]
flash[params[:type]] = params[:flash]
end
@ -83,7 +91,15 @@ class FoldersController < ApplicationController
def get_folders
@folders = @current_user.folders.order("name asc")
@current_folder = @current_user.folders.current(@selected_folder)
@folders_shown = []
@folders.each do |f|
if f.shown == true
@folders_shown << f
end
if f.selected?(@selected_folder)
@current_folder = f
end
end
end
end

View file

@ -8,33 +8,28 @@ class MessagesController < ApplicationController
before_filter :check_current_user ,:selected_folder
before_filter :get_current_folders, :only => [:index,:compose]
before_filter :open_imap_session, :only => :refresh
after_filter :close_imap_session, :only => :refresh
theme :theme_resolver
def index
@folders = @current_user.folders.order("name asc")
@current_folder = @current_user.folders.current(@selected_folder)
flash[:notice] = 'Not implemented yet'
end
def refresh
@current_user.folders.destroy_all
folders=@mailbox.folders
Folder.createBulk(@current_user,folders)
redirect_to :action => 'index'
end
def folder
session[:selected_folder] = params[:id]
redirect_to :action => 'index'
end
def compose
@folders = @current_user.folders.order("name asc")
@current_folder = @current_user.folders.current(@selected_folder)
flash[:notice] = 'Not impelented yet'
end
def refresh
redirect_to :action => 'index'
end
end

View file

@ -2,11 +2,11 @@ class PrefsController < ApplicationController
before_filter :check_current_user,:selected_folder
before_filter :get_current_folders, :only => [:index,:compose]
theme :theme_resolver
def index
@folders = @current_user.folders.order("name asc")
@current_folder = @current_user.folders.current(@selected_folder)
flash[:notice] = 'Not implemented yet'
end

View file

@ -89,7 +89,7 @@ end
#end
def nav_to_folders
link_to( t(:folders), :controller=>:folders, :action=>:manage )
link_to( t(:folders), :controller=>:folders, :action=>:index )
end
def nav_to_messages

View file

@ -10,8 +10,7 @@ module FolderHelper
end
def pretty_folder_name(folder)
#folder = folder.gsub(/#/,".")
folder.name.capitalize
folder.nil? ? t(:no_folder_selected) : folder.name.capitalize
end
def select_for_folders(name,id,object,label,blank)

View file

@ -16,6 +16,12 @@ class Folder < ActiveRecord::Base
parent.split('.').size
end
def selected?(session_folder)
fields = session_folder.split("#")
fields[1].nil? ? fields.insert(0,"") : fields
(fields[1].downcase == name.downcase) && (fields[0].downcase == parent.downcase)
end
private
def check_fill_params
@ -43,13 +49,19 @@ class Folder < ActiveRecord::Base
def self.current(data)
folder = data.split("#")
if folder.size > 1
where(['name = ? and parent = ?',folder[1],folder[0]]).first
else
where(['name = ?',folder[0]]).first
end
nam = folder.delete_at(folder.size - 1)
folder.size.zero? == true ? par = "" : par = folder.join(".")
where(['name = ? and parent = ?',nam,par]).first
end
def self.shown
where(['shown = ?',true])
end
def self.refresh(mailbox,user)
user.folders.destroy_all
folders=mailbox.folders
Folder.createBulk(user,folders)
end
end

View file

@ -15,8 +15,8 @@ session_encryption: true
session_password: asDD3s2@sAdc983#
mailbox_max_parent_folder_depth: 3
mailbox_inbox: inbox
mailbox_trash: inbox.trash
mailbox_sent: inbox.sent
mailbox_drafts: inbox.drafts
mailbox_inbox: INBOX
mailbox_trash: Trash
mailbox_sent: Sent
mailbox_drafts: Drafts

View file

@ -92,3 +92,5 @@ en:
folder_was_deleted: Folder was deleted
can_not_delete_folder: Can not delete folder
system_folder: System folder
refresh_folders: Refresh folders
show_hide: Show/Hide

View file

@ -5,12 +5,11 @@ Mailr::Application.routes.draw do
get "contacts/index"
get "folders/index"
post "folders/create"
post "folders/delete"
post "folders/sub_un_scribe"
get "folders/manage"
post "folders/show_hide"
get "folders/refresh"
post "folders/refresh"
get "internal/error"
get "internal/imaperror"
@ -22,6 +21,7 @@ Mailr::Application.routes.draw do
match 'messages/folder/:id' => 'messages#folder'
post "messages/ops"
get "messages/compose"
get"messages/refresh"
get "user/logout"
post "user/authenticate"

View file

@ -0,0 +1,11 @@
class AddShownToFolders < ActiveRecord::Migration
def self.up
add_column :folders, :shown, :boolean
add_column :folders, :alter_name, :string
end
def self.down
remove_column :folders, :alter_name
remove_column :folders, :shown
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110727134352) do
ActiveRecord::Schema.define(:version => 20110731185416) do
create_table "folders", :force => true do |t|
t.string "name"
@ -23,6 +23,8 @@ ActiveRecord::Schema.define(:version => 20110727134352) do
t.datetime "updated_at"
t.string "parent"
t.datetime "msgs_updated_at"
t.boolean "shown"
t.string "alter_name"
end
create_table "messages", :force => true do |t|

View file

@ -5,7 +5,7 @@ module ImapSessionModule
def open_imap_session
begin
@mailbox = ImapMailboxModule::IMAPMailbox.new(logger)
@mailbox ||= ImapMailboxModule::IMAPMailbox.new(logger)
@mailbox.connect(@current_user.servers.primary,@current_user.email, @current_user.get_cached_password(session))
rescue Exception => ex
redirect_to :controller => 'internal', :action => 'loginfailure'

View file

@ -365,4 +365,3 @@ input,select {
color: grey;
}

View file

@ -1,11 +1,19 @@
<div class="block">
<h3><%=t (:folders) %> <%= link_to t(:refresh), {:controller => 'messages', :action => 'refresh'}, :class=>'minor' %></h3>
<div class="content">
<% if @folders_shown.size.zero? %>
<p><%= t(:no_folders_shown) %></p>
<% else %>
<ul class="navigation">
<% @folders.each do |folder| -%>
<% @folders_shown.each do |folder| -%>
<% if folder == @current_folder %>
<li><b><%= raw folder_link(folder) %></b></li>
<% else %>
<li><%= raw folder_link(folder) %></li>
<% end %>
<% end -%>
</ul>
<% end %>
<br/>
<%= raw form_button_value(t(:logout),'tick.png',url_for(:controller => :user, :action => :logout)) %>
</div>

View file

@ -25,9 +25,12 @@
</form>
</div>
<div class="column right">
<%= form_tag({:controller=>'folders',:action=>'sub_un_scribe'},:class=>'form') %>
<%= raw multi_select("", 'folders_to_subscribe[]', @folders, @folders,t(:folders_subscribed),:id,"",{:text => [:parent,:delim,:name]}) %>
<%= raw form_button(t(:subscribe_unsubscribe),'tick.png') %>
<%= form_tag({:controller=>'folders',:action=>'refresh'},:class=>'form') %>
<%= raw form_button(t(:refresh_folders),'tick.png') %>
</form>
<%= form_tag({:controller=>'folders',:action=>'show_hide'},:class=>'form') %>
<%= raw multi_select("", 'folders_to_show[]', @folders, @folders_shown,t(:folders_shown),:id,"",{:text => [:parent,:delim,:name]}) %>
<%= raw form_button(t(:show_hide),'tick.png') %>
</form>
</div>
</div>

View file

@ -14,10 +14,21 @@
<%= form_tag({:controller=>'messages', :action=>'ops'})%>
</form>
</div>
</div>
<% if @current_folder.nil? %>
<%= t(:no_folder_selected) %>
<% else %>
<h1>Current: <%= pretty_folder_name(@current_folder) %></h1>
<%= @current_folder.inspect %>
<%= Time.now - @current_folder.msgs_updated_at %>
<% end %>
</div>
</div>