mirror of
https://bitbucket.org/wisemapping/wisemapping-open-source.git
synced 2024-11-09 00:43:23 +01: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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public enum MindmapFilter {
|
public abstract class MindmapFilter {
|
||||||
ALL("all") {
|
|
||||||
|
public static MindmapFilter ALL = new MindmapFilter("all") {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
},
|
public static MindmapFilter MY_MAPS = new MindmapFilter("my_maps") {
|
||||||
MY_MAPS("my_maps") {
|
|
||||||
@Override
|
@Override
|
||||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||||
return mindmap.getCreator().identityEquality(user);
|
return mindmap.getCreator().identityEquality(user);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
STARRED("starred") {
|
public static MindmapFilter STARRED = new MindmapFilter("starred") {
|
||||||
@Override
|
@Override
|
||||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||||
return mindmap.isStarred(user);
|
return mindmap.isStarred(user);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
SHARED_WITH_ME("shared_with_me") {
|
public static MindmapFilter SHARED_WITH_ME = new MindmapFilter("shared_with_me") {
|
||||||
@Override
|
@Override
|
||||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||||
return !MY_MAPS.accept(mindmap, user);
|
return !MY_MAPS.accept(mindmap, user);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
PUBLIC("public") {
|
public static MindmapFilter PUBLIC = new MindmapFilter("public") {
|
||||||
@Override
|
@Override
|
||||||
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
boolean accept(@NotNull Mindmap mindmap, @NotNull User user) {
|
||||||
return mindmap.isPublic();
|
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;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public MindmapFilter parse(@Nullable String valueStr) {
|
static public MindmapFilter parse(@Nullable final String valueStr) {
|
||||||
MindmapFilter result = ALL;
|
MindmapFilter result = valueStr == null ? ALL : null;
|
||||||
final MindmapFilter[] values = MindmapFilter.values();
|
for (MindmapFilter value : MindmapFilter.values) {
|
||||||
for (MindmapFilter value : values) {
|
|
||||||
if (value.id.equals(valueStr)) {
|
if (value.id.equals(valueStr)) {
|
||||||
result = value;
|
result = value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (result == null) {
|
||||||
|
assert valueStr != null;
|
||||||
|
result = new LabelFilter(valueStr);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract boolean accept(@NotNull Mindmap mindmap, @NotNull User user);
|
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 ...
|
// Deselect previous option ...
|
||||||
$('#foldersContainer li').removeClass('active');
|
$('#foldersContainer li').removeClass('active');
|
||||||
$('#foldersContainer i').removeClass('icon-white');
|
$('#foldersContainer i').removeClass('icon-white');
|
||||||
|
Loading…
Reference in New Issue
Block a user