Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/controllers/it-standards.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ function removeSavedCategories(techId) {
return `DELETE FROM zk_technology_TRM WHERE obj_technology_Id=${escape(techId)};`;
}
function saveCategories(techId, categoryId) {
return `INSERT INTO zk_technology_TRM (obj_TRM_Id, obj_technology_Id) VALUES (${escape(categoryId)}, ${escape(techId)});`;
// The root "Technical Reference Model (TRM)" node (level 0) must never be assigned
return `INSERT INTO zk_technology_TRM (obj_TRM_Id, obj_technology_Id)
SELECT Technology_Category_Id, ${escape(techId)} FROM obj_TRM
WHERE Technology_Category_Id = ${escape(categoryId)} AND TRM_Level <> '0';`;
}

// Remove and Save POCs
Expand Down
8 changes: 5 additions & 3 deletions api/queries/GET/get_it-standards_recent.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ SELECT
tech.Id AS ID,
IFNULL(tech.softwareReleaseName, tech.Keyname) AS Name,
tech.Description,
GROUP_CONCAT(DISTINCT obj_standard_category.Keyname SEPARATOR ', ') AS Category,
-- Each TRM entry is "Domain > Area > Name"; entries are separated by '|' because TRM names can contain commas
NULLIF(GROUP_CONCAT(DISTINCT CONCAT_WS(' > ', NULLIF(obj_TRM.TRM_Domain, ''), NULLIF(obj_TRM.TRM_Area, ''), obj_TRM.TRM_Name)
ORDER BY obj_TRM.TRM_Name SEPARATOR '|'), '') AS Category,
obj_technology_status.Keyname AS Status,
obj_deployment_type.Keyname AS DeploymentType,
DATE(tech.Approved_Status_Expiration_Date) AS ApprovalExpirationDate,
Expand All @@ -14,5 +16,5 @@ FROM obj_technology AS tech
LEFT JOIN obj_technology_status ON tech.obj_technology_status_Id = obj_technology_status.Id
LEFT JOIN obj_deployment_type ON tech.obj_deployment_type_Id = obj_deployment_type.Id

LEFT JOIN zk_technology_standard_category ON tech.Id = zk_technology_standard_category.obj_technology_Id
LEFT JOIN obj_standard_category ON zk_technology_standard_category.obj_standard_category_Id = obj_standard_category.Id
LEFT JOIN zk_technology_TRM ON tech.Id = zk_technology_TRM.obj_technology_Id
LEFT JOIN obj_TRM ON zk_technology_TRM.obj_TRM_Id = obj_TRM.Technology_Category_Id
29 changes: 29 additions & 0 deletions src/app/services/shared/shared.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,35 @@ export class SharedService {
else return value;
}

//// TRM Category Formatter
// Expects '|'-separated entries of "Domain > Area > Name" (see get_it-standards_recent.sql)
public formatTrmCategories(value: any, row: any) {
if (!value) return '-';
const escapeHtml = (s: string) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
const maxChips = 2;

const paths = String(value).split('|').filter(e => e.trim()).map(entry =>
// Areas repeat their name at the Area and Name levels, so collapse duplicates
entry.split(' > ').map(p => p.trim()).filter((p, i, arr) => p && p !== arr[i - 1])
);
// Drop parent Domains/Areas when a more specific TRM beneath them is also assigned
const entries = paths
.filter(p => !paths.some(other => other.length > p.length && p.every((part, i) => other[i] === part)))
.map(p => ({ label: p[p.length - 1], path: p.join(' › ') }));
if (!entries.length) return '-';

const chips = entries.slice(0, maxChips)
.map(e => `<span class="trm-category-chip" title="${escapeHtml(e.path)}">${escapeHtml(e.label)}</span>`);

const hidden = entries.slice(maxChips);
if (hidden.length) {
const hiddenTitle = escapeHtml(hidden.map(e => e.path).join('\n'));
chips.push(`<span class="trm-category-chip trm-category-chip-more" title="${hiddenTitle}">+${hidden.length} more</span>`);
}

return `<span class="trm-category-chips">${chips.join('')}</span>`;
}

