#NEWLINE# @ staticmethod #NEWLINE# def irs_timeline( r , **attr ) : #NEWLINE# #INDENT# '\n            Display the Incidents on a Simile Timeline\n\n            http://www.simile-widgets.org/wiki/Reference_Documentation_for_Timeline\n\n            @ToDo: Play button\n            http://www.simile-widgets.org/wiki/Timeline_Moving_the_Timeline_via_Javascript\n        ' #NEWLINE# if ( ( r . representation == 'html' ) and ( query . name == 'ireport' ) ) : #NEWLINE# #INDENT# T = current . T #NEWLINE# db = current . db #NEWLINE# s3db = current . s3db #NEWLINE# request = current . request #NEWLINE# response = current . response #NEWLINE# s3 = response . s3 #NEWLINE# itable = s3db . doc_image #NEWLINE# dtable = s3db . doc_document #NEWLINE# s3 . scripts . append ( ( '/%s/static/scripts/simile/timeline/timeline-api.js' % request . application ) ) #NEWLINE# if s3 . debug : #NEWLINE# #INDENT# s3 . scripts . append ( ( '/%s/static/scripts/S3/s3.timeline.js' % request . application ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# s3 . scripts . append ( ( '/%s/static/scripts/S3/s3.timeline.min.js' % request . application ) ) #NEWLINE# #UNINDENT# if r . record : #NEWLINE# #INDENT# rows = [ r . record ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# r . resource . load ( limit = 2000 ) #NEWLINE# rows = r . resource . _rows #NEWLINE# #UNINDENT# data = { #NEWLINE# #INDENT# 'dateTimeFormat' : 'iso8601' , #NEWLINE# #UNINDENT# } #NEWLINE# now = request . utcnow #NEWLINE# tl_start = tl_end = now #NEWLINE# events = [ ] #NEWLINE# for row in rows : #NEWLINE# #INDENT# start = ( row . datetime or '' ) #NEWLINE# if start : #NEWLINE# #INDENT# if ( start < tl_start ) : #NEWLINE# #INDENT# tl_start = start #NEWLINE# #UNINDENT# if ( start > tl_end ) : #NEWLINE# #INDENT# tl_end = start #NEWLINE# #UNINDENT# start = start . isoformat ( ) #NEWLINE# #UNINDENT# end = ( row . expiry or '' ) #NEWLINE# if end : #NEWLINE# #INDENT# if ( end > tl_end ) : #NEWLINE# #INDENT# tl_end = end #NEWLINE# #UNINDENT# end = end . isoformat ( ) #NEWLINE# #UNINDENT# query = ( ( itable . deleted == False ) & ( itable . doc_id == row . doc_id ) ) #NEWLINE# image = db ( query ) . select ( itable . url , limitby = ( 0 , 1 ) ) . first ( ) #NEWLINE# if image : #NEWLINE# #INDENT# image = ( image . url or '' ) #NEWLINE# #UNINDENT# link = URL ( args = [ row . id ] ) #NEWLINE# events . append ( { #NEWLINE# #INDENT# 'start' : start , #NEWLINE# 'end' : end , #NEWLINE# 'title' : row . name , #NEWLINE# 'caption' : ( row . message or '' ) , #NEWLINE# 'description' : ( row . message or '' ) , #NEWLINE# 'image' : ( image or '' ) , #NEWLINE# 'link' : ( link or '' ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# data [ 'events' ] = events #NEWLINE# data = json . dumps ( data , separators = SEPARATORS ) #NEWLINE# code = '' . join ( ( 'S3.timeline.data=' , data , '\nS3.timeline.tl_start="' , tl_start . isoformat ( ) , '"\nS3.timeline.tl_end="' , tl_end . isoformat ( ) , '"\nS3.timeline.now="' , now . isoformat ( ) , '"\n' ) ) #NEWLINE# s3 . js_global . append ( code ) #NEWLINE# item = DIV ( _id = 's3timeline' , _class = 's3-timeline' ) #NEWLINE# output = dict ( item = item ) #NEWLINE# if attr . get ( 'rheader' ) : #NEWLINE# #INDENT# rheader = attr [ 'rheader' ] ( r ) #NEWLINE# if rheader : #NEWLINE# #INDENT# output [ 'rheader' ] = rheader #NEWLINE# #UNINDENT# #UNINDENT# output [ 'title' ] = T ( 'Incident Timeline' ) #NEWLINE# response . view = 'timeline.html' #NEWLINE# return output #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise HTTP ( 405 , current . ERROR . BAD_METHOD )