Skip to content

Commit

Permalink
Ported to iron-router and meteor 0.8 - working now
Browse files Browse the repository at this point in the history
  • Loading branch information
sarfata committed Apr 20, 2014
1 parent 4968ec8 commit 7c1b761
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 133 deletions.
9 changes: 5 additions & 4 deletions client/admin/admin.js
Expand Up @@ -18,24 +18,25 @@ Template.adminPost.rendered = function() {
Template.adminDashboard.events({
'click button[name="buttonNewPost"]': function(event, template) {
var postId = Posts.insert(new Post());
Meteor.Router.to('learnEditor', postId);
Router.go('learnEditor', { _id: postId });
}
});

Template.adminPost.events({
'click button[name="edit"]': function(event, template) {
Meteor.Router.to('learnEditor', template.data._id);
Router.go('learnEditor', { _id: template.data._id } );
},
'click button[name="delete"]': function(event, template) {
var result = confirm("Are you sure?");

if (result) {
Posts.remove(template.data._id);
}
}
})

/*
// This is what needs to be ran on the mongodb to calculate stats.
var mapFunction = function() { emit(this.deviceId, { count: 1 } ); };
Expand All @@ -48,4 +49,4 @@ db.devicelogs.mapReduce(mapFunction, reduceFunction, { out: "devicelogsCount" })
db.devicelogsCount.find().sort( { "value" : -1 } )
*/
*/
8 changes: 4 additions & 4 deletions client/app.html
Expand Up @@ -3,7 +3,7 @@
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</head>

<body>
<template name="layout">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
Expand All @@ -12,7 +12,7 @@
</div>
</div>

{{ renderPage }}
{{> yield }}

<div class="container">
<hr>
Expand All @@ -35,7 +35,7 @@

</footer>
</div>
</body>
</template>

<template name="analyticsInit">
</template>
Expand All @@ -50,4 +50,4 @@
</div>
</div>
</div>
</template>
</template>
6 changes: 3 additions & 3 deletions client/dashboard/dashboard.html
Expand Up @@ -48,17 +48,17 @@ <h2>Your Raspberry Pis</h2>
<td class="deviceName">
{{#if editName }}
<div class="input-append">
<input type="text" class="endsInput" placeholder="Name me!" value="{{ name }}">
<input type="text" class="endsInput" placeholder="Name me!" value="{{ displayName }}">
<button class="btn endsInput" type="button"><i class="icon-ok"></i></button>
</div>
{{ else }}
{{ name }}
{{ displayName }}
{{/if }}
</td>
<td><pre>{{ software }} - {{ version }}</pre></td>
<td>{{ lastSeen }}</td>
<td>
<a class="btn" href="{{ editorPath _id }}">Edit Code</a>
<a class="btn" href="{{ pathFor 'editor' }}">Edit Code</a>
<button class="btn viewLogs"><i class="icon-list-alt"></i></button>
<button class="btn deleteLogs"><i class="icon-remove"></i></button>
</td>
Expand Down
9 changes: 7 additions & 2 deletions client/dashboard/dashboard.js
Expand Up @@ -29,8 +29,13 @@ Template.device.rowClass = function(status) {
Template.device.editName = function() {
return this.name === undefined || Session.get("edit-" + this._id);
}
Template.device.name = function() {
return "Name me!"
Template.device.displayName = function() {
if (this.name === undefined) {
return "Name me!";
}
else {
return this.name;
}
}
Template.device.lastSeen = function() {
return moment(this.lastSeen).fromNow();
Expand Down
42 changes: 17 additions & 25 deletions client/learn/edit/edit.html
Expand Up @@ -10,37 +10,29 @@
</ul>
<div class="tab-content">
<div class="tab-pane active" id="edit">
{{#isolate}}
{{#with post}}
{{> editTab }}
{{/with}}
{{/isolate}}
{{#with post}}
{{> editTab }}
{{/with}}
</div>
<div class="tab-pane" id="prerequisites">
{{#isolate}}
{{#with post}}
{{> prerequisitesTab }}
{{/with}}
{{/isolate}}
{{#with post}}
{{> prerequisitesTab }}
{{/with}}
</div>
<div class="tab-pane" id="code">
{{#isolate}}
{{#with post}}
{{> codeTab }}
{{/with}}
{{/isolate}}
{{#with post}}
{{> codeTab }}
{{/with}}
</div>
<div class="tab-pane" id="preview">
{{#isolate}}
{{#with post}}
{{> learnViewContent }}
{{/with}}
{{/isolate}}
{{#with post}}
{{> learnViewContent }}
{{/with}}
</div>
</div>
</div>
</div>
</div>
</div>
</template>

<template name="editTab">
Expand All @@ -60,7 +52,7 @@
<textarea name="summary" class="span8">{{{ summary }}}</textarea>
</div>
</div>

<div class="control-group">
<label class="control-label">Image</label>
<div class="controls">
Expand All @@ -74,9 +66,9 @@
<input name="fancyLink" type="text" value="{{ fancyLink }}">
<span class="help-block help-fancyLink">http://www.pijs.io/learn/{{ fancyLink }}</span>
</div>

</div>

<div class="control-group">
<label class="control-label">Content</label>
<div class="controls">
Expand Down Expand Up @@ -136,7 +128,7 @@
<input type="text" name="link" value="{{ link }}">
</div>
</div>

<button class="btn btn-danger pull-right"><i class="icon-trash icon-white"></i></button>
</fieldset>
</div>
Expand Down
4 changes: 2 additions & 2 deletions client/learn/view/view.js
Expand Up @@ -31,7 +31,7 @@ Template.learnViewContent.events({
analytics.event("Learn", "Deploy");
var deviceId = userDevices.fetch()[0]._id;
this.deployTo(deviceId);
Meteor.Router.to('editor', deviceId);
Router.go('editor', deviceId);
}
// User has several devices - Ask him where to deploy
else {
Expand Down Expand Up @@ -97,6 +97,6 @@ Template.deployTargetModalDevice.events({
var post = Posts.findOneWithFancyId(Session.get("currentPostId"));
post.deployTo(this._id);
$('#chooseDeployTargetModal').modal("hide");
Meteor.Router.to('editor', this._id);
Router.go('editor', this._id);
}
})
70 changes: 0 additions & 70 deletions client/lib/router.js

This file was deleted.

29 changes: 12 additions & 17 deletions client/nav/nav.js
@@ -1,40 +1,35 @@
var navLinks = [
{ title: 'Dashboard', to: Meteor.Router.dashboardPath(), logged: true },
{ title: 'Admin', to: Meteor.Router.adminDashboardPath(), logged:true, admin:true},
{ title: 'Learn', to: Meteor.Router.learnListPath() }
{ title: 'Dashboard', to: Router.path('dashboard'), logged: true },
{ title: 'Admin', to: Router.path('adminDashboard'), logged:true, admin:true},
{ title: 'Learn', to: Router.path('learnList') }
];

Template.nav.navLinks = function() {
if (Meteor.user()) {
if (Meteor.user().isAdmin === true) {
return navLinks
return navLinks;
}
else {
return _.reject(navLinks, function(e) { return "admin" in e && e['admin'] } );
}
}

else
return _.reject(navLinks, function(e) { return "logged" in e && e['logged'] } );
}
};

Template.navLink.hasSubItems = function() {
return this.subitems && this.subitems.length > 0;
}
};

Template.navLink.navClass = function() {
var currentPage = Meteor.Router.page();
var currentPage = Router.current();
var currentPath;
if (currentPage && currentPage in Meteor.Router.namedRoutes) {
currentPath = Meteor.Router.namedRoutes[currentPage].path;
if (currentPage) {
currentPath = currentPage.path;
}
if (this.to === currentPath)

if (currentPath && currentPath.indexOf(this.to) == 0)
return "active";

if (this.subitems)
for (var i in this.subitems)
if (i.to === currentPage)
return "active";
return "";
}
};
4 changes: 2 additions & 2 deletions client/nav/user.js
Expand Up @@ -12,7 +12,7 @@ signupCallback = function(provider, error) {
analytics.alias(Meteor.user()._id);
analytics.event("Signup+Login", "NewUser-" + provider);

Meteor.Router.to('dashboard');
Router.go('dashboard');
}
};
Template.userLoggedOut.events({
Expand Down Expand Up @@ -57,7 +57,7 @@ Template.userLoggedOut.events({
if (error)
Session.set("loginError", error.reason);
else
Meteor.Router.to('dashboard');
Router.go('dashboard');
});
analytics.event("Signup+Login", "Login password");
}
Expand Down
8 changes: 4 additions & 4 deletions lib/posts.js
Expand Up @@ -19,10 +19,10 @@ _.extend(Post.prototype, {
return this._id;
},
fancyPath: function() {
return Meteor.Router.learnPath(this._fancyId());
return Router.routes['learn'].path(this);
},
fancyUrl: function() {
return Meteor.Router.learnUrl(this._fancyId());
return Router.routes['learn'].path(this);
},

voteUp: function() {
Expand Down Expand Up @@ -51,7 +51,7 @@ Posts = new Meteor.Collection("posts", {

Posts.findOneWithFancyId = function(fancyId) {
return Posts.findOne({ $or: [ { '_id': fancyId }, { 'fancyLink': fancyId } ] });
}
};

Meteor.methods({
"post-vote-up": function(postId) {
Expand All @@ -68,4 +68,4 @@ Meteor.methods({
Posts.update(postId, { $set: { votes: post.votes, voters: post.voters } });
}
}
})
});

0 comments on commit 7c1b761

Please sign in to comment.