Class: Location
  
  
  
  
    - Inherits:
 
    - 
      Sequel::Model
      
        
          - Object
 
          
            - Sequel::Model
 
          
            - Location
 
          
        
        show all
      
       
    
  
  
    
  
    
      - Includes:
 
      - ASModel, AutoGenerator, ExternalIDs
 
      
    
  
  
  
    - Defined in:
 
    - backend/app/model/location.rb
 
  
  
    
      Class Method Summary
      (collapse)
    
    
  
    
      Instance Method Summary
      (collapse)
    
    
  
  
  
  
  
  
  
  
  
  
  included, #update_from_json
  
  
  
  
  
  
  
  
  
  included
  
  
  
  
  
  
  
  
  Methods included from ASModel
  all_models, included, update_publish_flag, update_suppressed_flag
  
  
  
  
  
  
  
  
  Methods included from JSONModel
  JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_repository, strict_mode, strict_mode?, with_repository
  
  
    Class Method Details
    
      
  
  
    + (Object) batch_update(location) 
  
  
  
  
    
      
42
43
44
45
46
47
48
49
50
51
52
53
54 
     | 
    
      # File 'backend/app/model/location.rb', line 42
def self.batch_update(location)
  updated_values = location.to_hash.select { |k| [ "building", "floor", "room", "area" ].include?(k) }
  location[:record_uris].map do |uri|
    id = JSONModel.parse_reference(uri)[:id]
    json = Location.to_jsonmodel(id)
    updated_values.each do |key, val|
      json[key.intern] = val if ( !val.nil? && val.length > 0 )
    end
    
    Location.get_or_die(id).update_from_json(json)
  end
end
     | 
  
 
    
      
  
  
    + (Object) create_for_batch(batch) 
  
  
  
  
    
      
37
38
39
40 
     | 
    
      # File 'backend/app/model/location.rb', line 37
def self.create_for_batch(batch)
  locations = generate_locations_for_batch(batch)
  locations.map{|location| self.create_from_json(location)}
end
     | 
  
 
    
      
  
  
    + (Object) generate_indicators(opts) 
  
  
  
  
    
      
98
99
100
101 
     | 
    
      # File 'backend/app/model/location.rb', line 98
def self.generate_indicators(opts)
  range = (opts["start"]..opts["end"]).take(AppConfig[:max_location_range].to_i)
  range.map{|i| "#{opts["prefix"]}#{i}#{opts["suffix"]}"}
end
     | 
  
 
    
      
  
  
    + (Object) generate_locations_for_batch(batch) 
  
  
  
  
    
      
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 
     | 
    
      # File 'backend/app/model/location.rb', line 61
def self.generate_locations_for_batch(batch)
  indicators_1, indicators_2, indicators_3  = [batch["coordinate_1_range"], batch["coordinate_2_range"], batch["coordinate_3_range"]].
                                                compact.
                                                map{|data| generate_indicators(data)}
  source_location = batch.clone
  results = []
  indicators_1.each do |indicator_1|
    source_location["coordinate_1_label"] = batch["coordinate_1_range"]["label"]
    source_location["coordinate_1_indicator"] = indicator_1
    if indicators_2
      indicators_2.each do |indicator_2|
        source_location["coordinate_2_label"] = batch["coordinate_2_range"]["label"]
        source_location["coordinate_2_indicator"] = indicator_2
        if indicators_3
          indicators_3.each do |indicator_3|
            source_location["coordinate_3_label"] = batch["coordinate_3_range"]["label"]
            source_location["coordinate_3_indicator"] = indicator_3
            results.push(JSONModel(:location).from_hash(source_location))
          end
        else
          results.push(JSONModel(:location).from_hash(source_location))
        end
      end
    else
      results.push(JSONModel(:location).from_hash(source_location))
    end
  end
  results
end
     | 
  
 
    
      
  
  
    + (Object) generate_title(json) 
  
  
  
  
    
      
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 
     | 
    
      # File 'backend/app/model/location.rb', line 11
def self.generate_title(json)
  title = ""
  title << json['building']
  title << ", #{json['floor']}" if json['floor']
  title << ", #{json['room']}" if json['room']
  title << ", #{json['area']}" if json['area']
  others = []
  others << json['barcode'] if json['barcode']
  others << json['classification'] if json['classification']
  others << "#{json['coordinate_1_label']}: #{json['coordinate_1_indicator']}" if json['coordinate_1_label']
  others << "#{json['coordinate_2_label']}: #{json['coordinate_2_indicator']}" if json['coordinate_2_label']
  others << "#{json['coordinate_3_label']}: #{json['coordinate_3_indicator']}" if json['coordinate_3_label']
  title << " [#{others.join(", ")}]"
  title
end
     | 
  
 
    
      
  
  
    + (Object) titles_for_batch(batch) 
  
  
  
  
    
      
56
57
58
59 
     | 
    
      # File 'backend/app/model/location.rb', line 56
def self.titles_for_batch(batch)
  locations = generate_locations_for_batch(batch)
  locations.map{|location| self.generate_title(location)}
end
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    - (Object) delete 
  
  
  
  
    
      
104
105
106
107
108
109
110
111
112
113 
     | 
    
      # File 'backend/app/model/location.rb', line 104
def delete
  
  object_graph = self.object_graph
  if object_graph.models.any? {|model| model.is_relationship?}
    raise ConflictException.new("Location cannot be deleted if linked")
  end
  super
end
     |