-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.js
88 lines (86 loc) · 2.48 KB
/
app.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
marked.setOptions({
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
});
angular.module('app', [
'ui.router'
]).config(function ($stateProvider) {
$stateProvider
.state('home', {
url: '',
controller: 'HomeCtrl',
templateUrl: 'templates/home.html'
})
.state('project', {
url: '/:projectId',
controller: 'ProjectCtrl',
templateUrl: 'templates/project.html',
resolve: {
dockerfile: function ($http, $state, $stateParams) {
return $http({
method: 'GET',
url: 'https://api.github.com/repos/dockerfile/' + $stateParams.projectId + '/contents/Dockerfile',
headers: {
Accept: 'application/vnd.github.VERSION.raw'
}
}).then(
function (res) {
return res.data;
},
function (res) {
alert(res.data.message);
console.error(res);
$state.go('home');
}
);
},
readme: function ($http, $state, $stateParams) {
return $http({
method: 'GET',
url: 'https://api.github.com/repos/dockerfile/' + $stateParams.projectId + '/readme',
headers: {
Accept: 'application/vnd.github.VERSION.raw'
}
}).then(
function (res) {
return res.data;
},
function (res) {
alert(res.data.message);
console.error(res);
$state.go('home');
}
);
}
}
});
}).run(function ($http, $rootScope, $state) {
$rootScope._ = _;
$rootScope.projects = [];
$http.get('https://api.github.com/users/dockerfile/repos?per_page=100')
.success(function (projects) {
_.sortBy(projects, 'name').forEach(function (project) {
if (!_.contains(['dockerfile.github.io'], project.name)) {
$rootScope.projects.push({
id: project.name,
description: project.description
});
}
});
})
.error(function (err) {
alert(err.message);
$state.go('home');
});
}).controller('HomeCtrl', function ($scope) {
// ...
}).controller('ProjectCtrl', function ($sce, $scope, $stateParams, dockerfile, readme) {
$scope.projectId = $stateParams.projectId;
$scope.dockerfile = $sce.trustAsHtml(dockerfile);
$scope.readme = $sce.trustAsHtml(marked(readme));
});