blob: b9d0c47e0d49593e17041916124d6b1fb07e7904 [file] [log] [blame]
<!-- The <gold-status-sk> element displays the status of gold
Attributes:
status: Input attribute that defines the current status. Should be in the format:
{
corpStatus: [
{name: "svg", untriagedCount: 47, negativeCount:949 },
{name: "colorImage", untriagedCount: 17, negativeCount:449 },
{name: "gm", untriagedCount: 27, negativeCount:649 },
{name: "image", untriagedCount: 61, negativeCount:9 }
],
lastCommit: {
hash: "136baaa927877e0f7fcc97acb456ee0d63f7f343",
author: "username",
}
}
The keys of corpStatus are the different corpora availalbe.
corpus: Output attribute that reflects the currently selected corpus.
Events:
corpus-change: Fired whenever the corpus is changed by the user.
Methods:
setCorpus(corpus): Sets the current corpus to the given argument. It does
not fire a corpus-change event.
-->
<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="bower_components/iron-flex-layout/iron-flex-layout-classes.html">
<dom-module id="gold-status-sk">
<template>
<style>
.statusEntry {
font-size: 12pt;
display: inline-block;
float: left;
height: 48px;
line-height: 48px;
padding: 0 1em 0 1em;
position: relative;
}
.statusEntry a {
color: white;
}
</style>
<template is="dom-if" if="{{status}}">
<div class="statusEntry">
<a href$="{{_commitURL(status.lastCommit.hash)}}" target="_blank">
Last Commit: {{_lastCommitText(status)}}
</a>
</div>
</template>
</template>
<script>
Polymer({
is: "gold-status-sk",
properties: {
status: {
type: Object,
value: null
},
corpus: {
type: String,
value: sk.app_config.defaultCorpus,
notify: true,
reflectToAttribute: true
}
},
ready: function() {
this.status = null;
this._noFire = true;
this._reload();
},
setCorpus: function(corpus) {
// no longer used
},
// Load or reload the listing.
_reload: function() {
sk.get("/json/trstatus").then(JSON.parse).then(function (json) {
if (JSON.stringify(json) != JSON.stringify(this.status)) {
this.status = json;
}
this.async(this._reload, 3000);
}.bind(this)).catch(function(errorMessage) {
this.status = null;
console.log("Status Error:", errorMessage);
this.async(this._reload, 3000);
}.bind(this));
},
_lastCommitText: function(status) {
return this._limitTo(status.lastCommit.hash, 7) + " - " + this._limitTo(status.lastCommit.author, 0);
},
// _limitTo is a custom filter that returns the first len characters of
// a string or all characters before '(' - depending on len.
_limitTo: function(val, len) {
if (len > 0) {
return val.substr(0, len);
}
var idx = val.indexOf('(');
return val.substring(0, (idx === -1) ? val.length : idx);
},
// _commitURL returns the repository url for the given hash.
_commitURL: function(hash) {
var url = sk.app_config.baseRepoURL;
if (!url) {
// should never happen, but with Polymer, one can never be too cautious.
return;
}
if (url.indexOf('github.com') !== -1) {
return url + '/commit/' + hash;
} else {
return url + '/+show/' + hash;
}
}
});
</script>
</dom-module>