add filterObjectsByStringEntries utility function
This commit is contained in:
Vendored
+30
-10
@@ -330,6 +330,17 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
function filterObjectsByStringEntries(reference, objects) {
|
||||||
|
const matches = [];
|
||||||
|
object_loop: for (const object of objects) {
|
||||||
|
reference_entry_loop: for (const referenceEntry of Object.entries(reference)) {
|
||||||
|
const [key, value] = referenceEntry;
|
||||||
|
if (object[key] != value) continue object_loop;
|
||||||
|
}
|
||||||
|
matches.push(object);
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
var IndexManager = class {
|
var IndexManager = class {
|
||||||
itemToString;
|
itemToString;
|
||||||
sortedStrings = [];
|
sortedStrings = [];
|
||||||
@@ -568,8 +579,8 @@
|
|||||||
return Color2;
|
return Color2;
|
||||||
})(Color || {});
|
})(Color || {});
|
||||||
|
|
||||||
// src/Model/Files/boardModel.ts
|
// src/Model/Files/boardsAndTasksModel.ts
|
||||||
var BoardModel = class _BoardModel {
|
var BoardsAndTasksModel = class _BoardsAndTasksModel {
|
||||||
storageModel;
|
storageModel;
|
||||||
chatModel;
|
chatModel;
|
||||||
fileModel;
|
fileModel;
|
||||||
@@ -620,7 +631,7 @@
|
|||||||
};
|
};
|
||||||
// boards
|
// boards
|
||||||
createBoard = (name) => {
|
createBoard = (name) => {
|
||||||
const boardInfoFileContent = _BoardModel.createBoardInfoFileContent(v4_default(), name, "standard" /* Standard */);
|
const boardInfoFileContent = _BoardsAndTasksModel.createBoardInfoFileContent(v4_default(), name, "standard" /* Standard */);
|
||||||
return boardInfoFileContent;
|
return boardInfoFileContent;
|
||||||
};
|
};
|
||||||
updateBoard = (boardInfoFileContent) => {
|
updateBoard = (boardInfoFileContent) => {
|
||||||
@@ -658,7 +669,7 @@
|
|||||||
};
|
};
|
||||||
//tasks
|
//tasks
|
||||||
createTask = (boardId) => {
|
createTask = (boardId) => {
|
||||||
const taskFileContent = _BoardModel.createTaskFileContent(
|
const taskFileContent = _BoardsAndTasksModel.createTaskFileContent(
|
||||||
v4_default(),
|
v4_default(),
|
||||||
"",
|
"",
|
||||||
boardId
|
boardId
|
||||||
@@ -765,7 +776,7 @@
|
|||||||
var FileModel = class _FileModel {
|
var FileModel = class _FileModel {
|
||||||
chatModel;
|
chatModel;
|
||||||
storageModel;
|
storageModel;
|
||||||
taskModel;
|
boardsAndTasksModel;
|
||||||
fileContentHandlerManager = new HandlerManager();
|
fileContentHandlerManager = new HandlerManager();
|
||||||
// paths
|
// paths
|
||||||
getBasePath = () => {
|
getBasePath = () => {
|
||||||
@@ -799,7 +810,7 @@
|
|||||||
handleFileContent = (fileContent) => {
|
handleFileContent = (fileContent) => {
|
||||||
const didStore = this.storeFileContent(fileContent);
|
const didStore = this.storeFileContent(fileContent);
|
||||||
if (didStore == false) return;
|
if (didStore == false) return;
|
||||||
this.taskModel.handleFileContent(fileContent);
|
this.boardsAndTasksModel.handleFileContent(fileContent);
|
||||||
this.fileContentHandlerManager.trigger(fileContent);
|
this.fileContentHandlerManager.trigger(fileContent);
|
||||||
};
|
};
|
||||||
// methods
|
// methods
|
||||||
@@ -852,7 +863,7 @@
|
|||||||
constructor(chatModel, storageModel2) {
|
constructor(chatModel, storageModel2) {
|
||||||
this.chatModel = chatModel;
|
this.chatModel = chatModel;
|
||||||
this.storageModel = storageModel2;
|
this.storageModel = storageModel2;
|
||||||
this.taskModel = new BoardModel(this.storageModel, chatModel, this);
|
this.boardsAndTasksModel = new BoardsAndTasksModel(this.storageModel, chatModel, this);
|
||||||
}
|
}
|
||||||
// utility
|
// utility
|
||||||
static generateFileContentId = (creationDate) => {
|
static generateFileContentId = (creationDate) => {
|
||||||
@@ -1499,7 +1510,7 @@
|
|||||||
};
|
};
|
||||||
// settings
|
// settings
|
||||||
save = () => {
|
save = () => {
|
||||||
const newTaskFileContent = BoardModel.createTaskFileContent(
|
const newTaskFileContent = BoardsAndTasksModel.createTaskFileContent(
|
||||||
this.task.fileId,
|
this.task.fileId,
|
||||||
this.name.value,
|
this.name.value,
|
||||||
this.task.boardId
|
this.task.boardId
|
||||||
@@ -1591,7 +1602,7 @@
|
|||||||
};
|
};
|
||||||
// settings
|
// settings
|
||||||
saveSettings = () => {
|
saveSettings = () => {
|
||||||
const newBoardInfoFileContent = BoardModel.createBoardInfoFileContent(
|
const newBoardInfoFileContent = BoardsAndTasksModel.createBoardInfoFileContent(
|
||||||
this.boardInfo.fileId,
|
this.boardInfo.fileId,
|
||||||
this.name.value,
|
this.name.value,
|
||||||
this.color.value
|
this.color.value
|
||||||
@@ -1905,7 +1916,7 @@
|
|||||||
this.chatListViewModel = chatListViewModel2;
|
this.chatListViewModel = chatListViewModel2;
|
||||||
this.taskPageViewModel = new TaskPageViewModel(
|
this.taskPageViewModel = new TaskPageViewModel(
|
||||||
this.storageModel,
|
this.storageModel,
|
||||||
this.chatModel.fileModel.taskModel,
|
this.chatModel.fileModel.boardsAndTasksModel,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
this.messagePageViewModel = new MessagePageViewModel(this);
|
this.messagePageViewModel = new MessagePageViewModel(this);
|
||||||
@@ -3516,6 +3527,15 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// src/index.tsx
|
// src/index.tsx
|
||||||
|
console.log(
|
||||||
|
filterObjectsByStringEntries({ a: "hello", b: "test" }, [
|
||||||
|
{ a: "hello", b: "test" },
|
||||||
|
{ a: "hello", b: "test", c: "something" },
|
||||||
|
{ a: "hello", b: "test 123" },
|
||||||
|
{ a: "hello blabla", b: "test" },
|
||||||
|
{ a: "hello" }
|
||||||
|
])
|
||||||
|
);
|
||||||
var storageModel = new StorageModel();
|
var storageModel = new StorageModel();
|
||||||
var settingsModel = new SettingsModel(storageModel);
|
var settingsModel = new SettingsModel(storageModel);
|
||||||
var connectionModel = new ConnectionModel(storageModel);
|
var connectionModel = new ConnectionModel(storageModel);
|
||||||
|
|||||||
@@ -28,6 +28,21 @@ export class HandlerManager<T> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filters
|
||||||
|
export function filterObjectsByStringEntries(reference: {[key: string]: string}, objects: any[]): any[] {
|
||||||
|
const matches: any[] = [];
|
||||||
|
|
||||||
|
object_loop: for (const object of objects) {
|
||||||
|
reference_entry_loop: for (const referenceEntry of Object.entries(reference)) {
|
||||||
|
const [key, value] = referenceEntry;
|
||||||
|
if (object[key] != value) continue object_loop
|
||||||
|
}
|
||||||
|
matches.push(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
// sorting
|
// sorting
|
||||||
export class IndexManager<T> {
|
export class IndexManager<T> {
|
||||||
private itemToString: (item: T) => string;
|
private itemToString: (item: T) => string;
|
||||||
|
|||||||
Reference in New Issue
Block a user