Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update URL's to use software-app #55

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
"command": "edit_preferences",
"caption": "Code Time: Settings"
},
{
"command": "go_to_software",
"caption": "Code Time: More data at Software.com"
},
{
"command": "show_tree_view",
"caption": "Code Time: Menu"
Expand All @@ -35,4 +31,4 @@
"command": "toggle_status_bar_metrics",
"caption": "Code Time: Toggle Status Bar Metrics"
}
]
]
4 changes: 2 additions & 2 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[
{ "keys": ["ctrl+alt+o"], "command": "go_to_software" }
]
{ "keys": ["ctrl+alt+o"], "command": "view_dashboard" }
]
6 changes: 1 addition & 5 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
"command": "edit_preferences",
"caption": "Settings"
},
{
"command": "go_to_software",
"caption": "More data at Software.com"
},
{
"command": "show_tree_view",
"caption": "Menu"
Expand All @@ -41,4 +37,4 @@
}
]
}
]
]
7 changes: 0 additions & 7 deletions Software.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ def run(self, edit):
def is_enabled(self):
return True

class GoToSoftware(sublime_plugin.TextCommand):
def run(self, edit):
launchWebDashboardUrl()

def is_enabled(self):
return True

class SwitchAccount(sublime_plugin.TextCommand):
def run(self, edit):
switchAccount()
Expand Down
7 changes: 1 addition & 6 deletions lib/SlackManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ def connectSlackWorkspace():
t.start()

def launchSlackSettings():
scheme = "https"
if('localhost' in getApiEndpoint()):
scheme = "http"
url = scheme + "://" + getWebUrl() + "data_sources/integration_types/slack"
url = getWebUrl() + "/data_sources/integration_types/slack"
webbrowser.open(url)

#######################################################################################
Expand All @@ -69,5 +66,3 @@ def getSlackAuth():
curentUser = getUser(True)

return hasSlackWorkspaces()


13 changes: 6 additions & 7 deletions lib/SoftwareHttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def isUnauthenticated(response):
def requestIt(method, api, payload, token=None):
return apiRequest(method, api, payload, getApiEndpoint(), token)

def appRequestIt(method, api, payload):
return apiRequest(method, api, payload, getAppEndpoint())
def appRequestIt(method, api, payload, token=None):
return apiRequest(method, api, payload, getAppEndpoint(), token)

def apiRequest(method, api, payload, api_endpoint, token=None):

Expand All @@ -73,7 +73,7 @@ def apiRequest(method, api, payload, api_endpoint, token=None):
# try to update kpm data.
try:
if jwt is None:
jwt = getItem('jwt')
jwt = getJwt()

headers = {'Content-Type': 'application/json', 'User-Agent': USER_AGENT}
connection = None
Expand Down Expand Up @@ -188,12 +188,11 @@ def getUser(refreshUser=True):

jwt = getItem("jwt")
if (jwt):
api = "/users/me"
response = requestIt("GET", api, None)
api = "/api/v1/user"
response = appRequestIt("GET", api, None)
if (isResponseOk(response)):
try:
responseObj = json.loads(response.read().decode('utf-8'))
currentUser = responseObj.get("data", None)
currentUser = json.loads(response.read().decode('utf-8'))
return currentUser
except Exception as ex:
logIt("Code Time: Unable to retrieve user: %s" % ex)
Expand Down
4 changes: 2 additions & 2 deletions lib/SoftwareUserStatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ def launchWebDashboardUrl():
webbrowser.open(getWebUrl())

def launchCodeTimeDashboard():
webbrowser.open(getWebUrl() + "/dashboard/code_time?view=summary")
webbrowser.open(getWebUrl() + "/dashboard/code_time")

def launchUpdatePreferences():
webbrowser.open(getWebUrl() + "/preferences")
webbrowser.open(getWebUrl() + "/dashboard/code_time/settings")

def switchAccount():
keys = ['Google', 'GitHub', 'Email']
Expand Down
2 changes: 1 addition & 1 deletion lib/SoftwareUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def initializeUserPreferences():

