-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.js
117 lines (100 loc) · 3.4 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require([
"Underscore",
"hr/hr",
"hr/args",
"vendors/base64",
"models/repo",
"models/message",
"utils/github",
"views/conversation",
"views/repoinfos",
"views/views",
"resources/resources"
], function(_, hr, args, Base64, Repo, Message, github, ConversationView, RepoInfosView) {
// Configure hr
hr.configure(args);
// Define base application
var Application = hr.Application.extend({
name: "Gitrap",
template: "main.html",
metas: {
"description": ""
},
links: {
"icon": hr.Urls.static("images/favicon.png")
},
routes: {
":owner/:name": "changeConversation"
},
events: {
"click .action-init-repo": "initRepo"
},
/* Constructor */
initialize: function() {
Application.__super__.initialize.apply(this, arguments);
github.on("logged", this.render, this);
this.repo = null;
this.conversationArgs = [];
return this;
},
/* Fnish rendering */
finish: function() {
if (_.size(this.conversationArgs) > 1) {
this.changeConversation.apply(this, this.conversationArgs);
}
return Application.__super__.finish.apply(this, arguments);
},
/* Context for template */
templateContext: function() {
return {
"logged": github.logged,
"user": github.user
}
},
/* (event) Change current conversation */
changeConversation: function(owner, name) {
var that, conv, i, curl, repoInfos;
that = this;
this.conversationArgs = _.values(arguments);
if (!github.logged) return this;
curl = owner+"/"+name;
this.repo = new github.Repo();
this.repo.load(owner, name).done(function() {
that.$("*[data-gitrap]").each(function() {
$(this).toggleClass("active", curl.indexOf($(this).data("gitrap")) === 0);
});
that.repo.checkBranch("gitrap").then(function() {
that.$el.removeClass("mode-init-repo");
that.$(".main-conversations").empty();
repoInfos = new RepoInfosView({
"repo": that.repo
});
repoInfos.render();
repoInfos.$el.appendTo(that.$(".main-repoinfos"));
conv = new ConversationView({
"repo": that.repo,
"path": null
});
conv.render();
conv.$el.appendTo(that.$(".main-conversations"));
}, function() {
that.$el.addClass("mode-init-repo");
});
});
return this;
},
/* Init repo */
initRepo: function(e) {
var that = this;
if (e != null) e.preventDefault();
hr.Cache.clear();
this.repo.checkBranch("gitrap", true, {
cache: false
}).done(function() {
that.changeConversation.apply(that, that.conversationArgs);
});
}
});
var app = new Application();
app.run();
});