Skip to content

Commit

Permalink
馃悰 improved rounding feature (fixes Buggy saving #186)
Browse files Browse the repository at this point in the history
馃悰 remove archived projects from AI autocomplete selection
猬嗭笍 updated package dependencies
  • Loading branch information
faburem committed Sep 26, 2023
1 parent 3821804 commit 767dcfc
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 145 deletions.
6 changes: 3 additions & 3 deletions imports/ui/pages/track/components/magicPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Template.magicPopup.onRendered(() => {
templateInstance.showPopup.set(true)
})
templateInstance.autorun(() => {
if (templateInstance.showPopup.get() && Meteor.user().profile.googleAPIexpiresAt) {
if (templateInstance.showPopup.get() && Meteor.user()?.profile?.googleAPIexpiresAt) {
getMagicData(templateInstance)
} else if (Meteor.user().profile.googleAPIexpiresAt) {
} else if (Meteor.user()?.profile?.googleAPIexpiresAt) {
templateInstance.$('.robot').removeClass('d-none')
templateInstance.$('.js-datatable-container').addClass('d-none')
}
Expand All @@ -61,7 +61,7 @@ Template.magicPopup.helpers({
? Template.instance().magicData.get() : false),
renderProjectSelect: (projectId) => `<select class="form-control js-magic-project" required>
<option value="">${t('project.project_placeholder')}</option>
${Projects.find().fetch().map((project) => (project._id === projectId ? `<option value="${project._id}" selected>${project.name}</option>` : `<option value="${project._id}">${project.name}</option>`)).join('')}
${Projects.find({ $or: [{ archived: { $exists: false } }, { archived: false }] }).fetch().map((project) => (project._id === projectId ? `<option value="${project._id}" selected>${project.name}</option>` : `<option value="${project._id}">${project.name}</option>`)).join('')}
</select>`,
})

Expand Down
27 changes: 11 additions & 16 deletions imports/ui/pages/track/tracktime.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ Template.tracktime.onRendered(() => {
templateInstance.autorun(() => {
const timeEntry = templateInstance.time_entry.get()
if (timeEntry) {
// Meteor.setTimeout(() => {
for (const customfield of CustomFields.find({ classname: 'time_entry', possibleValues: { $exists: true } })) {
waitForElement(templateInstance, `#${customfield.name}`).then((element) => {
element.value = timeEntry[customfield.name]
})
}
// }, 500)
}
})
})
Expand Down Expand Up @@ -161,14 +159,14 @@ Template.tracktime.events({
showToast(t('notifications.enter_task'))
return
}
if (!hours) {
if (!hours && hours !== 0 && !Number.isNaN(hours)) {
templateInstance.$('#hours').addClass('is-invalid')
showToast(t('notifications.enter_time'))
return
}
try {
hours = hours.replace(',', '.')
templateInstance.math.eval(hours)
hours = templateInstance.math.eval(hours)
} catch (exception) {
showToast(t('notifications.check_time_input'))
return
Expand All @@ -190,8 +188,6 @@ Template.tracktime.events({
return
}
}
hours = templateInstance.math.eval(hours)

if (getUserSetting('timeunit') === 'd') {
hours *= getUserSetting('hoursToDays')
}
Expand Down Expand Up @@ -336,20 +332,19 @@ Template.tracktime.events({
templateInstance.$('.js-save').click()
}
},
'change #hours': (event, templateInstance) => {
'focusout #hours': (event, templateInstance) => {
event.preventDefault()
if (getUserSetting('rounding') && getUserSetting('rounding') !== 0) {
const hours = templateInstance.$('#hours').val()
let modulo = 1
const hours = Number.parseFloat(templateInstance.$('#hours').val().replace(',', '.'))
const rounding = 1 / Number.parseFloat(getUserSetting('rounding'))
let result = Math.round(rounding * hours) / rounding
if (getUserSetting('timeunit') === 'm') {
modulo = 60
}
if (getUserSetting('timeunit') === 'h') {
modulo = 1
result %= 60
} else if (getUserSetting('timeunit') === 'd') {
modulo = getUserSetting('hoursToDays')
result %= getUserSetting('hoursToDays')
}
if (hours) {
templateInstance.$('#hours').val((Math.ceil(hours / getUserSetting('rounding')) * getUserSetting('rounding')) % modulo)
if (result) {
templateInstance.$('#hours').val(result)
}
}
},
Expand Down

0 comments on commit 767dcfc

Please sign in to comment.