mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-30 03:32:26 +08:00
refactor(views): pass argument to constructor
This commit is contained in:
parent
4592d6750b
commit
68ccd23540
@ -1,6 +1,7 @@
|
|||||||
import type FNote from "../entities/fnote.js";
|
import type FNote from "../entities/fnote.js";
|
||||||
import CalendarView from "../widgets/view_widgets/calendar_view.js";
|
import CalendarView from "../widgets/view_widgets/calendar_view.js";
|
||||||
import ListOrGridView from "../widgets/view_widgets/list_or_grid_view.js";
|
import ListOrGridView from "../widgets/view_widgets/list_or_grid_view.js";
|
||||||
|
import type { ViewModeArgs } from "../widgets/view_widgets/view_mode.js";
|
||||||
import type ViewMode from "../widgets/view_widgets/view_mode.js";
|
import type ViewMode from "../widgets/view_widgets/view_mode.js";
|
||||||
|
|
||||||
export default class NoteListRenderer {
|
export default class NoteListRenderer {
|
||||||
@ -9,14 +10,18 @@ export default class NoteListRenderer {
|
|||||||
private viewMode: ViewMode | null;
|
private viewMode: ViewMode | null;
|
||||||
|
|
||||||
constructor($parent: JQuery<HTMLElement>, parentNote: FNote, noteIds: string[], showNotePath: boolean = false) {
|
constructor($parent: JQuery<HTMLElement>, parentNote: FNote, noteIds: string[], showNotePath: boolean = false) {
|
||||||
console.log("Parent note is ", parentNote);
|
|
||||||
this.viewType = this.#getViewType(parentNote);
|
this.viewType = this.#getViewType(parentNote);
|
||||||
console.log("View type is ", this.viewType);
|
const args: ViewModeArgs = {
|
||||||
|
$parent,
|
||||||
|
parentNote,
|
||||||
|
noteIds,
|
||||||
|
showNotePath
|
||||||
|
}
|
||||||
|
|
||||||
if (this.viewType === "list" || this.viewType === "grid") {
|
if (this.viewType === "list" || this.viewType === "grid") {
|
||||||
this.viewMode = new ListOrGridView(this.viewType, $parent, parentNote, noteIds, showNotePath);
|
this.viewMode = new ListOrGridView(this.viewType, args);
|
||||||
} else if (this.viewType === "calendar") {
|
} else if (this.viewType === "calendar") {
|
||||||
this.viewMode = new CalendarView(this.viewType, $parent, parentNote, noteIds, showNotePath);
|
this.viewMode = new CalendarView(args);
|
||||||
} else {
|
} else {
|
||||||
this.viewMode = null;
|
this.viewMode = null;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import type FNote from "../../entities/fnote.js";
|
import type FNote from "../../entities/fnote.js";
|
||||||
import ViewMode from "./view_mode.js";
|
import ViewMode, { type ViewModeArgs } from "./view_mode.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="calendar-view">
|
<div class="calendar-view">
|
||||||
@ -19,11 +19,11 @@ export default class CalendarView extends ViewMode {
|
|||||||
|
|
||||||
private $root: JQuery<HTMLElement>;
|
private $root: JQuery<HTMLElement>;
|
||||||
|
|
||||||
constructor(viewType: string, $parent: JQuery<HTMLElement>, parentNote: FNote, noteIds: string[], showNotePath: boolean = false) {
|
constructor(args: ViewModeArgs) {
|
||||||
super($parent, parentNote, noteIds, showNotePath);
|
super(args);
|
||||||
|
|
||||||
this.$root = $(TPL);
|
this.$root = $(TPL);
|
||||||
$parent.append(this.$root);
|
args.$parent.append(this.$root);
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderList(): Promise<JQuery<HTMLElement> | undefined> {
|
async renderList(): Promise<JQuery<HTMLElement> | undefined> {
|
||||||
|
@ -6,7 +6,7 @@ import libraryLoader from "../../services/library_loader.js";
|
|||||||
import treeService from "../../services/tree.js";
|
import treeService from "../../services/tree.js";
|
||||||
import utils from "../../services/utils.js";
|
import utils from "../../services/utils.js";
|
||||||
import type FNote from "../../entities/fnote.js";
|
import type FNote from "../../entities/fnote.js";
|
||||||
import ViewMode from "./view_mode.js";
|
import ViewMode, { type ViewModeArgs } from "./view_mode.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="note-list">
|
<div class="note-list">
|
||||||
@ -172,24 +172,24 @@ class ListOrGridView extends ViewMode {
|
|||||||
/*
|
/*
|
||||||
* We're using noteIds so that it's not necessary to load all notes at once when paging
|
* We're using noteIds so that it's not necessary to load all notes at once when paging
|
||||||
*/
|
*/
|
||||||
constructor(viewType: string, $parent: JQuery<HTMLElement>, parentNote: FNote, noteIds: string[], showNotePath: boolean = false) {
|
constructor(viewType: string, args: ViewModeArgs) {
|
||||||
super($parent, parentNote, noteIds, showNotePath);
|
super(args);
|
||||||
this.$noteList = $(TPL);
|
this.$noteList = $(TPL);
|
||||||
this.viewType = viewType;
|
this.viewType = viewType;
|
||||||
|
|
||||||
this.parentNote = parentNote;
|
this.parentNote = args.parentNote;
|
||||||
const includedNoteIds = this.getIncludedNoteIds();
|
const includedNoteIds = this.getIncludedNoteIds();
|
||||||
|
|
||||||
this.noteIds = noteIds.filter((noteId) => !includedNoteIds.has(noteId) && noteId !== "_hidden");
|
this.noteIds = args.noteIds.filter((noteId) => !includedNoteIds.has(noteId) && noteId !== "_hidden");
|
||||||
|
|
||||||
if (this.noteIds.length === 0) {
|
if (this.noteIds.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent.append(this.$noteList);
|
args.$parent.append(this.$noteList);
|
||||||
|
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
this.pageSize = parseInt(parentNote.getLabelValue("pageSize") || "");
|
this.pageSize = parseInt(args.parentNote.getLabelValue("pageSize") || "");
|
||||||
|
|
||||||
if (!this.pageSize || this.pageSize < 1) {
|
if (!this.pageSize || this.pageSize < 1) {
|
||||||
this.pageSize = 20;
|
this.pageSize = 20;
|
||||||
@ -197,7 +197,7 @@ class ListOrGridView extends ViewMode {
|
|||||||
|
|
||||||
this.$noteList.addClass(`${this.viewType}-view`);
|
this.$noteList.addClass(`${this.viewType}-view`);
|
||||||
|
|
||||||
this.showNotePath = showNotePath;
|
this.showNotePath = args.showNotePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @returns {Set<string>} list of noteIds included (images, included notes) in the parent note and which
|
/** @returns {Set<string>} list of noteIds included (images, included notes) in the parent note and which
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
import type FNote from "../../entities/fnote.js";
|
import type FNote from "../../entities/fnote.js";
|
||||||
|
|
||||||
|
export interface ViewModeArgs {
|
||||||
|
$parent: JQuery<HTMLElement>;
|
||||||
|
parentNote: FNote;
|
||||||
|
noteIds: string[];
|
||||||
|
showNotePath?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export default abstract class ViewMode {
|
export default abstract class ViewMode {
|
||||||
|
|
||||||
constructor($parent: JQuery<HTMLElement>, parentNote: FNote, noteIds: string[], showNotePath: boolean = false) {
|
constructor(args: ViewModeArgs) {
|
||||||
// note list must be added to the DOM immediately, otherwise some functionality scripting (canvas) won't work
|
// note list must be added to the DOM immediately, otherwise some functionality scripting (canvas) won't work
|
||||||
$parent.empty();
|
args.$parent.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract renderList(): Promise<JQuery<HTMLElement> | undefined>;
|
abstract renderList(): Promise<JQuery<HTMLElement> | undefined>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user