Skip to content

Commit

Permalink
fix Changes requested
Browse files Browse the repository at this point in the history
  • Loading branch information
lorens-osman-dev committed Jan 13, 2024
1 parent 2b8346e commit 1476c17
Show file tree
Hide file tree
Showing 7 changed files with 409 additions and 478 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@

# Cluster plugin mainly designed to simplify the process of note clustering on mobile devices and work well on PCs ether.


### Note Clustering
Note clustering is a way to create a hierarchy or structure among your notes, making it easier to navigate and understand the relationships between them.
**Cluster Plugin** provides commands, in-note buttons, and ribbon actions to make clustering process easier on mobile devices and work well on PCs ether.
**Simple Example:**
Imagine you have notes about different animals. You could create `Animals cluster` like:
- Animals (cluster)
- Mammals (first generation note)
- Dogs (second generation note)
- Cats (second generation note)
- Whales (second generation note)

- Birds (first generation note)
- Eagles (second generation note)
- Penguins (second generation note)
- Owls (second generation note)

1. From ribbon or using "New cluster" command create "Animals" cluster .
2. From new opened note click "Create Son" with name "Mammals"
3. From new opened "Mammals" note click "Create Son" with name "Dogs"
4. From new opened "Dogs" note click "Create Brother" with name "Cats",
alternatively you go back to "Mammals" note click "Create Son" with name "Cats"
5. Continue ...

### 🤩🪄 Features

