Class: SesDashboard::ProjectsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ses_dashboard/projects_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
# File 'app/controllers/ses_dashboard/projects_controller.rb', line 27

def create
  @project = Project.new(project_params)
  if @project.save
    redirect_to project_path(@project), notice: "Project created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject



46
47
48
49
# File 'app/controllers/ses_dashboard/projects_controller.rb', line 46

def destroy
  @project.destroy
  redirect_to projects_path, notice: "Project deleted."
end

#editObject



36
# File 'app/controllers/ses_dashboard/projects_controller.rb', line 36

def edit; end

#indexObject



5
6
7
# File 'app/controllers/ses_dashboard/projects_controller.rb', line 5

def index
  @projects = Project.ordered
end

#newObject



23
24
25
# File 'app/controllers/ses_dashboard/projects_controller.rb', line 23

def new
  @project = Project.new
end

#showObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/ses_dashboard/projects_controller.rb', line 9

def show
  from = parse_date(params[:from]) || 30.days.ago.beginning_of_day
  to   = parse_date(params[:to])   || Time.current.end_of_day

  agg = StatsAggregator.new(project_id: @project.id, from: from, to: to)

  @counters     = agg.counters
  @total_opens  = agg.total_opens
  @total_clicks = agg.total_clicks
  @chart_data   = agg.time_series
  @from         = from
  @to           = to
end

#updateObject



38
39
40
41
42
43
44
# File 'app/controllers/ses_dashboard/projects_controller.rb', line 38

def update
  if @project.update(project_params)
    redirect_to project_path(@project), notice: "Project updated."
  else
    render :edit, status: :unprocessable_entity
  end
end