Skip to content

Commit

Permalink
Merge pull request #18 from CIDARLAB/feat/paper-compliance
Browse files Browse the repository at this point in the history
Feat/paper compliance
  • Loading branch information
0x174 authored Apr 9, 2021
2 parents 136a06b + 142b160 commit 82445ef
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 35 deletions.
100 changes: 68 additions & 32 deletions src/app/project/project.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,58 +21,94 @@ export class ProjectService {
this.apiService.getSettings().subscribe((data) => {
this.project.settings = data;
});
// this.project.name = "vava";
// this.apiService.getProjectResults("vava").subscribe((result) => {
// this.project.results = result.sort((a, b) => (a.name > b.name ? 1 : -1));
// });
}

// async submit() {
// return this.apiService.specify(this.project.getSpecification(), this.project.name);
// }

async alert(message: any) {
const alert = await this.alertController.create({
message: message,
message,
buttons: ['OK'],
});
return await alert.present();
}

async toast(message: string, color: string = '') {
const toast = await this.toastController.create({
message: message,
message,
position: 'bottom',
color: color,
color,
duration: 2000,
});
return await toast.present();
}

async validateProject() {
const { name, description, created, verilog, settings, library } = this.project;
const { input_constraints, output_constraints } = this.project.constraints;
let result = true;
if (verilog === undefined) {
Promise.resolve().then(() => {
this.toast('Input Verilog File not Found. ' + 'Please check Input Verilog File and resubmit.');
});
result = result && false;
}
if (!settings) {
Promise.resolve().then(() => {
this.toast('Input Settings File not Found. ' + 'Please check Input Settings File and resubmit.');
});
result = result && false;
}
if (!library) {
Promise.resolve().then(() => {
this.toast('Input Library File not Found. ' + 'Please check Input Library File and resubmit.');
});
result = result && false;
}
if (!input_constraints) {
Promise.resolve().then(() => {
this.toast('Input Constraints not Found. ' + 'Please validated UCF File and resubmit.');
});
result = result && false;
}
if (!output_constraints) {
Promise.resolve().then(() => {
this.toast('Output Constraints not Found. ' + 'Please validate UCF File and resubmit.');
});
result = result && false;
}
return result;
}

async submit() {
const name = this.project.name;
this.isLoading = true;
const loadingOverlay = await this.loadingController.create({});
return Promise.resolve()
.then(() => {
// let body = this.project.getSpecification();
this.toast('Submitting project. Results will appear after successful execution.');
const loading$ = from(loadingOverlay.present());
return this.apiService.createProject(this.project).toPromise();
})
.then(() => {
if (this.project.name == name) {
this.apiService.getProjectResults(name).subscribe((result) => {
this.project.results = result.sort((a, b) => (a.name > b.name ? 1 : -1));
});
this.isLoading = false;
loadingOverlay.dismiss();
this.toast('Project ' + name + ' finished successfully.', 'success');
}
})
.catch((error) => {
this.toastController.dismiss();
this.alert(error.error.message);
});
const validated = await this.validateProject();
if (validated) {
const timeoutPromise = new Promise((res) => setTimeout(() => res('timeoutPromise'), 30000));
const submissionPromise = Promise.resolve()
.then(() => {
// let body = this.project.getSpecification();
this.toast('Submitting project. Results will appear after successful execution.');
const loading$ = from(loadingOverlay.present());
return this.apiService.createProject(this.project).toPromise();
})
.then(() => {
if (this.project.name === name) {
this.apiService.getProjectResults(name).subscribe((result) => {
this.project.results = result.sort((a, b) => (a.name > b.name ? 1 : -1));
});
this.isLoading = false;
loadingOverlay.dismiss();
this.toast('Project ' + name + ' finished successfully.', 'success');
}
})
.catch((error) => {
this.toastController.dismiss();
this.alert(error.error.message);
});
return await Promise.race([timeoutPromise, submissionPromise]);
} else {
await loadingOverlay.dismiss();
}
}
}
26 changes: 23 additions & 3 deletions src/app/project/project/project.component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import { Component, OnInit } from '@angular/core';
import { ProjectService } from '../project.service';
import { AlertController, LoadingController } from '@ionic/angular';
import { AlertController, ToastController } from '@ionic/angular';

@Component({
selector: 'app-project',
templateUrl: './project.component.html',
styleUrls: ['./project.component.scss'],
})
export class ProjectComponent implements OnInit {
constructor(public projectService: ProjectService, private alertController: AlertController) {}
constructor(
public projectService: ProjectService,
private alertController: AlertController,
private toastController: ToastController
) {}

ngOnInit(): void {}

async toast(message: string, color: string = '') {
const toast = await this.toastController.create({
message,
position: 'bottom',
color,
duration: 2000,
});
return await toast.present();
}

async submit() {
const alert = await this.alertController.create({
header: 'Submit',
Expand All @@ -32,7 +46,13 @@ export class ProjectComponent implements OnInit {
handler: (data) => {
this.projectService.project.name = data.name;
this.projectService.project.description = data.description;
this.projectService.submit();
if (!this.projectService.project.name) {
this.toast('Project Name is Empty. Please fill out Project Name.');
} else if (!this.projectService.project.description) {
this.toast('Description Name is Empty. Please fill out Project Description.');
} else {
this.projectService.submit();
}
},
},
],
Expand Down

0 comments on commit 82445ef

Please sign in to comment.