Changeset 621 in tmcsimulator for branches/LCSv2/controllers/default.py


Ignore:
Timestamp:
08/19/2020 08:18:24 AM (6 years ago)
Author:
jdalbey
Message:

LCS implement exiting incident UI and javascript

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/LCSv2/controllers/default.py

    r620 r621  
    1919# List all the current records in the database - remove in final application 
    2020def list(): 
    21     highways = db().select(db.closures.ALL, orderby=db.closures.lognum) 
     21    highways = db().select(db.closures.ALL, orderby=db.closures.closureid) 
    2222    return dict(highways = highways) 
    2323# Show details of a single record - remove in final application 
     
    110110    return dict(msg=msg, count=count, highways=hwy, table=header, multiform=multiform) 
    111111 
    112 # Show the status box next to each search result 
     112# Show a selected closure with a status update form 
    113113def statuslist(): 
    114114    closedItems = [] 
     
    122122                retrieved = db(db.closures.closureid == item).select().first() 
    123123                closedItems.append(retrieved)  
    124  
     124        # Build the table rows         
     125        tblrows = TR()         
     126        for row in closedItems: 
     127            # Construct the status radio buttons; disable if date already in database 
     128            statusflags = "disabled" if row.s1097date == "" else ""   
     129            if row.s1097date == "": 
     130                btn = LABEL('1097'), INPUT(_type='radio', _name='statustype', _value='1097'+row.closureid) 
     131            else: 
     132                btn = LABEL('1097 ○',_class='labelgray'), 
     133            btngroup = btn 
     134            if row.s1098date == "": 
     135                btn = LABEL('1098'), INPUT(_type='radio', _name='statustype', _value='1098'+row.closureid) 
     136            else: 
     137                btn = LABEL('1098 ○',_class='labelgray'), 
     138            btngroup += btn 
     139            if row.s1022date == "": 
     140                btn = LABEL('1022'), INPUT(_type='radio', _name='statustype', _value='1022'+row.closureid) 
     141            else: 
     142                btn = LABEL('1022 ○',_class='labelgray'), 
     143            btngroup += btn 
     144 
     145            if row.s1097date != "" and row.s1098date != "" and row.s1022date != "": 
     146                btngroup += BR(),LABEL('Statuser:', _class='labelgray') 
     147            else:     
     148                btngroup += BR(),LABEL('Statuser:'),INPUT(_name='statuser',_size='9'),BR(),BR(),INPUT(_type='submit',_value="submit status update",_class="submit-button") 
     149#            LABEL('1097 ○',_class='colorgray'), INPUT(_type='radio', _name='statustype', _value='1097'+row.closureid),LABEL('1098'), INPUT(_type='radio', _name='statustype', _value='1098'+row.closureid),LABEL('1022'), INPUT(_type='radio', _name='statustype', _value='1022'+row.closureid),BR(), LABEL('Statuser:'),INPUT(_name='statuser',_size='9') 
     150            tblrows += TR(TD(row.closureid,HR(),row.lognum),TD(row.route,' ',row.direction,HR(),row.closuretype),TD(row.startdate,HR(),row.enddate,HR(),row.estdelay),TD(row.supervisor,BR(),db(db.supervisors.name == row.supervisor).select().first().radiocallnum),TD(btngroup)) 
    125151        form = FORM(BR(),  
    126152                TABLE(THEAD(TR(TH('Closure ID/',BR(),'Log No.'), TH('Route & Dir',BR(),'Type of Closure'),TH('Start Date/',BR(),'End Date/',BR(),'Est. Delay'),TH('Requestor/',BR(),'Radio Call No.'),TH('Status'))), 
    127                     [TR(TD(row.closureid,HR(),row.lognum),TD(row.route,' ',row.direction,HR(),row.closuretype),TD(row.startdate,HR(),row.enddate,HR(),row.estdelay),TD(row.supervisor,BR(),db(db.supervisors.name == row.supervisor).select().first().radiocallnum),TD(LABEL('1097'), INPUT(_type='checkbox', _name='statustype', _value='1097'+row.closureid),LABEL('1098'), INPUT(_type='checkbox', _name='statustype', _value='1098'+row.closureid),LABEL('1022'), INPUT(_type='checkbox', _name='statustype', _value='1022'+row.closureid),BR(), LABEL('Statuser:'),INPUT(_name='statuser',_size='9'))) for row in closedItems], 
    128                     _border='1', _cellpadding='5'),INPUT(_type='submit',_value="submit status form",_class="submit-button"),) 
     153                    tblrows, 
     154                      
     155                    _border='1', _cellpadding='5', _width="70%")) 
    129156         
    130157    else: 
     
    152179            now = datetime.datetime.today() 
    153180            fieldname = "s"+session.statustype[0:4]+"date" 
    154             db(db.closures.closureid == session.statustype[4:]).update(**{fieldname:now.strftime("%Y%m%d")}) 
     181            db(db.closures.closureid == session.statustype[4:]).update(**{fieldname:now.strftime("%Y-%m-%d")}) 
    155182            fieldname = "s"+session.statustype[0:4]+"time" 
    156183            db(db.closures.closureid == session.statustype[4:]).update(**{fieldname:now.strftime("%H%M")}) 
     
    167194    else: 
    168195        return "" 
     196 
    169197# Create a new record 
    170198def submit(): 
     
    188216        streets.append(row.street) 
    189217        streetlookup.append(row.route + ',' + row.street) 
    190  
     218    # Build the list of existing closures     
     219    existingclosures = [] 
     220    existingclosures.append("") 
     221    for row in db().select(db.closures.ALL, orderby=db.closures.closureid): 
     222        # Omit duplicate ID's (with different lognumbers) 
     223        if row.closureid not in existingclosures: 
     224            existingclosures.append(row.closureid) 
     225         
    191226    form = FORM( 
    192227                LABEL('*Route',_for='route'), SELECT(hwys,_name='route', _id='routecombo', _onchange='routechanged()', requires=IS_LENGTH(minsize=1,error_message='route cannot be empty')), XML('   '),  
     
    210245                 TR(TD(SELECT(closuretypes,_name='closuretype',requires=IS_LENGTH(minsize=1,error_message='type of closure cannot be empty'))),  
    211246                    TD(SELECT(worktypes,_name='worktype', requires=IS_LENGTH(minsize=1,error_message='type of work cannot be empty'))),  
    212                     TD(INPUT(_name='estdelay',_size='4',requires=IS_INT_IN_RANGE(1, 1441)),'minutes'),  
     247                    TD(INPUT(_name='estdelay',_size='4'),'minutes'),  
    213248                    TD(INPUT(_type='checkbox',_name='cozeep'),'CoZeep MaZeep/CHP',BR(),  
    214249                       INPUT(_type='checkbox', _name='detour'),'Detour Available')),  
    215250                 _width='100%' ), 
    216251    TABLE(TR(TD(LABEL('*Supervisor')), 
    217             TD(LABEL('Field Rep'))),  
    218                   TR(TD(SELECT(supervisors,_name='supervisor', requires=IS_LENGTH(minsize=1,error_message='supervisor cannot be empty'))), 
    219                      TD(SELECT(crew,_name='fieldrep')))), 
     252            TD(LABEL('Field Rep')) 
     253            ),  
     254          TR(TD(SELECT(supervisors,_name='supervisor', requires=IS_LENGTH(minsize=1,error_message='supervisor cannot be empty'))), 
     255             TD(SELECT(crew,_name='fieldrep')), 
     256             TD(XML("    ")), 
     257             TD('Is this an existing incident?', 
     258                INPUT(_type='radio',_name='existing',_value='No',_onclick='radioclicked()'), 
     259                'No', 
     260                INPUT(_type='radio',_name='existing',_value='Yes',value='Yes',_onclick='radioclicked()'), 
     261                'Yes' 
     262               ) 
     263             ), 
     264          TR(TD(),TD(),TD(), TD('    Select closure ID:',SELECT(existingclosures,_name='existingid'),_id='closureselect'))), 
    220265    TABLE(TR(TD( LABEL('Meeting Place/CHP Contact')), 
    221266            TD(LABEL('Reason for Closure')), 
     
    225270            XML('\n'),SELECT(streetlookup,_name='stlookup', _id='stlookup', _class='hideme'))  
    226271 
    227     if form.process().accepted: 
    228         newID = calcNextClosure(form.vars.route) 
     272    if form.process(onvalidation=validate_existing_id).accepted: 
     273        newLognum = calcNextLogNum(form.vars.existingid) 
     274        if newLognum == '1': 
     275            newID = calcNextClosureID(form.vars.route) 
     276        else: 
     277            newID = form.vars.existingid 
     278        supervisor_name = form.vars.supervisor[3:] 
     279        fieldrep_name = form.vars.fieldrep[5:] 
    229280        # Insert the record into the database 
    230         newrec = db.closures.insert(closureid=newID, lognum='1', route=form.vars.route, direction=form.vars.direction, facility=form.vars.facility, startcounty=form.vars.startcounty, endcounty=form.vars.endcounty, startlocation=form.vars.startlocation, endlocation=form.vars.endlocation, startdate=form.vars.startdate, enddate=form.vars.enddate, starttime=form.vars.starttime+form.vars.starttimemin, endtime=form.vars.endtime+form.vars.endtimemin, closuretype=form.vars.closuretype, worktype=form.vars.worktype, estdelay=form.vars.estdelay, tmpcozeep=getCheckbox(form.vars.cozeep), tmpdetour=getCheckbox(form.vars.detour), supervisor=form.vars.supervisor, fieldrep=form.vars.fieldrep, ) 
    231         session.flash = 'New lane closure added: ' + newID 
     281        newrec = db.closures.insert(closureid=newID, lognum=newLognum, route=form.vars.route, direction=form.vars.direction, facility=form.vars.facility, startcounty=form.vars.startcounty, endcounty=form.vars.endcounty, startlocation=form.vars.startlocation, endlocation=form.vars.endlocation, startdate=form.vars.startdate, enddate=form.vars.enddate, starttime=form.vars.starttime+form.vars.starttimemin, endtime=form.vars.endtime+form.vars.endtimemin, closuretype=form.vars.closuretype, worktype=form.vars.worktype, estdelay=form.vars.estdelay, tmpcozeep=getCheckbox(form.vars.cozeep), tmpdetour=getCheckbox(form.vars.detour), supervisor=supervisor_name, fieldrep=fieldrep_name, s1097date='', s1098date='', s1022date='' ) 
     282        session.flash = 'New lane closure added: ' + newID + ' ' + newLognum 
    232283        redirect(URL('search.html')) 
    233284    return dict(form=form) 
    234285 
     286# Validation for existing closure button 
     287# If user selected Yes (it's existing incident) then they must select a closure ID 
     288def validate_existing_id(form): 
     289    if form.vars.existing == 'Yes' and form.vars.existingid == '': 
     290        form.errors.existingid = "Existing incidents require selecting an existing closure ID" 
     291 
    235292# Calculate the closure id to assign to the new closure 
    236 def calcNextClosure(routeNum): 
     293def calcNextClosureID(routeNum): 
    237294    # Retrieve any existing closures on this route 
    238295    item = db(db.closures.closureid.startswith('T'+routeNum)).select().last() # Might need to sort these 
     
    245302    else: 
    246303        return 'T'+routeNum+'AA'  # For a non-existing route 
     304     
     305# If existing incident closure ID is provided, increment the log number by 1 
     306def calcNextLogNum(existingid): 
     307    if existingid != '': 
     308        item = db(db.closures.closureid.startswith(existingid)).select().last() 
     309        prevLog = int(item.lognum) 
     310        nextLog = prevLog + 1 
     311        return str(nextLog) 
     312    else: 
     313        return '1' 
     314 
    247315 
    248316# Convert checkbox value to YES/NO 
Note: See TracChangeset for help on using the changeset viewer.