Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7291 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
'   view_by_files_json.asp
5
'   
6
'   Provide dataTable information for pages that search for files
7
'   1) Global (no rtagId)
8
'   2) Within a Release (With rtagId and envtab)
9
'=====================================================
10
%>
11
<%
12
Option explicit
13
' Some searches may take a while
14
Server.ScriptTimeout=400
15
' Essential to get UTF through all the hoops. ie: VÄSTTRAFIK (VTK)
16
Response.ContentType = "text/html"
17
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
18
Response.CodePage = 65001
19
Response.CharSet = "UTF-8"
20
%>
21
<!--#include file="common/conf.asp"-->
22
<!--#include file="common/globals.asp"-->
23
<!--#include file="common/qstr.asp"-->
24
<!--#include file="common/common_subs.asp"-->
25
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
26
<%
27
'------------ Variable Definition -------------
28
Dim result : result = -1
29
Dim joiner
30
Dim SqlQry
31
Dim rsQry
32
 
33
Dim parRtagId, parEnvTab, parEnvTable
34
parRtagId = Request("rtag_id")
35
 
36
Dim parFileName
37
parFileName = Request.Form("columns[1][search][value]")
38
If parFileName = "" Then
39
    parFileName = Request("filename")
40
End If
41
 
42
' Calculate the table to be used when limiting search to a EnvTab
43
If parRtagId <> "" Then
44
    parEnvTab = Request("envtab")
45
 
46
	Select Case parEnvTab
47
        Case "0"  : parEnvTable = "work_in_progress"  
48
	    Case "1"  : parEnvTable = "planned"
49
	    Case "3"  : parEnvTable = "environment_view"
50
	    Case Else : parEnvTable = "release_content"
51
    End Select
52
End If
53
 
54
' Init the output JSON class
55
'   Operations can add data
56
'   Default data will be added at the end
57
Dim oJSON :Set oJSON = New aspJSON
58
Dim newitem
59
 
60
'On Error Resume Next
61
'
62
' Assist in debug
63
oJSON.data("start") = CLng(Request.Form("start"))
64
oJSON.data("length") = CLng(Request.Form("length"))
65
 
66
'Dim vName
67
'for each vName in Request.QueryString
68
'    oJSON.data("sReq_" & vName) = Request(vName)
69
'next
70
'For Each vName In Request.Form
71
'    oJSON.data("sFrm_" & vName) = Request(vName)
72
'Next
73
 
74
' Extract selected range
75
result = 0
76
dim firstRow,lastRow,noBuildTime
77
firstRow = CLng(Request.Form("start"))
78
lastRow = firstRow + CLng(Request.Form("length"))
79
 
80
'   Define array of colums to sort by
81
'       Must match user sort column request
82
Dim sortCols: sortCols = Array ( _
83
        "pv.pv_id", _
84
        "UPPER(art.file_name)",_
85
        "UPPER(art.file_path)",_
86
        "UPPER(pkg.pkg_name)",_
87
        "UPPER(pv.pkg_version)",_
88
        "UPPER(art.crc_cksum)" )
89
 
90
' Dim determine sorting options
91
'On Error goto 0
92
'Response.Write "<pre>"
93
 
94
Dim sortString
95
Dim sortJoin : sortJoin = " ORDER BY "
96
If Request.Form("order[0][column]") <> "" Then
97
 
98
    Dim sortCol : sortCol = CInt(Request.Form("order[0][column]"))
99
    Dim sortDir : sortDir = " " & Request.Form("order[0][dir]")
100
 
101
    sortString = sortJoin & sortCols(sortCol)
102
    sortString = sortString & sortDir
103
    sortJoin = ","
104
 
105
Else
106
    sortString = sortJoin & sortCols(CInt(1)) & " asc"
107
End If
108
 
109
' Filter (search )
110
' Support multicolumn filters
111
'
112
Dim searchString : searchString = ""
113
Dim maxCols  :maxCols = 5 ' 0 .. maxCols
114
Dim colIdx, colData
115
For colIdx = 0 to maxCols
116
    colData = Request.Form("columns["&colIdx&"][search][value]")
117
	If colData <> "" Then
118
		searchString = searchString + " AND " + sortCols(colIdx) + " LIKE UPPER('" + colData + "')" 
119
    End If
120
Next
121
If searchString = "" Then
122
    searchString = "AND UPPER (art.file_name) LIKE UPPER ('"&parFileName&"') "
