add feedback for currently running project
This commit is contained in:
29
src/feedbacks.ts
Normal file
29
src/feedbacks.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { combineRgb } from '@companion-module/base'
|
||||||
|
import type { TogglTrack } from './main.js'
|
||||||
|
|
||||||
|
export function UpdateFeedbacks(self: TogglTrack): void {
|
||||||
|
self.setFeedbackDefinitions({
|
||||||
|
ProjectRunningState: {
|
||||||
|
name: 'Project Counting',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultStyle: {
|
||||||
|
bgcolor: combineRgb(255, 0, 0),
|
||||||
|
color: combineRgb(0, 0, 0),
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: 'project',
|
||||||
|
type: 'dropdown',
|
||||||
|
label: 'Project',
|
||||||
|
default: -1,
|
||||||
|
choices: [{ id: -1, label: 'None' }].concat(self.projects!),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
callback: (feedback) => {
|
||||||
|
const projID = self.getVariableValue('timerProjectID')
|
||||||
|
self.log('debug', 'check if ' + feedback.options.project + '=' + projID)
|
||||||
|
return feedback.options.project == projID
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
21
src/main.ts
21
src/main.ts
@@ -7,6 +7,7 @@ import UpdateActions from './actions.js'
|
|||||||
import UpdatePresets from './presets.js'
|
import UpdatePresets from './presets.js'
|
||||||
import UpdateVariableDefinitions from './variables.js'
|
import UpdateVariableDefinitions from './variables.js'
|
||||||
import UpgradeScripts from './upgrades.js'
|
import UpgradeScripts from './upgrades.js'
|
||||||
|
import { UpdateFeedbacks } from './feedbacks.js'
|
||||||
import { Toggl, ITimeEntry, IWorkspaceProject } from 'toggl-track'
|
import { Toggl, ITimeEntry, IWorkspaceProject } from 'toggl-track'
|
||||||
import { togglGetWorkspaces } from './toggl-extend.js'
|
import { togglGetWorkspaces } from './toggl-extend.js'
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
await this.initToggleConnection()
|
await this.initToggleConnection()
|
||||||
|
|
||||||
this.updateActions()
|
this.updateActions()
|
||||||
|
this.updateFeedbacks()
|
||||||
|
|
||||||
if (this.toggl && this.workspaceId) {
|
if (this.toggl && this.workspaceId) {
|
||||||
this.updateStatus(InstanceStatus.Ok)
|
this.updateStatus(InstanceStatus.Ok)
|
||||||
@@ -105,6 +107,9 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
updateActions(): void {
|
updateActions(): void {
|
||||||
UpdateActions(this)
|
UpdateActions(this)
|
||||||
}
|
}
|
||||||
|
updateFeedbacks(): void {
|
||||||
|
UpdateFeedbacks(this)
|
||||||
|
}
|
||||||
|
|
||||||
updatePresets(): void {
|
updatePresets(): void {
|
||||||
UpdatePresets(this)
|
UpdatePresets(this)
|
||||||
@@ -149,6 +154,18 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
clearInterval(this.intervalId)
|
clearInterval(this.intervalId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setCurrentProject(projectID: number | undefined): void {
|
||||||
|
let pName: string | undefined
|
||||||
|
if (typeof projectID === 'number') {
|
||||||
|
pName = this.projects!.find((v) => v.id == projectID)?.label
|
||||||
|
}
|
||||||
|
this.setVariableValues({
|
||||||
|
timerProject: pName,
|
||||||
|
timerProjectID: projectID,
|
||||||
|
})
|
||||||
|
this.checkFeedbacks('ProjectRunningState')
|
||||||
|
}
|
||||||
|
|
||||||
async getCurrentTimer(): Promise<number | null> {
|
async getCurrentTimer(): Promise<number | null> {
|
||||||
this.log('debug', 'function: getCurrentTimer')
|
this.log('debug', 'function: getCurrentTimer')
|
||||||
|
|
||||||
@@ -167,6 +184,7 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
timerDescription: entry.description,
|
timerDescription: entry.description,
|
||||||
timerDuration: entry.duration,
|
timerDuration: entry.duration,
|
||||||
})
|
})
|
||||||
|
this.setCurrentProject(entry.project_id)
|
||||||
|
|
||||||
return entry.id
|
return entry.id
|
||||||
} else {
|
} else {
|
||||||
@@ -176,6 +194,7 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
timerDescription: undefined,
|
timerDescription: undefined,
|
||||||
timerDuration: undefined,
|
timerDuration: undefined,
|
||||||
})
|
})
|
||||||
|
this.setCurrentProject(undefined)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,6 +308,7 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
timerDescription: newEntry.description,
|
timerDescription: newEntry.description,
|
||||||
timerDuration: newEntry.duration,
|
timerDuration: newEntry.duration,
|
||||||
})
|
})
|
||||||
|
this.setCurrentProject(newEntry.project_id)
|
||||||
} else {
|
} else {
|
||||||
this.log('info', 'A timer is already running ' + currentId + ' not starting a new one!')
|
this.log('info', 'A timer is already running ' + currentId + ' not starting a new one!')
|
||||||
}
|
}
|
||||||
@@ -314,6 +334,7 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
timerDuration: undefined,
|
timerDuration: undefined,
|
||||||
lastTimerDuration: updated.duration,
|
lastTimerDuration: updated.duration,
|
||||||
})
|
})
|
||||||
|
this.setCurrentProject(undefined)
|
||||||
} else {
|
} else {
|
||||||
this.log('warn', 'No running timer to stop or running timer id unknown')
|
this.log('warn', 'No running timer to stop or running timer id unknown')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,13 @@ export default function (self: TogglTrack): void {
|
|||||||
name: 'Current Timer Description',
|
name: 'Current Timer Description',
|
||||||
variableId: 'timerDescription',
|
variableId: 'timerDescription',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Current Timer Project ID',
|
||||||
|
variableId: 'timerProjectID',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Current Timer Project',
|
||||||
|
variableId: 'timerProject',
|
||||||
|
},
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user