Open Markavian opened 9 years ago
This works:
<jenkins-jobs data-source-url="/api/connectedTvCloudJenkins" refresh-time="10"></jenkins-jobs>
<template for="jenkins-jobs">
{{#each jobs}}
<a href="{{url}}">
<button class="btn btn-{{alertType}}">{{name}} : {{color}}</button>
</a>
{{/each}}
</template>
<style for="jenkins-jobs">
jenkins-jobs > a {
margin: 5px 0;
display: inline-block;
text-decoration: none;
}
</style>
<script type="text/javascript" for="jenkins-jobs">
$(function() {
var JenkinsJobComponent = Component.configure('jenkins-jobs');
JenkinsJobComponent.prototype.selectAlertType = function(jenkinsColor) {
return ({
"red": 'danger',
"blue": 'success',
"blue_anime": 'info'
})[jenkinsColor] || 'danger';
}
JenkinsJobComponent.on('preRenderStep', function(instance) {
try {
var list = instance.jobs;
if (list) {
for (key in list) {
var item = list[key];
item.alertType = instance.selectAlertType(item.color);
item.url = instance.data.service + '/job/' + item.name;
}
}
} catch (e) {
// do nothing
}
});
});
</script>
Rolling with a slightly more advanced implementation here: https://github.com/connected-tv/connected-tv-app-monitor/blob/master/config/content/index.content.html
Probably needs componentising, using the compiler feature of Web Component JS (when its ready), see: https://github.com/connected-web/web-component-js/issues/7
Me thinks this would also be a good candidate for a plugin, see #32...
Feature: write a component tag that lets you hook into a Jekins job, or jobs, with an appropriate filter.
e.g.:
e.g. data source: