Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor date #27

Merged
merged 2 commits into from
Oct 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions README.me

This file was deleted.

2 changes: 1 addition & 1 deletion models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var PostSchema = new mongoose.Schema({
title: String,
content: String,
author: String,
date: String,
date: Date,
comments: Number
});

Expand Down
12 changes: 8 additions & 4 deletions public/js/packed.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@
redirectTo: "/posts",
});
}]);

app.controller('DateCtrl', ['$scope', function($scope) {
$scope.date = new Date();
}
]);
}());

__webpack_require__(4);
Expand Down Expand Up @@ -30131,20 +30136,19 @@
initialize();

function initialize () {
vm.post.date = new Date(Date.now());
if ($routeParams.post_id) {
PostsService.get($routeParams.post_id).then(function (resp) {
vm.post = resp.data;
vm.post.date = vm.post.date || new Date(Date.now());
});
}

}

function saveForm () {
var method;

// if (angular.isDefined(vm.post.author)) {
// vm.post.author = parseInt(vm.post.author, 10);
// }

method = $routeParams.post_id ? "update" : "create";
PostsService[method](vm.post).then(function (resp) {
$location.path("/posts/" + resp.data._id);
Expand Down
5 changes: 5 additions & 0 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ require('angular');
redirectTo: "/posts",
});
}]);

app.controller('DateCtrl', ['$scope', function($scope) {
$scope.date = new Date();
}
]);
}());

require('angular-route');
Expand Down
10 changes: 5 additions & 5 deletions src/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h1>{{post.title}}</h1>
<div class="post-data">
<ul>
<li>By {{post.author}}</li>
<li>{{post.date}}</li>
<li>{{post.date | date: 'MMM dd, yyyy'}}</li>
<li>{{post.comments}} comments</li>
</ul>
<a class="btn btn__text btn--dark" href="#/posts/{{post._id}}">Read More</a>
Expand All @@ -75,7 +75,7 @@ <h1>{{post.title}}</h1>
<h1>{{vm.post.title}}</h1>
<ul class="post-data">
<li>By {{vm.post.author}}</li>
<li>{{vm.post.date}}</li>
<li>{{vm.post.date | date: 'MMM dd, yyyy'}}</li>
<li>{{vm.post.comments}} comments</li>
</ul>
<p>{{vm.post.content}}</p>
Expand All @@ -84,10 +84,10 @@ <h1>{{vm.post.title}}</h1>
</script>

<script type="text/ng-template" id="partials/posts/post_form.html">
<form id="post-form" class="post-form" ng-submit="vm.save()">
<form id="post-form" class="post-form" ng-submit="vm.save()" ng-controller="DateCtrl">
<input type="text" ng-model="vm.post.title" placeholder="Title" />
<input type="text" ng-model="vm.post.author" placeholder="Author" />
<input type="text" ng-model="vm.post.date" placeholder="Date" />
<input id="date-birth" class="form-control" type="date" ng-model="vm.post.date">
<textarea ng-model="vm.post.content" form="post-form" rows="15"></textarea>
<input type="number" ng-model="vm.post.comments" placeholder="how many comments" />
<button type="submit" name="Submit" class="btn btn__text btn--light">Submit</button>
Expand All @@ -100,7 +100,7 @@ <h1>Serene in their assurance of their empire over matter</h1>
<a class="btn btn__text btn--theme">Contact Now</a>
<a class="btn btn__text btn--theme">Learn More</a>
</section> <!-- end feature-box -->
<aside class="contact"> <!-- cntact -->
<aside class="contact"> <!-- contact -->
<address class="contact__method"><a href="https://goo.gl/maps/C4Q1FUpTdJx">2319 Hilltop Haven Drive<br />Upper Greenwood Lake, NJ 07421</a></address>
<div class="contact__method">
<a href="tel:6624076792">662-407-6792</a>
Expand Down
7 changes: 3 additions & 4 deletions src/app/posts/post_form.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ require('../app');
initialize();

function initialize () {
vm.post.date = new Date(Date.now());
if ($routeParams.post_id) {
PostsService.get($routeParams.post_id).then(function (resp) {
vm.post = resp.data;
vm.post.date = vm.post.date || new Date(Date.now());
});
}

}

function saveForm () {
var method;

// if (angular.isDefined(vm.post.author)) {
// vm.post.author = parseInt(vm.post.author, 10);
// }

method = $routeParams.post_id ? "update" : "create";
PostsService[method](vm.post).then(function (resp) {
$location.path("/posts/" + resp.data._id);
Expand Down