user = getUser()
if(user):
session_threshold_in_sec = user.get("preferences", {}).get("sessionThresholdInSec", getSessionThresholdSeconds())
session_threshold_in_sec = user.get("preferences_parsed", {}).get("sessionThresholdInSec", getSessionThresholdSeconds())

# update values config
setItem("sessionThresholdInSec", session_threshold_in_sec)
Expand Down
52 changes: 26 additions & 26 deletions lib/TrackerManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def swdc_tracker(event_json, context):
global cached_tracker

if cached_tracker is None:
response = requestIt('GET', '/plugins/config', None, None)
response = appRequestIt('GET', '/api/v1/plugins/config', None)
if response is not None and isResponseOk(response):
config = json.loads(response.read().decode('utf-8'))
e = Emitter(config['tracker_api'])
Expand Down Expand Up @@ -79,18 +79,18 @@ def codetime_payload(**kwargs):
'iglu:com.software/codetime/jsonschema/1-0-2',
{
'keystrokes': kwargs['keystrokes'],
'lines_added': kwargs['lines_added'],
'lines_deleted': kwargs['lines_deleted'],
'characters_added': kwargs['characters_added'],
'characters_deleted': kwargs['characters_deleted'],
'single_deletes': kwargs['single_deletes'],
'multi_deletes': kwargs['multi_deletes'],
'single_adds': kwargs['single_adds'],
'multi_adds': kwargs['multi_adds'],
'auto_indents': kwargs['auto_indents'],
'replacements': kwargs['replacements'],
'is_net_change': kwargs['is_net_change'],
'start_time': datetime.utcfromtimestamp(int(kwargs['start_time'])).isoformat(),
'lines_added': kwargs['lines_added'],
'lines_deleted': kwargs['lines_deleted'],
'characters_added': kwargs['characters_added'],
'characters_deleted': kwargs['characters_deleted'],
'single_deletes': kwargs['single_deletes'],
'multi_deletes': kwargs['multi_deletes'],
'single_adds': kwargs['single_adds'],
'multi_adds': kwargs['multi_adds'],
'auto_indents': kwargs['auto_indents'],
'replacements': kwargs['replacements'],
'is_net_change': kwargs['is_net_change'],
'start_time': datetime.utcfromtimestamp(int(kwargs['start_time'])).isoformat(),
'end_time': datetime.utcfromtimestamp(int(kwargs['end_time'])).isoformat()
}
)
Expand All @@ -117,23 +117,23 @@ def auth_payload(**kwargs):
'iglu:com.software/auth/jsonschema/1-0-0',
{
'jwt': kwargs['jwt']
}
)
}
)

def file_payload(**kwargs):
hashed_name = hash_value(kwargs['file_name'].replace("\\", "/"), 'file_name', kwargs['jwt'])
hashed_path = hash_value(kwargs['file_path'], 'file_path', kwargs['jwt'])

return SelfDescribingJson(
'iglu:com.software/file/jsonschema/1-0-1',
{
'iglu:com.software/file/jsonschema/1-0-1',
{
'file_name': hashed_name,
'file_path': hashed_path,
'syntax': kwargs['syntax'],
'line_count': kwargs['line_count'],
'character_count': kwargs['character_count']
}
)
}
)

def plugin_payload(**kwargs):
plugin_id = kwargs["plugin_id"] or getPluginId()
Expand Down Expand Up @@ -176,8 +176,8 @@ def repo_payload(**kwargs):
'owner_id': hashed_owner_id,
'git_branch': hashed_git_branch,
'git_tag': hashed_git_tag
}
)
}
)

