Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][DO_NOT_MERGE] Resurrect extension-points in web console #6238

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions assets/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
<script src="bower_components/kubernetes-object-describer/dist/object-describer.js"></script>
<script src="bower_components/openshift-object-describer/dist/object-describer.js"></script>
<script src="bower_components/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js"></script>
<script src="bower_components/angular-extension-registry/dist/angular-extension-registry.min.js"></script>
<script src="bower_components/angular-extension-registry/dist/compiled-templates.js"></script>
<!-- endbower -->
<!-- endbuild -->

Expand Down Expand Up @@ -226,6 +228,15 @@
<script src="scripts/services/logLinks.js"></script>
<!-- endbuild -->

<!-- extension manager demo -->
<link rel="stylesheet" href="scripts/_extensions/build_details/style.css" />
<script src="scripts/_extensions/build_details/route.js"></script>
<script src="scripts/_extensions/build_details/stub.js"></script>
<script src="scripts/_extensions/build_details/service.js"></script>
<script src="scripts/_extensions/build_details/controller.js"></script>
<script src="scripts/_extensions/build_details/extension.js"></script>
<!-- /extension manager demo -->

<!-- Load any extensions last. -->
<script src="scripts/extensions.js"></script>

Expand Down
39 changes: 39 additions & 0 deletions assets/app/scripts/_extensions/build_details/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

angular.module('openshiftConsole')
.controller('GitRepoController', function($filter, $http, $scope, $routeParams, ProjectsService, DataService, Git, GitApiStub) {
$scope.projectName = $routeParams.project;
$scope.renderOptions = {
hideFilterWidget: true
};

ProjectsService
.get($routeParams.project)
.then(_.spread(function(project, context) {
$scope.project = project;

DataService
.get("builds", $routeParams.build, context)
.then(function(build) {
$scope.build = build;

if(!Git.uri.for.commits(build)) {
return;
};

Git // real API call
//GitApiStub // stub, to avoid hitting github's rate limit
.get(Git.uri.for.commits(build))
.then(function(request) {
$scope.githubLinks = request.data;
},function() {
$scope.alerts['error'] = {
type: "error",
message: "Error",
details: "We're sorry, but something went wrong."
};
});
});
}));

});
58 changes: 58 additions & 0 deletions assets/app/scripts/_extensions/build_details/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

angular
.module('openshiftConsole')
.run([
'$q',
'$timeout',
'extensionInput',
'Git',
'GitApiStub',
function($q, $timeout, extensionInput, Git, GitApiStub) {
var template = _.template([
'<div>',
'<h3>Github Activity</h3>',
'<table>',
'<tr>',
'<td>',
'<strong>Latest Commit Message to source repo: &nbsp;&nbsp;&nbsp;</strong>',
'</td>',
'<td>',
'<%= message %> &nbsp;&nbsp;',
'</td>',
'<td>',
'<a href="<%= route %>">View more </a>',
'</td>',
'</tr>',
'</table>',
'</div>'
].join(''));

extensionInput.register('build_details', _.spread(function(build, buildConfigName) {
var uri = build.spec &&
build.spec.source &&
build.spec.source.git &&
build.spec.source.git.uri,
route = URI('project')
.segment(build.metadata.namespace)
.segment('browse')
.segment('builds')
.segment(buildConfigName)
.segment(build.metadata.name)
.segment('gitrepo')
.toString();

return uri ?
Git // real API call
//GitApiStub // stub, to avoid hitting github's rate limit
.get(Git.uri.for.commits(build))
.then(function(request) {
return {
type: 'html',
html: template({ route: route, githubUri: uri, message: _.first(request.data).commit.message })
};
}) :
null;
}));
}
]);
16 changes: 16 additions & 0 deletions assets/app/scripts/_extensions/build_details/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

angular.module('openshiftConsole')
// add a route to support
.config([
'$routeProvider',
function($routeProvider) {
// TODO: register a route to a page that will show the last commits
// for the github repo
$routeProvider
.when('/project/:project/browse/builds/:buildconfig/:build/gitrepo', {
templateUrl: 'scripts/_extensions/build_details/view.html',
controller: 'GitRepoController'
})
}
])
31 changes: 31 additions & 0 deletions assets/app/scripts/_extensions/build_details/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

angular.module('openshiftConsole')
.factory('Git', function($http) {
return {
uri: {
for: {
commits: function(build) {
var gitUri = build.spec &&
build.spec.source &&
build.spec.source.git &&
build.spec.source.git.uri,
segments = URI(gitUri).suffix('').segment(),
apiUri = URI('https://api.github.com')
.segment('repos');

_.each(segments, function(segment) {
apiUri.segment(segment);
});
apiUri.segment('commits');
return apiUri;
}
}
},
get: function(apiUri) {
return $http({
url: apiUri
});
}
}
});
115 changes: 115 additions & 0 deletions assets/app/scripts/_extensions/build_details/stub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
'use strict';

