Start working on a folders support.
This commit is contained in:
@@ -41,15 +41,19 @@ public class MindmapController extends BaseController {
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/maps", produces = {"application/json", "text/html", "application/xml"})
|
||||
public ModelAndView getMindmaps() throws IOException {
|
||||
public ModelAndView getMindmaps(@RequestParam(required = false) String q) throws IOException {
|
||||
final User user = com.wisemapping.security.Utils.getUser();
|
||||
|
||||
final MindmapFilter filter = MindmapFilter.parse(q);
|
||||
|
||||
final List<MindmapUser> mapsByUser = mindmapService.getMindmapUserByUser(user);
|
||||
final List<MindMap> mindmaps = new ArrayList<MindMap>();
|
||||
for (MindmapUser mindmapUser : mapsByUser) {
|
||||
mindmaps.add(mindmapUser.getMindMap());
|
||||
final MindMap mindmap = mindmapUser.getMindMap();
|
||||
if (filter.accept(mindmap, user)) {
|
||||
mindmaps.add(mindmap);
|
||||
}
|
||||
}
|
||||
|
||||
final RestMindmapList restMindmapList = new RestMindmapList(mindmaps);
|
||||
return new ModelAndView("mapsView", "list", restMindmapList);
|
||||
}
|
||||
|
@@ -0,0 +1,56 @@
|
||||
package com.wisemapping.rest;
|
||||
|
||||
|
||||
import com.wisemapping.model.MindMap;
|
||||
import com.wisemapping.model.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum MindmapFilter {
|
||||
ALL("all") {
|
||||
@Override
|
||||
public boolean accept(@NotNull MindMap mindmap, @NotNull User user) {
|
||||
return true;
|
||||
}
|
||||
|
||||
},
|
||||
MY_MAPS("my_maps") {
|
||||
@Override
|
||||
boolean accept(@NotNull MindMap mindmap, @NotNull User user) {
|
||||
return mindmap.getOwner().equals(user);
|
||||
}
|
||||
},
|
||||
SHARED_WITH_ME("shared_with_me") {
|
||||
@Override
|
||||
boolean accept(@NotNull MindMap mindmap, @NotNull User user) {
|
||||
return !MY_MAPS.accept(mindmap, user);
|
||||
}
|
||||
},
|
||||
PUBLIC("public") {
|
||||
@Override
|
||||
boolean accept(@NotNull MindMap mindmap, @NotNull User user) {
|
||||
return mindmap.isPublic();
|
||||
}
|
||||
};
|
||||
|
||||
private String id;
|
||||
|
||||
MindmapFilter(@NotNull String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
static public MindmapFilter parse(@Nullable String valueStr) {
|
||||
MindmapFilter result = ALL;
|
||||
final MindmapFilter[] values = MindmapFilter.values();
|
||||
for (MindmapFilter value : values) {
|
||||
if (value.id.equals(valueStr)) {
|
||||
result = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
abstract boolean accept(@NotNull MindMap mindmap, @NotNull User user);
|
||||
|
||||
}
|
Reference in New Issue
Block a user