Permalink
Browse files

got more things working

did alot of shit
  • Loading branch information...
Rikuoe91 committed Oct 11, 2017
1 parent 41d7999 commit 0f527bebbb21c485581ce0c14c20cedcbe45c85e
@@ -7,7 +7,7 @@
<ion-header>
<ion-navbar color="secondary">
<ion-title>Checklist Title</ion-title>
<ion-title>{{checklist.title}}</ion-title>
<ion-buttons end>
<button icon-only (click)="uncheckItem()">
<ion-icon name="refresh-circle">
@@ -25,18 +25,18 @@
<ion-content>
<ion-list no-lines>
<ion-item-sliding>
<ion-item-sliding *ngFor="let item of checklist.items">
<ion-item>
<ion-label>Item Title</ion-label>
<ion-checkbox (click)="toggleItem()"></ion-checkbox>
<ion-label>{{item.title}}</ion-label>
<ion-checkbox [checked] (click)="toggleItem(item)"></ion-checkbox>
</ion-item>
<ion-item-options>
<button ion-button icon-only color="light" (click)="renameItem(item)">
<ion-icon name="clipboard">edit</ion-icon>
<ion-icon name="clipboard"></ion-icon>
</button>
<button ion-button icon-only color="danger" (click)="removeItem(item)">
<ion-icon name="trash">Delete</ion-icon>
<ion-icon name="trash"></ion-icon>
</button>
</ion-item-options>
</ion-item-sliding>
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {Component} from '@angular/core';
import {AlertController, IonicPage, Keyboard, NavController, NavParams, Platform} from 'ionic-angular';
/**
* Generated class for the ChecklistPage page.
@@ -10,16 +10,80 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-checklist',
templateUrl: 'checklist.html',
selector: 'page-checklist',
templateUrl: 'checklist.html',
providers: [Keyboard]
})
export class ChecklistPage {
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
checklist: any;
ionViewDidLoad() {
console.log('ionViewDidLoad ChecklistPage');
}
constructor(public navCtrl: NavController, public navParams: NavParams, public alertCtrl: AlertController,) {
this.checklist = this.navParams.get('checklist');
}
addItem(): void {
let prompt = this.alertCtrl.create({
title: "Add Item",
message: "Enter the name of your new Item Below",
inputs: [{
name: 'name'
}
], buttons: [{
text: 'cancel'
}, {
text: 'save',
handler: data => {
this.checklist.addItem(data.name)
}
}
]
});
prompt.present();
}
removeItem(item): void {
this.checklist.removeItem(item);
}
renameItem(item): void {
let prompt = this.alertCtrl.create({
title: "Rename Item",
message: "Rename your Item down below",
inputs: [{
name: 'name'
}
], buttons: [{
text: 'cancel'
}, {
text: 'save',
handler: data => {
this.checklist.renameItem(item, data.name);
}
}
]
});
prompt.present();
}
toggleItem(item): void {
this.checklist.toggleItem(item);
}
uncheckItem(): void {
this.checklist.items.forEach((item) => {
if (item.checked) {
this.checklist.toggleItem(item);
}
})
}
}
View
@@ -16,7 +16,7 @@
<ion-item-sliding *ngFor="let checklist of checkLists">
<button ion-item (click)="viewCheckList(checklist)">
{{checklist.title}}
<span>{{checklist.items.lenght}} items</span>
<span>{{checklist.items.length}} items</span>
</button>
<ion-item-options >
View
@@ -21,9 +21,34 @@ export class HomePage {
}
ionViewDidLoad() {
this.platform.ready().then(() => {
this.dataService.getData().then((checklists) => {
let savedChecklists: any = false;
if (typeof(checklists) != "undefined") {
savedChecklists = JSON.parse(checklists)
}
if (savedChecklists) {
savedChecklists.forEach((savedChecklists) => {
let loadChecklist = new ChecklistModel(savedChecklists.title, savedChecklists.items);
this.checkLists.push((loadChecklist));
loadChecklist.checkListUpdate().subscribe(update => {
this.save();
})
})
}
})
})
}
addChecklist(): void {
let prompt = this.alertCtrl.create({
@@ -80,22 +105,23 @@ export class HomePage {
}
viewCheckList(checklist): void {
this.navCtrl.push('CheckListPage', {
this.navCtrl.push('ChecklistPage', {
checklist: checklist
})
}
removeCheckList(checklist): void {
let index = this.checkLists.indexOf(checklist);
if (index>-1){
this.checkLists.splice(index,1);
if (index > -1) {
this.checkLists.splice(index, 1);
}
}
save(): void {
this.keyboard.close();
this.dataService.save(this.checkLists)
}
View
@@ -1,5 +1,6 @@
import {Injectable} from '@angular/core';
import 'rxjs/add/operator/map';
import {Storage} from "@ionic/storage";
/*
Generated class for the DataProvider provider.
@@ -10,8 +11,27 @@ import 'rxjs/add/operator/map';
@Injectable()
export class DataProvider {
constructor() {
console.log('Hello DataProvider Provider');
constructor(public storage:Storage) {
}
getData():Promise<any>{
return this.storage.get('checklists');
}
save(data):void{
let saveData=[];
data.forEach((checklist)=>{
saveData.push({
title:checklist.title,
items:checklist.items
});
});
let newData = JSON.stringify(saveData);
this.storage.set('checklists',newData);
}
}

0 comments on commit 0f527be

Please sign in to comment.