mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-09-11 23:00:06 +02:00
refactor MindmapFilter to accept Label Filters
This commit is contained in:
parent
684c412e95
commit
148b56aecb
@ -25,57 +25,73 @@ import com.wisemapping.model.User;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public enum MindmapFilter {
|
||||
ALL("all") {
|
||||
public abstract class MindmapFilter {
|
||||
|
||||
public static MindmapFilter ALL = new MindmapFilter("all") {
|
||||
@Override
|
||||
public boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||
return true;
|
||||
}
|
||||
|
||||
},
|
||||
MY_MAPS("my_maps") {
|
||||
};
|
||||
public static MindmapFilter MY_MAPS = new MindmapFilter("my_maps") {
|
||||
@Override
|
||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||
return mindmap.getCreator().identityEquality(user);
|
||||
}
|
||||
},
|
||||
STARRED("starred") {
|
||||
};
|
||||
public static MindmapFilter STARRED = new MindmapFilter("starred") {
|
||||
@Override
|
||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||
return mindmap.isStarred(user);
|
||||
}
|
||||
},
|
||||
SHARED_WITH_ME("shared_with_me") {
|
||||
};
|
||||
public static MindmapFilter SHARED_WITH_ME = new MindmapFilter("shared_with_me") {
|
||||
@Override
|
||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||
return !MY_MAPS.accept(mindmap, user);
|
||||
}
|
||||
},
|
||||
PUBLIC("public") {
|
||||
};
|
||||
public static MindmapFilter PUBLIC = new MindmapFilter("public") {
|
||||
@Override
|
||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||
return mindmap.isPublic();
|
||||
}
|
||||
};
|
||||
|
||||
private String id;
|
||||
protected String id;
|
||||
private static MindmapFilter[] values = {ALL, MY_MAPS, PUBLIC, STARRED, SHARED_WITH_ME};
|
||||
|
||||
MindmapFilter(@NotNull String id) {
|
||||
private 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) {
|
||||
static public MindmapFilter parse(@Nullable final String valueStr) {
|
||||
MindmapFilter result = valueStr == null ? ALL : null;
|
||||
for (MindmapFilter value : MindmapFilter.values) {
|
||||
if (value.id.equals(valueStr)) {
|
||||
result = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
assert valueStr != null;
|
||||
result = new LabelFilter(valueStr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
abstract boolean accept(@NotNull Mindmap mindmap, @NotNull User user);
|
||||
|
||||
private static final class LabelFilter extends MindmapFilter {
|
||||
|
||||
private LabelFilter(@NotNull String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||
return mindmap.hasLabel(this.id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -171,7 +171,8 @@ $(function () {
|
||||
}
|
||||
};
|
||||
|
||||
$('#foldersContainer li').click(function (event) {
|
||||
//live method is deprecated?
|
||||
$('#foldersContainer li').live('click', function (event) {
|
||||
// Deselect previous option ...
|
||||
$('#foldersContainer li').removeClass('active');
|
||||
$('#foldersContainer i').removeClass('icon-white');
|
||||
|
Loading…
Reference in New Issue
Block a user