/
FilterCount.xxm
131 lines (126 loc) · 3.84 KB
/
FilterCount.xxm
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
[[@Windows,txDefs,DataLank,txSession,txFilter,txFilterSql,]][[!var
fv:TtxFilterViewInfo;
fs:UTF8String;
f:TtxFilter;
fq:TtxSqlQueryFragments;
i,j:integer;
qr:TQueryResult;
tc1,tc2,tc3,tc4:TTimerIndex;
realms:boolean;
]][[
GetFilterViewInfo(Context,fv);
Context.Include('dHead.xxmi',['Filter Count','filter='+fv.filterU]);
realms:=Context['realms'].AsInteger=1;
if (fv.filter='') and not(realms) then
begin
<<p class="information">No current filter.<br /><a href="FilterBuild.xxm">Click here</a> to create a filter.</p>>
end
else
begin
f:=TtxFilter.Create;
fq:=TtxSqlQueryFragments.Create(itObj);
try
tc1:=GetTimerIndex;
f.FilterExpression:=fv.filter;
if f.ParseError='' then
begin
i:=Session.FilterCache.IndexOf(string(fv.filter));
if i>0 then Session.FilterCache.Delete(i);
if i<>0 then Session.FilterCache.Insert(0,string(fv.filter));
end
else
begin
<<p style="color:red;">>=f.ParseError<</p>>
end;
tc2:=GetTimerIndex;
<<p class="buttons">
<a href="Filter.xxm?filter=[[#fv.filterU]]" class="linkbutton">filter...</a>
|
<a href="FilterBuild.xxm?filter=[[#fv.filterU]]" class="linkbutton">edit filter</a>
<a class="linkbutton" href="FrameTree.xxm?filter=[[#fv.filterU]]" target="TreeFrame">tree</a>
<a class="linkbutton" href="FrameList.xxm?filter=[[#fv.filterU]]" target="TreeFrame">list</a>
|
<a class="linkbutton" href="Log.xxm?filter=[[#fv.filterU]]">log...</a>
<a class="linkbutton" href="Summary.xxm?filter=[[#fv.filterU]]">summary...</a>
<a class="linkbutton" href="Modify.xxm?filter=[[#fv.filterU]]">modify...</a>
</p>
<p>
<span id="filterCount">>#lblLoading<</span>
<span class="weight">parse: [[=GetTimerDeltaMS(tc1,tc2)]]ms</span>>
Context.Flush;
if realms then
begin
if not Session.IsAdmin('realms') then raise Exception.Create('Access denied');//?
fq.Fields:='Rlm.id,Rlm.name,COUNT(Obj.id) AS ocount';
fq.Tables:='Obj INNER JOIN ObjType ON ObjType.id=Obj.objtype_id LEFT OUTER JOIN Rlm ON Rlm.id=Obj.rlm_id'#13#10;
fq.AddFilter(f);
fq.GroupBy:='Rlm.id,Rlm.name';
fq.OrderBy:='Rlm.id';
end
else
begin
fq.Fields:='COUNT(*)';
fq.Tables:='Obj INNER JOIN ObjType ON ObjType.id=Obj.objtype_id'#13#10;
fq.AddFilter(f);
fq.Where:='Obj.rlm_id'+Session.Realms[fv.rp].SQL+' AND ('+fq.Where+')';
fq.OrderBy:='';
end;
fs:=fq.SQL;
finally
f.Free;
fq.Free;
end;
tc3:=GetTimerIndex;
<<span class="weight">build: [[=GetTimerDeltaMS(tc2,tc3)]]ms</span>>
Context.Flush;
qr:=TQueryResult.Create(Session.DbCon,fs,[]);
try
tc4:=GetTimerIndex;
<<span class="weight">query: [[=GetTimerDeltaMS(tc3,tc4)]]ms</span>
</p>>
if realms then
begin
<<table cellspacing="2" cellpadding="2" border="0" class="listtable">
<tr>
<th colspan="2">realm</th>
<th>#</th>
</tr>>
j:=0;
while qr.Read and Context.Connected do
begin
i:=qr.GetInt('ocount');
inc(j,i);
<<tr>>
if qr.IsNull('id') then
begin
<<td><b>default</b></td><td>#0</td>>
end
else
begin
<<td>>.name<</td><td>#[[.id]]</td>>
end;
<<td style="text-align:right;">>=i<</td>
</tr>>
end;
<<tr>
<th colspan="2"> </th>
<th style="text-align:right;">>=j<</th>
</tr>
</table>>
end
else
begin
<<p style="font-size:100pt;margin:4pt;font-weight:bold;">>=qr.GetInt(0)<</p>>
if Session.IsAdmin('realms') then
begin
<<p><a href="FilterCount.xxm?[[=Context.ContextString(csQueryString)]]&realms=1" class="linkbutton">realms...</a></p>>
end;
end;
finally
qr.Free;
end;
end;
<<script><!--
$("#filterCount").remove();
//--></script>>
Context.Include('dFoot.xxmi');