Skip to content

Commit

Permalink
🚧 optimize dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
volatile-static committed Apr 4, 2024
1 parent bf6aae0 commit 970fea8
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 23 deletions.
5 changes: 4 additions & 1 deletion addon/content/icons/date.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion addon/content/icons/group.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion addon/content/icons/page.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions addon/content/icons/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion addon/content/icons/relation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion addon/content/icons/timeline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions addon/locale/en-US/chartero.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ completeThreshold = Complete threshold for progress (seconds):
dashboardSection =
.label = Dashboard
.tooltiptext = Chartero Dashboard
dashboard-progress =
.tooltiptext = Reading Progress
dashboard-page =
.tooltiptext = Page-Time Chart
dashboard-date =
.tooltiptext = Date-Time Chart
dashboard-group =
.tooltiptext = User-Time Chart
dashboard-relation =
.tooltiptext = Relation Network Graph
dashboard-timeline =
.tooltiptext = Timeline
12 changes: 12 additions & 0 deletions addon/locale/it-IT/chartero.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ completeThreshold = Limite di avanzamento completo (secondi):
dashboardSection =
.label = Cruscotto
.tooltiptext = Chartero Cruscotto
dashboard-progress =
.tooltiptext = Ha letto
dashboard-page =
.tooltiptext = Tempo di lettura per pagina
dashboard-date =
.tooltiptext = Tempo di lettura giornaliero
dashboard-group =
.tooltiptext = Lettura dagli utenti
dashboard-relation =
.tooltiptext = Network delle relazioni
dashboard-timeline =
.tooltiptext = Linea temporale
12 changes: 12 additions & 0 deletions addon/locale/ja-JP/chartero.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ completeThreshold = 完了進捗閾値(秒):
dashboardSection =
.label = ダッシュボード
.tooltiptext = Charteroダッシュボード
dashboard-progress =
.tooltiptext = 阅读进度
dashboard-page =
.tooltiptext = 毎ページの読み時間
dashboard-date =
.tooltiptext = 毎日の読み時間
dashboard-group =
.tooltiptext = ユーザー統計
dashboard-relation =
.tooltiptext = 文献関連ネットワーク
dashboard-timeline =
.tooltiptext = タイムライン
12 changes: 12 additions & 0 deletions addon/locale/zh-CN/chartero.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ completeThreshold = 页均阅读阈值(用于进度统计):
dashboardSection =
.label = 仪表盘
.tooltiptext = Chartero仪表盘
dashboard-progress =
.tooltiptext = 阅读进度
dashboard-page =
.tooltiptext = 每页阅读时长
dashboard-date =
.tooltiptext = 每日阅读时长
dashboard-group =
.tooltiptext = 用户阅读时长
dashboard-relation =
.tooltiptext = 关联条目图
dashboard-timeline =
.tooltiptext = 时间线
32 changes: 20 additions & 12 deletions src/bootstrap/modules/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ export function updateDashboard(id?: number) {
* 初始化侧边栏TabPanel
*/
export function registerPanels() {
function post(body: HTMLDivElement, message: any) {
const iframe = body.getElementsByTagName('iframe')[0];
if (!iframe?.contentWindow)
addon.log(new Error('Dashboard iframe not found'));
else if (iframe.contentDocument?.readyState === 'complete')
iframe.contentWindow.postMessage(message, '*');
else
iframe.addEventListener('load', ({ target }) =>
(target as Document).defaultView!.postMessage(message, '*'), true);
addon.log(message, iframe.contentDocument?.readyState);
}
const tabs = ['progress', 'page', 'date', 'group', 'relation', 'timeline'];

if (!Zotero.ItemPaneManager?.registerSection)
addon.log(new Error('ItemPaneManager not found'));
Zotero.ItemPaneManager?.registerSection({
Expand All @@ -25,12 +38,14 @@ export function registerPanels() {
l10nID: 'chartero-dashboardSection',
icon: `resource://${config.addonName}/icons/sidebar.svg`,
},
sectionButtons: ['progress', 'page', 'date', 'group', 'relation', 'timeline'].map(tab => ({
sectionButtons: tabs.map(tab => ({
type: tab,
l10nID: `chartero-dashboard-${tab}`,
icon: `resource://${config.addonName}/icons/${tab}.svg`,
onClick(e) {
const iframe = e.body.getElementsByTagName('iframe')[0];
iframe.contentWindow!.postMessage({ tab }, '*');
post(e.body, { tab });
for (const t of tabs)
e.setSectionButtonStatus(t, { disabled: t === tab });
}
})),
onInit: args => {
Expand All @@ -44,15 +59,8 @@ export function registerPanels() {
(iframe.contentWindow as any).wrappedJSObject.addon = addon;
args.body.style.height = '600px';
},
onRender: args => {
},
onItemChange: args => {
addon.log(args);
const iframe = args.body.getElementsByTagName('iframe')[0],
id = Number(args.item.id);
iframe.contentWindow!.postMessage({ id }, '*');
},
onDestroy: args => addon.log(args),
onRender: args => post(args.body, 'render'),
onItemChange: args => post(args.body, { id: args.item.id }),
});
}

Expand Down
Loading

0 comments on commit 970fea8

Please sign in to comment.