Skip to content

Commit 6005393

Browse files
authored
Merge pull request #3 from cwolfes/master
Markdown-Content-Preview Widget
2 parents fec4854 + 2e41db4 commit 6005393

15 files changed

+226
-61
lines changed

bower.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
],
2424
"description": "SCM-Manager related widgets",
2525
"dependencies": {
26-
"angular": ">=1.4 <=1.6",
27-
"angular-dashboard-framework": "~0.12.0",
28-
"angular-chart.js": "^0.10.2"
26+
"angular": ">=1.4 <=1.6.4",
27+
"angular-dashboard-framework": "v0.12.x",
28+
"angular-chart.js": "^1.1.0",
29+
"angular-markdown-directive": "^0.3.1"
2930
},
3031
"devDependencies": {
3132
"angular-local-storage": ">=0.2"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"gulp-connect": "~2.2.0",
2121
"gulp-csslint": "^0.1.5",
2222
"gulp-headerfooter": "^1.0.3",
23-
"gulp-if": "^1.2.5",
23+
"gulp-if": "2.x",
2424
"gulp-inject": "^1.2.0",
2525
"gulp-jshint": "^1.9.4",
2626
"gulp-less": "^3.0.2",

src/charts/commitsByAuthor.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
'use strict';
2626

2727
angular.module('adf.widget.scm')
28-
.controller('CommitsByAuthorController', function(config, repository, commitsByAuthor){
28+
.controller('CommitsByAuthorController', function (config, repository, commitsByAuthor) {
2929
var vm = this;
30+
vm.repository = repository;
3031

3132
if (repository && commitsByAuthor) {
3233
vm.chart = createChart();
@@ -37,14 +38,22 @@ angular.module('adf.widget.scm')
3738

3839
angular.forEach(commitsByAuthor.author, function (entry) {
3940
var author = entry.value;
40-
data[author]= entry.count;
41+
data[author] = entry.count;
4142
});
4243

44+
var options = {
45+
legend: {
46+
display: true,
47+
position: "bottom"
48+
}
49+
};
50+
4351
var chart = {
4452
labels: [],
4553
data: [],
4654
series: ["Commits"],
47-
class: "chart-pie"
55+
class: "chart-pie",
56+
options: options
4857
};
4958

5059
angular.forEach(data, function (count, author) {

src/charts/commitsByMonth.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,41 @@
2525
'use strict';
2626

2727
angular.module('adf.widget.scm')
28-
.controller('CommitsByMonthController', function(config, repository, commitsByMonth) {
28+
.controller('CommitsByMonthController', function (config, repository, commitsByMonth) {
2929
var vm = this;
30+
vm.repository = repository;
31+
3032
if (commitsByMonth) {
3133
vm.chart = createChart();
3234
}
3335

34-
function parseDate(input) {
35-
var parts = input.split('-');
36-
return Date.UTC(parseInt(parts[0]), parseInt(parts[1]) - 1, 1);
37-
}
38-
3936
function createChart() {
4037
var chartData = [];
38+
var options = {
39+
scales: {
40+
yAxes: [
41+
{
42+
id: 'y-axis-1',
43+
display: true,
44+
position: 'left',
45+
ticks: {fixedStepSize: 1},
46+
scaleLabel: {
47+
display: true,
48+
labelString: 'Commits'
49+
}
50+
}
51+
]
52+
}
53+
};
4154
var chart = {
4255
labels: [],
4356
data: [chartData],
4457
series: ["Commits"],
45-
class: "chart-line"
58+
class: "chart-line",
59+
options: options
4660
};
4761

48-
angular.forEach(commitsByMonth.month, function(month) {
62+
angular.forEach(commitsByMonth.month, function (month) {
4963
chart.labels.push(month.value);
5064
chartData.push(month.count);
5165
});

src/charts/commitsLastCommits.js

+23-6
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,46 @@
2525
'use strict';
2626

2727
angular.module('adf.widget.scm')
28-
.controller('LastCommitsController', function($filter, config, repository, commits){
28+
.controller('LastCommitsController', function ($filter, config, repository, commits) {
2929
var vm = this;
30+
vm.repository = repository;
3031

3132
if (repository && commits) {
3233
vm.chart = createChart();
3334
}
3435

3536
function createChart() {
37+
var options = {
38+
scales: {
39+
yAxes: [
40+
{
41+
id: 'y-axis-1',
42+
display: true,
43+
position: 'left',
44+
ticks: {fixedStepSize: 1},
45+
scaleLabel: {
46+
display: true,
47+
labelString: 'Commits'
48+
}
49+
}
50+
]
51+
}
52+
};
3653
var chartData = [];
3754
var chart = {
3855
labels: [],
3956
data: [chartData],
4057
series: ["Commits"],
41-
class: "chart-line"
58+
class: "chart-line",
59+
options: options
4260
};
4361

4462
var data = {};
45-
angular.forEach(commits, function(commit){
63+
angular.forEach(commits, function (commit) {
4664
var date = new Date(commit.date);
4765
var key = date.getUTCFullYear() + '-' + (date.getUTCMonth() + 1) + '-' + date.getUTCDate();
4866
var entry = data[key];
49-
if (entry){
67+
if (entry) {
5068
entry.count += 1;
5169
} else {
5270
data[key] = {
@@ -56,8 +74,7 @@ angular.module('adf.widget.scm')
5674
}
5775
});
5876

59-
angular.forEach(data, function(entry) {
60-
console.log(entry);
77+
angular.forEach(data, function (entry) {
6178
chart.labels.push(entry.date);
6279
chartData.push(entry.count);
6380
});

src/charts/line-chart.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
<div class="alert alert-info" ng-if="!vm.chart">
33
Please insert a repository path in the widget configuration
44
</div>
5+
<div ng-if="vm.repository.status == 404 || vm.repository.status == 500" class="alert alert-danger">
6+
<b>Error {{vm.repository.status}}</b> the endpoint could not be reached, this could mean that the selected repository does not exist
7+
or that the statistics plugin is not installed
8+
</div>
59
<div ng-if="vm.chart">
610
<canvas id="line" class="chart chart-line"
711
chart-data="vm.chart.data" chart-labels="vm.chart.labels"
8-
chart-options="vm.chart.options" chart-series="vm.chart.series">
12+
chart-series="vm.chart.series" chart-options="vm.chart.options">
913
</canvas>
1014
</div>
15+
1116
</div>

src/charts/pie-chart.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
<div class="alert alert-info" ng-if="!vm.chart">
33
Please insert a repository path in the widget configuration
44
</div>
5+
<div ng-if="vm.repository.status == 404 || vm.repository.status == 500" class="alert alert-danger">
6+
<b>Error {{vm.repository.status}}</b> the endpoint could not be reached, this could mean that the selected repository does not exist
7+
or that the statistics plugin is not installed
8+
</div>
59
<div ng-if="vm.chart">
610
<canvas id="pie" class="chart chart-pie"
711
chart-legend="true" chart-data="vm.chart.data"
8-
chart-labels="vm.chart.labels">
12+
chart-labels="vm.chart.labels" chart-options="vm.chart.options">
913
</canvas>
1014
</div>
15+
1116
</div>

src/commits/commits.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@
2525
'use strict';
2626

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

3131
vm.repository = repository;
3232

3333
// allow html descriptions
34-
angular.forEach(commits, function(commit){
34+
angular.forEach(commits, function (commit) {
3535
commit.description = $sce.trustAsHtml(commit.description);
3636
});
3737
vm.commits = commits;
3838

39-
vm.gravatarHash = function(commit){
39+
vm.gravatarHash = function (commit) {
4040
var hash;
41-
if (commit.properties){
42-
for (var i=0; i<commit.properties.length; i++){
43-
if (commit.properties[0].key === 'gravatar-hash'){
41+
if (commit.properties) {
42+
for (var i = 0; i < commit.properties.length; i++) {
43+
if (commit.properties[0].key === 'gravatar-hash') {
4444
hash = commit.properties[0].value;
4545
break;
4646
}

src/commits/view.html

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<div ng-if="!config.repository" class="alert alert-info">
33
Please configure a repository
44
</div>
5+
<div ng-if="vm.repository.status == 404 || vm.repository.status == 500" class="alert alert-danger">
6+
<b>Error {{vm.repository.status}}</b> the endpoint could not be reached, this could mean that the selected repository does not exist
7+
</div>
58
<div ng-if="config.repository">
69
<ul class="media-list">
710
<li class="media" ng-repeat="commit in vm.commits">
@@ -16,4 +19,5 @@
1619
</li>
1720
</ul>
1821
</div>
22+
1923
</div>

src/markdownPreview/edit.html

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<form role="form">
2+
<div class="form-group">
3+
<p><label for="repository">Repository</label>
4+
<select name="repository" id="repository" class="form-control" ng-model="config.repository"
5+
ng-init="vm.getBranchesByRepositoryId(config.repository)"
6+
ng-change="vm.getBranchesByRepositoryId(config.repository)">
7+
<option ng-repeat="repository in vm.repositories | orderBy: 'name'" value="{{repository.id}}">
8+
{{repository.name}}
9+
</option>
10+
</select>
11+
</p>
12+
13+
<p ng-if="vm.branches"><label for="branch">Branch</label>
14+
<select name="branch" id="branch" class="form-control" ng-model="config.branch">
15+
<option ng-repeat="branch in vm.branches| orderBy: 'name'" value="{{branch.id}}">
16+
{{branch.name}}
17+
</option>
18+
</select>
19+
</p>
20+
<label for="path">Path to Markdown File</label>
21+
<input type="text" class="form-control" id="path" ng-model="config.path">
22+
</div>
23+
</form>
24+
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
angular.module('adf.widget.scm')
4+
.controller('MarkdownPreviewController', function (repository, fileContent) {
5+
var vm = this;
6+
vm.repository = repository;
7+
vm.fileContent = fileContent;
8+
});
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
angular.module('adf.widget.scm')
4+
.controller('MarkdownPreviewEditController', function (repositories, SCM) {
5+
var vm = this;
6+
vm.repositories = repositories;
7+
8+
vm.getBranchesByRepositoryId = function (repositoryId) {
9+
if (repositoryId) {
10+
SCM.getBranchesByRepositoryId(repositoryId).then(function (result) {
11+
// catch repositories without branch support
12+
if (result.status == 400) {
13+
vm.branches = null;
14+
}else{
15+
vm.branches = result.branch;
16+
}
17+
});
18+
}
19+
};
20+
21+
});

src/markdownPreview/view.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<style>
2+
div.markdownContent{
3+
overflow: auto;
4+
width: 100%;
5+
}
6+
</style>
7+
<div class="alert alert-info" ng-if="!vm.fileContent">
8+
Please configure a specific file
9+
</div>
10+
<div ng-if="vm.fileContent" btf-markdown="vm.fileContent" class="markdownContent">
11+
</div>
12+
<div class="alert alert-danger" ng-if="vm.fileContent.status == 500 || vm.fileContent.status == 404">
13+
<b>Error {{vm.fileContent.status}}</b> Markdown-File not found. Please check your configuration and try again.
14+
</div>
15+

0 commit comments

Comments
 (0)