Class: Redmine::ProjectJumpBox

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine/project_jump_box.rb

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ ProjectJumpBox

Returns a new instance of ProjectJumpBox.


22
23
24
25
# File 'lib/redmine/project_jump_box.rb', line 22

def initialize(user)
  @user = user
  @pref_project_ids = {}
end

Instance Method Details

#bookmark?(project) ⇒ Boolean

Returns:

  • (Boolean)

64
65
66
# File 'lib/redmine/project_jump_box.rb', line 64

def bookmark?(project)
  project && project.id && bookmarked_project_ids.include?(project.id)
end

#bookmark_project(project) ⇒ Object


53
54
55
56
# File 'lib/redmine/project_jump_box.rb', line 53

def bookmark_project(project)
  self.recently_used_project_ids = recently_used_project_ids.reject{|id| id == project.id}
  self.bookmarked_project_ids = (bookmarked_project_ids << project.id)
end

#bookmarked_projectsObject


39
40
41
# File 'lib/redmine/project_jump_box.rb', line 39

def bookmarked_projects
  Project.where(id: bookmarked_project_ids).visible.to_a
end

#delete_project_bookmark(project) ⇒ Object


58
59
60
61
62
# File 'lib/redmine/project_jump_box.rb', line 58

def delete_project_bookmark(project)
  self.bookmarked_project_ids = bookmarked_project_ids.reject do |id|
    id == project.id
  end
end

#project_used(project) ⇒ Object


43
44
45
46
47
48
49
50
51
# File 'lib/redmine/project_jump_box.rb', line 43

def project_used(project)
  return if project.blank? || project.id.blank?

  id_array = recently_used_project_ids
  id_array.reject!{ |i| i == project.id }
  # we dont want bookmarks in the recently used list:
  id_array.unshift(project.id) unless bookmark?(project)
  self.recently_used_project_ids = id_array[0, recent_projects_count]
end

#recent_projects_countObject


27
28
29
# File 'lib/redmine/project_jump_box.rb', line 27

def recent_projects_count
  @user.pref.recently_used_projects
end

#recently_used_projectsObject


31
32
33
34
35
36
37
# File 'lib/redmine/project_jump_box.rb', line 31

def recently_used_projects
  project_ids = recently_used_project_ids
  Project.where(id: project_ids).
    index_by(&:id).
    values_at(*project_ids). # sort according to stored order
    compact
end