Skip to content

Commit

Permalink
UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kazhamiakin committed Oct 21, 2023
1 parent 2a0f57a commit 4eb2284
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,27 +393,32 @@ public void importEmployees(String companyId, InputStream inputStream) throws Ex
lines = readCSV(new ByteArrayInputStream(bytes), ';', 4);
}
Set<String> codes = new HashSet<>();
int i = 0;
for (String[] l: lines) {
String code = l[2];
String code = stringValue(l[2], i + 1, 3, true);
if (codes.contains(code)) {
throw new InconsistentDataException("Duplicate employees", "INVALID_CSV_DUPLICATE_EMPLOYEES");
}
Employee existing = employeeRepo.findByCompanyIdAndCodeIgnoreCase(companyId, code).stream().findAny().orElse(null);
String location = stringValue(l[3], i + 1, 4, true);
String name = stringValue(l[0], i + 1, 1, true);
String surname = stringValue(l[1], i + 1, 2, true);
if (existing != null) {
existing.setLocation(l[3]);
existing.setName(l[0]);
existing.setSurname(l[1]);
existing.setLocation(location);
existing.setName(name);
existing.setSurname(surname);
employeeRepo.save(existing);
} else {
Employee e = new Employee();
e.setCode(code);
e.setName(l[0]);
e.setSurname(l[1]);
e.setName(name);
e.setSurname(surname);
e.setCompanyId(companyId);
e.setLocation(l[3]);
e.setLocation(location);
employeeRepo.save(e);
}
codes.add(code);
i++;
}
}

