mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Fixed blogs not showing correctly.
Added individual blog post viewing. Fixed javascript to use valid urls. Fixed Route registrations.
This commit is contained in:
parent
ff8bc3d464
commit
1bfddb9ec9
@ -29,6 +29,13 @@ namespace Teknik.Areas.Blog
|
||||
new { controller = "Blog", action = "Post", username = "", id = 0 }, // Parameter defaults
|
||||
new[] { typeof(Controllers.BlogController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Blog_dev_post_unique", // Route name
|
||||
"dev",
|
||||
"Blog/Action/{controller}/{action}", // URL with parameters
|
||||
new { controller = "Blog", action = "Blog" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.BlogController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Blog_default_blog", // Route name
|
||||
"blog",
|
||||
@ -43,6 +50,13 @@ namespace Teknik.Areas.Blog
|
||||
new { controller = "Blog", action = "Post", username = "", id = 0 }, // Parameter defaults
|
||||
new[] { typeof(Controllers.BlogController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Blog_default_post_unique", // Route name
|
||||
"blog",
|
||||
"Action/{controller}/{action}", // URL with parameters
|
||||
new { controller = "Blog", action = "Blog" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.BlogController).Namespace }
|
||||
);
|
||||
|
||||
// Register Bundles
|
||||
BundleTable.Bundles.Add(new ScriptBundle("~/bundles/blog").Include(
|
||||
|
@ -46,24 +46,31 @@ namespace Teknik.Areas.Blog.Controllers
|
||||
Models.Blog blog = null;
|
||||
if (string.IsNullOrEmpty(username))
|
||||
{
|
||||
ViewBag.Title = "Teknik Blog - " + Config.Title;
|
||||
blog = db.Blogs.Find(Constants.SERVERBLOGID);
|
||||
}
|
||||
else
|
||||
{
|
||||
var blogs = db.Blogs.Include("Blog.User").Where(p => p.User.Username == username);
|
||||
var blogs = db.Blogs.Include("User").Where(p => p.User.Username == username);
|
||||
if (blogs.Any())
|
||||
{
|
||||
blog = blogs.First();
|
||||
ViewBag.Title = blog.User.Username + "'s Blog - " + Config.Title;
|
||||
}
|
||||
}
|
||||
// find the post specified
|
||||
if (blog != null)
|
||||
{
|
||||
var foundPosts = db.Posts.Include("Blog").Include("Blog.User").Where(p => (p.Blog.BlogId == blog.BlogId) &&
|
||||
(p.Published || p.Blog.User.Username == User.Identity.Name)
|
||||
);
|
||||
BlogViewModel model = new BlogViewModel();
|
||||
model.BlogId = blog.BlogId;
|
||||
model.UserId = blog.UserId;
|
||||
model.User = blog.User;
|
||||
model.Posts = blog.Posts;
|
||||
model.Title = blog.Title;
|
||||
model.Description = blog.Description;
|
||||
model.Posts = (foundPosts != null && foundPosts.Any()) ? foundPosts.ToList() : null;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
@ -79,31 +86,36 @@ namespace Teknik.Areas.Blog.Controllers
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
// find the post specified
|
||||
|
||||
var post = db.Posts.Include("Blog").Include("Blog.User").Where(p => p.Blog.User.Username == username && p.PostId == id);
|
||||
if (post.Any())
|
||||
var post = db.Posts.Include("Blog").Include("Blog.User").Where(p => (p.Blog.User.Username == username && p.PostId == id) &&
|
||||
(p.Published || p.Blog.User.Username == User.Identity.Name)
|
||||
);
|
||||
if (post != null && post.Any())
|
||||
{
|
||||
Post curPost = post.First();
|
||||
PostViewModel model = new PostViewModel();
|
||||
model.BlogId = curPost.BlogId;
|
||||
model.PostId = curPost.PostId;
|
||||
model.DatePosted = curPost.DatePosted;
|
||||
model.Published = curPost.Published;
|
||||
model.DatePublished = curPost.DatePublished;
|
||||
model.Title = curPost.Title;
|
||||
model.Tags = curPost.Tags;
|
||||
model.Article = curPost.Article;
|
||||
PostViewModel model = new PostViewModel(curPost);
|
||||
|
||||
return View(model);
|
||||
ViewBag.Title = model.Title + " - " + username + "'s Blog - " + Config.Title;
|
||||
return View("~/Areas/Blog/Views/Blog/ViewPost.cshtml", model);
|
||||
}
|
||||
return new HttpStatusCodeResult(HttpStatusCode.NotFound);
|
||||
return View("~/Areas/Blog/Views/Blog/ViewPost.cshtml", null);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[AllowAnonymous]
|
||||
public ActionResult GetPosts(int blogID, int startPostID, int count)
|
||||
{
|
||||
object model = null;
|
||||
|
||||
return PartialView("Post", model);
|
||||
var posts = db.Posts.Include("Blog").Include("Blog.User").Where(p => (p.BlogId == blogID && p.PostId > startPostID) &&
|
||||
(p.Published || p.Blog.User.Username == User.Identity.Name)
|
||||
).Take(count);
|
||||
List<PostViewModel> postViews = new List<PostViewModel>();
|
||||
if (posts != null)
|
||||
{
|
||||
foreach (Post post in posts)
|
||||
{
|
||||
postViews.Add(new PostViewModel(post));
|
||||
}
|
||||
}
|
||||
return PartialView("~/Areas/Blog/Views/Blog/Posts.cshtml", postViews);
|
||||
}
|
||||
|
||||
// GET: Blogs/Create
|
||||
|
@ -1,13 +1,12 @@
|
||||
$(document).ready(function () {
|
||||
$("#blog_submit").click(function () {
|
||||
$('#newPost').modal('hide');
|
||||
userID = encodeURIComponent($("#blog_userid").val());
|
||||
title = encodeURIComponent($("#blog_title").val());
|
||||
post = encodeURIComponent($("#blog_post").val());
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../add_post.php",
|
||||
data: "userID=" + userID + "&title=" + title + "&post=" + post,
|
||||
url: addPostURL,
|
||||
data: { title: title, post: post },
|
||||
success: function (html) {
|
||||
if (html == 'true') {
|
||||
window.location.reload();
|
||||
@ -23,12 +22,12 @@
|
||||
|
||||
$('#editPost').on('show.bs.modal', function (e) {
|
||||
$("#edit_blog_post").val("");
|
||||
userID = encodeURIComponent($(e.relatedTarget).attr("id"));
|
||||
$("#edit_blog_postid").val(userID);
|
||||
postID = encodeURIComponent($(e.relatedTarget).attr("id"));
|
||||
$("#edit_blog_postid").val(postID);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../get_title_content.php",
|
||||
data: "id=" + userID,
|
||||
url: getPostTitleURL,
|
||||
data: { id: postID },
|
||||
success: function (html) {
|
||||
if (html) {
|
||||
$("#edit_blog_title").val(html);
|
||||
@ -37,8 +36,8 @@
|
||||
});
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../get_post_content.php",
|
||||
data: "id=" + userID,
|
||||
url: getPostArticleURL,
|
||||
data: { id: postID },
|
||||
success: function (html) {
|
||||
if (html) {
|
||||
$("#edit_blog_post").val(html);
|
||||
@ -50,13 +49,12 @@
|
||||
$("#edit_submit").click(function () {
|
||||
$('#editPost').modal('hide');
|
||||
postID = encodeURIComponent($("#edit_blog_postid").val());
|
||||
userID = encodeURIComponent($("#edit_blog_userid").val());
|
||||
title = encodeURIComponent($("#edit_blog_title").val());
|
||||
post = encodeURIComponent($("#edit_blog_post").val());
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../edit_post.php",
|
||||
data: "userID=" + userID + "&postID=" + postID + "&title=" + title + "&post=" + post,
|
||||
url: editPostURL,
|
||||
data: { postID: postID, title: title, post: post },
|
||||
success: function (html) {
|
||||
if (html == 'true') {
|
||||
window.location.reload();
|
||||
@ -76,8 +74,8 @@
|
||||
post = encodeURIComponent($("#comment_post").val());
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../includes/add_comment.php",
|
||||
data: "postID=" + postID + "&service=blog&comment=" + post,
|
||||
url: addCommentURL,
|
||||
data: { postID: postID, service: 'blog', comment: post },
|
||||
success: function (html) {
|
||||
if (html == 'true') {
|
||||
window.location.reload();
|
||||
@ -97,8 +95,8 @@
|
||||
$("#edit_comment_postid").val(commentID);
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../includes/get_comment_content.php",
|
||||
data: "id=" + commentID,
|
||||
url: getCommentContentURL,
|
||||
data: { id: commentID },
|
||||
success: function (html) {
|
||||
if (html) {
|
||||
$("#edit_comment_post").val(html);
|
||||
@ -113,8 +111,8 @@
|
||||
post = encodeURIComponent($("#edit_comment_post").val());
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../includes/edit_comment.php",
|
||||
data: "commentID=" + postID + "&post=" + post,
|
||||
url: editCommentURL,
|
||||
data: { commentID: postID, post: post },
|
||||
success: function (html) {
|
||||
if (html == 'true') {
|
||||
window.location.reload();
|
||||
@ -130,7 +128,7 @@
|
||||
|
||||
var imageUpload = $('#upload_image').upload({
|
||||
name: 'file',
|
||||
action: '../../../includes/upload.php',
|
||||
action: uploadURL,
|
||||
enctype: 'multipart/form-data',
|
||||
params: {},
|
||||
autoSubmit: true,
|
||||
@ -153,8 +151,8 @@ function loadMorePosts(start, count) {
|
||||
blog_id = encodeURIComponent($(".blog-main").attr("id"));
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../get_post.php",
|
||||
data: "userID=" + blog_id + "&postCount=" + count + "&startPost=" + start,
|
||||
url: getPostsURL,
|
||||
data: { blogID: blog_id, count: count, startPostID: start },
|
||||
success: function (html) {
|
||||
if (html) {
|
||||
$(".blog-main").append(html);
|
||||
@ -171,8 +169,8 @@ function loadMoreComments(start, count) {
|
||||
post_id = encodeURIComponent($(".post-comments").attr("id"));
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../includes/get_comment.php",
|
||||
data: "postID=" + post_id + "&service=blog&postCount=" + count + "&startPost=" + start,
|
||||
url: getCommentsURL,
|
||||
data: { postID: post_id, service: 'blog', postCount: count, startPost: start },
|
||||
success: function (html) {
|
||||
if (html) {
|
||||
$(".post-comments").append(html);
|
||||
@ -205,8 +203,8 @@ function linkPostUnpublish(selector) {
|
||||
post_id = encodeURIComponent(object.attr("id"));
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../publish_post.php",
|
||||
data: "publish=0&id=" + post_id,
|
||||
url: publishPostURL,
|
||||
data: { publish: false, id: post_id },
|
||||
success: function (html) {
|
||||
if (html == 'true') {
|
||||
window.location.reload();
|
||||
@ -226,8 +224,8 @@ function linkPostPublish(selector) {
|
||||
post_id = encodeURIComponent(object.attr("id"));
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../publish_post.php",
|
||||
data: "publish=1&id=" + post_id,
|
||||
url: publishPostURL,
|
||||
data: { publish: true, id: post_id },
|
||||
success: function (html) {
|
||||
if (html == 'true') {
|
||||
window.location.reload();
|
||||
@ -249,8 +247,8 @@ function linkPostDelete(selector) {
|
||||
if (result) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../delete_post.php",
|
||||
data: "id=" + post_id,
|
||||
url: deletePostURL,
|
||||
data: { id: post_id },
|
||||
success: function (html) {
|
||||
if (html == 'true') {
|
||||
window.location.reload();
|
||||
@ -274,8 +272,8 @@ function linkCommentDelete(selector) {
|
||||
if (result) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "../../../includes/delete_comment.php",
|
||||
data: "id=" + post_id,
|
||||
url: deleteCommentURL,
|
||||
data: { id: post_id },
|
||||
success: function (html) {
|
||||
if (html == 'true') {
|
||||
window.location.reload();
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Teknik.Areas.Blog.Models;
|
||||
using System.Security.Principal;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
@ -12,6 +13,8 @@ namespace Teknik.Areas.Blog.ViewModels
|
||||
|
||||
public int BlogId { get; set; }
|
||||
|
||||
public Models.Blog Blog { get; set; }
|
||||
|
||||
public DateTime DatePosted { get; set; }
|
||||
|
||||
public DateTime DatePublished { get; set; }
|
||||
@ -23,5 +26,23 @@ namespace Teknik.Areas.Blog.ViewModels
|
||||
public string Article { get; set; }
|
||||
|
||||
public List<string> Tags { get; set; }
|
||||
|
||||
public PostViewModel(Post post)
|
||||
{
|
||||
BlogId = post.BlogId;
|
||||
PostId = post.PostId;
|
||||
Blog = post.Blog;
|
||||
DatePosted = post.DatePosted;
|
||||
Published = post.Published;
|
||||
DatePublished = post.DatePublished;
|
||||
Title = post.Title;
|
||||
Tags = post.Tags;
|
||||
Article = post.Article;
|
||||
}
|
||||
|
||||
public bool CanView(IPrincipal user)
|
||||
{
|
||||
return (Published || Blog.User.Username == user.Identity.Name || user.IsInRole("Admin"));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,29 +1,48 @@
|
||||
@model Teknik.Areas.Blog.ViewModels.BlogViewModel
|
||||
|
||||
@using Teknik.Helpers
|
||||
|
||||
<script>
|
||||
// We need to define the action URLs for the script
|
||||
|
||||
var uploadURL = '@Url.Action("UploadFile", "Upload", new { area = "Upload" })';
|
||||
|
||||
var getPostsURL = '@Url.Action("GetPosts", "Blog", new { area = "Blog" })';
|
||||
var getPostTitleURL = '@Url.Action("GetPostTitle", "Blog", new { area = "Blog" })';
|
||||
var getPostArticleURL = '@Url.Action("GetPostArticle", "Blog", new { area = "Blog" })';
|
||||
var publishPostURL = '@Url.Action("PublishPost", "Blog", new { area = "Blog" })';
|
||||
var addPostURL = '@Url.Action("CreatePost", "Blog", new { area = "Blog" })';
|
||||
var editPostURL = '@Url.Action("EditPost", "Blog", new { area = "Blog" })';
|
||||
var deletePostURL = '@Url.Action("DeletePost", "Blog", new { area = "Blog" })';
|
||||
|
||||
var getCommentsURL = '@Url.Action("GetComments", "Blog", new { area = "Blog" })';
|
||||
var getCommentArticleURL = '@Url.Action("GetCommentArticle", "Blog", new { area = "Blog" })';
|
||||
var addCommentURL = '@Url.Action("CreatePost", "Blog", new { area = "Blog" })';
|
||||
var editCommentURL = '@Url.Action("EditPost", "Blog", new { area = "Blog" })';
|
||||
var deleteCommentURL = '@Url.Action("DeleteComment", "Blog", new { area = "Blog" })';
|
||||
</script>
|
||||
|
||||
@Scripts.Render("~/bundles/blog")
|
||||
|
||||
<div class="container">
|
||||
<?php
|
||||
if ($blog_id >= 0)
|
||||
@if (Model.BlogId != Constants.SERVERBLOGID)
|
||||
{
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 blog-heading">
|
||||
<h1 class="blog-title text-center"><?php echo $blog_title; ?></h1>
|
||||
<p class="lead blog-description text-center text-muted"><?php echo $blog_desc; ?></p>
|
||||
<h1 class="blog-title text-center">@Model.Title</h1>
|
||||
<p class="lead blog-description text-center text-muted">@Model.Description</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 text-center">
|
||||
<p>
|
||||
<a href="<?php echo get_page_url('rss', $CONF).'/blog/'.$blog_author; ?>"><i class="fa fa-rss fa-2x fa-border"></i></a>
|
||||
<a href="@Url.Action("Blog", "RSS", new { area = "RSS", username = Model.User.Username })"><i class="fa fa-rss fa-2x fa-border"></i></a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
if ($own_blog)
|
||||
@if (Model.User.Username == User.Identity.Name)
|
||||
{
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 text-center">
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newPost">Create Post</button>
|
||||
@ -38,7 +57,6 @@
|
||||
<h4 class="modal-title" id="newPostLabel">Create a New Post</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input name="blog_userid" id="blog_userid" type="hidden" value="<?php echo $blog_id; ?>" />
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="blog_title"><h4>Title</h4></label>
|
||||
@ -69,7 +87,6 @@
|
||||
<h4 class="modal-title" id="editPostLabel">Edit Your Post</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input name="edit_blog_userid" id="edit_blog_userid" type="hidden" value="<?php echo $blog_id; ?>" />
|
||||
<input name="edit_blog_postid" id="edit_blog_postid" type="hidden" />
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
@ -92,30 +109,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (empty($error))
|
||||
{
|
||||
?>
|
||||
<div class="blog-main" id="<?php echo $blog_id; ?>"></div>
|
||||
<div class="blog-main" id="@Model.BlogId"></div>
|
||||
<script>
|
||||
var posts = <?php echo $posts_per_load; ?>;
|
||||
var start_post = 0;
|
||||
var posts = @ViewBag.Config.PostsToLoad;
|
||||
var start_post = 0;
|
||||
loadMorePosts(start_post, posts);
|
||||
start_post = start_post + posts;
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
else
|
||||
{
|
||||
?>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 text-center">
|
||||
<h2><?php echo $error; ?></h2>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
@ -1,53 +1,38 @@
|
||||
@model Teknik.Areas.Blog.Models.Post
|
||||
@model Teknik.Areas.Blog.ViewModels.PostViewModel
|
||||
|
||||
<script>
|
||||
var converter = new Markdown.getSanitizingConverter();
|
||||
// Title Conversion
|
||||
var old_post = $("#title_@Model.PostId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#title_@Model.PostId").html(new_post);
|
||||
// Post Conversion
|
||||
var old_post = $("#post_@Model.PostId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#post_@Model.PostId").html(new_post);
|
||||
var converter = new Markdown.getSanitizingConverter();
|
||||
// Title Conversion
|
||||
var old_post = $("#title_@Model.PostId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#title_@Model.PostId").html(new_post);
|
||||
// Post Conversion
|
||||
var old_post = $("#post_@Model.PostId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#post_@Model.PostId").html(new_post);
|
||||
</script>
|
||||
<div class="row">
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
<div class="blog-post">
|
||||
<h2 class="blog-post-title text-center"><a href="@Url.Action("Post", "Blog", new { area = "Blog", username = Model.Blog.User.Username, id = Model.PostId })" id="title_@Model.PostId">@Model.Title</a></h2>
|
||||
<p class="blog-post-meta text-center text-muted">
|
||||
Posted on @Model.DatePublished.ToString("F d, Y") by <a href="@Url.Action("Index", "Profile", new { area = "Profile" })/@Model.Blog.User.Username">@Model.Blog.User.Username</a>
|
||||
<?php
|
||||
if ($own_blog)
|
||||
{
|
||||
?>
|
||||
<br />
|
||||
<button type="button" class="btn btn-info edit_post" id="<?php echo $post_id; ?>" data-toggle="modal" data-target="#editPost">Edit</button>
|
||||
<?php
|
||||
if ($published)
|
||||
{
|
||||
?>
|
||||
<button type="button" class="btn btn-warning unpublish_post" id="<?php echo $post_id; ?>">Unpublish</button>
|
||||
<?php
|
||||
Posted on @Model.DatePublished.ToString("MMMM dd, yyyy") by <a href="@Url.Action("Index", "Profile", new { area = "Profile", username = Model.Blog.User.Username })">@Model.Blog.User.Username</a>
|
||||
@if (Model.Blog.User.Username == User.Identity.Name)
|
||||
{
|
||||
<br />
|
||||
<button type="button" class="btn btn-info edit_post" id="@Model.PostId" data-toggle="modal" data-target="#editPost">Edit</button>
|
||||
if (Model.Published)
|
||||
{
|
||||
<button type="button" class="btn btn-warning unpublish_post" id="@Model.PostId">Unpublish</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button type="button" class="btn btn-success publish_post" id="@Model.PostId">Publish</button>
|
||||
}
|
||||
<button type="button" class="btn btn-danger delete_post" id="@Model.PostId">Delete</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
?>
|
||||
<button type="button" class="btn btn-success publish_post" id="<?php echo $post_id; ?>">Publish</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<button type="button" class="btn btn-danger delete_post" id="<?php echo $post_id; ?>">Delete</button>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</p>
|
||||
<p id="post_@Model.PostId">@Model.Article</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- NO POSTS -->
|
||||
<div class="row">
|
||||
<div class="col-sm-12 text-center">
|
||||
<h2>There are currently no articles.</h2>
|
||||
</div>
|
||||
</div>
|
17
Teknik/Areas/Blog/Views/Blog/Posts.cshtml
Normal file
17
Teknik/Areas/Blog/Views/Blog/Posts.cshtml
Normal file
@ -0,0 +1,17 @@
|
||||
@model List<Teknik.Areas.Blog.ViewModels.PostViewModel>
|
||||
|
||||
@if (Model.Any())
|
||||
{
|
||||
foreach (var post in Model)
|
||||
{
|
||||
@Html.Partial("Post", post)
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-sm-12 text-center">
|
||||
<h2>There are currently no articles.</h2>
|
||||
</div>
|
||||
</div>
|
||||
}
|
164
Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml
Normal file
164
Teknik/Areas/Blog/Views/Blog/ViewPost.cshtml
Normal file
@ -0,0 +1,164 @@
|
||||
@model Teknik.Areas.Blog.ViewModels.PostViewModel
|
||||
|
||||
@using Teknik.Helpers
|
||||
|
||||
<script>
|
||||
// We need to define the action URLs for the script
|
||||
|
||||
var uploadURL = '@Url.Action("UploadFile", "Upload", new { area = "Upload" })';
|
||||
|
||||
var getPostsURL = '@Url.Action("GetPosts", "Blog", new { area = "Blog" })';
|
||||
var getPostTitleURL = '@Url.Action("GetPostTitle", "Blog", new { area = "Blog" })';
|
||||
var getPostArticleURL = '@Url.Action("GetPostArticle", "Blog", new { area = "Blog" })';
|
||||
var publishPostURL = '@Url.Action("PublishPost", "Blog", new { area = "Blog" })';
|
||||
var addPostURL = '@Url.Action("CreatePost", "Blog", new { area = "Blog" })';
|
||||
var editPostURL = '@Url.Action("EditPost", "Blog", new { area = "Blog" })';
|
||||
var deletePostURL = '@Url.Action("DeletePost", "Blog", new { area = "Blog" })';
|
||||
|
||||
var getCommentsURL = '@Url.Action("GetComments", "Blog", new { area = "Blog" })';
|
||||
var getCommentContentURL = '@Url.Action("GetCommentContent", "Blog", new { area = "Blog" })';
|
||||
var addCommentURL = '@Url.Action("CreatePost", "Blog", new { area = "Blog" })';
|
||||
var editCommentURL = '@Url.Action("EditPost", "Blog", new { area = "Blog" })';
|
||||
var deleteCommentURL = '@Url.Action("DeleteComment", "Blog", new { area = "Blog" })';
|
||||
</script>
|
||||
|
||||
@Scripts.Render("~/bundles/blog")
|
||||
|
||||
<div class="container">
|
||||
@if (Model != null)
|
||||
{
|
||||
if (Model.Blog.User.Username == User.Identity.Name)
|
||||
{
|
||||
<div class="modal fade" id="editPost" tabindex="-1" role="dialog" aria-labelledby="editPostLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form class="form" action="##" method="post" id="editPostForm">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Cancel</span></button>
|
||||
<h4 class="modal-title" id="editPostLabel">Edit Your Post</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input name="edit_blog_userid" id="edit_blog_userid" type="hidden" value="@Model.Blog.User.UserId" />
|
||||
<input name="edit_blog_postid" id="edit_blog_postid" type="hidden" />
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="edit_blog_title"><h4>Title</h4></label>
|
||||
<input class="form-control" name="edit_blog_title" id="edit_blog_title" placeholder="generic click bait" title="enter a title for your post." type="text" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="edit_blog_post"><h4>Article</h4></label>
|
||||
<textarea class="form-control" name="edit_blog_post" id="edit_blog_post" placeholder="I ate a burger today." title="enter any information you want to share with the world." data-provide="markdown" rows="10"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" id="edit_submit">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<ol class="breadcrumb">
|
||||
<li><a href="@Url.Action("Blog", "Blog", new { area = "Blog", username = Model.Blog.User.Username })">@Model.Blog.User.Username</a></li>
|
||||
<li class="active"><a href="#">@Model.Title</a></li>
|
||||
</ol>
|
||||
|
||||
@Html.Partial("../../Areas/Blog/Views/Blog/Post", Model)
|
||||
|
||||
if (Request.IsAuthenticated)
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-sm-10 col-sm-offset-1">
|
||||
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#newComment">Add Comment</button>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
<div class="modal fade" id="newComment" tabindex="-1" role="dialog" aria-labelledby="newCommentLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form class="form" action="##" method="post" id="publishComment">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Cancel</span></button>
|
||||
<h4 class="modal-title" id="newCommentLabel">Add a New Comment</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input name="post_id" id="post_id" type="hidden" value="@Model.PostId" />
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="comment_post"><h4>Comment</h4></label>
|
||||
<textarea class="form-control wmd-input" name="comment_post" id="comment_post" placeholder="Nice post!" title="enter what you think about the post." data-provide="markdown" rows="10"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" id="comment_submit">Publish</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="editComment" tabindex="-1" role="dialog" aria-labelledby="editCommentLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form class="form" action="##" method="post" id="editCommentForm">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Cancel</span></button>
|
||||
<h4 class="modal-title" id="editCommentLabel">Edit Your Comment</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<input name="edit_comment_postid" id="edit_comment_postid" type="hidden" />
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-12">
|
||||
<label for="edit_comment_post"><h4>Comment</h4></label>
|
||||
<textarea class="form-control" name="edit_comment_post" id="edit_comment_post" placeholder="What an interesting article!" title="enter what you thought about the article." data-provide="markdown" rows="10"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-primary" id="edit_comment_submit">Save</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<a name="replies"></a>
|
||||
<div class="post-comments" id="<?php echo $post_id; ?>"></div>
|
||||
<script>
|
||||
var converter = new Markdown.getSanitizingConverter();
|
||||
// Title Conversion
|
||||
var old_post = $("#title_@Model.PostId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#title_@Model.PostId").html(new_post);
|
||||
// Post Conversion
|
||||
var old_post = $("#post_@Model.PostId").text();
|
||||
var new_post = converter.makeHtml(old_post);
|
||||
$("#post_@Model.PostId").html(new_post);
|
||||
|
||||
linkPostDelete('.delete_post');
|
||||
linkPostPublish('.publish_post');
|
||||
linkPostUnpublish('.unpublish_post');
|
||||
|
||||
var posts = @(ViewBag.Config.CommentsToLoad);
|
||||
var start_post = 0;
|
||||
var view_post_id = @(Model.PostId);
|
||||
loadMoreComments(start_post, posts);
|
||||
start_post = start_post + posts;
|
||||
</script>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-sm-12 text-center">
|
||||
<h2>That post does not exist</h2>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
@ -18,14 +18,14 @@ namespace Teknik.Areas.Contact
|
||||
context.MapSubdomainRoute(
|
||||
"Contact_dev", // Route name
|
||||
"dev",
|
||||
"Contact", // URL with parameters
|
||||
"Contact/{controller}/{action}", // URL with parameters
|
||||
new { controller = "Contact", action = "Index" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ContactController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Contact_default", // Route name
|
||||
"contact",
|
||||
"", // URL with parameters
|
||||
"{controller}/{action}", // URL with parameters
|
||||
new { controller = "Contact", action = "Index" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ContactController).Namespace }
|
||||
);
|
||||
|
@ -16,7 +16,7 @@ namespace Teknik.Areas.Profile.Controllers
|
||||
private TeknikEntities db = new TeknikEntities();
|
||||
|
||||
// GET: Profile/Profile
|
||||
public ActionResult Index()
|
||||
public ActionResult Index(string username)
|
||||
{
|
||||
ViewBag.Title = Config.Title + " - Profile";
|
||||
ViewBag.Message = "View Your Profile";
|
||||
|
@ -17,14 +17,28 @@ namespace Teknik.Areas.Profile
|
||||
context.MapSubdomainRoute(
|
||||
"Profile_dev", // Route name
|
||||
"dev",
|
||||
"Profile", // URL with parameters
|
||||
"Profile/{username}", // URL with parameters
|
||||
new { controller = "Profile", action = "Index", username = UrlParameter.Optional }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ProfileController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Profile_dev_unique", // Route name
|
||||
"dev",
|
||||
"Profile/{controller}/{action}", // URL with parameters
|
||||
new { controller = "Profile", action = "Index" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ProfileController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Profile_default", // Route name
|
||||
"profile",
|
||||
"", // URL with parameters
|
||||
"{username}", // URL with parameters
|
||||
new { controller = "Profile", action = "Index", username = UrlParameter.Optional }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ProfileController).Namespace }
|
||||
);
|
||||
context.MapSubdomainRoute(
|
||||
"Profile_default_unique", // Route name
|
||||
"profile",
|
||||
"{controller}/{action}", // URL with parameters
|
||||
new { controller = "Profile", action = "Index" }, // Parameter defaults
|
||||
new[] { typeof(Controllers.ProfileController).Namespace }
|
||||
);
|
||||
|
@ -1,11 +1,15 @@
|
||||
@model Teknik.Areas.Profile.ViewModels.LoginViewModel
|
||||
|
||||
<form role="form" id="loginForm" action="@Url.Action("Login", "Profile", new { area = "Profile" })" method="post" accept-charset="UTF-8">
|
||||
@using (Html.BeginForm("Login", "Profile", new { area = "Profile" }, FormMethod.Post, new { id = "loginForm" }))
|
||||
{
|
||||
@Html.ValidationMessage("Unable to login.")
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" id="Username" value="" placeholder="Username" name="Username" data-val-required="The Username field is required." data-val="true" />
|
||||
@Html.ValidationMessageFor(u => u.Username)
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="password" class="form-control" id="Password" value="" placeholder="Password" name="Password" data-val-required="The Password field is required." data-val="true" />
|
||||
@Html.ValidationMessageFor(u => u.Password)
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
@ -15,4 +19,4 @@
|
||||
<div class="form-group text-center">
|
||||
<button class="btn btn-primary" id="login_submit" type="submit" name="submit">Sign In</button>
|
||||
</div>
|
||||
</form>
|
||||
}
|
@ -1,18 +1,14 @@
|
||||
@model Teknik.Areas.Profile.ViewModels.RegisterViewModel
|
||||
|
||||
<form role="form" id="registrationForm" action="@Url.Action("Register", "Profile", new { area = "Profile" })" method="post" accept-charset="UTF-8">
|
||||
@Html.ValidationSummary(true, "Registration failed. Check your registration details.")
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" id="Username" value="" placeholder="Username" name="Username" data-val-required="The Username field is required." data-val="true"/>
|
||||
@Html.ValidationMessageFor(u => u.Username)
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="password" class="form-control" id="Password" value="" placeholder="Password" name="Password" data-val-required="The Password field is required." data-val="true"/>
|
||||
@Html.ValidationMessageFor(u => u.Password)
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="password" class="form-control" id="ConfirmPassword" value="" placeholder="Confirm Password" name="ConfirmPassword" data-val-required="The Confirm Password field is required." data-val="true" />
|
||||
@Html.ValidationMessageFor(u => u.ConfirmPassword)
|
||||
</div>
|
||||
<div class="form-group text-center">
|
||||
<button class="btn btn-primary" id="reg_submit" type="submit" name="submit">Sign Up</button>
|
||||
|
@ -20,6 +20,8 @@ namespace Teknik
|
||||
private SMTPConfig _SMTPConfig;
|
||||
private string _SupportEmail;
|
||||
private string _BitcoinAddress;
|
||||
private int _PostsToLoad;
|
||||
private int _CommentsToLoad;
|
||||
|
||||
public bool DevEnvironment { get { return _DevEnvironment; } set { _DevEnvironment = value; } }
|
||||
|
||||
@ -35,6 +37,10 @@ namespace Teknik
|
||||
|
||||
public string BitcoinAddress { get { return _BitcoinAddress; } set { _BitcoinAddress = value; } }
|
||||
|
||||
public int PostsToLoad { get { return _PostsToLoad; } set { _PostsToLoad = value; } }
|
||||
|
||||
public int CommentsToLoad { get { return _PostsToLoad; } set { _PostsToLoad = value; } }
|
||||
|
||||
public Config()
|
||||
{
|
||||
_ConfigRWLock = new ReaderWriterLockSlim();
|
||||
@ -47,14 +53,16 @@ namespace Teknik
|
||||
|
||||
public void SetDefaults()
|
||||
{
|
||||
DevEnvironment = false;
|
||||
Title = String.Empty;
|
||||
Description = String.Empty;
|
||||
Author = String.Empty;
|
||||
Host = String.Empty;
|
||||
SMTPConfig = new SMTPConfig();
|
||||
SupportEmail = string.Empty;
|
||||
BitcoinAddress = string.Empty;
|
||||
DevEnvironment = false;
|
||||
Title = String.Empty;
|
||||
Description = String.Empty;
|
||||
Author = String.Empty;
|
||||
Host = String.Empty;
|
||||
SMTPConfig = new SMTPConfig();
|
||||
SupportEmail = string.Empty;
|
||||
BitcoinAddress = string.Empty;
|
||||
PostsToLoad = 10;
|
||||
CommentsToLoad = 10;
|
||||
}
|
||||
|
||||
public static Config Deserialize(string text)
|
||||
|
@ -15,7 +15,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt
|
||||
<MSDeployServiceURL>teknik.io</MSDeployServiceURL>
|
||||
<DeployIisAppPath>Dev</DeployIisAppPath>
|
||||
<RemoteSitePhysicalPath />
|
||||
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
|
||||
<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
|
||||
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
|
||||
<EnableMSDeployBackup>True</EnableMSDeployBackup>
|
||||
<UserName>Administrator</UserName>
|
||||
|
@ -235,7 +235,9 @@
|
||||
<Content Include="Content\bootstrap.css.map" />
|
||||
<Content Include="Content\bootstrap-theme.min.css.map" />
|
||||
<Content Include="Content\bootstrap-theme.css.map" />
|
||||
<Content Include="Areas\Blog\Views\Blog\Posts.cshtml" />
|
||||
<Content Include="Areas\Blog\Views\Blog\Post.cshtml" />
|
||||
<Content Include="Areas\Blog\Views\Blog\ViewPost.cshtml" />
|
||||
<None Include="Properties\PublishProfiles\Teknik Dev.pubxml" />
|
||||
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
|
||||
<Content Include="Scripts\bootstrap.js" />
|
||||
|
@ -7,10 +7,10 @@
|
||||
<a href="#" id="user_menu" class="dropdown-toggle" data-toggle="dropdown">@User.Identity.Name <strong class="caret"></strong></a>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="user_menu">
|
||||
<li>
|
||||
<a href="@Url.Action("Index", "Profile", new { area = "Profile" })/@User.Identity.Name">Profile</a>
|
||||
<a href="@Url.Action("Index", "Profile", new { area = "Profile", username = User.Identity.Name })">Profile</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="@Url.Action("Index", "Blog", new { area = "Blog" })/@User.Identity.Name">Blog</a>
|
||||
<a href="@Url.Action("Blog", "Blog", new { area = "Blog", username = User.Identity.Name })">Blog</a>
|
||||
</li>
|
||||
@if (User.IsInRole("Admin"))
|
||||
{
|
||||
|
@ -7,7 +7,7 @@
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
<a class="navbar-brand" href="@Url.Action("Index", "Home", new { area = "Home" })"><img src="/Content/Images/logo-black.svg" height="20" alt="Teknik"></a>
|
||||
<a class="navbar-brand" href="@Url.Action("Index", "Home", new { area = "Home" })"><img src="/Images/logo-black.svg" height="20" alt="Teknik"></a>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<ul class="nav navbar-nav">
|
||||
@ -19,7 +19,7 @@
|
||||
<a href="#" id="services_menu" class="dropdown-toggle" data-toggle="dropdown">Services <strong class="caret"></strong></a>
|
||||
<ul class="dropdown-menu" role="menu" aria-labelledby="services_menu">
|
||||
<li>
|
||||
<a href="@Url.Action("Index", "Blog", new { area = "Blog" })">Blog</a>
|
||||
<a href="@Url.Action("Blog", "Blog", new { area = "Blog" })">Blog</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="@Url.Action("Index", "Podcast", new { area = "Podcast" })">Podcast</a>
|
||||
|
Loading…
Reference in New Issue
Block a user