-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_wdg.py
More file actions
1329 lines (1009 loc) · 44.3 KB
/
Copy pathtask_wdg.py
File metadata and controls
1329 lines (1009 loc) · 44.3 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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###########################################################
#
# 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.
#
#
#
__all__ = ['TaskSObjectEditCmd','TaskAssetCreateSelectWdg', 'TaskSObjectSelectWdg', 'TaskProcessSelectWdg',
'SObjectTaskTableElement', 'TaskWarningTableElement', 'TaskExtraInfoWdg',
'TaskParentInputWdg', 'TaskParentSpacingTableElement',
'UserAssignWdg', 'UserAssignContainerWdg', 'UserAssignCommand']
from pyasm.common import *
from pyasm.search import SearchType, Search, SearchKey, SearchException
from pyasm.web import *
from pyasm.command import *
from pyasm.search import Search
from pyasm.biz import Task, Pipeline, SimpleStatusAttr
from pyasm.web import HtmlElement, WidgetSettings
from table_element_wdg import ExpandableTextWdg, DateWdg, SimpleTableElementWdg
from input_wdg import BaseInputWdg, SelectWdg, HiddenWdg, FilterCheckboxWdg, FilterSelectWdg, MultiSelectWdg
from serial_status import SimpleStatusWdg
from icon_wdg import IconWdg, IconButtonWdg
from web_wdg import *
from timecard_wdg import *
from statistic_wdg import CalendarBarWdg
from creator_wdg import CreateSelectWdg
# FIXME: this is a circular import which fails on batch scripts.
# In order to fix, we have to move the classes that use the new
# BaseTableElementWdg to the tactic.ui.widget directory.
# Leaving them here for now because a lot of these are old classes and some
# are deprecated.
try:
from tactic.ui.common import BaseTableElementWdg
except:
from table_element_wdg import BaseTableElementWdg
def get_search_type():
web = WebContainer.get_web()
search_type = web.get_form_value("parent_search_type")
if not search_type:
search_type = web.get_form_value("search_type")
return search_type
class TaskSObjectEditCmd(DatabaseAction):
def execute(my):
value = my.get_value()
if value == "":
return
search_type, search_id = value.split("|")
my.sobject.set_value("search_type", search_type)
my.sobject.set_value("search_id", search_id)
class TaskAssetCreateSelectWdg(CreateSelectWdg):
''' Create a list of asset for multi task creations'''
def init_setup(my):
hidden = HiddenWdg(my.DELETE_MODE)
my.add_ajax_input(hidden)
hidden = HiddenWdg(my.NEW_ITEM)
my.add_ajax_input(hidden)
hidden = HiddenWdg(my.NEW_ITEM_LABEL)
my.add_ajax_input(hidden)
hidden = HiddenWdg("code_col")
my.add_ajax_input(hidden)
if not my.is_from_ajax():
hidden.set_value(my.get_option('code_col'))
my.add(hidden)
hidden = HiddenWdg('ref_search_type')
my.add_ajax_input(hidden)
if not my.is_from_ajax():
hidden.set_value(my.web.get_form_value('ref_search_type'))
my.add(hidden)
hidden = HiddenWdg('search_id')
my.add_ajax_input(hidden)
if my.is_from_ajax():
col_name = my.web.get_form_value('col_name')
else:
col_name = my.get_name()
my.col_name = HiddenWdg('col_name', col_name)
my.add_ajax_input(my.col_name)
my.select_items = HiddenWdg('%s|%s' %(col_name, my.SELECT_ITEMS))
my.add_ajax_input(my.select_items)
def get_delimiter(my):
return '||'
def get_search_key(my):
search_key = '%s|%s' % (my.web.get_form_value('ref_search_type'), \
my.web.get_form_value('search_id'))
return search_key
def get_item_list(my, items):
my.select = SelectWdg(my.SELECT_NAME)
my.select.set_attr("size", '%s' %(len(items)+1))
if items == ['']:
return my.select
my.select.set_option('values', items)
code_col = my.web.get_form_value('code_col')
labels = []
# assume they are all the same search type
search_ids = [item.split("|", 1)[1] for item in items]
search_type = ''
if items:
search_type = items[0].split('|', 1)[0]
if search_type and search_ids:
sobjs = Search.get_by_id(search_type, search_ids)
for sobj in sobjs:
name = sobj.get_name()
code = sobj.get_code()
if code_col and sobj.has_value(code_col):
code = sobj.get_value(code_col)
if name == code:
labels.append(code)
else:
labels.append('%s - %s' %(code, name))
my.select.set_option('labels', labels)
return my.select
def get_type_select(my, item_type):
return FloatDivWdg(' ', width=100)
def draw_widgets(my, widget, delete_widget, item_span):
'''actually drawing the widgets'''
widget.add(item_span)
widget.add(HtmlElement.br(2))
widget.add(SpanWdg(my.select, css='med'))
widget.add(delete_widget)
widget.add(HtmlElement.br(2))
def get_sequence_wdg(my):
text_span = SpanWdg('New item ')
current = my.get_my_sobject()
search_type = get_search_type()
select = SelectWdg(my.NEW_ITEM)
select.set_option('web_state', my.get_option('web_state') )
# get all of the options for this search type
search = Search(search_type)
search.add_order_by("code")
sobjects = search.get_sobjects()
if not sobjects:
raise SetupException("No Assets defined. Please create assets to add tasks to")
values = [x.get_search_key() for x in sobjects]
labels = []
code_col = my.web.get_form_value('code_col')
for x in sobjects:
name = x.get_name()
code = x.get_code()
if code_col and x.has_value(code_col):
code = x.get_value(code_col)
if name == code:
labels.append(code)
else:
labels.append("%s - %s" % (code, name) )
select.set_option("values", values)
select.set_option("labels", labels)
# transfer the options
for key, value in my.options.items():
select.set_option(key, value)
# extra code not needed here. setting web_state to true in the config
# is sufficient, still not perfect yet.
if not current:
pass
else:
search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id") )
select.set_value(search_key)
button = my.get_sequence_button()
text_span.add(select)
text_span.add(button)
return text_span
def get_sequence_button(my):
# add button
widget = Widget()
from pyasm.prod.web import ProdIconButtonWdg
add = ProdIconButtonWdg('Add')
script = ["append_item('%s','%s')" % (my.SELECT_NAME, my.NEW_ITEM )]
script.append( my.get_refresh_script() )
add.add_event('onclick', ';'.join(script))
widget.add(add)
hint = HintWdg('Add one or more items to the list.', title='Tip')
widget.add(hint)
return widget
class TaskSObjectSelectWdg(BaseInputWdg):
def get_display(my):
current = my.get_current_sobject()
parent_search_type = current.get_value('search_type')
if not parent_search_type:
return "No parent type"
search_type = parent_search_type
web = WebContainer.get_web()
is_edit = not current.is_insert()
# start a search
search = Search(search_type)
widget = Widget()
# avoid a search key == '|'
parent_search_key = ''
if is_edit and current.get_value("search_type"):
parent_search_key = "%s|%s" % (current.get_value("search_type"), current.get_value("search_id") )
#parent_search_key = web.get_form_value("edit|parent")
my.categorize(widget, search_type, search)
select = SelectWdg(my.get_input_name())
widget.add(select)
select.set_option('web_state', my.get_option('web_state') )
search.add_order_by("code")
sobjects = []
if is_edit:
if parent_search_key:
sobjects = [Search.get_by_search_key(parent_search_key)]
else:
sobjects = search.get_sobjects()
# Task planner task don't have a parent
if not sobjects and search_type !='sthpw/task':
span = SpanWdg("No Parents Defined. Parents for this task should be inserted first.")
span.add_style("color: #f44")
widget.add(span)
return widget
values = [x.get_search_key() for x in sobjects]
labels = []
code_col = my.get_option('code_col')
for x in sobjects:
name = x.get_name()
code = x.get_code()
if code_col and x.has_value(code_col):
code = x.get_value(code_col)
if name == code:
labels.append(code)
else:
labels.append("%s - %s" % (code, name) )
select.set_option("values", values)
select.set_option("labels", labels)
# transfer the options
for key, value in my.options.items():
select.set_option(key, value)
# extra code not needed here. setting web_state to true in the config
# is sufficient, still not perfect yet.
if current.is_insert():
pass
else:
select.set_value(parent_search_key)
return widget
def categorize(my, widget, search_type, search):
'''categorize parents based on search_type'''
# FIXME: this should not be here. This is a general class for all
# search types, not just prod/asset
if my.get_option('read_only') != 'true':
if search_type == "prod/asset":
lib_select = FilterSelectWdg('parent_lib')
lib_select.persistence = False
search2 = Search("prod/asset_library")
lib_select.set_search_for_options( search2, "code", "title" )
lib_select.add_empty_option("-- Any --")
widget.add(lib_select)
# get all of the options for this search type
parent_lib = lib_select.get_value()
if parent_lib:
search.add_filter('asset_library', parent_lib)
elif search_type == "prod/shot":
lib_select = FilterSelectWdg('parent_lib')
lib_select.persistence = False
search2 = Search("prod/sequence")
lib_select.set_search_for_options( search2, "code", "code" )
lib_select.add_empty_option("-- Any --")
widget.add(lib_select)
# get all of the options for this search type
parent_lib = lib_select.get_value()
if parent_lib:
search.add_filter('sequence_code', parent_lib)
elif search_type == 'prod/texture':
lib_select = FilterSelectWdg('parent_lib')
lib_select.persistence = False
search2 = Search("prod/texture")
search2.add_column('category')
search2.add_group_by("category")
lib_select.set_search_for_options( search2, "category", "category" )
lib_select.add_empty_option("-- Any --")
widget.add(lib_select)
# get all of the options for this search type
parent_lib = lib_select.get_value()
if parent_lib:
search.add_filter('category', parent_lib)
#
# TODO: this class is poorly named. It should be AssetProcessSelectWdg
#
# This should be DEPRECATED!!
#
class TaskProcessSelectWdg(SelectWdg):
def get_display(my):
current = my.get_current_sobject()
search_type = get_search_type()
parent_key = WebContainer.get_web().get_form_value("edit|asset")
if parent_key != "":
parent = Search.get_by_search_key(parent_key)
# get all of the options for this search type
status_attr_name = "status"
status_attr = parent.get_attr(status_attr_name)
pipeline = status_attr.get_pipeline()
else:
# FIXME: make this general by looking at the current asset
pipeline = Pipeline.get_by_name("flash_shot")
processes = pipeline.get_process_names()
my.set_option("values", "|".join(processes) )
return super(TaskProcessSelectWdg,my).get_display()
class SObjectTaskTableElement(BaseTableElementWdg, AjaxWdg):
'''lists all the tasks with the timeline as a table element'''
PROCESS_FILTER_NAME = "process_filter"
def init(my):
my.sobject = None
my.process_completion_dict = {}
#super(SObjectTaskTableElement, my).__init__()
my.data = {}
my.calendar_bar = CalendarBarWdg()
my.calendar_bar.set_option('width','100')
my.is_refresh = False
if my.kwargs.get('is_refresh')=='true':
my.is_refresh = True
my.init_cgi()
def is_sortable(my):
return False
def is_searchable(my):
return True
def get_searchable_search_type(my):
'''get the searchable search type for local search'''
return 'sthpw/task'
def alter_task_search(my, search, prefix='children', prefix_namespace='' ):
from tactic.ui.filter import FilterData, BaseFilterWdg, GeneralFilterWdg
filter_data = FilterData.get()
parent_search_type = get_search_type()
if not filter_data.get_data():
# use widget settings
key = "last_search:%s" % parent_search_type
data = WidgetSettings.get_value_by_key(key)
if data:
filter_data = FilterData(data)
filter_data.set_to_cgi()
filter_mode_prefix = 'filter_mode'
if prefix_namespace:
filter_mode_prefix = '%s_%s' %(prefix_namespace, filter_mode_prefix)
filter_mode = 'and'
filter_mode_value = filter_data.get_values_by_index(filter_mode_prefix, 0)
if filter_mode_value:
filter_mode = filter_mode_value.get('filter_mode')
if prefix_namespace:
prefix = '%s_%s' %(prefix_namespace, prefix)
values_list = BaseFilterWdg.get_search_data_list(prefix, \
search_type=my.get_searchable_search_type())
if values_list:
search.add_op('begin')
GeneralFilterWdg.alter_sobject_search( search, values_list, prefix)
if filter_mode != 'custom':
search.add_op(filter_mode)
return search
def preprocess(my):
if my.sobjects:
try:
search = Search(Task)
search_ids = [x.get_id() for x in my.sobjects]
search.add_filters("search_id", search_ids)
search_type = my.sobjects[0].get_search_type()
search.add_filter("search_type", search_type)
# go thru children of main search
search = my.alter_task_search(search, prefix='children')
# go thru Local Search
search = my.alter_task_search(search, prefix='main_body', prefix_namespace=my.__class__.__name__)
sobj = my.sobjects[0]
pipeline = Pipeline.get_by_sobject(sobj)
if pipeline:
process_names = pipeline.get_process_names(True)
search.add_enum_order_by("process", process_names)
else:
search.add_order_by("process")
search.add_order_by("id")
tasks = search.get_sobjects()
# create a data structure
for task in tasks:
search_type = task.get_value("search_type")
search_id = task.get_value("search_id")
search_key = "%s|%s" % (search_type, search_id)
sobject_tasks = my.data.get(search_key)
if not sobject_tasks:
sobject_tasks = []
my.data[search_key] = sobject_tasks
sobject_tasks.append(task)
except:
from tactic.ui.app import SearchWdg
parent_search_type = get_search_type()
SearchWdg.clear_search_data(parent_search_type)
raise
def get_prefs(my):
from pyasm.prod.web import UserFilterWdg
if UserFilterWdg.has_restriction():
return ''
else:
widget = Widget()
cb = FilterCheckboxWdg('show_all_tasks', label='show all tasks')
sub_cb = FilterCheckboxWdg('show_sub_tasks', label='show sub tasks')
widget.add(cb)
widget.add(sub_cb)
return widget
def get_title(my):
# create the calendar
widget = Widget()
my.calendar_bar.set_user_defined_bound(False)
widget.add(my.calendar_bar.get_calendar())
widget.add( super(SObjectTaskTableElement,my).get_title() )
assign_cont = UserAssignContainerWdg()
widget.add(assign_cont)
widget.add(my.calendar_bar.get_show_cal_script())
return widget
def init_cgi(my):
#if not my.is_ajax(check_name=True):
# return
my.data = {}
# get the sobject
keys = my.web.get_form_keys()
search_key = ''
for key in keys:
if key.startswith('skey_SObjectTaskTableElement_'):
search_key = my.web.get_form_value(key)
if search_key:
my.sobject = Search.get_by_search_key(search_key)
my.sobjects = [my.sobject]
# adding the CalendarBarWdg
my.calendar_bar = CalendarBarWdg()
my.calendar_bar.set_option('width','100')
my.calendar_bar.set_option('bid_edit', my.get_option('bid_edit'))
my.calendar_bar.set_user_defined_bound(False)
# run preprocess
my.preprocess()
my.add(my.calendar_bar.get_calendar())
def init_setup(my, widget):
my.reset_ajax()
hidden = HiddenWdg('skey_SObjectTaskTableElement_%s' \
%my.sobject.get_id(), my.sobject.get_search_key())
widget.add(hidden)
# add the search_key input
my.add_ajax_input(hidden)
# add the filter inputs
hidden = HiddenWdg('task_status')
my.add_ajax_input(hidden)
hidden = HiddenWdg('show_assigned_only')
my.add_ajax_input(hidden)
hidden = MultiSelectWdg('user_filter')
my.add_ajax_input(hidden)
hidden = HiddenWdg('show_all_tasks')
my.add_ajax_input(hidden)
hidden = HiddenWdg('show_sub_tasks')
my.add_ajax_input(hidden)
# put the display option in here
#hidden = HiddenWdg('doption_SObjectTaskTableElement')
#my.add_ajax_input(hidden)
def get_display(my):
web = WebContainer.get_web()
# this needs to be a BaseInputWdg since UserFilterWdg is hideable
user_filter = FilterSelectWdg("user_filter")
user_filter = user_filter.get_values()
#login = Environment.get_security().get_login()
#user = login.get_value("login")
if my.is_refresh:
widget = Widget()
my.init_cgi()
else:
my.sobject = my.get_current_sobject()
widget = DivWdg(id="task_elem_%s"% my.sobject.get_id())
widget.add_class('spt_task_panel')
my.set_as_panel(widget)
#TODO: remove this
my.init_setup(widget)
#my.set_ajax_top(widget)
table = Table(css="minimal")
table.add_style("width: 100%")
# get all of the tasks related to this sobject
search_type = my.sobject.get_search_type()
search_id = my.sobject.get_id()
if my.data:
tasks = my.data.get("%s|%s" % (search_type,search_id) )
else:
tasks = Task.get_by_sobject(my.sobject)
my.data[my.sobject.get_search_key()] = tasks
if not tasks:
tasks = []
task_statuses_filter = web.get_form_values("task_status")
show_sub_tasks = False
if not task_statuses_filter:
# NOTE: Not sure if this is correct!!
# have to do this because it is impossible to tell if a checkbox
# is empty or not there. This is used for pages that do not have
# tasks_status checkboxes
show_all_tasks = True
else:
cb = FilterCheckboxWdg('show_all_tasks')
show_all_tasks = cb.is_checked(False)
sub_cb = FilterCheckboxWdg('show_sub_tasks')
show_sub_tasks = sub_cb.is_checked(False)
# trim down the process list
"""
if not show_sub_tasks:
process_list = [x for x in process_list if "/" not in x]
"""
pipeline = Pipeline.get_by_sobject(my.sobject)
# retrieve the pipeline
if not pipeline:
td = table.add_cell("<br/><i>No pipeline</i>")
td.add_style("text-align: center")
return table
# store completion per process first in a dict
# reset it first
my.process_completion_dict = {}
for task in tasks:
task_process = task.get_value("process")
status_attr = task.get_attr('status')
percent = status_attr.get_percent_completion()
my.store_completion(task_process, percent)
security = WebContainer.get_security()
me = Environment.get_user_name()
for task in tasks:
has_valid_status = True
task_pipeline = task.get_pipeline()
task_statuses = task_pipeline.get_process_names()
task_process = task.get_value("process")
# Commenting this out. It is not very meaningful in 2.5 ...
# we need a better mechanism. The end result of this code
# is that "admin" never sees any tasks
#if security.check_access("public_wdg", "SObjectTaskTableElement|unassigned", "deny", is_match=True):
# assignee = task.get_value("assigned")
# if assignee != me:
# continue
if not show_all_tasks:
"""
if process_list and task_process not in process_list:
continue
"""
# skip sub tasks
if not show_sub_tasks and '/' in task_process:
continue
task_status = task.get_value("status")
if task_status not in task_statuses:
has_valid_status = False
if has_valid_status and task_status \
and task_status not in task_statuses_filter:
continue
# the first one shouldn't be empty
if user_filter and user_filter[0] and task.get_value("assigned") not in user_filter:
continue
table.add_row()
#link = "%s/Maya/?text_filter=%s&load_asset_process=%s" % (web.get_site_context_url().to_string(), my.sobject.get_code(), task_process)
#icon = IconButtonWdg("Open Loader", IconWdg.LOAD, False)
#table.add_cell( HtmlElement.href(icon, link, target='maya') )
td = table.add_cell(css='no_wrap')
description = task.get_value("description")
expand = ExpandableTextWdg()
expand.set_max_length(50)
expand.set_value(description)
assigned = task.get_value("assigned").strip()
status_wdg = SimpleStatusWdg()
status_wdg.set_sobject(task)
status_wdg.set_name("status")
# refresh myself on execution of SimpleStatusCmd
#post_scripts = my.get_refresh_script(show_progress=False)
post_scripts = '''var panel = bvr.src_el.getParent('.spt_task_panel');
var search_top = spt.get_cousin(bvr.src_el, '.spt_view_panel','.spt_search');
var search_val = spt.dg_table.get_search_values(search_top);
var values = spt.api.Utility.get_input_values(panel);
values['json'] = search_val;
spt.panel.refresh(panel, values);'''
status_wdg.set_post_ajax_script(post_scripts)
if assigned:
user_info = UserExtraInfoWdg(assigned).get_buffer_display()
else:
user_info = HtmlElement.i(" unassigned").get_buffer_display()
info_span = SpanWdg()
info_span.add(TaskExtraInfoWdg(task))
info_span.add("- ")
info_span.add(" [%s]" % user_info)
if UserAssignWdg.has_access() and my.get_option('supe')=='true':
my._add_user_assign_wdg(task, info_span, widget)
td.add( info_span )
#--------------
my.calendar_bar.set_sobject(task)
# set always recalculate since each task is set individually
my.calendar_bar.set_always_recal(True)
#---------------
td.add_color('color','color')
td.add(HtmlElement.br())
if description:
td.add(expand)
td.add(HtmlElement.br())
td.add(status_wdg)
if my.last_process_finished(pipeline, task_process):
dot = IconWdg(icon=IconWdg.DOT_GREEN)
dot.add_tip("All dependent processs complete")
dot.add_style('float','left')
dot.add_style('display','block')
td.add(dot)
else:
dot = IconWdg(icon=IconWdg.DOT_RED)
dot.add_tip("Dependent process in progress")
dot.add_style('float','left')
dot.add_style('display','block')
td.add(dot)
date_display = None
if my.get_option('simple_date') == 'true':
start_wdg = DateWdg()
start_wdg.set_option("pattern", "%b %d")
start_wdg.set_name('bid_start_date')
start_wdg.set_sobject(task)
end_wdg = DateWdg()
end_wdg.set_name('bid_end_date')
end_wdg.set_option("pattern", "%b %d")
end_wdg.set_sobject(task)
date_display = '%s - %s' %(start_wdg.get_buffer_display(), \
end_wdg.get_buffer_display())
else:
my.calendar_bar.set_sobject(task)
# set always recalculate since each task is set individuallly
my.calendar_bar.set_always_recal(True)
my.calendar_bar.set_option("width", "40")
my.calendar_bar.set_option("bid_edit", my.get_option('bid_edit'))
date_display = my.calendar_bar.get_buffer_display()
#td = table.add_cell(date_display, css='smaller')
td.add(FloatDivWdg(date_display, float='right', css='smaller'))
#td.set_style("width: 120; padding-left: 15px")
# This uses the parallel status widget to display status of
# dependent tasks
dependent_processes = pipeline.get_input_contexts(task_process)
from parallel_status import ParallelStatusWdg
dep_status_div = DivWdg()
dep_status_div.add_style("padding-right: 10px")
dep_status_wdg = ParallelStatusWdg()
dep_status_wdg.set_process_names(dependent_processes)
dep_status_wdg.set_label_format("abbr")
dep_status_wdg.set_sobject(my.sobject)
#dep_status_wdg.preprocess()
dep_status_wdg.set_data(my.data)
dep_status_div.add(dep_status_wdg)
td.add(dep_status_div)
#td.add_style("border-style: solid")
#td.add_style("border-bottom: 1px")
#td.add_style("border-color: #999")
td.add_style("padding: 3px 0 3px 0")
widget.add(table)
return widget
def _add_user_assign_wdg(my, task, info_span, widget):
''' add a user assignment icon '''
icon = IconWdg('assign', icon=IconWdg.ASSIGN)
icon.add_class('hand')
assign = UserAssignWdg(check_name=True)
assign.set_task(task)
# UserAssignWdg will take care of filtering duplicated refresh scripts
# eventually it is added into this widget below via assign.get_post_data()
assign.set_post_ajax_script(my.get_refresh_script(show_progress=False))
script = []
script.append("Common.follow_click(event, '%s', 12, -15)" \
% UserAssignContainerWdg.CONTAINER_ID)
script.append( "set_display_on('%s')" \
% UserAssignContainerWdg.CONTAINER_ID)
script.append(assign.get_refresh_script())
icon.add_event('onclick', ';'.join(script))
info_span.add(icon)
widget.add(assign.get_post_data())
def _has_assign_wdg_access(my):
''' check if the user can see this user assignment wdg '''
security = Environment.get_security()
group_names = security.get_group_names()
access_manager = security.get_access_manager()
if my.get_option('supe') == 'true':
for group in group_names:
if security.check_access("UserAssignWdg", group, "view"):
return True
return False
def store_completion(my, process, percent):
''' store the completion percentage per process in a dict'''
status_list = my.process_completion_dict.get(process)
if not status_list:
status_list = []
my.process_completion_dict[process] = status_list
status_list.append(percent)
def last_process_finished(my, pipeline, task_process, is_subpipeline=False):
''' find if the last process is finished '''
if not pipeline:
return True
last_processes = pipeline.get_backward_connects(task_process)
# TODO: use get_input_processes
#last_processes = pipeline.get_input_processes(task_process)
# subpipeline scenario
if task_process.find("/") != -1:
pipeline_code, process = task_process.split("/", 1)
pipeline = Pipeline.get_by_code(pipeline_code)
return my.last_process_finished(pipeline, process, is_subpipeline=True)
# the first process of the pipe should be green-lit
if not last_processes:
return True
for process in last_processes:
# if the process is from another pipeline
# TODO: disabling for now
full_process = process
if is_subpipeline:
full_process = '%s/%s' %(pipeline.get_code(), process)
complete_list = my.process_completion_dict.get(full_process)
# skip processes that have no tasks
# count is a safe-guard in case pipeline.get_backward_connects()
# does not return None or [] in the future by accident
# so the limit for a pipeline is 60 processes for now.
count = 0
while not complete_list and last_processes and count < 60:
count = count + 1
last_processes = pipeline.get_backward_connects(process)
for process in last_processes:
full_process = process
if is_subpipeline:
full_process = '%s/%s' %(pipeline.get_code(), process)
complete_list = my.process_completion_dict.get(full_process)
# previous processes have no tasks assigned, in other words, they are finished
if not complete_list:
return True
for item in complete_list:
if item != 100:
return False
return True
class TaskWarningTableElement(BaseTableElementWdg):
def get_title(my):
return " "
def get_display(my):
sobject = my.get_current_sobject()
bid_start_time = str(sobject.get_value("bid_start_date"))
bid_end_time = str(sobject.get_value("bid_end_date"))
if bid_start_time == "":
return " "
now = Date().get_db_time()
status = sobject.get_value("status")
if status == "Pending" and now > bid_start_time:
icon_wdg = IconWdg( "Start date has passed", IconWdg.ERROR )
return icon_wdg
if not bid_end_time:
return " "
if status != "Final" and now > bid_end_time:
icon_wdg = IconWdg( "End date has passed", IconWdg.ERROR )
return icon_wdg
return " "
class TaskExtraInfoWdg(ExtraInfoWdg):
def __init__(my, task=None):
my.task = task
my.height = 150
super(TaskExtraInfoWdg,my).__init__()
def init(my):
assert my.task
super(TaskExtraInfoWdg, my).init()
# create the visible element
icon = IconWdg('Time Card', icon=IconWdg.TIME)
my.add(icon)
my.add(HtmlElement.b(my.task.get_process()))
my.time_card = TimecardWdg()
my.time_card.set_task(my.task)
from pyasm.security import Login
# create the content
content = DivWdg()
content.add_style('width','46em')
# customize the extra info widget
my.set_class('timecard_main')
my.set_content(content)
my.set_mouseout_flag(False)
my.login = Login.get_by_login(my.task.get_assigned())
title = FloatDivWdg()
login_name = 'unassigned'
my.is_other = False
if my.login:
login_name = my.login.get_full_name()
if my.login.get_login() == Environment.get_login().get_login():
icon = IconWdg(icon=IconWdg.REFRESH)
icon.add_class('hand')
icon.add_event('onclick', my.time_card.get_refresh_script())
title.add(icon)
else:
my.is_other = True
title.add("Time card - %s" % login_name)
content.add(title)
content.add(CloseWdg(my.get_off_script()))
content.add(HtmlElement.br(2))
content.add(my.time_card, 'time')
if not my.login:
div = DivWdg(HtmlElement.b('Time card cannot be entered for unassigned task.'))
content.set_widget(div, 'time')
my.height = 60
elif my.is_other:
div = DivWdg(HtmlElement.b('Time card cannot be entered for other users [%s].'\
%login_name))
content.set_widget(div, 'time')
my.height = 60
def get_mousedown_script(my):
script = [super(TaskExtraInfoWdg,my).get_mousedown_script(height=my.height)]
if my.login and not my.is_other:
script.append(my.time_card.get_refresh_script())
return ';'.join(script)