Changeset 2193


Ignore:
Timestamp:
10/13/10 14:39:47 (19 months ago)
Author:
dart
Message:

LoDyn?:
o New battalion management
o Update database objects to the new spirit

MizTools?:
o Fix regex error

Location:
trunk
Files:
1 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/common/miztools/mizitem.py

    r2172 r2193  
    2424class MizItem(object): 
    2525    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*?,") 
    2727    array_regex = re.compile( r"\[(\d+)\]" ) 
    2828    #---------------------------------------------------------------- 
  • trunk/lodyn/lodyn/controllers/campaign.py

    r2192 r2193  
    2929    #---------------------------------------------------------------- 
    3030    def index(self): 
     31        c.coalition = PLAYER_COALITION 
    3132        return  render('/derived/page/campaign.html') 
    3233    #---------------------------------------------------------------- 
     
    6162                    'squadrons': squadrons 
    6263                    } 
    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) ) 
    6468 
    6569            d['items'].append( item ) 
     
    96100                'squadrons': squadrons 
    97101                } 
    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) ) 
    99106 
    100107        d['items'] = items 
     
    277284        """ Get all airports """ 
    278285        values = dict(request.params) 
    279         print " GET ALL GROUPS"  
    280286 
    281287        try: 
     
    315321    @ActionProtector(not_anonymous()) 
    316322    @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) 
    321326 
    322327        try: 
     
    331336        if not camp: return {'response': False, 'reason':_("Campaign not found") } 
    332337 
    333         obj_q = meta.Session.query(model.LoGroup) 
     338        obj_q = meta.Session.query(model.LBattalion) 
    334339        route_q = meta.Session.query(model.LoRoute) 
    335340        db_loobj_q = meta.Session.query(model.LoObject) 
     
    337342            if obj.coalition != PLAYER_COALITION: 
    338343                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  
    7676            d['groups'].append( t_d ) 
    7777        d["mission"] = db_mis.to_json() 
    78         d.update( mizfile.to_json(True) ) 
     78        d.update( mizfile.to_json(full=True) ) 
    7979        return d 
    8080    #---------------------------------------------------------------- 
     
    426426        if not mission: return  {'response':False, 'reason':_("Mission does not exists") } 
    427427        d = { 'response':True, } 
    428         d.update( mission.to_json(True) ) 
     428        d.update( mission.to_json(full=True) ) 
    429429        return d 
    430430    #---------------------------------------------------------------- 
     
    516516        meta.Session.commit() 
    517517        d = {'response': True} 
    518         d.update( mis.to_json(True) ) 
     518        d.update( mis.to_json(full=True) ) 
    519519        return d 
    520520    #---------------------------------------------------------------- 
     
    545545        meta.Session.commit() 
    546546        d = {'response': True} 
    547         d.update( mis.to_json(True) ) 
     547        d.update( mis.to_json(full=True) ) 
    548548        return d 
    549549    #---------------------------------------------------------------- 
  • trunk/lodyn/lodyn/controllers/objective.py

    r2192 r2193  
    4141        d= {'response':True, 'items':[] } 
    4242        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() ) 
    7747        return d 
    7848    #---------------------------------------------------------------- 
     
    9767        if not objective: return  {'response':False, 'reason':_("Objective does not exists") } 
    9868        d = { 'response':True, } 
    99         d.update( objective.to_json(True) ) 
     69        d.update( objective.to_json(full=True) ) 
    10070        return d 
    10171    #---------------------------------------------------------------- 
     
    11989        if not obj: return {'response': False, 'reason':_("Objective not found") } 
    12090         
     91        if item == "visible": data = (data == 'true') 
    12192        setattr( obj, item, data) 
    12293        meta.Session.commit() 
     
    176147        if not hasattr( obj, role): return {'response': False, 'reason':_("Role not found") } 
    177148 
    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 ) 
    184154 
    185155        meta.Session.commit() 
     
    211181        if not hasattr( obj, role): return {'response': False, 'reason':_("Role not found") } 
    212182 
    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 ) 
    219188 
    220189        meta.Session.commit() 
     
    225194            print "ERROR while acceds to objective with role " + role 
    226195        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  
    5151            os.mkdir( os.path.join( path, db_c.name ) )  
    5252            #-- 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" ) )  
    5456        except: 
    5557            #- try to load the master 
  • trunk/lodyn/lodyn/lib/mission_loader.py

    r2187 r2193  
    1616class MissionLoader(object): 
    1717    MISSION_DIR = 'missions' 
     18    OBJECTIVES_DIR = 'objectives' 
     19    BATTALIONS_DIR = 'battalions' 
    1820    MIS_FILES = ".miz" 
    1921    #------------------------------------------------------- 
    2022    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         
    2234        self.countries = {} 
    2335        self.campaign_path = campaign_path 
     
    2638        """ List all mission files """ 
    2739        #- Load mission 
     40        new_files = [] 
    2841         
    29         misfiles = []  
    30          
    31         #- First static ones 
    3242        path = os.path.join( self.campaign_path, self.MISSION_DIR ) 
    3343 
    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 
    4068    #------------------------------------------------------- 
    4169    def _get_md5sum(self, fileName, excludeLine="", includeLine=""): 
     
    6189        #- Get all filenames 
    6290        files = self.list_all() 
    63  
    64         md5dict = {} 
     91         
    6592        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() 
    102160    #------------------------------------------------------- 
    103161    def load_master_mission(self): 
     
    123181        return True 
    124182    #------------------------------------------------------- 
    125     def load_mission(self, db_file, filename): 
     183    def load_mission(self, db_file, filename, db_obj=None): 
    126184        """ Load mission file """ 
    127185        f = mizfile.MizFile( filename ) 
     
    130188        mission = f.miz_loader.mission 
    131189 
    132         #- Clean if exists 
    133         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.id 
    142             meta.Session.add( db_mis ) 
    143          
    144190        db_count_q = meta.Session.query(model.LoCountry) 
    145191        db_loobj_q = meta.Session.query(model.LoObject) 
    146192 
    147         db_mis.description = mission["mission"]["descriptionText"] 
     193        db_file.description = mission["mission"]["descriptionText"] 
    148194 
    149195        for coa in ["blue", "red"]: 
     
    154200                db_group.campaign_id = db_file.campaign_id 
    155201                db_group.object_type = g.parent.parent.name 
    156                 db_mis.groups.append( db_group ) 
     202                db_file.groups.append( db_group ) 
    157203                c_name = g.parent.parent.parent["name"] 
    158204                db_c = db_count_q.filter_by(name=c_name).first() 
     
    193239                        for it in ["speed", "alt", "type", "action"]: 
    194240                            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  
    77 
    88 
    9  
     9from constants import PLAYER_COALITION 
    1010from lodyn.model import meta 
    1111import uuid, datetime 
     
    1818 
    1919class 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): 
    2123        ls = [] 
    2224        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) 
    2439        return ls 
    2540 
  • trunk/lodyn/lodyn/model/loobjects.py

    r2192 r2193  
    5555    #- Can be plane|helicopter|car|ship 
    5656 
    57     mission_id  = sa.Column(UUID(), ForeignKey('lomissions.id')) 
    5857    name = sa.Column(sa.types.String, nullable=False) 
    5958    coalition = sa.Column(sa.types.String, nullable=False) 
     
    6261    country_id = sa.Column(UUID(), ForeignKey('locountries.id')) 
    6362    campaign_id  = sa.Column(UUID(), ForeignKey('lcampaigns.id')) 
     63    mizfile_id  = sa.Column(UUID(), ForeignKey('lmizfiles.id')) 
    6464 
    6565    def to_json(self, full=False): 
     
    234234    country    = sa.Column(sa.types.String) 
    235235    picture    = sa.Column(sa.types.String) 
    236 #---------------------------------------------------------------- 
    237 class LoMission(Base, LBase): 
    238     """ 
    239     Stores all lofc2 missions 
    240     """ 
    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  
    3030    description  = sa.Column(sa.types.String ) 
    3131    objectives = orm.relation("LObjective", backref="campaign") 
     32    battalions = orm.relation("LBattalion", backref="campaign") 
    3233    comments = orm.relation("LCampaignComment", backref="campaign") 
    3334    missions = orm.relation("LMission", backref="campaign") 
    34     lofiles = orm.relation("LMizFile", backref="campaign") 
    3535    squadrons = orm.relation('LSquadron', secondary=lcampaigns_lsquadrons, backref='campaigns') 
    3636    master = sa.Column(sa.types.Boolean ) 
     
    4545        self.master = False 
    4646 
    47     def to_json(self, full=False): 
     47    def to_json(self, full=False, **k): 
    4848        d = { 
    4949                'name': self.name,  
     
    5555        if full: 
    5656            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), 
    6161                }) 
    6262        return d 
     
    9292        self.duration = 120 
    9393        self.date = datetime.datetime.now() + datetime.timedelta(hours=2) 
    94     def to_json(self, full=False): 
     94    def to_json(self, full=False, **k): 
    9595        d = { 
    9696                'name': self.name,  
     
    103103        if full: 
    104104            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), 
    107107                }) 
    108108        return d 
     
    125125    def __init__(self): 
    126126        self.datetime = datetime.datetime.now() 
    127     def to_json(self, full=False): 
     127    def to_json(self, full=False, **k): 
    128128        return { 
    129129                'title':self.title, 
     
    160160    name  = sa.Column(sa.types.String ) 
    161161    filename  = sa.Column(sa.types.String ) 
     162    description  = sa.Column(sa.types.String ) 
    162163    md5sum  = sa.Column(sa.types.String ) 
    163164    campaign_id  = sa.Column(UUID(), ForeignKey('lcampaigns.id')) 
     165    battalion_id  = sa.Column(UUID(), ForeignKey('lbattalions.id')) 
    164166    comments = orm.relation("LMizFileComment", backref="mizfile") 
     167    groups = orm.relation("LoGroup", backref="mizfile") 
    165168 
    166169    mode  = sa.Column(sa.types.Integer ) 
     
    170173    KILLED = 2 
    171174 
    172     def to_json(self, full=False): 
     175    def to_json(self, full=False, **k): 
    173176        d = { 
    174177                'name': self.name,  
     
    177180                'mode': self.mode,  
    178181                'current_mode': self.current_mode,  
     182                'description': self.description,  
    179183            } 
    180184        if full: 
    181185            d.update({ 
    182                 'comments': self.get_items( "comments", True),  
     186                'comments': self.get_items( "comments", True, **k),  
    183187                }) 
    184188        return d 
     
    204208        self.designator = "F-${plane_id} ${pilot_name}" 
    205209#---------------------------------------------------------------- 
    206 lobjectives_logroups_defense = sa.Table('lobjectives_logroups_defense', metadata, 
     210lobjectives_lbattalions_defense = sa.Table('lobjectives_lbattalions_defense', metadata, 
    207211     sa.Column('lobjective_id', UUID(), ForeignKey('lobjectives.id')), 
    208      sa.Column('logroups_id', UUID(), ForeignKey('logroups.id')) 
     212     sa.Column('lbattalions_id', UUID(), ForeignKey('lbattalions.id')) 
    209213 ) 
    210214#---------------------------------------------------------------- 
    211 lobjectives_logroups_useby = sa.Table('lobjectives_logroups_useby', metadata, 
     215lobjectives_lbattalions_useby = sa.Table('lobjectives_lbattalions_useby', metadata, 
    212216     sa.Column('lobjective_id', UUID(), ForeignKey('lobjectives.id')), 
    213      sa.Column('logroups_id', UUID(), ForeignKey('logroups.id')) 
     217     sa.Column('lbattalions_id', UUID(), ForeignKey('lbattalions.id')) 
    214218 ) 
    215219#---------------------------------------------------------------- 
     
    220224    __tablename__ = 'lobjectives' 
    221225    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) 
    223227    description  = sa.Column(sa.types.String ) 
    224228    campaign_id = sa.Column(UUID(), ForeignKey('lcampaigns.id'), nullable=False) 
    225229    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 ) 
    230238    status  = sa.Column(sa.types.Integer ) 
    231239    INACTIVE = 0 
     
    235243    def __init__(self): 
    236244        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 {} 
    238249        d ={ 
    239250                'name': self.name,  
     
    241252                'description': self.description,  
    242253                'status': self.status,  
     254                'priority': self.priority,  
     255                'visible': self.visible,  
    243256             } 
    244257        if full: 
    245258            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),  
    249263                }) 
    250264        return d 
     
    257271    def get_all_roles_obj(self): 
    258272        return self.defenses + self.use_by 
    259  
     273#---------------------------------------------------------------- 
     274class 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#---------------------------------------------------------------- 
     298class 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  
    175175 
    176176    } 
    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     } 
    198177    load_objectives(); 
    199178    load_missions(); 
     
    212191            var name = obj.name; 
    213192            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: 
    214199            c.innerHTML = name; 
     200% endif 
    215201            c.href = '${h.url_for(controller="objective", action="show" )}/' + obj.id; 
    216202            c.target = "_blank"; 
     
    364350        <%include file="/derived/page/sub_campaign_objectives.html" /> 
    365351        <%include file="/derived/page/sub_campaign_missions.html" /> 
    366         <%include file="/derived/page/sub_campaign_files.html" /> 
    367352    </div> 
    368353</div> 
  • trunk/lodyn/lodyn/templates/derived/page/objective.html

    r2192 r2193  
    55     dojo.require("dijit.layout.ContentPane"); 
    66     dojo.require("dijit.form.MultiSelect"); 
     7     dojo.require("dijit.form.CheckBox"); 
    78     dojo.require("dojo.data.ItemFileReadStore"); 
    89 
    910     var objective = null; 
    10      var all_groups = null; 
     11     var all_battalions = null; 
     12     var defense_layer = null; 
    1113     var defense_groups = null; 
    12      var use_by_groups = null; 
     14     var use_by_layer = null; 
    1315 
    1416     dojo.addOnLoad( function init(){ 
    1517        dojo.xhrPost({ 
    1618            content : { name: "${c.campaign_name}" }, 
    17             url: '${h.url_for(controller="campaign", action="getallcoagroups")}', 
     19            url: '${h.url_for(controller="campaign", action="getallcoabattalions")}', 
    1820            load: function(response, ioArgs)  
    1921            { 
     
    2123                if( obj.response ) 
    2224                { 
    23                     all_groups = obj.items; 
     25                    all_battalions = obj.items; 
    2426                }else{ 
    2527                    alert( obj.reason ); 
     
    4749{ 
    4850    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; 
    4956    dijit.byId('description').set( 'value', objective.description ); 
    5057 
     
    5663{ 
    5764    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(); 
    7077    var i; 
    7178    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                ); 
    11388    } 
    11489} 
     
    153128    % if h.auth.is_creator(request.environ): 
    154129   var select = dojo.byId('defenseAddList');  
    155     if( select != null && all_groups != null ) 
     130    if( select != null && all_battalions != null ) 
    156131    { 
    157132        dojo.empty(select); 
     
    159134        var j; 
    160135        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]; 
    164139            index = -1; 
    165140            for( j=0; j < objective.defenses.length && index == -1 ; j++) 
     
    200175    % if h.auth.is_creator(request.environ): 
    201176   var select = dojo.byId('usebyAddList');  
    202     if( select != null && all_groups != null ) 
     177    if( select != null && all_battalions != null ) 
    203178    { 
    204179        dojo.empty(select); 
     
    207182        var i; 
    208183        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]; 
    212187            index = -1; 
    213188            for( j=0; j < objective.use_by.length && index == -1 ; j++) 
     
    230205    % endif 
    231206} 
    232 function send_data(e, item) 
    233 { 
    234     var data = e.get('value'); 
     207function send_data(e, item, data) 
     208{ 
     209    if( ! data ) 
     210    { 
     211        data = e.get('value'); 
     212    } 
    235213    eval( "objective."+item + "='" + data + "'" ); 
    236214    dojo.xhrPost({ 
     
    260238    } 
    261239    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" )}', 
    264242        load: function(response, ioArgs)  
    265243        { 
     
    267245            if( obj.response ) 
    268246            { 
     247                defense_groups = obj.items; 
    269248                dijit.byId('dialogMap').show(); 
    270249                load_map(); 
     
    282261        <h2 id='name'></h2> 
    283262        <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> 
    284270        <h2>${_('Description')}</h2> 
    285271        <div id="description" dojoType="dijit.InlineEditBox"  
     
    292278        </div> 
    293279        <h2>${_('Defend by')}</h2> 
     280        <p id='defenseslots'></p> 
    294281        <table> 
    295282            <tr> 
  • trunk/lodyn/lodyn/templates/derived/page/sub_campaign_objectives.html

    r2192 r2193  
    11<div dojoType="dijit.layout.ContentPane" title="${_('Objectives')}"> 
    22    <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     %endif 
    213    <div id="objectivesList"> </div> 
    224</div> 
Note: See TracChangeset for help on using the changeset viewer.