Expand Down
22 changes: 11 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export default class AdvancedNewFilePlugin extends Plugin {
actions = new Map();

async onload() {
console.log("loading plugin");
console.log("loading Cluster plugin");


//-Check For Advanced URI _Plugin
this.checkForAdvancedURI_Plugin();
//- Commands
this.addCommand({
id: "New-Brother",
name: "new_brother",
name: "New brother",
callback: () => {
this.createClusterFolder();
this.checkForAdvancedURI_Plugin();
Expand All @@ -25,7 +25,7 @@ export default class AdvancedNewFilePlugin extends Plugin {
});
this.addCommand({
id: "New-Son",
name: "new_son",
name: "New son",
callback: () => {
this.createClusterFolder();
this.checkForAdvancedURI_Plugin();
Expand All @@ -34,7 +34,7 @@ export default class AdvancedNewFilePlugin extends Plugin {
});
this.addCommand({
id: "New-Cluster",
name: "new_cluster",
name: "new cluster",
callback: () => {
this.createClusterFolder();
this.checkForAdvancedURI_Plugin();
Expand All @@ -43,7 +43,7 @@ export default class AdvancedNewFilePlugin extends Plugin {
});
this.addCommand({
id: "Delete-Active-Note",
name: "delete_active_note",
name: "Delete active note",
callback: () => {
this.createClusterFolder();
this.checkForAdvancedURI_Plugin();
Expand Down Expand Up @@ -71,14 +71,14 @@ export default class AdvancedNewFilePlugin extends Plugin {
//- createClusterFolder
async createClusterFolder() {
try {
const folderExists = await this.app.vault.adapter.exists("/[CLUSTERS]");
if (!folderExists) await this.app.vault.createFolder("/[CLUSTERS]");
const folderExists = await this.app.vault.adapter.exists("/CLUSTERS");
if (!folderExists) await this.app.vault.createFolder("/CLUSTERS");
//@ts-ignore
const isOtherClusters = this.app.vault.getRoot().children?.find((item : any) => item instanceof TFolder && item.name =="[CLUSTERS]").children.length
const isOtherClusters = this.app.vault.getRoot().children?.find((item : any) => item instanceof TFolder && item.name =="CLUSTERS").children.length
if(isOtherClusters == 0){
const fileExists = await this.app.vault.adapter.exists("/[CLUSTERS]/First-cluster.md");
const fileExists = await this.app.vault.adapter.exists("/CLUSTERS/First-cluster.md");

if (!fileExists) await this.app.vault.create("/[CLUSTERS]/first-cluster.md", firstClusterTemplate);
if (!fileExists) await this.app.vault.create("/CLUSTERS/first-cluster.md", firstClusterTemplate);

}

Expand All @@ -102,6 +102,6 @@ Create Son, Create Brother links to work
}

onunload() {
console.log("unloading plugin");
console.log("unloading Cluster plugin");
}
}
5 changes: 2 additions & 3 deletions src/createFamily/deleteActiveNoteModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class deleteActiveNoteModal extends Modal {
this.mode = mode;

//-Create input
const getActiveFile = app.workspace.getActiveFile();
const getActiveFile = this.app.workspace.getActiveFile();

this.inputEl = document.createElement("input");
this.inputEl.type = "text";
Expand Down Expand Up @@ -61,7 +61,7 @@ export default class deleteActiveNoteModal extends Modal {
evt.preventDefault();

// get current active file
const getActiveFile = app.workspace.getActiveFile();
const getActiveFile = this.app.workspace.getActiveFile();


//parent folder info
Expand All @@ -83,7 +83,6 @@ export default class deleteActiveNoteModal extends Modal {
//delete current active file + delete its Sons
await this.app.vault.adapter.remove(getActiveFile!.path)
await this.app.vault.adapter.rmdir(theRelatedSonsFolder.path , true)
console.log(theRelatedSonsFolder)
if(theContainingFolder == 2){
await this.app.vault.adapter.rmdir(theContainingFolderPath , true)
}
Expand Down
14 changes: 7 additions & 7 deletions src/createFamily/familyModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { templates , clusterTemplate} from "./templates";


export default class familyModal extends Modal {
app: App;
mode: NewFileLocation;
folder: TFolder;
newDirectoryPath: string;
Expand All @@ -15,6 +16,7 @@ export default class familyModal extends Modal {
createType: string;
constructor(app: App, mode: NewFileLocation, createType: string) {
super(app);
this.app = app;
this.createType = createType;
this.mode = mode;

Expand All @@ -28,7 +30,7 @@ export default class familyModal extends Modal {
this.modalEl.className = 'prompt';

//svg and placeholders
let getActiveFile = app.workspace.getActiveFile()
let getActiveFile = this.app.workspace.getActiveFile()

if(getActiveFile === null){

Expand Down Expand Up @@ -71,17 +73,15 @@ export default class familyModal extends Modal {
if (evt.key === 'Enter') {
// prevent enter after note creation
evt.preventDefault();

console.log(evt)
// get current active file
const getActiveFile = app.workspace.getActiveFile();
const getActiveFile = this.app.workspace.getActiveFile();

const currentActiveFileName = getActiveFile?.basename;


//-make clusterSon to the current active file
if (this.createType == "newSon") {
if(getActiveFile?.path.startsWith("[CLUSTERS]")){
if(getActiveFile?.path.startsWith("CLUSTERS")){
if(getActiveFile.basename.endsWith("-cluster") ){
if( (getActiveFile.path.match(/\//g) || []).length == 1 ){
const result = await templates(getActiveFile,"clusterSon");
Expand Down Expand Up @@ -134,7 +134,7 @@ export default class familyModal extends Modal {
}
//-make Brother to the current active file
else if (this.createType == "newBrother") {
if(getActiveFile!.path.startsWith("[CLUSTERS]")){
if(getActiveFile!.path.startsWith("CLUSTERS")){
// the next if statement to prevent make brother to a cluster
if (currentActiveFileName!.endsWith("-cluster")) {
new Notice(`You cant make Brother to a cluster.\nCreate new cluster instead`);
Expand All @@ -155,7 +155,7 @@ export default class familyModal extends Modal {


const rootChildren = this.app.vault.getRoot().children;
const ClustersFolder = rootChildren.find((item: any) => item instanceof TFolder && item.name == "[CLUSTERS]");
const ClustersFolder = rootChildren.find((item: any) => item instanceof TFolder && item.name == "CLUSTERS");
// @ts-ignore
this.setFolder(ClustersFolder, "");
const clusterName = `${this.inputEl.value}-cluster`;
Expand Down
Loading

0 comments on commit 1476c17

Please sign in to comment.