2019-07-26 11:46:59 +02:00
|
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
2018-10-12 11:05:24 +02:00
|
|
|
|
2019-01-19 21:55:06 +01:00
|
|
|
import { MainMenuService } from 'app/core/core-services/main-menu.service';
|
2019-06-25 10:45:24 +02:00
|
|
|
import { RoutingStateService } from 'app/core/ui-services/routing-state.service';
|
2019-07-26 11:46:59 +02:00
|
|
|
import { ViewportService } from 'app/core/ui-services/viewport.service';
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reusable head bar component for Apps.
|
|
|
|
*
|
|
|
|
* Will translate the title automatically.
|
|
|
|
*
|
|
|
|
* ## Examples:
|
|
|
|
*
|
|
|
|
* ### Usage of the selector:
|
|
|
|
*
|
|
|
|
* ```html
|
2018-09-03 17:57:20 +02:00
|
|
|
* <os-head-bar
|
2019-03-08 10:43:54 +01:00
|
|
|
* prevUrl="../.."
|
2018-11-06 15:35:51 +01:00
|
|
|
* [nav]="false"
|
2018-12-04 11:31:14 +01:00
|
|
|
* [goBack]="true"
|
2018-11-06 15:35:51 +01:00
|
|
|
* [mainButton]="opCanEdit()"
|
2018-11-08 17:38:44 +01:00
|
|
|
* [mainButtonIcon]="edit"
|
2018-11-06 15:35:51 +01:00
|
|
|
* [editMode]="editMotion"
|
2018-11-05 17:40:32 +01:00
|
|
|
* [multiSelectMode]="isMultiSelect"
|
2018-11-06 15:35:51 +01:00
|
|
|
* (mainEvent)="setEditMode(!editMotion)"
|
|
|
|
* (saveEvent)="saveMotion()">
|
|
|
|
*
|
|
|
|
* <!-- Title -->
|
|
|
|
* <div class="title-slot">
|
|
|
|
* My Component Title
|
|
|
|
* </div>
|
|
|
|
*
|
|
|
|
* <!-- Menu -->
|
|
|
|
* <div class="menu-slot">
|
|
|
|
* <button type="button" mat-icon-button [matMenuTriggerFor]="myComponentMenu">
|
|
|
|
* <mat-icon>more_vert</mat-icon>
|
|
|
|
* </button>
|
|
|
|
* </div>
|
2018-11-05 17:40:32 +01:00
|
|
|
* <!-- MultiSelect info -->
|
|
|
|
* <div class="central-info-slot">
|
|
|
|
* <button mat-icon-button (click)="toggleMultiSelect()">
|
|
|
|
* <mat-icon>arrow_back</mat-icon>
|
|
|
|
* </button>
|
|
|
|
* <span>{{ selectedRows.length }} </span><span translate>selected</span>
|
|
|
|
* </div>
|
2018-09-03 17:57:20 +02:00
|
|
|
* </os-head-bar>
|
2018-08-28 13:54:25 +02:00
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
@Component({
|
2018-09-03 17:57:20 +02:00
|
|
|
selector: 'os-head-bar',
|
2018-08-28 13:54:25 +02:00
|
|
|
templateUrl: './head-bar.component.html',
|
|
|
|
styleUrls: ['./head-bar.component.scss']
|
|
|
|
})
|
2018-11-06 15:35:51 +01:00
|
|
|
export class HeadBarComponent {
|
2018-10-05 16:34:08 +02:00
|
|
|
/**
|
|
|
|
* Determine if the the navigation "hamburger" icon should be displayed in mobile mode
|
|
|
|
*/
|
|
|
|
@Input()
|
|
|
|
public nav = true;
|
|
|
|
|
|
|
|
/**
|
2018-11-06 15:35:51 +01:00
|
|
|
* Custom icon if necessary
|
2018-10-05 16:34:08 +02:00
|
|
|
*/
|
|
|
|
@Input()
|
2018-11-08 17:38:44 +01:00
|
|
|
public mainButtonIcon = 'add';
|
2018-10-05 16:34:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine edit mode
|
2018-08-28 13:54:25 +02:00
|
|
|
*/
|
2018-09-19 15:18:57 +02:00
|
|
|
@Input()
|
2018-10-05 16:34:08 +02:00
|
|
|
public editMode = false;
|
2018-08-28 13:54:25 +02:00
|
|
|
|
2019-06-17 16:40:23 +02:00
|
|
|
/**
|
|
|
|
* The save button can manually be disabled.
|
|
|
|
*/
|
|
|
|
@Input()
|
|
|
|
public isSaveButtonEnabled = true;
|
|
|
|
|
2018-11-05 17:40:32 +01:00
|
|
|
/**
|
|
|
|
* Determine multiSelect mode: changed interactions and head bar
|
|
|
|
*/
|
|
|
|
@Input()
|
|
|
|
public multiSelectMode = false;
|
|
|
|
|
2018-08-28 13:54:25 +02:00
|
|
|
/**
|
2018-11-06 15:35:51 +01:00
|
|
|
* Determine if there should be the main action button
|
2018-08-28 13:54:25 +02:00
|
|
|
*/
|
2018-09-19 15:18:57 +02:00
|
|
|
@Input()
|
2018-11-06 15:35:51 +01:00
|
|
|
public mainButton = false;
|
2018-10-05 16:34:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set to true if the component should use location.back instead
|
|
|
|
* of navigating to the parent component
|
|
|
|
*/
|
|
|
|
@Input()
|
|
|
|
public goBack = false;
|
2018-08-28 13:54:25 +02:00
|
|
|
|
2019-03-08 10:43:54 +01:00
|
|
|
/**
|
|
|
|
* Determine the back URL. Default is ".." (previous parent page)
|
|
|
|
* Lazy Loaded modules sometimes have different routing events or require
|
|
|
|
* special "back" logic.
|
|
|
|
* Has only an effect if goBack is set to false
|
|
|
|
*/
|
|
|
|
@Input()
|
|
|
|
public prevUrl = '../';
|
|
|
|
|
2018-08-28 13:54:25 +02:00
|
|
|
/**
|
2018-11-06 15:35:51 +01:00
|
|
|
* Emit a signal to the parent component if the main button was clicked
|
2018-10-05 16:34:08 +02:00
|
|
|
*/
|
|
|
|
@Output()
|
2018-11-06 15:35:51 +01:00
|
|
|
public mainEvent = new EventEmitter<void>();
|
2018-10-05 16:34:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends a signal if a detail view should be saved
|
2018-08-28 13:54:25 +02:00
|
|
|
*/
|
2018-09-19 15:18:57 +02:00
|
|
|
@Output()
|
2018-10-05 16:34:08 +02:00
|
|
|
public saveEvent = new EventEmitter<boolean>();
|
2018-08-28 13:54:25 +02:00
|
|
|
|
2019-06-25 10:45:24 +02:00
|
|
|
public get showBackButton(): boolean {
|
2019-07-09 23:22:58 +02:00
|
|
|
return !this.nav && !this.multiSelectMode && (this.routingState.isSafePrevUrl || !this.goBack);
|
2019-06-25 10:45:24 +02:00
|
|
|
}
|
|
|
|
|
2018-08-28 13:54:25 +02:00
|
|
|
/**
|
|
|
|
* Empty constructor
|
|
|
|
*/
|
2018-10-05 16:34:08 +02:00
|
|
|
public constructor(
|
|
|
|
public vp: ViewportService,
|
|
|
|
private menu: MainMenuService,
|
|
|
|
private router: Router,
|
|
|
|
private route: ActivatedRoute,
|
2019-06-25 10:45:24 +02:00
|
|
|
private routingState: RoutingStateService
|
2018-10-05 16:34:08 +02:00
|
|
|
) {}
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
2018-10-05 16:34:08 +02:00
|
|
|
* Emits a signal to the parent if
|
2018-08-28 13:54:25 +02:00
|
|
|
*/
|
2018-11-06 15:35:51 +01:00
|
|
|
public sendMainEvent(): void {
|
|
|
|
this.mainEvent.next();
|
2018-10-05 16:34:08 +02:00
|
|
|
}
|
2018-08-28 13:54:25 +02:00
|
|
|
|
|
|
|
/**
|
2018-10-05 16:34:08 +02:00
|
|
|
* Clicking the burger-menu-icon should toggle the menu
|
2018-08-28 13:54:25 +02:00
|
|
|
*/
|
2018-10-05 16:34:08 +02:00
|
|
|
public clickHamburgerMenu(): void {
|
|
|
|
this.menu.toggleMenu();
|
2018-08-28 13:54:25 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 16:34:08 +02:00
|
|
|
/**
|
|
|
|
* Send a save signal and set edit mode
|
|
|
|
*/
|
|
|
|
public save(): void {
|
2018-11-06 15:35:51 +01:00
|
|
|
this.saveEvent.next(true);
|
2018-10-05 16:34:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exits the view to return to the previous page or
|
|
|
|
* visit the parent view again.
|
|
|
|
*/
|
|
|
|
public onBackButton(): void {
|
|
|
|
if (this.goBack) {
|
2019-06-25 10:45:24 +02:00
|
|
|
this.router.navigateByUrl(this.routingState.previousUrl);
|
2018-10-05 16:34:08 +02:00
|
|
|
} else {
|
2019-03-08 10:43:54 +01:00
|
|
|
this.router.navigate([this.prevUrl], { relativeTo: this.route });
|
2018-10-05 16:34:08 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-28 13:54:25 +02:00
|
|
|
}
|