Commit 4aa37ace authored by Alexander Philipp Nowosad's avatar Alexander Philipp Nowosad
Browse files

Add list wrapper to development methods

parent 895808e9
......@@ -31,16 +31,14 @@
Methods
</div>
<div class="my-3 p-3 bg-white rounded shadow-sm">
<h6 class="border-bottom border-gray pb-2">Method Building Blocks</h6>
<div *ngIf="!developmentMethodsList">Loading...</div>
<div *ngIf="developmentMethodsList && developmentMethodsList.length === 0">
No Method Building Blocks defined.
</div>
<ul
class="list-group"
*ngIf="developmentMethodsList && developmentMethodsList.length > 0"
>
<app-list-wrapper
listTitle="Method Building Blocks"
[reloading]="reloading"
[loading]="loading"
[noResults]="noResults"
>
<div noResults>No Method Building Blocks defined.</div>
<ul results class="list-group">
<li
class="
d-flex
......@@ -73,7 +71,7 @@
</div>
</li>
</ul>
</div>
</app-list-wrapper>
<div class="my-3 p-3 bg-white rounded shadow-sm">
<h6 class="border-bottom border-gray pb-2 mb-0">
......
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { DevelopmentMethod } from '../../development-process-registry/development-method/development-method';
import { DevelopmentMethodService } from '../../development-process-registry/development-method/development-method.service';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { ELEMENT_SERVICE, ListService } from '../../shared/list.service';
@Component({
selector: 'app-development-methods',
templateUrl: './development-methods.component.html',
styleUrls: ['./development-methods.component.css'],
providers: [
ListService,
{ provide: ELEMENT_SERVICE, useExisting: DevelopmentMethodService },
],
})
export class DevelopmentMethodsComponent implements OnInit {
developmentMethodsList: DevelopmentMethod[];
export class DevelopmentMethodsComponent {
developmentMethodForm = this.fb.group({
name: this.fb.control('', Validators.required),
});
......@@ -23,22 +26,11 @@ export class DevelopmentMethodsComponent implements OnInit {
deleteDevelopmentMethodModal: any;
constructor(
private developmentMethodService: DevelopmentMethodService,
private listService: ListService<DevelopmentMethod>,
private fb: FormBuilder,
private modalService: NgbModal
) {}
ngOnInit() {
this.loadDevelopmentMethods();
}
loadDevelopmentMethods() {
this.developmentMethodService
.getList()
.then((list) => (this.developmentMethodsList = list.docs))
.catch((error) => console.log('LoadDevelopmentMethods: ' + error));
}
openDeleteDevelopmentMethodModal(developmentMethod: DevelopmentMethod) {
this.modalDevelopmentMethod = developmentMethod;
this.modalReference = this.modalService.open(
......@@ -49,20 +41,28 @@ export class DevelopmentMethodsComponent implements OnInit {
);
}
deleteDevelopmentMethod(id: string) {
this.developmentMethodService
.delete(id)
.then(() => this.loadDevelopmentMethods())
.catch((error) => console.log('DeleteDevelopmentMethod: ' + error));
async deleteDevelopmentMethod(id: string) {
await this.listService.delete(id);
}
async addDevelopmentMethod(developmentMethodForm: FormGroup) {
await this.listService.add({ name: developmentMethodForm.value.name });
this.developmentMethodForm.reset();
}
get developmentMethodsList(): DevelopmentMethod[] {
return this.listService.elements;
}
get noResults(): boolean {
return this.listService.noResults;
}
get loading(): boolean {
return this.listService.loading;
}
addDevelopmentMethod(developmentMethodForm: FormGroup) {
this.developmentMethodService
.add({ name: developmentMethodForm.value.name })
.then(() => {
this.developmentMethodForm.reset();
this.loadDevelopmentMethods();
})
.catch((error) => console.log('AddDevelopmentMethod: ' + error));
get reloading(): boolean {
return this.listService.reloading;
}
}
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