diff --git a/Back/ecoreleve_server/GenericObjets/FrontModules.py b/Back/ecoreleve_server/GenericObjets/FrontModules.py index f44137537..4c5a4437d 100644 --- a/Back/ecoreleve_server/GenericObjets/FrontModules.py +++ b/Back/ecoreleve_server/GenericObjets/FrontModules.py @@ -143,10 +143,12 @@ def InputThesaurus(self) : def InputAutocomplete(self): if self.Options is not None and self.Options != '': option = json.loads(self.Options) - result = DBSession.execute(text(option['source'])).fetchall() - self.dto['options']= {'source':[]} - for row in result: - self.dto['options']['source'].append(row[0]) + if 'SELECT' in option['source']: + result = DBSession.execute(text(option['source'])).fetchall() + for row in result: + self.dto['options']['source'].append(row[0]) + else : + self.dto['options'] = {'source': option['source'],'minLength' :option['minLength']} func_type_context = { diff --git a/Back/ecoreleve_server/Views/__init__.py b/Back/ecoreleve_server/Views/__init__.py index f1d424a92..a8fdd8893 100644 --- a/Back/ecoreleve_server/Views/__init__.py +++ b/Back/ecoreleve_server/Views/__init__.py @@ -39,13 +39,14 @@ def add_routes(config): ##### User ##### config.add_route('core/user', 'ecoReleve-Core/user') config.add_route('core/currentUser', 'ecoReleve-Core/currentUser') + config.add_route('autocomplete', 'ecoReleve-Core/autocomplete/{obj}/{prop}') + # ------------------------------------------------------------------------------------------------------------------------- # ##### Stations ##### config.add_route('area', 'ecoReleve-Core/area') config.add_route('locality', 'ecoReleve-Core/locality') config.add_route('stations', 'ecoReleve-Core/stations/') - config.add_route('stations/autocomplete', 'ecoReleve-Core/stations/autocomplete/{prop}') #config.add_route('stations/fileImport', 'ecoReleve-Core/stations/fileImport/{id}') config.add_route('stations/id', 'ecoReleve-Core/stations/{id}',custom_predicates = (integers('id'),)) config.add_route('stations/action', 'ecoReleve-Core/stations/{action}') @@ -82,7 +83,6 @@ def add_routes(config): ##### Sensors caracteristics(Argos + GSM + RFID) ##### config.add_route('sensors', 'ecoReleve-Core/sensors/') - config.add_route('sensors/autocomplete', 'ecoReleve-Core/sensors/autocomplete/{prop}') config.add_route('sensors/insert', 'ecoReleve-Core/sensors') config.add_route('sensors/export', 'ecoReleve-Core/sensors/export') config.add_route('sensors/id', 'ecoReleve-Core/sensors/{id}',custom_predicates = (integers('id'),)) @@ -93,7 +93,6 @@ def add_routes(config): # ------------------------------------------------------------------------------------------------------------------------- # ##### Individuals ##### config.add_route('individuals', 'ecoReleve-Core/individuals/') - config.add_route('individuals/autocomplete', 'ecoReleve-Core/individuals/autocomplete/{prop}') config.add_route('individuals/insert', 'ecoReleve-Core/individuals') config.add_route('individuals/id', 'ecoReleve-Core/individuals/{id}',custom_predicates = (integers('id'),)) config.add_route('individuals/id/history', 'ecoReleve-Core/individuals/{id}/history',custom_predicates = (integers('id'),)) @@ -105,7 +104,6 @@ def add_routes(config): # ------------------------------------------------------------------------------------------------------------------------- # ##### MonitoredSite ##### config.add_route('monitoredSite', 'ecoReleve-Core/monitoredSites/') - config.add_route('monitoredSite/autocomplete', 'ecoReleve-Core/monitoredSites/autocomplete/{prop}') config.add_route('monitoredSite/', 'ecoReleve-Core/monitoredSites') config.add_route('monitoredSite/id', 'ecoReleve-Core/monitoredSites/{id}',custom_predicates = (integers('id'),)) config.add_route('monitoredSite/id/history', 'ecoReleve-Core/monitoredSites/{id}/history/',custom_predicates = (integers('id'),)) diff --git a/Back/ecoreleve_server/Views/autocomplete.py b/Back/ecoreleve_server/Views/autocomplete.py new file mode 100644 index 000000000..35d69b10d --- /dev/null +++ b/Back/ecoreleve_server/Views/autocomplete.py @@ -0,0 +1,39 @@ +from pyramid.view import view_config +from ..Models import ( + DBSession, + Base + ) +import transaction +from sqlalchemy import select, and_,cast, DATE,func,asc +from pyramid.security import NO_PERMISSION_REQUIRED + +dictObj = { +'stations':'Station', +'sensors':'Sensor', +'individuals':'Individual', +'monitoredSites':'MonitoredSite', +'users':'User', +'regions':'Region' +} + +def asInt(str): + try : return int(str) + except : return str + +@view_config(route_name= 'autocomplete', renderer='json', request_method = 'GET',permission = NO_PERMISSION_REQUIRED ) +def autocomplete (request): + objName = dictObj[request.matchdict['obj']] + criteria = request.params['term'] + prop = asInt(request.matchdict['prop']) + + if isinstance(prop,int): + table = Base.metadata.tables[objName+'DynPropValuesNow'] + query = select([table.c['ValueString'].label('label'),table.c['ValueString'].label('value')] + ).where(table.c['FK_'+objName+'DynProp']== prop) + query = query.where(table.c['ValueString'].like('%'+criteria+'%')).order_by(asc(table.c['ValueString'])) + else: + table = Base.metadata.tables[objName] + query = select([table.c[prop].label('value'),table.c[prop].label('label')]) + query = query.where(table.c[prop].like('%'+criteria+'%')).order_by(asc(table.c[prop])) + + return [dict(row) for row in DBSession.execute(query).fetchall()] \ No newline at end of file diff --git a/Back/ecoreleve_server/Views/individual.py b/Back/ecoreleve_server/Views/individual.py index 0e122647b..3ad77d02f 100644 --- a/Back/ecoreleve_server/Views/individual.py +++ b/Back/ecoreleve_server/Views/individual.py @@ -102,21 +102,6 @@ def getIndividualType(request): response = [ OrderedDict(row) for row in DBSession.execute(query).fetchall()] return response - -# ------------------------------------------------------------------------------------------------------------------------- # -@view_config(route_name= prefix+'/autocomplete', renderer='json', request_method = 'GET',permission = NO_PERMISSION_REQUIRED ) -def autocomplete (request): - criteria = request.params['term'] - prop = request.matchdict['prop'] - - table = Base.metadata.tables['IndividualDynPropValuesNow'] - query = select([table.c['ValueString'].label('label'),table.c['ValueString'].label('value')] - ).where(table.c['FK_IndividualDynProp']== prop) - query = query.where(table.c['ValueString'].like('%'+criteria+'%')).order_by(asc(table.c['ValueString'])) - - return [dict(row) for row in DBSession.execute(query).fetchall()] - - # ------------------------------------------------------------------------------------------------------------------------- # @view_config(route_name= prefix+'/id', renderer='json', request_method = 'GET') def getIndiv(request): diff --git a/Back/ecoreleve_server/Views/monitoredSite.py b/Back/ecoreleve_server/Views/monitoredSite.py index 04f681a50..eca432054 100644 --- a/Back/ecoreleve_server/Views/monitoredSite.py +++ b/Back/ecoreleve_server/Views/monitoredSite.py @@ -96,23 +96,6 @@ def getMonitoredSiteType(request): response = [ OrderedDict(row) for row in DBSession.execute(query).fetchall()] return response -# ------------------------------------------------------------------------------------------------------------------------- # -@view_config(route_name= prefix+'/autocomplete', renderer='json', request_method = 'GET',permission = NO_PERMISSION_REQUIRED ) -def autocomplete (request): - criteria = request.params['term'] - prop = request.matchdict['prop'] - if isinstance(prop,int): - table = Base.metadata.tables['MontoredSiteDynPropValuesNow'] - query = select([table.c['ValueString'].label('label'),table.c['ValueString'].label('value')] - ).where(table.c['FK_MontoredSiteDynProp']== prop) - query = query.where(table.c['ValueString'].like('%'+criteria+'%')).order_by(asc(table.c['ValueString'])) - else: - table = Base.metadata.tables['MontoredSite'] - query = select([table.c[prop].label('value'),table.c[prop].label('label')]) - query = query.where(table.c[prop].like('%'+criteria+'%')) - - return [dict(row) for row in DBSession.execute(query).fetchall()] - # ------------------------------------------------------------------------------------------------------------------------- # @view_config(route_name= prefix+'/id', renderer='json', request_method = 'GET',permission = NO_PERMISSION_REQUIRED) def getMonitoredSite(request): diff --git a/Back/ecoreleve_server/Views/sensor.py b/Back/ecoreleve_server/Views/sensor.py index 751402bd4..3277f5bc9 100644 --- a/Back/ecoreleve_server/Views/sensor.py +++ b/Back/ecoreleve_server/Views/sensor.py @@ -141,22 +141,6 @@ def getSensorType(request): transaction.commit() return response -# ------------------------------------------------------------------------------------------------------------------------- # -@view_config(route_name= prefix+'/autocomplete', renderer='json', request_method = 'GET',permission = NO_PERMISSION_REQUIRED ) -def autocomplete (request): - criteria = request.params['term'] - prop = request.matchdict['prop'] - if isinstance(prop,int): - table = Base.metadata.tables['SensorDynPropValuesNow'] - query = select([table.c['ValueString'].label('label'),table.c['ValueString'].label('value')] - ).where(table.c['FK_SensorDynProp']== prop) - query = query.where(table.c['ValueString'].like('%'+criteria+'%')).order_by(asc(table.c['ValueString'])) - else: - table = Base.metadata.tables['Sensor'] - query = select([table.c[prop].label('value'),table.c[prop].label('label')]) - query = query.where(table.c[prop].like('%'+criteria+'%')) - return [dict(row) for row in DBSession.execute(query).fetchall()] - # ------------------------------------------------------------------------------------------------------------------------- # @view_config(route_name= prefix+'/id', renderer='json', request_method = 'GET',permission = NO_PERMISSION_REQUIRED) def getSensor(request): diff --git a/Back/ecoreleve_server/Views/station.py b/Back/ecoreleve_server/Views/station.py index 08f199f55..f72110e5a 100644 --- a/Back/ecoreleve_server/Views/station.py +++ b/Back/ecoreleve_server/Views/station.py @@ -83,24 +83,6 @@ def getFields(request) : transaction.commit() return cols - -# ------------------------------------------------------------------------------------------------------------------------- # -@view_config(route_name= prefix+'/autocomplete', renderer='json', request_method = 'GET',permission = NO_PERMISSION_REQUIRED ) -def autocomplete (request): - criteria = request.params['term'] - prop = request.matchdict['prop'] - if isinstance(prop,int): - table = Base.metadata.tables['StationDynPropValuesNow'] - query = select([table.c['ValueString'].label('label'),table.c['ValueString'].label('value')] - ).where(table.c['FK_StationDynProp']== prop) - query = query.where(table.c['ValueString'].like('%'+criteria+'%')).order_by(asc(table.c['ValueString'])) - else: - table = Base.metadata.tables['Station'] - query = select([table.c[prop].label('value'),table.c[prop].label('label')]) - query = query.where(table.c[prop].like('%'+criteria+'%')) - - return [dict(row) for row in DBSession.execute(query).fetchall()] - # ------------------------------------------------------------------------------------------------------------------------- # @view_config(route_name= prefix+'/id', renderer='json', request_method = 'GET',permission = NO_PERMISSION_REQUIRED) def getStation(request): diff --git a/Back/ecoreleve_server/Views/statistics.py b/Back/ecoreleve_server/Views/statistics.py index e7c4e50fd..fbb8b155b 100644 --- a/Back/ecoreleve_server/Views/statistics.py +++ b/Back/ecoreleve_server/Views/statistics.py @@ -111,7 +111,10 @@ def location_graph(request): for row in DBSession.execute(query).fetchall() : curRow = OrderedDict(row) - data.append({'value':curRow['nb'],'label':curRow['type_'].upper()}) + lab = curRow['type_'].upper() + if lab == 'ARG': + lab = 'ARGOS' + data.append({'value':curRow['nb'],'label':lab}) data.sort(key = itemgetter('label')) transaction.commit() return data diff --git a/Back/ecoreleve_server/__init__.py b/Back/ecoreleve_server/__init__.py index 3d2edb724..f6993756d 100644 --- a/Back/ecoreleve_server/__init__.py +++ b/Back/ecoreleve_server/__init__.py @@ -1,4 +1,4 @@ -from datetime import datetime +import datetime from decimal import Decimal import transaction from urllib.parse import quote_plus @@ -34,7 +34,17 @@ def datetime_adapter(obj, request): """Json adapter for datetime objects.""" - return obj.strftime ('%d/%m/%Y %H:%M:%S') + try: + return obj.strftime ('%d/%m/%Y %H:%M:%S') + except : + return obj.strftime ('%d/%m/%Y') + +def time_adapter(obj, request): + """Json adapter for datetime objects.""" + try: + return obj.strftime('%H:%M') + except: + return obj.strftime('%H:%M:%S') def decimal_adapter(obj, request): """Json adapter for Decimal objects.""" @@ -58,8 +68,10 @@ def main(global_config, **settings): config = Configurator(settings=settings) # Add renderer for datetime objects json_renderer = JSON() - json_renderer.add_adapter(datetime, datetime_adapter) + json_renderer.add_adapter(datetime.datetime, datetime_adapter) + json_renderer.add_adapter(datetime.date, datetime_adapter) json_renderer.add_adapter(Decimal, decimal_adapter) + json_renderer.add_adapter(datetime.time, time_adapter) config.add_renderer('json', json_renderer) # Add renderer for CSV, PDF,GPX files. diff --git a/Back/ecoreleve_server/renderers/csvrenderer.py b/Back/ecoreleve_server/renderers/csvrenderer.py index 72b823bd5..c9ba620d6 100644 --- a/Back/ecoreleve_server/renderers/csvrenderer.py +++ b/Back/ecoreleve_server/renderers/csvrenderer.py @@ -25,7 +25,7 @@ def __call__(self, value, system): response.content_type = 'text/csv' fout = io.StringIO() - writer = csv.writer(fout, delimiter=',', quoting=csv.QUOTE_MINIMAL) + writer = csv.writer(fout, delimiter=';', quoting=csv.QUOTE_MINIMAL) writer.writerow(value.get('header', [])) writer.writerows(value.get('rows', [])) diff --git a/Back/ecoreleve_server/utils/generator.py b/Back/ecoreleve_server/utils/generator.py index 01c1e7ab3..b00d30872 100644 --- a/Back/ecoreleve_server/utils/generator.py +++ b/Back/ecoreleve_server/utils/generator.py @@ -153,26 +153,33 @@ def get_geoJSON(self,criteria={}) : result=[] total=None countResult = self.count_(criteria) - if(countResult <= 50000): - query = self.getFullQuery(criteria) - try : - data=DBSession.execute(query.where(self.table.c['LAT'] != None)).fetchall() - except : - data=DBSession.execute(query.where(self.table.c['lat'] != None)).fetchall() - tmp = data[0] - lat = self.case(tmp, 'LAT') - lon = self.case(tmp, 'LON') - geoJson=[] - for row in data: - properties = {} - # if cols_for_properties != None : - # for col in cols_for_properties : - # properties[col.replace('_',' ')] = row[col] - geoJson.append({'type':'Feature', 'properties':properties, 'geometry':{'type':'Point', 'coordinates':[row[lat],row[lon]]}}) - transaction.commit() - return {'type':'FeatureCollection', 'features': geoJson, 'exceed': False, 'total':countResult} + + if 'lat' in self.table.c or 'LAT'in self.table.c: + if(countResult <= 50000): + query = self.getFullQuery(criteria) + try : + data=DBSession.execute(query.where(self.table.c['LAT'] != None)).fetchall() + except : + try: + data=DBSession.execute(query.where(self.table.c['lat'] != None)).fetchall() + except: + pass + + tmp = data[0] + lat = self.case(tmp, 'LAT') + lon = self.case(tmp, 'LON') + geoJson=[] + for row in data: + properties = {} + # if cols_for_properties != None : + # for col in cols_for_properties : + # properties[col.replace('_',' ')] = row[col] + geoJson.append({'type':'Feature', 'properties':properties, 'geometry':{'type':'Point', 'coordinates':[row[lat],row[lon]]}}) + transaction.commit() + return {'type':'FeatureCollection', 'features': geoJson, 'exceed': False, 'total':countResult} else : return {'type':'FeatureCollection', 'features': [],'exceed': True, 'total':countResult} + def case(self, row, arg) : if( arg in row ) : diff --git a/Front/app/modules/release/layouts/lyt-release-individual.js b/Front/app/modules/release/layouts/lyt-release-individual.js index 5d8edafa3..aa42d81f5 100644 --- a/Front/app/modules/release/layouts/lyt-release-individual.js +++ b/Front/app/modules/release/layouts/lyt-release-individual.js @@ -28,11 +28,12 @@ define([ 'filters': '#indiv_filters', 'detail': '#detail', 'totalEntries': '#totalEntries', - 'nbSelected': '#nbSelected' + 'nbSelected': '#nbSelected', + 'release':'#release' }, events: { - 'click #btnFilter': 'filter', + 'click #btnFilterRel': 'filter', 'click #back': 'hideDetails', 'click button#clear': 'clearFilter', 'click #release': 'toolTipShow', @@ -52,9 +53,10 @@ define([ this.model = options.station; this.releaseMethod = null; - + this.getReleaseMethod(); var _this = this; + //todo: fix var MySensorPicker = ObjectPicker.extend({ rowClicked: function(row) { @@ -92,6 +94,15 @@ define([ //Backbone.history.navigate('release/individuals',{trigger: false}); }, + getReleaseMethod: function(){ + var _this = this; + $.ajax({ + url:config.coreUrl+'release/individuals/getReleaseMethod' + }).done(function(data){ + _this.releaseMethodList=data; + }); + }, + initGrid: function() { var myGrid = NsGrid.extend({ }); @@ -100,7 +111,7 @@ define([ this.grid = new myGrid({ pageSize: 1400, pagingServerSide: false, - //com: this.com, + com: this.com, url: config.coreUrl + 'release/individuals/', urlParams: this.urlParams, rowClicked: true, @@ -130,7 +141,7 @@ define([ displayFilter: function() { this.filters = new NsFilter({ url: config.coreUrl + 'release/individuals/', - //com: this.com, + com: this.com, filterContainer: this.ui.filters, }); }, @@ -168,7 +179,9 @@ define([ this.total = grid.collection.state.totalRecords; $(this.ui.totalEntries).html(this.total); }, - release: function() { + + + release: function(releaseMethod) { var mds = this.grid.grid.getSelectedModels(); if (!mds.length) { return; @@ -178,7 +191,7 @@ define([ $.ajax({ url: config.coreUrl + 'release/individuals/', method: 'POST', - data: {IndividualList: JSON.stringify(col),StationID: this.station.get('ID'),releaseMethod: _this.releaseMethod}, + data: {IndividualList: JSON.stringify(col),StationID: this.station.get('ID'),releaseMethod: releaseMethod}, context: this, }).done(function(resp) { if (resp.errors) { @@ -252,18 +265,15 @@ define([ toolTipShow: function(e) { var _this = this; - $(e.target).tooltipList({ - + this.ui.release.tooltipList({ position: 'top', // pass avalaible options - availableOptions: [{'label': 'direct release','val': 1},{'label': 'direct release grid 5x5','val': 2},], - // li click event - liClickEvent: $.proxy(function(liClickValue, origin, tooltip) { - _this.releaseMethod = liClickValue; - _this.release(); - }, this), + availableOptions: _this.releaseMethodList, + liClickEvent:function(liClickValue) { + _this.release(liClickValue); + }, }); - $(e.target).tooltipster('show'); + this.ui.release.tooltipster('show'); } }); });