track client and add feedback for running client
This commit is contained in:
@@ -16,13 +16,34 @@ export function UpdateFeedbacks(self: TogglTrack): void {
|
|||||||
type: 'dropdown',
|
type: 'dropdown',
|
||||||
label: 'Project',
|
label: 'Project',
|
||||||
default: -1,
|
default: -1,
|
||||||
choices: [{ id: -1, label: 'None' }].concat(self.projects!),
|
choices: self.projects ?? [{ id: -1, label: 'None' }],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
callback: (feedback) => {
|
callback: (feedback) => {
|
||||||
const projID = self.getVariableValue('timerProjectID')
|
//self.log('debug', 'check project counting ' + feedback.options.project)
|
||||||
self.log('debug', 'check if ' + feedback.options.project + '=' + projID)
|
return feedback.options.project == self.currentEntry?.project_id
|
||||||
return feedback.options.project == projID
|
},
|
||||||
|
},
|
||||||
|
ClientRunningState: {
|
||||||
|
name: 'Client Counting',
|
||||||
|
type: 'boolean',
|
||||||
|
defaultStyle: {
|
||||||
|
bgcolor: combineRgb(255, 0, 0),
|
||||||
|
color: combineRgb(0, 0, 0),
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: 'client',
|
||||||
|
type: 'dropdown',
|
||||||
|
label: 'Client',
|
||||||
|
default: -1,
|
||||||
|
choices: self.clients ?? [{ id: -1, label: 'None' }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
callback: (feedback) => {
|
||||||
|
//self.log('debug', 'check client counting ' + feedback.options.client)
|
||||||
|
// find the project that matches the project_id of the current entry and compare its client_id with the configured one
|
||||||
|
return feedback.options.client == self.projects?.find((p) => p.id == self.currentEntry?.project_id)?.clientID
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
60
src/main.ts
60
src/main.ts
@@ -8,7 +8,7 @@ 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 { UpdateFeedbacks } from './feedbacks.js'
|
||||||
import { Toggl, ITimeEntry, IWorkspaceProject } from 'toggl-track'
|
import { Toggl, ITimeEntry, IWorkspaceProject, IClient } from 'toggl-track'
|
||||||
import { togglGetWorkspaces } from './toggl-extend.js'
|
import { togglGetWorkspaces } from './toggl-extend.js'
|
||||||
import { timecodeSince } from './utils.js'
|
import { timecodeSince } from './utils.js'
|
||||||
|
|
||||||
@@ -19,7 +19,10 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
|
|
||||||
workspaceId?: number // current active workspace id
|
workspaceId?: number // current active workspace id
|
||||||
workspaceName: string = '' // name of workspace
|
workspaceName: string = '' // name of workspace
|
||||||
projects?: { id: number; label: string }[]
|
projects?: { id: number; label: string; clientID?: number }[]
|
||||||
|
clients?: { id: number; label: string }[]
|
||||||
|
currentEntry?: ITimeEntry
|
||||||
|
|
||||||
intervalId?: NodeJS.Timeout
|
intervalId?: NodeJS.Timeout
|
||||||
currentTimerUpdaterIntervalId?: NodeJS.Timeout
|
currentTimerUpdaterIntervalId?: NodeJS.Timeout
|
||||||
|
|
||||||
@@ -163,13 +166,17 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
* @param entry running entry or undefined
|
* @param entry running entry or undefined
|
||||||
*/
|
*/
|
||||||
private setCurrentlyRunningTimeEntry(entry: ITimeEntry | undefined): void {
|
private setCurrentlyRunningTimeEntry(entry: ITimeEntry | undefined): void {
|
||||||
|
this.currentEntry = entry
|
||||||
if (entry) {
|
if (entry) {
|
||||||
|
const project = this.projects?.find((p) => p.id == entry.project_id)
|
||||||
this.setVariableValues({
|
this.setVariableValues({
|
||||||
timerId: entry.id,
|
timerId: entry.id,
|
||||||
timerDescription: entry.description,
|
timerDescription: entry.description,
|
||||||
timerDuration: timecodeSince(new Date(entry.start)),
|
timerDuration: timecodeSince(new Date(entry.start)),
|
||||||
timerProject: this.projects!.find((v) => v.id == entry?.project_id)?.label,
|
timerProject: project?.label,
|
||||||
timerProjectID: entry.project_id,
|
timerProjectID: entry.project_id,
|
||||||
|
timerClient: this.clients!.find((c) => c.id == project?.clientID)?.label,
|
||||||
|
timerClientID: project?.clientID,
|
||||||
})
|
})
|
||||||
|
|
||||||
// in case there is on update thread running clear it
|
// in case there is on update thread running clear it
|
||||||
@@ -192,9 +199,11 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
timerDuration: undefined,
|
timerDuration: undefined,
|
||||||
timerProject: undefined,
|
timerProject: undefined,
|
||||||
timerProjectID: undefined,
|
timerProjectID: undefined,
|
||||||
|
timerClient: undefined,
|
||||||
|
timerClientID: undefined,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.checkFeedbacks('ProjectRunningState')
|
this.checkFeedbacks('ProjectRunningState', 'ClientRunningState')
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCurrentTimer(): Promise<number | null> {
|
async getCurrentTimer(): Promise<number | null> {
|
||||||
@@ -260,6 +269,7 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
})
|
})
|
||||||
|
|
||||||
await this.getProjects()
|
await this.getProjects()
|
||||||
|
await this.getClients()
|
||||||
}
|
}
|
||||||
|
|
||||||
async getProjects(): Promise<void> {
|
async getProjects(): Promise<void> {
|
||||||
@@ -287,6 +297,7 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
return {
|
return {
|
||||||
id: p.id,
|
id: p.id,
|
||||||
label: p.name,
|
label: p.name,
|
||||||
|
clientID: p.client_id,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
@@ -305,6 +316,47 @@ export class TogglTrack extends InstanceBase<ModuleConfig> {
|
|||||||
this.log('debug', 'Projects: ' + JSON.stringify(this.projects))
|
this.log('debug', 'Projects: ' + JSON.stringify(this.projects))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async getClients(): Promise<void> {
|
||||||
|
this.log('debug', 'function: getClients ' + this.workspaceId)
|
||||||
|
|
||||||
|
if (!this.workspaceId) {
|
||||||
|
this.log('warn', 'workspaceId undefined')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const clients: IClient[] = await this.toggl!.me.clients()
|
||||||
|
|
||||||
|
if (typeof clients === 'string' || clients.length == 0) {
|
||||||
|
this.log('debug', 'No clients found')
|
||||||
|
this.clients = undefined
|
||||||
|
this.log('debug', 'clients response' + JSON.stringify(clients))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.clients = clients
|
||||||
|
.filter((c) => c.wid == this.workspaceId)
|
||||||
|
.map((c) => {
|
||||||
|
return {
|
||||||
|
id: c.id,
|
||||||
|
label: c.name,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sort((a, b) => {
|
||||||
|
const fa = a.label.toLowerCase()
|
||||||
|
const fb = b.label.toLowerCase()
|
||||||
|
|
||||||
|
if (fa < fb) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if (fa > fb) {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
})
|
||||||
|
|
||||||
|
this.log('debug', 'Clients: ' + JSON.stringify(this.clients))
|
||||||
|
}
|
||||||
|
|
||||||
async startTimer(project: number, description: string): Promise<void> {
|
async startTimer(project: number, description: string): Promise<void> {
|
||||||
if (!this.toggl || !this.workspaceId) {
|
if (!this.toggl || !this.workspaceId) {
|
||||||
this.log('error', 'toggle not initialized. Do not start time')
|
this.log('error', 'toggle not initialized. Do not start time')
|
||||||
|
|||||||
@@ -30,5 +30,13 @@ export default function (self: TogglTrack): void {
|
|||||||
name: 'Current Timer Project',
|
name: 'Current Timer Project',
|
||||||
variableId: 'timerProject',
|
variableId: 'timerProject',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'Current Timer Client ID',
|
||||||
|
variableId: 'timerClientID',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Current Timer Client',
|
||||||
|
variableId: 'timerClient',
|
||||||
|
},
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user