aboutsummaryrefslogtreecommitdiffstats
path: root/src/angular/tag-cloud/tag-cloud.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/angular/tag-cloud/tag-cloud.component.ts')
-rw-r--r--src/angular/tag-cloud/tag-cloud.component.ts46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/angular/tag-cloud/tag-cloud.component.ts b/src/angular/tag-cloud/tag-cloud.component.ts
new file mode 100644
index 0000000..1635b8d
--- /dev/null
+++ b/src/angular/tag-cloud/tag-cloud.component.ts
@@ -0,0 +1,46 @@
+import { Component, EventEmitter, Input, Output } from "@angular/core";
+import template from "./tag-cloud.component.html";
+
+@Component({
+ selector: 'sdc-tag-cloud',
+ template: template,
+})
+export class TagCloudComponent {
+ @Input() public list: string[];
+ @Input() public isViewOnly: boolean|number[]; // get a boolean parameter or array of specific items indexes.
+ @Input() public isUniqueList: boolean;
+ @Input() public uniqueErrorMessage: string = "Unique error";
+ @Input() public label: string;
+ @Input() public placeholder: string;
+ @Output() public listChanged: EventEmitter<string[]> = new EventEmitter<string[]>();
+ private newTagItem: string;
+ private uniqueError: boolean;
+
+ private onKeyup = (e): void => {
+ if (e.keyCode === 13) {
+ this.insertItemToList();
+ }
+ }
+
+ private insertItemToList = (): void => {
+ this.validateTag();
+ if (!this.uniqueError && this.newTagItem.length) {
+ this.list.push(this.newTagItem);
+ this.newTagItem = "";
+ this.listChanged.emit(this.list);
+ }
+ }
+
+ private deleteItemFromList = (index: number): void => {
+ this.list.splice(index, 1);
+ if (Array.isArray(this.isViewOnly)) {
+ this.isViewOnly = this.isViewOnly.map((i: number) => {
+ return i > index ? i - 1 : i;
+ });
+ }
+ }
+
+ private validateTag = (): void => {
+ this.uniqueError = this.list && this.list.indexOf(this.newTagItem) > -1;
+ }
+}