diff --git a/rocketc/rocketc.py b/rocketc/rocketc.py index d23c214d..14b52f8b 100644 --- a/rocketc/rocketc.py +++ b/rocketc/rocketc.py @@ -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 @@ -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): """ @@ -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) diff --git a/rocketc/static/css/rocketc.css b/rocketc/static/css/rocketc.css index 18a405cb..fe148253 100644 --- a/rocketc/static/css/rocketc.css +++ b/rocketc/static/css/rocketc.css @@ -5,11 +5,7 @@ } .rocketc_block p { - cursor: pointer; -} - -.rocketc_block p:hover { - background-color: red; + text-align: center; } .rocketc_block embed-container { diff --git a/rocketc/static/html/studio.html b/rocketc/static/html/studio.html index 42104b7b..7e9af160 100644 --- a/rocketc/static/html/studio.html +++ b/rocketc/static/html/studio.html @@ -1,12 +1,63 @@ +
+ +
-
- -
+
+
\ No newline at end of file +
  • + CREATE GROUP +
  • + + diff --git a/rocketc/static/js/src/studio_view.js b/rocketc/static/js/src/studio_view.js new file mode 100644 index 00000000..ea1dcf3e --- /dev/null +++ b/rocketc/static/js/src/studio_view.js @@ -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"); + }); + +} diff --git a/setup.cfg b/setup.cfg index b84feb70..a9f99db6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.3 +current_version = 0.2.4 commit = True tag = True diff --git a/setup.py b/setup.py index 02bae0cf..43bd67ba 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup -__version__ = '0.2.3' +__version__ = '0.2.4' def package_data(pkg, roots):