Skip to content

Commit 51013d9

Browse files
authored
Merge pull request #4 from msuewer/master
Adding Widget for all activities of SCM repositories
2 parents 6ea6d4e + 189c227 commit 51013d9

File tree

8 files changed

+121
-24
lines changed

8 files changed

+121
-24
lines changed

gulpfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var pkg = require('./package.json');
3636
// proxy stuff for scm-manager
3737
var url = require('url');
3838
var proxy = require('proxy-middleware');
39-
var scmUrl = 'http://localhost:8080/scm/api/rest'
39+
var scmUrl = 'http://localhost:8080/scm/api/rest';
4040
var scmCredentials = {
4141
user: 'scmadmin',
4242
password: 'scmadmin'

sample/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<script type="text/javascript">
5252
angular
5353
.module('adfWidgetSample', ['adf', 'adf.widget.scm', 'LocalStorageModule'])
54-
.constant('scmEndpoint', '/api/scm/')
54+
.constant('scmEndpoint', '/api/scm/')
5555
.config(function(dashboardProvider, localStorageServiceProvider){
5656
localStorageServiceProvider.setPrefix('adf.scm');
5757
dashboardProvider.structure('1', {

src/activities/activities.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2016, Sebastian Sdorra
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
'use strict';
26+
27+
angular.module('adf.widget.scm')
28+
.controller('ActivitiesController', function ($sce, activities, SCM) {
29+
var vm = this;
30+
vm.status = activities.status;
31+
32+
// allow html descriptions
33+
angular.forEach(activities.activities, function (activity) {
34+
activity.changeset.description = $sce.trustAsHtml(activity.changeset.description);
35+
activity.repoName = activity["repository-name"];
36+
});
37+
38+
// handling and displaying only 15 activities
39+
if (activities.activities) {
40+
vm.activities = activities.activities.slice(0, 15);
41+
}
42+
43+
vm.gravatarHash = function (activity) {
44+
return SCM.getGravatarHash(activity.changeset.properties);
45+
};
46+
});

src/activities/activityView.html

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div>
2+
<div ng-if="!vm.activities" class="alert alert-info">
3+
There are no activities for your available repositories.
4+
</div>
5+
<div ng-if="vm.status == 404 || vm.status == 500" class="alert alert-danger">
6+
<b>Error {{vm.status}}:</b> The endpoint could not be reached, this could mean that the activity plugin is not installed.
7+
</div>
8+
<div ng-if="vm.activities">
9+
<ul class="media-list">
10+
<li class="media" ng-repeat="activity in vm.activities">
11+
<div ng-if="vm.gravatarHash(activity)" class="media-left">
12+
<img class="media-object img-thumbnail" ng-src="http://www.gravatar.com/avatar/{{vm.gravatarHash(activity)}}?s=64&d=identicon" alt="">
13+
</div>
14+
<div class="media-body">
15+
<!--h4 class="media-heading">Media heading</h4-->
16+
<b>{{activity.repoName}}</b>
17+
<p ng-bind-html="activity.changeset.description"></p>
18+
<small>{{activity.changeset.author.name}}, {{activity.changeset.date | date: 'yyyy-MM-dd HH:mm'}}</small>
19+
</div>
20+
</li>
21+
</ul>
22+
</div>
23+
</div>

src/commits/commits.js

+12-21
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,18 @@
2525
'use strict';
2626

2727
angular.module('adf.widget.scm')
28-
.controller('CommitsController', function ($sce, config, repository, commits) {
29-
var vm = this;
28+
.controller('CommitsController', function ($sce, config, repository, commits, SCM) {
29+
var vm = this;
3030

31-
vm.repository = repository;
31+
vm.repository = repository;
3232

33-
// allow html descriptions
34-
angular.forEach(commits, function (commit) {
35-
commit.description = $sce.trustAsHtml(commit.description);
36-
});
37-
vm.commits = commits;
33+
// allow html descriptions
34+
angular.forEach(commits, function (commit) {
35+
commit.description = $sce.trustAsHtml(commit.description);
36+
});
37+
vm.commits = commits;
3838

39-
vm.gravatarHash = function (commit) {
40-
var hash;
41-
if (commit.properties) {
42-
for (var i = 0; i < commit.properties.length; i++) {
43-
if (commit.properties[0].key === 'gravatar-hash') {
44-
hash = commit.properties[0].value;
45-
break;
46-
}
47-
}
48-
}
49-
return hash;
50-
};
51-
});
39+
vm.gravatarHash = function (commit) {
40+
return SCM.getGravatarHash(commit.properties);
41+
};
42+
});

src/commits/view.html

+2
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121
</div>
2222

2323
</div>
24+
25+

src/scm.js

+15
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,21 @@ angular.module('adf.widget.scm', ['adf.provider', 'chart.js', 'ngSanitize', 'btf
131131
},
132132
edit: edit
133133
})
134+
.widget('scm-activities', {
135+
title: 'SCM Activities',
136+
description: 'SCM Activities for all repositories',
137+
category: category,
138+
templateUrl: '{widgetsPath}/scm/src/activities/activityView.html',
139+
controller: 'ActivitiesController',
140+
controllerAs: 'vm',
141+
reload: true,
142+
resolve: {
143+
activities: function(SCM){
144+
var result = null;
145+
result = SCM.getActivities();
146+
return result;
147+
}
148+
}})
134149
.widget('scm-markdown-content', {
135150
title: 'SCM Markdown Content',
136151
description: 'Displays a Markdown Content Preview',

src/service.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ angular.module('adf.widget.scm')
5959
});
6060
}
6161

62+
63+
function getActivities(){
64+
return request('activity.json');
65+
}
66+
6267
function getFileContent(id, filePath) {
6368
return request('repositories/' + id + '/content?path=' + filePath);
6469
}
@@ -67,13 +72,28 @@ angular.module('adf.widget.scm')
6772
return request('repositories/' + id + '/branches');
6873
}
6974

75+
function getGravatarHash(properties) {
76+
var hash;
77+
if (properties){
78+
for (var i=0; i<properties.length; i++){
79+
if (properties[0].key === 'gravatar-hash'){
80+
hash = properties[0].value;
81+
break;
82+
}
83+
}
84+
}
85+
return hash;
86+
}
87+
7088
return {
7189
getRepositories: getRepositories,
7290
getRepository: getRepository,
7391
getCommitsByAuthor: getCommitsByAuthor,
7492
getCommitsByMonth: getCommitsByMonth,
7593
getCommits: getCommits,
94+
getActivities: getActivities,
7695
getFileContent: getFileContent,
77-
getBranchesByRepositoryId: getBranchesByRepositoryId
96+
getBranchesByRepositoryId: getBranchesByRepositoryId,
97+
getGravatarHash: getGravatarHash
7898
};
7999
});

0 commit comments

Comments
 (0)