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

add support for web-ide and global ranking #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions assets/js/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ var NavBar = reactCreateClass({
}
};

var project_name = function () {

if(that.props.show_project_editor === false ){
return (
<p className="navbar-text" onClick={that.props.toggleEditor}> Project: <b>{that.props.projectName}</b></p>
);
}else{
return (
<p className="navbar-text" > Project: <input type = "text" defaultValue = {that.props.projectName} onBlur={that.props.toggleEditor} onChange={that.props.updateEditor} onKeyPress={that.props.handleKeyPress} ></input></p>
);
}
};

var ranking = function () {

if (config.rankingDisplayType == 'global' && that.props.global_rank) {
return ( <p className="navbar-text"> Global Ranking: <b>{that.props.global_rank} / 5000 </b></p> );
}

};

return (
<nav className="navbar navbar-default" role="navigation">
<div className="container-fluid">
Expand All @@ -61,6 +82,8 @@ var NavBar = reactCreateClass({
</div>
<div className="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
{signedInAs()}
{project_name()}
{ranking()}
<ul className="nav navbar-nav">
{customRules()}
{dashboard()}
Expand Down
82 changes: 81 additions & 1 deletion assets/js/components/Options.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ var Options = reactCreateClass({
theme: config.theme,
blacklist: '',
whitelist: '',
idelist: '',
projectType: 'last',
loggingType: config.loggingType,
loggingStyle: config.loggingStyle,
displayAlert: false,
defaultProjectName: config.defaultProjectName,
alertType: config.alert.success.type,
alertText: config.alert.success.text,
};
Expand All @@ -42,16 +45,22 @@ var Options = reactCreateClass({
theme: config.theme,
blacklist: '',
whitelist: '',
idelist: '',
projectType: 'last',
loggingType: config.loggingType,
loggingStyle: config.loggingStyle,
defaultProjectName: config.defaultProjectName,
})
.then(function (items) {
that.setState({
theme: items.theme,
blacklist: items.blacklist,
whitelist: items.whitelist,
idelist: items.idelist,
projectType: items.projectType,
loggingType: items.loggingType,
loggingStyle: items.loggingStyle,
defaultProjectName: items.defaultProjectName,
});

that.refs.theme.value = items.theme;
Expand Down Expand Up @@ -82,18 +91,24 @@ var Options = reactCreateClass({
theme: theme,
blacklist: blacklist,
whitelist: whitelist,
idelist: items.idelist,
projectType: items.projectType,
loggingType: loggingType,
loggingStyle: loggingStyle,
defaultProjectName: items.defaultProjectName,
})
.then(function () {
// Set state to be newly entered values.
that.setState({
theme: theme,
blacklist: blacklist,
whitelist: whitelist,
idelist: items.idelist,
projectType: items.projectType,
loggingType: loggingType,
loggingStyle: loggingStyle,
displayAlert: true,
defaultProjectName: items.defaultProjectName,
});
});
},
Expand All @@ -116,6 +131,24 @@ var Options = reactCreateClass({
});
},

_updateDefaultProjectState: function(event){
this.setState({
defaultProjectName: event.target.value
});
},

_updateIdelistState: function(sites){
this.setState({
idelist: sites
});
},

_updateTypeState: function(type){
this.setState({
projectType: type
});
},

render: function () {
var that = this;

Expand Down Expand Up @@ -158,6 +191,47 @@ var Options = reactCreateClass({
);
};

var ideList = function () {

return (
<SitesList
handleChange={that._updateIdelistState}
label="Idelist"
sites={that.state.idelist}
helpText="Sites that you want to show in your reports as codeing." />
);
};

var projectType = function () {

return (
<div className="form-group">
<label className="col-lg-2 control-label">Project Selection</label>

<div className="col-lg-10">
<select className="form-control" ref="projectType" defaultValue="last" onChange={that._updateTypeState}>
<option value="last">The last project reported to Wakatime</option>
<option value="unknown">Unknown/New project</option>
</select>
</div>
</div>
);
};

var defaultProjectName = function () {

return (
<div className="form-group">
<label className="col-lg-2 control-label">Default Project Name</label>

<div className="col-lg-10">
<input className="form-control" ref="defaultProjectName" defaultValue="Unknown Project" onChange={that._updateDefaultProjectState} />
</div>
</div>
);
};


return (
<div className="container">
<div className="row">
Expand Down Expand Up @@ -187,7 +261,13 @@ var Options = reactCreateClass({
</div>
</div>

{loggingStyle()}
{(defaultProjectName())}

{projectType()}

{loggingStyle()}

{ideList()}

<div className="form-group">
<label className="col-lg-2 control-label">Logging type</label>
Expand Down
118 changes: 109 additions & 9 deletions assets/js/components/WakaTime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@ var Wakatime = reactCreateClass({
full_name: null,
email: null,
photo: null,
display_name: null,
last_project: null,
username: null
},
loggedIn: false,
loggingEnabled: config.loggingEnabled,
totalTimeLoggedToday: '0 minutes',
projectType: config.projectType,
globalRank: null,
defaultProjectName: config.defaultProjectName,
projectName: config.projectName,
show_project_editor: false
};
},

Expand All @@ -40,9 +48,25 @@ var Wakatime = reactCreateClass({
browser.storage.sync
.get({
loggingEnabled: config.loggingEnabled,
projectType: config.projectType,
projectName: config.projectName,
defaultProjectName: config.defaultProjectName
})
.then(function (items) {
that.setState({ loggingEnabled: items.loggingEnabled });
var projectName = items.projectName;

if (items.projectName === null) {
if(items.projectType == 'last')
{
projectName = data.last_project;
}else{
projectName = items.defaultProjectName;
}

}

that.setState({ loggingEnabled: items.loggingEnabled, projectName: projectName});


if (items.loggingEnabled === true) {
changeExtensionState('allGood');
Expand All @@ -56,8 +80,12 @@ var Wakatime = reactCreateClass({
full_name: data.full_name,
email: data.email,
photo: data.photo,
display_name: data.display_name,
last_project: data.last_project,
username: data.username
},
loggedIn: true,
globalRank: null
});

wakatime.getTotalTimeLoggedToday().done(function (grand_total) {
Expand All @@ -66,6 +94,12 @@ var Wakatime = reactCreateClass({
});
});

wakatime.getRanking().done(function (rank) {
that.setState({
globalRank: rank.text
});
});

wakatime.recordHeartbeat();
} else {
changeExtensionState('notSignedIn');
Expand Down Expand Up @@ -136,6 +170,72 @@ var Wakatime = reactCreateClass({
});
},

_updateLastProjectState: function (last_project) {
this.setState({
user: {
full_name: this.full_name,
email: this.email,
photo: this.photo,
display_name: this.display_name,
last_project: last_project,
username: this.username
},
});

changeExtensionState('allGood');

chrome.storage.sync.set({
loggingEnabled: true
});
},

updateEditor: function (event) {
var projectName = event.target.value;

this.setState({
projectName: projectName,
});

if(projectName == null || projectName == this.defaultProjectName || projectName == this.state.user.last_project){
changeExtensionState('allGood');
}else{
changeExtensionState('allGoodOverride');
}

},

handleKeyPress: function(event) {
if(event.charCode==13){
var projectName = event.target.value;

this.setState({
projectName: projectName,
});

if(projectName == null || projectName == this.defaultProjectName || projectName == this.state.user.last_project){
changeExtensionState('allGood');
}else{
changeExtensionState('allGoodOverride');
}
this.toggleEditor;
}
},


toggleEditor: function () {
var value = false;

if (this.state.show_project_editor === false) {
value = true;

}

this.setState({
show_project_editor: value
});

},

render: function () {
return (
<div>
Expand All @@ -144,14 +244,14 @@ var Wakatime = reactCreateClass({
<div className="row">
<div className="col-md-12">
<MainList
disableLogging={this._disableLogging}
enableLogging={this._enableLogging}
loggingEnabled={this.state.loggingEnabled}
user={this.state.user}
totalTimeLoggedToday={this.state.totalTimeLoggedToday}
logoutUser={this._logoutUser}
loggedIn={this.state.loggedIn}
/>
disableLogging={this._disableLogging}
enableLogging={this._enableLogging}
loggingEnabled={this.state.loggingEnabled}
handleKeyPress={this.handleKeyPress}
user={this.state.user}
totalTimeLoggedToday={this.state.totalTimeLoggedToday}
logoutUser={this._logoutUser}
loggedIn={this.state.loggedIn} />
</div>
</div>
</div>
Expand Down
14 changes: 13 additions & 1 deletion assets/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,28 @@ var config = {
logoutUserUrl: 'https://wakatime.com/logout',
// Gets stats from the WakaTime API
summariesApiUrl: 'https://wakatime.com/api/v1/users/current/summaries',
// Default Project Type
projectType: 'last',
// Default Project Name if projectname == null
defaultProjectName: 'Unknown Project',
// Default ranking display type
rankingDisplayType: 'global',
// Projectname reported to wakatime
projectName: null,
// The url to rank the user from wakatime
rankingUrl: 'https://wakatime.com/api/v1/leaders',
// Different colors for different states of the extension
colors: {
allGood: '',
allGoodOverride: 'override',
notLogging: 'gray',
notSignedIn: 'red',
lightTheme: 'white',
},
// Tooltips for each of the extension states
tooltips: {
allGood: '',
allGoodOverride: 'Project name has been overridden',
notLogging: 'Not logging',
notSignedIn: 'Not signed In',
blacklisted: 'This URL is blacklisted',
Expand All @@ -43,7 +55,7 @@ var config = {
// Default theme
theme: 'light',
// Valid extension states
states: ['allGood', 'notLogging', 'notSignedIn', 'blacklisted', 'whitelisted'],
states: ['allGood', 'allGoodOverride','notLogging', 'notSignedIn', 'blacklisted', 'whitelisted'],
// Predefined alert type and text for success and failure.
alert: {
success: {
Expand Down
Loading