44 <el-form :model =" form" >
55 <el-form-item label =" Time spent" >
66 <el-input
7- v-model =" form.worklog. timeSpent"
7+ v-model =" form.timeSpent"
88 placeholder =" 1d 9h 12m"
99 autocomplete =" off"
1010 @blur =" handleBlur"
1111 />
1212 </el-form-item >
1313 <el-form-item label =" Date" >
1414 <el-date-picker
15- v-model =" form.worklog. started"
15+ v-model =" form.started"
1616 :readonly =" false"
1717 type =" datetime"
18- value- format =" yyyy-MM-ddTHH :mm:ss.000ZZ "
18+ format =" yyyy-MM-dd HH :mm"
1919 placeholder =" Started datetime"
2020 />
2121 </el-form-item >
3434
3535<script >
3636import moment from ' moment'
37+ import service from ' @/service'
38+
39+ const getWorkedTimeParsed = timeSpent => {
40+ const getNumberBeforeLetter = letter => {
41+ const regex = new RegExp (` (\\ d+)${ letter} ` , ' i' )
42+ return + (regex .exec (timeSpent) || [0 , 0 ])[1 ]
43+ }
44+ return [' d' , ' h' , ' m' ].map (getNumberBeforeLetter)
45+ }
46+
47+ const parseToSeconds = timeSpent => {
48+ const [days , hours , minutes ] = getWorkedTimeParsed (timeSpent)
49+
50+ const minute = 60
51+ const hour = minute * 60
52+ const day = hour * 24
53+
54+ return (days * day) + (hours * hour) + (minutes * minute)
55+ }
3756
3857export default {
3958 data () {
4059 return {
4160 dialogVisible: false ,
4261 form: {
43- worklog: {}
62+ timeSpent: null ,
63+ started: null
4464 },
4565 issue: null
4666 }
@@ -50,42 +70,31 @@ export default {
5070 this .issue = issue
5171 this .dialogVisible = true
5272 this .form = {
53- worklog: {}
73+ timeSpent: null ,
74+ started: null
5475 }
5576 },
5677 submitForm () {
57- this .$jira .issue .addWorkLog ({
58- issueId: this .issue .id ,
59- ... this .form
60- }).then (response => {
61- this .$notify ({
62- title: ' Success' ,
63- message: ' Worklog saved' ,
64- type: ' success'
78+ const timeSpentSeconds = parseToSeconds (this .form .timeSpent )
79+ service .addWorkLog (this .issue .id , moment (this .form .started ), timeSpentSeconds)
80+ .then (() => {
81+ this .$notify ({
82+ title: ' Success' ,
83+ message: ' Worklog saved' ,
84+ type: ' success'
85+ })
86+ this .closeDialog ()
6587 })
66- this .closeDialog ()
67- }).catch (this .handleErrors )
88+ .catch (this .handleErrors )
6889 },
6990 closeDialog () {
7091 this .issue = null
7192 this .dialogVisible = false
7293 },
73- handleBlur (event ) {
74- const inputValue = event .target .value
75- const getNumberBeforeLetter = letter => {
76- const regex = new RegExp (` (\\ d+)${ letter} ` , ' i' )
77- return + (regex .exec (inputValue) || [0 , 0 ])[1 ]
78- }
79- const [days , hours , minutes ] = [' d' , ' h' , ' m' ].map (getNumberBeforeLetter)
80-
81- const startDate = moment ().subtract ({
82- days,
83- hours,
84- minutes
85- }).toDate ()
86- if (! this .form .worklog .started ) {
87- this .$set (this .form .worklog , ' started' , startDate)
88- }
94+ handleBlur () {
95+ const [days , hours , minutes ] = getWorkedTimeParsed (this .form .timeSpent )
96+ const startDate = moment ().subtract ({ days, hours, minutes }).toDate ()
97+ if (! this .form .started ) this .$set (this .form , ' started' , startDate)
8998 }
9099 }
91100}
0 commit comments