Skip to content

Commit

Permalink
Merge pull request #176 from softrams/167
Browse files Browse the repository at this point in the history
Asset Archive Feature
  • Loading branch information
Whamo12 committed Aug 1, 2020
2 parents 75ad4fc + a433792 commit ef85dd0
Show file tree
Hide file tree
Showing 17 changed files with 708 additions and 153 deletions.
1 change: 1 addition & 0 deletions .jest/setEnvVars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.env.NODE_ENV = 'test';
29 changes: 28 additions & 1 deletion frontend/src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class AppService {
}

/**
* Function returns all assests related to the organization ID
* Function returns all active assets related to the organization ID
* @param id is the ID of the organization
* @returns all assets related to the organization passed
*/
Expand All @@ -128,6 +128,15 @@ export class AppService {
});
}

/**
* Function returns all archived assets related to the organization ID
* @param id is the ID of the organization
* @returns all assets related to the organization passed
*/
getOrganizationArchiveAssets(id: number) {
return this.http.get(`${this.api}/organization/${id}/asset/archive`);
}

/**
* Function is responsible for archiving an organization by altering it's status
* @param id is the organization being passed for archiving
Expand Down Expand Up @@ -264,6 +273,24 @@ export class AppService {
);
}

/**
* Function is responsible for archiving an asset
* @param asset is the ID associated to the asset
* @returns http status code of the request
*/
archiveAsset(asset: Asset) {
return this.http.patch(`${this.api}/asset/archive/${asset.id}`, {});
}

/**
* Function is responsible for activating an asset
* @param asset is the ID associated to the asset
* @returns http status code of the request
*/
activateAsset(asset: Asset) {
return this.http.patch(`${this.api}/asset/activate/${asset.id}`, {});
}

