Skip to content

Commit

Permalink
Add git addon as a core addon
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Nov 12, 2013
1 parent 2f957ee commit 374f0f5
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/git/addon-built.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions addons/git/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
define(["views/dialog"], function(GitDialog) {
var commands = codebox.require("core/commands");
var app = codebox.require("core/app");
var dialogs = codebox.require("utils/dialogs");

// Add opening command
commands.register("addons.git", {
title: "GIT",
icon: "code-fork"
}, function() {
dialogs.open(GitDialog);
});
});

16 changes: 16 additions & 0 deletions addons/git/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "git",
"version": "0.0.3",
"title": "GIT",
"description": "Integration of Git into your workspace.",
"homepage": "https://github.com/FriendCode/codebox-addon-git",
"license": "Apache",
"author": {
"name": "Samy Pessé",
"email": "[email protected]",
"url": "http://samypesse.fr"
},
"client": {
"main": "client"
}
}
40 changes: 40 additions & 0 deletions addons/git/stylesheets/git.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.addon-git-dialog {
.modal-body {
padding: 0px;
}
.modal-footer {
margin: 0px;
}

.navbar {
margin: 0px;
}

.git-commit {
padding: 10px;
background: #f8f8f8;
}

.git-changes {
list-style: none;
margin: 0px;
padding: 0px;

.file {
margin: 5px 3px;
background: #f5f5f5;
border-left: 5px solid transparent;
padding: 5px;

&.type-M {
border-left-color: #3498db;
}
&.type-A {
border-left-color: #2ecc71;
}
&.type-R {
border-left-color: #e74c3c;
}
}
}
}
46 changes: 46 additions & 0 deletions addons/git/templates/dialog.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-8">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Git</a>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-8">
<ul class="nav navbar-nav">
<li class="active"><a href="#git-tab-changes" tabindex="-1" data-toggle="tab">Changes</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>

<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane fade in active" id="git-tab-changes">
<form class="git-commit">
<div class="form-group">
<textarea class="form-control" rows="2" placeholder="Commit summary"></textarea>
</div>
<button type="submit" class="btn btn-default">Commit</button>
<button type="button" class="btn btn-git-sync btn-default" data-toggle="button"><i class="fa fa-refresh"></i></button>
</form>
<ul class="git-changes">
<% _.each(git.files || {}, function(file, path) { %>
<li class="file type-<%- file.type || 'A' %>"><%- path %></li>
<% }); %>
</ul>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-default action-close">Close</button>
</div>
</div>
</div>
70 changes: 70 additions & 0 deletions addons/git/views/dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
define([
"less!stylesheets/git.less"
], function() {
var DialogView = codebox.require("views/dialogs/base");
var box = codebox.require("core/box");

var GitDialog = DialogView.extend({
className: "addon-git-dialog modal fade",
templateLoader: "addon.git.templates",
template: "dialog.html",
events: _.extend({}, DialogView.prototype.events,{
"submit .git-commit": "submit"
}),

// Constructor
initialize: function(options) {
var that = this;
GitDialog.__super__.initialize.apply(this, arguments);

that.git = null;

box.gitStatus().then(function(status) {
that.git = status;
that.render();
});
return this;
},

// Template Context
templateContext: function() {
return {
git: this.git
};
},

// Render
render: function() {
if (!this.git) return this;
return GitDialog.__super__.render.apply(this, arguments);
},

// Finish rendering
finish: function() {
return GitDialog.__super__.finish.apply(this, arguments);
},

// Commit (and sync)
submit: function(e) {
if (e) e.preventDefault();

var that = this;
var sync = this.$(".git-commit .btn-git-sync").hasClass("active");
var message = this.$(".git-commit textarea").val();

if (message.length == 0) {
return;
}

box.commit({
'message': message
}).then(function() {
if (sync) return box.sync();
}).then(function() {
that.close();
})
}
});

return GitDialog;
});

0 comments on commit 374f0f5

Please sign in to comment.