Commit 586ef6df authored by Smejky338's avatar Smejky338
Browse files

feat: add assignment list, create link, cancel edit button

parent 7218b10c
Pipeline #142437 waiting for manual action with stage
......@@ -22,6 +22,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
/**
* @author Jan Smejkal
......@@ -76,6 +79,15 @@ public class AssignmentController {
assignmentService.deleteById(id);
}
@GetMapping()
public List<AgentAssignmentDTO> getAllAssignments() {
logger.debug("rest GET all assignments");
List<AgentAssignment> assignments = assignmentService.findAll();
// return assignments.map(value -> beanMappingService.map(value, AgentAssignmentDTO.class)).orElse(null);
return StreamSupport.stream(assignments.spliterator(), false)
.map(o -> beanMappingService.map(o, AgentAssignmentDTO.class)).collect(Collectors.toList());
}
@GetMapping("/{id}")
public AgentAssignmentDTO getDetail(@PathVariable("id") String id) {
logger.debug("rest GET detail for id=" + id);
......
......@@ -3,6 +3,7 @@ package cz.fi.muni.pa165.seminar4.group7.agent_assignment;
import cz.fi.muni.pa165.seminar4.group7.entity.AgentAssignment;
import cz.fi.muni.pa165.seminar4.group7.entity.PerformanceEvaluation;
import java.util.List;
import java.util.Optional;
/**
......@@ -83,4 +84,10 @@ public interface AgentAssignmentService {
*/
Iterable<AgentAssignment> getAssignmentsByMissionId(String id);
/**
* Returns all agent assignments, no matter the mission or agent.
*
* @return assignments - iterable of all agent assignments.
*/
List<AgentAssignment> findAll();
}
......@@ -109,4 +109,9 @@ public class AgentAssignmentServiceImpl implements AgentAssignmentService {
return mission.get().getAgentAssignments();
}
@Override
public List<AgentAssignment> findAll() {
return (List<AgentAssignment>) assignmentDao.findAll();
}
}
......@@ -4,6 +4,7 @@ import { AgentDetailComponent } from './agent/agent-detail.component';
import { AgentListComponent } from './agent/agent-list.component';
import { AssignmentCreateComponent } from './assignment/assignment-create.component';
import { AssignmentDetailComponent } from './assignment/assignment-detail.component';
import { AssignmentListComponent } from './assignment/assignment-list.component';
import { AgentDetailGuard } from './auth/agent-detail.guard';
import { AgentListGuard } from './auth/agent-list.guard';
import { AuthComponent } from './auth/auth.component';
......@@ -30,6 +31,7 @@ const routes: Routes = [
},
{ path: 'assignment/create', component: AssignmentCreateComponent },
{ path: 'assignment/:id', component: AssignmentDetailComponent },
{ path: 'assignments', component: AssignmentListComponent },
{ path: 'agents', component: AgentListComponent ,
canActivate: [AgentListGuard],
},
......
......@@ -29,6 +29,7 @@ import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatNativeDateModule } from "@angular/material/core";
import { MatToolbarModule } from "@angular/material/toolbar";
import { NotFoundComponent } from './not-found.component';
import {AssignmentListComponent} from "./assignment/assignment-list.component";
@NgModule({
declarations: [
......@@ -44,6 +45,7 @@ import { NotFoundComponent } from './not-found.component';
NotFoundComponent,
AssignmentDetailComponent,
AssignmentCreateComponent,
AssignmentListComponent,
LoginComponent,
],
......
......@@ -12,16 +12,18 @@
<mat-label>Duration (days):</mat-label>
<input matInput [disabled]="!editing" [(ngModel)]="assignment.durationInDays" type="number" min="0"/>
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>Agent's name:</mat-label>
<input matInput [disabled]="true" [(ngModel)]="assignment.agent.name" />
</mat-form-field>
<div routerLink="../agent/{{ assignment.agent.id }}">
<mat-form-field appearance="fill">
<mat-label>Agent's name:</mat-label>
<input matInput [disabled]="true" [(ngModel)]="assignment.agent.name" />
</mat-form-field>
</div>
<mat-form-field appearance="fill">
<mat-label>Mission:</mat-label>
<input matInput [disabled]="true" [(ngModel)]="assignment.mission.name" />
</mat-form-field>
</div>
<div *ngIf="assignment && state === requestState.SUCCESS">
<div *ngIf="assignment && state === requestState.SUCCESS" class="w-full">
<mat-form-field appearance="fill" >
<mat-label>Agent's report:</mat-label>
<textarea matInput placeholder="Agent's report" [(ngModel)]="assignment.report" [disabled]="!editing"></textarea>
......@@ -31,7 +33,11 @@
<div>
<section>
<button mat-raised-button *ngIf="!editing" (click)="setEditing(true)">Edit</button>
<button mat-raised-button *ngIf="editing" (click)="setEditing(false); saveAssignment()">Save</button>
<button mat-raised-button *ngIf="editing" (click)="setEditing(false); saveAssignment();">Save</button>
<button mat-raised-button *ngIf="editing" (click)="setEditing(false); loadAssignment();">Cancel</button>
</section>
<section>
<button mat-raised-button (click)="deleteAssignment()">Delete</button>
</section>
</div>
......@@ -73,7 +73,21 @@ export class AssignmentDetailComponent implements OnInit {
)
);
this.state = RequestState.SUCCESS;
await this.router.navigate(['/']);
await this.router.navigate(['/auth']);
} catch (err) {
this.state = RequestState.ERROR;
throw err;
}
}
async loadAssignment() {
try {
this.state = RequestState.PENDING;
this.assignment = await firstValueFrom(
this.httpClient.get<Assignment>(`${environment.apiUrl}/assignments/${this.id}`)
);
this.state = RequestState.SUCCESS;
} catch (err) {
this.state = RequestState.ERROR;
throw err;
......
<div *ngIf="state === requestState.ERROR">
Error showing assignment detail: {{ errorMessage }}
</div>
<button mat-raised-button routerLink="../assignment/create">Create new assignment</button>
<div *ngIf="assignments && state === requestState.SUCCESS">
Assignments:
<table mat-table [dataSource]="assignments" class="w-full">
<ng-container matColumnDef="start">
<th mat-header-cell *matHeaderCellDef>Start date</th>
<td mat-cell *matCellDef="let assignment">
{{ assignment.start }}
</td>
</ng-container>
<ng-container matColumnDef="durationInDays">
<th mat-header-cell *matHeaderCellDef>Duration (days):</th>
<td mat-cell *matCellDef="let assignment">
{{ assignment.durationInDays }}
</td>
</ng-container>
<ng-container matColumnDef="mission">
<th mat-header-cell *matHeaderCellDef>Mission:</th>
<td mat-cell *matCellDef="let assignment">
{{ assignment.mission.name }}
</td>
</ng-container>
<ng-container matColumnDef="agent">
<th mat-header-cell *matHeaderCellDef>Agent:</th>
<td mat-cell *matCellDef="let assignment">
{{ assignment.agent.name }}
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr
mat-row
class="hover:bg-gray-200"
routerLink="../mission/{{ row.id }}"
*matRowDef="let row; columns: displayedColumns"
></tr>
</table>
</div>
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { firstValueFrom } from 'rxjs';
import { environment } from 'src/environments/environment';
import { RequestState } from '../request-state.enum';
import { Assignment } from './assignment.interface';
@Component({
selector: 'assignment-list',
templateUrl: 'assignment-list.component.html',
})
export class AssignmentListComponent implements OnInit {
requestState = RequestState;
state: RequestState = this.requestState.PENDING;
errorMessage = '';
assignments: Assignment[] = [];
displayedColumns: string[] = ['start', 'durationInDays', 'mission', 'agent'];
constructor(private httpClient: HttpClient) {}
async ngOnInit() {
try {
this.state = RequestState.PENDING;
this.assignments = await firstValueFrom(
this.httpClient.get<Assignment[]>(`${environment.apiUrl}/assignments/`)
);
this.state = RequestState.SUCCESS;
} catch (err) {
this.state = RequestState.ERROR;
this.errorMessage = 'Could not load assignments!';
throw err;
}
}
}
......@@ -25,4 +25,11 @@
>
Countries
</button>
<button
*ngIf="hasRole(agentRole.ADMIN) || hasRole(agentRole.SUPERVISOR)"
class="border-b-[1px] border-gray-200 w-full py-4 text-xl"
routerLink="assignments"
>
Agent Assignments
</button>
</div>
Supports Markdown
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