Implemented Notes in journal

This commit is contained in:
Thaum
2015-02-19 10:45:57 +00:00
parent 9601826475
commit 93578709cd
9 changed files with 169 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
Notes = new Meteor.Collection("notes");
Schemas.Note = new SimpleSchema({
charId: {type: String, regEx: SimpleSchema.RegEx.Id},
name: {type: String},
description: {type: String, optional: true},
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
});
Notes.attachSchema(Schemas.Note);

View File

@@ -24,7 +24,7 @@
<swipe-detect touch-action="pan-y" flex>{{> inventory}}</swipe-detect>
<swipe-detect touch-action="pan-y" flex>{{> spells}}</swipe-detect>
<swipe-detect touch-action="pan-y" flex>{{> persona}}</swipe-detect>
<swipe-detect touch-action="pan-y" flex>Journal Under Construction</swipe-detect>
<swipe-detect touch-action="pan-y" flex>{{> journal}}</swipe-detect>
</core-animated-pages>
</div>
</template>

View File

@@ -0,0 +1,25 @@
<template name="journal">
<div fit>
<div id="journal" class="scroll-y" fit>
<div class="containers">
{{#each notes}}
<paper-shadow class="card container" hero-id="main" {{detailHero}}>
<div class="containerTop {{colorClass}}" hero-id="toolbar" layout horizontal center {{detailHero}}>
<div flex>
<div class="containerName subhead">{{name}}</div>
</div>
</div>
<div class="containerMain">
{{description}}
</div>
</paper-shadow>
{{/each}}
</div>
<div class="fab-buffer"></div>
</div>
</div>
<paper-fab-menu id="inventoryAddMenu" icon="add" closeIcon="close" duration="0.3">
<paper-fab-menu-item id="addNote" icon="note-add" color="#d23f31" tooltip="Note"></paper-fab-menu-item>
<paper-fab-menu-item id="addXP" icon="work" color="#d23f31" tooltip="Experience"></paper-fab-menu-item>
</paper-fab-menu>
</template>

View File

@@ -0,0 +1,48 @@
Template.journal.helpers({
notes: function(){
return Notes.find({charId: this._id}, {sort: {color: 1, name: 1}});
}
});
Template.journal.events({
"tap .containerTop": function(event){
GlobalUI.setDetail({
template: "noteDialog",
data: {noteId: this._id, charId: this.charId},
heroId: this._id
});
},
"tap #addNote": function(event){
var charId = this.charId;
Notes.insert({
name: "New Note",
charId: this._id
}, function(error, id){
if(!error){
GlobalUI.setDetail({
template: "noteDialog",
data: {noteId: id, charId: charId},
heroId: id
});
}
});
},
"tap #addXP": function(event){
var charId = this.charId;
var listId = this.listId;
throw new Error("not implemented")/*
Spells.insert({
name: "New Spell",
charId: this._id,
listId: SpellLists.findOne({charId: this._id})._id
}, function(error, id){
if(!error){
GlobalUI.setDetail({
template: "spellDialog",
data: {spellId: id, charId: charId, listId: listId},
heroId: id
});
}
});*/
}
});

View File

@@ -0,0 +1,3 @@
.noteDialog .colorDropdown {
top: 0;
}

View File

@@ -0,0 +1,30 @@
<template name="noteDialog">
{{#with note}}
<core-header-panel fit class="noteDialog">
<core-toolbar hero-id="toolbar" class={{colorClass}} hero>
<paper-icon-button id="backButton" role="button" tabindex="0" icon="arrow-back" aria-label="close"></paper-icon-button>
<div flex hero-id="title" hero>{{name}}</div>
<paper-icon-button id="deleteNote"
role="button"
tabindex="0"
icon="delete"
aria-label="Delete Feature"
noink></paper-icon-button>
</core-toolbar>
<div class="detailContent">
<!--Name-->
<div horizontal layout>
<paper-input id="noteNameInput" label="Name" floatinglabel value={{name}} flex></paper-input>
<!--Color-->
{{> colorDropdown}}<br>
</div>
<!--Description-->
<paper-input-decorator label="Description" floatinglabel layout vertical>
<paper-autogrow-textarea>
<textarea id="noteDescriptionInput" placeholder value={{description}}></textarea>
</paper-autogrow-textarea>
</paper-input-decorator>
</div>
</core-header-panel>
{{/with}}
</template>

View File

@@ -0,0 +1,50 @@
Template.noteDialog.rendered = function(){
var self = this;
//update all autogrows after they've been filled
var pata = this.$("paper-autogrow-textarea");
pata.each(function(index, el){
el.update($(el).children().get(0));
})
//update all input fields as well
var input = this.$("paper-input");
input.each(function(index, el){
el.valueChanged();
})
//after the dialog is built, open it
if (!this.alreadyRendered){
Session.set("global.ui.detailShow", true);
this.alreadyRendered = true;
}
}
Template.noteDialog.events({
"tap #backButton": function(){
GlobalUI.closeDetail();
},
"tap #deleteNote": function(){
Notes.remove(this._id);
GlobalUI.closeDetail();
},
//TODO clean up String -> num here so they don't need casting by Schema.clean
//TODO validate input (integer, non-negative, etc) for these inputs and give validation errors
"change #noteNameInput, input #noteNameInput": function(event){
var value = event.currentTarget.value
Notes.update(this._id, {$set: {name: value}});
},
"change #noteDescriptionInput": function(event){
var value = event.currentTarget.value
Notes.update(this._id, {$set: {description: value}});
},
"core-select .colorDropdown": function(event){
var detail = event.originalEvent.detail;
if(!detail.isSelected) return;
var value = detail.item.getAttribute("name");
Notes.update(this._id, {$set: {color: value}});
}
});
Template.noteDialog.helpers({
note: function(){
return Notes.findOne(this.noteId);
}
});

View File

@@ -7,6 +7,7 @@ Meteor.publish("singleCharacter", function(characterId, userId){
Features.find({charId: characterId}),
Effects.find({charId: characterId}),
Spells.find({charId: characterId}),
SpellLists.find({charId: characterId})
SpellLists.find({charId: characterId}),
Notes.find({charId: characterId})
];
});