//// OS & App Bundle formatter
public csvFormatter(value: any, row: any) {
if(value) {
Expand Down
1 change: 1 addition & 0 deletions src/app/views/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy {
header: 'Category',
isSortable: false,
showColumn: true,
formatter: this.sharedService.formatTrmCategories
},{
field: 'Status',
header: 'Status',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,40 @@
<div class="data">
<label for="itStandCategory" class="data-label">Technology Category<span class="text-danger">*</span></label>
<ng-select id="itStandCategory" formControlName="itStandCategory"
class="trm-select"
[items]="categories"
[multiple]="true"
bindLabel="Name"
bindValue="Id"
[searchFn]="trmSearchFn"
clearAllText="Clear All"
[clearSearchOnAdd]="true"
[clearSearchOnAdd]="false"
[closeOnSelect]="false"
[loading]="catsLoading"
placeholder="Search & Select Categories Here"
[virtualScroll]="true"
(scroll)="modalService.onScroll($event, catsBuffer, bufferSize, categories, catsLoading)"
(scrollToEnd)="modalService.onScrollToEnd(catsBuffer, bufferSize, categories, catsLoading)"
placeholder="Search by name or definition (e.g. vulnerability, database)"
notFoundText="No technology categories match your search"
required>
<ng-template ng-header-tmp>
<small class="form-text text-muted">Loaded {{ catsBuffer.length }} of {{ categories.length }}</small>
<small class="form-text text-muted">
Search matches TRM names and definitions. Choose the most specific category that applies;
you can select more than one.
</small>
</ng-template>
<ng-template ng-label-tmp let-item="item" let-clear="clear">
<span class="ng-value-icon left" (click)="clear(item)" aria-hidden="true">×</span>
<span class="ng-value-label" [title]="item.Path">{{ item.Name }}</span>
</ng-template>
<ng-template ng-option-tmp let-item="item" let-search="searchTerm">
<div class="trm-option" [style.padding-left.rem]="search ? 0 : item.Depth * 1.25">
<div class="trm-option-header">
<span class="trm-option-name" [innerHTML]="highlightTrmText(item.Name, search)"></span>
<span class="trm-level-badge" [ngClass]="'trm-level-' + item.Type?.toLowerCase()">{{ item.Type }}</span>
</div>
@if (search && item.Parents) {
<div class="trm-option-path">{{ item.Parents }}</div>
}
<div class="trm-option-desc" [innerHTML]="trmDescriptionSnippet(item.Description, search)"></div>
</div>
</ng-template>
</ng-select>
@if (modalService.fieldValidCheck(itStandardsForm, 'itStandCategory')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,70 @@
}
}
}
}
}
// Technology Category (TRM) picker
.trm-option {
display: flex;
flex-direction: column;
gap: .15rem;
white-space: normal;

& .trm-option-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: .5rem;
}

& .trm-option-name {
font-weight: 600;
}

& .trm-option-path {
font-size: .75rem;
color: #565C65;
}

& .trm-option-desc {
font-size: .75rem;
color: #3D4551;
line-height: 1.35;
}

& .trm-level-badge {
flex-shrink: 0;
padding: .1rem .45rem;
border-radius: .25rem;
font-size: .65rem;
letter-spacing: .5px;
text-transform: uppercase;
background: #E7F2F8;
color: #0B4778;

&.trm-level-domain {
background: #0B4778;
color: #fff;
}

&.trm-level-area {
background: #CFE8FF;
color: #0B4778;
}
}
}

