diff --git a/src/app/item-detail/share/delete-share-link/delete-share-link.component.ts b/src/app/item-detail/share/delete-share-link/delete-share-link.component.ts index 56a848c6..bf0789f1 100644 --- a/src/app/item-detail/share/delete-share-link/delete-share-link.component.ts +++ b/src/app/item-detail/share/delete-share-link/delete-share-link.component.ts @@ -1,8 +1,6 @@ import { Component, Input, OnInit } from "@angular/core"; import { FormControl, Validators, FormGroup } from "@angular/forms"; import { NgbModal, NgbModalRef } from "@ng-bootstrap/ng-bootstrap"; -import { of } from "rxjs"; -import { catchError } from "rxjs/operators"; import { ItemsApiService } from "src/app/items-api.service"; import { ItemsService } from "src/app/items.service"; import { NotificationMessage } from "src/app/notification/notification-messages"; diff --git a/src/app/notification/notification-messages.ts b/src/app/notification/notification-messages.ts index 3e98758e..2bc794a4 100644 --- a/src/app/notification/notification-messages.ts +++ b/src/app/notification/notification-messages.ts @@ -86,6 +86,15 @@ export class NotificationMessage { return this.statusCodeMessage(response, "Settings updated"); } + createScenarioShareToken(response) { + return this.statusCodeMessage(response, "Scenario share token was created"); + } + + deleteScenarioShareTokenNotification(response) { + return this.statusCodeMessage(response, "Scenario share token was deleted"); + + } + appInitialization(response) { return this.statusCodeMessage(response, "") } diff --git a/src/app/scenario-api.service.model.ts b/src/app/scenario-api.service.model.ts new file mode 100644 index 00000000..ad380183 --- /dev/null +++ b/src/app/scenario-api.service.model.ts @@ -0,0 +1,5 @@ +export interface ScenarioShareToken { + id: string + toke: string + note: string +} diff --git a/src/app/scenario-api.service.ts b/src/app/scenario-api.service.ts index 6ddae9f5..b2d2f221 100644 --- a/src/app/scenario-api.service.ts +++ b/src/app/scenario-api.service.ts @@ -3,6 +3,7 @@ import { HttpClient } from "@angular/common/http"; import { BehaviorSubject, Observable } from "rxjs"; import { IScenarios, ScenarioNotifications } from "./items.service.model"; import { Scenario } from "./scenario.service.model"; +import { ScenarioShareToken } from "./scenario-api.service.model"; @Injectable({ providedIn: "root" @@ -36,9 +37,9 @@ export class ScenarioApiService { `projects/${projectName}/scenarios/${scenarioName}/trends`, { params }); } - fetchScenarioEnvironments(projectName, scenarioName): Observable { + fetchScenarioEnvironments(projectName, scenarioName, params): Observable { return this.http.get( - `projects/${projectName}/scenarios/${scenarioName}/environment`); + `projects/${projectName}/scenarios/${scenarioName}/environment`, { params }); } createNewScenario(projectName, body): Observable> { @@ -61,6 +62,18 @@ export class ScenarioApiService { return this.http.post(`projects/${projectName}/scenarios/${scenarioName}/trends/settings`, body, { observe: "response" }); } + fetchScenarioShareTokens(projectName, scenarioName): Observable { + return this.http.get(`projects/${projectName}/scenarios/${scenarioName}/share-token`); + } + + createScenarioShareToken(projectName, scenarioName, body) { + return this.http.post(`projects/${projectName}/scenarios/${scenarioName}/share-token`, body, { observe: "response" }); + } + + deleteScenarioShareToken(projectName, scenarioName, token) { + return this.http.delete(`projects/${projectName}/scenarios/${scenarioName}/share-token/${token}`, { observe: "response" }) + } + setData(data) { this.response.next(data); } diff --git a/src/app/scenario.service.ts b/src/app/scenario.service.ts index 4000fd72..9a01035e 100644 --- a/src/app/scenario.service.ts +++ b/src/app/scenario.service.ts @@ -3,6 +3,7 @@ import { BehaviorSubject, Observable } from "rxjs"; import { ScenarioNotifications } from "./items.service.model"; import { ScenarioApiService } from "./scenario-api.service"; import { EnvironmentService } from "./_services/environment.service"; +import { ScenarioShareToken } from "./scenario-api.service.model"; @Injectable({ providedIn: "root" @@ -18,6 +19,10 @@ export class ScenarioService { private notifications = new BehaviorSubject([]); public notifications$ = this.notifications.asObservable(); + + private scenarioShareTokens = new BehaviorSubject([]) + public scenarioShareTokens$ = this.scenarioShareTokens.asObservable() + private environment: string; constructor( @@ -30,8 +35,8 @@ export class ScenarioService { } - fetchScenarioTrends(projectName, scenarioName) { - const queryParams = { environment: this.environment }; + fetchScenarioTrends(projectName, scenarioName, params = {}) { + const queryParams = { environment: this.environment, ...params }; this.scenarioApiService.fetchScenarioTrend(projectName, scenarioName, queryParams) .subscribe(_ => this.trends.next(_)); } @@ -41,8 +46,13 @@ export class ScenarioService { .subscribe(_ => this.notifications.next(_)); } - fetchEnvironments(projectName, scenarioName) { - this.scenarioApiService.fetchScenarioEnvironments(projectName, scenarioName) + fetchScenarioShareTokens(projectName: string, scenarioName: string) { + this.scenarioApiService.fetchScenarioShareTokens(projectName, scenarioName) + .subscribe(tokens => this.scenarioShareTokens.next(tokens)) + } + + fetchEnvironments(projectName, scenarioName, queryParams = {}) { + this.scenarioApiService.fetchScenarioEnvironments(projectName, scenarioName, queryParams) .subscribe(_ => this.environments.next(_)); } diff --git a/src/app/scenario/environments/environments.component.spec.ts b/src/app/scenario/environments/environments.component.spec.ts index 394834dd..a9cae090 100644 --- a/src/app/scenario/environments/environments.component.spec.ts +++ b/src/app/scenario/environments/environments.component.spec.ts @@ -25,6 +25,10 @@ describe("EnvironmentsComponent", () => { fixture = TestBed.createComponent(EnvironmentsComponent); component = fixture.componentInstance; component.params = { projectName: "test-project", scenarioName: "test-scenario" }; + component.anonymous = { + token: "", + isAnonymous: false, + } fixture.detectChanges(); }); diff --git a/src/app/scenario/environments/environments.component.ts b/src/app/scenario/environments/environments.component.ts index e668878c..f4887e60 100644 --- a/src/app/scenario/environments/environments.component.ts +++ b/src/app/scenario/environments/environments.component.ts @@ -15,6 +15,7 @@ export class EnvironmentsComponent implements OnInit { defaultEnvironment = "All Environments"; @Input() params + @Input() anonymous: { token?: string, isAnonymous: boolean} constructor( private scenarioService: ScenarioService, private itemsService: ItemsService, @@ -24,7 +25,7 @@ export class EnvironmentsComponent implements OnInit { } ngOnInit(): void { - this.scenarioService.fetchEnvironments(this.params.projectName, this.params.scenarioName); + this.scenarioService.fetchEnvironments(this.params.projectName, this.params.scenarioName, { token: this.anonymous.token }); this.reloadData("") } @@ -38,9 +39,12 @@ export class EnvironmentsComponent implements OnInit { private reloadData(environment) { this.environmentService.setEnvironment(environment) - this.itemsService.fetchItems(this.params.projectName, this.params.scenarioName, { limit: 15, offset: 0 }); - this.scenarioService.fetchScenarioTrends(this.params.projectName, this.params.scenarioName) - this.itemsService.setProcessingItemsIntervalSubscription(this.params.projectName, this.params.scenarioName); + + if (!this.anonymous.isAnonymous) { + this.itemsService.fetchItems(this.params.projectName, this.params.scenarioName, { limit: 15, offset: 0 }); + this.itemsService.setProcessingItemsIntervalSubscription(this.params.projectName, this.params.scenarioName); + } + this.scenarioService.fetchScenarioTrends(this.params.projectName, this.params.scenarioName, { token: this.anonymous.token }) } } diff --git a/src/app/scenario/scenario-settings/scenario-settings.component.html b/src/app/scenario/scenario-settings/scenario-settings.component.html index ccc74f66..414d77bd 100644 --- a/src/app/scenario/scenario-settings/scenario-settings.component.html +++ b/src/app/scenario/scenario-settings/scenario-settings.component.html @@ -432,8 +432,6 @@
Generate extra chart aggregations
- -
diff --git a/src/app/scenario/scenario.component.html b/src/app/scenario/scenario.component.html index a38e85d3..4e4abd8c 100644 --- a/src/app/scenario/scenario.component.html +++ b/src/app/scenario/scenario.component.html @@ -1,22 +1,23 @@
- - -
+ +
@@ -26,14 +27,14 @@ -
+
-
+
Test Runs diff --git a/src/app/scenario/scenario.component.ts b/src/app/scenario/scenario.component.ts index 3cacbdb7..01a282d2 100644 --- a/src/app/scenario/scenario.component.ts +++ b/src/app/scenario/scenario.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit, OnDestroy } from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; import { of, Observable, Subscription } from "rxjs"; -import { switchMap, catchError } from "rxjs/operators"; +import { switchMap, catchError, withLatestFrom } from "rxjs/operators"; import { Items } from "../items.service.model"; import { ItemsService } from "../items.service"; import { SharedMainBarService } from "../shared-main-bar.service"; @@ -28,6 +28,8 @@ export class ScenarioComponent implements OnInit, OnDestroy { processingItems; subscription: Subscription; zeroErrorToleranceEnabled: boolean; + token: string; + isAnonymous = false; constructor( private route: ActivatedRoute, @@ -38,8 +40,6 @@ export class ScenarioComponent implements OnInit, OnDestroy { private sharedMainBarService: SharedMainBarService, private environmentService: EnvironmentService, ) { - this.items$ = itemsService.items$; - this.environment$ = this.environmentService.environment$.subscribe(value => this.page = 1); } ngOnDestroy() { @@ -49,32 +49,55 @@ export class ScenarioComponent implements OnInit, OnDestroy { } ngOnInit() { - this.route.params.pipe( - switchMap(routeParams => { - this.params = routeParams; - this.sharedMainBarService.setProjectName(this.params.projectName); - this.scenarioApiService.getScenario(this.params.projectName, this.params.scenarioName).subscribe(_ => { - this.zeroErrorToleranceEnabled = _.zeroErrorToleranceEnabled; - }); - return new Observable().pipe(catchError(err => of([]))); - }) - ).subscribe(_ => _); - this.subscription = this.itemsService.processingItems$.subscribe((_) => { - this.processingItems = _; - const { inprogress } = _ as any; - if (Array.isArray(inprogress)) { - const processingItems = inprogress.map((item) => item.id); - const reloadItems = !this.currentProcessingItems.every((id) => processingItems.includes(id)); - if (reloadItems) { - this.itemsService.fetchItems(this.params.projectName, this.params.scenarioName, { limit: LIMIT, offset: 0 }); - this.scenarioService.fetchScenarioTrends(this.params.projectName, this.params.scenarioName); - this.scenarioService.fetchEnvironments(this.params.projectName, this.params.scenarioName); - } - return this.currentProcessingItems = inprogress.map((item) => item.id); + this.route.queryParams.subscribe(_ => { + this.token = _.token; + if (this.token) { + this.isAnonymous = true; } }); + + if (!this.isAnonymous) { + this.items$ = this.itemsService.items$; + this.environment$ = this.environmentService.environment$.subscribe(value => this.page = 1); + + this.route.params.pipe( + switchMap(routeParams => { + this.params = routeParams; + this.sharedMainBarService.setProjectName(this.params.projectName); + this.scenarioApiService.getScenario(this.params.projectName, this.params.scenarioName).subscribe(_ => { + this.zeroErrorToleranceEnabled = _.zeroErrorToleranceEnabled; + }); + return new Observable().pipe(catchError(err => of([]))); + }) + ).subscribe(_ => _); + this.subscription = this.itemsService.processingItems$.subscribe((_) => { + this.processingItems = _; + const { inprogress } = _ as any; + if (Array.isArray(inprogress)) { + const processingItems = inprogress.map((item) => item.id); + const reloadItems = !this.currentProcessingItems.every((id) => processingItems.includes(id)); + if (reloadItems) { + this.itemsService.fetchItems(this.params.projectName, this.params.scenarioName, { limit: LIMIT, offset: 0 }); + this.scenarioService.fetchScenarioTrends(this.params.projectName, this.params.scenarioName); + this.scenarioService.fetchEnvironments(this.params.projectName, this.params.scenarioName); + } + return this.currentProcessingItems = inprogress.map((item) => item.id); + } + }); + } else { + this.route.params.pipe( + switchMap(routeParams => { + this.params = routeParams; + return new Observable().pipe(catchError(err => of([]))); + }) + ).subscribe(_ => _); + } + + + } + loadMore() { const offset = (this.page - 1) * OFFSET; this.itemsService.fetchItems(this.params.projectName, this.params.scenarioName, { limit: LIMIT, offset }); diff --git a/src/app/scenario/scenario.module.ts b/src/app/scenario/scenario.module.ts index 6ab59608..e222a9d8 100644 --- a/src/app/scenario/scenario.module.ts +++ b/src/app/scenario/scenario.module.ts @@ -25,6 +25,9 @@ import { RoleModule } from "../_directives/role.module"; import { AddNewItemModule } from "./add-new-item/add-new-item.module"; import { ScenarioTrendsSettingsComponent } from "./scenario-trends/scenario-trends-settings/scenario-trends-settings.component"; import { EnvironmentsComponent } from "./environments/environments.component"; +import { NewScenarioShareTokenComponent } from "./share-token/new-share-token/new-scenario-share-token.component"; +import { DeleteScenarioShareTokenComponent } from "./share-token/delete-share-token/delete-scenario-share-token.component"; +import { ScenarioShareTokenComponent } from "./share-token/scenario-share-token.component"; const routes: Routes = [ { @@ -37,7 +40,7 @@ const routes: Routes = [ @NgModule({ declarations: [ScenarioComponent, ScenarioTrendsComponent, SettingsScenarioComponent, DeleteScenarioComponent, ExternalNotificationComponent, - ItemControlsComponent, AddNewExternalNotificationComponent, DeleteExternalNotificationComponent, ScenarioTrendsSettingsComponent, EnvironmentsComponent + ItemControlsComponent, AddNewExternalNotificationComponent, DeleteExternalNotificationComponent, ScenarioTrendsSettingsComponent, EnvironmentsComponent, NewScenarioShareTokenComponent, DeleteScenarioShareTokenComponent, ScenarioShareTokenComponent, ScenarioShareTokenComponent ], imports: [ CommonModule, RouterModule.forRoot(routes), NgxSpinnerModule, NgbModule, SharedModule, HighchartsChartModule, @@ -48,4 +51,5 @@ const routes: Routes = [ SettingsScenarioComponent, DeleteScenarioComponent, ExternalNotificationComponent, ItemControlsComponent] }) -export class ScenarioModule { } +export class ScenarioModule { +} diff --git a/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.css b/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.css new file mode 100644 index 00000000..fa8d599d --- /dev/null +++ b/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.css @@ -0,0 +1,3 @@ +.revoke { + margin-left: 10px; +} diff --git a/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.html b/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.html new file mode 100644 index 00000000..cd269d73 --- /dev/null +++ b/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.html @@ -0,0 +1,33 @@ + + +
+ + +
+ +
+ + diff --git a/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.spec.ts b/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.spec.ts new file mode 100644 index 00000000..a2c4a86d --- /dev/null +++ b/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.spec.ts @@ -0,0 +1,29 @@ +import { ComponentFixture, TestBed } from "@angular/core/testing"; + +import { DeleteScenarioShareTokenComponent } from "./delete-scenario-share-token.component"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; + +describe("DeleteShareTokenComponent", () => { + let component: DeleteScenarioShareTokenComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [DeleteScenarioShareTokenComponent], + imports: [ + HttpClientTestingModule, + ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(DeleteScenarioShareTokenComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it("should create", () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.ts b/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.ts new file mode 100644 index 00000000..1516644d --- /dev/null +++ b/src/app/scenario/share-token/delete-share-token/delete-scenario-share-token.component.ts @@ -0,0 +1,70 @@ +import { Component, Input, OnInit } from "@angular/core"; +import { FormControl, FormGroup, Validators } from "@angular/forms"; +import { NgbModal, NgbModalRef } from "@ng-bootstrap/ng-bootstrap"; +import { ScenarioApiService } from "../../../scenario-api.service"; +import { ScenarioService } from "../../../scenario.service"; +import { NotificationMessage } from "../../../notification/notification-messages"; + +@Component({ + selector: "app-delete-share-token", + templateUrl: "./delete-scenario-share-token.component.html", + styleUrls: ["./delete-scenario-share-token.component.css"] +}) +export class DeleteScenarioShareTokenComponent implements OnInit { + + deleteCheck: FormControl; + deleteScenarioShareTokenForm: FormGroup; + modal: NgbModalRef; + + @Input() params: { projectName: string, scenarioName: string }; + @Input() tokenId: string; + + + constructor( + private modalService: NgbModal, + private scenarioApiService: ScenarioApiService, + private scenarioService: ScenarioService, + private notification: NotificationMessage + ) { } + + ngOnInit(): void { + this.createFormControls() + this.createForm() + } + + createFormControls() { + this.deleteCheck = new FormControl("", [ + Validators.required, + Validators.minLength(5) + ]); + } + + createForm() { + this.deleteScenarioShareTokenForm = new FormGroup({ + deleteCheck: this.deleteCheck, + }); + } + + open(content) { + this.modal = this.modalService.open(content, { ariaLabelledBy: "modal-basic-title" }); + } + + onSubmit() { + if (this.deleteScenarioShareTokenForm.valid) { + this.scenarioApiService.deleteScenarioShareToken( + this.params.projectName, + this.params.scenarioName, + this.tokenId + ).subscribe((_) => { + this.scenarioService.fetchScenarioShareTokens(this.params.projectName, this.params.scenarioName); + const message = this.notification.deleteScenarioShareTokenNotification(_); + this.scenarioApiService.setData(message); + }); + + this.deleteScenarioShareTokenForm.reset(); + this.modal.close(); + + } + } + +} diff --git a/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.css b/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.css new file mode 100644 index 00000000..623abc69 --- /dev/null +++ b/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.css @@ -0,0 +1,3 @@ +.create-new-link{ + margin-bottom: 1.5rem; +} diff --git a/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.html b/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.html new file mode 100644 index 00000000..9e76c8ec --- /dev/null +++ b/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.html @@ -0,0 +1,31 @@ + + +
+ + + +
+ +
+ + diff --git a/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.spec.ts b/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.spec.ts new file mode 100644 index 00000000..6a844e5d --- /dev/null +++ b/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.spec.ts @@ -0,0 +1,29 @@ +import { ComponentFixture, TestBed } from "@angular/core/testing"; + +import { NewScenarioShareTokenComponent } from "./new-scenario-share-token.component"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; + +describe("NewShareTokenComponent", () => { + let component: NewScenarioShareTokenComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [NewScenarioShareTokenComponent], + imports: [ + HttpClientTestingModule, + ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(NewScenarioShareTokenComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it("should create", () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.ts b/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.ts new file mode 100644 index 00000000..7e52f662 --- /dev/null +++ b/src/app/scenario/share-token/new-share-token/new-scenario-share-token.component.ts @@ -0,0 +1,68 @@ +import { Component, Input, OnInit } from "@angular/core"; +import { FormControl, FormGroup, Validators } from "@angular/forms"; +import { NgbActiveModal, NgbModal } from "@ng-bootstrap/ng-bootstrap"; +import { catchError } from "rxjs/internal/operators/catchError"; +import { of } from "rxjs"; +import { NotificationMessage } from "../../../notification/notification-messages"; +import { ScenarioApiService } from "../../../scenario-api.service"; +import { ScenarioService } from "../../../scenario.service"; + +@Component({ + selector: "app-new-share-token", + templateUrl: "./new-scenario-share-token.component.html", + styleUrls: ["./new-scenario-share-token.component.css"] +}) +export class NewScenarioShareTokenComponent implements OnInit { + + private note: FormControl; + private newScenarioShareTokenForm: FormGroup; + modal: NgbActiveModal; + @Input() params: { projectName: string, scenarioName: string }; + + constructor( + private modalService: NgbModal, + private notification: NotificationMessage, + private scenarioApiService: ScenarioApiService, + private scenarioService: ScenarioService + ) { + } + + ngOnInit() { + this.createFormControls(); + this.createForm(); + } + + open(content) { + this.modal = this.modalService.open(content, { ariaLabelledBy: "modal-basic-title" }); + } + + createFormControls() { + this.note = new FormControl("", [ + Validators.maxLength(100), + Validators.required + ]); + } + + createForm() { + this.newScenarioShareTokenForm = new FormGroup({ + note: this.note + }); + } + + onSubmit() { + const { note } = this.newScenarioShareTokenForm.value; + const { projectName, scenarioName } = this.params; + console.log(note) + + this.scenarioApiService.createScenarioShareToken(projectName, scenarioName, { note }) + .pipe(catchError(r => of(r))) + .subscribe(_ => { + const message = this.notification.createScenarioShareToken(_); + this.scenarioApiService.setData(message); + this.scenarioService.fetchScenarioShareTokens(projectName, scenarioName); + }); + this.newScenarioShareTokenForm.reset(); + this.modal.close(); + } + +} diff --git a/src/app/scenario/share-token/scenario-share-token.component.css b/src/app/scenario/share-token/scenario-share-token.component.css new file mode 100644 index 00000000..e69de29b diff --git a/src/app/scenario/share-token/scenario-share-token.component.html b/src/app/scenario/share-token/scenario-share-token.component.html new file mode 100644 index 00000000..923b0038 --- /dev/null +++ b/src/app/scenario/share-token/scenario-share-token.component.html @@ -0,0 +1,61 @@ + + +
+ + +
+ +
+ + diff --git a/src/app/scenario/share-token/scenario-share-token.component.spec.ts b/src/app/scenario/share-token/scenario-share-token.component.spec.ts new file mode 100644 index 00000000..302d163d --- /dev/null +++ b/src/app/scenario/share-token/scenario-share-token.component.spec.ts @@ -0,0 +1,31 @@ +import { ComponentFixture, TestBed } from "@angular/core/testing"; + +import { ScenarioShareTokenComponent } from "./scenario-share-token.component"; +import { HttpClientTestingModule } from "@angular/common/http/testing"; + +describe("ShareTokenComponent", () => { + let component: ScenarioShareTokenComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ScenarioShareTokenComponent ], + imports:[ + HttpClientTestingModule, + ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ScenarioShareTokenComponent); + component = fixture.componentInstance; + component.params = { projectName: "test-project", scenarioName: "test-scenario" }; + + fixture.detectChanges(); + }); + + it("should create", () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/scenario/share-token/scenario-share-token.component.ts b/src/app/scenario/share-token/scenario-share-token.component.ts new file mode 100644 index 00000000..22dda6e6 --- /dev/null +++ b/src/app/scenario/share-token/scenario-share-token.component.ts @@ -0,0 +1,51 @@ +import { Component, Input, OnInit } from "@angular/core"; +import { NgbModal } from "@ng-bootstrap/ng-bootstrap"; +import { FormGroup } from "@angular/forms"; +import { ScenarioService } from "../../scenario.service"; +import { Observable } from "rxjs"; +import { ScenarioShareToken } from "../../scenario-api.service.model"; + +@Component({ + selector: "app-share-token", + templateUrl: "./scenario-share-token.component.html", + styleUrls: ["./scenario-share-token.component.css"] +}) +export class ScenarioShareTokenComponent implements OnInit { + + @Input() params: { scenarioName: string, projectName: string }; + + shareForm: FormGroup; + scenarioShareTokens$: Observable; + selfUrl: string + + + constructor( + private modalService: NgbModal, + private scenarioService: ScenarioService + ) { + this.scenarioShareTokens$ = scenarioService.scenarioShareTokens$; + + } + + ngOnInit(): void { + this.scenarioService.fetchScenarioShareTokens(this.params.projectName, this.params.scenarioName); + this.createForm(); + this.selfUrl = window.location.href; + + } + + createForm() { + this.shareForm = new FormGroup({}); + } + + copyInputMessage(inputElement) { + inputElement.select(); + document.execCommand("copy"); + inputElement.setSelectionRange(0, 0); + } + + open(content) { + this.modalService.open(content, { ariaLabelledBy: "modal-basic-title", size: "lg" }); + } + +} diff --git a/src/app/shared/breadcrumb/breadcrumb.component.html b/src/app/shared/breadcrumb/breadcrumb.component.html index 3d9508ca..86911399 100644 --- a/src/app/shared/breadcrumb/breadcrumb.component.html +++ b/src/app/shared/breadcrumb/breadcrumb.component.html @@ -1,6 +1,7 @@ \ No newline at end of file + diff --git a/src/app/shared/breadcrumb/breadcrumb.component.ts b/src/app/shared/breadcrumb/breadcrumb.component.ts index b609ed93..e7a8a93d 100644 --- a/src/app/shared/breadcrumb/breadcrumb.component.ts +++ b/src/app/shared/breadcrumb/breadcrumb.component.ts @@ -9,6 +9,7 @@ import { ActivatedRoute } from "@angular/router"; }) export class BreadcrumbComponent implements OnInit, OnChanges { @Input() testName + @Input() isAnonymous: boolean params; urls = []; @@ -18,7 +19,7 @@ export class BreadcrumbComponent implements OnInit, OnChanges { ngOnChanges(changes: SimpleChanges): void { const { testName } = changes - if (testName.currentValue !== testName.previousValue) { + if (testName?.currentValue !== testName?.previousValue) { this.urls[this.urls.length - 1] = { label: this.testName || "test run", url: "", last: true } } }