Commit 17ffb895 authored by Somaia Amin's avatar Somaia Amin
Browse files

added comments and README for frontend

parent a2c7bc4e
......@@ -36,11 +36,11 @@
# Steps to run the frontend app:
* navigate to web-app/
*`npm install`
* run `npm install`
* open 3 different terminals and execute only ONE command from the below in each terminal:
*`npm run start-m1`
*`npm run start-m2`
*`npm run start-s1`
* `npm run start-m1`
* `npm run start-m2`
* `npm run start-s1`
* open 3 different browsers, each browser with one of the below urls:
* `http://localhost:4200`
......
# WebApp
# Steps to run the frontend app:
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 6.0.8.
* run `npm install`
* open 3 different terminals and execute only ONE command from the below in each terminal:
## Development server
* `npm run start-m1`
* `npm run start-m2`
* `npm run start-s1`
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.
## Code scaffolding
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
## Build
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build.
## Running unit tests
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Running end-to-end tests
Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).
* open 3 different browsers, each browser with one of the below urls:
* `http://localhost:4200`
* `http://localhost:4201`
* `http://localhost:4202`
......@@ -9,15 +9,22 @@ import { HttpClient } from '@angular/common/http';
templateUrl: './companies-page.component.html',
styleUrls: ['./companies-page.component.scss']
})
/*
The main/companies page component
*/
export class CompaniesPageComponent implements OnInit {
errorMessage: string;
public listFilter: string;
//update the list of companies filtered by the searchbar
//calls performFilter () to perform the search
/*
updates the list of companies filtered by the searchbar
calls performFilter () to perform the search
input: search word
*/
setlistFilter(value: string) {
this.listFilter = value;
this.filteredCompanies = this.listFilter ? this.performFilter(this.listFilter) : this.companies;
......@@ -30,17 +37,23 @@ export class CompaniesPageComponent implements OnInit {
}
//the method that implements the functionality the searchbar in the main page
/*
implements the functionality of the searchbar in the main page
input: search word
output: filtered companies list
*/
performFilter(filterBy: string): Company[] {
console.log("inside filter");
filterBy = filterBy.toLocaleLowerCase();
return this.companies.filter((company: Company) =>
company.name.toLocaleLowerCase().indexOf(filterBy) !== -1);
}
/*
initializing function.
companies are retrieved here
*/
ngOnInit(): void {
//retrieving all the compaines from rest_api then displaying them
......
......@@ -8,6 +8,10 @@ import { ActivatedRoute, Router } from '@angular/router';
templateUrl: './company-card.component.html',
styleUrls: ['./company-card.component.scss']
})
/*
The component for displaying individual company cards in the main page
*/
export class CompanyCardComponent implements OnInit {
@Input() company: Company;
constructor(private _route: ActivatedRoute,
......
......@@ -25,7 +25,7 @@
<ul>
<!-- New comment input -->
<li *ngIf="audit.hasBusinessRelation && audit.acquired">
<input class="comment-input" placeholder="Give a rating ..." (keydown.enter)="keyDownFunction($event)" type="text" pInputText [(ngModel)]="questionComment"/>
<input class="comment-input" placeholder="Give a rating ..." type="text" pInputText [(ngModel)]="questionComment"/>
</li>
<li *ngIf="!showComment" class="comment-input">
<p (click)="showCommentOnClick()" style="text-align: center; color: blue; cursor: pointer;"> Show Comments...</p>
......
......@@ -13,6 +13,10 @@ import { environment } from '../../environments/environment';
templateUrl: './company-profile-audit.component.html',
styleUrls: ['./company-profile-audit.component.scss']
})
/*
The component responsible for showing the audits in the company's profile page
*/
export class CompanyProfileAuditComponent implements OnInit {
@Input() audit: Audit;
@Input() company: Company;
......@@ -33,12 +37,14 @@ export class CompanyProfileAuditComponent implements OnInit {
}
constructor(private _router: Router, private _DataService: DataService) {
//this.auditBought = false;
this.showComment = false;
this.auditPending = false;
}
//the method mapped to the buy button on audit
/*
The method mapped to the buy button on audit
calls the buyAuditAPI
*/
buyAudit() {
this._DataService.buyAuditAPI(this.audit.checksum, this.company.ownerPubKey).subscribe((data: JSON) => {
if (data['dev_message'] == "Success"){
......@@ -51,11 +57,19 @@ export class CompanyProfileAuditComponent implements OnInit {
});
}
showCommentOnClick() {
this.showComment = !this.showComment;
}
showCommentOnClick() {
this.showComment = !this.showComment;
}
/*
the method mapped to the view button on audit
calls the getAuditAPI to retrieve the Audit's pdf
output: redirects to the pdfviewr in case the call was successful
*/
//the method mapped to the view button on audit
viewAudit(){
var AuditType;
if (this.audit.acquired){
......@@ -86,24 +100,18 @@ showCommentOnClick() {
});
}
keyDownFunction(event){
// this._DataService.rateAuditAPI(this.audit.checksum, this.mark, this.questionComment);
}
updateMark(mark){
this.mark = mark;
}
/*
retrieves the Rating and the comments for an audit
*/
getAuditRating(){
//default value:
this._DataService.getAuditRatingAPI(this.audit.checksum).subscribe((data: JSON) => {
if(data['rating'] != null){
this.rating = data['rating'];
}
if(data['comments'] != null){
this.comments = data['comments']; //if this works delete the below
// for (let comment of data['comments']){
// this.comments.push(comment);
// }
this.comments = data['comments'];
}
else
this.rating = 0;
......
......@@ -18,7 +18,13 @@ export class CompanyProfileCertificateComponent implements OnInit {
ngOnInit() {
}
//the method mapped to the view button on the certificate
/*
the method mapped to the view button on the certificate
calls the getCertificateAPI to retrieve the Certificate's pdf
output: redirects to the pdfviewr in case the call was successful
*/
viewCertificate(){
this._DataService.getCertificateAPI(this.certificate.checksum).subscribe((data: JSON) => {
if (!data['error']){
......
......@@ -34,7 +34,12 @@ export class CompanyProfilePageComponent implements OnInit {
}
//retrieve the company by the id
/*
retrieves the company by the id
retrieves all the audits and certificates for the found company
input: Company's id
*/
getCompany(id: string) {
this._DataService.getCompanyAPI(id).subscribe((data: JSON)=> {
if (!data['error']){
......
......@@ -9,9 +9,9 @@ import { map} from 'rxjs/operators';
providedIn: 'root'
})
//The service that handles the calls to the rest_api
/*
*The service that handles the calls to the rest_api
*/
export class DataService {
restAPIURL:string = "http://127.0.0.1:"+ environment.restAPIport;
......@@ -39,7 +39,7 @@ export class DataService {
return this.http.get<JSON>(this.restAPIURL + "/api/v0/assets/audits/"+companyId);
}
getAuditAPI(checksum, type){ // TODO: remove companyType from the function header
getAuditAPI(checksum, type){
return this.http.get<JSON>(this.restAPIURL + "/api/v0/assets/audit/"+checksum+"&"+type);
}
......
......@@ -13,16 +13,20 @@ import { environment } from '../../environments/environment'
styleUrls: ['./pdf-viewer.component.scss']
})
//The component Responsible for viewing the audit or the certificate
/*
The component Responsible for viewing the audit or the certificate
*/
export class PdfViewerComponent implements OnInit {
@Input() company: Company;
public sub: Observable<string>;
public path : string;
public type: string;
public filename: string;
trustedURL: any;
/*
the construcor builds the path to the pdf file
*/
constructor(private _location: Location, private _route: ActivatedRoute, public sanitizer: DomSanitizer) {
//getting the file name
......@@ -51,9 +55,7 @@ export class PdfViewerComponent implements OnInit {
this.trustedURL = "http://localhost:" + environment.restAPIport + this.path;
console.log(this.trustedURL);
}
......
......@@ -7,7 +7,12 @@ import { NgForm } from '@angular/forms';
templateUrl: './searchbox.component.html',
styleUrls: ['./searchbox.component.scss']
})
/**
* the component responsible for the searchbox in the top of the main/companies page
*/
export class SearchboxComponent implements OnInit {
listFilter: string = this._CompaniesPageComponent.listFilter;
constructor(private _CompaniesPageComponent: CompaniesPageComponent) { }
......@@ -15,8 +20,14 @@ export class SearchboxComponent implements OnInit {
ngOnInit() {
}
onSubmit(f: NgForm) {
this._CompaniesPageComponent.setlistFilter(f.value["srch-term"]);
}
/*
Called on pressing enter while the cursor is in the searchbox
calls setlistFilter in the CompaiesPageComponent
input: search word entered in the field
*/
onSubmit(f: NgForm) {
this._CompaniesPageComponent.setlistFilter(f.value["srch-term"]);
}
}
......@@ -9,7 +9,9 @@ import { DataService } from '../data.service';
styleUrls: ['./star-rating.component.scss'],
})
//The component responsible for showing the ratings as stars
/*
*The component responsible for showing the ratings as stars
*/
export class StarRatingComponent implements OnInit {
@Input() starsCount: number;
@Input() readonly: boolean;
......@@ -20,15 +22,16 @@ export class StarRatingComponent implements OnInit {
ngOnInit() {
}
/*
called whenever a star is clicked to update the ratings
calls the rateAuditAPI to update the rating for an audit
*/
updateRating(){
if (this.comment == null){
alert("enter a comment first");
return;
}
this._DataService.rateAuditAPI(this.auditChecksum, this.starsCount, this.comment);
}
}
......@@ -17,7 +17,9 @@ const certificateUploudURL = "http://localhost:"+ environment.restAPIport +"/api
styleUrls: ['./upload-file.component.scss']
})
//the component responsible for uploading Audits and Certificates
/*
*the component responsible for uploading Audits and Certificates
*/
export class UploadFileComponent implements OnInit {
public uploader:FileUploader;
......@@ -25,6 +27,7 @@ export class UploadFileComponent implements OnInit {
companyId: String;
companyBCDBPubKey: string;
fileType: String; //Audit or Certificate
constructor(private _route: ActivatedRoute, public dialogRef: MatDialogRef<UploadFileComponent>,
private _router: Router, private _DataService: DataService,
@Inject(MAT_DIALOG_DATA) public data: any) {}
......@@ -56,8 +59,6 @@ export class UploadFileComponent implements OnInit {
//able to deal with the server response.
this.uploader.onCompleteItem = (item:any, response:any, status:any, headers:any) => {
console.log("PDFUpload:uploaded:", item, status, response);
console.log("response: " +response);
console.log("status: " +status);
alert ("Document Uploaded Successfully");
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment