Skip to content

Add screening criteria #194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public void update(AnActionEvent e) {
}
}
}

e.getPresentation().setIcon(null);

}


Expand All @@ -51,7 +49,11 @@ public AnAction[] getChildren(AnActionEvent anActionEvent) {

if (tags != null && !tags.isEmpty()) {
for (Tag tag : tags) {
anActionList.add(new FindTagAction(tag.getName(), tag));
if ("leetcode.find.Category".equals(id)) {
anActionList.add(new FindTagAction(tag.getName(), tag, true));
}else {
anActionList.add(new FindTagAction(tag.getName(), tag));
}
}
}
AnAction[] anActions = new AnAction[anActionList.size()];
Expand All @@ -69,6 +71,8 @@ private List<Tag> getTags(String id) {
tags = ViewManager.getFilter(Constant.FIND_TYPE_LISTS);
} else if ("leetcode.find.Tags".equals(id)) {
tags = ViewManager.getFilter(Constant.FIND_TYPE_TAGS);
} else if ("leetcode.find.Category".equals(id)) {
tags = ViewManager.getFilter(Constant.FIND_TYPE_CATEGORY);
}

return tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ public void actionPerformed(AnActionEvent anActionEvent, Config config) {
if (tree == null) {
return;
}
ViewManager.clearFilter();
ViewManager.update(tree);
boolean isLoad = ViewManager.clearFilter();
if (isLoad) {
ViewManager.loadServiceData(tree,anActionEvent.getProject());
} else {
ViewManager.update(tree);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
import com.shuzijun.leetcode.plugin.manager.ViewManager;
import com.shuzijun.leetcode.plugin.model.Tag;
import com.shuzijun.leetcode.plugin.utils.DataKeys;
import com.shuzijun.leetcode.plugin.window.WindowFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
Expand All @@ -17,11 +21,19 @@ public class FindTagAction extends ToggleAction {

private Tag tag;

private boolean againLoad = false;

public FindTagAction(@Nullable String text, Tag tag) {
super(text);
this.tag = tag;
}

public FindTagAction(@Nullable String text, Tag tag, boolean againLoad) {
super(text);
this.tag = tag;
this.againLoad = againLoad;
}

@Override
public boolean isSelected(AnActionEvent anActionEvent) {
return tag.isSelect();
Expand All @@ -34,7 +46,22 @@ public void setSelected(AnActionEvent anActionEvent, boolean b) {
if (tree == null) {
return;
}
ViewManager.update(tree);
if (againLoad) {
ProgressManager.getInstance().run(new Task.Backgroundable(anActionEvent.getProject(), "leetcode.editor." + tag.getName(), false) {
@Override
public void run(@NotNull ProgressIndicator progressIndicator) {
if (b) {
ViewManager.loadServiceData(tree, anActionEvent.getProject(), tag.getType());
} else {
ViewManager.loadServiceData(tree, anActionEvent.getProject());
}

}
});

} else {
ViewManager.update(tree);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public class QuestionManager {
private final static String TRANSLATIONNAME = "translation.json";


public static List<Question> getQuestionService(Project project) {
public static List<Question> getQuestionService(Project project, String url) {
List<Question> questionList = null;

HttpRequest httpRequest = HttpRequest.get(URLUtils.getLeetcodeAll());
HttpRequest httpRequest = HttpRequest.get(url);
HttpResponse response = HttpRequestUtils.executeGet(httpRequest);
if (response != null && response.getStatusCode() == 200) {
questionList = parseQuestion(response.getBody());
Expand Down Expand Up @@ -175,6 +175,24 @@ public static List<Tag> getLists() {
return tags;
}

public static List<Tag> getCategory(String url) {
List<Tag> tags = new ArrayList<>();

HttpRequest httpRequest = HttpRequest.get(URLUtils.getLeetcodeCardInfo());
HttpResponse response = HttpRequestUtils.executeGet(httpRequest);
if (response != null && response.getStatusCode() == 200) {
try {
String body = response.getBody();
tags = parseCategory(body, url);
} catch (Exception e1) {
LogUtils.LOG.error("Request CardInfo exception", e1);
}
} else {
LogUtils.LOG.error("Request CardInfo failed, status:" + response.getStatusCode() + "body:" + response.getBody());
}
return tags;
}


private static List<Question> parseQuestion(String str) {

Expand Down Expand Up @@ -202,18 +220,18 @@ private static List<Question> parseQuestion(String str) {
question.setTitleSlug(object.getJSONObject("stat").getString("question__title_slug"));
question.setLevel(object.getJSONObject("difficulty").getInteger("level"));
try {
if(object.getJSONObject("stat").containsKey("question__article__live")) {
if (object.getJSONObject("stat").containsKey("question__article__live")) {
if (object.getJSONObject("stat").get("question__article__live") == null
|| !object.getJSONObject("stat").getBoolean("question__article__live")) {
question.setArticleLive(Constant.ARTICLE_LIVE_NONE);
} else {
question.setArticleLive(Constant.ARTICLE_LIVE_ONE);
question.setArticleSlug(object.getJSONObject("stat").getString("question__title_slug"));
}
}else {
} else {
question.setArticleLive(Constant.ARTICLE_LIVE_LIST);
}
}catch (Exception e){
} catch (Exception e) {
LogUtils.LOG.error("Identify abnormal article", e);
question.setArticleLive(Constant.ARTICLE_LIVE_NONE);
}
Expand Down Expand Up @@ -251,7 +269,7 @@ private static void translation(List<Question> questions) {
String filePathTranslation = PersistentConfig.getInstance().getTempFilePath() + TRANSLATIONNAME;

try {
HttpRequest httpRequest = HttpRequest.post(URLUtils.getLeetcodeGraphql(),"application/json");
HttpRequest httpRequest = HttpRequest.post(URLUtils.getLeetcodeGraphql(), "application/json");
httpRequest.setBody("{\"operationName\":\"getQuestionTranslation\",\"variables\":{},\"query\":\"query getQuestionTranslation($lang: String) {\\n translations: allAppliedQuestionTranslations(lang: $lang) {\\n title\\n questionId\\n __typename\\n }\\n}\\n\"}");
httpRequest.addHeader("Accept", "application/json");
HttpResponse response = HttpRequestUtils.executePost(httpRequest);
Expand Down Expand Up @@ -312,6 +330,27 @@ private static List<Tag> parseTag(String str) {
return tags;
}

private static List<Tag> parseCategory(String str, String url) {
List<Tag> tags = new ArrayList<Tag>();

if (StringUtils.isNotBlank(str)) {

JSONArray jsonArray = JSONArray.parseObject(str).getJSONObject("categories").getJSONArray("0");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
Tag tag = new Tag();
tag.setSlug(object.getString("slug"));
tag.setType(URLUtils.getLeetcodeUrl() + "/api" + object.getString("url").replace("problemset","problems"));
tag.setName(object.getString("title"));
if(url.contains(tag.getType())){
tag.setSelect(true);
}
tags.add(tag);
}
}
return tags;
}

private static List<Tag> parseList(String str) {
List<Tag> tags = new ArrayList<Tag>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.shuzijun.leetcode.plugin.model.Tag;
import com.shuzijun.leetcode.plugin.utils.MessageUtils;
import com.shuzijun.leetcode.plugin.utils.PropertiesUtils;
import com.shuzijun.leetcode.plugin.utils.URLUtils;
import com.shuzijun.leetcode.plugin.window.WindowFactory;

import javax.swing.*;
Expand All @@ -35,7 +36,11 @@ public class ViewManager {
private static boolean intersection = Boolean.FALSE;

public static void loadServiceData(JTree tree, Project project) {
List<Question> questionList = QuestionManager.getQuestionService(project);
loadServiceData(tree, project, URLUtils.getLeetcodeAll());
}

public static void loadServiceData(JTree tree, Project project, String url) {
List<Question> questionList = QuestionManager.getQuestionService(project, url);
if (questionList == null || questionList.isEmpty()) {
MessageUtils.getInstance(project).showWarnMsg("warning", PropertiesUtils.getInfo("response.cache"));
questionList = QuestionManager.getQuestionCache();
Expand All @@ -56,6 +61,8 @@ public String apply(Question question) {
filter.put(Constant.FIND_TYPE_STATUS, QuestionManager.getStatus());
filter.put(Constant.FIND_TYPE_LISTS, QuestionManager.getLists());
filter.put(Constant.FIND_TYPE_TAGS, QuestionManager.getTags());
filter.put(Constant.FIND_TYPE_CATEGORY, QuestionManager.getCategory(url));


DefaultTreeModel treeMode = (DefaultTreeModel) tree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeMode.getRoot();
Expand Down Expand Up @@ -83,12 +90,18 @@ public static List<Tag> getFilter(String key) {
return filter.get(key);
}

public static void clearFilter() {
for (List<Tag> tagList : filter.values()) {
public static boolean clearFilter() {
boolean isLoad = false;
for (String key : filter.keySet()) {
List<Tag> tagList = filter.get(key);
for (Tag tag : tagList) {
if (tag.isSelect() && Constant.FIND_TYPE_CATEGORY.equals(key)) {
isLoad = true;
}
tag.setSelect(Boolean.FALSE);
}
}
return isLoad;
}

public static void updateStatus() {
Expand All @@ -105,7 +118,11 @@ public static void setIntersection(boolean intersection) {

public static void update(JTree tree) {
TreeSet<String> selectQuestionList = null;
for (List<Tag> tagList : filter.values()) {
for (String key : filter.keySet()) {
if (Constant.FIND_TYPE_CATEGORY.equals(key)) {
continue;
}
List<Tag> tagList = filter.get(key);
TreeSet<String> tagQuestionList = null;
for (Tag tag : tagList) {
if (tag.isSelect()) {
Expand Down Expand Up @@ -263,7 +280,7 @@ public static void position(JTree tree, JBScrollPane scrollPane, Question questi
for (int i = 0, j = node.getChildCount(); i < j; i++) {
DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node.getChildAt(i);
Question nodeData = (Question) childNode.getUserObject();
if(nodeData.getQuestionId().equals(question.getQuestionId())){
if (nodeData.getQuestionId().equals(question.getQuestionId())) {
TreePath toShowPath = new TreePath(childNode.getPath());
tree.setSelectionPath(toShowPath);
Rectangle bounds = tree.getPathBounds(toShowPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class Constant {
public static final String FIND_TYPE_STATUS = "Status";
public static final String FIND_TYPE_LISTS = "Lists";
public static final String FIND_TYPE_TAGS = "Tags";
public static final String FIND_TYPE_CATEGORY = "Category";

/**
* 状态类型
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class URLUtils {
private static String leetcodeVerify = "/problemset/all/";
private static String leetcodeProgress = "/api/progress/all/";
private static String leetcodeSession = "/session/";
private static String leetcodeCardInfo = "/problems/api/card-info/";

public static String getLeetcodeHost() {
String host = PersistentConfig.getInstance().getConfig().getUrl();
Expand Down Expand Up @@ -85,6 +86,9 @@ public static String getLeetcodeSession(){
return getLeetcodeUrl() + leetcodeSession;
}

public static String getLeetcodeCardInfo(){
return getLeetcodeUrl() + leetcodeCardInfo;
}

public static String getDescContent() {
if ("leetcode.com".equals(getLeetcodeHost()) || PersistentConfig.getInstance().getConfig().getEnglishContent()) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,9 @@
</group>

<group id="leetcode.find.Toolbar" popup="true" text="Status" description="Status">
<group id="leetcode.find.Category" class="com.shuzijun.leetcode.plugin.actions.toolbar.FindActionGroup"
popup="true" text="Category" description="Category">
</group>
<group id="leetcode.find.Difficulty" class="com.shuzijun.leetcode.plugin.actions.toolbar.FindActionGroup"
popup="true" text="Difficulty" description="Difficulty">
</group>
Expand Down