Skip to content

Commit d528085

Browse files
authored
Merge pull request #899 from MatzElectronics/demo
Add project list to user profile page
2 parents 2ac27e4 + f395c07 commit d528085

File tree

7 files changed

+133
-11
lines changed

7 files changed

+133
-11
lines changed

src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public List<ProjectRecord> getSharedProjects(TableSort sort, TableOrder order, I
213213
}
214214
Condition conditions = Tables.PROJECT.SHARED.eq(Boolean.TRUE);
215215
if (idUser != null) {
216-
conditions = conditions.or(Tables.PROJECT.ID_USER.eq(idUser));
216+
conditions = conditions.and(Tables.PROJECT.ID_USER.eq(idUser));
217217
}
218218
return create.selectFrom(Tables.PROJECT).where(conditions).orderBy(orderField).limit(limit).offset(offset).fetch();
219219
}
@@ -227,7 +227,7 @@ public int countUserProjects(Long idUser) {
227227
public int countSharedProjects(Long idUser) {
228228
Condition conditions = Tables.PROJECT.SHARED.equal(Boolean.TRUE);
229229
if (idUser != null) {
230-
conditions = conditions.or(Tables.PROJECT.ID_USER.eq(idUser));
230+
conditions = conditions.and(Tables.PROJECT.ID_USER.eq(idUser));
231231
}
232232
return create.fetchCount(Tables.PROJECT, conditions);
233233
}

src/main/java/com/parallax/server/blocklyprop/rest/RestSharedProject.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,30 @@ public Response get(@QueryParam("sort") TableSort sort, @QueryParam("order") Tab
7272
return Response.ok(result.toString()).build();
7373
}
7474

75+
@GET
76+
@Path("/list/user/{id}")
77+
@Detail("Get shared projects by user")
78+
@Name("Get shared projects by user")
79+
@Produces("application/json")
80+
public Response get(@QueryParam("sort") TableSort sort, @QueryParam("order") TableOrder order, @QueryParam("limit") Integer limit, @QueryParam("offset") Integer offset, @PathParam("id") Long idUser) {
81+
System.out.println("Sort: " + sort);
82+
83+
List<ProjectRecord> projects = projectService.getSharedProjectsByUser(sort, order, limit, offset, idUser);
84+
int projectCount = projectService.countSharedProjectsByUser(idUser);
85+
86+
JsonObject result = new JsonObject();
87+
JsonArray jsonProjects = new JsonArray();
88+
for (ProjectRecord project : projects) {
89+
jsonProjects.add(projectConverter.toListJson(project));
90+
}
91+
92+
result.add("rows", jsonProjects);
93+
result.addProperty("total", projectCount);
94+
95+
return Response.ok(result.toString()).build();
96+
}
97+
98+
7599
@GET
76100
@Path("/get/{id}")
77101
@Detail("Get project by id")

src/main/java/com/parallax/server/blocklyprop/services/ProjectService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ public interface ProjectService {
2525

2626
List<ProjectRecord> getSharedProjects(TableSort tablesSort, TableOrder order, Integer limit, Integer offset);
2727

28+
List<ProjectRecord> getSharedProjectsByUser(TableSort tablesSort, TableOrder order, Integer limit, Integer offset, Long idUser);
29+
2830
int countUserProjects(Long idUser);
2931

3032
int countSharedProjects();
33+
34+
int countSharedProjectsByUser(Long idUser);
3135

3236
ProjectRecord saveProject(Long idProject, String name, String description, String descriptionHtml, boolean privateProject, boolean sharedProject, ProjectType type, String board);
3337

src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public List<ProjectRecord> getSharedProjects(TableSort sort, TableOrder order, I
8686
return projectDao.getSharedProjects(sort, order, limit, offset, BlocklyPropSecurityUtils.getCurrentUserId());
8787
}
8888

89+
@Override
90+
public List<ProjectRecord> getSharedProjectsByUser(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) {
91+
return projectDao.getSharedProjects(sort, order, limit, offset, idUser);
92+
}
93+
8994
@Override
9095
public int countUserProjects(Long idUser) {
9196
return projectDao.countUserProjects(idUser);
@@ -95,6 +100,11 @@ public int countUserProjects(Long idUser) {
95100
public int countSharedProjects() {
96101
return projectDao.countSharedProjects(BlocklyPropSecurityUtils.getCurrentUserId());
97102
}
103+
104+
@Override
105+
public int countSharedProjectsByUser(Long idUser) {
106+
return projectDao.countSharedProjects(idUser);
107+
}
98108

99109
@Override
100110
public ProjectRecord saveProject(Long idProject, String name, String description, String descriptionHtml, boolean privateProject, boolean sharedProject, ProjectType type, String board) {

src/main/webapp/WEB-INF/servlet/public-profile.jsp

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,97 @@
2020
<h2><fmt:message key="public-profile.title" />: <span class="user"><%= request.getAttribute("screenname")%></span></h2>
2121
<div>
2222
<ul class="nav nav-pills" role="tablist">
23-
<li role="presentation" class="active"><a data-toggle="tab" href="#profile"><fmt:message key="public-profile.nav.profile" /></a></li>
24-
<li role="presentation"><a data-toggle="tab" href="#projects"><fmt:message key="public-profile.nav.projects" /></a></li>
25-
</ul>
23+
<li role="presentation" id="select-projects" class="active"><a data-toggle="tab" href="#projects"><fmt:message key="public-profile.nav.projects" /></a></li>
24+
<li role="presentation" id="select-profile"><a data-toggle="tab" href="#profile"><fmt:message key="public-profile.nav.profile" /></a></li>
25+
</ul>
2626
<div class="tab-content">
27-
<div role="tabpanel" class="tab-pane active" id="profile">
27+
<div role="tabpanel" class="tab-pane" id="profile">
2828
<h3><fmt:message key="public-profile.friends" /></h3>
2929
</div>
30-
<div role="tabpanel" class="tab-pane" id="projects">
30+
<div role="tabpanel" class="tab-pane active" id="projects">
3131
<h3><fmt:message key="public-profile.projects" /></h3>
32+
<hr>
33+
<ul class="latest-projects"></ul>
34+
<hr>
35+
<span id="project-list-pages">Projects: </span>
36+
37+
<script>
38+
var getUrlParameter = function getUrlParameter(sParam) {
39+
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
40+
sURLVariables = sPageURL.split('&'),
41+
sParameterName,
42+
i;
43+
44+
for (i = 0; i < sURLVariables.length; i++) {
45+
sParameterName = sURLVariables[i].split('=');
46+
47+
if (sParameterName[0] === sParam) {
48+
return sParameterName[1] === undefined ? true : sParameterName[1];
49+
}
50+
}
51+
};
52+
53+
54+
var getUrl = window.location;
55+
var baseUrl = getUrl.protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];
56+
var pageUrl = getUrl.protocol + "/" + getUrl.host + "/" + getUrl.pathname.split('?')[0];
57+
58+
var projectTypes = {
59+
"PROPC": {
60+
"editor": "blocklyc.jsp",
61+
"class": "editor-c-link"
62+
},
63+
"SPIN": {
64+
"editor": "blocklyspin.jsp",
65+
"class": "editor-spin-link"
66+
}
67+
};
68+
69+
var page = 0;
70+
if(getUrlParameter('page') === undefined) page = 0;
71+
else {
72+
$('#profile').removeClass('active');
73+
$('#projects').addClass('active');
74+
$('#select-projects').tab('show');
75+
page = parseInt(getUrlParameter('page')) * 10;
76+
}
77+
78+
$.get(baseUrl + "/rest/shared/project/list/user/" + getUrlParameter('id-user') + "?sort=modified&order=desc&limit=10&offset=" + page.toString(10), function (data) {
79+
$.each(data['rows'], function (index, project) {
80+
var projectItem = $("<li/>", {
81+
"class": "project"
82+
});
83+
$("<a/>", {
84+
"class": "editor-view-link editor-icon " + projectTypes[project['type']]['class'],
85+
"href": baseUrl + "/projects.jsp#" + project['id'],
86+
"text": project['name']
87+
}).appendTo(projectItem);
88+
$(".latest-projects").append(projectItem);
89+
});
90+
var projPages = parseInt(data['total']);
91+
for(var idx = 1; idx <= projPages; idx += 10) {
92+
var startNum = idx.toString(10);
93+
var endNum = (idx + 9).toString(10);
94+
if(endNum > projPages) endNum = projPages;
95+
96+
var linkPage = parseInt(idx/10).toString(10);
97+
var btnLink = '';
98+
btnLink += '<a href="?id-user=' + getUrlParameter('id-user');
99+
btnLink += '&page=' + linkPage + '" class="btn btn-secondary btn-sm" ';
100+
btnLink += 'role="button" id="projPage-' + linkPage + '">';
101+
102+
$("#project-list-pages").append(btnLink + startNum + "-" + endNum + "</a>");
103+
104+
if(linkPage === getUrlParameter('page')) {
105+
$('#projPage-' + linkPage).removeClass('btn-secondary').addClass('btn-primary');
106+
} else if( getUrlParameter('page') === undefined && linkPage === '0') {
107+
$('#projPage-' + linkPage).removeClass('btn-secondary').addClass('btn-primary');
108+
}// Use to add active to button class
109+
}
110+
});
111+
112+
</script>
113+
32114
</div>
33115
</div>
34116
</div>
@@ -37,7 +119,9 @@
37119
</div>
38120
</div>
39121

122+
40123
<%@ include file="/WEB-INF/includes/pageparts/footer.jsp"%>
41124

125+
42126
</body>
43127
</html>

src/main/webapp/cdn/blocklyc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ function tabClick(id) {
8181
function renderContent() {
8282
var content = document.getElementById('content_' + selected);
8383
// Initialize the pane.
84-
if (content.id == 'content_blocks') {
84+
if (content.id === 'content_blocks') {
8585
Blockly.mainWorkspace.render();
86-
} else if (content.id == 'content_xml') {
86+
} else if (content.id === 'content_xml') {
8787
var xmlDom = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace);
8888
var xmlText = Blockly.Xml.domToPrettyText(xmlDom);
8989
codeXml.setValue(xmlText);
9090
codeXml.gotoLine(0);
91-
} else if (content.id == 'content_propc') {
91+
} else if (content.id === 'content_propc') {
9292
var code = Blockly.propc.workspaceToCode(Blockly.mainWorkspace);
9393
codePropC.setValue(js_beautify(code, {
9494
'brace_style': 'expand'

src/main/webapp/editor/blocklyc.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<div class="modal-content">
7171
<div class="modal-header">
7272
<button type="button" class="close" data-dismiss="modal" onclick="clearUploadInfo();" aria-hidden="true">&times;</button>
73-
<h4 class="modal-title" id="compile-dialog-title"><fmt:message key="editor.upload" /></h4>
73+
<h4 class="modal-title" id="upload-dialog-title"><fmt:message key="editor.upload" /></h4>
7474
</div>
7575
<div class="modal-body">
7676

0 commit comments

Comments
 (0)