Skip to content

Commit

Permalink
Merge pull request #33 from NSWC-Crane/CHRIS_DEV
Browse files Browse the repository at this point in the history
Bug fixes and general improvements
  • Loading branch information
crodriguez6497 authored Feb 6, 2024
2 parents a3efe8d + a753cb6 commit 994d28e
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<button style="margin-left:20px;" nbButton outline status="info" *ngIf="showApprove" (click)="approvePoamAll(poam)">Approve ALL</button> -->

<div class="col">
<angular2-smart-table [settings]="poamApproverSettings" [source]="poamApprovers"
<angular2-smart-table [settings]="poamApproverSettings" [source]="poamApprovers" mode="inline"
(createConfirm)="confirmCreateApprover($event)" (editConfirm)="confirmEditApprover($event)" (deleteConfirm)="confirmDeleteApprover($event)">
</angular2-smart-table>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class PoamDetailsComponent implements OnInit {
collectionOwners: any;
collectionMaintainers: any;
collection: any;
collectionApprovers: any[] = [];
collectionApprovers: any;
poamApprovers: any[] = [];
assets: any;
poamAssets: any[] = [];
Expand All @@ -78,7 +78,6 @@ export class PoamDetailsComponent implements OnInit {
editButtonContent: '<img src="../../../../assets/icons/edit-outline.svg" width="20" height="20" >',
saveButtonContent: '<img src="../../../../assets/icons/checkmark-square-2-outline.svg" width="20" height="20" >',
cancelButtonContent: '<img src="../../../../assets/icons/close-square-outline.svg" width="20" height="20" >', //<i class="nb-close"></i>',
confirmSave: true
},
delete: {
deleteButtonContent: '<img src="../../../../assets/icons/trash-2-outline.svg" width="20" height="20" >',
Expand Down Expand Up @@ -121,7 +120,6 @@ export class PoamDetailsComponent implements OnInit {
editButtonContent: '<img src="../../../../assets/icons/edit-outline.svg" width="20" height="20" >',
saveButtonContent: '<img src="../../../../assets/icons/checkmark-square-2-outline.svg" width="20" height="20" >',
cancelButtonContent: '<img src="../../../../assets/icons/close-square-outline.svg" width="20" height="20" >', //<i class="nb-close"></i>',
confirmSave: true
},
delete: {
deleteButtonContent: '<img src="../../../../assets/icons/trash-2-outline.svg" width="20" height="20" >',
Expand All @@ -145,7 +143,7 @@ export class PoamDetailsComponent implements OnInit {
if (userId === undefined || userId === null) {
return '';
}
var user = this.collectionApprovers.find((tl: any) => tl.userId === userId);
var user = this.collectionApprovers.collectionApprovers.find((tl: any) => tl.userId === userId);
return user ? user.fullName : userId.toString();
} catch (error) {
console.error("Error in valuePrepareFunction: ", error);
Expand All @@ -155,7 +153,7 @@ export class PoamDetailsComponent implements OnInit {
editor: {
type: 'list',
config: {
list: [{ title: "T1", value: '1' }],
list: [],
},
},
},
Expand Down Expand Up @@ -222,7 +220,6 @@ export class PoamDetailsComponent implements OnInit {
editButtonContent: '<img src="../../../../assets/icons/edit-outline.svg" width="20" height="20" >',
saveButtonContent: '<img src="../../../../assets/icons/checkmark-square-2-outline.svg" width="20" height="20" >',
cancelButtonContent: '<img src="../../../../assets/icons/close-square-outline.svg" width="20" height="20" >', //<i class="nb-close"></i>',
confirmSave: true
},
delete: {
deleteButtonContent: '<img src="../../../../assets/icons/trash-2-outline.svg" width="20" height="20" >',
Expand Down Expand Up @@ -378,7 +375,7 @@ export class PoamDetailsComponent implements OnInit {
rawSeverity: "",
adjSeverity: "Minor",
scheduledCompletionDate: '',
ownerId: String(this.payload.userId),
ownerId: this.payload.userId,
mitigations: "",
requiredResources: "",
milestones: "",
Expand Down Expand Up @@ -414,8 +411,7 @@ export class PoamDetailsComponent implements OnInit {
// console.log("collectionOwners: ", this.collectionOwners)
// console.log("collectionMaintainers: ", this.collectionMaintainers)

this.setAssetsAssignees();
this.setApprovers();
this.setChartSelectionData();
});

} else {
Expand Down Expand Up @@ -455,8 +451,7 @@ export class PoamDetailsComponent implements OnInit {
// console.log("poamAssets: ", this.poamAssets)
// console.log("poamAssignees: ", this.poamAssignees)

this.setAssetsAssignees();
this.setApprovers();
this.setChartSelectionData();
});
}
}
Expand Down Expand Up @@ -486,80 +481,69 @@ export class PoamDetailsComponent implements OnInit {
})
}

