File

src/app/core/ui/latest-changes/latest-changes-dialog.service.ts

Description

Manage the changelog information and display it to the user on request or automatically on the first visit of a new version after update.

Index

Properties
Methods

Constructor

constructor(dialog: MatDialog, latestChangesService: LatestChangesService)
Parameters :
Name Type Optional
dialog MatDialog No
latestChangesService LatestChangesService No

Methods

getCurrentVersion
getCurrentVersion()

Get current app version inferred from the latest changelog entry.

Returns : string
Public showLatestChanges
showLatestChanges(previousVersion?: string)

Open a modal window displaying the changelog of the latest version.

Parameters :
Name Type Optional Description
previousVersion string Yes

(Optional) previous version back to which all changes should be displayed

Returns : void
Public showLatestChangesIfUpdated
showLatestChangesIfUpdated()

Display the latest changes info box automatically if the current user has not seen this version before.

Returns : void

Properties

Static Readonly VERSION_KEY
Type : string
Default value : "AppVersion"
import { Injectable } from "@angular/core";
import { MatDialog } from "@angular/material/dialog";
import { ChangelogComponent } from "./changelog/changelog.component";
import { environment } from "../../../../environments/environment";
import { LatestChangesService } from "./latest-changes.service";

/**
 * Manage the changelog information and display it to the user
 * on request or automatically on the first visit of a new version after update.
 */
@Injectable({ providedIn: "root" })
export class LatestChangesDialogService {
  public static readonly VERSION_KEY = "AppVersion";

  constructor(
    private dialog: MatDialog,
    private latestChangesService: LatestChangesService,
  ) {}

  /**
   * Get current app version inferred from the latest changelog entry.
   */
  getCurrentVersion(): string {
    return environment.appVersion;
  }

  /**
   * Open a modal window displaying the changelog of the latest version.
   * @param previousVersion (Optional) previous version back to which all changes should be displayed
   */
  public showLatestChanges(previousVersion?: string): void {
    this.dialog
      .open(ChangelogComponent, {
        width: "80%",
        data: this.latestChangesService.getChangelogsBetweenVersions(
          this.getCurrentVersion(),
          previousVersion,
        ),
      })
      .afterClosed()
      .subscribe(() => this.updateCurrentVersion());
  }

  private updateCurrentVersion() {
    window.localStorage.setItem(
      LatestChangesDialogService.VERSION_KEY,
      this.getCurrentVersion(),
    );
  }

  /**
   * Display the latest changes info box automatically if the current user has not seen this version before.
   */
  public showLatestChangesIfUpdated() {
    const previousVersion = window.localStorage.getItem(
      LatestChangesDialogService.VERSION_KEY,
    );
    if (previousVersion && this.getCurrentVersion() !== previousVersion) {
      this.showLatestChanges(previousVersion);
    }
  }
}

results matching ""

    No results matching ""