smartclient 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/DSRequest.rb +39 -0
- data/lib/DSResponse.rb +28 -0
- data/lib/DataSource.rb +103 -0
- metadata +4 -1
data/lib/DSRequest.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'DataSource'
|
2
|
+
class DSRequest
|
3
|
+
attr_accessor :dataSource, :operationType, :startRow, :endRow, :textMatchStyle, :data, :sortBy, :oldValues
|
4
|
+
|
5
|
+
@dataSource = nil
|
6
|
+
@operationType = nil
|
7
|
+
@startRow = nil
|
8
|
+
@endRow = nil
|
9
|
+
@textMatchStyle = nil
|
10
|
+
@componentId = nil
|
11
|
+
@data = nil
|
12
|
+
@sortBy = nil
|
13
|
+
@oldValues = nil
|
14
|
+
|
15
|
+
@@obj = nil
|
16
|
+
def initialize(data, model)
|
17
|
+
@componentId = data[:componentId]
|
18
|
+
@dataSource = data[:dataSource]
|
19
|
+
@operationType = data[:operationType]
|
20
|
+
@startRow = data[:startRow]
|
21
|
+
@endRow = data[:endRow]
|
22
|
+
@textMatchStyle = data[:textMatchStyle]
|
23
|
+
@data = data[:data]
|
24
|
+
@sortBy = data[:sortBy]
|
25
|
+
@oldValues = data[:oldValues]
|
26
|
+
|
27
|
+
@@obj = model
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute
|
31
|
+
ds = DataSource.new(@dataSource, @@obj)
|
32
|
+
if ds.nil?
|
33
|
+
return nil
|
34
|
+
else
|
35
|
+
return ds.execute(self)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
data/lib/DSResponse.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class DSResponse
|
2
|
+
@data = nil
|
3
|
+
@startRow = 0
|
4
|
+
@endRow = 0
|
5
|
+
@totalRow = 0
|
6
|
+
@status = -1
|
7
|
+
|
8
|
+
def data=(value)
|
9
|
+
@data = value
|
10
|
+
end
|
11
|
+
|
12
|
+
def startRow=(value)
|
13
|
+
@startRow = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def endRow=(value)
|
17
|
+
@endtRow = value
|
18
|
+
end
|
19
|
+
|
20
|
+
def totalRow=(value)
|
21
|
+
@totalRow = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def status=(value)
|
25
|
+
@status = value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/lib/DataSource.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
class DataSource
|
2
|
+
attr_accessor :data_source
|
3
|
+
@data_source = nil
|
4
|
+
@model = nil
|
5
|
+
def initialize(path, model)
|
6
|
+
#@data_source = self.get_data(path)
|
7
|
+
@model = model
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_data(path)
|
11
|
+
ds_content = File.read(path)
|
12
|
+
#remove the isc tag and the end tag
|
13
|
+
ds_content['isc.RestDataSource.create('] = ''
|
14
|
+
ds_content[');'] = ''
|
15
|
+
#remove tab, newline tag \n \r \t etc
|
16
|
+
result = ds_content.gsub('/\r|\n|\t|>>|\/\//', '')
|
17
|
+
return JSON.parse(result)
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_field(field_name)
|
21
|
+
fields = @data_source['fields']
|
22
|
+
|
23
|
+
fields.each do | f |
|
24
|
+
if f['name'] == filed_name
|
25
|
+
return f
|
26
|
+
end
|
27
|
+
end
|
28
|
+
return nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def execute(request)
|
32
|
+
operation_type = request.operationType
|
33
|
+
case operation_type
|
34
|
+
when 'fetch'
|
35
|
+
@result = fetch(request)
|
36
|
+
when 'add'
|
37
|
+
@result = add(request)
|
38
|
+
when 'remove'
|
39
|
+
@result = remove(request)
|
40
|
+
when 'update'
|
41
|
+
@result = update(request)
|
42
|
+
end
|
43
|
+
return @result
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
def fetch(request)
|
48
|
+
unless request.data.empty?
|
49
|
+
@obj_items = @model.filter(request)
|
50
|
+
else
|
51
|
+
# get all supplyitems from the database
|
52
|
+
@obj_items = @model.find(:all)
|
53
|
+
end
|
54
|
+
|
55
|
+
objs_count = @obj_items.count
|
56
|
+
# get the count of the obj_items
|
57
|
+
endRow = (objs_count > 0)?objs_count - 1 : objs_count
|
58
|
+
response = DSResponse.new
|
59
|
+
response.data = @obj_items
|
60
|
+
response.startRow = 0
|
61
|
+
response.endRow = endRow
|
62
|
+
response.status = 0
|
63
|
+
response.totalRow = objs_count
|
64
|
+
|
65
|
+
@result = { :response => response }
|
66
|
+
return @result
|
67
|
+
end
|
68
|
+
|
69
|
+
def add(request)
|
70
|
+
new_data = request.data
|
71
|
+
new_supplyitem = @model.create(new_data)
|
72
|
+
response = DSResponse.new
|
73
|
+
response.data = new_data
|
74
|
+
response.status = 0
|
75
|
+
@result = { :response => response }
|
76
|
+
return @result
|
77
|
+
end
|
78
|
+
|
79
|
+
def remove(request)
|
80
|
+
data = request.data
|
81
|
+
item_id = data['itemID']
|
82
|
+
@model.destroy(item_id)
|
83
|
+
response = DSResponse.new
|
84
|
+
response.data = data
|
85
|
+
response.status = 0
|
86
|
+
@result = { :response => response }
|
87
|
+
return @result
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def update(request)
|
92
|
+
old_data = request.oldValues
|
93
|
+
update_data = request.data
|
94
|
+
item_id = update_data['itemID']
|
95
|
+
|
96
|
+
merged_data = old_data.merge!(update_data)
|
97
|
+
merged_data.delete('itemID')
|
98
|
+
|
99
|
+
#update
|
100
|
+
@model.update(item_id, merged_data)
|
101
|
+
return nil
|
102
|
+
end
|
103
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,6 +18,9 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/RPCManager.rb
|
21
|
+
- lib/DSRequest.rb
|
22
|
+
- lib/DSResponse.rb
|
23
|
+
- lib/DataSource.rb
|
21
24
|
homepage: https://isomorphic.atlassian.net
|
22
25
|
licenses: []
|
23
26
|
post_install_message:
|