File

projects/web-mev/src/app/features/workarea/workarea.component.ts

Description

Workarea Component

Container component. Used to display 2 tabs for File Manager and Workspace Manager

Implements

OnInit

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector mev-workarea
styleUrls ./workarea.component.scss
templateUrl ./workarea.component.html

Index

Properties
Methods

Constructor

constructor()

Methods

goToNextTab
goToNextTab()

Method is triggered when the user clicks the Next button to show the next tab

Returns : void
ngAfterViewInit
ngAfterViewInit()

Gets the default tab from local storage

Returns : void
ngOnInit
ngOnInit()
Returns : void
onTabChange
onTabChange(event: MatTabChangeEvent)

Method is triggered when the user switched between tab and saves the active tab to local storage

Parameters :
Name Type Optional
event MatTabChangeEvent No
Returns : void

Properties

Private Readonly API_NAME
Default value : environment.appName
selectedTabIndex
Type : number
Default value : 0
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { MatTabChangeEvent } from '@angular/material/tabs';
import { environment } from '@environments/environment';

/**
 * Workarea Component
 *
 * Container component. Used to display 2 tabs for File Manager and Workspace Manager
 */

@Component({
  selector: 'mev-workarea',
  templateUrl: './workarea.component.html',
  styleUrls: ['./workarea.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class WorkareaComponent implements OnInit {
  private readonly API_NAME = environment.appName;
  selectedTabIndex = 0; // the first tab is default
  constructor() {}

  ngOnInit(): void {}

  /**
   * Gets the default tab from local storage
   */

  ngAfterViewInit() {
    const index =
      localStorage.getItem(`${this.API_NAME}selectedTab`) ||
      this.selectedTabIndex;
    this.selectedTabIndex = Number(index);
  }

  /**
   * Method is triggered when the user clicks the Next button to show the next tab
   */

  goToNextTab() {
    this.selectedTabIndex = 1; // update tab index
  }

  /**
   * Method is triggered when the user switched between tab and saves the active tab to local storage
   */

  onTabChange(event: MatTabChangeEvent) {
    localStorage.setItem(`${this.API_NAME}selectedTab`, String(event.index));
  }
}
<section class="workarea">
  <mat-tab-group animationDuration="0ms" color="accent" (selectedTabChange)="onTabChange($event)" [(selectedIndex)]="selectedTabIndex">
    <mat-tab>
      <ng-template mat-tab-label>
        <mat-icon class="tab-icon">file_copy</mat-icon>
        Files
      </ng-template>
      <mev-file-list></mev-file-list>
    </mat-tab>

    <mat-tab>
      <ng-template mat-tab-label>
        <mat-icon class="tab-icon">work</mat-icon>
        Workspaces
      </ng-template>
      <mev-workspace-list></mev-workspace-list>
    </mat-tab>

  </mat-tab-group>
</section>

<div class="workarea-footer" *ngIf="selectedTabIndex == 0">
  <button mat-raised-button color="accent" (click)="goToNextTab()">
    Next
    <mat-icon aria-label="Next step">navigate_next</mat-icon>
  </button>
</div>

./workarea.component.scss

.workarea {
  margin: 20px;
}
.mat-tab-group {
  margin-bottom: 48px;
}
.tab-icon {
  margin-right: 8px;
}

.workarea-footer {
  float: right;
  padding: 20px;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""