-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98e0579
commit d331632
Showing
5 changed files
with
1,443 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
'use strict'; | ||
|
||
import { | ||
serverStyle, pageMasterName, pageBuildName, pageType, dataURL, | ||
} from './poudriere'; | ||
|
||
export function jailURL(mastername) { | ||
if (serverStyle === 'hosted') { | ||
if (mastername) { | ||
return `jail.html?mastername=${encodeURIComponent(mastername)}`; | ||
} | ||
return '#'; | ||
} | ||
return '../'; | ||
} | ||
|
||
export function buildURL(mastername, buildname) { | ||
if (!mastername || !buildname) { | ||
return ''; | ||
} | ||
return ( | ||
'build.html?' | ||
+ `mastername=${ | ||
encodeURIComponent(mastername) | ||
}&` | ||
+ `build=${ | ||
encodeURIComponent(buildname)}` | ||
); | ||
} | ||
|
||
export function formatOrigin(origin, flavor) { | ||
if (!origin) { | ||
return ''; | ||
} | ||
|
||
const data = origin.split('/'); | ||
let resultFlavor = ''; | ||
|
||
if (flavor) { | ||
resultFlavor = `@${flavor}`; | ||
} else { | ||
resultFlavor = ''; | ||
} | ||
|
||
return ( | ||
`<a target="_new" title="freshports for ${ | ||
origin | ||
}" href="https://www.freshports.org/${ | ||
data[0] | ||
}/${ | ||
data[1] | ||
}/"><span ` | ||
+ `class="glyphicon glyphicon-tasks"></span>${ | ||
origin | ||
}${resultFlavor | ||
}</a>` | ||
); | ||
} | ||
|
||
export function formatPkgName(pkgname) { | ||
return pkgname; | ||
} | ||
|
||
export function formatMasterName(mastername) { | ||
let html; | ||
|
||
if (!mastername) { | ||
return ''; | ||
} | ||
|
||
if (pageMasterName && mastername === pageMasterName && pageType === 'jail') { | ||
html = `<a href="#top" onclick="scrollToElement('#top'); return false;">${ | ||
mastername | ||
}</a>`; | ||
} else { | ||
html = `<a title="List builds for ${ | ||
mastername | ||
}" href="${ | ||
jailURL(mastername) | ||
}">${ | ||
mastername | ||
}</a>`; | ||
} | ||
|
||
return html; | ||
} | ||
|
||
export function formatJailName(jailname) { | ||
return jailname; | ||
} | ||
|
||
export function formatSetName(setname) { | ||
return setname; | ||
} | ||
|
||
export function formatPtName(ptname) { | ||
return ptname; | ||
} | ||
|
||
export function formatBuildName(mastername, buildname) { | ||
let html; | ||
|
||
if (!mastername) { | ||
return buildname; | ||
} if (!buildname) { | ||
return ''; | ||
} | ||
|
||
if ( | ||
pageMasterName | ||
&& mastername === pageMasterName | ||
&& pageBuildName | ||
&& buildname === pageBuildName | ||
&& pageType === 'build' | ||
) { | ||
html = `<a href="#top" onclick="scrollToElement('#top'); return false;">${ | ||
buildname | ||
}</a>`; | ||
} else { | ||
html = `<a title="Show build results for ${ | ||
buildname | ||
}" href="${ | ||
buildURL(mastername, buildname) | ||
}">${ | ||
buildname | ||
}</a>`; | ||
} | ||
|
||
return html; | ||
} | ||
|
||
export function formatPortSet(ptname, setname) { | ||
return ptname + (setname ? '-' : '') + setname; | ||
} | ||
|
||
export function formatLog(pkgname, errors, text) { | ||
const html = `<a target="logs" title="Log for ${ | ||
pkgname | ||
}" href="${ | ||
dataURL | ||
}logs/${ | ||
errors ? 'errors/' : '' | ||
}${pkgname | ||
}.log"><span class="glyphicon glyphicon-file"></span>${ | ||
text | ||
}</a>`; | ||
return html; | ||
} | ||
|
||
function formatDuration(duration) { | ||
let hours; let minutes; let | ||
seconds; | ||
|
||
if (duration === undefined || duration === '' || Number.isNaN(duration)) { | ||
return ''; | ||
} | ||
|
||
hours = Math.floor(duration / 3600); | ||
const tmpDuration = duration - hours * 3600; | ||
minutes = Math.floor(tmpDuration / 60); | ||
seconds = tmpDuration - minutes * 60; | ||
|
||
if (hours < 10) { | ||
hours = `0${hours}`; | ||
} | ||
if (minutes < 10) { | ||
minutes = `0${minutes}`; | ||
} | ||
if (seconds < 10) { | ||
seconds = `0${seconds}`; | ||
} | ||
|
||
return `${hours}:${minutes}:${seconds}`; | ||
} | ||
|
||
export function formatStartToEnd(start, end) { | ||
let duration; | ||
|
||
if (!start) { | ||
return ''; | ||
} | ||
const startStr = parseInt(start, 10); | ||
if (Number.isNaN(startStr)) { | ||
return ''; | ||
} | ||
|
||
if (end === undefined) { | ||
duration = startStr; | ||
} else { | ||
duration = end - startStr; | ||
} | ||
|
||
if (duration < 0) { | ||
duration = 0; | ||
} | ||
|
||
return formatDuration(duration); | ||
} | ||
|
||
export function formatSkipped(skippedCnt, pkgname) { | ||
if (skippedCnt === undefined || skippedCnt === 0) { | ||
return 0; | ||
} | ||
return ( | ||
`<a href="#skipped" onclick="filterSkipped('${ | ||
pkgname | ||
}'); return false;"><span class="glyphicon ` | ||
+ `glyphicon-filter"></span>${ | ||
skippedCnt | ||
}</a>` | ||
); | ||
} | ||
|
||
export function formatStatusRow(status, row, n) { | ||
const tableRow = []; | ||
|
||
tableRow.push(n + 1); | ||
if (status === 'built') { | ||
tableRow.push(formatPkgName(row.pkgname)); | ||
tableRow.push(formatOrigin(row.origin, row.flavor)); | ||
tableRow.push(formatLog(row.pkgname, false, 'success')); | ||
tableRow.push(formatDuration(row.elapsed ? row.elapsed : '')); | ||
} else if (status === 'failed') { | ||
tableRow.push(formatPkgName(row.pkgname)); | ||
tableRow.push(formatOrigin(row.origin, row.flavor)); | ||
tableRow.push(row.phase); | ||
tableRow.push(row.skipped_cnt); | ||
tableRow.push(formatLog(row.pkgname, true, row.errortype)); | ||
tableRow.push(formatDuration(row.elapsed ? row.elapsed : '')); | ||
} else if (status === 'skipped') { | ||
tableRow.push(formatPkgName(row.pkgname)); | ||
tableRow.push(formatOrigin(row.origin, row.flavor)); | ||
tableRow.push(formatPkgName(row.depends)); | ||
} else if (status === 'ignored') { | ||
tableRow.push(formatPkgName(row.pkgname)); | ||
tableRow.push(formatOrigin(row.origin, row.flavor)); | ||
tableRow.push(row.skipped_cnt); | ||
tableRow.push(row.reason); | ||
} else if (status === 'fetched') { | ||
tableRow.push(formatPkgName(row.pkgname)); | ||
tableRow.push(formatOrigin(row.origin, row.flavor)); | ||
} else if (status === 'remaining') { | ||
tableRow.push(formatPkgName(row.pkgname)); | ||
tableRow.push(row.status); | ||
} else if (status === 'queued') { | ||
tableRow.push(formatPkgName(row.pkgname)); | ||
tableRow.push(formatOrigin(row.origin, row.flavor)); | ||
if (row.reason === 'listed') { | ||
tableRow.push(row.reason); | ||
} else { | ||
tableRow.push(formatOrigin(row.reason)); | ||
} | ||
} else { | ||
throw new Error(`Unknown data type "${status}". Try flushing cache.`); | ||
} | ||
|
||
return tableRow; | ||
} |
Oops, something went wrong.