Skip to content
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

Add plugin method updateCards #10065

Closed
IAliceBobI opened this issue Jan 3, 2024 · 20 comments
Closed

Add plugin method updateCards #10065

IAliceBobI opened this issue Jan 3, 2024 · 20 comments
Assignees
Milestone

Comments

@IAliceBobI
Copy link

In what scenarios do you need this feature?

希望openTab, card类型可以接受插件提供的ids,并且按照提供是顺序展示闪卡。

有时希望能够对闪卡排序做优先级。
乱序:一起制的卡,不要一起复习,上一个闪卡可能带有下一个闪卡的答案。

Describe the optimal solution

希望openTab, card类型可以接受插件提供的ids。

Describe the candidate solution

No response

Other information

No response

@QQQOrange
Copy link

附议

@Vanessa219
Copy link
Member

单独传 ids 可能不行,里面还涉及到很多计算操作是需要其他对象辅助。

cardsData?: {

如果是需要修改背诵顺序的话可以传个排序方法进来。

@IAliceBobI
Copy link
Author

@Vanessa219 那传个回调,我排序+过滤行不?

@IAliceBobI
Copy link
Author

@Vanessa219 改动大的话就传个排序函数也行。尽量小改吧。

@Jiangshuon
Copy link

@Vanessa219 那传个回调,我排序+过滤行不?

@IAliceBobI 大佬,过滤是指?和筛选一个意思吗?那这个需求有望通过您的插件在官方界面实现吗

#8832

@QQQOrange
Copy link

@Vanessa219 那传个回调,我排序+过滤行不?

@IAliceBobI 大佬,过滤是指?和筛选一个意思吗?那这个需求有望通过您的插件在官方界面实现吗

#8832

大概意思就是实现类似supermeno一样的优先性队列。

@IAliceBobI
Copy link
Author

@Jiangshuon 筛选需求奇奇怪怪的,没办法一网打尽。
不好做到官方界面里。当然如果能通过sql去筛选, 筛选条件包括到期的闪卡id列表,好像也能对付一些需求了。

@Vanessa219 Vanessa219 changed the title 希望openTab, card类型可以接受插件提供的ids。 Add plugin event bus update-cards Jan 5, 2024
@Vanessa219 Vanessa219 self-assigned this Jan 5, 2024
@Vanessa219 Vanessa219 added this to the 2.12.1 milestone Jan 5, 2024
Vanessa219 added a commit to siyuan-note/plugin-sample that referenced this issue Jan 5, 2024
Vanessa219 added a commit to siyuan-note/petal that referenced this issue Jan 5, 2024
Vanessa219 added a commit that referenced this issue Jan 5, 2024
@Vanessa219
Copy link
Member

大家有空看看是否满足了?

@IAliceBobI
Copy link
Author

@Vanessa219 是每次都给全量闪卡来排序吗。排序后自动存储起来,下次复习时,就弹出按照这个顺序并且到期的哪些卡吗?

@IAliceBobI
Copy link
Author

IAliceBobI commented Jan 6, 2024

@Vanessa219 是每次有一个闪卡改变都进行全量排序,还是找个位置进行插入而已?如果整体算法改变,还需要整体排序。

如果是复习前,就复习的那些闪卡排序也是OK的。

@Vanessa219
Copy link
Member

排序可以自己控制。

@IAliceBobI
Copy link
Author

@Vanessa219

还有问题请教一下:

关于内部具体是如何处理的。

是每次加一个闪卡,或者复习一个闪卡一次,改变状态后,都全量闪卡排序?

把排序结果保存,下次复习拉出卡时,参考排序结果,播放闪卡?

Vanessa219 added a commit to siyuan-note/plugin-sample that referenced this issue Jan 6, 2024
@Vanessa219
Copy link
Member

复习完一轮
不用保存,每次都会调用你排序的方法。

Vanessa219 added a commit that referenced this issue Jan 6, 2024
@IAliceBobI
Copy link
Author

@Vanessa219

发事件的机制,是不是相当于一边排序,一边复习。

排序要查询db。
如果排序慢点了,会不会先复习再变更顺序,导致有的卡没展示,有的展示多次?

@Vanessa219
Copy link
Member

你看一下 demo,可能和你想的不一样。

                    this.eventBus.on("update-cards", (event) => {
                        event.detail.cardsData.cards.sort((a: ICard, b: ICard) => {
                            if (a.blockID < b.blockID) {
                                return -1;
                            }
                            if (a.blockID > b.blockID) {
                                return 1;
                            }
                            return 0;
                        })
                    });

@IAliceBobI
Copy link
Author

@Vanessa219 这是接收事件,处理的时候,你那边也不会阻塞等候吧。

另外,我排序需要根据ial,需要查一下db。可能会比较慢。

EightDoor added a commit to EightDoor/siyuan that referenced this issue Jan 7, 2024
* commit '796df799315490e3a9d6e045f1c6bc98fb661e45': (455 commits)
  🐛 Fix `name` attribute could not be visited in the plugin constructor (siyuan-note#10071)
  🎨 Support ignore index siyuan-note#9198
  ♻️ Rename func
  🎨 siyuan-note#10090
  🎨 Reduce the delay in adding rows in database table view siyuan-note#10082
  🎨 Reduce the delay in adding rows in database table view siyuan-note#10082
  🎨 siyuan-note#10065
  🎨 Cards expired no longer appear in the same review round siyuan-note#10087
  🎨 https://ld246.com/article/1704285860053/comment/1704528635155#comments
  🐛 fix siyuan-note#10088
  🎨 https://ld246.com/article/1704285860053
  🎨 fix siyuan-note#10086
  🎨 fix siyuan-note#10085
  🎨 fix siyuan-note#10048
  🎨 Add internal kernel API `/api/filetree/upsertIndexes` and `/api/filetree/removeIndexes` siyuan-note#10079
  🎨 fix siyuan-note#10083
  ⬆️ Upgrade kernel deps
  ⬆️ Upgrade kernel deps
  🎨 fix siyuan-note#10000
  🎨 siyuan-note#10065
  ...

# Conflicts:
#	app/src/util/needSubscribe.ts
#	kernel/model/conf.go
@Vanessa219
Copy link
Member

这个数据已经是查询出来的了,如果需要等待其他查询的话可能无法使用 event bus,需要重新设计。

目前的数据是通过 "/api/riff/getRiffDueCards","/api/riff/getTreeRiffDueCards" 和 "/api/riff/getNotebookRiffDueCards" 接口传出来的。你是需要基于这些数据进行修改,还是数据也自己查询?

@IAliceBobI
Copy link
Author

@Vanessa219

感谢回复。

我也是使用 *DueCards 接口查询。

如果可以简单修改Plugin,给Plugin加个排序函数字段updateCards,也可以。

export abstract class Plugin {
    eventBus: EventBus;
    updateCards?: any; **<----- 还是传入 options**
    i18n: I18N;
    data: any;
    displayName: string;
    readonly name: string;
    app: App;

原来发事件的几个地方大概改一下:

    const fetchNewRound = () => {
        const currentCardType = filterElement.getAttribute("data-cardtype");
        fetchPost(currentCardType === "all" ? "/api/riff/getRiffDueCards" :
            (currentCardType === "doc" ? "/api/riff/getTreeRiffDueCards" : "/api/riff/getNotebookRiffDueCards"), {
            rootID: filterElement.getAttribute("data-id"),
            deckID: filterElement.getAttribute("data-id"),
            notebook: filterElement.getAttribute("data-id"),
        }, (treeCards) => {
            index = 0;
            options.cardsData = treeCards.data;
            const newRound = (options) => {
                if (options.cardsData.cards.length > 0) {
                    nextCard({
                        countElement,
                        editor,
                        actionElements,
                        index,
                        blocks: options.cardsData.cards
                    });
                } else {
                    allDone(countElement, editor, actionElements);
                }
            }
            for(const plugin of options.app.plugins){
                if(plugin.updateCards) {
                    plugin.updateCards(options).then((options)=>{
                        newRound(options);
                    });
                    return;
                }
            }
            newRound(options);
        });
    };

这样会有多个插件互相排斥的问题。但这样比较简单。以后可以设计更好的方案。比较两个插件都注册了要排序,那得有地方看到目前用的哪个插件的。

@Vanessa219
Copy link
Member

这样所有插件都会执行,只能靠用户自己选择插件了。

@IAliceBobI
Copy link
Author

@Vanessa219 嗯,目前这种写法,还得靠插件提供开关,让用户自己选择。

@Vanessa219 Vanessa219 changed the title Add plugin event bus update-cards Add plugin method updateCards Jan 8, 2024
Vanessa219 added a commit to siyuan-note/plugin-sample that referenced this issue Jan 8, 2024
Vanessa219 added a commit that referenced this issue Jan 8, 2024
Vanessa219 added a commit to siyuan-note/petal that referenced this issue Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants