Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(about-tool): Open guide on new tab / add menu if multiple #833

Merged
merged 4 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,33 @@
[discoverTitleInLocale$]="discoverTitleInLocale$">
</igo-interactive-tour>

<button *ngIf="auth.authenticated"
<button *ngIf="auth.authenticated && trainingGuideURLs && trainingGuideURLs.length === 1"
class="training-guide-button"
mat-raised-button
tooltip-position="below"
matTooltipShowDelay="500"
[disabled]="!trainingGuideURLs || !trainingGuideURLs.length"
[disabled]="!trainingGuideURLs.length"
[matTooltip]="'igo.integration.aboutTool.trainingGuideTooltip' | translate"
(click)="openGuide()">
<span>{{'igo.integration.aboutTool.trainingGuide' | translate}}</span>
<mat-icon svgIcon="file-document"></mat-icon>
</button>

<button *ngIf="auth.authenticated && trainingGuideURLs && trainingGuideURLs.length > 1"
class="training-guide-button"
mat-raised-button
tooltip-position="below"
matTooltipShowDelay="500"
[matTooltip]="'igo.integration.aboutTool.trainingGuideTooltip' | translate"
[matMenuTriggerFor]="menu">
<span>{{'igo.integration.aboutTool.trainingGuide' | translate}}</span>
<mat-icon svgIcon="file-document"></mat-icon>
</button>

<mat-menu #menu="matMenu">
<button *ngFor="let guide of trainingGuideURLs" mat-menu-item (click)="openGuide(guide)">{{formatFileName(guide)}}</button>
</mat-menu>

<igo-custom-html class="mat-typography"
[html]="html |  translate: {version: version}">
</igo-custom-html>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class AboutToolComponent implements OnInit {
this.discoverTitleInLocale$ = of(value);
}

public trainingGuideURLs;
@Input() trainingGuideURLs;

public version: Version;
private _html: string = 'igo.integration.aboutTool.html';
Expand All @@ -56,28 +56,37 @@ export class AboutToolComponent implements OnInit {
}

ngOnInit() {
this.http.get(this.baseUrlProfil).subscribe((profil) => {
const recast = profil as any;
this.trainingGuideURLs = recast.guides;
this.cdRef.detectChanges();
if (this.auth.authenticated && this.configService.getConfig('context.url')) {
this.http.get(this.baseUrlProfil).subscribe((profil) => {
const recast = profil as any;
this.trainingGuideURLs = recast.guides;
this.cdRef.detectChanges();
});
} else if (
this.auth.authenticated &&
!this.configService.getConfig('context.url') &&
this.configService.getConfig('depot.trainingGuides')) {
this.trainingGuideURLs = this.configService.getConfig('depot.trainingGuides');
}
}

openGuide(guide?) {
const url = guide ?
this.baseUrlGuide + guide + '?' :
this.baseUrlGuide + this.trainingGuideURLs[0] + '?';
this.http
.get(url, {
responseType: 'blob'
})
.subscribe(() => {
window.open(url, '_blank');
});
}

openGuide() {
for (const trainingGuideURL of this.trainingGuideURLs) {
this.http
.get(this.baseUrlGuide + trainingGuideURL + '?', {
responseType: 'blob'
})
.subscribe((response) => {
const blob = new Blob([response]);
const url = window.URL.createObjectURL(blob);
const anchor = document.createElement('a');
anchor.href = url;
anchor.download = trainingGuideURL;
anchor.click();
URL.revokeObjectURL(url);
});
}
formatFileName(name: string) {
name = name.split('_').join(' ');
const index = name.indexOf('.');
name = name.slice(0, index);
return name;
}
}
2 changes: 2 additions & 0 deletions packages/integration/src/lib/about/about.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CommonModule } from '@angular/common';
import { MatTooltipModule } from '@angular/material/tooltip';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatMenuModule } from '@angular/material/menu';

import { IgoLanguageModule } from '@igo2/core';
import { IgoCustomHtmlModule, IgoInteractiveTourModule } from '@igo2/common';
Expand All @@ -20,6 +21,7 @@ import { AboutToolComponent } from './about-tool/about-tool.component';
MatButtonModule,
MatTooltipModule,
MatIconModule,
MatMenuModule,
IgoInteractiveTourModule,
CommonModule
],
Expand Down