mirror of
https://github.com/discourse/discourse.git
synced 2025-06-08 14:26:21 +08:00
Convert github commits widget to ember
This commit is contained in:
43
app/assets/javascripts/admin/models/github_commit.js
Normal file
43
app/assets/javascripts/admin/models/github_commit.js
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
A model for a git commit to the discourse repo, fetched from the github.com api.
|
||||
|
||||
@class GithubCommit
|
||||
@extends Discourse.Model
|
||||
@namespace Discourse
|
||||
@module Discourse
|
||||
**/
|
||||
Discourse.GithubCommit = Discourse.Model.extend({
|
||||
gravatarUrl: function(){
|
||||
if( this.get('author') && this.get('author.gravatar_id') ){
|
||||
return("https://www.gravatar.com/avatar/" + this.get('author.gravatar_id') + ".png?s=38&r=pg&d=identicon");
|
||||
} else {
|
||||
return "https://www.gravatar.com/avatar/b30fff48d257cdd17c4437afac19fd30.png?s=38&r=pg&d=identicon";
|
||||
}
|
||||
}.property("commit"),
|
||||
|
||||
commitUrl: function(){
|
||||
return("https://github.com/discourse/discourse/commit/" + this.get('sha'));
|
||||
}.property("sha"),
|
||||
|
||||
timeAgo: function() {
|
||||
return Date.create(this.get('commit.committer.date')).relative();
|
||||
}.property("commit.committer.date")
|
||||
});
|
||||
|
||||
Discourse.GithubCommit.reopenClass({
|
||||
findAll: function() {
|
||||
var result;
|
||||
result = Em.A();
|
||||
$.ajax( "https://api.github.com/repos/discourse/discourse/commits?callback=callback", {
|
||||
dataType: 'jsonp',
|
||||
type: 'get',
|
||||
data: { per_page: 10 },
|
||||
success: function(response, textStatus, jqXHR) {
|
||||
response.data.each(function(commit) {
|
||||
result.pushObject( Discourse.GithubCommit.create(commit) );
|
||||
});
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user