::ng-deep .trm-select {
& .ng-dropdown-panel .ng-dropdown-panel-items {
max-height: 26rem;
}

& .ng-dropdown-panel .ng-option {
border-bottom: 1px solid #F0F0F0;
}

& .trm-option mark {
padding: 0;
background: #FFE396;
color: inherit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class ItStandardsManagerComponent implements OnInit {
this.types = types;

// categories
this.categories = cats;
this.categories = this.buildTrmOptions(cats);
this.catsBuffer = this.categories.slice(0, this.bufferSize);
this.catsLoading = false;

Expand Down Expand Up @@ -370,18 +370,13 @@ export class ItStandardsManagerComponent implements OnInit {
var fedramp = this.itStandard.fedramp === 'T';
var openSource = this.itStandard.open_source === 'T';

// Parse and find IDs for list of Categories
var categoryIDs = [];
if (this.itStandard.Category) {
this.itStandard.Category.split(', ').forEach(cat => {
if(cat) {
const catId = this.sharedService.findInArray(this.categories, 'Name', cat, 'Id');
if(catId !== undefined && catId !== null) {
categoryIDs.push(catId);
}
}
// Load assigned TRM IDs directly; TRM names can contain commas so the joined Category string can't be split reliably
this.apiService.getITStandardsRelatedTRM(this.itStandard.ID).subscribe((trms: any[]) => {
const validIds = new Set(this.categories.map(c => c.Id));
this.itStandardsForm.patchValue({
itStandCategory: (trms || []).map(t => t.Id).filter(id => validIds.has(id))
});
};
});

let selectedOSList: string[] = [];
if(this.itStandard.OperatingSystems) {
Expand Down Expand Up @@ -414,7 +409,6 @@ export class ItStandardsManagerComponent implements OnInit {
itStandPOC: pocIDs,
itStandDesc: this.itStandard.Description,
itStandType: this.sharedService.findInArray(this.types, 'Name', this.itStandard.StandardType),
itStandCategory: categoryIDs,
itStand508: this.sharedService.findInArray(this.compliance, 'Name', this.itStandard.ComplianceStatus),
itStand508ExceptionLink: this.itStandard.ExceptionLink,
itStandMyView: myView,
Expand Down Expand Up @@ -993,6 +987,74 @@ export class ItStandardsManagerComponent implements OnInit {
}
}

// Orders TRMs depth-first (Domain > Area > Category) and drops the root TRM node, which should never be assigned
private buildTrmOptions(trms: any[]): any[] {
if (!trms) return [];
const ids = new Set(trms.map(t => Number(t.Id)));
const childrenOf = new Map<number, any[]>();
trms.forEach(t => {
const parentId = ids.has(Number(t.ParentId)) ? Number(t.ParentId) : null;
if (!childrenOf.has(parentId)) childrenOf.set(parentId, []);
childrenOf.get(parentId).push(t);
});
childrenOf.forEach(list => list.sort((a, b) => a.Name.localeCompare(b.Name)));

const options: any[] = [];
const visit = (parentId: number, ancestors: string[]) => {
(childrenOf.get(parentId) || []).forEach(t => {
const isRoot = String(t.Level) === '0';
if (!isRoot) {
options.push({
...t,
Type: t.Type || 'Category',
Depth: ancestors.length,
Parents: ancestors.join(' › '),
Path: [...ancestors, t.Name].join(' › ')
});
}
visit(Number(t.Id), isRoot ? ancestors : [...ancestors, t.Name]);
});
};
visit(null, []);
return options;
}

public trmSearchFn = (term: string, item: any): boolean => {
const words = term.toLowerCase().split(/\s+/).filter(w => w);
const haystack = `${item.Name} ${item.Parents} ${item.Description || ''}`.toLowerCase();
return words.every(w => haystack.includes(w));
};

private escapeHtml(text: string): string {
return String(text ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
}

public highlightTrmText(text: string, term: string): string {
const raw = String(text ?? '');
const words = (term || '').trim().split(/\s+/).filter(w => w).map(w => w.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'));
if (!words.length) return this.escapeHtml(raw);
// Split on the raw text so highlighting never lands inside an HTML entity
return raw.split(new RegExp(`(${words.join('|')})`, 'gi'))
.map((part, i) => i % 2 ? `<mark>${this.escapeHtml(part)}</mark>` : this.escapeHtml(part))
.join('');
}

// Shows the start of the definition, or a window around the first search hit when it falls later in the text
public trmDescriptionSnippet(description: string, term: string, maxLength: number = 160): string {
const text = String(description ?? '').replace(/\s+/g, ' ').trim();
if (!text) return '';
let start = 0;
const firstWord = (term || '').trim().split(/\s+/)[0]?.toLowerCase();
if (firstWord) {
const hit = text.toLowerCase().indexOf(firstWord);
if (hit > maxLength - firstWord.length) start = Math.max(0, hit - 40);
}
let snippet = text.substring(start, start + maxLength);
if (start > 0) snippet = '…' + snippet;
if (start + maxLength < text.length) snippet += '…';
return this.highlightTrmText(snippet, term);
}

cleanup() {
this.itStandardsForm = new FormGroup({
auditUser: new FormControl(null),
Expand Down Expand Up @@ -1109,7 +1171,7 @@ export class ItStandardsManagerComponent implements OnInit {
// Populate Categories
this.catsLoading = true;
this.apiService.getTRM().subscribe((data: any[]) => {
this.categories = data;
this.categories = this.buildTrmOptions(data);
this.catsBuffer = this.categories.slice(0, this.bufferSize);
this.catsLoading = false;
});
Expand Down
23 changes: 23 additions & 0 deletions src/styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,29 @@ body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
-webkit-box-orient: vertical;
}

.trm-category-chips {
display: flex;
flex-direction: column;
gap: .25rem;
}

.trm-category-chip {
display: inline-block;
width: fit-content;
padding: .25rem .625rem;
border-radius: .25rem;
background: #E7F2F8;
color: #0B4778;
font-size: .75rem;
line-height: 1.3;
cursor: help;

&.trm-category-chip-more {
background: #F0F0F0;
color: #3D4551;
}
}

.fixed-table-toolbar .search input {
border: 1px solid;
height: 100%;
Expand Down
Loading