|
6 | 6 |
|
7 | 7 | "use strict"; |
8 | 8 |
|
| 9 | +const xssFilters = require("xss-filters"); |
9 | 10 | const $common = function() { |
10 | 11 | }; |
11 | 12 |
|
@@ -213,6 +214,32 @@ $common.componentClassifierLabelFormatter = (i18n) => { |
213 | 214 | } |
214 | 215 | }; |
215 | 216 |
|
| 217 | +/** |
| 218 | + * |
| 219 | + * @param {*} i18n - VueI18n instance with $t translate function available |
| 220 | + * @returns a specialized label for component and project classifiers (APPLICATION, LIBRARY, etc). |
| 221 | + * It must have a corresponding entry in the locales files (e.g. src/locales/en.json) |
| 222 | + * (application, library, etc.) |
| 223 | + */ |
| 224 | +$common.componentClassifierLabelProjectUrlFormatter = (i18n) => { |
| 225 | + return function (value) { |
| 226 | + let url = "../projects/?classifier=" + value; |
| 227 | + switch (value) { |
| 228 | + case 'APPLICATION': |
| 229 | + case 'FRAMEWORK': |
| 230 | + case 'LIBRARY': |
| 231 | + case 'CONTAINER': |
| 232 | + case 'OPERATING_SYSTEM': |
| 233 | + case 'DEVICE': |
| 234 | + case 'FIRMWARE': |
| 235 | + case 'FILE': |
| 236 | + return `<a href="${url}">${i18n.$t(`message.component_${value.toLowerCase()}`)}</a>` |
| 237 | + default: |
| 238 | + return null; |
| 239 | + } |
| 240 | + } |
| 241 | +}; |
| 242 | + |
216 | 243 | /** |
217 | 244 | * Given a UNIX timestamp, this function will return a formatted date. |
218 | 245 | * i.e. 15 Jan 2017 |
@@ -315,6 +342,7 @@ module.exports = { |
315 | 342 | makeAnalysisStateLabelFormatter: $common.makeAnalysisStateLabelFormatter, |
316 | 343 | makeAnalysisJustificationLabelFormatter: $common.makeAnalysisJustificationLabelFormatter, |
317 | 344 | componentClassifierLabelFormatter: $common.componentClassifierLabelFormatter, |
| 345 | + componentClassifierLabelProjectUrlFormatter: $common.componentClassifierLabelProjectUrlFormatter, |
318 | 346 | formatTimestamp: $common.formatTimestamp, |
319 | 347 | concatenateComponentName: $common.concatenateComponentName, |
320 | 348 | valueWithDefault: $common.valueWithDefault, |
|
0 commit comments