-
Notifications
You must be signed in to change notification settings - Fork 6
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
13 changed files
with
212 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface GlobalSettings { | ||
projectAutoProvisioning: boolean | ||
} |
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,28 @@ | ||
import { HttpClient } from "@angular/common/http"; | ||
import { BehaviorSubject, Observable } from "rxjs"; | ||
import { GlobalSettings } from "./global-settings.model"; | ||
import { Injectable } from "@angular/core"; | ||
|
||
@Injectable({ | ||
providedIn: "root" | ||
}) | ||
export class GlobalSettingsService { | ||
|
||
private notification = new BehaviorSubject<any>({}); | ||
public notification$ = this.notification.asObservable(); | ||
|
||
constructor(private http: HttpClient) { | ||
} | ||
|
||
getGlobalSettings(): Observable<GlobalSettings> { | ||
return this.http.get<GlobalSettings>("global-settings"); | ||
} | ||
|
||
updateGlobalSettings(payload: GlobalSettings) { | ||
return this.http.put("global-settings", payload, { observe: "response" }); | ||
} | ||
|
||
setNotificationMessage(response) { | ||
this.notification.next(response); | ||
} | ||
} |
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
Empty file.
41 changes: 41 additions & 0 deletions
41
src/app/administration/global-settings/global-settings.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,41 @@ | ||
<div class="administration"> | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col"> | ||
<div class="card card-content card-shadow"> | ||
<h6 class="card-header bg-transparent">Settings <span class="inline-controller"></span></h6> | ||
|
||
<div class="card-body"> | ||
<div class="card-body"> | ||
<form [formGroup]="globalSettingsForm" (ngSubmit)="onSubmit()" class="pl-3" *ngIf="globalSettingsForm"> | ||
|
||
<div class="form-sub"> | ||
<h6>Project auto-provisioning</h6> | ||
<div class="text-secondary mb-2"><i class="fas fa-info-circle"> </i> | ||
<small> When pushing a test report into a project that does not exist, the application will create | ||
a project and a scenario on the fly.</small></div> | ||
<div class="form-group"> | ||
<div class="custom-control custom-switch"> | ||
<input type="checkbox" class="custom-control-input" id="projectAutoProvisioning" | ||
formControlName="projectAutoProvisioning"> | ||
<label class="custom-control-label" for="projectAutoProvisioning">Project auto-provisioning</label> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<button type="submit" *userRole="'admin'" class="btn btn-primary">Submit</button> | ||
</div> | ||
</form> | ||
|
||
|
||
|
||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
|
35 changes: 35 additions & 0 deletions
35
src/app/administration/global-settings/global-settings.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,35 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
|
||
import { GlobalSettingsComponent } from "./global-settings.component"; | ||
import { RouterTestingModule } from "@angular/router/testing"; | ||
import { ReactiveFormsModule } from "@angular/forms"; | ||
import { HTTP_INTERCEPTORS, HttpClientModule } from "@angular/common/http"; | ||
import { HttpRequestInterceptorMock } from "../../_interceptors/mock-interceptor"; | ||
|
||
describe("GlobalSettingsComponent", () => { | ||
let component: GlobalSettingsComponent; | ||
let fixture: ComponentFixture<GlobalSettingsComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [RouterTestingModule, ReactiveFormsModule, HttpClientModule], | ||
declarations: [ GlobalSettingsComponent ], | ||
providers: [{ | ||
provide: HTTP_INTERCEPTORS, | ||
useClass: HttpRequestInterceptorMock, | ||
multi: true | ||
}] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(GlobalSettingsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
src/app/administration/global-settings/global-settings.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,60 @@ | ||
import { Component, OnInit } from "@angular/core"; | ||
import { FormControl, FormGroup } from "@angular/forms"; | ||
import { GlobalSettingsService } from "../../_services/global-settings.service"; | ||
import { GlobalSettings } from "../../_services/global-settings.model"; | ||
import { catchError } from "rxjs/operators"; | ||
import { of } from "rxjs"; | ||
import { NotificationMessage } from "../../notification/notification-messages"; | ||
|
||
@Component({ | ||
selector: "app-global-settings", | ||
templateUrl: "./global-settings.component.html", | ||
styleUrls: ["./global-settings.component.css", "../administration.css", "../../shared-styles.css"] | ||
}) | ||
export class GlobalSettingsComponent implements OnInit { | ||
globalSettingsForm: FormGroup; | ||
|
||
formControls = { | ||
projectAutoProvisioning: null | ||
} | ||
|
||
constructor( | ||
private globalSettingsService: GlobalSettingsService, | ||
private notification: NotificationMessage, | ||
) { | ||
} | ||
|
||
ngOnInit(): void { | ||
this.globalSettingsService.getGlobalSettings().subscribe((body) => { | ||
this.createFormControls(body); | ||
this.createForm(); | ||
}) | ||
|
||
} | ||
|
||
onSubmit() { | ||
console.log(this.globalSettingsForm.valid) | ||
if (this.globalSettingsForm.valid) { | ||
const { projectAutoProvisioning } = this.globalSettingsForm.value | ||
this.globalSettingsService.updateGlobalSettings({ projectAutoProvisioning }) | ||
.pipe(catchError(r => of(r))) | ||
.subscribe(_ => { | ||
const message = this.notification.globalSettingsNotification(_); | ||
this.globalSettingsService.setNotificationMessage(message) | ||
}) | ||
} | ||
} | ||
|
||
private createFormControls(settings: GlobalSettings) { | ||
this.formControls.projectAutoProvisioning = new FormControl(settings.projectAutoProvisioning, []); | ||
} | ||
|
||
private createForm() { | ||
this.globalSettingsForm = new FormGroup({ | ||
projectAutoProvisioning: this.formControls.projectAutoProvisioning | ||
}) | ||
} | ||
|
||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/app/administration/global-settings/global-settings.module.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,25 @@ | ||
import { NgModule } from "@angular/core"; | ||
import { CommonModule } from "@angular/common"; | ||
import { SharedModule } from "../../shared/shared.module"; | ||
import { ReactiveFormsModule } from "@angular/forms"; | ||
import { GlobalSettingsComponent } from "./global-settings.component"; | ||
import { RouterModule, Routes } from "@angular/router"; | ||
import { AuthGuard } from "../../auth.guard"; | ||
import { AddUserModule } from "../users/add-user/add-user.module"; | ||
import { DeleteUserModule } from "../users/delete-user/delete-user.module"; | ||
import { RoleModule } from "../../_directives/role.module"; | ||
|
||
|
||
const routes: Routes = [ | ||
{ path: "administration/global-settings", component: GlobalSettingsComponent, canActivate: [AuthGuard] }, | ||
]; | ||
|
||
@NgModule({ | ||
declarations: [GlobalSettingsComponent], | ||
imports: [ | ||
CommonModule, RouterModule.forRoot(routes), SharedModule, ReactiveFormsModule, AddUserModule, DeleteUserModule, RoleModule | ||
], | ||
exports: [GlobalSettingsComponent] | ||
}) | ||
export class GlobalSettingsModule { | ||
} |
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