diff --git a/back/infolica/routes.py b/back/infolica/routes.py index 13cf20d0..cd4a30ce 100644 --- a/back/infolica/routes.py +++ b/back/infolica/routes.py @@ -63,6 +63,7 @@ def includeme(config): config.add_route('recherche_operateurs', '/infolica/api/recherche_operateurs') config.add_route('recherche_operateurs_s', '/infolica/api/recherche_operateurs/') config.add_route('operateur_update', '/infolica/api/operateur_update') + config.add_route('search_operateur_aggregated', '/infolica/api/search_operateur_aggregated') #Test (temp endpoint) config.add_route('test_client', '/infolica/api/test_client') #Controle_mutation diff --git a/back/infolica/views/operateur.py b/back/infolica/views/operateur.py index f21d9d44..5fc3797c 100644 --- a/back/infolica/views/operateur.py +++ b/back/infolica/views/operateur.py @@ -7,10 +7,10 @@ from infolica.models.models import Operateur, EtapeMailer from infolica.scripts.utils import Utils from infolica.scripts.authentication import check_connected -from datetime import datetime +from datetime import datetime, date from sqlalchemy.dialects.postgresql import ARRAY -from sqlalchemy import BigInteger, func +from sqlalchemy import BigInteger, func, or_ import json @@ -237,3 +237,58 @@ def operateurs_delete_view(request): model.sortie = datetime.utcnow() return Utils.get_data_save_response(Constant.SUCCESS_DELETE.format(Operateur.__tablename__)) + + +@view_config(route_name='search_operateur_aggregated', request_method='GET', renderer='json') +def search_operateur_aggregated(request): + """ + Search operateur(s) aggregated + """ + # Check connected + if not check_connected(request): + raise exc.HTTPForbidden() + + inactive_operateurs = True + if 'inactive_operateurs' in request.params and request.params['inactive_operateurs'] == 'false': + inactive_operateurs = False + operateur_id = int(request.params['operateur_id']) if 'operateur_id' in request.params else None + + now = date.today() + + results = request.dbsession.query( + Operateur + ).filter( + Operateur.chef_equipe == True + ) + + if inactive_operateurs == False: + results = results.filter( + or_( + Operateur.sortie > now, + Operateur.sortie == None + ) + ) + + if operateur_id is not None and operateur_id > 0: + results = results.filter( + Operateur.id == operateur_id + ) + + results = results.order_by(Operateur.prenom.asc(), Operateur.nom.asc()).all() + + operateur_liste = { + 'active': [], + 'inactive': [], + } + for res in results: + type_operateur = 'active' + if res.sortie is not None and res.sortie < now: + # operateur inactif + type_operateur = 'inactive' + + operateur_liste[type_operateur].append({ + 'id': res.id, + 'prenom_nom': ' '.join([res.prenom, res.nom]), + }) + + return operateur_liste diff --git a/front/.env b/front/.env index 78c3c0bc..7e7b7359 100644 --- a/front/.env +++ b/front/.env @@ -50,6 +50,7 @@ VUE_APP_CLIENT_MORAL_PERSONNES_ENDPOINT = "/client_moral_personnes" VUE_APP_OPERATEURS_ENDPOINT = "/operateurs" VUE_APP_SEARCH_OPERATEURS_ENDPOINT = "/recherche_operateurs" VUE_APP_OPERATEUR_UPDATE_ENDPOINT = "/operateur_update" +VUE_APP_OPERATEUR_AGGREGATED_ENDPOINT = "/search_operateur_aggregated" #Cadastres VUE_APP_CADASTRES_ENDPOINT = "/cadastres" diff --git a/front/src/components/Cockpit/Cockpit.vue b/front/src/components/Cockpit/Cockpit.vue index bcf46f6a..b549177a 100644 --- a/front/src/components/Cockpit/Cockpit.vue +++ b/front/src/components/Cockpit/Cockpit.vue @@ -4,15 +4,17 @@ diff --git a/front/src/components/Utils/OperatorSelect/operatorSelect.css b/front/src/components/Utils/OperatorSelect/operatorSelect.css new file mode 100644 index 00000000..4f4661ed --- /dev/null +++ b/front/src/components/Utils/OperatorSelect/operatorSelect.css @@ -0,0 +1,4 @@ +#operatorSelect .select-field { + margin-left: 50px; + width: 280px !important; +} \ No newline at end of file diff --git a/front/src/components/Utils/OperatorSelect/operatorSelect.html b/front/src/components/Utils/OperatorSelect/operatorSelect.html new file mode 100644 index 00000000..413dc5ca --- /dev/null +++ b/front/src/components/Utils/OperatorSelect/operatorSelect.html @@ -0,0 +1,35 @@ +