-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcept_find.coffee
289 lines (258 loc) · 9.76 KB
/
concept_find.coffee
1
2
3
4
5
6
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
51
52
53
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
conceptBuilder = (json, name) ->
switch json.dataType
when "DvQuantity"
new DvQuantity(json, name)
when "DV_CODED_TEXT"
new DvCodedText(json, name)
when "DV_BOOLEAN"
new DvBoolean(json, name)
when "DV_TEXT"
new DvText(json, name)
when "DV_COUNT"
new DvCount(json, name)
when "DvOrdinal"
new DvOrdinal(json, name)
when "DV_MULTIMEDIA"
new DvMultiMedia(json, name)
when "DV_DATE_TIME"
new DvDateTime(json, name)
when "DV_INTERVAL"
new DvInterval(json, name)
when "DV_PROPORTION"
new DvProportion(json, name)
when "DV_URI"
new DvUri(json, name)
when "DvMultipleElements"
new DvMultipleElements(json, name)
when "DvCluster"
new DvCluster(json, name)
else
new DvAny(json, name)
class Concept
constructor: (json, adlName) ->
@name = json.name
@adlName = adlName
@path = @adlName + "." + json.path.replace(/\./g, "___")
@type = json.dataType
# <input type="text" value="@value" aqbe:path="@path" />
inputBuilder: (placeholder="") ->
$("<input>").attr("type", "text").attr("value", "").attr("aqbe:path", @path).attr("aqbe:type", @type).attr("placeholder", placeholder)
# <input type="text" value="@value" aqbe:path="@path" id="fieldDate" />
calenderBuilder: () ->
@inputBuilder().attr("id", "fieldDate")
# <select aqbe:path="@path"><option value="">Please Select</option></select>
selectBuilder: (path=@path, type=@type, require=false) ->
selecter = $("<select>").attr("aqbe:path", path).attr("aqbe:type", type)
if require
selecter
else
selecter.append("""<option value="">Please Select</option>""")
# = != > < <= >= のセレクトボックス
conditionBuilder: (type="text") ->
selecter = $("<select>").attr("class", "condition")
selecter.append("""<option value="0">=</option>""")
selecter.append("""<option value="1">!=</option>""")
selecter.append("""<option value="2">></option>""") if type is "number" # >
selecter.append("""<option value="3"><</option>""") if type is "number" # <
selecter.append("""<option value="4">>=</option>""") if type is "number" # >=
selecter.append("""<option value="5"><=</option>""") if type is "number" # <=
selecter
submitBuilder: () ->
submitter = $("<input>").attr("type", "button").attr("class", "submit btn").val("add")
submitter.click ->
submit(submitter)
submitter
getHtml: (adlName) ->
$("#pathList").append("#{@path},#{@name}\n")
$("<tr>").append($("<td>").append($("<input>").attr("type","checkbox").attr("aqbe:path",@path).attr("class","selection")).append($("<span>").append(@name)))
class DvQuantity extends Concept
constructor: (json, name) ->
super json, name
@path = @path + "/magnitude"
@unitPath = @path.replace("/magnitude", "/units")
@min = if json.min[0]? then json.min else [-999999]
@max = if json.max[0]? then json.max else [999999]
@unit = json.unit
getHtml: ->
input = @inputBuilder("0.0").attr("aqbe:min", @min[0]).attr("aqbe:max", @max[0])
unitSelecter = @selectBuilder(path=@unitPath, type="DvQuantityUnit", require=true)
for k, v in @unit
unitSelecter.append("<option value=\"#{v}\">#{k}</option>")
unitSelecter.change =>
index = unitSelecter.val()
$(input).attr("aqbe:min", @min[index]).attr("aqbe:max", @max[index])
super.append($("<td>").append(@conditionBuilder("number")).append(" ").append(input).append(" ").append(unitSelecter).append("<span class=\"error\">").append(@submitBuilder()))
class DvCodedText extends Concept
constructor: (json, name) ->
super json, name
@codeList = json.codeList
getHtml: ->
select = @selectBuilder()
for code in @codeList
select.append("<option value=\"#{code}\">#{code}</option>")
super.append($("<td>").append(@conditionBuilder()).append(select).append(@submitBuilder()))
class DvBoolean extends Concept
constructor: (json, name) ->
super json, name
getHtml: ->
super.append($("<td>").append(@selectBuilder().append("""<option value="true">true</option>""").append("""<option value="false">false</option>""")).append(@submitBuilder()))
class DvText extends Concept
constructor: (json, name) ->
super json, name
getHtml: ->
super.append($("<td>").append(@conditionBuilder()).append(" ").append(@inputBuilder("FreeText")).append(@submitBuilder()))
class DvCount extends Concept
constructor: (json, name) ->
super json, name
@min = if json.min? then json.min else -999999
@max = if json.max? then json.max else 999999
getHtml: ->
super.append($("<td>").append(@conditionBuilder("number")).append(" ").append(@inputBuilder("0").attr("aqbe:min", @min).attr("aqbe:max", @max)).append("<span class=\"error\">").append(@submitBuilder()))
class DvOrdinal extends Concept
constructor: (json, name) ->
super json, name
@codeList = json.codeList
getHtml: ->
select = @selectBuilder()
for c in @codeList
select.append("<option value=\"#{c._1}\">#{c._2}</option>")
super.append($("<td>").append(@conditionBuilder()).append(select).append(@submitBuilder()))
class DvMultiMedia extends Concept
constructor: (json, name) ->
super json, name
@codeList = json.codeList
getHtml: ->
select = @selectBuilder()
for c in @codeList
select.append("<option value=\"#{c}\">#{c}</option>")
super.append($("<td>").append(@conditionBuilder()).append(select).append(@submitBuilder()))
class DvDateTime extends Concept
constructor: (json, name) ->
super json, name
getHtml: ->
super.append($("<td>").append(@conditionBuilder("number")).append(" ").append(@calenderBuilder("Date Time")).append("""<input type="hidden" value="" aqbe:type="DvDateTimeInteger" aqbe:path=""" + @path + """ />""").append(@submitBuilder()))
class DvInterval extends Concept
constructor: (json, name) ->
super json, name
@interval = json.interval
getHtml: ->
newTable = $("<table>").attr("class", "adl2 table table-bordered")
for c in @interval
cc = conceptBuilder(c, @adlName)
newTable.append(cc.getHtml())
super.append($("<td>").append(newTable))
class DvProportion extends Concept
constructor: (json, name) ->
super json, name
@minNum = json.minNum
@maxNum = json.maxNum
@minDen = json.minDen
@maxDen = json.maxDen
getHtml: ->
@min = @minNum
@max = @maxNum
num = @inputBuilder("0")
@min = @minDen
@max = @maxNum
den = @inputBuilder("0")
super.append($("<td>").append(@conceptBuilder("number")).append(" ").append(num).append(" : ").appedn(den).append(@submitBuilder()))
class DvUri extends Concept
constructor: (json, name) ->
super json, name
getHtml: ->
super.append($("<td>").append(@conceptBuilder()).append(" ").append(@inputBuilder("input", "url").attr("placeholder", "URL")).append(@submitBuilder()))
class DvAny extends Concept
constructor: (json, name) ->
super json, name
getHtml: ->
super.append($("<td>").append("""<span class="any">[Any]<span>"""))
class DvCluster extends Concept
constructor: (json, name) ->
super json, name
@cluster = json.cluster
getHtml: ->
newTable = $("<table>").attr("class", "adl2 table table-bordered")
for c in @cluster
cc = conceptBuilder(c, @adlName)
newTable.append(cc.getHtml())
super.append($("<td>").append(newTable))
class DvMultipleElements extends Concept
constructor: (json, name) ->
super json, name
@elements = json.elements
getHtml: ->
newTable = $("<table>").attr("class", "adl2 table table-bordered")
for c in @elements
cc = conceptBuilder(c._2, @adlName)
super.append($("<td>").append(newTable))
newTable.append(cc.getHtml())
submit = (obj) ->
parent = $(obj).parent("td") # 親要素の取得
# validation
unless parent.find("span").text() is ""
alert "Error"
return
input = parent.find("input, select") # 各種inputの取得
name = parent.prev("td").find("span").text() # nameの取得
empty = ""
for i in input
unless $(i).attr("class") is "submit btn" or $(i).attr("class") is "remover btn btn-mini"
if $(i).attr("class") is "condition"
condition = $(i).val()
else
unless path?
path = $(i).attr("aqbe:path")
else
path = path
type = $(i).attr("aqbe:type")
if type is "DvQuantityUnit"
unit = $(i).val()
unitStr = $(i).children(":selected").text()
pathUnit = $(i).attr("aqbe:path")
else if type is "DV_DATE_TIME"
calStr = $(i).val()
else
value = $(i).val()
$(i).val("")
# empty value
if value is ""
alert "empty!"
return
# condition to conditonString
conStr = con2str(condition)
# make string
if name is "" then name = path.replace("$","")
str = "#{name},#{path},#{condition},#{conStr},#{value},#{unit},#{unitStr},#{pathUnit},#{calStr}"
# display
remover = $("<input>").attr("type","button").attr("class", "remover btn btn-mini").val("x")
remover.click ->
remover.parent("p").remove()
text = $("#stack").text()
$("#stack").empty()
flag = true
for x in text.split("\n")
if x is str and flag
flag = false
else
$("#stack").append("#{x}\n")
$(obj).parent("td").append($("<p>").text("#{conStr} #{(if calStr? then calStr else value)} #{(if unitStr? then unitStr else empty)}").append(remover))
# stack data
# name, path, condition, condition string, value, unit, unit string, calendar string \n
$("#stack").append("#{str}\n")
con2str = (condition) ->
switch parseInt(condition)
when 0
conStr = "="
when 1
conStr = "!="
when 2
conStr = ">"
when 3
conStr = "<"
when 4
conStr = ">="
when 5
conStr = "<="
else
conStr = "="
conStr