Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/AnTTSE61258/AMS
Browse files Browse the repository at this point in the history
  • Loading branch information
anltnmse60906 committed Jul 20, 2016
2 parents 02dc3c2 + d1fc46c commit 0ae5116
Show file tree
Hide file tree
Showing 9 changed files with 272 additions and 10 deletions.
Binary file modified .vs/AMS/v14/.suo
Binary file not shown.
Binary file modified AMS.v12.suo
Binary file not shown.
1 change: 1 addition & 0 deletions AMS/AMS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@
<LastGenOutput>Model1.cs</LastGenOutput>
</Content>
<Content Include="Scripts\amsScript\additional-methods.js" />
<Content Include="Scripts\amsScript\DisplaySinglePost.js" />
<Content Include="Scripts\amsScript\jquery.validate.js" />
<Content Include="Scripts\ai.0.15.0-build58334.js" />
<Content Include="Scripts\ai.0.15.0-build58334.min.js" />
Expand Down
20 changes: 20 additions & 0 deletions AMS/Controllers/PostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ public Object getPost(int? idToken, int? houseId)
string json = JsonConvert.SerializeObject(all,settings);
return json;
}

[HttpGet]
[Authorize]
public Object getSinglePost(int postId)
{
PostMapping singlePost = postService.getSiglePost(postId);

// Serializer settings
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.ContractResolver = new CustomResolver(typeof(PostMapping));
settings.PreserveReferencesHandling = PreserveReferencesHandling.None;
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
settings.Formatting = Formatting.Indented;

// Do the serialization and output to the console
string json = JsonConvert.SerializeObject(singlePost, settings);
return json;


}
[HttpGet]
[Authorize]
public String getUserProfileForPost(int? postId)
Expand Down
11 changes: 6 additions & 5 deletions AMS/Scripts/_references.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
/// <autosync enabled="true" />
/// <reference path="ai.0.15.0-build58334.min.js" />
/// <reference path="amsScript/additional-methods.js" />
/// <reference path="amsScript/additional-methods.min.js" />
/// <reference path="amsScript/canvasjs.min.js" />
/// <reference path="amsScript/custom.js" />
/// <reference path="amsscript/displaysinglepost.js" />
/// <reference path="amsscript/jquery.balanced-gallery.js" />
/// <reference path="amsScript/jquery.timepicker.min.js" />
/// <reference path="amsScript/jquery.validate.min.js" />
/// <reference path="amsscript/lg-fullscreen.js" />
/// <reference path="amsscript/lg-thumbnail.js" />
/// <reference path="amsscript/lightgallery.js" />
/// <reference path="amsscript/loadfamilytree.js" />
/// <reference path="amsscript/loaduserprofile.js" />
/// <reference path="amsscript/masonry.pkgd.min.js" />
/// <reference path="amsScript/moment.min.js" />
/// <reference path="amsscript/reportpost.js" />
/// <reference path="amsscript/scripts.js" />
Expand Down Expand Up @@ -38,11 +44,6 @@
/// <reference path="modernizr-2.6.2.js" />
/// <reference path="rating.js" />
/// <reference path="respond.js" />
/// <reference path="amsScript/additional-methods.js" />
/// <reference path="amsscript/masonry.pkgd.min.js" />
/// <reference path="amsscript/lg-fullscreen.js" />
/// <reference path="amsscript/lg-thumbnail.js" />
/// <reference path="amsscript/lightgallery.js" />



Expand Down
1 change: 1 addition & 0 deletions AMS/Scripts/amsScript/DisplaySinglePost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

