Skip to content

Commit

Permalink
introduce local environment
Browse files Browse the repository at this point in the history
  • Loading branch information
mghilardelli committed Jul 24, 2024
1 parent f3d0a61 commit 244a407
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jakarta.xml.bind.JAXBException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Component;

Expand All @@ -18,8 +19,9 @@ public class SferaHandler {
private static final Logger log = LoggerFactory.getLogger(SferaHandler.class);

private final StaticSferaService staticSferaService;

public String replyTopic;
@Value("${spring.profiles.active}")
private String profile;

public SferaHandler(StaticSferaService staticSferaService) {
this.staticSferaService = staticSferaService;
Expand Down Expand Up @@ -104,6 +106,7 @@ private String replyTopic(String topic) {
String companyCode = topicParts[3];
String trainIdentifier = topicParts[4];
String clientId = topicParts[5];
return "90940/2/G2B/" + companyCode + "/" + trainIdentifier + "/" + clientId;
String env = this.profile.equals("local") ? "local/" : "";
return env + "90940/2/G2B/" + companyCode + "/" + trainIdentifier + "/" + clientId;
}
}
9 changes: 1 addition & 8 deletions webapp/src/app/sfera-observer/sfera-observer.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<h2>SFERA Communication</h2>
@if ((mqService.state | async) !== MqttConnectionState.CONNECTED) {
<sbb-form-field class="sbb-form-field-long">
<sbb-label>Umgebung</sbb-label>
<sbb-select placeholder="Lieblingsessen" [formControl]="environmentControl">
@for (environment of environments; track environment) {
<sbb-option [value]="environment">{{ environment }}</sbb-option>
}
</sbb-select>
</sbb-form-field>
<sbb-form-field class="sbb-form-field-long">
<sbb-label>Company Code</sbb-label>
<input type="text" sbbInput [formControl]="companyControl"/>
Expand All @@ -24,6 +16,7 @@ <h2>SFERA Communication</h2>
<sbb-label>Client ID</sbb-label>
<input type="text" sbbInput [formControl]="clientIdControl"/>
</sbb-form-field>
<sbb-checkbox class="checkbox" [formControl]="environmentControl">local</sbb-checkbox>
<button type="button" sbb-button (click)="observe()">Observe</button>
} @else {
<button type="button" class="disconnect" sbb-button (click)="disconnect()">Disconnect/Change
Expand Down
7 changes: 7 additions & 0 deletions webapp/src/app/sfera-observer/sfera-observer.component.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
@use '@sbb-esta/angular' as sbb;

.checkbox {
width: 100%;
margin-bottom: sbb.pxToRem(16);
}

.disconnect {
margin-bottom: sbb.pxToRem(16);
}

.messages {
.title {
display: flex;

div {
width: 50%;
}
}

.message {
display: flex;

Expand Down
9 changes: 4 additions & 5 deletions webapp/src/app/sfera-observer/sfera-observer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { firstValueFrom, map, Subscription } from "rxjs";
import { CommonModule } from "@angular/common";
import { MqttConnectionState } from "ngx-mqtt";
import { OidcSecurityService } from "angular-auth-oidc-client";
import { SbbSelectModule } from "@sbb-esta/angular/select";
import { SbbCheckboxModule } from "@sbb-esta/angular/checkbox";

@Component({
selector: 'app-sfera-observer',
Expand All @@ -21,19 +21,18 @@ import { SbbSelectModule } from "@sbb-esta/angular/select";
SbbFormFieldModule,
SbbInputModule,
SbbButtonModule,
SbbCheckboxModule,
SimpleXmlComponent,
SbbSelectModule
],
templateUrl: './sfera-observer.component.html',
styleUrl: './sfera-observer.component.scss',
})
export class SferaObserverComponent implements OnDestroy {
environments = ['', 'dev', 'e2e'];
environmentControl = new FormControl('', {nonNullable: true});
companyControl = new FormControl('1088', {nonNullable: true});
trainControl = new FormControl('9232', {nonNullable: true});
dateControl = new FormControl(new Date().toISOString().split('T')[0], {nonNullable: true});
clientIdControl = new FormControl('', {nonNullable: true});
environmentControl = new FormControl(false, {nonNullable: true});
g2bTopic?: string;
b2gTopic?: string;
messages: { message: string, topic: string }[] = [];
Expand All @@ -49,7 +48,7 @@ export class SferaObserverComponent implements OnDestroy {
}

async observe() {
const env = this.environmentControl.value !== '' ? this.environmentControl.value + '/' : '';
const env = this.environmentControl.value ? 'local/' : '';
const trainOperation = this.dateControl.value + '_' + this.trainControl.value;
this.g2bTopic = env + '90940/2/G2B/' + this.companyControl.value + '/' + trainOperation + '/' + this.clientIdControl.value;
this.b2gTopic = env + '90940/2/B2G/' + this.companyControl.value + '/' + trainOperation + '/' + this.clientIdControl.value
Expand Down

0 comments on commit 244a407

Please sign in to comment.