Commit f5c6ca1c authored by Simone Vuotto's avatar Simone Vuotto

Update task component

parent a651f523
......@@ -4,8 +4,9 @@
<i class='fa fa-spinner fa-spin' *ngIf="translateLoading"></i>
&nbsp;Translate
</button>
<button type="button" class="btn btn-primary pull-right" [disabled]="!taskIsRunning" (click)="consistencyCheck()">
<i class="fa fa-play" aria-hidden="true"></i>
<button type="button" class="btn btn-primary pull-right" [disabled]="taskIsRunning" (click)="consistencyCheck()">
<i class="fa fa-play" aria-hidden="true" *ngIf="!validateLoading"></i>
<i class='fa fa-spinner fa-spin' *ngIf="validateLoading"></i>
&nbsp;Validate
</button>
</div>
......@@ -26,9 +27,12 @@
<div class="card-text">
<div>
<label >Logs:</label>
<textarea class="form-control" readonly="readonly">{{task.log}}</textarea>
<textarea class="form-control" readonly="readonly" rows="5">{{task.log}}</textarea>
</div>
<div *ngIf="task.id === tasks[0].id && task.fail" style="padding-top: 10px">
<a href="javascript:void(0);" (click)="computeMUC();">Click here</a> if you want to search for the minimum unsatisfiable core of
requirements (Warning: it may take a long time).
</div>
</div>
</div>
</div>
......
......@@ -15,6 +15,7 @@ export class TasksTabComponent implements OnInit {
tasks: Task[];
translateLoading = false;
validateLoading = false;
taskIsRunning = false;
constructor(private taskService: TaskService,
......@@ -28,7 +29,7 @@ export class TasksTabComponent implements OnInit {
this.taskService.getTasks(this.projectId).subscribe(
tasks => {
this.tasks = tasks.map(t => new Task(t));
this.taskIsRunning = this.tasks.every(t => !t.running);
this.taskIsRunning = !this.tasks.every(t => !t.running);
this.tasks.forEach(task => {
if (task.running) {
this.checkRunningTask(task);
......@@ -55,28 +56,57 @@ export class TasksTabComponent implements OnInit {
consistencyCheck() {
this.taskIsRunning = true;
this.validateLoading = true;
this.taskService.performConsistencyCheck(this.projectId).subscribe(
task => {
this.tasks.unshift(new Task(task));
this.checkRunningTask(task);
this.validateLoading = false;
},
error => {
this.alertService.error(error.message);
this.taskIsRunning = false;
this.validateLoading = false;
}
);
}
checkRunningTask(task: Task) {
checkRunningTask(task: Task, timeout = 2500) {
setTimeout(() => {
this.taskService.getTask(this.projectId, task.id).subscribe(
t => {
task = new Task(t);
response => {
task = new Task(response);
const index = this.tasks.findIndex( t => t.id === task.id);
this.tasks[index] = task;
if (task.running) {
this.checkRunningTask(task);
this.checkRunningTask(task, timeout);
} else {
const index = this.tasks.findIndex( x => x.id === task.id);
this.tasks[index] = task;
this.taskIsRunning = false;
}
},
error => {
console.log(error);
this.taskIsRunning = false;
}
);
}, 2500);
}, timeout);
}
computeMUC() {
this.taskIsRunning = true;
this.validateLoading = true;
this.taskService.performComputeMuc(this.projectId).subscribe(
task => {
this.tasks.unshift(new Task(task));
this.checkRunningTask(task, 5000);
this.validateLoading = false;
},
error => {
this.alertService.error(error.message);
this.taskIsRunning = false;
this.validateLoading = false;
}
);
}
}
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