Commit e2391727 authored by Simone Vuotto's avatar Simone Vuotto

Add requirements translation download

parent 6f9849b3
......@@ -2858,6 +2858,11 @@
"schema-utils": "0.3.0"
}
},
"file-saver": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-1.3.3.tgz",
"integrity": "sha1-zdTETTqiZOrC9o7BZbx5HDSvEjI="
},
"filename-regex": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz",
......
......@@ -25,6 +25,7 @@
"bootstrap": "^3.3.7",
"bootswatch": "^4.0.0-beta.2",
"core-js": "^2.4.1",
"file-saver": "^1.3.3",
"font-awesome": "^4.7.0",
"jquery": "^3.2.1",
"rxjs": "^5.5.2",
......
<div class="row top-container">
<div class="col-md-9">
<div class="col-md-8">
<h1 *ngIf="project != null">{{ project.name }}</h1>
</div>
<div class="col-md-3">
<div class="col-md-4">
<div class="hidden"><input type="file" #fileInput (change)="fileChange($event)"/></div>
<button type="button" class="btn btn-primary pull-right btn-top" (click)="fileInput.click()"
[disabled]="uploadLoading">
......@@ -11,7 +11,14 @@
&nbsp;Upload File
</button>
<button type="button" class="btn btn-primary pull-right btn-top">
<i class="fa fa-play" aria-hidden="true"></i>&nbsp;Validate</button>
<i class="fa fa-play" aria-hidden="true"></i>
&nbsp;Validate
</button>
<button type="button" class="btn btn-primary pull-right btn-top" [disabled]="translateLoading" (click)="getTranslation()">
<i class="fa fa-download" aria-hidden="true" *ngIf="!translateLoading"></i>
<i class='fa fa-spinner fa-spin' *ngIf="translateLoading"></i>
&nbsp;Translate
</button>
</div>
</div>
......
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Project } from '../models/project';
import { ReqState, Requirement } from '../models/requirement';
import { Requirement } from '../models/requirement';
import { ProjectService } from '../services/project.service';
import { RequirementService } from '../services/requirement.service';
import { AlertService } from '../alert/alert.service';
import { errorObject } from 'rxjs/util/errorObject';
import { saveAs } from 'file-saver/FileSaver';
@Component({
......@@ -20,6 +21,7 @@ export class ProjectDetailsComponent implements OnInit {
requirements: Requirement[];
uploadLoading = false;
translateLoading = false;
selectedRequirement = new Requirement();
constructor(private route: ActivatedRoute,
......@@ -75,4 +77,20 @@ export class ProjectDetailsComponent implements OnInit {
}
}
getTranslation() {
this.translateLoading = true;
this.requirementService.getTranslation(this.projectId).subscribe(
response => {
const blob = new Blob([response.body], { type: 'text/plain;charset=utf-8' });
saveAs(blob, 'output.nusmv');
this.translateLoading = false;
},
error => {
this.alertService.error(error);
console.log(error);
this.translateLoading = false;
}
);
}
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { Requirement } from '../models/requirement';
import { Observable } from 'rxjs/Observable';
......@@ -8,6 +8,7 @@ export class RequirementService {
private requirementsUrl = 'api/requirements';
private reqFileUrl = 'api/requirements/file';
private reqTranslateUrl = 'api/requirements/translate';
constructor(private http: HttpClient) { }
......@@ -32,4 +33,11 @@ export class RequirementService {
}
getTranslation(projectId: number): Observable<HttpResponse<Blob>> {
const params = new HttpParams().set('pId', projectId.toString());
const options = {params: params, observe: 'response' as 'response', responseType: 'blob' as 'blob'};
return this.http.get(this.reqTranslateUrl, options);
}
}
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