Class: Nightlight::PagesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/nightlight/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_noObject



67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/nightlight/pages_controller.rb', line 67

def add_no
  @page = Page.new page_params
  @page.hidden = true
  if @page.save
    flash[:success] = "Settings saved."
  else
    flash[:error] = @page.errors.full_messages.first
  end
  redirect_to root_url
end

#add_yesObject



57
58
59
60
61
62
63
64
65
# File 'app/controllers/nightlight/pages_controller.rb', line 57

def add_yes
  @page = Page.new page_params
  if @page.save
    flash[:success] = "Page added."
  else
    flash[:error] = @page.errors.full_messages.first
  end
  redirect_to root_url
end

#assignObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/nightlight/pages_controller.rb', line 78

def assign
  if @page.assignee
    flash[:error] = "Someone is already assigned to this page"
    redirect_to page_url(@page)
    return
  end
  @page.assignee = current_user
  if @page.save
    flash[:success] = "You are now assigned to this page"
    redirect_to page_url(@page)
  else
    flash.now[:error] = @page.errors.full_messages.first
    render 'nightlight/pages/show'
  end
end

#checkedObject



105
106
107
108
109
# File 'app/controllers/nightlight/pages_controller.rb', line 105

def checked
  @page.checked! current_user
  flash[:success] = "Nice job"
  redirect_to page_url(@page)
end

#createObject



30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/nightlight/pages_controller.rb', line 30

def create
  @page = Nightlight::Page.new page_params
  if @page.save
    flash[:success] = "Page saved."
    redirect_to page_url(@page)
  else
    flash.now[:error] = @page.errors.full_messages.first
    render 'nightlight/pages/new'
  end
end

#destroyObject



51
52
53
54
55
# File 'app/controllers/nightlight/pages_controller.rb', line 51

def destroy
  @page.destroy
  flash[:success] = "Page deleted."
  redirect_to root_url
end

#editObject



23
24
# File 'app/controllers/nightlight/pages_controller.rb', line 23

def edit
end

#indexObject



8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/nightlight/pages_controller.rb', line 8

def index
  @pages = Nightlight::Page.where(hidden: false).order('last_checked_at ASC')
  @new_pages = routes_pages.select do |r|
    Nightlight::Page.where(path: r[:path]).none?
  end

  if params[:all]
    @hidden_pages = Nightlight::Page.hidden
  end
end

#newObject



26
27
28
# File 'app/controllers/nightlight/pages_controller.rb', line 26

def new
  @page = Nightlight::Page.new
end

#randomObject



111
112
113
114
115
116
117
118
# File 'app/controllers/nightlight/pages_controller.rb', line 111

def random
  scope = Nightlight::Page.unhidden.unassigned
  offset = rand(scope.count)
  @page = scope.offset(offset).first
  @page.update! assignee: current_user
  flash[:success] = "You are now assigned to this page"
  redirect_to page_url(@page)
end

#showObject



19
20
21
# File 'app/controllers/nightlight/pages_controller.rb', line 19

def show
  @status = Nightlight::Activity.new
end

#unassignObject



94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/nightlight/pages_controller.rb', line 94

def unassign
  @page.assignee = nil
  if @page.save
    flash[:success] = "You are no longer assigned to this page"
    redirect_to page_url(@page)
  else
    flash.now[:error] = @page.errors.full_messages.first
    render 'nightlight/pages/show'
  end
end

#updateObject



41
42
43
44
45
46
47
48
49
# File 'app/controllers/nightlight/pages_controller.rb', line 41

def update
  if @page.update page_params
    flash[:success] = "Page updated."
    redirect_to page_url(@page)
  else
    flash.now[:error] = @page.errors.full_messages.first
    render 'nightlight/pages/edit'
  end
end