-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFilter.xxm
168 lines (150 loc) · 4.71 KB
/
Filter.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
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
[[@Windows,txDefs,DataLank,txSession,txFilter,txFilterSql,txCache,]][[!var
fv:TtxFilterViewInfo;
fs:UTF8String;
f:TtxFilter;
fq:TtxSqlQueryFragments;
id,pid,i:integer;
qr:TQueryResult;
c:cardinal;
tc1,tc2,tc3,tc4:TTimerIndex;
InControl:boolean;
ObjLocationCache:TItemCache;
const
FlushEveryX=25;
]][[
GetFilterViewInfo(Context,fv);
if fv.filter='' then
begin
Context.Include('dHead.xxmi',['Filter']);
<<p class="information">No current filter.<br /><a href="FilterBuild.xxm">Click here</a> to create a filter.</p>
<p class="midnav">stored filters</p>>
id:=Session.UserID;
while (id>0) and Context.Connected do
begin
qr:=TQueryResult.Create(Session.DbCon,'SELECT Obj.id, Obj.pid, Obj.rlm_id, Obj.name, ObjType.icon, ObjType.name AS typename FROM Obj INNER JOIN ObjType ON ObjType.id=Obj.objtype_id WHERE Obj.id=?',[id]);
try
pid:=qr.GetInt('pid');
InControl:=true;
try
Session.HasRealmPermission(id,qr.GetInt('rlm_id'),rpEdit);
except
on ERealmNotEditableByUser do InControl:=false;
end;
<<p><a href="Item.xxm?x=i[[.id]]" title="[[.typename]]">>#txImg(qr.GetInt('icon'))]] [[.name<</a></p>>
finally
qr.Free;
end;
qr:=TQueryResult.Create(Session.DbCon,'SELECT * FROM Flt WHERE Flt.obj_id=? ORDER BY Flt.name, Flt.c_ts',[id]);
try
if qr.EOF then
begin
<<p><i>none</i></p>>
end
else
while qr.Read and Context.Connected do
Context.Include('dFilter.xxmi',[InControl],[qr]);
finally
qr.Free;
end;
id:=pid;
end;
if Session.FilterCache.Count<>0 then
begin
<<p class="midnav">recent filters</p>>
for i:=0 to Session.FilterCache.Count-1 do Context.Include('dFilter.xxmi',[i,Session.FilterCache[i]]);
end;
end
else
begin
Context.Include('dHead.xxmi',['Filter: '+fv.filter,'filter='+fv.filterU]);
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 class="linkbutton" href="FilterBuild.xxm?filter=[[#fv.filterU]]">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>>
if Use_Journals and (Length(Session.Journals)<>0) then
begin
]] <a class="linkbutton" href="Journal.xxm?filter=[[#fv.filterU]]">journal...</a>>
end;
]] <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;
fq.AddFilter(f);
fq.Where:='Obj.rlm_id'+Session.Realms[fv.rp].SQL+' AND ('+fq.Where+')';
fs:=fq.SQL;
finally
f.Free;
fq.Free;
end;
tc3:=GetTimerIndex;
<<span class="weight">build: [[=GetTimerDeltaMS(tc2,tc3)]]ms</span>>
Context.Flush;
c:=0;
qr:=TQueryResult.Create(Session.DbCon,fs,[]);
ObjLocationCache:=TItemCache.Create;
try
tc4:=GetTimerIndex;
//recordcount is -1 on adOpenForwardOnly
<<span class="weight">query: [[=GetTimerDeltaMS(tc3,tc4)]]ms</span>
</p>>
while qr.Read and Context.Connected do
begin
inc(c);
Context.Include('dObjList.xxmi',[],[qr,ObjLocationCache]);
if (c mod FlushEveryX)=0 then Context.Flush;
end;
finally
qr.Free;
ObjLocationCache.Free;
end;
<<script><!--
$("#filterCount").html("[[=c]] objects found");
//--></script>>
Context.Flush;
//if (c=0) and (rpFilter<>rpAny) then
if (c=0) and (fv.view='') then
begin
f:=TtxFilter.Create;
fq:=TtxSqlQueryFragments.Create(itObj);
try
f.FilterExpression:=fv.filter;
fq.AddFilter(f);
fq.Where:='Obj.rlm_id'+Session.Realms[rpAny].SQL+' AND ('+fq.Where+')';
fq.OrderBy:='';
fq.Limit:=1;
fs:=fq.SQL;
finally
f.Free;
fq.Free;
end;
if DBExists(fs,[]) then
begin
<<p class="information">
No items found in your current viewable realms.
<a href="Filter.xxm?filter=[[#fv.filterU]]&view=any">Click here</a>
to search both viewable or editable realms.
</p>>
end;
end;
end;
Context.Include('dFoot.xxmi');