Skip to content

Commit

Permalink
逐步完善文献矩阵功能
Browse files Browse the repository at this point in the history
  • Loading branch information
zzlb0224 committed Aug 22, 2024
1 parent b462576 commit cd12047
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 30 deletions.
19 changes: 19 additions & 0 deletions addon/locale/en-US/addon.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,23 @@ popupRoot-TagsSetting = 标签设置
popupRoot-Development = 开发中
popupRoot-FollowParent = Follow
popupRoot-ConfigType-Green = Green
popupRoot-ConfigType-Yellow = Yellow
popupRoot-ConfigType-Red = Red
popupRoot-ConfigType-FollowParent = Follow
popupRoot-WindowType-FollowParent = Follow
popupRoot-WindowType-FixedPanel = FixedPanel
popupRoot-WindowType-PopupPanel = PopupPanel
popupRoot-SortType-RecentUse = RecentUse
popupRoot-SortType-ItemAndRecent = ItemAndRecent
popupRoot-SortType-UseCountDesc = UseCountDesc
popupRoot-SortType-CharAsc = CharAsc
menu-AnnotationMatrix = AnnotationMatrix
70 changes: 70 additions & 0 deletions src/component/AnnotationMatrix.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { createRoot } from "react-dom/client";
import { IntlProvider } from "react-intl";
import * as React from "react";
import { AnnotationRes } from '../utils/zzlb';

export function content2AnnotationMatrix(content: HTMLElement, annotations: AnnotationRes[]) {
createRoot(content).render(
<IntlProvider
locale={window.navigator.language}
// messages={this._localizedStrings}
onError={window.development &&
(() => {
ztoolkit.log("e", content);
})}
>
<AnnotationMatrix
annotations={annotations} />
</IntlProvider>
);
}
const innerStyle =
`
.annotationMatrix table{
border: 1px solid black;
borderCollapse: collapse
}
.annotationMatrix table td {
border: 1px solid black;
}
.annotationMatrix table td:hover{
background:#fee
}
`;
export function AnnotationMatrix({
annotations
}: { annotations: AnnotationRes[] }) {

return (
<>
<div>
<div>
<div>列设置</div>
<div>大于100条要分页 {annotations.length}</div>
<div>导出</div></div>

<style>
{innerStyle}
</style>
<div className='annotationMatrix'>
<table style={{

}} cellPadding={0} cellSpacing={0} >
{annotations.map((annotation) => (

<tr key={annotation.ann.key}>
<td >{annotation.author}</td>
<td >{annotation.year}</td>
<td >{annotation.text}</td>
<td >{annotation.comment}</td>
{/* <td > <span dangerouslySetInnerHTML={{ __html: annotation.html }}></span></td> */}
<td >{annotation.annotationTags}</td>
</tr>

))}
</table>
</div>
</div>
</>
)
}
2 changes: 1 addition & 1 deletion src/modules/AnnotationPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import { groupByResult } from "../utils/groupBy";
import { groupBy } from "../utils/groupBy";
import { Relations } from "../utils/Relations";
import { createRoot } from "react-dom/client";
import { IntlProvider } from "react-intl";
import * as React from "react";
import { usePopover } from "react-tiny-popover";
import { HexColorPicker } from "react-colorful";
import { PopupRoot } from "../component/PopupRoot";
import TagPopup from "../component/TagPopup";
import { IntlProvider } from "react-intl";

export class AnnotationPopup {
reader?: _ZoteroTypes.ReaderInstance;
Expand Down
38 changes: 30 additions & 8 deletions src/modules/AnnotationsToNote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import { groupBy } from "../utils/groupBy";
import { getCiteItemHtmlWithPage, getCiteAnnotationHtml } from "./getCitationItem";
import { ProgressWindowHelper } from "zotero-plugin-toolkit/dist/helpers/progressWindow";
import { getString } from "../utils/locale";
import { createRoot } from "react-dom/client";
import { IntlProvider } from "react-intl";
import * as React from "react";
import { AnnotationMatrix, content2AnnotationMatrix } from '../component/AnnotationMatrix';
// import { groupBy } from "lodash";

export function getAllAnnotations(items: Zotero.Item[]) {
Expand Down Expand Up @@ -718,14 +722,13 @@ export function createSearchAnnContent(dialogWindow: Window | undefined, popupDi
display: bShowRank || bShowTag ? "" : "none",
},
properties: {
innerHTML: `${
bShowTag
? anTo
.getTags()
.map((a) => a.tag)
.join(",")
: ""
} ${bShowRank ? getPublicationTags(anTo) : ""}`,
innerHTML: `${bShowTag
? anTo
.getTags()
.map((a) => a.tag)
.join(",")
: ""
} ${bShowRank ? getPublicationTags(anTo) : ""}`,
},
},
],
Expand Down Expand Up @@ -1085,3 +1088,22 @@ export async function createNote(txt = "", pw: ProgressWindowHelper | undefined
.startCloseTimer(5000);
return targetNoteItem;
}



