Printing docstring on the web frontend
antonysigma opened this issue · 1 comments
Hi! I am wondering how I can modify the openhtf code to print the test phase docstring on the web frontend?
For multi-line docstring, only the first line is shown. The rest of the docstrings are shown when we click the "expand all" button on the web frontend.
I know this is achievable because I have seen it work on a forked project https://gitlab.com/tackv/spintop-openhtf . In fact, I have been using spintop until the underlying company (TackV GmBH) went out of business last year.
Reference:
https://gitlab.com/tackv/spintop-openhtf/-/blob/master/docs/docs/doc/documenting.md#L6
Tracing back the commit history, it appears that the feature was mentioned at [1], which in turn results in the merge request [2]. I don't know how the control script phase_descriptor.py
should be modified, but I know that the Angular web frontend code looks something like this, according to the commits at [2].
Any suggestions on how to port over the code from repo spintop_openhtf
to this repo?
# src/openhtf/output/web_gui/src/app/stations/station/phase.component.html
<div class="htf-layout-header" [class.header-with-measurements]="showMeasurements" [class.teardown-phase]="isTeardown">
<span class="u-clamp-text">
<strong class="phase-name">{{ phase.name }}</strong>
- <span class="phase-doc">: {{ phase.doc }}</span>
+ <span *ngIf="!showDocExtended" class="phase-doc">: {{ phase.doc }}</span>
<span *ngIf="phase.status !== PhaseStatus.waiting">
{{ phase \| elapsedTime:'(%s)' }}
</span>
# src/openhtf/output/web_gui/src/app/shared/models/phase.model.ts
@@ -40,7 +40,7 @@ export class Phase {
if (params.doc) docLines = params.doc.split("\n");
else docLines = []
params.doc = docLines.length > 0 ? docLines[0] : '';
- params.docExtended = docLines.slice(1).join("\n");
+ params.docExtended = docLines.join("\n");
Object.assign(this, params);
}
}
# openhtf/output/web_gui/src/app/stations/station/phase.component.ts
ngOnChanges(changes: SimpleChanges) {
if (changes.phase) {
this.computeDocExtended()
}
}
+ computeDocExtended() {
+ const doc = this.markdownService.compile(this.phase.docExtended);
+ // const safeHtml = this.sanitizer.sanitize(SecurityContext.HTML, doc);
+ this.docExtended = this.sanitizer.bypassSecurityTrustHtml(doc);
+ }
get isTeardown() {
return this.phase.runOptions && this.phase.runOptions.type === 'TEARDOWN';
}
+ get showDocExtended() {
+ const shouldShow = this.expand || (this.expandIfRunning && this.phase.status === PhaseStatus.running);
+ return shouldShow && this.phase.docExtended;
+ }
[1] https://gitlab.com/tackv/spintop-openhtf/-/issues/10
[2] https://gitlab.com/tackv/spintop-openhtf/-/merge_requests/8