mirror of
https://gitlab.com/aviortheking/code-stats-vscode.git
synced 2025-08-03 23:31:59 +00:00
Done
This commit is contained in:
committed by
Juha Ristolainen
parent
2343164b29
commit
e8421926dc
@@ -10,6 +10,11 @@ export class CodeStatsAPI {
|
||||
private axios = null;
|
||||
|
||||
constructor(apiKey: string, apiURL: string, userName: string) {
|
||||
this.updateSettings(apiKey, apiURL, userName);
|
||||
}
|
||||
|
||||
public updateSettings( apiKey: string, apiURL: string, userName: string) {
|
||||
|
||||
this.API_KEY = apiKey;
|
||||
this.UPDATE_URL = apiURL;
|
||||
this.USER_NAME = userName;
|
||||
@@ -71,6 +76,7 @@ export class CodeStatsAPI {
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -18,6 +18,9 @@ export class ProfileProvider implements TextDocumentContentProvider {
|
||||
|
||||
provideTextDocumentContent(uri: Uri, token: CancellationToken): string | Thenable<string> {
|
||||
|
||||
if( token.isCancellationRequested )
|
||||
return;
|
||||
|
||||
const LEVEL_FACTOR = 0.025;
|
||||
|
||||
function getLevel(xp: number): number {
|
||||
@@ -66,6 +69,11 @@ export class ProfileProvider implements TextDocumentContentProvider {
|
||||
|
||||
return this.api.getProfile().then(profile => {
|
||||
|
||||
if( profile === null )
|
||||
{
|
||||
return `<h1>Can't fetch profile. Please try again later</h1> Make sure <strong>codestats.username</strong> setting is set to correct user name.`;
|
||||
}
|
||||
|
||||
let htmlTemplate = fs.readFileSync(this.context.asAbsolutePath("assets/profile.html.eex"));
|
||||
|
||||
profile["level"] = getLevel(profile["total_xp"]);
|
||||
|
@@ -51,17 +51,26 @@ export class XpCounter {
|
||||
this.statusBarItem.command = "code-stats.profile";
|
||||
}
|
||||
|
||||
let provider = new ProfileProvider(context, this.api);
|
||||
|
||||
let registration = workspace.registerTextDocumentContentProvider('code-stats', provider);
|
||||
|
||||
subscriptions.push(registration);
|
||||
|
||||
let previewUri = Uri.parse('code-stats://profile')
|
||||
|
||||
subscriptions.push(workspace.registerTextDocumentContentProvider('code-stats', new ProfileProvider(context, this.api)));
|
||||
|
||||
subscriptions.push(commands.registerCommand("code-stats.profile", () => {
|
||||
commands.executeCommand('vscode.previewHtml', previewUri, ViewColumn.Two, 'Code::Stats Profile');
|
||||
} ) );
|
||||
|
||||
let config: WorkspaceConfiguration = workspace.getConfiguration(
|
||||
"codestats"
|
||||
);
|
||||
|
||||
if (!config) {
|
||||
window.showErrorMessage('codestats.username configuration setting is missing');
|
||||
return;
|
||||
}
|
||||
|
||||
if( config.get("username") === '' ){
|
||||
window.showErrorMessage('codestats.username configuration setting is missing');
|
||||
return;
|
||||
}
|
||||
|
||||
commands.executeCommand('vscode.previewHtml', Uri.parse('code-stats://profile'), ViewColumn.Two, 'Code::Stats Profile');
|
||||
}));
|
||||
|
||||
workspace.onDidChangeTextDocument(
|
||||
this.onTextDocumentChanged,
|
||||
@@ -145,6 +154,9 @@ export class XpCounter {
|
||||
`
|
||||
);
|
||||
|
||||
this.api = new CodeStatsAPI(apiKey, apiURL, userName);
|
||||
if( this.api != null )
|
||||
this.api.updateSettings(apiKey, apiURL, userName);
|
||||
else
|
||||
this.api = new CodeStatsAPI(apiKey,apiURL,userName);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user