diff --git a/companion/HELP.md b/companion/HELP.md index 0162d04..e127034 100644 --- a/companion/HELP.md +++ b/companion/HELP.md @@ -68,5 +68,5 @@ Presets are available for **Start Timer** and **Stop Timer**. - use module toggl-track instead of implementing api on our own - add status reports for some failure cases in connections dashboard - add configurable time entry poller -- add feedback for currently running project +- add feedback for currently running project and client - update timerDuration to contain the correct duration formatted as time string diff --git a/src/actions.ts b/src/actions.ts index c68e642..253ce2d 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -16,7 +16,7 @@ export default function (self: TogglTrack): void { label: 'Project', id: 'project', default: '0', - choices: self.projects!, + choices: self.projects ?? [{ id: -1, label: 'None' }], }, ], callback: async ({ options }) => { @@ -44,7 +44,15 @@ export default function (self: TogglTrack): void { name: 'Refresh Project List', options: [], callback: async () => { - await self.getWorkspace() + await self.getProjects() + }, + }, + + refreshStaticData: { + name: 'Refresh Workspace, Project and Client List', + options: [], + callback: async () => { + await self.loadStaticData() }, }, }) diff --git a/src/main.ts b/src/main.ts index e6bccae..3402ee3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -48,21 +48,13 @@ export class TogglTrack extends InstanceBase { this.config = config - this.projects = [{ id: 0, label: 'None' }] - this.updateVariableDefinitions() this.updatePresets() - this.setVariableValues({ - timerId: undefined, - timerDuration: undefined, - timerDescription: undefined, - lastTimerDuration: undefined, - workspace: undefined, - }) - await this.initToggleConnection() + await this.loadStaticData() + this.updateActions() this.updateFeedbacks() @@ -70,6 +62,7 @@ export class TogglTrack extends InstanceBase { this.updateStatus(InstanceStatus.Ok) } + await this.getCurrentTimer() if (this.config.startTimerPoller) { this.startTimeEntryPoller() } @@ -88,9 +81,10 @@ export class TogglTrack extends InstanceBase { this.log('debug', 'api token changed. init new toggle connection') this.toggl = undefined await this.initToggleConnection() + await this.loadStaticData() } else if (workSpaceDefaultChanged) { this.log('debug', 'workspace default changed. reload workspaces') - await this.getWorkspace() + await this.loadStaticData() } if (timeEntryPollerChanged) { @@ -141,8 +135,6 @@ export class TogglTrack extends InstanceBase { this.updateStatus(InstanceStatus.AuthenticationFailure, resp) return } - await this.getWorkspace() - await this.getCurrentTimer() } } @@ -229,7 +221,17 @@ export class TogglTrack extends InstanceBase { } } - async getWorkspace(): Promise { + async loadStaticData(): Promise { + if (!this.toggl) { + this.log('warn', 'loadStaticData: toggle connection not set up') + return + } + await this.getWorkspace() + await this.getProjects() + await this.getClients() + } + + private async getWorkspace(): Promise { this.log('debug', 'function: getWorkspace') if (!this.toggl) { this.log('warn', 'Not authorized') @@ -282,11 +284,9 @@ export class TogglTrack extends InstanceBase { const projects: IWorkspaceProject[] = await this.toggl!.projects.list(this.workspaceId) - //const projects: IWorkspaceProject[] = await togglGetProjects(this.toggl!, this.workspaceId!) - if (typeof projects === 'string' || projects.length == 0) { this.log('debug', 'No projects found') - this.projects = [{ id: 0, label: 'None' }] + this.projects = undefined this.log('debug', 'projects response' + JSON.stringify(projects)) return }