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(page: detail): can add tags to item #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions src/app/pages/main/detail/detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@
</div>
<label nz-checkbox (click)="$event.stopPropagation()" [(ngModel)]="currentTodo.completedFlag"></label>
<span>标记完成</span>
<nz-divider nzText="标签" nzOrientation="left"></nz-divider>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag has no superior priority to title and date. It should be placed after date and before description.

<div class="input-container">
<nz-tag
*ngFor="let tagName of currentTodo.tags; let i = index"
nzMode="closeable"
(nzAfterClose)="handleTagClose(i)">{{ tagName }}</nz-tag>
<nz-tag
*ngIf="!addTagInputVisible"
class="editable-tag"
(click)="showAddTagInput()">
<i class="anticon anticon-plus"></i> New Tag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Chinese for now. i18n would be introduced later.

</nz-tag>
<input
*ngIf="addTagInputVisible"
#tagNameInput
style="width: 78px;"
nz-input
[(ngModel)]="newTagName"
nzSize="small"
(blur)="handleAddTagConfirm()"
(keyup.enter)="handleAddTagConfirm()">
</div>
<nz-divider nzText="标题" nzOrientation="left"></nz-divider>
<div class="input-container">
<input nz-input [(ngModel)]="currentTodo.title" placeholder="待办事项" [disabled]="!!currentTodo.completedFlag" id="title" name="title">
Expand Down
29 changes: 27 additions & 2 deletions src/app/pages/main/detail/detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
EventEmitter,
OnInit,
Output,
HostBinding
HostBinding,
ViewChild,
ElementRef
} from '@angular/core';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { first } from 'rxjs/operators';
Expand All @@ -23,11 +25,15 @@ import { detailTransition } from './detail.animation';
export class DetailComponent implements OnInit {
@HostBinding('@detailTransition') state = 'activated';
@Output() changedTodo = new EventEmitter();
@ViewChild('tagNameInput') tagNameInput: ElementRef;

private trueSource: Todo;
currentTodo: Todo;
dueDate: Date;
planDate: Date;
tags: string[];
addTagInputVisible = false;
newTagName = '';

constructor(
private route: ActivatedRoute,
Expand All @@ -41,7 +47,7 @@ export class DetailComponent implements OnInit {
const id = paramsMap.get('id');
const todo = this.todoService.getByUUID(id);
this.trueSource = todo;
this.currentTodo = Object.assign({}, todo) as Todo;
this.currentTodo = { ...todo, tags: [...(todo.tags || [])] };
if (todo.dueAt) {
this.dueDate = new Date(todo.dueAt);
}
Expand Down Expand Up @@ -105,4 +111,23 @@ export class DetailComponent implements OnInit {
this.todoService.delete(this.currentTodo._id);
this.goBack();
}

showAddTagInput(): void {
this.addTagInputVisible = true;
setTimeout(() => {
this.tagNameInput.nativeElement.focus();
}, 10);
}

handleAddTagConfirm(): void {
if (this.newTagName && this.currentTodo.tags.indexOf(this.newTagName) === -1) {
this.currentTodo.tags.push(this.newTagName);
}
this.newTagName = '';
this.addTagInputVisible = false;
}

handleTagClose(index: number): void {
this.currentTodo.tags.splice(index, 1);
}
}
1 change: 1 addition & 0 deletions src/app/pages/main/right-control/todo/todo.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ng-template #nzTitle>
<label nz-checkbox (click)="$event.stopPropagation()" [(ngModel)]="item.completedFlag" (ngModelChange)="toggle(item._id)"></label>
<span [class.strikethrough]="item.completedFlag">{{ item.title }}</span>
<nz-tag *ngFor="let tagName of item.tags">{{ tagName }}</nz-tag>
</ng-template>
<ng-template #nzDescription>
<span *ngIf="item.dueAt" class="todo-desc">
Expand Down
1 change: 1 addition & 0 deletions src/domain/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class Todo {
dueAt: number;
planAt: number;
notifyMe = false;
tags: string[] = [];

constructor(title: string, listUUID?: string) {
this._id = generateUUID();
Expand Down