/**
* Function is responsible for creating new assessments
* @param assessment data contained in the assessment form object
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/assessments/assessments.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
style="margin-right: 5px;" data-toggle="tooltip" data-placement="bottom" title="Back to Organization">
Back to Organization
</button>
</div>
</div>
81 changes: 53 additions & 28 deletions frontend/src/app/organization/organization.component.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
<div class="container">
<div class="container-fluid">
<div class="row">
<h3 class="mx-auto">{{ org?.name }} Assets</h3>
<h3 class="mx-auto">{{ org?.name }} {{isArchive ? 'Archived':'Active'}} Assets</h3>
</div>
<br />
<div class="row card-group">
<h4 *ngIf="!assetAry.length">The organization {{ org?.name }} does not have any assets.</h4>
<div class="col-3" *ngFor="let asset of assetAry">
<div class="card text-center">
<div class="card-body">
<h5 class="card-title">{{ asset.name }}</h5>
<button (click)="navigateToAsset(asset.id)" class="btn btn-secondary" style="margin-right: 5px;"
data-toggle="tooltip" data-placement="bottom" title="Edit {{ asset.name }}">
Edit
</button>
<button (click)="navigateToAssessment(asset.id)" class="btn btn-primary" data-toggle="tooltip"
data-placement="bottom" title="Assessments">
Assessments
</button>
</div>
</div>
</div>
</div>
<h4 *ngIf="!assetAry.length">The organization {{ org?.name }} does not have any assets.</h4>
<table class="table" *ngIf="assetAry && assetAry.length">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Status</th>
<th scope="col"></th>
</tr>
</thead>
<tbody *ngFor="let asset of assetAry">
<td scope="row">{{ asset?.id }}</td>
<td>{{ asset?.name }}</td>
<td>{{ asset?.status === 'A' ? 'Active':'Archived' }}</td>
<td>
<button *ngIf="!isArchive" class="btn btn-secondary" type="button" style="margin-right: 10px;"
data-toggle="tooltip" (click)="navigateToAsset(asset.id)" c data-placement="bottom" title="Edit Asset">
<fa-icon [icon]="faPencilAlt"></fa-icon>
</button>
<button *ngIf="!isArchive" (click)="navigateToAssessment(asset.id)" class="btn btn-primary"
style="margin-right: 10px;" type="button" data-toggle="tooltip" data-placement="bottom"
title="View Assessments">
<fa-icon [icon]="faList"></fa-icon>
</button>
<button (click)="archiveAsset(asset);" *ngIf="!isArchive" class="btn btn-dark" type="button"
data-toggle="tooltip" data-placement="bottom" title="Archive">
<fa-icon [icon]="faBox"></fa-icon>
</button>
<button (click)="activateAsset(asset);" *ngIf="isArchive" class="btn btn-dark" type="button"
data-toggle="tooltip" data-placement="bottom" title="Activate">
<fa-icon [icon]="faBoxOpen"></fa-icon>
</button>
</td>
</tbody>
</table>
<br />
<button (click)="navigateToCreateAsset()" type="button" class="btn btn-primary float-right">
Add Asset
</button>
<button style="margin-right: 5px;" (click)="navigateToDashboard()" type="button"
class="btn btn-secondary float-right">
Back to Dashboard
</button>
</div>
<div class="float-right">
<button style="margin-right: 5px;" (click)="navigateToDashboard()" type="button" class="btn btn-secondary ">
Back to Dashboard
</button>
<button style="margin-right: 5px;" *ngIf="!isArchive" (click)="getArchivedAssets()" type="button"
class="btn btn-dark " data-toggle="tooltip" data-placement="bottom" title="View Archived Assets">
View Archive
</button>
<button style="margin-right: 5px;" *ngIf="isArchive" (click)="getActiveAssets()" type="button" class="btn btn-dark "
data-toggle="tooltip" data-placement="bottom" title="View Active Assets">
View Active
</button>
<button (click)="navigateToCreateAsset()" *ngIf="!isArchive" type="button" class="btn btn-primary ">
Add Asset
</button>
</div>
78 changes: 71 additions & 7 deletions frontend/src/app/organization/organization.component.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,66 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { AppService } from '../app.service';
import { Organization } from '../org-form/Organization';

import {
faPencilAlt,
faList,
faBox,
faBoxOpen,
} from '@fortawesome/free-solid-svg-icons';
import { Asset } from '../asset-form/Asset';
import { AlertService } from '../alert/alert.service';
@Component({
selector: 'app-organization',
templateUrl: './organization.component.html',
styleUrls: ['./organization.component.sass']
styleUrls: ['./organization.component.sass'],
})
export class OrganizationComponent implements OnInit {
assetAry: any = [];
orgId: number;
org: any;
constructor(public activatedRoute: ActivatedRoute, public router: Router, public appService: AppService) {}
isArchive = false;
faPencilAlt = faPencilAlt;
faList = faList;
faBox = faBox;
faBoxOpen = faBoxOpen;
constructor(
public activatedRoute: ActivatedRoute,
public router: Router,
public appService: AppService,
public alertService: AlertService
) {}

ngOnInit() {
this.activatedRoute.data.subscribe(({ assets }) => (this.assetAry = assets));
this.activatedRoute.data.subscribe(
({ assets }) => (this.assetAry = assets)
);
this.activatedRoute.params.subscribe((params) => {
this.orgId = params.orgId;
this.appService.getOrganizationById(this.orgId).then((org) => (this.org = org));
this.appService
.getOrganizationById(this.orgId)
.then((org) => (this.org = org));
});
}

/**
* Function responsible retrieving active assets
*/
getActiveAssets() {
this.appService.getOrganizationAssets(this.orgId).then((activeAssets) => {
this.assetAry = activeAssets;
this.isArchive = false;
});
}
/**
* Function responsible retrieving archived assets
*/
getArchivedAssets() {
this.appService
.getOrganizationArchiveAssets(this.orgId)
.subscribe((archivedAssets) => {
this.assetAry = archivedAssets;
this.isArchive = true;
});
}
/**
* Function responsible for navigating the user to an Assessment
* @param id assessment ID is required
Expand Down Expand Up @@ -52,4 +91,29 @@ export class OrganizationComponent implements OnInit {
navigateToAsset(assetId: number) {
this.router.navigate([`organization/${this.orgId}/asset-form/${assetId}`]);
}

/**
* Function responsible for archiving an asset
*/
archiveAsset(asset: Asset) {
const confirmed = confirm(`Archive the asset "${asset.name}"?`);
if (confirmed) {
this.appService.archiveAsset(asset).subscribe((res: string) => {
this.alertService.success(res);
this.getActiveAssets();
});
}
}
/**
* Function responsible for activating an asset
*/
activateAsset(asset: Asset) {
const confirmed = confirm(`Activate the asset "${asset.name}"?`);
if (confirmed) {
this.appService.activateAsset(asset).subscribe((res: string) => {
this.alertService.success(res);
this.getArchivedAssets();
});
}
}
}
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ module.exports = {
'<rootDir>/src/classes',
'<rootDir>/src/entity',
'<rootDir>/src/enums'
]
],
setupFiles: ['<rootDir>/.jest/setEnvVars.js']
};
109 changes: 109 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"cz-conventional-changelog": "^3.2.0",
"husky": "^4.2.5",
"jest": "^26.2.2",
"mock-express-request": "^0.2.2",
"mock-express-response": "^0.2.2",
"nodemon": "^2.0.4",
"rimraf": "^3.0.2",
"sqlite3": "^5.0.0",
Expand Down
Loading

0 comments on commit ef85dd0

Please sign in to comment.