export function createAnnotationMatrix(dialogWindow: Window | undefined, popupDiv: HTMLElement | undefined, annotations: AnnotationRes[]) {
const isWin = dialogWindow != undefined;
const doc = dialogWindow?.document.documentElement || popupDiv;
if (!doc) return;
dialogWindow?.addEventListener("resize", (e) => {
});

const content = doc.querySelector(".content") as HTMLElement;
const query = doc.querySelector(".query") as HTMLElement;

ztoolkit.log(content);
setTimeout(async () => {
await convertHtml(annotations)
content2AnnotationMatrix(content, annotations);
});
}
80 changes: 59 additions & 21 deletions src/modules/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { sortBy, sortValuesLengthKeyAsc } from "../utils/sort";
import { Tab } from "../utils/tab";
import { uniqueBy } from "../utils/uniqueBy";
import { ReTest, clearChild, createDialog, getChildCollections, isDebug, memFixedColor, stopPropagation } from "../utils/zzlb";
import { createChooseTagsDiv, createSearchAnnContent, getAllAnnotations } from "./AnnotationsToNote";
import { createAnnotationMatrix, createChooseTagsDiv, createSearchAnnContent, getAllAnnotations } from "./AnnotationsToNote";
import { copyAnnotations, mergePdfs, pasteAnnotations } from "./BackupAnnotation";
import { DDDTagClear, DDDTagRemove, DDDTagSet } from "./DDD";
import { getCiteItemHtml } from "./getCitationItem";
Expand Down Expand Up @@ -324,12 +324,50 @@ function buildMenu(collectionOrItem: "collection" | "item") {
},
},
{
tag: "menu",
tag: "menuitem",
label: getString("menu-AnnotationMatrix") + "(测试中)",
icon: iconBaseUrl + "favicon.png",
commandListener: async (ev: Event) => {
//!TODO
alert("测试中。。。");
const target = ev.target as HTMLElement;
const doc = target.ownerDocument;
const items = await getSelectedItems(collectionOrItem);
const annotations = getAllAnnotations(items);
const mainWindow = Zotero.getMainWindow();
let header = "";
if (collectionOrItem == "collection") {
header = `collection:${ZoteroPane.getSelectedCollection()?.name}`;
} else if (items.length == 1) {
header = `单条目:${items[0].getDisplayTitle()}`;
} else {
header = `多条目:${items.length}个条目`;
}
const win = await createDialog(header, [
{ tag: "div", classList: ["query"] },
{
tag: "div",
classList: ["status"],
properties: { innerHTML: "" },
},
{
tag: "div",
classList: ["content"],
// properties: { innerHTML: "2 0" },
styles: {
display: "flex",
// minHeight: "20px",
// minWidth: "100px",
// height: Math.max(mainWindow.innerHeight*0.7,700)+ "px",
// width: Math.max(mainWindow.outerWidth *0.8, 700) + "px",
// minHeight: Math.max(mainWindow.innerHeight*0.7,700)+ "px",
// minWidth: Math.max(mainWindow.outerWidth *0.8, 700) + "px",
// maxHeight: Math.max(mainWindow.innerHeight*0.9,700) + "px",
// maxWidth: Math.max(mainWindow.outerWidth -180, 700) + "px",
flexWrap: "wrap",
overflowY: "overlay",
},
},
]);
createAnnotationMatrix(win, undefined, annotations);
},
},
{
Expand Down Expand Up @@ -691,24 +729,24 @@ export function createActionTag(
// },
action
? {
tag: "button",
namespace: "html",
properties: { textContent: "确定生成" },
// styles: {
// padding: "6px",
// background: "#f99",
// margin: "1px",
// },
listeners: [
{
type: "click",
listener: (ev: any) => {
stopPropagation(ev);
action();
},
tag: "button",
namespace: "html",
properties: { textContent: "确定生成" },
// styles: {
// padding: "6px",
// background: "#f99",
// margin: "1px",
// },
listeners: [
{
type: "click",
listener: (ev: any) => {
stopPropagation(ev);
action();
},
],
}
},
],
}
: { tag: "span" },
...others,
];
Expand Down

0 comments on commit cd12047

Please sign in to comment.