angular.module('openshiftConsole')
.factory('GitApiStub', function($q) {
return {
get: function() {
// Fake data of same format as Github's api, but with some dummy values injected
return $q.when({
data: [
{
"sha": "123456789012345",
"commit": {
"author": {
"name": "John Doe",
"email": "jdoe@users.noreply.github.com",
"date": "2015-12-02T12:54:13Z"
},
"message": "Merge pull request #49 from jdoe/bump_version\n\nmove hello world example to ruby-22 image",
"url": "https://api.github.com/repos/jdoe/stuff-and-things/git/commits/123456789012345",
"comment_count": 0
},
"url": "https://api.github.com/repos/jdoe/stuff-and-things/commits/123456789012345",
"html_url": "https://github.com/jdoe/stuff-and-things/commit/123456789012345",
"comments_url": "https://api.github.com/repos/jdoe/stuff-and-things/commits/123456789012345/comments",
"author": {
"login": "jdoe",
"id": 1234567,
"avatar_url": "https://avatars.githubusercontent.com/u/1234567?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/jdoe",
"html_url": "https://github.com/jdoe",
"repos_url": "https://api.github.com/users/jdoe/repos",
"events_url": "https://api.github.com/users/jdoe/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdoe/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "jdoe",
"id": 1234567,
"avatar_url": "https://avatars.githubusercontent.com/u/1234567?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/jdoe",
"html_url": "https://github.com/jdoe",
"repos_url": "https://api.github.com/users/jdoe/repos",
"type": "User"
},
"parents": [
{
"sha": "12345123451234512345",
"url": "https://api.github.com/repos/jdoe/stuff-and-things/commits/12345123451234512345",
"html_url": "https://github.com/jdoe/stuff-and-things/commit/12345123451234512345"
},
{
"sha": "09876543210987654321",
"url": "https://api.github.com/repos/jdoe/stuff-and-things/commits/09876543210987654321",
"html_url": "https://github.com/jdoe/stuff-and-things/commit/09876543210987654321"
}
]
},{
"sha": "123456789012345",
"commit": {
"author": {
"name": "John Doe",
"email": "jdoe@users.noreply.github.com",
"date": "2015-12-02T12:54:13Z"
},
"message": "Merge pull request #49 from jdoe/bump_version\n\nmove hello world example to ruby-22 image",
"url": "https://api.github.com/repos/jdoe/stuff-and-things/git/commits/123456789012345",
"comment_count": 0
},
"url": "https://api.github.com/repos/jdoe/stuff-and-things/commits/123456789012345",
"html_url": "https://github.com/jdoe/stuff-and-things/commit/123456789012345",
"comments_url": "https://api.github.com/repos/jdoe/stuff-and-things/commits/123456789012345/comments",
"author": {
"login": "jdoe",
"id": 1234567,
"avatar_url": "https://avatars.githubusercontent.com/u/1234567?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/jdoe",
"html_url": "https://github.com/jdoe",
"repos_url": "https://api.github.com/users/jdoe/repos",
"events_url": "https://api.github.com/users/jdoe/events{/privacy}",
"received_events_url": "https://api.github.com/users/jdoe/received_events",
"type": "User",
"site_admin": false
},
"committer": {
"login": "jdoe",
"id": 1234567,
"avatar_url": "https://avatars.githubusercontent.com/u/1234567?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/jdoe",
"html_url": "https://github.com/jdoe",
"repos_url": "https://api.github.com/users/jdoe/repos",
"type": "User"
},
"parents": [
{
"sha": "12345123451234512345",
"url": "https://api.github.com/repos/jdoe/stuff-and-things/commits/12345123451234512345",
"html_url": "https://github.com/jdoe/stuff-and-things/commit/12345123451234512345"
},
{
"sha": "09876543210987654321",
"url": "https://api.github.com/repos/jdoe/stuff-and-things/commits/09876543210987654321",
"html_url": "https://github.com/jdoe/stuff-and-things/commit/09876543210987654321"
}
]
}
]
});
}
}
});
4 changes: 4 additions & 0 deletions assets/app/scripts/_extensions/build_details/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#git .sha { width: 25%;}
#git .author { width: 15%;}
#git .date { width: 15%;}
#git .message {width: 45%;}
38 changes: 38 additions & 0 deletions assets/app/scripts/_extensions/build_details/view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="content">
<project-page>
<breadcrumbs breadcrumbs="[{}]"></breadcrumbs>
<alerts></alerts>
<div class="row">
<div class="col-md-12">
<div class="tile">
<h1>{{build.metadata.name}} Git Commits</h1>

<table id="git" class="table table-bordered table-hover table-mobile">
<thead>
<tr>
<th class="sha">SHA</th>
<th class="author">Author</th>
<th class="date">Date</th>
<th class="message">Message</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="gitLink in githubLinks">
<td class="sha">
<a href="{{gitLink.html_url}}" target="_blank">
<span class="truncate">{{gitLink.sha}}</span>
</a>
</td>
<td class="author">
<a href="mailto:{{gitLink.commit.author.email}}">{{gitLink.commit.author.name}}</a>
</td>
<td class="date">{{gitLink.commit.author.date | date : short }}</td>
<td class="message">{{gitLink.commit.message}}</td>
</tr>
</tbody>

</div>
</div>
</div>
</project-page>
</div>
3 changes: 2 additions & 1 deletion assets/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ angular
'kubernetesUI',
'ui.bootstrap',
'patternfly.charts',
'openshiftConsoleTemplates'
'openshiftConsoleTemplates',
'extension-registry'
])
.constant("mainNavTabs", []) // even though its not really a "constant", it has to be created as a constant and not a value
// or it can't be referenced during module config
Expand Down
11 changes: 11 additions & 0 deletions assets/app/styles/__extension.prototype.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.extension-pod {
border: 1px solid #0099d3;
color: #0099d3;
background: #F2F2F2;
padding: 2px;
margin: 2px;
border-radius: 4px
}
.extension-pod:hover {
background: #C1DEE8;
}
4 changes: 4 additions & 0 deletions assets/app/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,7 @@
@import "_tile.less";
@import "_topology.less";
@import "_log.less";


/* extension registry prototype */
@import "__extension.prototype.less";
Loading