Skip to content

Commit

Permalink
got more things working
Browse files Browse the repository at this point in the history
did alot of shit
  • Loading branch information
Rikuoe91 committed Oct 11, 2017
1 parent 41d7999 commit 0f527be
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/pages/checklist/checklist.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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>
Expand Down
82 changes: 73 additions & 9 deletions src/pages/checklist/checklist.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
}
})
}

}
2 changes: 1 addition & 1 deletion src/pages/home/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 >
Expand Down
34 changes: 30 additions & 4 deletions src/pages/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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)
}


Expand Down
24 changes: 22 additions & 2 deletions src/providers/data/data.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.