123
End If
124
 
125
Dim BasicSql, FromSql, WhereSql
126
 
127
FromSql =   " FROM RELEASE_COMPONENTS art, " &_
128
            "  packages pkg, " &_
129
            "  PACKAGE_VERSIONS pv "
130
If parRtagId <> "" Then
131
    FromSql = FromSql & "," & parEnvTable & " rc "
132
End If
133
 
134
WhereSql =  " WHERE pv.PKG_ID  = pkg.PKG_ID " &_
135
			" AND art.pv_id = pv.pv_id " &_
136
			" AND art.file_name is not null "
137
 
138
If parRtagId <> "" Then
139
    WhereSql = WhereSql & " AND rc.rtag_id = "& parRtagId &" AND art.pv_id = rc.pv_id "
140
End If
141
 
142
BasicSql =  "SELECT pv.pv_id, "&_
143
            " art.file_name, " &_
144
            "  art.file_path, " &_
145
            "  pkg.pkg_name, " &_
146
            "  pv.pkg_version, " &_
147
            "  art.crc_cksum " &_
148
            FromSql &_
149
            WhereSql &_
150
            searchString &_
151
            sortString
152
 
153
SqlQry = "select * from ( "&_
154
            "select a.*, ROWNUM rnum from (" & BasicSql &_
155
                ") a where ROWNUM <= " & lastRow &_
156
            ") where rnum >= " & firstRow
157
 
158
 ' Assist in debug
159
oJSON.data("BasicSql") = BasicSql
160
oJSON.data("SqlQry") = SqlQry
161
 
162
' First query is to determine the overall size of the dataset
163
'
164
Dim SizeSql
165
Dim MaxCount : MaxCount = 0
166
 
167
SizeSql = "select count(*) as count " & FromSql  & WhereSql & searchString
168
oJSON.data("iSql") = SizeSql
169
 
170
objEH.ErrorRedirect = FALSE
171
objEH.TryORA ( OraSession )
172
Set rsQry = OraDatabase.DbCreateDynaset( SizeSql, ORADYN_DEFAULT )
173
objEH.CatchORA ( OraSession )
174
    If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
175
        MaxCount = rsQry("COUNT")
176
    End If
177
rsQry.Close
178
Set rsQry = Nothing
179
 
180
' Basic Header
181
'   recordsTotal = total records without any filtering/limits
182
'   recordsFiltered = filtered result count
183
 
184
oJSON.data("draw") = CLng(Request.Form("draw"))
185
oJSON.data("recordsTotal") = CLng(MaxCount)
186
oJSON.data("recordsFiltered") = CLng(MaxCount)
187
 
188
' Perform the full database query with pagination support
189
Set oJSON.data("data") = oJSON.Collection()
190
'On Error Resume Next
191
objEH.ErrorRedirect = FALSE
192
objEH.TryORA ( OraSession )
193
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
194
objEH.CatchORA ( OraSession )
195
' Process each row and return required fields to the user
196
If objEH.Finally Then
197
    While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
198
        Set newitem = oJSON.AddToCollection(oJSON.data("data"))
199
 
200
        ' Attempt to speed up access tot he data
201
        '    Extract all fields for the row
202
        '    Access fields by index
203
        Dim fields
204
        Set fields = rsQry.Fields
205
 
206
        newitem(0) = fields(0)      '   pvId      
207
        newitem(1) = fields(1)  	'   fileName  
208
        newitem(2) = fields(2)  	'   filePath  
209
        newitem(3) = fields(3)  	'   pkgName   
210
        newitem(4) = fields(4)  	'   pkgVersion
211
        newitem(5) = fields(5)  	'   chkSum    
212
 
213
        Set fields = nothing
214
        rsQry.MoveNext
215
    Wend
216
End IF
217
 
218
rsQry.Close
219
Set rsQry = Nothing
220
 
221
'
222
' SQL error detection and reporting
223
If objEH.LastOraFailed Then
224
    oJSON.data("error") = 1
225
 
226
    oJSON.data("emsgSummary") = objEH.MessageSummary
227
    oJSON.data("emsgDetails") = objEH.MessageDetails
228
    oJSON.data("SqlQry") = SqlQry
229
End If
230
 
231
'Return the object
232
Response.Write oJSON.JSONoutput()
233
 
234
' Cleanup
235
Set oJSON = Nothing
236
Call Destroy_All_Objects
237
 %>