Skip to content

Commit

Permalink
Added filter for prompt data fields
Browse files Browse the repository at this point in the history
  • Loading branch information
frianasoa committed Jan 3, 2024
1 parent 08022d3 commit e063cc4
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 11 deletions.
27 changes: 24 additions & 3 deletions content/notes/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,27 @@ Table = {
var annotationcontent = div.querySelector(".direct-quote").innerText;
var author = div.querySelector(".direct-quote").parentNode.dataset.author;
var date = div.querySelector(".direct-quote").parentNode.dataset.date;
var tag = div.querySelector(".direct-quote").parentNode.dataset.tag;
var annotationcomments = Table.splitusernotes(div.querySelector(".annotation-comment").innerHTML);
s = annotationcomments;
s["Direct quote"] = annotationcontent;
s["Author"] = author;
s["Date"] = date;
s["Tag"] = tag;
s = this.filter(s);

if(Object.keys(d).includes("Selections"))
{
d["Selections"].push(s);
if(Object.keys(s).length>0)
{
d["Selections"].push(s);
}
}
else {
d["Selections"] = [s];
if(Object.keys(s).length>0)
{
d["Selections"] = [s];
}
}
});

Expand Down Expand Up @@ -111,6 +121,17 @@ Table = {
r[k] = r[k].join("\n");
}
return r;
}
},

filter(s)
{
Object.keys(Zotero.ZeNotes.Filter.excludefields).forEach(field=>{
let r = Zotero.ZeNotes.Prefs.get("exclude-"+field, false);
if(r=="true" || r==true)
{
delete s[field];
}
})
return s;
}
}
4 changes: 4 additions & 0 deletions content/settings/exclude-from-prompt.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div xmlns="http:https://www.w3.org/1999/xhtml" id="group-exclude-from-prompt">
<table id="exclude-from-prompt">
</table>
</div>
15 changes: 15 additions & 0 deletions content/settings/preferences.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,19 @@ menulist {

#ai-prompts tr td{
border-bottom: solid 1px;
}


.json-key {
color: red;
}
.json-number {
color: blue;
}
.json-string {
color: green;
}
.json-null {
color: blue;
font-weight: bold;
}
60 changes: 60 additions & 0 deletions content/settings/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ Zotero_Preferences.ZeNotes = {
["load-settings", "zn-load-settings"]
];
break;
case 'exclude-from-prompt':
this.promptdataselection();
return;
}

for(arg of args)
Expand All @@ -316,6 +319,52 @@ Zotero_Preferences.ZeNotes = {
}
}
},

promptdataselection()
{
var fields = Zotero.ZeNotes.Filter.excludefields;
var table = document.getElementById("exclude-from-prompt");
table.innerHTML = "";
let i = 0;
for(field in fields)
{
let l = fields[field];
let row = table.insertRow();
let lcell = row.insertCell();
let rcell = row.insertCell();
if(i==0)
{
let tcell = row.insertCell();
let sample = this.filterlist(JSON.parse(JSON.stringify(Zotero.ZeNotes.Filter.excludefields)));
tcell.style = "padding-left: 2em;"
tcell.setAttribute("rowspan", Object.keys(fields).length);
tcell.innerHTML = "A cell prompt will be followed by the following data.<hr/>var celldata = "+Zotero.ZeNotes.Utils.displayjson(sample);
}

let label = document.createElementNS("http:https://www.w3.org/1999/xhtml", "label");
label.innerText = l;
label.setAttribute("for", "zn-exclude-"+field);

let ipt = document.createElementNS("http:https://www.w3.org/1999/xhtml", "input");
ipt.type = "checkbox";
ipt.setAttribute("id", "zn-exclude-"+field);
ipt.dataset.field = "exclude-"+field;
ipt.addEventListener("change", function(e){
try {
Zotero_Preferences.ZeNotes.setpreference(e, e.currentTarget.dataset.field);
Zotero_Preferences.ZeNotes.promptdataselection()
}
catch(e)
{
alert(e);
}
})
lcell.appendChild(label);
rcell.appendChild(ipt);
Zotero_Preferences.ZeNotes.loadpreference(ipt.dataset.field, ipt.getAttribute("id"));
i+=1;
}
},

loadtagmanager(box)
{
Expand Down Expand Up @@ -443,6 +492,17 @@ Zotero_Preferences.ZeNotes = {
}
this.tableutils.rendertags(table, tags, columns, this.usersettings);
return table;
},
filterlist(s)
{
Object.keys(Zotero.ZeNotes.Filter.excludefields).forEach(field=>{
let r = Zotero.ZeNotes.Prefs.get("exclude-"+field, false);
if(r=="true" || r==true)
{
delete s[field];
}
})
return s;
}
}

