Skip to content

Commit

Permalink
chore: display function revision information
Browse files Browse the repository at this point in the history
  • Loading branch information
llorentelemmc committed Oct 14, 2024
1 parent dfd94c7 commit ce7dea4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ <h5 class="modal-title" id="editFunctionTitle">{{ getTitle() }}</h5>
}"
></ngx-codemirror>
</div>
<div class="mb-3">
<label class="form-label">Compare with history</label>
<div ngbDropdown>
<button class="btn btn-secondary dropdown-toggle" id="revisionDropdown" ngbDropdownToggle>
Select Revision
</button>
<ul ngbDropdownMenu aria-labelledby="revisionDropdown">
<li ngbDropdownItem *ngFor="let revision of revisions">
<a class="dropdown-item">{{ revision.displayName ?? 'Unnamed Revision' }}</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="modal-footer">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import { Component, EventEmitter, inject, Input, Output } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { CommonModule } from '@angular/common';
import { AppFunction } from './appFunction';
import { CodemirrorModule } from '@ctrl/ngx-codemirror';
import { FunctionsService } from './functions.service';
import {RevisionInformation} from "./revisionInformation";
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';

@Component({
selector: 'amw-function-edit',
templateUrl: './function-edit.component.html',
standalone: true,
imports: [FormsModule, CodemirrorModule],
imports: [FormsModule, CodemirrorModule, CommonModule, NgbDropdownModule],
})
export class FunctionEditComponent {
@Input() function: AppFunction;
@Input() canManage: boolean;
@Output() saveFunction: EventEmitter<AppFunction> = new EventEmitter<AppFunction>();

private functionsService = inject(FunctionsService);
public revisions: RevisionInformation[]= [];

constructor(public activeModal: NgbActiveModal) {}

ngOnInit(): void {
this.loadRevisions(this.function.id);
}

getTitle(): string {
return this.function.id ? 'Edit function' : 'Add function';
}
Expand All @@ -33,4 +41,13 @@ export class FunctionEditComponent {
this.saveFunction.emit(this.function);
this.activeModal.close();
}

loadRevisions(functionId: number): void {
this.functionsService.getFunctionRevisions(functionId).subscribe(revisions => {
console.log('Revisions received from API:', revisions); // Debugging the data
this.revisions = revisions; // Ensure the revisions are set correctly
console.log('Revisions in component:', this.revisions); // Log after setting to ensure it's correct
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppFunction } from './appFunction';
import { Observable, startWith, Subject } from 'rxjs';
import { toSignal } from '@angular/core/rxjs-interop';
import { shareReplay, switchMap } from 'rxjs/operators';
import {RevisionInformation} from "./revisionInformation";

@Injectable({ providedIn: 'root' })
export class FunctionsService extends BaseService {
Expand All @@ -31,10 +32,15 @@ export class FunctionsService extends BaseService {
modifyFunction(newFunction: AppFunction): Observable<void> {
return this.http.put<void>(`${this.getBaseUrl()}/functions`, newFunction);
}

deleteFunction(id: number): Observable<void> {
return this.http.delete<void>(`${this.getBaseUrl()}/functions/${id}`);
}

getFunctionRevisions(id: number): Observable<RevisionInformation[]> {
return this.http.get<RevisionInformation[]>(`${this.getBaseUrl()}/functions/${id}/revisions`);
}

refreshData() {
this.reload$.next([]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface RevisionInformation {
revision: number;
revisionDate: number;
userName: string;
displayName: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ch.puzzle.itc.mobiliar.business.globalfunction.boundary.GlobalFunctionsBoundary;
import ch.puzzle.itc.mobiliar.business.globalfunction.entity.GlobalFunctionEntity;
import ch.puzzle.itc.mobiliar.business.template.entity.RevisionInformation;
import ch.puzzle.itc.mobiliar.common.exception.NotFoundException;
import ch.puzzle.itc.mobiliar.common.exception.ValidationException;
import io.swagger.annotations.Api;
Expand Down Expand Up @@ -71,4 +72,14 @@ public Response deleteGlobalFunction(@PathParam("id") int id) throws NotFoundExc
globalFunctionsBoundary.deleteGlobalFunction(id);
return Response.status(Response.Status.NO_CONTENT).build();
}

@GET
@Path("/{id}/revisions")
@ApiOperation(value = "Get all revisions of a specific function")
public Response getFunctionRevisions(@PathParam("id") int id) {
// returns empty array if nothing is found; change this behaviour
// NotFoundException?
List<RevisionInformation> revisions = globalFunctionsBoundary.getFunctionRevisions(id);
return Response.ok(revisions).build();
}
}

0 comments on commit ce7dea4

Please sign in to comment.