Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 12.3: Implemented the events in the UI
- Loading branch information
1 parent
d1499ba
commit 43f0354
Showing
2 changed files
with
88 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,112 @@ | ||
import {Component, OnInit} from "@angular/core"; | ||
import {ActivatedRoute, Params} from "@angular/router"; | ||
import {ActivatedRoute, Params, Router} from "@angular/router"; | ||
import {MeteorObservable} from "meteor-rxjs"; | ||
import {Lists} from "../../../imports/api/lists/lists"; | ||
import { | ||
updateName, | ||
makePublic, | ||
makePrivate, | ||
remove, | ||
insert, | ||
} from '../../../imports/api/todos/methods'; | ||
import { displayError } from '../../../imports/ui/lib/errors'; | ||
import {Observable} from "rxjs"; | ||
|
||
@Component({ | ||
template: '<blaze-template *ngIf="templateContext" name="Lists_show_page" [context]="templateContext"></blaze-template>' | ||
templateUrl: '/client/imports/components/list-show.html' | ||
}) | ||
export class ListShowComponent implements OnInit { | ||
private list : any; | ||
private todosReady : boolean = false; | ||
private todos : Array<any>; | ||
private todos : Observable<any>; | ||
private editing : boolean = false; | ||
private editModel : any; | ||
private newItemModel : string = ''; | ||
|
||
constructor(private currentRoute: ActivatedRoute) { | ||
|
||
constructor(private currentRoute: ActivatedRoute, private router: Router) { | ||
this.editModel = { | ||
name: '' | ||
} | ||
} | ||
|
||
ngOnInit() { | ||
this.currentRoute.params.subscribe((params: Params) => { | ||
const listId = params['_id']; | ||
MeteorObservable.subscribe('todos.inList', listId).subscribe(); | ||
MeteorObservable.subscribe('todos.inList', listId).zone().subscribe(); | ||
|
||
MeteorObservable.autorun().zone().subscribe(() => { | ||
if (listId && Lists.findOne(listId)) { | ||
this.list = Lists.findOne(listId); | ||
this.todosReady = true; | ||
this.todos = this.list.todos(); | ||
this.todos = this.list.todos().zone(); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
deleteList() { | ||
const list = this.list; | ||
const message = `Are you sure you want to delete the list?`; | ||
|
||
if (confirm(message)) { | ||
remove.call({ | ||
listId: list._id, | ||
}, displayError); | ||
|
||
this.router.navigate(['Home']); | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
editList(toggle) { | ||
this.editModel.name = this.list.name; | ||
this.editing = toggle; | ||
} | ||
|
||
toggleListPrivacy() { | ||
const list = this.list; | ||
|
||
if (list.userId) { | ||
makePublic.call({ listId: list._id }, displayError); | ||
} else { | ||
makePrivate.call({ listId: list._id }, displayError); | ||
} | ||
} | ||
|
||
addNew() { | ||
if (this.newItemModel == '') { | ||
return; | ||
} | ||
|
||
insert.call({ | ||
listId: this.list._id, | ||
text: this.newItemModel, | ||
}, displayError); | ||
|
||
this.newItemModel = ''; | ||
} | ||
|
||
saveList() { | ||
if (this.editing) { | ||
updateName.call({ | ||
listId: this.list._id, | ||
newName: this.editModel.name, | ||
}, displayError); | ||
|
||
this.editing = false; | ||
} | ||
} | ||
|
||
getContextForItem(todo) { | ||
return { | ||
todo: todo, | ||
editing: false, | ||
onEditingChange(editing) { | ||
todo: todo, | ||
editing: false, | ||
onEditingChange(editing) { | ||
|
||
}, | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters