Action

Add to List

Posted by FlohGro, Last update 6 months ago

UPDATES

6 months ago

description update

show all updates...

6 months ago

description update

6 months ago

description update an minor improvements

created by @FlohGro / more on my Blog

Add to List

This action adds the content of the current draft to the list draft you select in a prompt. The content will be added after a checkbox. You can also create a list for a new topic from the prompt.

[Configuration]

You need to configure the tag this action should use. To do so, edit this line in the script const listTag = "ref_list"; and replace ref_lists with the tag you want to use for your lists.

[Usage]

After you configured the action you can add the content of the current open draft to one of your lists. If you want to create a new list for a topic just select CREATE NEW LIST and insert the name for the list. The action will automatically create the new list and add the content to it.

To quickly open one of your lists check out the Show List action


If you find this useful and want to support me you can

Buy Me A Coffee

Steps

  • script

    // add to list
    // tag to assign to list drafts
    const listTag = "ref_list";
    
    
    // grab text
    const currentContent = draft.content.trim();
    
    /////////
    var res;
    {
    let ws = Workspace.create();
    ws.tagFilter = listTag;
    ws.tagFilterRequireAll = true;
    res = ws.query("all");
    }
    res.sort((a,b) => (a.title.toUpperCase() > b.title.toUpperCase()) ? 1:-1);
    var listTitles = [];
    var p = Prompt.create();
    p.title = "Select List"
    
    for(i in res)
    {
    	p.addButton(res[i].title,res[i].uuid);
    	listTitles.push(res[i].title);
    }
    p.addButton("CREATE NEW LIST");
    
    showSelectPrompt:
    var didSelect = p.show();
    if (didSelect == 1) {
    	if(p.buttonPressed != "CREATE NEW LIST")
    	{
    		var selecteduuid = p.buttonPressed;
    		var selectedDraft = Draft.find((selecteduuid));
    	} else {
    		var pN = Prompt.create();
    		pN.title = "create new list";
    		pN.message = "set title for new list";
    		pN.addTextField("setTitle", "set title","",[autocorrect=false, autocapitalization="words", keyboard="default",wantsFocus=true]);
    		pN.addButton("set title");
    		if(pN.show()){
    			if(pN.buttonPressed == "set title"){
    				var newListCategory = pN.fieldValues["setTitle"];
    				if (newListCategory != "") {
    					if(listTitles.includes(newListCategory)){
    						alert("list already exists, restart action and select the right list!");
    						context.cancel("user selected already existing list!")					} else {
    					var selectedDraft = Draft.create();
    					selectedDraft.content = "# " + newListCategory + "\n\n";
    					selectedDraft.languageGrammar = "Simple List";
    					}
    				} else {
    					alert("you must set a title, aborting!");
    					context.cancel("no title specified");
    				}
    			} else {
    				context.cancel("user cancelled title input");
    			}	
    		}
    	}
    
    
    var category = selectedDraft.title;
    
    var d;
    if (selectedDraft.content.startsWith("# " + category)) {
    			d = selectedDraft;
    } // else {
    
    //}
    
    d.addTag(listTag);
    d.content = d.content + "- [ ] " + currentContent + "\n"
    d.update();
    
    editor.load(d);
    } else {
    context.cancel("user cancelled add to list");
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.