setAssetsAssignees() {
setChartSelectionData() {
// Reset or initialize collections
this.collectionOwners = [];
this.collectionMaintainers = [];


// Populate owners and maintainers based on permissions
if (this.collectionUsers.permissions) {
this.collectionUsers.permissions.forEach((user: any) => {
//console.log("user: ", user)
if (user.canOwn) this.collectionOwners.push({ ...user });
if (user.canMaintain || user.canOwn) this.collectionMaintainers.push({ ...user });
})
}
// console.log("collectionOwners: ", this.collectionOwners)
// console.log("collectionMaintainers: ", this.collectionMaintainers)

let settings = this.poamAssetsSettings;
if (settings.columns['assetId']?.editor?.type === 'list') {
let editorConfig = settings.columns['assetId'].editor.config as ListEditorSettings;
editorConfig.list = this.assets.map((asset: any) => ({
title: asset.assetName,
value: asset.assetId
}));
});
}

this.poamAssetsSettings = Object.assign({}, settings);

let userSettings = this.poamAssigneesSettings;
if (userSettings.columns['userId']?.editor?.type === 'list') {
let editorConfig = userSettings.columns['userId'].editor.config as ListEditorSettings;
editorConfig.list = this.collectionUsers.permissions.map((assignee: any) => ({
title: assignee.fullName,
value: assignee.userId
}));

// Set Asset Selection Data
let assetSettings = this.poamAssetsSettings;
if (assetSettings.columns['assetId']?.editor?.type === 'list') {
let assetEditorConfig = assetSettings.columns['assetId'].editor.config as ListEditorSettings;
const assetPlaceholder = { title: 'Select an Asset...', value: '' };
assetEditorConfig.list = [
assetPlaceholder,
...this.assets.map((asset: any) => ({
title: asset.assetName,
value: asset.assetId,
}))
];
}

this.poamAssigneesSettings = Object.assign({}, userSettings);
}