def ui_element_payload(**kwargs):
return SelfDescribingJson(
Expand Down Expand Up @@ -216,15 +216,15 @@ def hash_value(value, data_type, jwt):

def fetch_user_hashed_values():
try:
response = requestIt('GET', '/hashed_values', None, getJwt())
response = appRequestIt('GET', '/api/v1/user/hashed_values', None)
user_hashed_values = json.loads(response.read().decode('utf-8'))

global cached_hashed_values
cached_hashed_values = user_hashed_values
storeHashedValues(user_hashed_values)
except Exception as ex:
print("ERROR FETCHING HASHED VALUES")
print(ex)
logIt("ERROR FETCHING HASHED VALUES")
logIt(ex)

def encrypt_and_save(value, hashed_value, data_type, jwt):
params = {
Expand All @@ -233,9 +233,9 @@ def encrypt_and_save(value, hashed_value, data_type, jwt):
'data_type': data_type
}

response = requestIt('POST', '/user_encrypted_data', json.dumps(params), jwt)
response = appRequestIt('POST', '/api/v1/user/encrypted_data', json.dumps(params))
if response and isResponseOk(response):
return True
else:
print("error POSTing to /user_encrypted_data for value: " + hashed_value)
logIt("error POSTing to /api/v1/user/encrypted_data for value: " + hashed_value)
return False
18 changes: 7 additions & 11 deletions lib/TreePanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
UPDATE_PREFERENCES_LABEL = 'Settings'
LEARN_MORE_LABEL = 'Learn more'
VIEW_DASHBOARD_LABEL = 'View dashboard'
SEE_ADVANCED_METRICS = 'More data at Software.com'
TODAY_VS_AVG_LABEL = 'Today vs.'
SLACK_WORKSPACES_LABEL = 'Slack workspaces'
ADD_SLACK_WORKSPACE_LABEL = 'Add workspace'
Expand Down Expand Up @@ -71,13 +70,12 @@ def create_tree(self):

self.keys.append('%s%s' % (firstChildDepth, UPDATE_PREFERENCES_LABEL))
self.keys.append('%s%s' % (firstChildDepth, VIEW_DASHBOARD_LABEL))
self.keys.append('%s%s' % (firstChildDepth, SEE_ADVANCED_METRICS))

data = getSessionSummaryData()

# active code time
activeCodeTimeStr = humanizeMinutes(data["currentDayMinutes"]).strip()
activeCodeTimeAvg = data["averageDailyMinutes"]
activeCodeTimeStr = humanizeMinutes(data.get("currentDayMinutes", 0)).strip()
activeCodeTimeAvg = data.get("averageDailyMinutes", 0)
activeCodeTimeAvgStr = humanizeMinutes(activeCodeTimeAvg).strip()
self.keys.append('%s%s' % (firstChildDepth, "Active code time: " + activeCodeTimeStr))

Expand All @@ -103,15 +101,15 @@ def create_tree(self):
if (len(workspaces) > 0):
for i in range(len(workspaces)):
workspace = workspaces[i]
team_info = json.loads(workspace['meta']).get('team', { 'name': 'slack workspace' })
team_info = workspace['meta'].get('team', { 'name': 'slack workspace' })
self.keys.append('%s%s' % (secondChildDepth, team_info.get('name')))
else:
self.keys.append('%s%s' % (secondChildDepth, '<No workspaces found>'))

self.keys.append('%s%s' % (secondChildDepth, ADD_SLACK_WORKSPACE_LABEL))

def buildTopFilesNode(self, fileChangeInfoMap):

filesChanged = len(fileChangeInfoMap.keys()) if fileChangeInfoMap else 0

if filesChanged > 0:
Expand All @@ -121,7 +119,7 @@ def buildTopFilesNode(self, fileChangeInfoMap):

def topFilesMetricsNode(self, fileChangeInfos, sortBy, id):
if not fileChangeInfos or len(fileChangeInfos) == 0:
return None
return None

sortedArr = []
if sortBy == 'duration_seconds' or sortBy == 'kpm' or sortBy == 'keystrokes':
Expand All @@ -146,8 +144,8 @@ def topFilesMetricsNode(self, fileChangeInfos, sortBy, id):
label = '{} | {}'.format(fileName, val)

childrenNodes.append(label)
return childrenNodes

return childrenNodes

def itemSelectionHandler(self, idx):
if (idx is not None and idx >= 0):
Expand All @@ -165,8 +163,6 @@ def itemSelectionHandler(self, idx):
launchCodeTimeDashboard()
elif (key == UPDATE_PREFERENCES_LABEL):
launchUpdatePreferences()
elif (key == SEE_ADVANCED_METRICS):
launchWebDashboardUrl()
elif (key == ENABLE_FLOW_MODE):
enableFlowMode()
elif (key == EXIT_FLOW_MODE):
Expand Down