Class: PbBaseController

Inherits:
ApplicationController
  • Object
show all
Includes:
Marshaller
Defined in:
lib/controllers/pbbase_controller.rb

Instance Method Summary collapse

Instance Method Details

#dictionary_updateObject



105
106
107
108
109
110
111
112
113
114
# File 'lib/controllers/pbbase_controller.rb', line 105

def dictionary_update
  lang = session[:lang]
  id = params['id']
  value = params['value']
  if ((lang != nil) && (id != nil)) then
    updateDictionary(lang, id, value)
  end
  # render back the value to confirm change
  render(:text => value)
end

#entity_addObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/controllers/pbbase_controller.rb', line 63

def entity_add
  name = params['name']
  if (params['type'] == 'coverage') then
    type = :coverage
  else
    type = :entity
  end
  unless (name == nil) then
    addProductEntity(session[:selected_product], type, name)
  end
  render(:text => :OK)
end

#entity_deleteObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/controllers/pbbase_controller.rb', line 85

def entity_delete
  name = params['name']
  unless (name == nil) then
    deleteProductEntity(session[:selected_product], name)
    if (session[:selected_product_item] == name) then
      session[:selected_product_item] = nil
    end
  end
  render(:text => :OK)
end

#entity_saveObject



96
97
98
99
100
101
102
103
# File 'lib/controllers/pbbase_controller.rb', line 96

def entity_save
  entities = params['entities']
  unless (entities == nil) then
    selected = entities.split(' ');
    saveEntityDetails(session[:selected_product], session[:selected_product_item], selected.sort)
  end    
  render(:text => :OK)
end

#product_addObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/controllers/pbbase_controller.rb', line 28

def product_add
  name = params['name']
  unless (name == nil) then
    name.strip!()
    name.capitalize!()
    addProduct(name)
    session[:selected_product] = name
    session[:selected_product_item] = nil
  end
  redirect_to(:action => 'products')
end

#product_cloneObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/controllers/pbbase_controller.rb', line 40

def product_clone
  existingName = session[:selected_product]
  clonedName = params['clonedName']
  unless ((existingName == nil) || (clonedName == nil) || (clonedName.empty?())) then
    clonedName.strip!()
    clonedName = Inflector.camelize(clonedName)
    cloneProduct(existingName, clonedName)
    session[:selected_product] = clonedName
    session[:selected_product_item] = nil
  end
  redirect_to(:action => 'products')
end

#product_deleteObject



53
54
55
56
57
58
59
60
61
# File 'lib/controllers/pbbase_controller.rb', line 53

def product_delete
  name = session[:selected_product]
  unless (name == nil) then
    deleteProduct(name)
    session[:selected_product] = nil
    session[:selected_product_item] = nil
  end
  redirect_to(:action => 'products')
end

#productsObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/controllers/pbbase_controller.rb', line 10

def products
  product = params['product']
  if (product != nil) then
    if (!product?(product)) then
      session[:selected_product] = nil
      session[:selected_product_item] = nil
    else
      session[:selected_product] = product
      session[:selected_product_item] = nil
    end
  end
  entity = params['entity']
  if (entity != nil) then
    session[:selected_product_item] = entity
  end
  render(:template => "pb/products", :layout => 'products')
end

#test_driveObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/controllers/pbbase_controller.rb', line 116

def test_drive
  # extract data from incoming params
  lang = params['lang']
  brand = params['brand']
  product = params['product']
  # the following config could be externalised if required
  port = '9000'
  edit = 'true'
  environment = 'development'
  logDir = 'log'
  pidFile = File.join(logDir, 'testdrive.pid')
  logFile = File.join(logDir, 'testdrive.log')
  if (File.exist?(logFile)) then
    FileUtils.rm(logFile)
  end
  # stop existing mongrel if there is one
  startCmd = "source ~/.bash_profile;mongrel_rails start  --daemonize --port #{port} --environment #{environment} --log #{logFile} --pid #{pidFile}"
  stopCmd = "mongrel_rails stop --pid #{pidFile}"
  restartCmd = "mongrel_rails restart --pid #{pidFile}"
  if (File.exist?(pidFile)) then
    cmd = restartCmd
  else
   cmd = startCmd
  end
  system(cmd)
  sleep(1)
  puts "Executed Mongrel command [#{cmd}] see log file [#{logFile}] for further details\n"
  # send back the url for test driving
  url = "http://127.0.0.1:#{port}/iab/QNBRiskDataCollect?brand=#{brand}&product=#{product}&lang=#{lang}&edit=#{edit}"
  puts "Returned URL for test drive [#{url}]"
  render(:text => url)
end

#update_cardinalityObject



76
77
78
79
80
81
82
83
# File 'lib/controllers/pbbase_controller.rb', line 76

def update_cardinality
  entity = params['entity']
  cardinality = params['cardinality']
  unless ((entity == nil) || (cardinality == nil)) then
    updateEntityCardinality(session[:selected_product], entity, cardinality)
  end
  render(:text => :OK)
end

#update_mandatoryObject



149
150
151
152
# File 'lib/controllers/pbbase_controller.rb', line 149

def update_mandatory
  puts 'PLEASE WRITE ME'
  render(:text => :OK)
end