Skip to content

Commit

Permalink
feat(context): copy context id
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarbeau committed Jul 8, 2020
1 parent 97d8229 commit d3391e6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@
<span class="fieldWrapper">
<input matInput
maxlength="64"
floatLabel = "always"
[placeholder]="'igo.context.contextManager.form.uri' | translate"
formControlName="uri">
</span>
</mat-form-field>

<button
id="copyButton"
type="button"
mat-icon-button
tooltip-position="below"
matTooltipShowDelay="500"
[matTooltip]="'igo.context.contextManager.form.copy' | translate"
color="primary"
(click)="copyTextToClipboard()">
<mat-icon svgIcon="content-copy"></mat-icon>
</button>

<div class="igo-form-button-group">
<button
mat-raised-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ form {
float: left;
}
}

#copyButton {
width: 24px;
float: right;
position: relative;
top: -58px;
left: 5px;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Component, Input, Output, EventEmitter, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';

import { ObjectUtils } from '@igo2/utils';
import { ObjectUtils, Clipboard } from '@igo2/utils';
import { MessageService, LanguageService } from '@igo2/core';
import { Context } from '../shared/context.interface';

@Component({
Expand Down Expand Up @@ -46,7 +47,11 @@ export class ContextFormComponent implements OnInit {
@Output() clone: EventEmitter<any> = new EventEmitter();
@Output() delete: EventEmitter<any> = new EventEmitter();

constructor(private formBuilder: FormBuilder) {}
constructor(
private formBuilder: FormBuilder,
private languageService: LanguageService,
private messageService: MessageService
) {}

ngOnInit(): void {
this.buildForm();
Expand All @@ -64,6 +69,21 @@ export class ContextFormComponent implements OnInit {
this.submitForm.emit(inputs);
}

public copyTextToClipboard() {
const text = this.prefix + '-' + this.form.value.uri.replace(' ', '');
const successful = Clipboard.copy(text);
if (successful) {
const translate = this.languageService.translate;
const title = translate.instant(
'igo.context.contextManager.dialog.copyTitle'
);
const msg = translate.instant(
'igo.context.contextManager.dialog.copyMsg'
);
this.messageService.success(msg, title);
}
}

private buildForm(): void {
const context: any = this.context || {};

Expand Down
3 changes: 3 additions & 0 deletions packages/context/src/locale/en.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"dialog": {
"cloneMsg": "The context '{{value}}' was cloned",
"cloneTitle": "Context cloned",
"copyMsg": "Text copied",
"copyTitle": "Context ID",
"confirmDelete": "Are you sure you want to delete this context?",
"deleteMsg": "The context '{{value}}' was deleted",
"deleteTitle": "Context deleted",
Expand All @@ -36,6 +38,7 @@
},
"favorite": "Set as favorite context",
"form": {
"copy": "Copy the context ID",
"edit": "Save",
"title": "Title",
"titleRequired": "Title required",
Expand Down
3 changes: 3 additions & 0 deletions packages/context/src/locale/fr.context.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"dialog": {
"cloneMsg": "Le contexte '{{value}}' a été cloné",
"cloneTitle": "Contexte cloné",
"copyMsg": "Texte copié",
"copyTitle": "Identifiant du contexte",
"confirmDelete": "Êtes-vous sûr de vouloir supprimer ce contexte ?",
"deleteMsg": "Le contexte '{{value}}' a été supprimé",
"deleteTitle": "Contexte supprimé",
Expand All @@ -36,6 +38,7 @@
},
"favorite": "Définir comme context favori",
"form": {
"copy": "Copier l'identifiant du contexte",
"edit": "Enregistrer",
"title": "Titre",
"titleRequired": "Le titre est obligatoire",
Expand Down

0 comments on commit d3391e6

Please sign in to comment.