Prettified Code!

This commit is contained in:
daniep01
2023-06-29 12:12:35 +00:00
committed by GitHub Action
parent 31da474061
commit 853a97db81
5 changed files with 135 additions and 134 deletions

View File

@@ -15,7 +15,6 @@ class toggltrack extends InstanceBase {
this.updateActions = updateActions.bind(this) this.updateActions = updateActions.bind(this)
this.updatePresets = updatePresets.bind(this) this.updatePresets = updatePresets.bind(this)
this.updateVariables = updateVariables.bind(this) this.updateVariables = updateVariables.bind(this)
} }
getConfigFields() { getConfigFields() {
@@ -50,7 +49,7 @@ class toggltrack extends InstanceBase {
this.gotOptions = { this.gotOptions = {
responseType: 'json', responseType: 'json',
throwHttpErrors: false throwHttpErrors: false,
} }
this.gotOptions.prefixUrl = this.prefixUrl this.gotOptions.prefixUrl = this.prefixUrl
@@ -73,13 +72,10 @@ class toggltrack extends InstanceBase {
this.gotOptions.headers = this.auth() this.gotOptions.headers = this.auth()
if (this.gotOptions.headers != null) { if (this.gotOptions.headers != null) {
this.getWorkspace().then( this.getWorkspace().then(this.getCurrentTimer())
this.getCurrentTimer()
)
} }
this.updateActions() this.updateActions()
} }
async configUpdated(config) { async configUpdated(config) {
@@ -89,9 +85,7 @@ class toggltrack extends InstanceBase {
this.gotOptions.headers = this.auth() this.gotOptions.headers = this.auth()
if (this.gotOptions.headers != null) { if (this.gotOptions.headers != null) {
this.getWorkspace().then( this.getWorkspace().then(this.getCurrentTimer())
this.getCurrentTimer()
)
} }
this.updateActions() this.updateActions()
@@ -122,8 +116,7 @@ class toggltrack extends InstanceBase {
let cmd = 'me/time_entries/current' let cmd = 'me/time_entries/current'
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.sendGetCommand(cmd).then( this.sendGetCommand(cmd).then((result) => {
(result) => {
if (typeof result === 'object' && result !== null) { if (typeof result === 'object' && result !== null) {
if ('id' in result) { if ('id' in result) {
this.setVariableValues({ this.setVariableValues({
@@ -138,7 +131,7 @@ class toggltrack extends InstanceBase {
this.setVariableValues({ this.setVariableValues({
timerId: null, timerId: null,
timerDescription: null, timerDescription: null,
timerDuration: null timerDuration: null,
}) })
resolve(null) resolve(null)
} }
@@ -147,12 +140,11 @@ class toggltrack extends InstanceBase {
this.setVariableValues({ this.setVariableValues({
timerId: null, timerId: null,
timerDescription: null, timerDescription: null,
timerDuration: null timerDuration: null,
}) })
resolve(null) resolve(null)
} }
} })
)
}) })
} }
@@ -168,12 +160,11 @@ class toggltrack extends InstanceBase {
// reset // reset
this.workspace = null this.workspace = null
this.setVariableValues({ this.setVariableValues({
workspace: null workspace: null,
}) })
// get workspace ID // get workspace ID
this.sendGetCommand(cmd).then( this.sendGetCommand(cmd).then((result) => {
(result) => {
// console.log('result ' + JSON.stringify(result, null, 4)) // console.log('result ' + JSON.stringify(result, null, 4))
if (typeof result === 'object' && result !== null) { if (typeof result === 'object' && result !== null) {
console.log('Found ' + result.length + ' workspace') console.log('Found ' + result.length + ' workspace')
@@ -183,7 +174,7 @@ class toggltrack extends InstanceBase {
this.workspaceName = result[0].name this.workspaceName = result[0].name
this.log('info', 'Workspace: ' + this.workspace + ' - ' + this.workspaceName) this.log('info', 'Workspace: ' + this.workspace + ' - ' + this.workspaceName)
this.setVariableValues({ this.setVariableValues({
workspace: this.workspaceName workspace: this.workspaceName,
}) })
this.getProjects() this.getProjects()
} }
@@ -191,8 +182,7 @@ class toggltrack extends InstanceBase {
console.log('result ' + JSON.stringify(result, null, 4)) console.log('result ' + JSON.stringify(result, null, 4))
this.log('debug', 'No workspace') this.log('debug', 'No workspace')
} }
} })
)
} }
getProjects() { getProjects() {
@@ -200,8 +190,7 @@ class toggltrack extends InstanceBase {
if (this.workspace !== null) { if (this.workspace !== null) {
let cmd = 'workspaces/' + this.workspace + '/projects' let cmd = 'workspaces/' + this.workspace + '/projects'
this.sendGetCommand(cmd).then( this.sendGetCommand(cmd).then((result) => {
(result) => {
// console.log('result ' + JSON.stringify(result, null, 4)) // console.log('result ' + JSON.stringify(result, null, 4))
if (typeof result === 'object' && result !== null) { if (typeof result === 'object' && result !== null) {
// reset // reset
@@ -285,18 +274,31 @@ class toggltrack extends InstanceBase {
// no timer currently running or we want to restart it // no timer currently running or we want to restart it
cmd = 'workspaces/' + this.workspace + '/time_entries' cmd = 'workspaces/' + this.workspace + '/time_entries'
if (project == '0') { if (project == '0') {
body = '{"wid":' + this.workspace + ',"description":"' + description + body =
'","created_with":"companion",' + '"start":"' + startTime.toISOString() + '","duration":-1}' '{"wid":' +
this.workspace +
',"description":"' +
description +
'","created_with":"companion",' +
'"start":"' +
startTime.toISOString() +
'","duration":-1}'
} else { } else {
body = body =
'{"wid":' + this.workspace + ',"description":"' + description + '{"wid":' +
'","created_with":"companion","project_id":' + project + this.workspace +
',"start":"' + startTime.toISOString() + '","duration":-1}' ',"description":"' +
description +
'","created_with":"companion","project_id":' +
project +
',"start":"' +
startTime.toISOString() +
'","duration":-1}'
} }
// console.log(body) // console.log(body)
this.sendPostCommand(cmd, body).then((result) => { this.sendPostCommand(cmd, body).then((result) => {
if (typeof result === 'object' && result !== null) { if (typeof result === 'object' && result !== null) {
this.log('info', 'New timer started ' + result.id + " " + result.description) this.log('info', 'New timer started ' + result.id + ' ' + result.description)
this.setVariableValues({ this.setVariableValues({
timerId: result.id, timerId: result.id,
timerDescription: result.description, timerDescription: result.description,
@@ -414,13 +416,11 @@ class toggltrack extends InstanceBase {
} }
async sendPostCommand(cmd, body) { async sendPostCommand(cmd, body) {
console.log(body) console.log(body)
let response let response
let postdata = {} let postdata = {}
postdata.prefixUrl = this.prefixUrl postdata.prefixUrl = this.prefixUrl
postdata.responseType = 'json', ;(postdata.responseType = 'json'), (postdata.throwHttpErrors = false)
postdata.throwHttpErrors = false
postdata.headers = this.auth() postdata.headers = this.auth()
postdata.json = JSON.parse(body) postdata.json = JSON.parse(body)

View File

@@ -13,8 +13,10 @@ export function updatePresets() {
color: combineRgb(255, 255, 255), color: combineRgb(255, 255, 255),
bgcolor: combineRgb(0, 0, 0), bgcolor: combineRgb(0, 0, 0),
}, },
steps: [{ steps: [
down: [{ {
down: [
{
actionId: 'startNewTimer', actionId: 'startNewTimer',
options: { options: {
description: '', description: '',
@@ -38,12 +40,12 @@ export function updatePresets() {
color: combineRgb(255, 255, 255), color: combineRgb(255, 255, 255),
bgcolor: combineRgb(0, 0, 0), bgcolor: combineRgb(0, 0, 0),
}, },
steps: [{ steps: [
{
down: [ down: [
{ {
actionId: 'stopCurrentTimer', actionId: 'stopCurrentTimer',
options: { options: {},
},
}, },
], ],
up: [], up: [],

View File

@@ -25,5 +25,4 @@ export function updateVariables() {
) )
this.setVariableDefinitions(variables) this.setVariableDefinitions(variables)
} }