-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
290 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
AMW_angular/io/src/app/resources/resource-add/resource-add.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<div class="container"> | ||
<app-modal-header [title]="getTitle()" (cancel)="cancel()"></app-modal-header> | ||
<div class="modal-body"> | ||
<div class="needs-validation mb-3"> | ||
<label for="resourceName" class="form-label">Resource name</label> | ||
<input type="text" class="form-control" id="resourceName" | ||
[(ngModel)]="resourceName" required | ||
pattern="^[a-zA-Z0-9_\-]+$"/> | ||
<div class="invalid-feedback"> | ||
The name must not contain any other than alphanumerical and "_" / "-" characters. | ||
</div> | ||
</div> | ||
<div class="mb-3"> | ||
<label class="form-label">Release</label> | ||
<ng-select id="selectRelease" | ||
[clearable]="false" | ||
[(ngModel)]="selectedReleaseName" | ||
(change)="setSelectedRelease($event)"> | ||
@for (release of releases; track release.id) { | ||
<ng-option [value]="release.name">{{ release.name }}</ng-option> | ||
} | ||
</ng-select> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<app-button [variant]="'light'" (click)="cancel()">Cancel</app-button> | ||
<app-button [variant]="'primary'" | ||
[disabled]="!isValidForm()" | ||
(click)="save()">Save | ||
</app-button> | ||
</div> | ||
</div> |
23 changes: 23 additions & 0 deletions
23
AMW_angular/io/src/app/resources/resource-add/resource-add.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { ResourceAddComponent } from './resource-add.component'; | ||
|
||
describe('ResourceAddComponent', () => { | ||
let component: ResourceAddComponent; | ||
let fixture: ComponentFixture<ResourceAddComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ResourceAddComponent], | ||
providers: [NgbActiveModal], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ResourceAddComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
AMW_angular/io/src/app/resources/resource-add/resource-add.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ChangeDetectionStrategy, Component, EventEmitter, inject, Input, Output } from '@angular/core'; | ||
import { NgbActiveModal, NgbTypeahead } from '@ng-bootstrap/ng-bootstrap'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { ModalHeaderComponent } from '../../shared/modal-header/modal-header.component'; | ||
import { ButtonComponent } from '../../shared/button/button.component'; | ||
import { ResourceType } from '../../resource/resource-type'; | ||
import { Release } from '../../settings/releases/release'; | ||
import { NgSelectModule } from '@ng-select/ng-select'; | ||
|
||
@Component({ | ||
selector: 'app-resource-add', | ||
standalone: true, | ||
imports: [FormsModule, ModalHeaderComponent, ButtonComponent, NgbTypeahead, NgSelectModule], | ||
templateUrl: './resource-add.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ResourceAddComponent { | ||
activeModal = inject(NgbActiveModal); | ||
@Input() resourceType: ResourceType; | ||
@Input() releases: Release[]; | ||
@Input() selectedReleaseName: Release; | ||
resourceName: string; | ||
@Output() saveResource: EventEmitter<any> = new EventEmitter<any>(); | ||
|
||
getTitle() { | ||
if (!this.resourceType) return; | ||
return this.resourceType.name ? `Create new instance for ${this.resourceType.name}` : `Create new instance`; | ||
} | ||
|
||
save() { | ||
let forms: NodeListOf<Element> = document.querySelectorAll('.needs-validation'); | ||
if (this.isValidForm()) { | ||
const resourceToAdd = { | ||
name: this.resourceName, | ||
type: this.resourceType.name, | ||
releaseName: this.selectedReleaseName, | ||
}; | ||
this.saveResource.emit(resourceToAdd); | ||
this.activeModal.close(); | ||
} else { | ||
forms[0].classList.add('was-validated'); | ||
} | ||
} | ||
|
||
cancel() { | ||
this.activeModal.close(); | ||
} | ||
|
||
setSelectedRelease($event: any) { | ||
this.selectedReleaseName = $event; | ||
} | ||
|
||
isValidForm() { | ||
const REGEXP_ALPHANUMERIC_WITH_UNDERSCORE_HYPHEN = /^[a-zA-Z0-9_-]+$/; | ||
return this.resourceName ? REGEXP_ALPHANUMERIC_WITH_UNDERSCORE_HYPHEN.test(this.resourceName) : false; | ||
} | ||
} |
13 changes: 11 additions & 2 deletions
13
AMW_angular/io/src/app/resources/resources-list/resources-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.