Skip to content

Commit

Permalink
Merge pull request #19 from eduNEXT/and/create_edit_view
Browse files Browse the repository at this point in the history
And/create edit view
  • Loading branch information
andrey-canon authored Apr 20, 2018
2 parents 8e74cca + 6f9c39f commit ce61581
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 22 deletions.
66 changes: 59 additions & 7 deletions rocketc/rocketc.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ def author_view(self, context=None):

return frag

def studio_view(self, context=None):
""" Returns edit studio view fragment """
frag = super(RocketChatXBlock, self).studio_view(context)
frag.add_content(LOADER.render_template(
'static/html/studio.html', context))
frag.add_css(self.resource_string("static/css/rocketc.css"))
frag.add_javascript(self.resource_string("static/js/src/studio_view.js"))
frag.initialize_js('StudioViewEdit')
return frag

# TO-DO: change this to create the scenarios you'd like to see in the
# workbench while developing your XBlock.
@staticmethod
Expand Down Expand Up @@ -344,16 +354,32 @@ def _update_user(self, user_id, username, email):
self._set_avatar(username)

@XBlock.json_handler
def set_default_channel(self, data, suffix=""):
def create_group(self, data, suffix=""):
"""
This method set the default variable for the channels
This method allows to create a group from studio
"""
# pylint: disable=unused-argument
default_channel = data["channel"]
if default_channel != " " and default_channel is not None:
default_channel = default_channel.replace(" ", "_")
self._create_group(default_channel)
self.default_channel = default_channel

group_name = data["groupName"]
description = data["description"]
topic = data["topic"]

if group_name == "" or group_name is None:
return {"success": False, "error": "Group Name is not valid"}

group_name = group_name.replace(" ", "_")
group = self._create_group(group_name)

if group["success"]:
self.default_channel = group_name

if "group" in group:
group_id = group["group"]["_id"]

self._set_description(group_id, description)
self._set_topic(group_id, topic)

return group

def _add_to_default_group(self, group_name, user_id):
"""
Expand Down Expand Up @@ -394,3 +420,29 @@ def _private_channel(self, room_name):
url_path = "channels.setType"
data = {"roomId": channel_id, "type": "p"}
self._request_rocket_chat("post", url_path, data)

def _set_description(self, group_id, description):
"""
This method allows to set a description's group
"""
if description == "" or description is None:
return

url_path = "groups.setDescription"
data = {"roomId": group_id, "description": description}
method = "post"

self._request_rocket_chat(method, url_path, data)

def _set_topic(self, group_id, topic):
"""
This method allows to set a topic's group
"""
if topic == "" or topic is None:
return

url_path = "groups.setTopic"
data = {"roomId": group_id, "topic": topic}
method = "post"

self._request_rocket_chat(method, url_path, data)
6 changes: 1 addition & 5 deletions rocketc/static/css/rocketc.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
}

.rocketc_block p {
cursor: pointer;
}

.rocketc_block p:hover {
background-color: red;
text-align: center;
}

.rocketc_block embed-container {
Expand Down
67 changes: 59 additions & 8 deletions rocketc/static/html/studio.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,63 @@

<div class="rocketc_block">
<div class="editor-with-buttons" style="display: none;">
<div class="wrapper-comp-settings is-active editor-with-buttons">
<ul class="list-input settings-list">

<li class="field comp-setting-entry metadata_entry ">
<div class="wrapper-comp-setting">
<label class="label setting-label">Group Name</label>
<input type="text" id="group-name" required></input>
</div>
</li>

<li class="field comp-setting-entry metadata_entry ">
<div class="wrapper-comp-setting">
<label class="label setting-label">Description</label>
<input type="text" id="group-description"></input>
</div>
</li>

<li class="field comp-setting-entry metadata_entry ">
<div class="wrapper-comp-setting">
<label class="label setting-label">Topic</label>
<input type="text" id="group-topic"></input>
</div>
</li>

<li class="field comp-setting-entry metadata_entry ">
<div class="wrapper-comp-setting">
<p id="message"></p>
</div>
</li>


</ul>
</div>

<div class="xblock-actions" style="background-color: #E5E5E5;">
<ul>
<li class="action-item">
<a href="#" class="button action-primary" id="button-create">Create Group</a>
</li>

<li class="action-item">
<a href="#" class="button cancel-button">Exit</a>
</li>
</ul>
</div>

<div>
<label for="name">Channel:</label>
<input type="text" id="name" placeholder="{{default_channel}}" />
</div>
</div>
</div>

<div class="button">
<button id="button" type="submit">Save</button>
</div>
<div class="xblock-actions" id="options" style="cursor: pointer;">
<ul>
<li class="action-item">
<a class="button action-primary" id="select-default" >DEFAULT CHANNEL</a>
</li>

</div>
<li class="action-item">
<a class="button" id="select-create">CREATE GROUP</a>
</li>
</ul>
</div>
50 changes: 50 additions & 0 deletions rocketc/static/js/src/studio_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Javascript for StudioView. */
function StudioViewEdit(runtime, element) {
"use strict";

/*eslint no-undef: "error"*/
StudioEditableXBlockMixin(runtime, element);

function responseCreate(data){
if (data["success"]) {
$("#message").text("Group Created").
css("color", "green");
}else{
$("#message").text(data["error"]).
css("color", "red");
}

}

var createGroup = runtime.handlerUrl(element, "create_group");

$("#button-create").click(function(eventObject) {
var groupName = $("#group-name").val();
var description = $("#group-description").val();
var topic = $("#group-topic").val();
var data = {groupName, description, topic};
$.ajax({
type: "POST",
url: createGroup,
data: JSON.stringify(data),
success: responseCreate
});
});

$(".action-modes").append($("#options"));

$("#select-default").on("click",function(){
$(".editor-with-buttons").css("display", "block");
$(".rocketc_block .editor-with-buttons").css("display", "none");
$("#select-create").attr("class", "button");
$("#select-default").attr("class", "button action-primary");
});

$("#select-create").on("click",function(){
$(".editor-with-buttons").css("display", "none");
$(".rocketc_block .editor-with-buttons").css("display", "block");
$("#select-create").attr("class", "button action-primary");
$("#select-default").attr("class", "button");
});

}
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.3
current_version = 0.2.4
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from setuptools import setup

__version__ = '0.2.3'
__version__ = '0.2.4'


def package_data(pkg, roots):
Expand Down

0 comments on commit ce61581

Please sign in to comment.