setApprovers() {

let settings = this.poamApproverSettings;
let approverList: any[] = [];

if (this.collectionApprovers && this.collectionApprovers.length > 0) {
this.collectionApprovers.forEach((approver: any) => {
let listValue = {
title: approver.fullName,
value: approver.userId
}
//console.log("approver2: ", approver)
approverList.push(listValue);

// console.log("approver: ",approver)
});
this.poamAssetsSettings = Object.assign({}, assetSettings);

// Set Assignees Selection Data
let assigneeSettings = this.poamAssigneesSettings;
if (assigneeSettings.columns['userId']?.editor?.type === 'list') {
let assigneeEditorConfig = assigneeSettings.columns['userId'].editor.config as ListEditorSettings;
const assigneePlaceholder = { title: 'Select a Team Member...', value: '' };
assigneeEditorConfig.list = [
assigneePlaceholder,
...this.collectionUsers.permissions.map((assignee: any) => ({
title: assignee.fullName,
value: assignee.userId
}))
];
}

if (settings.columns['userId']?.editor?.type === 'list') {
let editorConfig = settings.columns['userId'].editor.config as ListEditorSettings;
editorConfig.list = approverList;
// Correctly use 'isEditable' instead of 'editable'
settings.columns['userId'].isEditable = this.showApprove;
// Trigger change detection if necessary
this.poamApproverSettings = Object.assign({}, settings);
this.poamAssigneesSettings = Object.assign({}, assigneeSettings);

// Set Approvers Selection Data
let approverSettings = this.poamApproverSettings;
if (approverSettings.columns['userId']?.editor?.type === 'list') {
let approverEditorConfig = approverSettings.columns['userId'].editor.config as ListEditorSettings;
const approverPlaceholder = { title: 'Select an Approver...', value: '' };

approverEditorConfig.list = [
approverPlaceholder,
...this.collectionApprovers.collectionApprovers.map((approver: any) => ({
title: approver.fullName,
value: approver.userId,
}))
];
}

this.poamApproverSettings = Object.assign({}, settings);

// console.log("SetApprovers collectionApprovers: ", this.collectionApprovers)
// console.log("SetApprovers approverList: ", approverList)
}

this.poamApproverSettings = Object.assign({}, approverSettings);
}

async approvePoam(poam: any) {
//this.router.navigateByUrl("");
await this.router.navigateByUrl("/poam-approve/" + +this.poam.poamId);

await this.router.navigateByUrl("/poam-approve/" + this.poam.poamId);
}

async approvePoamAll(poam: any) {
Expand Down Expand Up @@ -729,63 +713,6 @@ export class PoamDetailsComponent implements OnInit {
this.router.navigateByUrl("/poam-processing");
}

async confirmCreateApprover(event: any) {
// console.log("poamDetails confirmCreateApprover data: ", event)

if (this.poam.poamId === "ADDPOAM") {
//
event.confirm.reject();
return;
}

if (this.poam.status != "Draft") {
this.showConfirmation("you may only modify the approver list if poam status is 'Draft'.");
event.confirm.reject();
return;
}

if (this.poam.poamId &&
event.newData.userId
) {
// console.log("poamDetails confirmCreate poam.colectionId: ",this.poam.collectionId,", userId: ", event.newData.userId);
// console.log("poamDetails confirmCreate collectionApprovers: ",this.collectionApprovers)
let user = await this.collectionApprovers.find((tl: any) => tl.collectionId == this.poam.collectionId && tl.userId == event.newData.userId)

let approver: any = {
poamId: +this.poam.poamId,
userId: +event.newData.userId,
status: event.newData.status,
approved: 'Not Reviewed',
comments: event.newData.comments
}
// console.log("user: ", usert)
if (user) {
approver.firstName = user.firstName;
approver.lastName = user.lastName;
approver.fullName = user.fullName;
approver.userEmail = user.userEmail;
}

await this.poamService.addPoamApprover(approver).subscribe((res: any) => {
// console.log("poamDetail confirmCreatePoam res: ", res)
if (res.null) {
this.showConfirmation("Unable to insert row, potentially a duplicate.");
event.confirm.reject();
return;
} else {

event.confirm.resolve();
this.poamApprovers.push(approver);
this.poamApprovers = [...this.poamApprovers];
}
})

} else {
this.showConfirmation("Failed to create entry on poamApprover. Invalid input.");
event.confirm.reject();
}
}

confirmEditApprover(event: any) {
// console.log("poamDetails confirmEditApprover event: ", event)
if (this.poam.poamId === "ADDPOAM") {
Expand Down Expand Up @@ -826,14 +753,18 @@ export class PoamDetailsComponent implements OnInit {

async confirmDeleteApprover(event: any) {
// console.log("poamDetails confirmDeleteApprover event: ", event)
if (this.poam.poamId === "ADDPOAM") {
event.confirm.resolve();
return;
}

if (this.poam.status != "Draft") {
this.showConfirmation("you may only modify the approver list if poam status is 'Draft'.");
event.confirm.reject();
return;
}

await this.poamService.deletePoamApprover(event.data.poamId, event.data.userId).subscribe((res: any) => {
this.poamService.deletePoamApprover(event.data.poamId, event.data.userId).subscribe((res: any) => {
// console.log("confirmDelete res to delete: ", res)
const index = this.poamApprovers.findIndex(((e: any) => {e.poamId == event.data.poamId && e.userId == event.data.userId}));
if (index > -1) {
Expand All @@ -844,6 +775,62 @@ export class PoamDetailsComponent implements OnInit {
})
}

async confirmCreateApprover(event: any) {
// console.log("poamDetails confirmCreateApprover data: ", event)

if (this.poam.poamId === "ADDPOAM") {
event.confirm.resolve();
return;
}

if (this.poam.status != "Draft") {
this.showConfirmation("you may only modify the approver list if poam status is 'Draft'.");
event.confirm.reject();
return;
}

if (this.poam.poamId &&
event.newData.userId
) {
// console.log("poamDetails confirmCreate poam.colectionId: ",this.poam.collectionId,", userId: ", event.newData.userId);
// console.log("poamDetails confirmCreate collectionApprovers: ",this.collectionApprovers)
let user = await this.collectionApprovers.collectionApprovers.find((tl: any) => tl.collectionId == this.poam.collectionId && tl.userId == event.newData.userId)

let approver: any = {
poamId: +this.poam.poamId,
userId: +event.newData.userId,
status: event.newData.status,
approved: 'Not Reviewed',
comments: event.newData.comments
}
// console.log("user: ", usert)
if (user) {
approver.firstName = user.firstName;
approver.lastName = user.lastName;
approver.fullName = user.fullName;
approver.userEmail = user.userEmail;
}

await this.poamService.addPoamApprover(approver).subscribe((res: any) => {
// console.log("poamDetail confirmCreatePoam res: ", res)
if (res.null) {
this.showConfirmation("Unable to insert row, potentially a duplicate.");
event.confirm.reject();
return;
} else {

event.confirm.resolve();
this.poamApprovers.push(approver);
this.poamApprovers = [...this.poamApprovers];
}
})

} else {
this.showConfirmation("Failed to create entry on poamApprover. Invalid input.");
event.confirm.reject();
}
}

confirmCreate(data: any) {
// console.log("confirmCreate data: ", data)
if (this.poam.poamId === "ADDPOAM") {
Expand Down
20 changes: 7 additions & 13 deletions Front End/poam-app/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@
<head>
<meta charset="utf-8">
<title>C-PAT</title>
<base href="./">
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<!-- <app-root></app-root> -->
<ngx-app>Loading...</ngx-app>
<div class="sk-container" id="nb-global-spinner">
<div class="sk-chase">
<div class="sk-chase-dot"></div>
<div class="sk-chase-dot"></div>
<div class="sk-chase-dot"></div>
<div class="sk-chase-dot"></div>
<div class="sk-chase-dot"></div>
<div class="sk-chase-dot"></div>
</div>
</div>
<ngx-app></ngx-app>
<script src="runtime.js" type="module"></script>
<script src="polyfills.js" type="module"></script>
<script src="styles.js" defer></script>
<script src="vendor.js" type="module"></script>
<script src="main.js" type="module"></script>
</body>
</html>

0 comments on commit 994d28e

Please sign in to comment.