diff options
Diffstat (limited to '')
4 files changed, 54 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.html b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.html new file mode 100644 index 000000000..a9090aaf2 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.html @@ -0,0 +1,5 @@ +<button class="btn btn-light tc_backButton" + (click)="back()" + type="button"> + {{ name }} +</button> diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.scss b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.scss new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.scss diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.spec.ts new file mode 100644 index 000000000..d3120a283 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; + +import { configureTestBed } from '~/testing/unit-test-helper'; +import { BackButtonComponent } from './back-button.component'; + +describe('BackButtonComponent', () => { + let component: BackButtonComponent; + let fixture: ComponentFixture<BackButtonComponent>; + + configureTestBed({ + imports: [RouterTestingModule], + declarations: [BackButtonComponent] + }); + + beforeEach(() => { + fixture = TestBed.createComponent(BackButtonComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.ts new file mode 100644 index 000000000..a578f0394 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/back-button/back-button.component.ts @@ -0,0 +1,24 @@ +import { Location } from '@angular/common'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; + +import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; + +@Component({ + selector: 'cd-back-button', + templateUrl: './back-button.component.html', + styleUrls: ['./back-button.component.scss'] +}) +export class BackButtonComponent { + @Output() backAction = new EventEmitter(); + @Input() name: string = this.actionLabels.CANCEL; + + constructor(private location: Location, private actionLabels: ActionLabelsI18n) {} + + back() { + if (this.backAction.observers.length === 0) { + this.location.back(); + } else { + this.backAction.emit(); + } + } +} |