blob: 1212d6074b2f4626164127bf97feb9ff3416e05b [file]
<link rel="import" href="../polymer/polymer.html">
<dom-module id="bug-link">
<template>
<style>
:host {
display: block;
}
p {
display: inline;
}
</style>
<a href$="http://bugs.chromium.org/p/[[_bugProject]]/issues/detail?id=[[_bugId]]">
[[_bugProject]]:[[_bugId]]</a>
<template is="dom-if" if="[[status]]">
<p>([[status]])</p>
</template>
<template is="dom-if" if="[[pri]]">
<p>(Pri-[[pri]])</p>
</template>
<template is="dom-if" if="[[!short]]">
<p>[[description]]</p>
</template>
</template>
<script>
'use strict';
const bugIdRe = /[0-9]{3,}/;
const bugRe = /([^0-9]*)?[0-9]{3,}([^0-9]*)?/;
const bugProjectUrlRe = /(\/p\/[a-z0-9][-a-z0-9]*[a-z0-9]\/)/i;
const bugProjectPairRe = /([a-z0-9][-a-z0-9]*[a-z0-9]:)/i;
const bugProjectNameRe = /[a-z0-9][-a-z0-9]*[a-z0-9]/i;
/**
* `<bug-link>` displays a link to a chromium bug.
*
* All properties except for `bug` are optional. Set short to true
* when the description should not be shown.
*
* @customElement
* @polymer
* @demo /demo/bug-link_demo.html
*/
class BugLink extends Polymer.Element {
static get is() { return 'bug-link'; }
static get properties() {
return {
/** A bug id, bug url, or a bug in the form of 'projectName:bugId' . Required. */
bug: String,
/** The bug id. */
_bugId: {
type: String,
computed: '_computeBugId(bug)',
},
/** The bug's project name. */
_bugProject: {
type: String,
computed: '_computeBugProject(bug)',
},
/** The status of the bug, eg. 'Untriaged', 'Available'. Optional. */
status: String,
/** The priority number of the bug. Optional. */
pri: {
type: String,
},
/** The bug's description. Optional. */
description: String,
/** Set to true if you don't want the bug's description to be displayed. */
short: {
type: Boolean,
value: false,
}
}
}
_computeBugId(bug) {
return bugRe.test(bug) ? bugIdRe.exec(bug) : 'Unknown';
}
_computeBugProject(bug) {
let cleanBug = bug.replace(/http(s?):/i, "");
let projectSection = bugProjectUrlRe.exec(cleanBug) || bugProjectPairRe.exec(cleanBug);
return projectSection ? bugProjectNameRe.exec(projectSection)[0] : 'chromium';
}
}
customElements.define(BugLink.is, BugLink);
</script>
<dom-module>