add loadStaticData() which loads data in steps instead of chaining through 'getWorkspace'
This commit is contained in:
@@ -68,5 +68,5 @@ Presets are available for **Start Timer** and **Stop Timer**.
|
|||||||
- use module toggl-track instead of implementing api on our own
|
- use module toggl-track instead of implementing api on our own
|
||||||
- add status reports for some failure cases in connections dashboard
|
- add status reports for some failure cases in connections dashboard
|
||||||
- add configurable time entry poller
|
- 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
|
- update timerDuration to contain the correct duration formatted as time string
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export default function (self: TogglTrack): void {
|
|||||||
label: 'Project',
|
label: 'Project',
|
||||||
id: 'project',
|
id: 'project',
|
||||||
default: '0',
|
default: '0',
|
||||||
choices: self.projects!,
|
choices: self.projects ?? [{ id: -1, label: 'None' }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
callback: async ({ options }) => {
|
callback: async ({ options }) => {
|
||||||
@@ -44,7 +44,15 @@ export default function (self: TogglTrack): void {
|
|||||||
name: 'Refresh Project List',
|
name: 'Refresh Project List',
|
||||||
options: [],
|
options: [],
|
||||||
callback: async () => {
|
callback: async () => {
|
||||||
await self.getWorkspace()
|
await self.getProjects()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
refreshStaticData: {
|
||||||
|
name: 'Refresh Workspace, Project and Client List',
|
||||||
|
options: [],
|
||||||
|
callback: async () => {
|
||||||
|
await self.loadStaticData()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
34
src/main.ts
34
src/main.ts
@@ -48,21 +48,13 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
|
|
||||||
this.config = config
|
this.config = config
|
||||||
|
|
||||||
this.projects = [{ id: 0, label: 'None' }]
|
|
||||||
|
|
||||||
this.updateVariableDefinitions()
|
this.updateVariableDefinitions()
|
||||||
this.updatePresets()
|
this.updatePresets()
|
||||||
|
|
||||||
this.setVariableValues({
|
|
||||||
timerId: undefined,
|
|
||||||
timerDuration: undefined,
|
|
||||||
timerDescription: undefined,
|
|
||||||
lastTimerDuration: undefined,
|
|
||||||
workspace: undefined,
|
|
||||||
})
|
|
||||||
|
|
||||||
await this.initToggleConnection()
|
await this.initToggleConnection()
|
||||||
|
|
||||||
|
await this.loadStaticData()
|
||||||
|
|
||||||
this.updateActions()
|
this.updateActions()
|
||||||
this.updateFeedbacks()
|
this.updateFeedbacks()
|
||||||
|
|
||||||
@@ -70,6 +62,7 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
this.updateStatus(InstanceStatus.Ok)
|
this.updateStatus(InstanceStatus.Ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.getCurrentTimer()
|
||||||
if (this.config.startTimerPoller) {
|
if (this.config.startTimerPoller) {
|
||||||
this.startTimeEntryPoller()
|
this.startTimeEntryPoller()
|
||||||
}
|
}
|
||||||
@@ -88,9 +81,10 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
this.log('debug', 'api token changed. init new toggle connection')
|
this.log('debug', 'api token changed. init new toggle connection')
|
||||||
this.toggl = undefined
|
this.toggl = undefined
|
||||||
await this.initToggleConnection()
|
await this.initToggleConnection()
|
||||||
|
await this.loadStaticData()
|
||||||
} else if (workSpaceDefaultChanged) {
|
} else if (workSpaceDefaultChanged) {
|
||||||
this.log('debug', 'workspace default changed. reload workspaces')
|
this.log('debug', 'workspace default changed. reload workspaces')
|
||||||
await this.getWorkspace()
|
await this.loadStaticData()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeEntryPollerChanged) {
|
if (timeEntryPollerChanged) {
|
||||||
@@ -141,8 +135,6 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
this.updateStatus(InstanceStatus.AuthenticationFailure, resp)
|
this.updateStatus(InstanceStatus.AuthenticationFailure, resp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await this.getWorkspace()
|
|
||||||
await this.getCurrentTimer()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,7 +221,17 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getWorkspace(): Promise<void> {
|
async loadStaticData(): Promise<void> {
|
||||||
|
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<void> {
|
||||||
this.log('debug', 'function: getWorkspace')
|
this.log('debug', 'function: getWorkspace')
|
||||||
if (!this.toggl) {
|
if (!this.toggl) {
|
||||||
this.log('warn', 'Not authorized')
|
this.log('warn', 'Not authorized')
|
||||||
@@ -282,11 +284,9 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
|
|
||||||
const projects: IWorkspaceProject[] = await this.toggl!.projects.list(this.workspaceId)
|
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) {
|
if (typeof projects === 'string' || projects.length == 0) {
|
||||||
this.log('debug', 'No projects found')
|
this.log('debug', 'No projects found')
|
||||||
this.projects = [{ id: 0, label: 'None' }]
|
this.projects = undefined
|
||||||
this.log('debug', 'projects response' + JSON.stringify(projects))
|
this.log('debug', 'projects response' + JSON.stringify(projects))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user