import { Component, ViewChild, Input, Output, EventEmitter } from '@angular/core'; import { OnInit, OnDestroy } from '@angular/core'; import { AlertController, ToastController, Events } from 'ionic-angular'; import { ColorTag, ColorTagUtil, DateIdUtil } from '@canvuus-internal/mvp0-task-core'; import { TaskItem, TaskStatus, TaskBit } from '@canvuus-internal/mvp0-task-data'; import { CommonColorTagComponent } from '@canvuus-internal/mvp0-task-view'; import { TaskEvents } from '../../common/events/task-events'; @Component({ selector: 'mvp0-task-card', // templateUrl: 'mvp0-task-card.html', template: ` {{itemPriority}} {{itemTitle}}

{{targetDateString}}

{{itemDescription}}

` }) export class Mvp0TaskCardComponent implements OnInit, OnDestroy { @ViewChild("itemColorTag") itemColorTag: CommonColorTagComponent; @Input("iid") itemId: string; @Input("ictag") itemCTag: string; // ColorTag.toString() @Input("ititle") itemTitle: string; @Input("ipriority") itemPriority: number; @Input("itargetdate") itemTargetDate: string; // date id. @Input("iduedate") itemDueDate: string; // date id. @Input("idescription") itemDescription: string; @Input("color-prioritybadge") colorPriorityBadge: string; @Input("color-openbutton") colorOpenButton: string; @Input("size-openbutton") sizeOpenButton: string; @Input("show-openbutton") showOpenTaskButton: boolean; @Input("show-doitbutton") showDoItButton: boolean; @Input("show-donebutton") showMarkAsDoneButton: boolean; @Input("show-deferbutton") showDeferTaskButton: boolean; @Input("show-backlogbutton") showMoveToBacklogButton: boolean; @Input("show-deletebutton") showDeleteTaskButton: boolean; @Input("show-editbutton") showEditTaskButton: boolean; @Input("grayscale") isGrayscale: boolean; // For display. targetDateString: string; dueDateString: string; // Currently, not being used. isOpenButtonLarge: boolean; // isOpenButtonLarge: any; constructor(private alertCtrl: AlertController, private toastCtrl: ToastController, private events: Events) { // console.log('Hello Mvp0TaskCard Component'); // Default values. this.targetDateString = ''; this.dueDateString = ''; this.colorPriorityBadge = 'primary'; this.colorOpenButton = 'primary'; this.isOpenButtonLarge = false; // this.isOpenButtonLarge = null; this.showOpenTaskButton = true; this.showDoItButton = false; this.showMarkAsDoneButton = true; this.showDeferTaskButton = true; this.showMoveToBacklogButton = true; this.showDeleteTaskButton = true; this.showEditTaskButton = false; // False by default. this.isGrayscale = false; // // temporary // this.data = new TaskItem(null); // // this.itemColorTag.colorTag = this.data.colorTag; // // .... // this does not work // console.log(">>>>>> taskItemId = " + this.itemId); // // This seems to be needed to avoid the null pointr exception on the UI.... // this.itemCTag = ColorTagUtil.randomColorTag().toString(); // // if(this.itemColorTag) { // // let colorTag = ColorTagUtil.randomColorTag(); // // this.itemColorTag.colorTag = colorTag; // // } } ngOnInit() { // console.log('::: ngOnInit()'); // variables can be read here.... // console.log(">>>>>> this.itemId = " + this.itemId); // console.log(">>>>>> this.itemCTag = " + this.itemCTag); // console.log(">>>>>> this.itemTargetDate = " + this.itemTargetDate); // console.log(">>>>>> this.itemTitle = " + this.itemTitle); // console.log(">>>>>> this.itemDescription = " + this.itemDescription); // console.log(">>>>>> this.showOpenTaskButton = " + this.showOpenTaskButton); // TBD: this does not work.... // -> This logic has been moved to somewhere else. // // If targetDate is today, hide the "do it today" button. // if(this.showOpenTaskButton) { // let todayId = DateIdUtil.getTodayId(); // if(this.itemTargetDate == todayId) { // this.showOpenTaskButton = false; // } // } // TBD: // Do not save it. // Just for display. if (!this.itemTitle) { this.itemTitle = "(Task)"; // ??? } if(!this.itemPriority) { this.itemPriority = 0; // ??? } // .... // TBD: if(this.itemTargetDate) { this.targetDateString = DateIdUtil.getLocaleDateString(this.itemTargetDate); } else { this.targetDateString = ''; } if(this.itemDueDate) { this.dueDateString = DateIdUtil.getLocaleDateString(this.itemDueDate); } else { this.dueDateString = ''; } // testing.... // tbd: use @Input ???? if (this.itemColorTag) { let colorTag: ColorTag; if(this.itemCTag) { colorTag = ColorTag.fromString(this.itemCTag); } else { colorTag = ColorTag.BW_SILVER_SQUARE; // ??? } this.itemColorTag.colorTag = colorTag; } // ... // temporary // For now, we only check "large"... if(this.sizeOpenButton) { if(this.sizeOpenButton == "large") { this.isOpenButtonLarge = true; } else { this.isOpenButtonLarge = false; // this.isOpenButtonLarge = null; } } } ngOnDestroy() { // console.log('::: ngOnDestroy()'); } // // Not being used. // displayViewTaskPage() { // console.log('displayViewTaskPage(). this.itemId = ' + this.itemId); // this.events.publish(TaskEvents.MVP0_UI_TASK_ENTRY_VIEW, this.itemId); // } // doItToday() { // console.log('doItToday(). this.itemId = ' + this.itemId); // this.events.publish(TaskEvents.MVP0_UI_TASK_ENTRY_DOIT, this.itemId); // } // // Not being used. openThisItem() { // console.log('openThisItem(). this.itemId = ' + this.itemId); this.events.publish(TaskEvents.MVP0_UI_TASK_CARD_OPEN_TASK, this.itemId); } openTaskDetail() { // console.log('openTaskDetail(). this.itemId = ' + this.itemId); this.events.publish(TaskEvents.MVP0_UI_TASK_CARD_TASK_DETAIL, this.itemId); } doItToday() { // console.log('doItToday(). this.itemId = ' + this.itemId); this.events.publish(TaskEvents.MVP0_UI_TASK_CARD_ACTION_DOIT, this.itemId); } markAsDone() { // console.log('markAsDone(). this.itemId = ' + this.itemId); this.events.publish(TaskEvents.MVP0_UI_TASK_CARD_ACTION_DONE, this.itemId); } deferTillTomorrow() { // console.log('deferTillTomorrow(). this.itemId = ' + this.itemId); this.events.publish(TaskEvents.MVP0_UI_TASK_CARD_ACTION_DEFER, this.itemId); } moveToBacklog() { // console.log('moveToBacklog(). this.itemId = ' + this.itemId); this.events.publish(TaskEvents.MVP0_UI_TASK_CARD_ACTION_BACKLOG, this.itemId); } editThisItem() { // console.log('editThisItem(). this.itemId = ' + this.itemId); this.events.publish(TaskEvents.MVP0_UI_TASK_CARD_ACTION_EDIT, this.itemId); } deleteThisItem() { // console.log('deleteThisItem(). this.itemId = ' + this.itemId); this.events.publish(TaskEvents.MVP0_UI_TASK_CARD_ACTION_DELETE, this.itemId); } }