Commit db21ab6c authored by Rachana's avatar Rachana

Merge pull request #1243 from kedar2a/mongokit-discussion

enabled replies in discussion
parents 43da5d69 a0eb03e3
......@@ -9988,7 +9988,7 @@ aside#help p, aside#help h5, aside#help h6 {
/* line 926, ../../../scss/_app_styles.scss */
#replies-area .disc-replies {
padding: 10px;
background-color: #dffbfd;
background-color: #98f2f7;
width: 27em;
max-width: 40em;
margin-left: 48px;
......
......@@ -10082,7 +10082,7 @@ aside#help p, aside#help h5, aside#help h6 {
/* line 926, ../../../scss/_app_styles.scss */
#replies-area .disc-replies {
padding: 10px;
background-color: #fcfdfe;
background-color: #bedcf0;
width: 27em;
max-width: 40em;
margin-left: 48px;
......
......@@ -9988,7 +9988,7 @@ aside#help p, aside#help h5, aside#help h6 {
/* line 926, ../../../scss/_app_styles.scss */
#replies-area .disc-replies {
padding: 10px;
background-color: #dffbfd;
background-color: #98f2f7;
width: 27em;
max-width: 40em;
margin-left: 48px;
......
......@@ -926,7 +926,7 @@ aside#help{
#replies-area .disc-replies {
padding:10px;
background-color: lighten($primary-color, 55%);
background-color: lighten($primary-color, 40%);
width:27em;
max-width: 40em;
margin-left: 48px;
......
......@@ -138,7 +138,7 @@ function insertImg(fileurl){
$("#orgitdown_content_org").val(content);
}
}
$(".close-reveal-modal").trigger("click");
$("#insert-pic .close-reveal-modal").trigger("click");
}
}
......@@ -243,12 +243,13 @@ $(".orgitdownButton.orgitdownButton10 a").click(function(){
</div>
<div id="insert-pic" class="small reveal-modal" data-reveal>
<a class="close-reveal-modal">&#215;</a>
<h3>Add Internal/External Images:</h3>
<div>
<input type="radio" id="extimage" name="imginsert" onclick="externalImg()"><label>External</label>
<input type="radio" id="intimage" name="imginsert" onclick="internalImg()"><label>Internal</label>
</div></div>
<a class="close-reveal-modal">&#215;</a>
<h3>Add Internal/External Images:</h3>
<div>
<input type="radio" id="extimage" name="imginsert" onclick="externalImg()"><label>External</label>
<input type="radio" id="intimage" name="imginsert" onclick="internalImg()"><label>Internal</label>
</div>
</div>
<div id="int-img" class="small reveal-modal" data-reveal>
<a class="close-reveal-modal">&#215;</a>
......
......@@ -32,6 +32,20 @@
{{each_reply.HTMLcontent | safe }}
{% endspaceless %}
</div>
{% for node in each_reply.collection_set %}
<div style="margin: 1em;">
{{node.mime_type}}
<br/>
<a class="th" style="" href="{% url 'read_file' group_id node node.name %}">
{% if 'image' in node.mime_type %}
<img style="height:100px;" src="{% url 'getFileThumbnail' group_id node.pk %}" />
{% endif %}
<p>{{node.name}}</p>
</a>
</div>
{% endfor %}
</div>
<div class="row">
......@@ -53,6 +67,7 @@
<!-- Reply : -->
<textarea id="orgitdownreps" name="content_org" placeholder="Enter your reply text here."></textarea>
<input data-id="{{ node.pk }}" type="button" value="Post" class="button expand reply-button" onclick="addReply($(this))">
<input type="file" id="uploaded-files" style="" value="" multiple>
<input type="hidden" id="prior-node" style="visibility:hidden" value="">
<!-- <input type="hidden" id="thd" style="visibility:hidden" value=""> -->
</div>
......@@ -80,6 +95,7 @@
{% if request.user.is_authenticated %}
$("#orgitdownreps").orgitdown(mySettings);
{% endif %}
function createDiscussion()
{
......@@ -198,13 +214,30 @@
function createReplyHTML(replyStyle, data)
{
var files = data[8];
// console.log(files)
filesContent = ""
files.forEach(function(f){
// console.log("=========")
// console.log(f)
var mime_type = f[1];
filesContent += "<div style='margin: 1em;'>"+ f[1] +"<br/>"+
"<a class='th' href='/{{group_id}}/file/readDoc/"+f[0]+"/"+f[2]+"'>";
if(mime_type.indexOf("image") >= 0){
filesContent += "<img style='height: 100px;' src='/{{group_id}}/file/thumbnail/"+ f[0] +"'/>";}
filesContent += "<p>" + f[2] + "</p></a></div>";
// console.log(filesContent);
});
var htmlReply = "<div style='"+ replyStyle +"' data-reply-id='"+ data[1] +"' data-priornode-id='"+ data[2] +"' class='disc-replies'>"
+ "<div class='row'><div class='small-3 columns'><a href='/home/"+ data[5] +"/dashboard' class='text-center'>"
+ "<span class='align-center'><i class='fi-torso'></i></span>"
+ "<label>" + data[6] + "</label></a></div>"
+ "<div class='small-9 columns'>"+ data[3] +"</div></div>"
+ "<div class='small-9 columns'>"+ data[3] + filesContent +"</div></div>"
+ "<div class='row'><div class='small-8 columns'><small>"+ data[7] + "</small></div>"
+ "<div class='row'><div class='small-8 columns'><small>"+ data[7] +"</small></div>"
+ "<div class='reply-btn small-2 columns' data-userid='"+ data[5] +"' onclick='deleteReply($(this))'>delete</div>"
+ "<div data-org-content='"
+ data[4] + "' onclick='openOrgEditor($(this))' data-id='"
......@@ -225,19 +258,30 @@
if( (replyContent.length > 0) && (priorNodeId.length == 24) )
{
docs_list = new FormData();
var all_files = document.getElementById("uploaded-files");
var docs_count = all_files.files.length;
for(var i = 0; i < docs_count; i++)
{
docs_list.append("upload"+i, all_files.files[i]);
// console.log(all_files.files[i]);
}
docs_list.append('upload_cnt', docs_count)
docs_list.append('csrfmiddlewaretoken','{{csrf_token}}');
docs_list.append('reply_text_content', replyContent)
docs_list.append('prior_node_id', priorNodeId)
$.ajax({
type: "POST",
url: "{% url 'discussion_reply' group_id node.pk %}",
data: {
"csrfmiddlewaretoken": "{{ csrf_token }}",
"prior_node_id": priorNodeId,
"reply_text_content": replyContent
},
data: docs_list,
processData: false,
contentType: false,
success: function(data){
......
......@@ -854,6 +854,7 @@ def get_disc_replies( oid, group_id, global_disc_all_replies, level=1 ):
temp_disc_reply["userid"] = int(each.created_by)
temp_disc_reply["oid"] = str(each._id)
temp_disc_reply["prior_node"] = str(each.prior_node[0])
temp_disc_reply["collection_set"] = [node_collection.one({'_id': ObjectId(i)}) for i in each.collection_set]
temp_disc_reply["level"] = level
# to avoid redundancy of dicts, it checks if any 'oid' is not equals to each._id. Then only append to list
......
......@@ -98,9 +98,9 @@ urlpatterns = patterns('',
# (r'^(?P<group_id>[^/]+)/Observations', include('gnowsys_ndf.ndf.urls.observation')),
# --discussion--
url(r'^(?P<group_id>[^/]+)/(?P<node_id>[^/]+)/create_discussion$', 'gnowsys_ndf.ndf.views.methods.create_discussion', name='create_discussion'),
url(r'^(?P<group_id>[^/]+)/(?P<node_id>[^/]+)/discussion_reply$', 'gnowsys_ndf.ndf.views.methods.discussion_reply', name='discussion_reply'),
url(r'^(?P<group_id>[^/]+)/discussion_delete_reply$', 'gnowsys_ndf.ndf.views.methods.discussion_delete_reply', name='discussion_delete_reply'),
url(r'^(?P<group_id>[^/]+)/(?P<node_id>[^/]+)/create_discussion$', 'gnowsys_ndf.ndf.views.discussion.create_discussion', name='create_discussion'),
url(r'^(?P<group_id>[^/]+)/(?P<node_id>[^/]+)/discussion_reply$', 'gnowsys_ndf.ndf.views.discussion.discussion_reply', name='discussion_reply'),
url(r'^(?P<group_id>[^/]+)/discussion_delete_reply$', 'gnowsys_ndf.ndf.views.discussion.discussion_delete_reply', name='discussion_delete_reply'),
# --end of discussion
url(r'^(?P<group_id>[^/]+)/visualize', include('gnowsys_ndf.ndf.urls.visualise_urls')),
......
......@@ -4720,7 +4720,14 @@ def edit_task_content(request, group_id):
@get_execution_time
def insert_picture(request, group_id):
if request.is_ajax():
resource_list=node_collection.find({'_type' : 'File', 'mime_type' : u"image/jpeg" },{'name': 1})
resource_list=node_collection.find(
{
'_type' : 'File',
'group_set': {'$in': [ObjectId(group_id)]},
'mime_type' : u"image/jpeg"
},
{'name': 1})
resources=list(resource_list)
n=[]
for each in resources:
......
This diff is collapsed.
......@@ -2564,171 +2564,6 @@ def set_all_urls(member_of):
############################################### ###############################################
@login_required
@get_execution_time
def create_discussion(request, group_id, node_id):
'''
Method to create discussion thread for File and Page.
'''
try:
twist_st = node_collection.one({'_type':'GSystemType', 'name':'Twist'})
node = node_collection.one({'_id': ObjectId(node_id)})
# group = node_collection.one({'_id':ObjectId(group_id)})
thread = node_collection.one({ "_type": "GSystem", "name": node.name, "member_of": ObjectId(twist_st._id), "prior_node": ObjectId(node_id) })
if not thread:
# retriving RelationType
# relation_type = node_collection.one({ "_type": "RelationType", "name": u"has_thread", "inverse_name": u"thread_of" })
# Creating thread with the name of node
thread_obj = node_collection.collection.GSystem()
thread_obj.name = unicode(node.name)
thread_obj.status = u"PUBLISHED"
thread_obj.created_by = int(request.user.id)
thread_obj.modified_by = int(request.user.id)
thread_obj.contributors.append(int(request.user.id))
thread_obj.member_of.append(ObjectId(twist_st._id))
thread_obj.prior_node.append(ObjectId(node_id))
thread_obj.group_set.append(ObjectId(group_id))
thread_obj.save()
# creating GRelation
# create_grelation(node_id, relation_type, twist_st)
response_data = [ "thread-created", str(thread_obj._id) ]
return HttpResponse(json.dumps(response_data))
else:
response_data = [ "Thread-exist", str(thread._id) ]
return HttpResponse(json.dumps(response_data))
except Exception as e:
error_message = "\n DiscussionThreadCreateError: " + str(e) + "\n"
raise Exception(error_message)
# return HttpResponse("server-error")
# to add discussion replie
@get_execution_time
def discussion_reply(request, group_id, node_id):
try:
prior_node = request.POST.get("prior_node_id", "")
content_org = request.POST.get("reply_text_content", "") # reply content
# process and save node if it reply has content
if content_org:
user_id = int(request.user.id)
user_name = unicode(request.user.username)
# auth = node_collection.one({'_type': 'Author', 'name': user_name })
reply_st = node_collection.one({ '_type': 'GSystemType', 'name': 'Reply'})
# creating empty GST and saving it
reply_obj = node_collection.collection.GSystem()
reply_obj.name = unicode("Reply of:" + str(prior_node))
reply_obj.status = u"PUBLISHED"
reply_obj.created_by = user_id
reply_obj.modified_by = user_id
reply_obj.contributors.append(user_id)
reply_obj.member_of.append(ObjectId(reply_st._id))
reply_obj.prior_node.append(ObjectId(prior_node))
reply_obj.group_set.append(ObjectId(group_id))
reply_obj.content_org = unicode(content_org)
filename = slugify(unicode("Reply of:" + str(prior_node))) + "-" + user_name + "-"
reply_obj.content = org2html(content_org, file_prefix=filename)
# saving the reply obj
reply_obj.save()
formated_time = reply_obj.created_at.strftime("%B %d, %Y, %I:%M %p")
# ["status_info", "reply_id", "prior_node", "html_content", "org_content", "user_id", "user_name", "created_at" ]
reply = json.dumps( [ "reply_saved", str(reply_obj._id), str(reply_obj.prior_node[0]), reply_obj.content, reply_obj.content_org, user_id, user_name, formated_time], cls=DjangoJSONEncoder )
# ---------- mail/notification sending -------
node = node_collection.one({"_id": ObjectId(node_id)})
node_creator_user_obj = User.objects.get(id=node.created_by)
node_creator_user_name = node_creator_user_obj.username
site = Site.objects.get(pk=1)
site = site.name.__str__()
from_user = user_name
to_user_list = [node_creator_user_obj]
msg = "\n\nDear " + node_creator_user_name + ",\n\n" + \
"A reply has been added in discussion under the " + \
node.member_of_names_list[0] + " named: '" + \
node.name + "' by '" + user_name + "'."
activity = "Discussion Reply"
render_label = render_to_string(
"notification/label.html",
{
# "sender": from_user,
"activity": activity,
"conjunction": "-",
"link": "url_link"
}
)
notification.create_notice_type(render_label, msg, "notification")
notification.send(to_user_list, render_label, {"from_user": from_user})
# ---------- END of mail/notification sending ---------
return HttpResponse( reply )
else: # no reply content
return HttpResponse(json.dumps(["no_content"]))
except Exception as e:
error_message = "\n DiscussionReplyCreateError: " + str(e) + "\n"
raise Exception(error_message)
return HttpResponse(json.dumps(["Server Error"]))
@get_execution_time
def discussion_delete_reply(request, group_id):
nodes_to_delete = json.loads(request.POST.get("nodes_to_delete", "[]"))
reply_st = node_collection.one({ '_type':'GSystemType', 'name':'Reply'})
deleted_replies = []
for each_reply in nodes_to_delete:
temp_reply = node_collection.one({"_id": ObjectId(each_reply)})
if temp_reply:
deleted_replies.append(temp_reply._id.__str__())
temp_reply.delete()
return HttpResponse(json.dumps(deleted_replies))
@get_execution_time
def get_user_group(userObject):
'''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment