Class: Api::AuditTrailController

Inherits:
ApiController
  • Object
show all
Includes:
ActionController::Serialization
Defined in:
app/controllers/api/audit_trail_controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) index

index to be removed… only there to view the functionality



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/api/audit_trail_controller.rb', line 7

def index
  #get all edits from PaperTrail
  @edits = PaperTrail::Version.order('created_at DESC')
  #make array to properly send all edits to front end
  @prettyEdits = Array.new

  #loop though all edits
  @edits.each do |i|
    #hash for each individual edit
    @edit = Hash.new()
    #use PaperTrailserializer on the changelog string
    @changes = PaperTrail.serializer.load(i.object_changes)

    #if the person model was changed
    if i.item_type=="Person"

      #get appropriate attributes from the version object or serialized object
      @edit[:changes] = @changes
      @edit[:date] = i.created_at
      @edit[:type] = i.item_type
      @edit[:person_id] = i.item_id



    #if the supervisor or mentor model was changed
    else
      #get the original object (in order to obtain the person_id)
      @originalObject = PaperTrail.serializer.load(i.object)

      #get appropriate attributes from the version object or serialized object
      @edit[:changes] = @changes
      @edit[:date] = i.created_at
      @edit[:type] = i.item_type
      @edit[:person_id] = @originalObject["person_id"]
    end

  #finally append the edit to the full array
  @prettyEdits<<@edit
  end

  #render it for the frontend
  render json: {edits:@prettyEdits}

end

- (Object) show



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/api/audit_trail_controller.rb', line 54

def show
  #get all edits from PaperTrail
  @edits = PaperTrail::Version.order('created_at DESC')
  #make array to properly send all edits to front end
  @prettyEdits = Array.new

  #loop though all edits
  @edits.each do |i|
    #hash for each individual edit
    @edit = Hash.new()
    #use PaperTrailserializer on the changelog string
    @changes = PaperTrail.serializer.load(i.object_changes)

    #if the person model was changed
    if i.item_type=="Person"

      #get appropriate attributes from the version object or serialized object
      @edit[:changes] = @changes
      @edit[:date] = i.created_at
      @edit[:type] = i.item_type
      @edit[:person_id] = i.item_id



    #if the supervisor or mentor model was changed
    else
      #get the original object (in order to obtain the person_id)
      @originalObject = PaperTrail.serializer.load(i.object)

      #get appropriate attributes from the version object
      @edit[:changes] = @changes
      @edit[:date] = i.created_at
      @edit[:type] = i.item_type
      @edit[:person_id] = @originalObject["person_id"]
    end

  #finally append the edit to the full array
  @prettyEdits<<@edit
  end

  #render it for the frontend
  render json: {edits:@prettyEdits}

end