Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New component for operator selection #743

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions back/infolica/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 57 additions & 2 deletions back/infolica/views/operateur.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions front/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
53 changes: 17 additions & 36 deletions front/src/components/Cockpit/Cockpit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

<script>
import Matdiff from "@/components/Cockpit/Matdiff/Matdiff.vue";
import OperatorSelect from "@/components/Utils/OperatorSelect/OperatorSelect.vue";
import Snow from "@/components/Utils/Snow/Snow.vue";

import { handleException } from '@/services/exceptionsHandler';
import { checkPermission, getOperateurs, stringifyAutocomplete, stringifyAutocomplete2, getCurrentUserRoleId } from '@/services/helper';
import { checkPermission, stringifyAutocomplete, getCurrentUserRoleId } from '@/services/helper';

export default {
name: "Cockpit",
components: {
Matdiff,
OperatorSelect,
Snow,
},
data: () => {
Expand All @@ -28,7 +30,6 @@ export default {
affaireTypes: [],
loadingAffaires: false,
newAffaireAllowed: false,
operateurs: [],
plural: '',
refreshAffaire: null,
showMatdiff_secr: false,
Expand Down Expand Up @@ -203,35 +204,6 @@ export default {
return query;
},

/**
* Get operateurs
*/
async getOperateursList() {
return new Promise ((resolve, reject) => {
getOperateurs()
.then(response => {
if (response && response.data) {
let tmp = response.data;
tmp = tmp.filter(x => x.chef_equipe);

// set operateur by default if he is chef_equipe
let currentUserID = JSON.parse(localStorage.getItem("infolica_user")).id;
let currentUserRoleID = getCurrentUserRoleId();
if (tmp.some(x => (x.id === currentUserID) && x.chef_equipe) && (currentUserRoleID && [this.role.mo, this.role.ppe, this.role.mo_ppe].includes(currentUserRoleID))) {
this.search.operateur_id = Number(currentUserID);
}

tmp = stringifyAutocomplete2(tmp, "prenom_nom", null, "prenom_nom");

this.operateurs = tmp;
resolve(tmp);
}
}).catch(err => {
handleException(err, this);
reject(err);
});
});
},

/**
* custom sort
Expand Down Expand Up @@ -287,16 +259,25 @@ export default {
this.search.current_sort = this.current_sort;
this.search.current_sort_order = this.current_sort_order;
localStorage.setItem("infolica_cockpit_searchParams", JSON.stringify(this.search));
},

setOperatorFilter() {
// set operateur by default if he is chef_equipe
let currentUserChefEquipe = JSON.parse(localStorage.getItem("infolica_user")).chef_equipe;
let currentUserID = JSON.parse(localStorage.getItem("infolica_user")).id;
let currentUserRoleID = getCurrentUserRoleId();
if (currentUserChefEquipe && (currentUserRoleID && [this.role.mo, this.role.ppe, this.role.mo_ppe].includes(currentUserRoleID))) {
this.search.operateur_id = Number(currentUserID);
}
}

},

mounted: function() {
this.getAffaireEtapes()
this.getAffaireTypes()
this.getOperateursList().then(() => {
this.getAffaire();
});
this.setOperatorFilter();
this.getAffaireEtapes();
this.getAffaireTypes();
this.getAffaire();
this.getPermissions();

// snow
Expand Down
2 changes: 0 additions & 2 deletions front/src/components/Cockpit/Matdiff/Matdiff.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export default {
Matdiff_ctrl
},
props: {
operateurs: {type: Array},
showMatdiff_secr: {type: Boolean},
showMatdiff_mo: {type: Boolean},
showMatdiff_ctrl: {type: Boolean},
Expand All @@ -26,7 +25,6 @@ export default {
affaires: [{}],
affaires_bk: [{}],
plural: "",
selectedOperateur_id: -1,
}
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

<script>
import { handleException } from '@/services/exceptionsHandler'
import OperatorSelect from "@/components/Utils/OperatorSelect/OperatorSelect.vue";

const moment = require('moment')

export default {
name: "Matdiff_ctrl",
props: {
operateurs: {type: Array},
components: {
OperatorSelect,
},
data: () => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
</div>

<div class="md-toolbar-section-end">
<md-field style="margin-left: 50px; width: 250px">
<label for="operateur">Opérateur·rice</label>
<md-select v-model="selectedOperateur_id" name="operateur" id="operateur" @md-selected="getNumerosDifferes()" md-dense>
<md-option :value="-1">Tous</md-option>
<md-option v-for="item in operateurs" :value="item.id">{{ item.prenom_nom }}</md-option>
</md-select>
</md-field>
<operatorSelect
:operateur_id="selectedOperateur_id"
@update:operateur_id="newValue => selectedOperateur_id = newValue"
@update:selected="getNumerosDifferes"
:select_all_permitted="true"
:inactive_operateurs_permitted="true"
/>
</div>
</md-table-toolbar>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
<script>
import { handleException } from '@/services/exceptionsHandler'
import { checkPermission, getCurrentUserRoleId } from '@/services/helper'
import OperatorSelect from "@/components/Utils/OperatorSelect/OperatorSelect.vue";

const moment = require('moment')

export default {
name: "Matdiff_mo",
props: {
operateurs: {type: Array},
components: {
OperatorSelect,
},
data: () => {
return {
Expand Down
14 changes: 7 additions & 7 deletions front/src/components/Cockpit/Matdiff/Matdiff_mo/matdiff_mo.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

<div class="md-toolbar-section-end">
<md-checkbox v-model="showBFProjet" class="md-primary" @change="getNumerosDifferes">Afficher les bf non déposés</md-checkbox>
<md-field style="margin-left: 50px; width: 250px">
<label for="operateur">Opérateur·rice</label>
<md-select v-model="selectedOperateur_id" name="operateur" id="operateur" @md-selected="getNumerosDifferes()" md-dense>
<md-option :value="-1">Tous</md-option>
<md-option v-for="item in operateurs" :value="item.id">{{ item.prenom_nom }}</md-option>
</md-select>
</md-field>
<operatorSelect
:operateur_id="selectedOperateur_id"
@update:operateur_id="newValue => selectedOperateur_id = newValue"
@update:selected="getNumerosDifferes"
:select_all_permitted="true"
:inactive_operateurs_permitted="true"
/>
</div>
</md-table-toolbar>

Expand Down
4 changes: 2 additions & 2 deletions front/src/components/Cockpit/Matdiff/matdiff.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

<!-- OPERATEUR MO - MAT DIFF A REALISER -->
<div v-if="showMatdiff_mo">
<Matdiff_mo :operateurs="operateurs" ></Matdiff_mo>
<Matdiff_mo></Matdiff_mo>
<br>
</div>

<!-- OPERATEUR COORDINATEUR - CONTROLE MAT DIFF -->
<div v-if="showMatdiff_ctrl">
<Matdiff_ctrl :operateurs="operateurs" ></Matdiff_ctrl>
<Matdiff_ctrl></Matdiff_ctrl>
<br>
</div>

Expand Down
15 changes: 7 additions & 8 deletions front/src/components/Cockpit/cockpit.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ <h1>Cockpit</h1>
<!-- mat diff -->
<div>
<Matdiff v-if="showMatdiff_secr || showMatdiff_mo"
:operateurs="operateurs"
:showMatdiff_secr="showMatdiff_secr"
:showMatdiff_mo="showMatdiff_mo"
:showMatdiff_ctrl="showMatdiff_ctrl"></Matdiff>
Expand All @@ -25,13 +24,13 @@ <h1>Cockpit</h1>
<md-icon>search</md-icon>
</md-field>

<md-field style="margin-left: 50px; width: 250px !important;">
<label for="operateur">Opérateur·rice</label>
<md-select v-model="search.operateur_id" name="operateur" id="operateur" @md-selected="getAffaire" md-dense>
<md-option :value="-1">Tous</md-option>
<md-option v-for="item in operateurs" :value="item.id">{{ item.prenom_nom }}</md-option>
</md-select>
</md-field>
<operatorSelect
:operateur_id="search.operateur_id"
@update:operateur_id="newValue => search.operateur_id = newValue"
@update:selected="getAffaire"
:select_all_permitted="true"
:inactive_operateurs_permitted="true"
/>

<md-field style="margin-left: 50px; width: 250px !important;">
<label>Type(s) d'affaire</label>
Expand Down
Loading