Permalink
Browse files

Merge branch 'develop' into feature/fixSecurityWarnings

  • Loading branch information...
bwollmer committed Jan 11, 2019
2 parents 8cd9cfa + 9289952 commit e03f86f80c4b75a544e0c833fd2944654c31c2f9
@@ -13,6 +13,7 @@ import {CsiValueBaseComponent} from "../shared/components/csi-value/csi-value-ba
import {CsiValueMediumComponent} from "../shared/components/csi-value/csi-value-medium/csi-value-medium.component";
import {ApplicationJobStatusComponent} from "./components/application-job-status/application-job-status.component";
import {GraphiteIntegrationComponent} from "./components/application-job-status/graphite-integration/graphite-integration.component";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";

describe('ApplicationDashboardComponent', () => {
let component: ApplicationDashboardComponent;
@@ -21,7 +22,9 @@ describe('ApplicationDashboardComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
SharedMocksModule
SharedMocksModule,
FormsModule,
ReactiveFormsModule
],
declarations: [
ApplicationDashboardComponent,
@@ -10,6 +10,7 @@ import {SharedModule} from "../shared/shared.module";
import {HttpClientModule} from "@angular/common/http";
import { ApplicationJobStatusComponent } from './components/application-job-status/application-job-status.component';
import {GraphiteIntegrationComponent} from "./components/application-job-status/graphite-integration/graphite-integration.component";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";

const DashboardRoutes: Routes = [
{path: '', component: ApplicationDashboardComponent},
@@ -20,7 +21,9 @@ const DashboardRoutes: Routes = [
imports: [
RouterModule.forChild(DashboardRoutes),
SharedModule,
HttpClientModule
HttpClientModule,
ReactiveFormsModule,
FormsModule
],
declarations: [
ApplicationDashboardComponent,
@@ -7,6 +7,7 @@ import {Application} from "../../../../models/application.model";
import {FailingJobStatistic} from "../../models/failing-job-statistic.model";
import {GraphiteIntegrationComponent} from "./graphite-integration/graphite-integration.component";
import {GrailsBridgeService} from "../../../../services/grails-bridge.service";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";

describe('ApplicationJobStatusComponent', () => {
let component: ApplicationJobStatusComponent;
@@ -32,7 +33,9 @@ describe('ApplicationJobStatusComponent', () => {
GraphiteIntegrationComponent
],
imports: [
SharedMocksModule
SharedMocksModule,
FormsModule,
ReactiveFormsModule
],
providers: [
ApplicationService,
@@ -61,6 +61,13 @@ <h2>{{ 'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegrat
</section>

<section class="server-detail">
<button *ngIf="!showCreateSection" class="btn btn-primary" (click)="showCreationSection()">
{{'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.addServer' | translate}}
</button>
<h2 *ngIf="showCreateSection">
{{'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.addServerTitle' | translate}}
</h2>

<table *ngIf="selectedGraphiteServer">
<tr>
<td>Graphite Server Address</td>
@@ -83,6 +90,70 @@ <h2>{{ 'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegrat
<td>{{selectedGraphiteServer.prefix ? selectedGraphiteServer.prefix : "no prefix"}}</td>
</tr>
</table>

<form [formGroup]="createServerForm" *ngIf="showCreateSection && !selectedGraphiteServer" class="graphite-form-group">
<table>
<tr>
<td>
{{'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.address' | translate}}
<span class="required-dot">*</span>
</td>
<td>
<input type="url" class="form-control"
placeholder="{{'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.address' | translate}}"
formControlName="address">
</td>
</tr>
<tr>
<td>
{{'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.port' | translate}}
<span class="required-dot">*</span>
</td>
<td>
<input type="number" class="form-control" placeholder="2003"
formControlName="port">
</td>
</tr>
<tr>
<td>
{{'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.protocol' | translate}}
<span class="required-dot">*</span>
</td>
<td>
<input type="text" class="form-control" placeholder="TCP"
formControlName="protocol">
</td>
</tr>
<tr>
<td>
{{'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.webAppAddress' | translate}}
<span class="required-dot">*</span>
</td>
<td>
<input type="url" class="form-control"
placeholder="{{'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.webAppAddress' | translate}}"
formControlName="webAppAddress">
</td>
</tr>
<tr>
<td>{{'frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.prefix' | translate}}</td>
<td>
<input type="text" class="form-control" placeholder="jobstatus"
formControlName="prefix">
</td>
</tr>
<tr>
<td></td>
<td>
<div class="creation-buttons">
<button type="reset" class="btn btn-default" (click)="cancelCreation()">{{'frontend.default.button.cancel' | translate}}</button>
<button type="submit" class="btn btn-primary" (click)="create()"
[disabled]="!allFormsFilled()">{{'frontend.default.button.save' | translate}}</button>
</div>
</td>
</tr>
</table>
</form>
</section>

</main>
@@ -104,4 +104,22 @@ ngx-smart-modal {
margin: 0 10px;
}
}
.creation-buttons {
display: flex;
button {
flex-basis: 50%;
&:first-child {
margin-right: 5px;
}
&:last-child {
margin-left: 5px;
}
}
}
.graphite-form-group input {
text-align: left;
}
.required-dot {
color: darkred;
}
}
@@ -8,6 +8,7 @@ import {GlobalOsmNamespace} from "../../../../../models/global-osm-namespace.mod
import {SharedModule} from "../../../../shared/shared.module";
import {NgxSmartModalService} from "ngx-smart-modal";
import {By} from "@angular/platform-browser";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";

describe('GraphiteIntegrationComponent', () => {
let component: GraphiteIntegrationComponent;
@@ -20,7 +21,9 @@ describe('GraphiteIntegrationComponent', () => {
declarations: [ GraphiteIntegrationComponent ],
imports: [
SharedMocksModule,
SharedModule
SharedModule,
FormsModule,
ReactiveFormsModule
],
providers: [
ApplicationService,
@@ -59,6 +62,7 @@ describe('GraphiteIntegrationComponent', () => {
expect(modalContent.innerText).toMatch("frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.modalTitle\n" +
"frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.select\n" +
"frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.select.noneAvailable\n" +
"frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.addServer\n" +
"frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.footerTop\n" +
"frontend.de.iteratec.osm.applicationDashboard.jobStatus.graphiteIntegration.footerBottom\n" +
"frontend.default.button.savefrontend.default.button.cancel");
@@ -231,6 +235,27 @@ describe('GraphiteIntegrationComponent', () => {
expect(component.jobHealthGraphiteServers[0].id).toBe(1);
});

it("should create Server from FormControl", () => {
component.createServerForm.get("webAppAddress").setValue("app.iteratec");
component.createServerForm.get("address").setValue("test.iteratec");
component.createServerForm.get("prefix").setValue("jobstatus");
component.createServerForm.get("port").setValue(2003);
component.createServerForm.get("protocol").setValue("TCP");
spyOn(applicationService, "createGraphiteServer");
fixture.detectChanges();

component.create();
fixture.detectChanges();

expect(applicationService.createGraphiteServer).toHaveBeenCalledWith({
address: "test.iteratec",
id: null,
port : 2003,
prefix : "jobstatus",
protocol : "TCP",
webAppAddress : "app.iteratec"
});
});
});

class MockGrailsBridgeService extends GrailsBridgeService {
@@ -4,6 +4,9 @@ import {GraphiteServer} from "../../../models/graphite-server.model";
import {ApplicationService} from "../../../../../services/application.service";
import {Application} from "../../../../../models/application.model";
import {GrailsBridgeService} from "../../../../../services/grails-bridge.service";
import {FormGroup, FormControl} from "@angular/forms";
import {switchMap} from "rxjs/operators";
import {Observable} from "rxjs";

@Component({
selector: 'osm-graphite-integration',
@@ -22,7 +25,11 @@ export class GraphiteIntegrationComponent {

selectedGraphiteServer: GraphiteServer;

showCreateSection = false;
createServerForm : FormGroup;

constructor(public ngxSmartModalService: NgxSmartModalService, private applicationService: ApplicationService, private grailsBridgeService: GrailsBridgeService) {
this.resetFormGroup();
this.applicationService.jobHealthGraphiteServers$.subscribe(value => {this.jobHealthGraphiteServers = value});
this.applicationService.availableGraphiteServers$.subscribe(value => {this.availableGraphiteServers = value});
}
@@ -74,7 +81,73 @@ export class GraphiteIntegrationComponent {
this.selectedGraphiteServer = null;
} else {
this.selectedGraphiteServer = graphiteServer;
this.showCreateSection = false;
}
}

showCreationSection(): void {
this.showCreateSection = true;
this.selectedGraphiteServer = null;
}

cancelCreation(): void {
this.showCreateSection = false;
this.resetFormGroup();
}

create(): void {
if(!this.grailsBridgeService.globalOsmNamespace.user.loggedIn) {
window.location.href = '/login/auth';
}
const observable = this.applicationService.createGraphiteServer( {
address : this.createServerForm.get('address').value,
id : null,
port : this.createServerForm.get('port').value,
prefix : this.createServerForm.get('prefix').value,
protocol : this.createServerForm.get('protocol').value,
webAppAddress : this.createServerForm.get('webAppAddress').value
});
if(observable){
this.resetFormGroup();
this.addNewServer(observable);
}
}

addNewServer( observable: Observable<Map<String, any>> ) : void {
observable.subscribe(next => {
if (next != null && next["success"] && next["id"] != null) {
this.applicationService.selectedApplication$.pipe(
switchMap((application: Application) => this.applicationService.updateAvailableGraphiteServers(application))
).subscribe(server => {
this.applicationService.availableGraphiteServers$.next(server);
this.selectNewServer(server, next["id"]);
});
}
});
}

private selectNewServer(server: GraphiteServer[], id: number, ): void {
if (server != null) {
const target = server.find(value => value.id == id);
this.add(target);
this.toggleSelectedGraphiteServer(target);
}
}

private resetFormGroup(): void {
this.createServerForm = new FormGroup({
address: new FormControl(''),
port: new FormControl(2003),
protocol: new FormControl('TCP'),
webAppAddress: new FormControl(''),
prefix: new FormControl('jobstatus')
});
}

allFormsFilled() : boolean {
return this.createServerForm.get('address').value != "" &&
this.createServerForm.get('port').value.toString() != "" &&
this.createServerForm.get('webAppAddress').value != "" &&
this.createServerForm.get('protocol').value != "";
}
}
@@ -1,5 +1,5 @@
import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {HttpClient, HttpParams} from "@angular/common/http";
import {BehaviorSubject, combineLatest, EMPTY, Observable, OperatorFunction, ReplaySubject} from "rxjs";
import {PageMetricsDto} from "../modules/application-dashboard/models/page-metrics.model";
import {PageCsiDto} from "../modules/application-dashboard/models/page-csi.model";
@@ -9,7 +9,7 @@ import {catchError, distinctUntilKeyChanged, filter, map, startWith, switchMap,
import {ResponseWithLoadingState} from "../models/response-with-loading-state.model";
import {Csi, CsiDTO} from "../models/csi.model";
import {FailingJobStatistic} from "../modules/application-dashboard/models/failing-job-statistic.model";
import {GraphiteServer} from "../modules/application-dashboard/models/graphite-server.model";
import {GraphiteServer, GraphiteServerDTO} from "../modules/application-dashboard/models/graphite-server.model";
import {FailingJob, FailingJobDTO} from '../modules/landing/models/failing-jobs.model';

@Injectable()
@@ -254,6 +254,18 @@ export class ApplicationService {
startWith(null)
)
}

createGraphiteServer(server: GraphiteServerDTO): Observable<Map<String, any>> {
let params = new HttpParams().set("port", server.port.toString());
params = params.set("address", server.address.toString());
params = params.set("prefix", server.prefix.toString());
params = params.set("protocol", server.protocol);
params = params.set("webAppAddress", server.webAppAddress.toString());
return this.http.post<GraphiteServerDTO>('/graphiteServer/rest/createGraphiteServer', params).pipe(
handleError(),
startWith(null)
)
}
}

function handleError(): OperatorFunction<any, any> {
@@ -102,10 +102,7 @@ OpenSpeedMonitor.ChartModules.UrlHandling.ChartSwitch = (function () {
if (updatedMap["measurand"] == null) updatedMap["measurand"] = "{\"values\":[\"" + measurand + "\"]}";
}
var params = $.param(updatedMap, true);
var showLinks = false;
if (params.length > 0) {
showLinks = true;
}
var showLinks = true;
updateUrl("#timeSeriesWithDataLink", OpenSpeedMonitor.urls.eventResultDashboardShowAll + "?" + params, showLinks);
updateUrl("#pageAggregationWithDataLink", OpenSpeedMonitor.urls.pageAggregationShow + "?" + params, showLinks);
updateUrl("#jobGroupAggregationWithDataLink", OpenSpeedMonitor.urls.jobGroupAggregationShow + "?" + params, showLinks);
@@ -34,6 +34,7 @@ class UrlMappings {
"/applicationDashboard/rest/$action"(controller: "applicationDashboard")
"/queueDashboard/rest/$action"(controller: "queueDashboard")
"/queueDashboard"(view: "/angularFrontend")
"/graphiteServer/rest/$action"(controller: "graphiteServer")

////////////////////////////////////////////////////////////////////////////////////////////////
// Pages with controller
Oops, something went wrong.

0 comments on commit e03f86f

Please sign in to comment.