Expand Down Expand Up @@ -511,6 +516,12 @@ public void importLocations(String companyId, InputStream inputStream) throws Ex
if (locations.size() > 0) {
Company c = companyRepo.findById(companyId).orElse(null);
if (c != null) {
Map<String, CompanyLocation> map = locations.stream().collect(Collectors.toMap(l -> l.getId(), l -> l));
if (c.getLocations() != null) {
for (CompanyLocation l : c.getLocations()) {
if (!map.containsKey(l.getId())) locations.add(l);
}
}
c.setLocations(locations);
companyRepo.save(c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public ErrorMsg(String message, String type, Map<String, Object> errorData) {
super();
this.message = message;
this.errorData = errorData;
this.type = type;
}

public ErrorMsg() {
Expand Down
6 changes: 3 additions & 3 deletions console_aziendale/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ export default {
status(newCount, oldCount) {
console.log(JSON.stringify(newCount) + JSON.stringify(oldCount));
},
message(newAlert,oldAlert){
console.log(JSON.stringify(newAlert) + JSON.stringify(oldAlert));
message(){
// console.log('Message:' + this.message + ',' + this.active);
// setTimeout(()=>this.clearAlert(),2500)
},
// eslint-disable-next-line no-unused-vars
$route(to, from) {
$route() {
// clear alert on location change
setTimeout(()=>this.clearAlert(),2500);
window.scrollTo(0,0);
Expand Down
10 changes: 7 additions & 3 deletions console_aziendale/src/components/Snackbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ quando chiamato e avviato, gestire i messaggi lanciati dall'applicativo e farli
all'utente come una snackbar.
-->
<template>
<v-snackbar v-model="snackbar" class="up" :color="type=='success'?'':type" :timeout="5000">
<v-snackbar v-model="snackbar" class="up" :color="type=='success'?'':type">
{{ message }}
<v-btn :color="type=='success'? 'primary': 'alert'" text @click="clearAlert"> Chiudi </v-btn>
</v-snackbar>
Expand All @@ -28,8 +28,12 @@ export default {
},
watch: {
message(newMsg) {
if (newMsg)
this.snackbar = true;
if (newMsg) {
this.snackbar = true;
setTimeout(() => {
this.clearAlert();
}, 5000);
}
else this.snackbar = false;
},
},
Expand Down
6 changes: 3 additions & 3 deletions console_aziendale/src/pages/companies/Company.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@
-->

<!-- PROVA nuovo Modifica con nuovo MODAL -->
<v-btn icon
<v-btn icon v-if="role == 'ROLE_ADMIN'"
@click="openModal({type:'aziendaFormEdit', object:null})">
<v-icon>mdi-pencil</v-icon>
</v-btn>

<v-btn icon v-show="$route.name !== 'ProfiloAzienda'"
<v-btn icon v-show="$route.name !== 'ProfiloAzienda' && role == 'ROLE_ADMIN'"
@click="openModal({type:'updateCompanyState', object:null})">
<v-icon>{{actualCompany.item.state ? 'mdi-close' : 'mdi-check'}}</v-icon>
</v-btn>

<v-btn icon v-show="$route.name !== 'ProfiloAzienda'"
<v-btn icon v-show="$route.name !== 'ProfiloAzienda' && role == 'ROLE_ADMIN'"
@click="openModal({type:'deleteAzienda', object:null})">
<v-icon>mdi-delete</v-icon>
</v-btn>
Expand Down
12 changes: 8 additions & 4 deletions console_aziendale/src/pages/stats/StatsMenagement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
><br /><span
v-for="(agg, index) in activeSelection.puntualAggregationItems"
:key="index"
>{{ agg.name }} {{ agg.surname ? agg.surname : null
}} </span></template
>{{ agg.label }} </span></template
><template v-else><br /><span>Nessuno</span></template>
</p>
</v-card-text>
Expand Down Expand Up @@ -119,6 +118,7 @@
item-text="label"
return-object
outlined
@change="resetPunctualAggregation"
></v-autocomplete>

<div
Expand Down Expand Up @@ -438,6 +438,11 @@ export default {
this.getLocalStat(this.localSelection);
},
resetPunctualAggregation() {
this.puntualAggregationSelected = 'NONE';
this.updatePuntualAggregationChange();
},
fillTheViewWithValues(values, view, activeSelection, currentCampaign, loader) {
viewStatService
.fillTheViewWithValues(values, view, activeSelection, currentCampaign)
Expand All @@ -461,8 +466,7 @@ export default {
}
},
getItemText(item) {
if (item.surname) return `${item.surname} ${item.name}`;
return `${item.name}`;
return item.label;
},
exportCsv() {
this.downloadCsv(this.localSelection);
Expand Down
14 changes: 9 additions & 5 deletions console_aziendale/src/pages/stats/statsConfigurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ export const statsConfigurations = [
value: 'NONE',
function:''
}
// ,{
// label: VARIABLES.STATS.VIEWS.PUNTUALAGGREGATION.LOCATIONS,
// value: 'LOCATIONS',
// function:''
// }
,{
label: VARIABLES.STATS.VIEWS.PUNTUALAGGREGATION.LOCATIONS,
value: 'LOCATIONS',
function:'aggregateByLocation'
}
]
},
{
Expand Down Expand Up @@ -295,6 +295,10 @@ export const statsConfigurations = [
label: VARIABLES.STATS.VIEWS.PUNTUALAGGREGATION.NONE,
value: 'NONE',
function:''
},{
label: VARIABLES.STATS.VIEWS.PUNTUALAGGREGATION.LOCATIONS,
value: 'LOCATIONS',
function:'aggregateByLocation'
}]
}
],
Expand Down
48 changes: 44 additions & 4 deletions console_aziendale/src/services/stat.services.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import { statsConfigurations } from "../pages/stats/statsConfigurations";
// import { VARIABLES } from "../variables";
import { campaignService } from '.';
import { campaignService, locationService } from '.';
// import { companyService } from ".";
import { employeeService } from ".";
// import { viewStatService } from "./viewStat.services";
Expand Down Expand Up @@ -39,11 +39,28 @@ function getConfigurationByRole(ROLE, temporaryAdmin) {
function getItemsAggregation(itemAggregationValue, campaignId, companyId) {
switch (itemAggregationValue) {
case "EMPLOYEES":
return employeeService.getAllEmployees(companyId);
return employeeService.getAllEmployees(companyId).then((content) => {
return content.filter(e => e.campaigns.indexOf(campaignId) >= 0)
.map(e => {
e.label = (e.surname) ? `${e.surname} ${e.name}` : `${e.name}`;
return e;
});
});
case "LOCATIONS":
return;
return locationService.getAllLocations(companyId).then(content => {
return content.map(l => {
l.label = l.id;
return l;
});

})
case "COMPANIES":
return campaignService.getAllCompaniesOfCampaign(campaignId);
return campaignService.getAllCompaniesOfCampaign(campaignId).then(content => {
return content.map(c => {
c.label = c.companyId;
return c;
});
});
default:
return Promise.resolve(null);

Expand Down Expand Up @@ -236,6 +253,22 @@ function aggregateByEmployeeStat(configuration) {
configuration.csv
);
}
function aggregateByLocationStat(configuration) {
console.log('aggregateByLocationStat', configuration);
return callStatsAPI(
configuration.campaign.id,
configuration.company.id,
null,
null,
configuration.timeUnit.apiField,
'location',
configuration.timePeriod.value != 'ALL' ? (configuration.selectedDateFrom ? configuration.selectedDateFrom : null) : null,
configuration.timePeriod.value != 'ALL' ? (configuration.selectedDateTo ? configuration.selectedDateTo : null) : null,
getFields(configuration),
true,
configuration.csv
);
}

function getCampaignCompanyStats(configuration) {
console.log('getCampaignCompanyStats', configuration);
Expand Down Expand Up @@ -330,6 +363,13 @@ function getStat(configuration) {
return getAllEmployeesStats(configuration);
case "aggregateByemployee":
return aggregateByEmployeeStat(configuration);
case "aggregateByLocation":
return aggregateByLocationStat(configuration).then(res => {
console.log('RES', res);
const arr = configuration.puntualAggregationItems ? configuration.puntualAggregationItems.map(l => l.id) : [];
if (arr.length == 0) return res;
return res.filter(l => arr.indexOf(l.key) >= 0);
});
case "getLocationsStats":
return getAllLocationsStats(configuration);
case "getCompanyStats":
Expand Down
10 changes: 9 additions & 1 deletion console_aziendale/src/store/alert.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ const HttpErrors = {
'REPEATING_SUBSCRIPTION': 'Attenzione, utente giá presente!'
}

const mapErrorData = (type, errorData) => {
if (!errorData) return '';
if (type == 'INVALID_IMPORT_DATA') {
return ` (riga ${errorData.row}, colonna ${errorData.col})`
}
return '';
}


const actions = {
success({ commit }, message) {
Expand All @@ -59,7 +67,7 @@ const mutations = {
error(state, message) {
state.type = 'error';
if (!!message && message.response && !!message.response.data.type && HttpErrors[message.response.data.type]) {
state.message = HttpErrors[message.response.data.type];
state.message = HttpErrors[message.response.data.type] + mapErrorData(message.response.data.type, message.response.data.errorData);
}
else { state.message = HttpErrors['GENERIC_ERROR']; }
},
Expand Down
10 changes: 5 additions & 5 deletions console_aziendale/src/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const VARIABLES = {
NAME: {
EMPLOYEES_PARTECIPATION: "Partecipazione Dipendenti",
ENVIRONMENTAL_IMPACT: "Impatto Ambientale",
KM_COUNTED: "Punti totali e utili",
KM_COUNTED: "Punteggio Campagna",
},
VIEWS: {
TYPE: {
Expand Down Expand Up @@ -40,12 +40,12 @@ export const VARIABLES = {
apiField: "score"
},
COUNTING_POINTS: {
label: "Punti",
label: "Punti utili",
value: "limitedScore",
apiField: "limitedScore"
},
N_COUNTING_TRAVEL: {
label: "Viaggi",
label: "Viaggi utili",
value: "limitedTrackCount",
apiField: "limitedTrackCount"
},
Expand All @@ -61,7 +61,7 @@ export const VARIABLES = {
mean: true
},
MEAN_COUNTING_POINTS: {
label: "Punti per mezzo",
label: "Punti utili per mezzo",
value: "limitedMeanScore",
apiField: "limitedMeanScore",
mean: true
Expand All @@ -85,7 +85,7 @@ export const VARIABLES = {
mean: true
},
MEAN_N_TRAVEL: {
label: "Viaggi per mezzo",
label: "Tratte per mezzo",
value: "meanTracks",
apiField: "meanTracks",
mean: true
Expand Down

0 comments on commit 4eb2284

Please sign in to comment.