Skip to content

Commit

Permalink
Merge pull request #33 from rwth-acis/develop
Browse files Browse the repository at this point in the history
v1.1.1
  • Loading branch information
phil-cd committed Jul 14, 2022
2 parents 6912fe8 + c3c5302 commit e8fe95d
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 47 deletions.
54 changes: 20 additions & 34 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rwth-acis/las2peer-project-service-frontend",
"version": "0.3.2",
"version": "0.4.0",
"description": "Frontend for las2peer project service.",
"main": "project-list.js",
"module": "project-list.js",
Expand All @@ -21,6 +21,7 @@
"@polymer/iron-icons": "^3.0.1",
"@polymer/paper-button": "^3.0.1",
"@polymer/paper-card": "^3.0.1",
"@polymer/paper-checkbox": "^3.1.0",
"@polymer/paper-dialog": "^3.0.1",
"@polymer/paper-dropdown-menu": "^3.1.0",
"@polymer/paper-input": "^3.2.1",
Expand Down
30 changes: 29 additions & 1 deletion frontend/project-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '@polymer/paper-listbox/paper-listbox.js';
import '@polymer/paper-tabs';
import '@polymer/iron-icon/iron-icon.js';
import '@polymer/iron-icons/social-icons.js';
import '@polymer/paper-checkbox/paper-checkbox.js';
import OnlineUserListHelper from './util/online-user-list-helper'

import Auth from './util/auth';
Expand Down Expand Up @@ -205,7 +206,8 @@ export class ProjectList extends LitElement {
*/
projectOptionsSelected: {
type: Object
}
},
connectChannelVisible: { type: Boolean }
};
}

Expand All @@ -225,6 +227,7 @@ export class ProjectList extends LitElement {
this.disableAllProjects = false;
this.yjsAddress = "http://127.0.0.1:1234";
this.yjsResourcePath = "./socket.io";
this.connectChannelVisible = false;
}

connectedCallback() {
Expand Down Expand Up @@ -378,6 +381,14 @@ export class ProjectList extends LitElement {
`)}
</paper-listbox>
</paper-dropdown-menu>
<div>
<paper-checkbox id="cb-connect-channel" @change=${(e) => this.connectChannelVisible = e.target.checked} >Connect to chat channel</paper-checkbox>
<div ?hidden=${!this.connectChannelVisible}>
<paper-input id="input-channel-name" placeholder="Channel name"></paper-input>
or:
<paper-checkbox id="cb-create-new-channel">Create new channel</paper-checkbox>
</div>
</div>
<div class="buttons">
<paper-button @click="${this._closeCreateProjectDialogClicked}" dialog-dismiss>Cancel</paper-button>
<paper-button id="dialog-button-create" @click="${this._createProject}" dialog-confirm>Create</paper-button>
Expand Down Expand Up @@ -733,6 +744,23 @@ export class ProjectList extends LitElement {
"linkedGroup": linkedGroup,
"users": users
};

// check if project should be linked to chat channel
const connectChannel = this.shadowRoot.getElementById("cb-connect-channel").checked;
const chatInfo = {
connectChannel,
newChannel: false
};
if(connectChannel) {
// check if new channel should be created
const newChannel = this.shadowRoot.getElementById("cb-create-new-channel").checked;
chatInfo.newChannel = newChannel;
if(!newChannel) {
chatInfo.channelName = this.shadowRoot.getElementById("input-channel-name").value;
}
}
body.chatInfo = chatInfo;

if(GitHub.gitHubUsernameStored()) {
body.gitHubUsername = GitHub.getGitHubUsername();
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
core.version=1.2.2
service.name=i5.las2peer.services.projectService
service.class=ProjectService
service.version=1.1.0
service.version=1.1.1
java.version=17

las2peer_user1.name=alice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ public Response postProject(@PathParam("system") String system, String inputProj
Project project;
String creatorGitHubUsername = null;

JSONObject bodyJSON;

try {
project = new Project(agent, inputProject);
JSONObject bodyJSON = (JSONObject) JSONValue.parseWithException(inputProject);
bodyJSON = (JSONObject) JSONValue.parseWithException(inputProject);
if(bodyJSON.containsKey("gitHubUsername")) {
creatorGitHubUsername = (String) bodyJSON.get("gitHubUsername");
}
Expand Down Expand Up @@ -296,12 +298,27 @@ public Response postProject(@PathParam("system") String system, String inputProj
}
}

// check if chat channel should be created
if(this.systemsConfig.isChannelCreationEnabled(system)) {
ChatManager chatManager = this.systemsConfig.getChatManager(system);
JSONObject chatInfo = chatManager.createProjectChannel(project, system);
if(chatInfo != null) {
project.setChatInfo(chatInfo);
// check if chat channel connection is enabled for the system
if(this.systemsConfig.isChannelConnectionEnabled(system)) {
// check if channel should be linked for the new project
JSONObject bodyChatInfo = (JSONObject) bodyJSON.get("chatInfo");
boolean connectChannel = (boolean) bodyChatInfo.get("connectChannel");
if(connectChannel) {
ChatManager chatManager = this.systemsConfig.getChatManager(system);
JSONObject chatInfo;

boolean newChannel = (boolean) bodyChatInfo.get("newChannel");
if (newChannel) {
chatInfo = chatManager.createProjectChannel(project, system);
} else {
// use existing channel
String channelName = (String) bodyChatInfo.get("channelName");
chatInfo = chatManager.getChannelInfoForExistingChannel(channelName);
}

if (chatInfo != null) {
project.setChatInfo(chatInfo);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public ChatManager(ChatConfig config) {
}

public abstract JSONObject createProjectChannel(Project project, String systemName);
public abstract JSONObject getChannelInfoForExistingChannel(String channelName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ public JSONObject createProjectChannel(Project project, String systemName) {
return channelInfo;
}

@Override
public JSONObject getChannelInfoForExistingChannel(String channelName) {
String channelId = getChannelIdByName(channelName);
JSONObject channelInfo = new JSONObject();
channelInfo.put("type", "RocketChat");
channelInfo.put("url", getConfig().getUrl());
channelInfo.put("channelId", channelId);
channelInfo.put("chatUrl", getConfig().getUrl() + "/channel/" + channelId);
return channelInfo;
}

private String getChannelIdByName(String channelName) {
HttpResponse<String> response = Unirest.get(getConfig().getUrl() + "/api/v1/channels.info")
.header("X-Auth-Token", getConfig().getBotAuthToken())
.header("X-User-Id", getConfig().getBotUserId())
.queryString("roomName", channelName)
.asString();

if(!response.isSuccess()) {
System.out.println("RocketChat channel info request failed.");
return null;
}

JSONObject res = (JSONObject) JSONValue.parse(response.getBody());
JSONObject resChannel = (JSONObject) res.get("channel");
return (String) resChannel.get("_id");
}

private RocketChatConfig getConfig() {
return (RocketChatConfig) this.config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public RocketChatConfig getRocketChatConfig() {
return rocketChatConfig;
}

public boolean isChannelCreationEnabled() {
public boolean isChannelConnectionEnabled() {
return this.rocketChatConfig != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ public String getGitHubPATBySystem(String systemName) {
return null;
}

public boolean isChannelCreationEnabled(String systemName) {
public boolean isChannelConnectionEnabled(String systemName) {
for(ProjectServiceSystem system : this.systems) {
if(system.getName().equals(systemName)) return system.isChannelCreationEnabled();
if(system.getName().equals(systemName)) return system.isChannelConnectionEnabled();
}
return false;
}
Expand Down

0 comments on commit e8fe95d

Please sign in to comment.