Skip to content

Build your personal knowledge base with Trilium Notes

note info sidebar widget

zadameb28a3b0c919
diff --git a/src/public/javascripts/services/sidebar.js b/src/public/javascripts/services/sidebar.js
index 030934f85e..905c15f466 100644
--- a/src/public/javascripts/services/sidebar.js
+++ b/src/public/javascripts/services/sidebar.js
@@ -1,3 +1,23 @@
+import NoteInfoWidget from "../widgets/note_info.js";
+
+const WIDGET_TPL = `
+<div class="card widget">
+ <div class="card-header">
+ <h5 class="mb-0">
+ <button class="btn btn-sm widget-title" data-toggle="collapse" data-target="#collapseOne">
+ Collapsible Group Item
+ </button>
+ </h5>
+ </div>
+
+ <div id="collapseOne" class="collapse show body-wrapper">
+ <div class="card-body"></div>
+ </div>
+</div>
+`;
+
+let widgetIdCtr = 1;
+
class Sidebar {
/**
* @param {TabContext} ctx
@@ -5,6 +25,7 @@ class Sidebar {
constructor(ctx) {
this.ctx = ctx;
this.$sidebar = ctx.$tabContent.find(".note-detail-sidebar");
+ this.$widgets = this.$sidebar.find(".note-detail-widgets");
this.$showSideBarButton = this.ctx.$tabContent.find(".show-sidebar-button");
this.$showSideBarButton.hide();
@@ -18,7 +39,35 @@ class Sidebar {
this.$showSideBarButton.click(() => {
this.$sidebar.show();
this.$showSideBarButton.hide();
- })
+ });
+ }
+
+ async noteLoaded() {
+ this.$widgets.empty();
+
+ this.addNoteInfoWidget();
+ this.addNoteInfoWidget();
+ }
+
+ async addNoteInfoWidget() {
+ const $widget = this.createWidgetElement();
+
+ const noteInfoWidget = new NoteInfoWidget(this.ctx, $widget);
+ await noteInfoWidget.renderBody();
+
+ console.log($widget);
+
+ this.$widgets.append($widget);
+ }
+
+ createWidgetElement() {
+ const widgetId = 'widget-' + widgetIdCtr++;
+
+ const $widget = $(WIDGET_TPL);
+ $widget.find('[data-target]').attr('data-target', "#" + widgetId);
+ $widget.find('.body-wrapper').attr('id', widgetId);
+
+ return $widget;
}
}
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index a12cf59089..5751a54f8d 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -60,9 +60,9 @@ class TabContext {
this.noteChangeDisabled = false;
this.isNoteChanged = false;
this.attributes = new Attributes(this);
- this.sidebar = new Sidebar(this);
if (utils.isDesktop()) {
+ this.sidebar = new Sidebar(this);
this.noteType = new NoteTypeContext(this);
}
@@ -133,6 +133,10 @@ class TabContext {
this.showPaths();
+ if (this.sidebar) {
+ this.sidebar.noteLoaded();
+ }
+
console.debug(`Switched tab ${this.tabId} to ${this.noteId}`);
}
diff --git a/src/public/javascripts/widgets/note_info.js b/src/public/javascripts/widgets/note_info.js
new file mode 100644
index 0000000000..d412a3ca23
--- /dev/null
+++ b/src/public/javascripts/widgets/note_info.js
@@ -0,0 +1,59 @@
+const TPL = `
+<table class="note-info-table">
+ <tr>
+ <th>Note ID</th>
+ <td class="note-info-note-id"></td>
+ </tr>
+ <tr>
+ <th>Created</th>
+ <td class="note-info-date-created"></td>
+ </tr>
+ <tr>
+ <th>Modified</th>
+ <td class="note-info-date-modified"></td>
+ </tr>
+ <tr>
+ <th>Type</th>
+ <td class="note-info-type"></td>
+ </tr>
+ <tr>
+ <th>MIME</th>
+ <td class="note-info-mime"></td>
+ </tr>
+</table>
+`;
+
+class NoteInfoWidget {
+ /**
+ * @param {TabContext} ctx
+ * @param {jQuery} $widget
+ */
+ constructor(ctx, $widget) {
+ this.ctx = ctx;
+ this.$widget = $widget;
+ this.$title = this.$widget.find('.widget-title');
+ this.$title.text("Note info");
+ }
+
+ async renderBody() {
+ const $body = this.$widget.find('.card-body');
+
+ $body.html(TPL);
+
+ const $noteId = $body.find(".note-info-note-id");
+ const $dateCreated = $body.find(".note-info-date-created");
+ const $dateModified = $body.find(".note-info-date-modified");
+ const $type = $body.find(".note-info-type");
+ const $mime = $body.find(".note-info-mime");
+
+ const note = this.ctx.note;
+
+ $noteId.text(note.noteId);
+ $dateCreated.text(note.dateCreated);
+ $dateModified.text(note.dateModified);
+ $type.text(note.type);
+ $mime.text(note.mime);
+ }
+}
+
+export default NoteInfoWidget;
\ No newline at end of file
diff --git a/src/public/stylesheets/desktop.css b/src/public/stylesheets/desktop.css
index 6d2a330135..3e24c8870a 100644
--- a/src/public/stylesheets/desktop.css
+++ b/src/public/stylesheets/desktop.css
@@ -152,8 +152,8 @@ body {
background-color: inherit;
}
-#note-info-table td, #note-info-table th {
- padding: 15px;
+.widget .note-info-table td, .widget .note-info-table th {
+ padding: 5px;
}
[data-toggle="tooltip"] span {
diff --git a/src/views/sidebar.ejs b/src/views/sidebar.ejs
index a481b4b760..69cded6ddd 100644
--- a/src/views/sidebar.ejs
+++ b/src/views/sidebar.ejs
@@ -3,47 +3,5 @@
<button class="hide-sidebar-button" style="background: none; border: none;">hide sidebar <span class="jam jam-chevron-right"></span></button>
</div>
- <div class="card">
- <div class="card-header" id="headingOne">
- <h5 class="mb-0">
- <button class="btn btn-sm" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
- Collapsible Group Item #1
- </button>
- </h5>
- </div>
-
- <div id="collapseOne" class="collapse show" aria-labelledby="headingOne">
- <div class="card-body">
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
- </div>
- </div>
- </div>
- <div class="card">
- <div class="card-header" id="headingTwo">
- <h5 class="mb-0">
- <button class="btn btn-sm collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
- Collapsible Group Item #2
- </button>
- </h5>
- </div>
- <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo">
- <div class="card-body">
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
- </div>
- </div>
- </div>
- <div class="card">
- <div class="card-header" id="headingThree">
- <h5 class="mb-0">
- <button class="btn btn-sm collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
- Collapsible Group Item #3
- </button>
- </h5>
- </div>
- <div id="collapseThree" class="collapse" aria-labelledby="headingThree">
- <div class="card-body">
- Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
- </div>
- </div>
- </div>
+ <div class="note-detail-widgets"></div>
</div>
\ No newline at end of file