Class: NextSgad::PositionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/next_sgad/positions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /positions



26
27
28
29
30
31
32
33
34
# File 'app/controllers/next_sgad/positions_controller.rb', line 26

def create
  @position = Position.new(position_params)

  if @position.save
    redirect_to @position, notice: 'Position was successfully created.'
  else
    render :new
  end
end

#destroyObject

DELETE /positions/1



46
47
48
49
# File 'app/controllers/next_sgad/positions_controller.rb', line 46

def destroy
  @position.destroy
  redirect_to positions_url, notice: 'Position was successfully destroyed.'
end

#editObject

GET /positions/1/edit



22
23
# File 'app/controllers/next_sgad/positions_controller.rb', line 22

def edit
end

#indexObject

GET /positions



8
9
10
# File 'app/controllers/next_sgad/positions_controller.rb', line 8

def index
  @positions = Position.all
end

#newObject

GET /positions/new



17
18
19
# File 'app/controllers/next_sgad/positions_controller.rb', line 17

def new
  @position = Position.new
end

#orgchartObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/next_sgad/positions_controller.rb', line 51

def orgchart
  @o = (Department.all + Position.all + Employee.all).group_by{|x| [x.class.name, x.id]}
  @positions = Position.all.group_by{|p| p.position_id}
  @root = Position.find_by(id: params[:root_id]) || Position.where(position_id: nil).first
  if @root.present?
    @return = org_data(@root, @o, @positions)
  else
    @return = {}
  end

  respond_to do |format|
    format.html
    format.json{render json: @return}
  end
end

#showObject

GET /positions/1



13
14
# File 'app/controllers/next_sgad/positions_controller.rb', line 13

def show
end

#updateObject

PATCH/PUT /positions/1



37
38
39
40
41
42
43
# File 'app/controllers/next_sgad/positions_controller.rb', line 37

def update
  if @position.update(position_params)
    redirect_to @position, notice: 'Position was successfully updated.'
  else
    render :edit
  end
end