Skip to content

Commit 374f0f5

Browse files
committed
Add git addon as a core addon
1 parent 2f957ee commit 374f0f5

File tree

6 files changed

+187
-0
lines changed

6 files changed

+187
-0
lines changed

addons/git/addon-built.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

addons/git/client.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
define(["views/dialog"], function(GitDialog) {
2+
var commands = codebox.require("core/commands");
3+
var app = codebox.require("core/app");
4+
var dialogs = codebox.require("utils/dialogs");
5+
6+
// Add opening command
7+
commands.register("addons.git", {
8+
title: "GIT",
9+
icon: "code-fork"
10+
}, function() {
11+
dialogs.open(GitDialog);
12+
});
13+
});
14+

addons/git/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "git",
3+
"version": "0.0.3",
4+
"title": "GIT",
5+
"description": "Integration of Git into your workspace.",
6+
"homepage": "https://github.com/FriendCode/codebox-addon-git",
7+
"license": "Apache",
8+
"author": {
9+
"name": "Samy Pessé",
10+
"email": "samypesse@gmail.com",
11+
"url": "http://samypesse.fr"
12+
},
13+
"client": {
14+
"main": "client"
15+
}
16+
}

addons/git/stylesheets/git.less

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.addon-git-dialog {
2+
.modal-body {
3+
padding: 0px;
4+
}
5+
.modal-footer {
6+
margin: 0px;
7+
}
8+
9+
.navbar {
10+
margin: 0px;
11+
}
12+
13+
.git-commit {
14+
padding: 10px;
15+
background: #f8f8f8;
16+
}
17+
18+
.git-changes {
19+
list-style: none;
20+
margin: 0px;
21+
padding: 0px;
22+
23+
.file {
24+
margin: 5px 3px;
25+
background: #f5f5f5;
26+
border-left: 5px solid transparent;
27+
padding: 5px;
28+
29+
&.type-M {
30+
border-left-color: #3498db;
31+
}
32+
&.type-A {
33+
border-left-color: #2ecc71;
34+
}
35+
&.type-R {
36+
border-left-color: #e74c3c;
37+
}
38+
}
39+
}
40+
}

addons/git/templates/dialog.html

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<div class="modal-dialog">
2+
<div class="modal-content">
3+
<div class="modal-body">
4+
<nav class="navbar navbar-default navbar-static-top" role="navigation">
5+
<!-- Brand and toggle get grouped for better mobile display -->
6+
<div class="navbar-header">
7+
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-8">
8+
<span class="sr-only">Toggle navigation</span>
9+
<span class="icon-bar"></span>
10+
<span class="icon-bar"></span>
11+
<span class="icon-bar"></span>
12+
</button>
13+
<a class="navbar-brand" href="#">Git</a>
14+
</div>
15+
16+
<!-- Collect the nav links, forms, and other content for toggling -->
17+
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-8">
18+
<ul class="nav navbar-nav">
19+
<li class="active"><a href="#git-tab-changes" tabindex="-1" data-toggle="tab">Changes</a></li>
20+
</ul>
21+
</div><!-- /.navbar-collapse -->
22+
</nav>
23+
24+
<!-- Tab panes -->
25+
<div class="tab-content">
26+
<div class="tab-pane fade in active" id="git-tab-changes">
27+
<form class="git-commit">
28+
<div class="form-group">
29+
<textarea class="form-control" rows="2" placeholder="Commit summary"></textarea>
30+
</div>
31+
<button type="submit" class="btn btn-default">Commit</button>
32+
<button type="button" class="btn btn-git-sync btn-default" data-toggle="button"><i class="fa fa-refresh"></i></button>
33+
</form>
34+
<ul class="git-changes">
35+
<% _.each(git.files || {}, function(file, path) { %>
36+
<li class="file type-<%- file.type || 'A' %>"><%- path %></li>
37+
<% }); %>
38+
</ul>
39+
</div>
40+
</div>
41+
</div>
42+
<div class="modal-footer">
43+
<button class="btn btn-default action-close">Close</button>
44+
</div>
45+
</div>
46+
</div>

addons/git/views/dialog.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
define([
2+
"less!stylesheets/git.less"
3+
], function() {
4+
var DialogView = codebox.require("views/dialogs/base");
5+
var box = codebox.require("core/box");
6+
7+
var GitDialog = DialogView.extend({
8+
className: "addon-git-dialog modal fade",
9+
templateLoader: "addon.git.templates",
10+
template: "dialog.html",
11+
events: _.extend({}, DialogView.prototype.events,{
12+
"submit .git-commit": "submit"
13+
}),
14+
15+
// Constructor
16+
initialize: function(options) {
17+
var that = this;
18+
GitDialog.__super__.initialize.apply(this, arguments);
19+
20+
that.git = null;
21+
22+
box.gitStatus().then(function(status) {
23+
that.git = status;
24+
that.render();
25+
});
26+
return this;
27+
},
28+
29+
// Template Context
30+
templateContext: function() {
31+
return {
32+
git: this.git
33+
};
34+
},
35+
36+
// Render
37+
render: function() {
38+
if (!this.git) return this;
39+
return GitDialog.__super__.render.apply(this, arguments);
40+
},
41+
42+
// Finish rendering
43+
finish: function() {
44+
return GitDialog.__super__.finish.apply(this, arguments);
45+
},
46+
47+
// Commit (and sync)
48+
submit: function(e) {
49+
if (e) e.preventDefault();
50+
51+
var that = this;
52+
var sync = this.$(".git-commit .btn-git-sync").hasClass("active");
53+
var message = this.$(".git-commit textarea").val();
54+
55+
if (message.length == 0) {
56+
return;
57+
}
58+
59+
box.commit({
60+
'message': message
61+
}).then(function() {
62+
if (sync) return box.sync();
63+
}).then(function() {
64+
that.close();
65+
})
66+
}
67+
});
68+
69+
return GitDialog;
70+
});

0 commit comments

Comments
 (0)