var app = angular.module("app", ["ngRoute"]);
app.config(
function ($routeProvider, $locationProvider)
{
$routeProvider
.when("/", {templateUrl: "views/blog.html", controller: "blog"})
.when("/create", {templateUrl: "views/create.html", controller: "create"})
.when("/about", {templateUrl: "views/about.html", controller: "about"})
.when("/faq", {templateUrl: "views/faq.html", controller: "faq"})
.otherwise("
yeey
");
$locationProvider.html5mode(true);
}
);
app.controller("blog",
[
"$scope",
"$http",
function($scope, $http)
{
$scope.posts = [];
$http.get("/getnews")
.then(
(r) =>
{
if (r.status != 200) console.log("Failed to get posts (" + r.statusText + ")");
else $scope.posts = angular.fromJson(r.data).arr.reverse();
}
);
}
]
);
app.controller("create",
[
"$scope",
"$http",
function($scope, $http)
{
$scope.postTitle = "";
$scope.postAuthor = "";
$scope.postContent = "";
$scope.postTags = "";
$scope.timestamp = currentTime() + " - " + currentDate();
$scope.postSubmit = function()
{
// Push to the post service
post = {
"postTitle": $scope.postTitle,
"postAuthor": $scope.postAuthor,
"postContent": $scope.postContent,
"postTags": $scope.postTags,
"postTime": currentTime(),
"postDate": currentDate()
};
$http.post("/writenews", post)
.then(
(r) =>
{
if (r.status != 204) console.log("Failed to push new post (" + r.statusText + ")");
}
);
// Clear the fields
$scope.postTitle = "";
$scope.postAuthor = "";
$scope.postContent = "";
$scope.postTags = "";
// Tell the user that the deed is done *diabolical laughter*
alert("Post has been submitted. Thank you!");
}
}
]
);
app.controller("about",
[
"$scope",
function($scope)
{
$scope.aboutHeader = "Lorem Ipsum Dolor Sit Amet!";
$scope.aboutContent = "Aenean in lorem non odio ullamcorper tempor sed vitae nibh. Proin fermentum risus vel dui congue fringilla. Curabitur ac nulla vel ante molestie fermentum. Pellentesque et nisi eu eros euismod volutpat sed non turpis. Donec in sollicitudin tellus. Suspendisse sit amet mauris id est auctor sodales mattis vel mi. Vivamus id semper enim, id euismod orci. Donec placerat turpis eget mollis gravida. Sed nisi lectus, ullamcorper eget mi vitae, maximus rhoncus orci. Pellentesque vel accumsan lorem. Proin condimentum fermentum est, nec fermentum velit elementum eu. Maecenas pharetra odio ut mauris lobortis lobortis. Suspendisse ut maximus risus, vel pharetra dolor. Etiam vel mi vitae ipsum aliquam aliquam. Donec eget rhoncus urna, eu maximus metus. Cras porttitor mauris a urna tempus fringilla. Nunc dolor arcu, laoreet ac sapien sed, dignissim tincidunt magna. Curabitur eu rhoncus leo. Vivamus congue odio suscipit ante interdum rutrum. Aliquam erat volutpat. Mauris lacinia lobortis sem, in blandit tortor tempor at. In hac habitasse platea dictumst. Donec in massa quis urna facilisis fermentum. Cras tempor ut odio at sagittis. Mauris iaculis pellentesque eros, ut rutrum odio condimentum at. Donec et ultricies mauris, et scelerisque purus. Nulla porttitor ante in turpis scelerisque, sed ultrices felis feugiat. Duis elementum nisl in tincidunt mattis. Donec faucibus scelerisque augue nec vestibulum. Duis hendrerit nulla nec congue sollicitudin. In hac habitasse platea dictumst. Vestibulum ut augue consequat, accumsan mi vitae, posuere libero. Nullam scelerisque lacinia turpis vitae fermentum. Integer blandit consectetur nulla, a malesuada erat commodo ut. Nunc sit amet quam vitae sapien efficitur accumsan.";
}
]
);
app.controller("faq",
[
"$scope",
function($scope)
{
}
]
);
app.controller("navbar",
[
"$scope",
"$location",
function($scope, $location)
{
$scope.setNews = function()
{
$location.path('/');
$scope.newsButton = "current";
$scope.createButton = "";
$scope.aboutButton = "";
$scope.loginButton = "";
}
$scope.setContentCreation = function()
{
$location.path('/content');
$scope.newsButton = "";
$scope.createButton = "current";
$scope.aboutButton = "";
$scope.loginButton = "";
}
$scope.setAbout = function()
{
$location.path('/about');
$scope.newsButton = "";
$scope.createButton = "";
$scope.aboutButton = "current";
$scope.loginButton = "";
}
$scope.setLogin = function()
{
$location.path('/login');
$scope.newsButton = "";
$scope.createButton = "";
$scope.aboutButton = "";
$scope.loginButton = "current";
}
}
]
);
app.controller("header",
[
"$scope",
function($scope)
{
$scope.heading = "Not Fake News!";
}
]
);
app.controller("footer",
[
"$scope",
function($scope)
{
$scope.date = currentDate();
}
]
);
function currentTime()
{
var date = new Date();
var timestr = "";
timestr += date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
timestr += ":";
timestr += date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
return timestr;
}
function currentDate()
{
var date = new Date();
var datestr = "";
datestr += date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
datestr += "/";
datestr += (date.getMonth()+1) < 10 ? "0" + (date.getMonth()+1) : (date.getMonth()+1);
datestr += "/";
datestr += date.getFullYear();
return datestr;
}