Expand Down
8 changes: 8 additions & 0 deletions content/settings/preferences6.xul
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<tab id="zn-tags-sorting" label="Tag sorting"/>
<tab id="zn-api-settings" label="API settings"/>
<tab id="zn-prompt-settings" label="Custom prompts"/>
<tab id="zn-prompt-data-settings" label="Prompts data"/>
<tab id="zn-global-settings" label="Global setting"/>
<tab id="zn-advanced-settings" label="Advanced"/>
</tabs>
Expand Down Expand Up @@ -53,12 +54,19 @@
<box class="zn-include" src="ai-prompts.xhtml" onload="Zotero_Preferences.ZeNotes.initpanel('prompts')"> </box>
</groupbox>
</tabpanel>
<tabpanel orient="vertical" id="zn-prompt-data">
<groupbox>
<caption label="Exclude from prompt"/>
<box class="zn-include" src="exclude-from-prompt.xhtml" onload="Zotero_Preferences.ZeNotes.initpanel('exclude-from-prompt')"> </box>
</groupbox>
</tabpanel>
<tabpanel orient="vertical" id="zn-global-panel">
<groupbox>
<caption label="Global display"/>
<box class="zn-include" src="display.xhtml" onload="Zotero_Preferences.ZeNotes.initpanel('global')"> </box>
</groupbox>
</tabpanel>

<tabpanel orient="vertical" id="zn-advanced-panel">
<groupbox>
<caption label="Performance"/>
Expand Down
10 changes: 10 additions & 0 deletions core/filter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
Filter = {
excludefields : {
"Translation":"Translation",
"Paraphrase":"Paraphrase",
"Reader notes":"Reader notes",
"Direct quote":"Direct quote",
"Author":"Author",
"Date":"Date",
"Tag":"Tag"
},

apply(txt, selectors = "", replacement=""){
txt = Filter.legacy(txt);

Expand Down
24 changes: 24 additions & 0 deletions core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,29 @@ Utils = {
arr.splice(dindex, 0, arr.splice(sindex, 1)[0]);
}
return arr;
},
displayjson(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
json = json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'json-number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'json-key';
} else {
cls = 'json-string';
}
} else if (/true|false/.test(match)) {
cls = 'json-boolean';
} else if (/null/.test(match)) {
cls = 'json-null';
}
return '<span class="' + cls + '">' + match + '</span>';
});

json = json.split("\n").join("<br/>").split(" ").join("&#160;&#160;");
return json;
}
}
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description about="urn:mozilla:install-manifest">
<em:id>[email protected]</em:id>
<em:name>ZeNotes</em:name>
<em:version>0.7.3</em:version>
<em:version>0.7.4</em:version>
<em:multiprocessCompatible>true</em:multiprocessCompatible>
<em:updateURL>https://raw.githubusercontent.com/frianasoa/zenotes/main/zenote-update.json</em:updateURL>
<em:homepageURL>https://github.com/frianasoa/zenotes</em:homepageURL>
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ze Notes",
"version": "0.7.3",
"version": "0.7.4",
"description": "Advanced notes manager",
"homepage_url": "https://github.com/frianasoa/zenotes",
"author": "Fanantenana Rianasoa Andriariniaina",
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"[email protected]": {
"updates": [
{
"version": "0.7.3",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.3/zenotes-v0.7.3.xpi",
"update_hash": "sha256:1a7bf8ee2c9df6f80ad5f8982a8ac76d490d98c701a8a7cc1f78ebd9fda6e5a1",
"version": "0.7.4",
"update_link": "https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.4/zenotes-v0.7.4.xpi",
"update_hash": "sha256:36381006d77f3ba9f5f353edd38ce8b663e3ee0b02d00af79ad4838be259a752",
"applications": {
"gecko": {
"strict_min_version": "60.0"
Expand Down
6 changes: 3 additions & 3 deletions zenote-update.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<rdf:Seq>
<rdf:li>
<rdf:Description>
<ns1:version>0.7.3</ns1:version>
<ns1:version>0.7.4</ns1:version>
<ns1:targetApplication>
<rdf:Description>
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>5.0.0</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.3/zenotes-v0.7.3.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.4/zenotes-v0.7.4.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand All @@ -20,7 +20,7 @@
<ns1:id>[email protected]</ns1:id>
<ns1:minVersion>4.999</ns1:minVersion>
<ns1:maxVersion>6.*</ns1:maxVersion>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.3/zenotes-v0.7.3.xpi</ns1:updateLink>
<ns1:updateLink>https://github.com/frianasoa/Ze-Notes/releases/download/v0.7.4/zenotes-v0.7.4.xpi</ns1:updateLink>
</rdf:Description>
</ns1:targetApplication>

Expand Down

0 comments on commit e063cc4

Please sign in to comment.