Added calculated duration of new timestamps

This commit is contained in:
Maximilian Giller 2021-01-03 21:43:00 +01:00
parent 64ba600a8f
commit 1d5df2a4b1
4 changed files with 48 additions and 16 deletions

View file

@ -21,6 +21,7 @@
placeholder="Choose a start date" placeholder="Choose a start date"
:max="times.end.date" :max="times.end.date"
dark dark
@input="() => updateCurrentDuration()"
> >
</b-form-datepicker> </b-form-datepicker>
</b-form-group> </b-form-group>
@ -32,6 +33,7 @@
required required
placeholder="Choose a start time" placeholder="Choose a start time"
dark dark
@input="() => updateCurrentDuration()"
> >
</b-form-timepicker> </b-form-timepicker>
</b-form-group> </b-form-group>
@ -47,6 +49,7 @@
placeholder="Choose an end date" placeholder="Choose an end date"
:min="times.start.date" :min="times.start.date"
dark dark
@input="() => updateCurrentDuration()"
> >
</b-form-datepicker> </b-form-datepicker>
</b-form-group> </b-form-group>
@ -59,6 +62,7 @@
show-seconds show-seconds
placeholder="Choose an end time" placeholder="Choose an end time"
dark dark
@input="() => updateCurrentDuration()"
> >
</b-form-timepicker> </b-form-timepicker>
</b-form-group> </b-form-group>
@ -67,17 +71,30 @@
label="Duration [seconds]" label="Duration [seconds]"
label-for="duration" label-for="duration"
> >
<b-input-group>
<b-input-group-prepend
is-text
:class="{ disabled: !times.finished || !times.editableDuration }"
>
<b-form-checkbox
class="mr-n2"
v-model="times.editableDuration"
@input="() => updateCurrentDuration()"
>
</b-form-checkbox>
</b-input-group-prepend>
<b-form-input <b-form-input
id="duration" id="duration"
v-model="times.duration" v-model="times.duration"
type="number" type="number"
:required="times.finished" :required="times.finished && !times.editableDuration"
:disabled="!times.finished" :disabled="!times.finished || !times.editableDuration"
placeholder="Choose a duration" placeholder="Choose a duration"
min="0" min="0"
dark dark
> >
</b-form-input> </b-form-input>
</b-input-group>
</b-form-group> </b-form-group>
<b-form-invalid-feedback :state="!failed"> <b-form-invalid-feedback :state="!failed">
Something went wrong. Something went wrong.
@ -117,7 +134,8 @@ export default {
start: { date: undefined, time: undefined }, start: { date: undefined, time: undefined },
end: { date: undefined, time: undefined }, end: { date: undefined, time: undefined },
finished: false, finished: false,
duration: 0 duration: 0,
editableDuration: false
}, },
selectableProjects: [], selectableProjects: [],
failed: false, failed: false,
@ -156,6 +174,12 @@ export default {
} }
return result; return result;
},
exactCalcDuration: function() {
return helperService.calcDurationInSeconds(
this.resultRecord.start_time,
this.resultRecord.end_time
);
} }
}, },
methods: { methods: {
@ -185,6 +209,11 @@ export default {
}, },
deleteRecord: function() { deleteRecord: function() {
store.dispatch("removeRecord", this.record.record_id); store.dispatch("removeRecord", this.record.record_id);
},
updateCurrentDuration: function() {
if (!this.times.editableDuration) {
this.times.duration = this.exactCalcDuration;
}
} }
}, },
created: function() { created: function() {

View file

@ -146,5 +146,9 @@ export const helperService = {
":" + ":" +
dateTime.getSeconds() dateTime.getSeconds()
); );
},
calcDurationInSeconds(start, end = new Date()) {
return (new Date(end).getTime() - new Date(start).getTime()) / 1000;
} }
}; };

View file

@ -145,8 +145,7 @@ function processRecords(data) {
rec.running = rec.end_time === null; rec.running = rec.end_time === null;
if (rec.running) { if (rec.running) {
rec.duration = rec.duration = helperService.calcDurationInSeconds(rec.start_time);
(new Date().getTime() - new Date(rec.start_time).getTime()) / 1000;
} }
}); });
return data; return data;

View file

@ -114,11 +114,11 @@ header.b-calendar-grid-caption, .b-calendar-grid-weekdays *, header.b-calendar-h
.b-form-datepicker label:not(.text-muted), .b-form-timepicker label:not(.text-muted) .b-form-datepicker label:not(.text-muted), .b-form-timepicker label:not(.text-muted)
color: $font-primary !important color: $font-primary !important
input:disabled, .b-form-timepicker[aria-disabled=true], .b-form-datepicker[aria-disabled=true] input:disabled, .b-form-timepicker[aria-disabled=true], .b-form-datepicker[aria-disabled=true], .input-group-prepend.disabled *
color: $font-inactive !important color: $font-inactive !important
border-color: $background-primary !important border-color: $background-primary !important
input input, .input-group-prepend *
color: $font-primary !important color: $font-primary !important
border-color: $grey !important border-color: $grey !important
background-color: $background-primary !important background-color: $background-primary !important