-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasset_history_wdg.py_prep_Python
More file actions
487 lines (368 loc) · 16.1 KB
/
asset_history_wdg.py_prep_Python
File metadata and controls
487 lines (368 loc) · 16.1 KB
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
###########################################################
#
# Copyright (c) 2005, Southpaw Technology
# All Rights Reserved
#
# PROPRIETARY INFORMATION. This software is proprietary to
# Southpaw Technology, and is not to be reproduced, transmitted,
# or disclosed in any way without written permission.
#
#
#
# TODO: this class is poorly named. It should be AssetHistoryLoadWdg
__all__ = ['AssetHistoryWdg', 'ShotHistoryWdg', 'InstanceHistoryWdg', 'LayerHistoryWdg']
from pyasm.search import Search
from pyasm.web import *
from pyasm.widget import *
from pyasm.prod.biz import *
from pyasm.biz import *
from pyasm.common import Common
from asset_loader_wdg import *
from tactic.ui.common import BaseRefreshWdg
class AssetHistoryWdg(BaseRefreshWdg):
'''history that includes the loader'''
CB_NAME = 'load_snapshot'
def init(my):
my.parent_key = my.kwargs.get("search_key")
if not my.parent_key:
my.parent_key = WebContainer.get_web().get_form_value('search_key')
my.parent = Search.get_by_search_key(my.parent_key)
my.search_type = my.parent.get_search_type()
my.base_search_type = Project.extract_base_search_type(my.search_type)
my.search_id = my.parent.get_id()
my.asset_search_type = my.kwargs.get('asset_search_type')
def _get_value(my, sobject, snapshot):
loader = AssetLoaderWdg(parent_key=my.parent_key)
value = loader.get_input_value(sobject, snapshot)
return value
def get_default_versions_filter(my):
return "last 10"
def get_snapshot_search(my):
search = Search(Snapshot.SEARCH_TYPE)
search.add_filter("search_type", my.search_type)
search.add_filter("search_id", my.search_id)
return search
def get_snapshot_contexts(my, search_type, search_id):
'''get the contexts for the snapshots'''
return Snapshot.get_contexts(search_type, search_id)
def get_master_checkbox(my, select):
'''turn them all off first, then turn on the one for the selected context'''
master = SpanWdg(css='med')
master.add_color("color", "color")
cb_name = '%s_%s' %(my.base_search_type, my.CB_NAME)
value = select.get_value()
if value:
master_cb = CheckboxWdg('master_control', label='Toggle all current [%s]' %value)
master_cb.add_behavior({'type': 'click_up',
'propagate_evt': True,
'cbjs_action': '''
var context_sel = bvr.src_el.getParent('.spt_history_wdg').getElement('.spt_context_select')
var filter = '.spt_history_' + context_sel.value;
var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_table'),'%s','.spt_history');
for (var i = 0; i < inputs.length; i++)
inputs[i].checked = false;
var inputs = spt.api.Utility.get_inputs(bvr.src_el.getParent('.spt_table'),'%s', filter);
for (var i = 0; i < inputs.length; i++)
inputs[i].checked = bvr.src_el.checked;
''' %(cb_name, cb_name)})
master.add(master_cb)
return master
def get_display(my):
web = WebContainer.get_web()
args = web.get_form_args()
if not my.search_type:
my.search_type = args.get('search_type')
if not my.search_id:
my.search_id = args.get('search_id')
# get from cgi
if not my.search_type:
my.search_type = web.get_form_value("search_type")
my.search_id = web.get_form_value("search_id")
if not my.asset_search_type:
my.asset_search_type = web.get_form_value('asset_search_type')
context_filter = web.get_form_value("context_%s_%s" % (my.search_type, my.search_id) )
versions_filter = web.get_form_value("versions_%s_%s" % (my.search_type, my.search_id) )
div_id = "history_%s_%s" % (my.search_type, my.search_id)
ajax = AjaxLoader(div_id)
if ajax.is_refresh():
div = Widget()
else:
div = DivWdg()
div.add_color('background','background2')
div.add_class('spt_history_wdg')
div.add_style("display: block")
div.add_style("float: right")
div.add_style("width: 95%")
div.add_style("margin-left: 50px")
div.set_id( div_id )
div.add( my.get_filter_wdg(my.search_type, my.search_id, div_id) )
# get the sobject
sobject = Search.get_by_id(my.search_type, my.search_id)
# get the snapshots
search = my.get_snapshot_search()
if context_filter:
search.add_filter("context", context_filter)
if not versions_filter:
versions_filter = my.get_default_versions_filter()
my.select.set_value(versions_filter)
if versions_filter == 'current':
search.add_filter("is_current", True)
elif versions_filter == 'latest':
search.add_filter("is_latest", True)
elif versions_filter == 'last 10':
search.add_limit(10)
elif versions_filter == 'today':
from pyasm.search import Select
search.add_where(Select.get_interval_where(versions_filter))
elif versions_filter == 'all':
pass
else:
search.add_filter("is_latest", True)
search.add_order_by("timestamp desc")
snapshots = search.do_search()
div.add(my.get_table(sobject,snapshots) )
return div
def get_filter_wdg(my, search_type, search_id, div_id):
filter_wdg = DivWdg()
filter_wdg.add_style("margin-bottom: 5px")
filter_wdg.add_style("text-align: right")
ajax = AjaxLoader()
ajax.set_option("search_key", my.parent_key)
ajax.set_option("search_type", search_type)
if my.asset_search_type:
ajax.set_option("asset_search_type", my.asset_search_type)
ajax.set_option("search_id", search_id)
ajax.add_element_name("context_%s_%s" % (search_type, search_id) )
ajax.add_element_name("versions_%s_%s" % (search_type, search_id) )
# add a shot id
ajax.add_element_name("shot_id")
ajax.set_display_id(div_id)
cls = my.__class__
class_path = '%s.%s' %(cls.__module__, cls.__name__)
ajax.set_load_class( class_path )
refresh_script = ajax.get_refresh_script(show_progress=False)
# add a context selector
select = SelectWdg("context_%s_%s" % (search_type, search_id) )
select.add_class('spt_context_select')
select.add_event("onchange", refresh_script)
# find all of the contexts that have been checked in
contexts = my.get_snapshot_contexts(search_type, search_id)
select.set_option("values", contexts )
select.add_empty_option("-- Select --")
select.set_persist_on_submit()
span = SpanWdg(css="med")
span.add_color("color", "color")
span.add("Context: ")
span.add(select)
# add the fast check checkbox that checks all current for a context
filter_wdg.add(my.get_master_checkbox(select))
filter_wdg.add(span)
# add a versions selector
my.select = SelectWdg("versions_%s_%s" % (search_type, search_id) )
my.select.add_empty_option("-- Select --")
my.select.add_event("onchange", refresh_script)
my.select.set_option("values", "latest|current|today|last 10|all")
my.select.set_persist_on_submit()
span = SpanWdg(css="med")
span.add_color("color", "color")
span.add("Versions: ")
span.add(my.select)
filter_wdg.add(span)
button = IconButtonWdg("Refresh", IconWdg.REFRESH, long=False)
button.add_event("onclick", refresh_script)
filter_wdg.add(button)
return filter_wdg
def get_table(my, sobject, snapshots):
table = Table()
table.add_color("color", "color")
table.set_class("embed")
table.add_style("font-size: 0.9em")
tr = table.add_row()
tr.add_style('text-align: left')
table.add_header(" ")
table.add_header("Code")
table.add_header("Context")
table.add_header("Ver#")
table.add_header("Rev#")
table.add_header("Level")
table.add_header("Icon")
table.add_header("Type")
table.add_header("Dependency")
table.add_header("User")
table.add_header("Time")
table.add_header("Comment")
th = table.add_header("Load")
table.add_header(" ")
th.add_style("text-align: center")
# get the session
session = SessionContents.get()
# add the file type icon
thumb = ThumbWdg()
thumb.set_icon_size(15)
thumb.set_sobjects(snapshots)
count = 0
for snapshot in snapshots:
current = None
tr = table.add_row()
tr.add_color("background", "background2")
tr.add_color("color", "color")
palette = tr.get_palette()
# selection colors
hilite = palette.color("background2", +15)
tr.add_behavior( {
'type': 'hover',
'mod_styles': 'background-color: %s' %hilite,
} )
time_wdg = DateTimeWdg()
time_wdg.set_name("timestamp")
time_wdg.set_sobject(snapshot)
context = snapshot.get_value("context")
version = snapshot.get_value("version")
revision = snapshot.get_value("revision", no_exception=True)
if snapshot.is_current():
current = IconWdg("current", IconWdg.CURRENT)
table.add_cell(current)
else:
table.add_blank_cell()
#render_link = RenderLinkTableElement()
#render_link.set_sobject(snapshot)
#table.add_cell( render_link )
'''
label = snapshot.get_label()
if label:
try:
icon = IconWdg(label, eval('IconWdg.%s' %label.upper()))
except:
icon = HtmlElement.b(label[0].upper())
table.add_cell(icon)
else:
table.add_blank_cell()
'''
table.add_cell( snapshot.get_code() )
table.add_cell( "<b>%s</b>" % context )
table.add_cell( "v%0.3d" % version )
if revision:
table.add_cell( "r%0.3d" % revision )
else:
table.add_cell( "---" )
# add level
level_type = snapshot.get_value("level_type")
level_id = snapshot.get_value("level_id")
if level_type and level_id:
sobject = Search.get_by_id(level_type, level_id)
table.add_cell(sobject.get_code())
else:
table.add_cell("---")
thumb.set_current_index(count)
table.add_cell(thumb.get_display())
count += 1
table.add_cell( snapshot.get_value("snapshot_type") )
dependency_wdg = DependencyLink()
dependency_wdg.set_sobject(snapshot)
table.add_cell( dependency_wdg )
table.add_cell( snapshot.get_value("login") )
table.add_cell( time_wdg)
wiki_wdg = WikiElementWdg("description")
wiki_wdg.set_sobject(snapshot)
table.add_cell( wiki_wdg )
if context == "icon":
td = table.add_cell("X")
td.add_style("text-align: center")
continue
#value = "%s|%s" % (snapshot.get_code(),context)
value = my._get_value(sobject, snapshot)
load_checkbox = CheckboxWdg('%s_%s' %(my.base_search_type, my.CB_NAME))
load_checkbox.add_behavior({'type': 'click_up',
'propagate_evt': True})
load_checkbox.set_option("value", value )
load_checkbox.add_class('spt_history')
if current:
load_checkbox.add_class('spt_history_%s'%context)
td = table.add_cell( load_checkbox )
td.add_style("text-align: center")
# check to see if this snapshot is in the session
if session and session.get_node_by_snapshot(snapshot) is not None:
table.add_cell( IconWdg(icon=IconWdg.GOOD) )
else:
table.add_blank_cell()
return table
# TODO: should eventually replace the table above with the table
# below. First have to make it look the same
#div = HtmlElement.div()
#div.add_style("float: right")
#div.add_style("width: 95%")
#table2 = TableWdg("sthpw/snapshot")
#table2.set_sobjects(snapshots)
#div.add(table2)
#my.add(div)
class ShotHistoryWdg(AssetHistoryWdg):
'''history that includes the loader'''
def _get_value(my, sobject, snapshot):
loader = ShotLoaderWdg(parent_key=my.parent_key)
value = loader.get_input_value(sobject, snapshot)
return value
class InstanceHistoryWdg(AssetHistoryWdg):
'''Asset Instance History'''
def _get_value(my, sobject, snapshot):
loader = InstanceLoaderWdg(parent_key=my.parent_key)
value = loader.get_input_value(sobject, snapshot)
return value
def get_snapshot_contexts(my, search_type, search_id):
'''get the contexts for the snapshots'''
contexts = Snapshot.get_contexts(search_type, search_id)
# add all of the asset snapshots
#my.instance_search_type = my.kwargs.get('search_type')
instance = Search.get_by_id(search_type, search_id)
if not my.asset_search_type:
my.asset_search_type = 'prod/asset'
#asset = instance.get_asset(search_type = my.asset_search_type)
asset_code = instance.get_value("asset_code")
asset = Search.get_by_code(my.asset_search_type, asset_code)
if not asset:
return contexts
asset_id = asset.get_id()
asset_search_type = asset.get_search_type()
asset_contexts = Snapshot.get_contexts(asset_search_type, asset_id)
contexts.extend(asset_contexts)
contexts = Common.get_unique_list(contexts)
contexts.sort()
return contexts
def get_snapshot_search(my):
web = WebContainer.get_web()
args = web.get_form_args()
if not my.search_type:
my.search_type = args.get('search_type')
my.search_id = args.get('search_id')
if not my.search_type:
my.search_type = web.get_form_value("search_type")
my.search_id = web.get_form_value("search_id")
# add all of the asset snapshots
#instance = ShotInstance.get_by_id(my.search_id)
instance = Search.get_by_id(my.search_type, my.search_id)
#asset = instance.get_asset(my.asset_search_type)
asset_code = instance.get_value("asset_code")
asset = Search.get_by_code(my.asset_search_type, asset_code)
asset_search_type = ''
asset_id = ''
if asset:
asset_id = asset.get_id()
asset_search_type = asset.get_search_type()
snapshot_type = "sthpw/snapshot"
search = Search(snapshot_type)
where = "(search_id = '%s' and search_type ='%s')" % \
(my.search_id, my.search_type)
where2 = "(search_id = '%s' and search_type ='%s')" % \
(asset_id, asset_search_type)
if asset_search_type and asset_id:
search.add_where("(%s or %s)" % (where,where2) )
else:
search.add_where(where)
# ignore icon checkins
search.add_where("context != 'icon'")
search.add_order_by("timestamp desc")
return search
class LayerHistoryWdg(AssetHistoryWdg):
def _get_value(my, sobject, snapshot):
loader = LayerLoaderWdg()
value = loader.get_input_value(sobject, snapshot)
return value