import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { AlertController, ToastController, Events } from 'ionic-angular';
import { ColorTag, ColorTagUtil } from '@canvuus-internal/mvp0-task-core';
@Component({
selector: 'mini-color-dot',
template: `
`
})
//
export class MiniColorDotComponent implements OnInit {
colorTag: ColorTag;
@Input("cell-size") cellSize: number;
// gridSize: number;
@Input("color-tag") itemCTag: string;
// If set to true (typically, but not always, because the associated task is disabled or done, etc.)
// we display the "grayscale" image rather than the original color version.
@Input("grayscale") isGrayscale: boolean;
// To avoid error when colorTag is not properly set.
get color0(): string {
if(this.isGrayscale) {
return (this.colorTag && this.colorTag.grayscaleColors && this.colorTag.grayscaleColors.length > 0) ? this.colorTag.grayscaleColors[0].toString() : "#ffffff";
} else {
return (this.colorTag && this.colorTag.colors && this.colorTag.colors.length > 0) ? this.colorTag.colors[0].toString() : "#ffffff";
}
}
get color1(): string {
if(this.isGrayscale) {
return (this.colorTag && this.colorTag.grayscaleColors && this.colorTag.grayscaleColors.length > 1) ? this.colorTag.grayscaleColors[1].toString() : "#ffffff";
} else {
return (this.colorTag && this.colorTag.colors && this.colorTag.colors.length > 1) ? this.colorTag.colors[1].toString() : "#ffffff";
}
}
get color3(): string {
if(this.isGrayscale) {
return (this.colorTag && this.colorTag.grayscaleColors && this.colorTag.grayscaleColors.length > 3) ? this.colorTag.grayscaleColors[3].toString() : "#ffffff";
} else {
return (this.colorTag && this.colorTag.colors && this.colorTag.colors.length > 3) ? this.colorTag.colors[3].toString() : "#ffffff";
}
}
get color4(): string {
if(this.isGrayscale) {
return (this.colorTag && this.colorTag.grayscaleColors && this.colorTag.grayscaleColors.length > 4) ? this.colorTag.grayscaleColors[4].toString() : "#ffffff";
} else {
return (this.colorTag && this.colorTag.colors && this.colorTag.colors.length > 4) ? this.colorTag.colors[4].toString() : "#ffffff";
}
}
constructor(private alertCtrl: AlertController,
private toastCtrl: ToastController,
private events: Events) {
// console.log('Hello MiniColorDot Component');
// testing...
// this.colorTag = ColorTagUtil.randomColorTag();
this.colorTag = ColorTag.BW_CHECKER_BOARD_A;
// this.cellSize = 8;
this.cellSize = 12;
// this.gridSize = 2 * this.cellSize;
this.isGrayscale = false;
}
ngOnInit() {
// variables can be read here....
// console.log(">>>>>> this.cellSize = " + this.cellSize);
// console.log(">>>>>> this.gridSize = " + this.gridSize);
if(this.itemCTag) {
let colorTag = ColorTag.fromString(this.itemCTag);
this.colorTag = colorTag;
}
}
}