Skip to content

Commit

Permalink
🐛 fixed issue #10, the timer feature is now working again ⏱
Browse files Browse the repository at this point in the history
⬆️ regular package dependency updates
♻️ refactored code for better readability
  • Loading branch information
faburem committed Mar 26, 2020
1 parent 5313a1c commit 82ee3ca
Show file tree
Hide file tree
Showing 17 changed files with 89 additions and 75 deletions.
2 changes: 1 addition & 1 deletion docker-compose-auto-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
- "com.centurylinklabs.watchtower.enable=true"
restart: always
mongodb:
image: mongo:4.0
image: mongo:4.2
container_name: mongodb
restart: always
volumes:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ services:
- "3000:3000"
restart: always
mongodb:
image: mongo:4.0
image: mongo:4.2
container_name: mongodb
restart: always
14 changes: 14 additions & 0 deletions imports/api/timecards/methods.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dayjs from 'dayjs'
import i18next from 'i18next'
// import { VM } from 'vm2'
import { HTTP } from 'meteor/http'
import { check, Match } from 'meteor/check'
import { Promise } from 'meteor/promise'
Expand All @@ -24,6 +25,19 @@ function insertTimeCard(projectId, task, date, hours, userId) {
} else {
Tasks.update({ userId, name: task.replace(/(:.*:)/g, emojify) }, { $set: { lastUsed: new Date() } })
}
// const vm = new VM({
// timeout: 1000,
// sandbox: {
// user: Meteor.users.findOne({ _id: userId }).profile,
// timecard: {
// projectId,
// task,
// date,
// hours,
// },
// },
// })
// console.log(vm.run('this.user'))
return Timecards.insert({
userId,
projectId,
Expand Down
4 changes: 2 additions & 2 deletions imports/startup/client/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Meteor.startup(() => {
Template.registerHelper('i18nextReady', () => i18nextReady.get())
Template.registerHelper('unit', () => {
if (!Meteor.loggingIn() && Meteor.user() && Meteor.user().profile) {
return getUserSetting('unit') ? getUserSetting('unit') : getGlobalSetting('unit')
return getUserSetting('unit')
}
return false
})
Expand Down Expand Up @@ -229,7 +229,7 @@ Template.registerHelper('timeunitVerbose', () => {
})
Template.registerHelper('timetrackview', () => {
if (!Meteor.loggingIn() && Meteor.user() && Meteor.user().profile) {
return getUserSetting('timetrackview') ? getUserSetting('timetrackview') : getGlobalSetting('timetrackview')
return getUserSetting('timetrackview')
}
return false
})
Expand Down
5 changes: 1 addition & 4 deletions imports/ui/components/allprojectschart.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Template.allprojectschart.helpers({
})
Template.allprojectschart.onRendered(() => {
const templateInstance = Template.instance()
const precision = getUserSetting('precision') ? getUserSetting('precision') : getGlobalSetting('precision')
const precision = getUserSetting('precision')
templateInstance.autorun(() => {
if (templateInstance.subscriptionsReady()) {
if (templateInstance.projectStats.get()) {
Expand All @@ -46,17 +46,14 @@ Template.allprojectschart.onRendered(() => {
if (getUserSetting('timeunit') === 'd') {
stats.beforePreviousMonthHours
/= getUserSetting('hoursToDays')
? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays')
stats.beforePreviousMonthHours = Number(stats.beforePreviousMonthHours)
.toFixed(precision)
stats.previousMonthHours
/= getUserSetting('hoursToDays')
? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays')
stats.previousMonthHours = Number(stats.previousMonthHours)
.toFixed(precision)
stats.currentMonthHours
/= getUserSetting('hoursToDays')
? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays')
stats.currentMonthHours = Number(stats.currentMonthHours).toFixed(precision)
}
templateInstance.chart = new Chart(templateInstance.$('.js-chart-container')[0], {
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/components/projectProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Template.projectProgress.onCreated(function projectProgressCreated() {
})
Template.projectProgress.helpers({
totalHours() {
const precision = getUserSetting('precision') ? getUserSetting('precision') : getGlobalSetting('precision')
const precision = getUserSetting('precision')
const projectStats = ProjectStats.findOne({ _id: Template.currentData()._id })
return projectStats
? Number(projectStats.totalHours).toFixed(precision)
Expand Down
17 changes: 9 additions & 8 deletions imports/ui/components/timetracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { Meteor } from 'meteor/meteor'
import { Template } from 'meteor/templating'
import { ReactiveVar } from 'meteor/reactive-var'
import dayjs from 'dayjs'
import preciseDiff from 'dayjs-precise-range'
import './timetracker.html'
import { getGlobalSetting, getUserSetting } from '../../utils/frontend_helpers'

Template.timetracker.onCreated(function createTimeTracker() {
this.timer = new ReactiveVar(null)
dayjs.extend(preciseDiff)
})
function pad(num, size) {
const s = `0000${num}`
Expand All @@ -16,19 +18,18 @@ function pad(num, size) {
Template.timetracker.events({
'click .js-stop': (event, templateInstance) => {
event.preventDefault()
const precision = getUserSetting('precision') ? getUserSetting('precision') : getGlobalSetting('precision')
templateInstance.$('#hours').val(dayjs.duration(dayjs().valueOf() - templateInstance.timer.get().valueOf()).asHours().toFixed(precision))
const duration = dayjs.preciseDiff(dayjs(), templateInstance.timer.get(), true)
const hours = (Number(duration.days * getUserSetting('hoursToDays'))) + Number(duration.hours) + Number((duration.minutes / 60))
$('#hours').val(Number(hours).toFixed(getUserSetting('precision')))
Meteor.clearTimeout(templateInstance.intervalHandle)
Template.instance().timer.set(null)
},
'click .js-start': (event, templateInstance) => {
event.preventDefault()
Template.instance().timer.set(dayjs())
const timer = templateInstance.timer.get()
Template.instance().intervalHandle = Meteor.setInterval(function handleTimer() {
// console.log(timer)
const duration = dayjs.duration(dayjs().valueOf() - timer.get().valueOf())
this.$('.js-timer').text(`${pad(duration.hours(), 2)}:${pad(duration.minutes(), 2)}:${pad(duration.seconds(), 2)}`)
templateInstance.timer.set(dayjs())
templateInstance.intervalHandle = Meteor.setInterval(function handleTimer() {
const duration = dayjs.preciseDiff(dayjs(), templateInstance.timer.get(), true)
this.$('.js-timer').text(`${pad(duration.hours, 2)}:${pad(duration.minutes, 2)}:${pad(duration.seconds, 2)}`)
}, 1000)
},
})
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/components/weektable.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Template.weektable.events({
}
let hours = Number(value)
if (getUserSetting('timeunit') === 'd') {
hours *= (getUserSetting('hoursToDays') ? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays'))
hours *= (getUserSetting('hoursToDays'))
}
weekArray.push({
projectId: $(element).data('project-id'),
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/pages/editproject.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Template.editproject.events({
const projectArray = templateInstance.$('#editProjectForm').serializeArray()
projectArray.push({ name: 'desc', value: Template.instance().quill.getContents() })
if (getUserSetting('timeunit') === 'd') {
templateInstance.$('#target').val(templateInstance.$('#target').val() * (getUserSetting('hoursToDays') ? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays')))
templateInstance.$('#target').val(templateInstance.$('#target').val() * (getUserSetting('hoursToDays')))
}
if (FlowRouter.getParam('id')) {
Meteor.call('updateProject', {
Expand Down
36 changes: 18 additions & 18 deletions imports/ui/pages/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@ Template.settings.onRendered(function settingsRendered() {
templateInstance.autorun(() => {
if (!Meteor.loggingIn() && Meteor.user()
&& Meteor.user().profile && this.subscriptionsReady()) {
templateInstance.$('#timeunit').val(getUserSetting('timeunit') ? getUserSetting('timeunit') : getGlobalSetting('timeunit'))
templateInstance.$('#timetrackview').val(getUserSetting('timetrackview') ? getUserSetting('timetrackview') : getGlobalSetting('timetrackview'))
templateInstance.$('#dailyStartTime').val(getUserSetting('dailyStartTime') ? getUserSetting('dailyStartTime') : getGlobalSetting('dailyStartTime'))
templateInstance.$('#breakStartTime').val(getUserSetting('breakStartTime') ? getUserSetting('breakStartTime') : getGlobalSetting('breakStartTime'))
templateInstance.$('#breakDuration').val(getUserSetting('breakDuration') ? getUserSetting('breakDuration') : getGlobalSetting('breakDuration'))
templateInstance.$('#regularWorkingTime').val(getUserSetting('regularWorkingTime') ? getUserSetting('regularWorkingTime') : getGlobalSetting('regularWorkingTime'))
templateInstance.$('#timeunit').val(getUserSetting('timeunit'))
templateInstance.$('#timetrackview').val(getUserSetting('timetrackview'))
templateInstance.$('#dailyStartTime').val(getUserSetting('dailyStartTime'))
templateInstance.$('#breakStartTime').val(getUserSetting('breakStartTime'))
templateInstance.$('#breakDuration').val(getUserSetting('breakDuration'))
templateInstance.$('#regularWorkingTime').val(getUserSetting('regularWorkingTime'))
}
})
})

Template.settings.helpers({
unit: () => (getUserSetting('timeunit') ? getUserSetting('timeunit') : getGlobalSetting('unit')),
dailyStartTime: () => (Meteor.user() ? getUserSetting('dailyStartTime') : getGlobalSetting('dailyStartTime')),
breakStartTime: () => (Meteor.user() ? getUserSetting('breakStartTime') : getGlobalSetting('breakStartTime')),
breakDuration: () => (Meteor.user() ? getUserSetting('breakDuration') : getGlobalSetting('breakDuration')),
regularWorkingTime: () => (Meteor.user() ? getUserSetting('regularWorkingTime') : getGlobalSetting('regularWorkingTime')),
precision: () => (getUserSetting('precision') ? getUserSetting('precision') : getGlobalSetting('precision')),
timetrackview: () => (getUserSetting('timetrackview') ? getUserSetting('timetrackview') : getGlobalSetting('timetrackview')),
hoursToDays: () => (getUserSetting('hoursToDays') ? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays')),
unit: () => getUserSetting('timeunit'),
dailyStartTime: () => getUserSetting('dailyStartTime'),
breakStartTime: () => getUserSetting('breakStartTime'),
breakDuration: () => getUserSetting('breakDuration'),
regularWorkingTime: () => getUserSetting('regularWorkingTime'),
precision: () => getUserSetting('precision'),
timetrackview: () => getUserSetting('timetrackview'),
hoursToDays: () => getUserSetting('hoursToDays'),
displayHoursToDays: () => Template.instance().displayHoursToDays.get(),
enableWekan: () => (getUserSetting('enableWekan') ? getUserSetting('enableWekan') : getGlobalSetting('enableWekan')),
siwappurl: () => (getUserSetting('siwappurl') ? getUserSetting('siwappurl') : false),
siwapptoken: () => (getUserSetting('siwapptoken') ? getUserSetting('siwapptoken') : false),
titraAPItoken: () => (getUserSetting('APItoken') ? getUserSetting('APItoken') : false),
enableWekan: () => getUserSetting('enableWekan'),
siwappurl: () => getUserSetting('siwappurl'),
siwapptoken: () => getUserSetting('siwapptoken'),
titraAPItoken: () => getUserSetting('APItoken'),
})


Expand Down
2 changes: 1 addition & 1 deletion imports/ui/pages/tracktime.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Template.tracktime.events({
hours = templateInstance.math.eval(hours)

if (getUserSetting('timeunit') === 'd') {
hours *= (getUserSetting('hoursToDays') ? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays'))
hours *= getUserSetting('hoursToDays')
}
const buttonLabel = $('.js-save').text()
templateInstance.$('.js-save').text(i18next.t('navigation.saving'))
Expand Down
9 changes: 4 additions & 5 deletions imports/utils/frontend_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { Globalsettings } from '../api/globalsettings/globalsettings.js'
const clientTimecards = new Mongo.Collection('clientTimecards')

function getGlobalSetting(name) {
return Globalsettings.findOne({ name }) ? Globalsettings.findOne({ name }).value : ''
return Globalsettings.findOne({ name }) ? Globalsettings.findOne({ name }).value : false
}

function getUserSetting(field) {
check(field, String)
if ((Meteor.isClient && !Meteor.loggingIn()) && Meteor.user() && Meteor.user().profile) {
return Meteor.user().profile[field]
return Meteor.user().profile[field] ? Meteor.user().profile[field] : getGlobalSetting(field)
}
return false
}
Expand All @@ -36,10 +36,9 @@ function timeInUserUnit(time) {
if (!time || time === 0) {
return false
}
const precision = getUserSetting('precision') ? getUserSetting('precision') : getGlobalSetting('precision')
const precision = getUserSetting('precision')
if (getUserSetting('timeunit') === 'd') {
const convertedTime = Number(time / (getUserSetting('hoursToDays')
? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays'))).toFixed(precision)
const convertedTime = Number(time / getUserSetting('hoursToDays')).toFixed(precision)
return convertedTime !== Number(0).toFixed(precision) ? convertedTime : undefined
}
if (time) {
Expand Down
7 changes: 3 additions & 4 deletions imports/utils/periodHelpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import { getGlobalSetting } from './frontend_helpers'
import { getGlobalSetting, getUserSetting } from './frontend_helpers'

function periodToDates(period) {
check(period, String)
Expand Down Expand Up @@ -44,10 +44,9 @@ function periodToDates(period) {
return { startDate, endDate }
}
function timeInUserUnit(time, meteorUser) {
const precision = meteorUser.profile.precision ? meteorUser.profile.precision : getGlobalSetting('precision')
const precision = getUserSetting('precision')
if (meteorUser.profile.timeunit === 'd') {
const convertedTime = Number(time / (meteorUser.profile.hoursToDays
? meteorUser.profile.hoursToDays : getGlobalSetting('hoursToDays'))).toFixed(precision)
const convertedTime = Number(time / (getUserSetting('hoursToDays'))).toFixed(precision)
return convertedTime !== Number(0).toFixed(precision) ? convertedTime : undefined
}
return Number(time).toFixed(precision)
Expand Down
6 changes: 2 additions & 4 deletions imports/utils/server_method_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ function totalHoursForPeriodMapper(entry) {
let { totalHours } = entry
if (Meteor.user()) {
if (getUserSetting('timeunit') === 'd') {
totalHours = Number(entry.totalHours / (getUserSetting('hoursToDays')
? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays')))
totalHours = Number(entry.totalHours / getUserSetting('hoursToDays'))
}
}
return {
Expand All @@ -74,8 +73,7 @@ function dailyTimecardMapper(entry) {
let { totalHours } = entry
if (Meteor.user()) {
if (getUserSetting('timeunit') === 'd') {
totalHours = Number(entry.totalHours / (getUserSetting('hoursToDays')
? getUserSetting('hoursToDays') : getGlobalSetting('hoursToDays')))
totalHours = Number(entry.totalHours / getUserSetting('hoursToDays'))
}
}
return {
Expand Down
37 changes: 21 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 82ee3ca

Please sign in to comment.