Changeset 2193
- Timestamp:
- 10/13/10 14:39:47 (19 months ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 13 edited
-
common/miztools/mizitem.py (modified) (1 diff)
-
lodyn/development.db (modified) (previous)
-
lodyn/lodyn/controllers/campaign.py (modified) (7 diffs)
-
lodyn/lodyn/controllers/mission.py (modified) (4 diffs)
-
lodyn/lodyn/controllers/objective.py (modified) (6 diffs)
-
lodyn/lodyn/lib/campaignmanager.py (modified) (1 diff)
-
lodyn/lodyn/lib/mission_loader.py (modified) (7 diffs)
-
lodyn/lodyn/model/databases.py (modified) (2 diffs)
-
lodyn/lodyn/model/loobjects.py (modified) (3 diffs)
-
lodyn/lodyn/model/webobjects.py (modified) (14 diffs)
-
lodyn/lodyn/templates/derived/page/campaign.html (modified) (3 diffs)
-
lodyn/lodyn/templates/derived/page/objective.html (modified) (13 diffs)
-
lodyn/lodyn/templates/derived/page/sub_campaign_files.html (deleted)
-
lodyn/lodyn/templates/derived/page/sub_campaign_objectives.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/common/miztools/mizitem.py
r2172 r2193 24 24 class MizItem(object): 25 25 field_numbers_regex = re.compile(r"(?P<name>[\[\]\w\-_]+)\s*?=\s*?(?P<value>[^\"\{\}]+?)\s*?," ) 26 field_strings_regex = re.compile(r"(?s)(?P<name>[\[\]\w\-_]+)\s*?=\s*?\"(?P<value>\{*?.+? [^\\\{\}]\}*?)\"\s*?,")26 field_strings_regex = re.compile(r"(?s)(?P<name>[\[\]\w\-_]+)\s*?=\s*?\"(?P<value>\{*?.+?\}*?)\"\s*?,") 27 27 array_regex = re.compile( r"\[(\d+)\]" ) 28 28 #---------------------------------------------------------------- -
trunk/lodyn/lodyn/controllers/campaign.py
r2192 r2193 29 29 #---------------------------------------------------------------- 30 30 def index(self): 31 c.coalition = PLAYER_COALITION 31 32 return render('/derived/page/campaign.html') 32 33 #---------------------------------------------------------------- … … 61 62 'squadrons': squadrons 62 63 } 63 item.update( camp.to_json() ) 64 if h.auth.is_creator(request.environ): 65 item.update( camp.to_json() ) 66 else: 67 item.update( camp.to_json(only_objectives_visible=True) ) 64 68 65 69 d['items'].append( item ) … … 96 100 'squadrons': squadrons 97 101 } 98 items.update( camp.to_json(True) ) 102 if h.auth.is_creator(request.environ): 103 items.update( camp.to_json(full=True) ) 104 else: 105 items.update( camp.to_json(full=True, only_objectives_visible=True) ) 99 106 100 107 d['items'] = items … … 277 284 """ Get all airports """ 278 285 values = dict(request.params) 279 print " GET ALL GROUPS"280 286 281 287 try: … … 315 321 @ActionProtector(not_anonymous()) 316 322 @jsonify 317 def getallcoagroups(self): 318 """ Get all airports """ 319 values = dict(request.params) 320 print " GET ALL GROUPS" 323 def getallcoabattalions(self): 324 """ Get all coalitions battalions """ 325 values = dict(request.params) 321 326 322 327 try: … … 331 336 if not camp: return {'response': False, 'reason':_("Campaign not found") } 332 337 333 obj_q = meta.Session.query(model.L oGroup)338 obj_q = meta.Session.query(model.LBattalion) 334 339 route_q = meta.Session.query(model.LoRoute) 335 340 db_loobj_q = meta.Session.query(model.LoObject) … … 337 342 if obj.coalition != PLAYER_COALITION: 338 343 continue 339 points = [] 340 if not obj.route_id: continue 341 route = route_q.get( obj.route_id ) 342 for p in route.points: 343 points.append( { 'lat': p.lat, 'long': p.long } ) 344 mapclasskey = "" 345 if obj.lounits: 346 loo = db_loobj_q.get( obj.lounits[0].loobject_id ) 347 if loo: mapclasskey = loo.mapclasskey 348 t_d = { 349 'name':obj.name, 350 'mapclasskey':mapclasskey.replace("P00", "P"), 351 'points': points 352 } 353 t_d.update( obj.to_json() ) 354 d['items'].append(t_d) 355 return d 344 batt = obj.to_json() 345 batt['versions'] = [] 346 for mizfile in obj.versions: 347 version = mizfile.to_json() 348 version['groups'] = [] 349 for grp in mizfile.groups: 350 points = [] 351 if not grp.route_id: continue 352 route = route_q.get( grp.route_id ) 353 for p in route.points: 354 points.append( { 'lat': p.lat, 'long': p.long } ) 355 mapclasskey = "" 356 if grp.lounits: 357 loo = db_loobj_q.get( grp.lounits[0].loobject_id ) 358 if loo: mapclasskey = loo.mapclasskey 359 t_d = { 360 'name':grp.name, 361 'mapclasskey':mapclasskey.replace("P00", "P"), 362 'points': points 363 } 364 t_d.update( grp.to_json() ) 365 version['groups'].append( t_d ) 366 batt['versions'].append( version ) 367 d['items'].append(batt) 368 return d -
trunk/lodyn/lodyn/controllers/mission.py
r2192 r2193 76 76 d['groups'].append( t_d ) 77 77 d["mission"] = db_mis.to_json() 78 d.update( mizfile.to_json( True) )78 d.update( mizfile.to_json(full=True) ) 79 79 return d 80 80 #---------------------------------------------------------------- … … 426 426 if not mission: return {'response':False, 'reason':_("Mission does not exists") } 427 427 d = { 'response':True, } 428 d.update( mission.to_json( True) )428 d.update( mission.to_json(full=True) ) 429 429 return d 430 430 #---------------------------------------------------------------- … … 516 516 meta.Session.commit() 517 517 d = {'response': True} 518 d.update( mis.to_json( True) )518 d.update( mis.to_json(full=True) ) 519 519 return d 520 520 #---------------------------------------------------------------- … … 545 545 meta.Session.commit() 546 546 d = {'response': True} 547 d.update( mis.to_json( True) )547 d.update( mis.to_json(full=True) ) 548 548 return d 549 549 #---------------------------------------------------------------- -
trunk/lodyn/lodyn/controllers/objective.py
r2192 r2193 41 41 d= {'response':True, 'items':[] } 42 42 for obj in objectives: 43 d['items'].append( obj.to_json() ) 44 return d 45 #---------------------------------------------------------------- 46 @ActionProtector(has_permission('creator')) 47 @jsonify 48 def create(self): 49 values = dict(request.params) 50 try: 51 name = values['name'] 52 campaign_name = values['campaign_name'] 53 except: 54 return {'response': False, 'reason':_("Bad parameters") } 55 obj_q = meta.Session.query(model.LObjective) 56 objective = obj_q.filter_by(name=name).first() 57 58 if objective: return {'response':False, 'reason':_("Objective already exists") } 59 60 camp_q = meta.Session.query(model.LCampaign) 61 camp = camp_q.filter_by(name=campaign_name).first() 62 if not camp: return {'response':False, 'reason':_("Campaign does not exist") } 63 64 db_c = model.LObjective() 65 db_c.name = name 66 db_c.status = model.LObjective.INACTIVE 67 db_c.description = _("Enter a description") 68 camp.objectives.append( db_c ) 69 meta.Session.add( db_c ) 70 meta.Session.commit() 71 72 d= {'response':True, 'objectives':[] } 73 objectives = obj_q.filter_by(campaign_id=camp.id).all() 74 75 for obj in objectives: 76 d['objectives'].append( obj.to_json() ) 43 if has_permission('creator'): 44 d['items'].append( obj.to_json() ) 45 elif obj.visible: 46 d['items'].append( obj.to_json() ) 77 47 return d 78 48 #---------------------------------------------------------------- … … 97 67 if not objective: return {'response':False, 'reason':_("Objective does not exists") } 98 68 d = { 'response':True, } 99 d.update( objective.to_json( True) )69 d.update( objective.to_json(full=True) ) 100 70 return d 101 71 #---------------------------------------------------------------- … … 119 89 if not obj: return {'response': False, 'reason':_("Objective not found") } 120 90 91 if item == "visible": data = (data == 'true') 121 92 setattr( obj, item, data) 122 93 meta.Session.commit() … … 176 147 if not hasattr( obj, role): return {'response': False, 'reason':_("Role not found") } 177 148 178 print objects 179 group_q = meta.Session.query(model.LoGroup) 180 for grp in objects.split(','): 181 db_g = group_q.get(uuid.UUID(grp)) 182 if db_g: 183 getattr(obj, role).append( db_g ) 149 battalion_q = meta.Session.query(model.LBattalion) 150 for bat in objects.split(','): 151 db_b = battalion_q.get(uuid.UUID(bat)) 152 if db_b: 153 getattr(obj, role).append( db_b ) 184 154 185 155 meta.Session.commit() … … 211 181 if not hasattr( obj, role): return {'response': False, 'reason':_("Role not found") } 212 182 213 print objects 214 group_q = meta.Session.query(model.LoGroup) 215 for grp in objects.split(','): 216 db_g = group_q.get(uuid.UUID(grp)) 217 if db_g: 218 getattr(obj, role).remove( db_g ) 183 battalion_q = meta.Session.query(model.LBattalion) 184 for bat in objects.split(','): 185 db_b = battalion_q.get(uuid.UUID(bat)) 186 if db_b: 187 getattr(obj, role).remove( db_b ) 219 188 220 189 meta.Session.commit() … … 225 194 print "ERROR while acceds to objective with role " + role 226 195 return {'response': True, role:new_datas} 196 #---------------------------------------------------------------- 197 @ActionProtector(not_anonymous()) 198 @jsonify 199 def getdefensesgroups(self): 200 """ Get all defenses groups for this objectives """ 201 values = dict(request.params) 202 203 try: 204 id = values['id'] 205 except: 206 return {'response': False, 'reason':_("Bad parameters") } 207 208 obj_q = meta.Session.query(model.LObjective) 209 d = { 'response': True, 'datas':[]} 210 211 obj = obj_q.get( uuid.UUID( id ) ) 212 if not obj: return {'response': False, 'reason':_("Objective not found") } 213 214 grp_q = meta.Session.query(model.LoGroup) 215 route_q = meta.Session.query(model.LoRoute) 216 db_loobj_q = meta.Session.query(model.LoObject) 217 d = {'response': True, 'items':[]} 218 for grp in obj.defense_groups: 219 points = [] 220 if not grp.route_id: continue 221 route = route_q.get( grp.route_id ) 222 for p in route.points: 223 points.append( { 'lat': p.lat, 'long': p.long } ) 224 mapclasskey = "" 225 if grp.lounits: 226 loo = db_loobj_q.get( grp.lounits[0].loobject_id ) 227 if loo: mapclasskey = loo.mapclasskey 228 t_d = { 229 'mapclasskey':mapclasskey.replace("P00", "P"), 230 'points': points 231 } 232 t_d.update( grp.to_json() ) 233 d['items'].append( t_d ) 234 return d -
trunk/lodyn/lodyn/lib/campaignmanager.py
r2185 r2193 51 51 os.mkdir( os.path.join( path, db_c.name ) ) 52 52 #-- Missions 53 os.mkdir( os.path.join( path, db_c.name, self.MISSION_DIR ) ) 53 os.mkdir( os.path.join( path, db_c.name, "missions" ) ) 54 os.mkdir( os.path.join( path, db_c.name, "missions", "battalions" ) ) 55 os.mkdir( os.path.join( path, db_c.name, "missions", "objectives" ) ) 54 56 except: 55 57 #- try to load the master -
trunk/lodyn/lodyn/lib/mission_loader.py
r2187 r2193 16 16 class MissionLoader(object): 17 17 MISSION_DIR = 'missions' 18 OBJECTIVES_DIR = 'objectives' 19 BATTALIONS_DIR = 'battalions' 18 20 MIS_FILES = ".miz" 19 21 #------------------------------------------------------- 20 22 def __init__(self, campaign_path): 21 self.files = [] 23 self.coalitions = { 24 'blue' : { 25 'objectives':[], 26 'battalions': {} 27 }, 28 'red' : { 29 'objectives':[], 30 'battalions': {} 31 } 32 } 33 22 34 self.countries = {} 23 35 self.campaign_path = campaign_path … … 26 38 """ List all mission files """ 27 39 #- Load mission 40 new_files = [] 28 41 29 misfiles = []30 31 #- First static ones32 42 path = os.path.join( self.campaign_path, self.MISSION_DIR ) 33 43 34 for root, dirs, files in os.walk(path): 35 for name in files: 36 if name.endswith( self.MIS_FILES ): 37 misfiles.append( os.path.join(root, name) ) 38 return misfiles 39 44 for coa in self.coalitions.iterkeys(): 45 #- Fill objectives 46 obj_dir = os.path.join(path, coa, self.OBJECTIVES_DIR) 47 for f in os.listdir( obj_dir ): 48 if f.endswith( self.MIS_FILES ): 49 full = os.path.join(obj_dir, f) 50 if not full in self.coalitions[coa]['objectives']: 51 self.coalitions[coa]['objectives'].append( full ) 52 new_files.append(full) 53 54 #- Fill battalions 55 bats_dir = os.path.join(path, coa, self.BATTALIONS_DIR) 56 for d in os.listdir( bats_dir ): 57 bat_dir = os.path.join( bats_dir, d ) 58 if os.path.isdir( bat_dir ): 59 if not self.coalitions[coa]['battalions'].has_key( d ): 60 self.coalitions[coa]['battalions'][d] = [] 61 for f in os.listdir( bat_dir ): 62 if f.endswith( self.MIS_FILES ): 63 full = os.path.join(bat_dir, f) 64 if not full in self.coalitions[coa]['battalions'][d]: 65 self.coalitions[coa]['battalions'][d].append( full ) 66 new_files.append( full ) 67 return new_files 40 68 #------------------------------------------------------- 41 69 def _get_md5sum(self, fileName, excludeLine="", includeLine=""): … … 61 89 #- Get all filenames 62 90 files = self.list_all() 63 64 md5dict = {} 91 65 92 db_mizfile_q = meta.Session.query(model.LMizFile) 66 for mf in db_mizfile_q.all(): 67 md5dict[ mf.filename ] = mf 68 69 #- Process 70 for f in files: 71 print "Check", f 72 md5sum = self._get_md5sum( f ) 73 need_update = False 74 db_file = None 75 if f in self.files: 76 if md5dict[ f.replace( self.campaign_path, "") ].md5sum != md5sum: 77 print "-"*20 78 print f, "has changed" 79 print "-"*20 80 need_update = True 81 db_file = mf 82 else: 83 need_update = True 84 if need_update: 85 print "MISSION LOAD", f 86 if not db_file: 87 db_file = LMizFile() 88 db_file.filename = f.replace( self.campaign_path, "") 89 db_file.name = os.path.basename( f ).replace( self.MIS_FILES, "") 90 91 meta.Session.add( db_file ) 92 meta.Session.commit() 93 db_camp.lofiles.append( db_file ) 94 self.files.append( f ) 95 96 db_file.md5sum = md5sum 97 self.load_mission( db_file, f ) 98 99 meta.Session.commit() 100 return self.files 101 93 db_objective_q = meta.Session.query(model.LObjective) 94 db_battalion_q = meta.Session.query(model.LBattalion) 95 96 for coa in self.coalitions.iterkeys(): 97 for objective in self.coalitions[coa]['objectives']: 98 if not db_mizfile_q.filter_by(filename=objective.replace( self.campaign_path, "")).first(): 99 self.load_objective( objective, db_camp ) 100 101 for k, versions in self.coalitions[coa]['battalions'].iteritems(): 102 db_battalion = db_battalion_q.filter_by(name=k, coalition=coa).first() 103 if not db_battalion: db_battalion = self.load_battalion( k, coa, db_camp ) 104 for version in versions: 105 self.load_battalion_version( db_battalion, version, db_camp ) 106 #------------------------------------------------------- 107 def load_objective(self, f, db_camp): 108 print "LOAD OBJECTIVE" , f 109 db_file = LMizFile() 110 db_file.filename = f.replace( self.campaign_path, "") 111 db_file.name = os.path.basename( f ).replace( self.MIS_FILES, "") 112 113 meta.Session.add( db_file ) 114 meta.Session.commit() 115 116 #- Create objective 117 db_objective = LObjective() 118 db_objective.campaign_id = db_camp.id 119 db_objective.mizfile_id = db_file.id 120 meta.Session.add( db_objective ) 121 meta.Session.commit() 122 123 self.load_mission( db_file, f, db_objective ) 124 125 126 db_objective.name = db_file.name 127 if db_file.description: 128 db_objective.description = db_file.description 129 130 131 db_camp.objectives.append( db_objective ) 132 meta.Session.commit() 133 #------------------------------------------------------- 134 def load_battalion(self, battalion, coa, db_camp): 135 print "LOAD BATTALION" , battalion 136 db_battalion = LBattalion() 137 db_battalion.name = battalion 138 db_battalion.coalition = coa 139 db_battalion.campaign_id = db_camp.id 140 meta.Session.add( db_battalion ) 141 meta.Session.commit() 142 db_camp.battalions.append( db_battalion ) 143 meta.Session.commit() 144 return db_battalion 145 146 #------------------------------------------------------- 147 def load_battalion_version(self, db_battalion, f, db_camp): 148 print "LOAD BATTALION VERSION" , f 149 db_file = LMizFile() 150 db_file.filename = f.replace( self.campaign_path, "") 151 db_file.name = os.path.basename( f ).replace( self.MIS_FILES, "") 152 153 meta.Session.add( db_file ) 154 meta.Session.commit() 155 156 self.load_mission( db_file, f ) 157 db_battalion.versions.append( db_file ) 158 159 meta.Session.commit() 102 160 #------------------------------------------------------- 103 161 def load_master_mission(self): … … 123 181 return True 124 182 #------------------------------------------------------- 125 def load_mission(self, db_file, filename ):183 def load_mission(self, db_file, filename, db_obj=None): 126 184 """ Load mission file """ 127 185 f = mizfile.MizFile( filename ) … … 130 188 mission = f.miz_loader.mission 131 189 132 #- Clean if exists133 db_mission_q = meta.Session.query(model.LoMission)134 db_mis = db_mission_q.filter_by(mizfile_id=db_file.id).first()135 if db_mis:136 db_mis.clean()137 138 139 if not db_mis:140 db_mis = LoMission()141 db_mis.mizfile_id = db_file.id142 meta.Session.add( db_mis )143 144 190 db_count_q = meta.Session.query(model.LoCountry) 145 191 db_loobj_q = meta.Session.query(model.LoObject) 146 192 147 db_ mis.description = mission["mission"]["descriptionText"]193 db_file.description = mission["mission"]["descriptionText"] 148 194 149 195 for coa in ["blue", "red"]: … … 154 200 db_group.campaign_id = db_file.campaign_id 155 201 db_group.object_type = g.parent.parent.name 156 db_ mis.groups.append( db_group )202 db_file.groups.append( db_group ) 157 203 c_name = g.parent.parent.parent["name"] 158 204 db_c = db_count_q.filter_by(name=c_name).first() … … 193 239 for it in ["speed", "alt", "type", "action"]: 194 240 setattr(db_p, it, u[it]) 195 meta.Session.commit() 196 197 241 if db_obj: 242 for trigzone in mission["mission"]["triggers"]["zones"].items(): 243 if trigzone['name'].startswith("DEFENSE_"): 244 db_defense_slot = LDefenseSlot() 245 db_defense_slot.name = trigzone['name'].replace("DEFENSE_", "") 246 db_defense_slot.lat = float(trigzone["lat"]) 247 db_defense_slot.long = float(trigzone["long"]) 248 db_defense_slot.x = float(trigzone["x"]) 249 db_defense_slot.y = float(trigzone["y"]) 250 db_defense_slot.objective_id = db_obj.id 251 meta.Session.add( db_defense_slot ) 252 meta.Session.commit() 253 db_obj.defenses_slots.append( db_defense_slot ) 254 meta.Session.commit() 255 256 -
trunk/lodyn/lodyn/model/databases.py
r2192 r2193 7 7 8 8 9 9 from constants import PLAYER_COALITION 10 10 from lodyn.model import meta 11 11 import uuid, datetime … … 18 18 19 19 class LBase: 20 def get_items(self, item, full=False): 20 def check_item( self, item, k ): 21 return k.has_key(item) and k[item] 22 def get_items(self, item, full=False, **k): 21 23 ls = [] 22 24 for l in getattr(self, item): 23 ls.append(l.to_json(full)) 25 d = l.to_json(full=full, **k) 26 if d: ls.append(d) 27 return ls 28 29 def get_coa_items(self, item, full=False): 30 ls = [] 31 for l in getattr(self, item): 32 if hasattr( l, 'coalition'): 33 if l.coalition == PLAYER_COALITION: 34 d = l.to_json(full=full, **k) 35 if d: ls.append(d) 36 else: 37 d = l.to_json(full=full, **k) 38 if d: ls.append(d) 24 39 return ls 25 40 -
trunk/lodyn/lodyn/model/loobjects.py
r2192 r2193 55 55 #- Can be plane|helicopter|car|ship 56 56 57 mission_id = sa.Column(UUID(), ForeignKey('lomissions.id'))58 57 name = sa.Column(sa.types.String, nullable=False) 59 58 coalition = sa.Column(sa.types.String, nullable=False) … … 62 61 country_id = sa.Column(UUID(), ForeignKey('locountries.id')) 63 62 campaign_id = sa.Column(UUID(), ForeignKey('lcampaigns.id')) 63 mizfile_id = sa.Column(UUID(), ForeignKey('lmizfiles.id')) 64 64 65 65 def to_json(self, full=False): … … 234 234 country = sa.Column(sa.types.String) 235 235 picture = sa.Column(sa.types.String) 236 #----------------------------------------------------------------237 class LoMission(Base, LBase):238 """239 Stores all lofc2 missions240 """241 __tablename__ = 'lomissions'242 id = sa.Column(UUID(), primary_key=True,default=uuid.uuid4)243 groups = orm.relation("LoGroup", backref="mission")244 mizfile_id = sa.Column(UUID(), ForeignKey('lmizfiles.id'), nullable=False)245 description = sa.Column(sa.types.String )246 247 def to_json(self, full=False):248 return {249 'id': str(self.id),250 'description': self.description,251 }252 def clean(self):253 db_clean_array( self.groups ) -
trunk/lodyn/lodyn/model/webobjects.py
r2192 r2193 30 30 description = sa.Column(sa.types.String ) 31 31 objectives = orm.relation("LObjective", backref="campaign") 32 battalions = orm.relation("LBattalion", backref="campaign") 32 33 comments = orm.relation("LCampaignComment", backref="campaign") 33 34 missions = orm.relation("LMission", backref="campaign") 34 lofiles = orm.relation("LMizFile", backref="campaign")35 35 squadrons = orm.relation('LSquadron', secondary=lcampaigns_lsquadrons, backref='campaigns') 36 36 master = sa.Column(sa.types.Boolean ) … … 45 45 self.master = False 46 46 47 def to_json(self, full=False ):47 def to_json(self, full=False, **k): 48 48 d = { 49 49 'name': self.name, … … 55 55 if full: 56 56 d.update( { 57 'comments': self.get_items("comments", True ),58 ' lofiles' : self.get_items("lofiles", True),59 ' objectives' : self.get_items("objectives", True),60 'missions' : self.get_items("missions", True ),57 'comments': self.get_items("comments", True, **k), 58 'objectives' : self.get_items("objectives", True, **k), 59 'battalions' : self.get_items("battalions", True, **k), 60 'missions' : self.get_items("missions", True, **k), 61 61 }) 62 62 return d … … 92 92 self.duration = 120 93 93 self.date = datetime.datetime.now() + datetime.timedelta(hours=2) 94 def to_json(self, full=False ):94 def to_json(self, full=False, **k): 95 95 d = { 96 96 'name': self.name, … … 103 103 if full: 104 104 d.update( { 105 'comments': self.get_items("comments", True ),106 'objectives' : self.get_items("objectives", True ),105 'comments': self.get_items("comments", True, **k), 106 'objectives' : self.get_items("objectives", True, **k), 107 107 }) 108 108 return d … … 125 125 def __init__(self): 126 126 self.datetime = datetime.datetime.now() 127 def to_json(self, full=False ):127 def to_json(self, full=False, **k): 128 128 return { 129 129 'title':self.title, … … 160 160 name = sa.Column(sa.types.String ) 161 161 filename = sa.Column(sa.types.String ) 162 description = sa.Column(sa.types.String ) 162 163 md5sum = sa.Column(sa.types.String ) 163 164 campaign_id = sa.Column(UUID(), ForeignKey('lcampaigns.id')) 165 battalion_id = sa.Column(UUID(), ForeignKey('lbattalions.id')) 164 166 comments = orm.relation("LMizFileComment", backref="mizfile") 167 groups = orm.relation("LoGroup", backref="mizfile") 165 168 166 169 mode = sa.Column(sa.types.Integer ) … … 170 173 KILLED = 2 171 174 172 def to_json(self, full=False ):175 def to_json(self, full=False, **k): 173 176 d = { 174 177 'name': self.name, … … 177 180 'mode': self.mode, 178 181 'current_mode': self.current_mode, 182 'description': self.description, 179 183 } 180 184 if full: 181 185 d.update({ 182 'comments': self.get_items( "comments", True ),186 'comments': self.get_items( "comments", True, **k), 183 187 }) 184 188 return d … … 204 208 self.designator = "F-${plane_id} ${pilot_name}" 205 209 #---------------------------------------------------------------- 206 lobjectives_l ogroups_defense = sa.Table('lobjectives_logroups_defense', metadata,210 lobjectives_lbattalions_defense = sa.Table('lobjectives_lbattalions_defense', metadata, 207 211 sa.Column('lobjective_id', UUID(), ForeignKey('lobjectives.id')), 208 sa.Column('l ogroups_id', UUID(), ForeignKey('logroups.id'))212 sa.Column('lbattalions_id', UUID(), ForeignKey('lbattalions.id')) 209 213 ) 210 214 #---------------------------------------------------------------- 211 lobjectives_l ogroups_useby = sa.Table('lobjectives_logroups_useby', metadata,215 lobjectives_lbattalions_useby = sa.Table('lobjectives_lbattalions_useby', metadata, 212 216 sa.Column('lobjective_id', UUID(), ForeignKey('lobjectives.id')), 213 sa.Column('l ogroups_id', UUID(), ForeignKey('logroups.id'))217 sa.Column('lbattalions_id', UUID(), ForeignKey('lbattalions.id')) 214 218 ) 215 219 #---------------------------------------------------------------- … … 220 224 __tablename__ = 'lobjectives' 221 225 id = sa.Column(UUID(), primary_key=True,default=uuid.uuid4) 222 name = sa.Column(sa.types.String , nullable=False)226 name = sa.Column(sa.types.String) 223 227 description = sa.Column(sa.types.String ) 224 228 campaign_id = sa.Column(UUID(), ForeignKey('lcampaigns.id'), nullable=False) 225 229 comments = orm.relation("LObjectiveComment", backref="objective") 226 227 defenses = orm.relation('LoGroup', secondary=lobjectives_logroups_defense, backref='objectives_defense') 228 use_by = orm.relation('LoGroup', secondary=lobjectives_logroups_useby, backref='objectives_use_by') 229 230 mizfile_id = sa.Column(UUID(), ForeignKey('lmizfiles.id'), nullable=False) 231 232 defenses_slots = orm.relation('LDefenseSlot', backref='objective') 233 defenses = orm.relation('LBattalion', secondary=lobjectives_lbattalions_defense, backref='objectives_defense') 234 use_by = orm.relation('LBattalion', secondary=lobjectives_lbattalions_useby, backref='objectives_use_by') 235 236 visible = sa.Column(sa.types.Boolean ) 237 priority = sa.Column(sa.types.Integer ) 230 238 status = sa.Column(sa.types.Integer ) 231 239 INACTIVE = 0 … … 235 243 def __init__(self): 236 244 self.status = self.INACTIVE 237 def to_json(self, full=False): 245 self.visible = True 246 self.description = "" 247 def to_json(self, full=False, **k): 248 if self.check_item('only_objectives_visible', k) and not self.visible: return {} 238 249 d ={ 239 250 'name': self.name, … … 241 252 'description': self.description, 242 253 'status': self.status, 254 'priority': self.priority, 255 'visible': self.visible, 243 256 } 244 257 if full: 245 258 d.update( { 246 'comments': self.get_items("comments", full), 247 'defenses': self.get_items("defenses", full), 248 'use_by': self.get_items("use_by", full), 259 'comments': self.get_items("comments", full, **k), 260 'defenses': self.get_items("defenses", full, **k), 261 'defenses_slots': self.get_items("defenses_slots", full, **k), 262 'use_by': self.get_items("use_by", full, **k), 249 263 }) 250 264 return d … … 257 271 def get_all_roles_obj(self): 258 272 return self.defenses + self.use_by 259 273 #---------------------------------------------------------------- 274 class LDefenseSlot(Base, LBase): 275 """ 276 Stores all defenses slot 277 """ 278 __tablename__ = 'ldefensesslots' 279 id = sa.Column(UUID(), primary_key=True,default=uuid.uuid4) 280 name = sa.Column(sa.types.String, nullable=False) 281 x = sa.Column(sa.types.Float) 282 y = sa.Column(sa.types.Float) 283 lat = sa.Column(sa.types.Float) 284 long = sa.Column(sa.types.Float) 285 objective_id = sa.Column(UUID(), ForeignKey('lobjectives.id'), nullable=False) 286 battalion_id = sa.Column(UUID(), ForeignKey('lbattalions.id')) 287 def to_json(self, full=False, **k): 288 d ={ 289 'name': self.name, 290 'id': str(self.id), 291 'x': self.x, 292 'y': self.y, 293 'lat': self.lat, 294 'long': self.long, 295 } 296 return d 297 #---------------------------------------------------------------- 298 class LBattalion(Base, LBase): 299 """ 300 Stores all battalions 301 """ 302 __tablename__ = 'lbattalions' 303 id = sa.Column(UUID(), primary_key=True,default=uuid.uuid4) 304 name = sa.Column(sa.types.String, nullable=False) 305 description = sa.Column(sa.types.String ) 306 campaign_id = sa.Column(UUID(), ForeignKey('lcampaigns.id'), nullable=False) 307 versions = orm.relation('LMizFile', backref='battalion') 308 coalition = sa.Column(sa.types.String, nullable=False) 309 310 status = sa.Column(sa.types.Integer ) 311 INACTIVE = 0 312 ACTIVE = 1 313 DESTROYED = 2 314 def __init__(self): 315 self.status = self.INACTIVE 316 def to_json(self, full=False, **k): 317 d ={ 318 'name': self.name, 319 'id': str(self.id), 320 'description': self.description, 321 'status': self.status, 322 'coalition': self.coalition, 323 } 324 if full: 325 d.update( { 326 'versions': self.get_items("versions", full, **k), 327 }) 328 return d 329 -
trunk/lodyn/lodyn/templates/derived/page/campaign.html
r2192 r2193 175 175 176 176 } 177 /** LOFiles **/178 cont = dojo.byId('filesList');179 if( cont != null )180 {181 dojo.empty(cont);182 for( i=0; i<item.lofiles.length;i++)183 {184 var file = item.lofiles[i];185 var name = file.name;186 var c = dojo.doc.createElement('a');187 c.innerHTML = name;188 c.href = '${h.url_for(controller="mission", action="mizfile" )}/' + name;189 c.target = "_blank";190 cont.appendChild(c);191 192 /* if( file.mode == 2 ) */193 /* dojo.setStyle( c, "text-decoration", "line-through"); */194 195 cont.appendChild(dojo.doc.createElement('br'));196 }197 }198 177 load_objectives(); 199 178 load_missions(); … … 212 191 var name = obj.name; 213 192 var c = dojo.doc.createElement('a'); 193 % if h.auth.is_creator(request.environ): 194 if( obj.visible ) 195 c.innerHTML = name; 196 else 197 c.innerHTML = "(" + name + ")"; 198 % else: 214 199 c.innerHTML = name; 200 % endif 215 201 c.href = '${h.url_for(controller="objective", action="show" )}/' + obj.id; 216 202 c.target = "_blank"; … … 364 350 <%include file="/derived/page/sub_campaign_objectives.html" /> 365 351 <%include file="/derived/page/sub_campaign_missions.html" /> 366 <%include file="/derived/page/sub_campaign_files.html" />367 352 </div> 368 353 </div> -
trunk/lodyn/lodyn/templates/derived/page/objective.html
r2192 r2193 5 5 dojo.require("dijit.layout.ContentPane"); 6 6 dojo.require("dijit.form.MultiSelect"); 7 dojo.require("dijit.form.CheckBox"); 7 8 dojo.require("dojo.data.ItemFileReadStore"); 8 9 9 10 var objective = null; 10 var all_groups = null; 11 var all_battalions = null; 12 var defense_layer = null; 11 13 var defense_groups = null; 12 var use_by_ groups= null;14 var use_by_layer = null; 13 15 14 16 dojo.addOnLoad( function init(){ 15 17 dojo.xhrPost({ 16 18 content : { name: "${c.campaign_name}" }, 17 url: '${h.url_for(controller="campaign", action="getallcoa groups")}',19 url: '${h.url_for(controller="campaign", action="getallcoabattalions")}', 18 20 load: function(response, ioArgs) 19 21 { … … 21 23 if( obj.response ) 22 24 { 23 all_ groups = obj.items;25 all_battalions = obj.items; 24 26 }else{ 25 27 alert( obj.reason ); … … 47 49 { 48 50 dojo.byId('name').innerHTML = objective.name; 51 dojo.byId('priority').innerHTML = objective.priority; 52 % if h.auth.is_creator(request.environ): 53 dijit.byId('visible').set( 'checked', objective.visible ); 54 % endif 55 dojo.byId('defenseslots').innerHTML = objective.defenses_slots.length; 49 56 dijit.byId('description').set( 'value', objective.description ); 50 57 … … 56 63 { 57 64 var i; 58 if( ! defense_ groups)59 { 60 defense_ groups= new OpenLayers.Layer.Vector( "${_('Defenses')}" );61 map.addLayers([ defense_ groups]);62 } 63 defense_ groups.removeAllFeatures();64 if( ! use_by_groups)65 {66 use_by_groups= new OpenLayers.Layer.Vector( "${_('Use By')}" );67 map.addLayers([ use_by_groups]);68 }69 use_by_groups.removeAllFeatures();65 if( ! defense_layer ) 66 { 67 defense_layer = new OpenLayers.Layer.Vector( "${_('Defenses')}" ); 68 map.addLayers([ defense_layer ]); 69 } 70 defense_layer.removeAllFeatures(); 71 // if( ! use_by_layer ) 72 // { 73 // use_by_layer = new OpenLayers.Layer.Vector( "${_('Use By')}" ); 74 // map.addLayers([ use_by_layer ]); 75 // } 76 // use_by_layer.removeAllFeatures(); 70 77 var i; 71 78 var group; 72 var is_defense; 73 var is_use_by; 74 for( i=0; i<all_groups.length;i++) 75 { 76 group = all_groups[i]; 77 is_defense = false; 78 is_use_by = false; 79 for( j=0; j<objective.defenses.length; j++) 80 { 81 if( objective.defenses[j].id == group.id ) 82 { 83 is_defense = true; 84 break; 85 } 86 } 87 for( j=0; j<objective.use_by.length; j++) 88 { 89 if( objective.use_by[j].id == group.id ) 90 { 91 is_use_by = true; 92 break; 93 } 94 } 95 if ( is_defense ) 96 { 97 defense_groups.addFeatures( 98 add_pov( group.points[0].long, 99 group.points[0].lat, 100 '/images/map/nato/'+ group.coalition + "/" + group.mapclasskey + '.png', 101 20, 20 ) 102 ); 103 } 104 if ( is_use_by ) 105 { 106 use_by_groups.addFeatures( 107 add_pov( group.points[0].long, 108 group.points[0].lat, 109 '/images/map/nato/'+ group.coalition + "/" + group.mapclasskey + '.png', 110 20, 20 ) 111 ); 112 } 79 for( i=0; i<defense_groups.length;i++) 80 { 81 group = defense_groups[i]; 82 defense_layer.addFeatures( 83 add_pov( group.points[0].long, 84 group.points[0].lat, 85 '/images/map/nato/'+ group.coalition + "/" + group.mapclasskey + '.png', 86 20, 20 ) 87 ); 113 88 } 114 89 } … … 153 128 % if h.auth.is_creator(request.environ): 154 129 var select = dojo.byId('defenseAddList'); 155 if( select != null && all_ groups != null )130 if( select != null && all_battalions != null ) 156 131 { 157 132 dojo.empty(select); … … 159 134 var j; 160 135 var index; 161 for( i=0; i<all_ groups.length;i++)162 { 163 grp = all_ groups[i];136 for( i=0; i<all_battalions.length;i++) 137 { 138 grp = all_battalions[i]; 164 139 index = -1; 165 140 for( j=0; j < objective.defenses.length && index == -1 ; j++) … … 200 175 % if h.auth.is_creator(request.environ): 201 176 var select = dojo.byId('usebyAddList'); 202 if( select != null && all_ groups != null )177 if( select != null && all_battalions != null ) 203 178 { 204 179 dojo.empty(select); … … 207 182 var i; 208 183 var index; 209 for( i=0; i<all_ groups.length;i++)210 { 211 grp = all_ groups[i];184 for( i=0; i<all_battalions.length;i++) 185 { 186 grp = all_battalions[i]; 212 187 index = -1; 213 188 for( j=0; j < objective.use_by.length && index == -1 ; j++) … … 230 205 % endif 231 206 } 232 function send_data(e, item) 233 { 234 var data = e.get('value'); 207 function send_data(e, item, data) 208 { 209 if( ! data ) 210 { 211 data = e.get('value'); 212 } 235 213 eval( "objective."+item + "='" + data + "'" ); 236 214 dojo.xhrPost({ … … 260 238 } 261 239 dojo.xhrPost({ 262 content : { ' groups': ids},263 url: '${h.url_for(controller=" mission", action="getcoagroups" )}',240 content : { 'id': "${c.objective_id}" }, 241 url: '${h.url_for(controller="objective", action="getdefensesgroups" )}', 264 242 load: function(response, ioArgs) 265 243 { … … 267 245 if( obj.response ) 268 246 { 247 defense_groups = obj.items; 269 248 dijit.byId('dialogMap').show(); 270 249 load_map(); … … 282 261 <h2 id='name'></h2> 283 262 <p id='filename'></p> 263 % if h.auth.is_creator(request.environ): 264 <h2>${_('Visibility')}</h2> 265 <input id="visible" name="visible" dojoType="dijit.form.CheckBox" onChange="send_data(this, 'visible', arguments[0])" /> 266 <label for="visible">${_('visible by all pilots')}</label> 267 %endif 268 <h2>${_('Priority')}</h2> 269 <p id='priority'></p> 284 270 <h2>${_('Description')}</h2> 285 271 <div id="description" dojoType="dijit.InlineEditBox" … … 292 278 </div> 293 279 <h2>${_('Defend by')}</h2> 280 <p id='defenseslots'></p> 294 281 <table> 295 282 <tr> -
trunk/lodyn/lodyn/templates/derived/page/sub_campaign_objectives.html
r2192 r2193 1 1 <div dojoType="dijit.layout.ContentPane" title="${_('Objectives')}"> 2 2 <h3>${_('Objectives')}</h3> 3 % if h.auth.is_creator(request.environ):4 <div id="createObjDlg" dojoType="dijit.form.DropDownButton">5 <span>6 ${_('Add')}7 </span>8 <div dojoType="dijit.TooltipDialog">9 <label for="objName">10 ${_('Name:')}11 </label>12 <input dojoType="dijit.form.TextBox" id="objName" name="objName">13 <br>14 <button dojoType="dojox.form.BusyButton" busyLabel="${('Add objective...')}" onClick="createObj(this);" id="addobjBtn">15 ${_('Save')}16 </button>17 </div>18 </div>19 <hr class="spacer" />20 %endif21 3 <div id="objectivesList"> </div> 22 4 </div>
Note: See TracChangeset
for help on using the changeset viewer.