227 changes: 225 additions & 2 deletions AMS/Scripts/amsScript/LoadUserProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function addModal(data, loadMember) {
console.log("Moreinfo: " + moreinfos.length);
var moreInfoHtmlArea = "";
for (var i = 0; i < moreinfos.length; i++) {

var moreinfo = moreinfos[i];
moreInfoHtmlArea += '<li style="border-bottom: 1px solid #9E9E9E;">'
+ '<div class="row" style="font-size: 16px;">'
Expand Down Expand Up @@ -189,6 +190,228 @@ function addModal(data, loadMember) {
}




function displaySinglePost(postId) {
alert("Display single post " + postId + " Not implemented");
}
appendSinglePostModal();
getSinglePostObject(postId)
}
function appendSinglePostModal() {
var element = $("#displaySinglePost");
if (element.length > 0) {
return
}
$("body").append('<div class="modal fade" id="displaySinglePost" role="dialog" style="z-index:9999">'
+'<div class="modal-dialog">'
+'<div class="modal-content">'
+'<div class="modal-body" id="singlePostModal">'
+'</div>'
+'<div class="modal-footer">'
+'<button type="button" class="btn btn-default" data-dismiss="modal">Đóng</button>'
+'</div>'
+'</div>'

+'</div>'
+ '</div>')

}

function addPostTo(dir, index, postObject) {
if (dir == "singlePostModal") {
var reportDiv = "";
if (postObject['UserId'] != '@curUser.Id') {
reportDiv = '<div href="" class="btn btn-white btn-xs pull-right" onclick="report(' + postObject['Id'] + ')"><i class="fa fa-fw fa-warning"></i></div>';
}
var header = '<div class="panel-heading clearfix" style="background-color: transparent;">' +
'<div class="form-group" style="margin-bottom:0">' +
'<div style="display: flex">' +
'<div class="pull-left" id="userLoadProfilePost' + postObject['Id'] + '" onclick="LoadUserProfile(' + postObject['UserId'] + ',true)" style="margin-right: 10px">' +
'<img id="userImagePost' + postObject['Id'] + '" src="' + postObject['userProfile'] + '" onerror="this.src=\'/Content/Images/defaultProfile.png\';" class="avartar-img">' +
'</div>' +
'<div style="flex: 1; width: 0">' +
'<h3 class="" style="margin-top: 0;margin-bottom: 0;">' +
'<strong>' +
' <a class="text-capitalize user-name" id="userNamePost' + postObject['Id'] + '">' + postObject['userFullName'] + '</a>' +
'</strong>' +
'<strong class="house-name"> ' +
'<span style="font-size: 17px;">' +
'<i class="fa fa-home icon-house"></i>' +
postObject['houseName'] +
'</span>' +
'</strong>' +
'</h3>' +
'<h3 class="" style="margin-top: 0;margin-bottom: 0;">' +
' <strong>' +
'<span class="post-time">' +
'<i class="fa fa-globe icon-house"></i> ' +
timeSince(postObject['CreateDate']) +
'</span>' +
'</strong>' +
'</h3>' +
'</div>' +
'</div>' +
'</div>' +
'</div>';
$("#singlePostModal").html("");
$("#singlePostModal").append('<li class="media">'
+ '<div class="media-body">'
+ '<div class="panel panel-default panel-feed" style="width:100%">' + header
+ '<div class="panel-body" >'
+ reportDiv
+ '<p>' + postObject['Body'] + '</p>'
+ '<div class="form-group">'
+ '<div class="grid" id="imagesPostForSinglePost' + postObject['Id'] + '">'
+ '</div>'
+ '</div>'


+ '<div class="row" style="height:auto;">'
+ postObject['EmbedCode']
+ '</div>'
+ '</div>'
+ '<div class="view-all-comments" id="countCommentForSinglePost' + postObject['Id'] + '"><a href="#"><i class="fa fa-comments-o"></i> View all</a> 10 comments</div>'
+ '<ul class="comments" id="commentsAreaForSinglePost' + postObject['Id'] + '">'

+ '</ul>'
+ '<ul class="comments">'
+ '</div>'




+ '</div>'
+ '</li>'
+ '</ul>'
+ '</div>'
+ '</div>'
+ '</li>'
)

}
}
function getImagesForSiglePost(index, id) {
if (id == null) {
alert("postid = nul");
return;
}
$.ajax({
url: "/Post/getImagesForPost",
type: "GET",
data: {
postId: id,
},
success: function (successData) {
var obj = JSON.parse(successData);
var currentElement = {};
var listElement = "";
var isFirst = true;
$.each(obj, function (index, image) {
if (isFirst) {
$("#imagesPostForSinglePost" + image.postId).html("");
currentElement = $("#imagesPostForSinglePost" + image.postId);
isFirst = false;
if (obj.length == 1) {
$("#imagesPostForSinglePost" + image.postId).removeClass("testetetet").addClass("one-col");
if (parseInt(image.width) >= parseInt(image.height)) {
listElement = listElement +
'<div data-src="' + image.url + '" style="border:1px solid white"><img style="width:100%; height:auto" src="' +
image.thumbnailurl +
'" alt="The Last of us"></div>';
} else {
listElement = listElement +
'<div data-src="' + image.url + '" style="border:1px solid white" ><img style="height:100% !important; width:auto !important "src="' +
image.thumbnailurl +
'" alt="The Last of us"></div>';
}
return;
} else {
$("#imagesPostForSinglePost" + image.postId).removeClass("one-col").addClass("testetetet");
}
}
if (parseInt(image.width) >= parseInt(image.height)) {
listElement = listElement + '<div data-src="' + image.url + '" style="border:1px solid white"><img style="width:100% !important; height:auto !important" src="' + image.thumbnailurl + '" ></div>';
} else {
listElement = listElement + '<div data-src="' + image.url + '" style="border:1px solid white" ><img style="width:100% !important; height:auto !important" src="' + image.thumbnailurl + '"></div>';
}

});
listElement = listElement + "</div>";
currentElement.append(listElement);
currentElement.lightGallery();
},
error: function (er) {
alert(er);
}

});
}
function GetCommentForSinglePost(postid) {
if (postid == null) {
alert("postid == null");
return;
}
$.ajax({
url: "/Post/getCommentsForPost",
type: "GET",
data: {
postId: postid,
},
success: function (successData) {
var obj = JSON.parse(successData);
if (obj.length === 0) {
$("#countCommentForSinglePost" + postid).html("Chưa có bình luận nào");
} else {
$("#countCommentForSinglePost" + postid).html(obj.length + " bình luận");
}
$.each(obj, function (index, comment) {
addCommentToCommentAreaForSinglePost(postid, comment);
});
},
error: function (er) {
alert(er)
}

});
}
function addCommentToCommentAreaForSinglePost(postId, comment) {
$("#commentsAreaForSinglePost" + postId).append('<li>'
+ '<div class="media">'
+ '<a href="javascript:void(0)" onclick ="LoadUserProfile(' + comment["userId"] + ',true)" class="pull-left">'
+ '<img src="' + comment['userProfile'] + '" onerror="this.src=\'/Content/Images/defaultProfile.png\';" class="media-object avartar-img">'
+ '</a>'
+ '<div class="media-body">'
+ '<a href="javascript:void(0)" onclick ="LoadUserProfile(' + comment["userId"] + ',true)" class="comment-author">' + comment['username'] + ': </a>'
+ '<span>' + comment['detail'] + '</span>'
+ '<div class="comment-date">' + timeSince(comment['createdDate']) + ' trước </div>'
+ '</div>'
+ '</div>'

+ '</li>');

}



function getSinglePostObject(postId) {
$.ajax({
url: "/Post/getSinglePost",
type: "GET",
datatype: 'json',
data: {
postId: postId,
},
success: function (successData) {
console.log("GetPostData: " + successData);
var obj = JSON.parse(successData);
addPostTo("singlePostModal", 0, obj);
getImagesForSiglePost(0, obj["Id"]);
GetCommentForSinglePost(obj["Id"]);
// curTokenId = obj["Id"];
$("#displaySinglePost").modal('show');
},
error: function (er) {
alert(er);
}

});
}
16 changes: 16 additions & 0 deletions AMS/Service/PostService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ public List<PostMapping> getAllPostMapping(int? tokenId, int? houseId)

return postMappingResult;
}
public PostMapping getSiglePost(int postId)
{
Post p = postRepository.FindById(postId);
PostMapping pMapping = new PostMapping();
pMapping.Id = p.Id;
pMapping.Body = p.Body;
pMapping.CreateDate = p.CreateDate.GetValueOrDefault();
pMapping.EmbedCode = p.EmbedCode;
pMapping.UserId = p.UserId;
pMapping.username = p.User == null ? "Không xác định sở hữu" : p.User.Username;
pMapping.userProfile = p.User == null || p.User.ProfileImage == null || p.User.ProfileImage.Equals("") ? "/Content/Images/defaultProfile.png" : p.User.ProfileImage;
pMapping.userFullName = p.User == null ? "Không xác định" : p.User.Fullname;
pMapping.houseName = p.User.House == null ? "Không xác định" : p.User.House.HouseName;
return pMapping;
}

public List<Post> getAllPostByRole(int roleId)
{
var result = postRepository.List.Where(t => t.User.RoleId == roleId).OrderByDescending(t =>t.CreateDate).ToList();
Expand Down
6 changes: 3 additions & 3 deletions AMS/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
}
<link rel="stylesheet" href="~/Content/css/FamilyTree.css" type="text/css" />
<link rel="stylesheet" href="~/Content/css/lightgallery.min.css" type="text/css" />
<script src="~/Scripts/amsScript/DisplaySinglePost.js"></script>
<script src="~/Scripts/amsScript/LoadFamilyTree.js"></script>
<script src="~/Scripts/amsScript/LoadUserProfile.js"></script>
<script src="~/Scripts/amsScript/ReportPost.js"></script>

<style>
.button {
display: block;
Expand Down Expand Up @@ -470,8 +470,6 @@





@{
if (!alert.Equals("") && SLIM_CONFIG.CURRENT_MODE == SLIM_CONFIG.PROGRAM_MODE_PRODUCT)
{
Expand Down Expand Up @@ -952,4 +950,6 @@
o.style.height = "1px";
o.style.height = (25 + o.scrollHeight) + "px";
}
</script>

0 comments on commit 0ae5116

Please sign in to comment.