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)


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

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

#bookmark_project(project) ⇒ Object



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

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



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

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

#delete_project_bookmark(project) ⇒ Object



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

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

#project_used(project) ⇒ Object



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

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
38
# File 'lib/redmine/project_jump_box.rb', line 31

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