DATAVIEW: Subfolders in list organized by folder show up at the bottom of the whole list, rather

What I’m trying to do

I’m trying to create an index of files in each folder within a project folder, and I have gotten that to work. However, in the list generated, the subfolders in each top level folder show up at the bottom. Is there a way to create an indented line in for a subfolder that exists in the grouped folder?

I am very new, so if this can be done without js, that would be especially great.

Things I have tried

LIST
rows.file.link
WHERE contains(file.folder, this.file.folder)
GROUP BY regexreplace(file.folder, ".*\/([^\/]+)$", "$1")

Topic : 1/2

Summary
  • How to create an indented line for a subfolder within the grouped folder in list view?
    • DQL10
    • mDVJS01 + Q30_DQL10a_JS.js + Q30_ParentFolder_Config_a.md: It supports three different use cases.

Test

Summary
  • dataview: v0.5.55

Input

Summary

the current notes

  • Location: “100_Project/02_dataview/Q30_CurrentFolder/Q30_test_data/C0_Parent”

  • filename : Q30_DQL01_C0
```md
### Q30_DQL01


```

  • filename : Q30_DQL10_C0
````md
### Q30_DQL10


````

  • filename : Q30_mDVJS01_C0 or Q30_index_C0
````md
### Q30_mDVJS01


````

dictionary files

  • Location: “100_Project/02_dataview/Q30_CurrentFolder/Q30_test_data/C0_Parent”

folder: C1_04

  • filename : dic_19530401
```md
---
date: 1953-04-01
---

```

  • filename : dic_19530406
```md
---
date: 1953-04-06
---

```

folder: C1_05

  • filename : dic_19530501
```md
---
date: 1953-05-01
---

```

  • filename : dic_19530506
```md
---
date: 1953-05-06
---

```

folder: C1_05/C2_01

  • filename : dic_19530511
```md
---
date: 1953-05-11
---

```

  • filename : dic_19530516
```md
---
date: 1953-05-16
---

```

folder: C1_05/C2_02

  • filename : dic_19530521
```md
---
date: 1953-05-21
---

```

  • filename : dic_19530526
```md
---
date: 1953-05-26
---

```

folder: C1_06

  • filename : dic_19530601
```md
---
date: 1953-06-01
---

```

  • filename : dic_19530606
```md
---
date: 1953-06-06
---

```

DQL01_create_Indentations_for_subfolder_within_grouped_folder_and_TABLE: For Debugging

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL01
_create_Indentations
_for_subfolder
_within_grouped_folder
_and_LIST
file.folder:
a string

this.file.folder:
a string
yes 1.To filter by file.folder

2.To define field variables:
2.1 To define three field variables, such as SubFolderName, SubFolderWithPathRelativeToParent, ParentFolderName
2.2 To define three field variables, such as SubFolderWithPath, pName, and sName
2.3 To define ten field variables, such as C0, C1,… ,C9

3.To define field variables:
3.1 To define one field variable CN
3.2 To define one field variable SomeIndentation for Indentations

4.To sort by file.folder in ascending order
5.To group by SubFolderWithPath
6.To define two field variables, such as P_SomeIndentation and P_SubFolderName

7.To render as a table

Code DQL01_create_Indentations_for_subfolder_within_grouped_folder_and_TABLE

Summary_code

NOTE:
The location for the DQL01 is “100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent”.

title: DQL01_create_Indentations_for_subfolder_within_grouped_folder_and_TABLE => 
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      rows.file.link,
      rows.CN,  
      rows.ParentFolderName,
      rows.SubFolderName,
      rows.SubFolderWithPath

FROM "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"
FLATTEN this.file.folder AS C0_Parent
WHERE startswith(file.folder, C0_Parent)


FLATTEN regexreplace(file.folder, "^.*\/([^/]+)$", "$1") AS SubFolderName
FLATTEN regexreplace(file.folder, C0_Parent + "\/", "") AS SubFolderWithPathRelativeToParent
FLATTEN regexreplace(C0_Parent, "^.*\/([^/]+)$", "$1") AS ParentFolderName


FLATTEN SubFolderWithPathRelativeToParent AS SubFolderWithPath
FLATTEN ParentFolderName AS pName
FLATTEN SubFolderName AS sName


FLATTEN choice(sName = pName, "C0", "") AS C0
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+)$", "C1"), "") AS C1
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){1,1})$", "C2"), "") AS C2
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){2,2})$", "C3"), "") AS C3
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){3,3})$", "C4"), "") AS C4
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){4,4})$", "C5"), "") AS C5
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){5,5})$", "C6"), "") AS C6
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){6,6})$", "C7"), "") AS C7
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){7,7})$", "C8"), "") AS C8
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){8,})$", "C9"), "") AS C9


FLATTEN C0 + choice(C1="C1", "C1", "") + choice(C2="C2", "C2", "") + choice(C3="C3", "C3", "") +
        choice(C4="C4", "C4", "") + choice(C5="C5", "C5", "") + choice(C6="C6", "C6", "") + 
        choice(C7="C7", "C7", "") + choice(C8="C8", "C8", "") + choice(C9="C9", "C9", "") 
        AS CN


FLATTEN "  " AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation


SORT file.folder ASC
GROUP BY SubFolderWithPath AS G_SubFolderWithPath


FLATTEN rows.SomeIndentation[0] AS P_SomeIndentation
FLATTEN rows.SubFolderName[0] AS P_SubFolderName
```

Screenshots(DQL01):


DQL10_create_Indentations_for_subfolder_within_grouped_folder_and_LIST

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10
_create_Indentations
_for_subfolder
_within_grouped_folder
_and_LIST
file.folder:
a string

this.file.folder:
a string
yes 1.To define field variables C0_Parent
2.To filter file.folder by C0_Parent

3.To define field variables:
3.1 To define three field variables, such as SubFolderName, SubFolderWithPathRelativeToParent, ParentFolderName
3.2 To define three field variables, such as SubFolderWithPath, pName, and sName
3.3 To define ten field variables, such as C0, C1,… ,C9

4.To define field variables:
4.1 To define one field variable CN
4.2 To define one field variable SomeIndentation for Indentations

5.To sort by file.folder in ascending order
6.To group by SubFolderWithPath
7.To define two field variables, such as P_SomeIndentation and P_SubFolderName
8.To render as a list with desired structure
The DQL10 is based on the DQL01 in the topic.

Notes

Summary

Q1: How to modify the following code in order to use the DQL10 in any page in any location?

Summary_Q1
Original Example: Q1 (To be modified)
```dataview
LIST WITHOUT ID
     P_SomeIndentation + 
     P_SubFolderName + 
     map(rows.file.link, (e) =>  "<br>" + P_SomeIndentation + "⦁ " + e)

FROM "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"
FLATTEN this.file.folder AS C0_Parent
WHERE startswith(file.folder, C0_Parent)
```

A1_11:

Another Example: A1_11

NOTE:

  1. Remove the FROM expression.
  2. The DQL10 performance is poor without the FROM expression.
  3. For best performance, use the mDVJS01 instead of the DQL10, where the FROM expression is removed.
```dataview
LIST WITHOUT ID
     P_SomeIndentation + 
     P_SubFolderName + 
     map(rows.file.link, (e) =>  "<br>" + P_SomeIndentation + "⦁ " + e)


FLATTEN this.file.folder AS C0_Parent
WHERE startswith(file.folder, C0_Parent)
```

Q2: How to customize different folder levels of Indentations?

Summary_Q2
Original Example: Q2 (To be modified)
```dataview

FLATTEN "&ensp;&ensp;" AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation
```

A2_21: Add Circled Sans-Serif Digits

Another Example: A2_21
```dataview

FLATTEN "&ensp;&ensp;" AS INDT

FLATTEN {
    "C0": "",
    "C1": "➁" + INDT,
    "C2": INDT + "➂" + INDT,
    "C3": INDT + INDT + "➃" + INDT,
    "C4": INDT + INDT + INDT + "➄" + INDT,
    "C5": INDT + INDT + INDT + INDT + "➅" + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + "➆" + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + "➇" + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + "➈" + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + "➉" + INDT
}[CN] AS SomeIndentation

```
Screenshots(A2_21):


A2_22: Add Vertical Lines

Another Example: A2_22
```dataview

FLATTEN "|&ensp;&ensp;" AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation

```
Screenshots(A2_22):


A2_23: Add Vertical Lines with HTML formatting

Another Example: A2_23
```dataview

FLATTEN "<span style='color:grey'>" + "|&ensp;&ensp;" + "</span>" AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation

```
Screenshots(A2_23):


Code DQL10_create_Indentations_for_subfolder_within_grouped_folder_and_LIST

Summary_code

NOTE:

  1. It supprts up to eight levels of subfolders (C0~C8) for the file.folder.
  2. The file.folder subfolders at or above nine levels (C9, C10~) are rendered as nine levels.
  3. The location for the DQL10 is “100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent”.

C0=Parent
C1=Childern of C0_Parent
C2=Childern of C1
C3=Childern of C2
C4=Childern of C3
C5=Childern of C4
C6=Childern of C5
C7=Childern of C6
C8=Childern of C7
C9=Childern of C8, C9, C10, C11, and so on

title: DQL10_create_Indentations_for_subfolder_within_grouped_folder_and_LIST =>1.To define field variables `C0_Parent` 2.To filter `file.folder` by `C0_Parent` 3.To define field variables: 3.1 To define three field variables, such as `SubFolderName`, `SubFolderWithPathRelativeToParent`, `ParentFolderName` 3.2 To define three field variables, such as `SubFolderWithPath`, `pName`, and `sName` 3.3 To define ten field variables, such as `C0`, `C1`,... ,`C9` 4.To define field variables: 4.1 To define one field variable `CN` 4.2 To define one field variable `SomeIndentation` for Indentations 5.To sort by `file.folder` in ascending order 6.To group by `SubFolderWithPath` 7.To define two field variables, such as `P_SomeIndentation` and `P_SubFolderName` 8.To render as a list with desired structure
collapse: close
icon: 
color: 
```dataview
LIST WITHOUT ID
     P_SomeIndentation + 
     P_SubFolderName + 
     map(rows.file.link, (e) =>  "<br>" + P_SomeIndentation + "⦁ " + e)

FROM "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"
FLATTEN this.file.folder AS C0_Parent
WHERE startswith(file.folder, C0_Parent)


FLATTEN regexreplace(file.folder, "^.*\/([^/]+)$", "$1") AS SubFolderName
FLATTEN regexreplace(file.folder, C0_Parent + "\/", "") AS SubFolderWithPathRelativeToParent
FLATTEN regexreplace(C0_Parent, "^.*\/([^/]+)$", "$1") AS ParentFolderName


FLATTEN SubFolderWithPathRelativeToParent AS SubFolderWithPath
FLATTEN ParentFolderName AS pName
FLATTEN SubFolderName AS sName


FLATTEN choice(sName = pName, "C0", "") AS C0
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+)$", "C1"), "") AS C1
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){1,1})$", "C2"), "") AS C2
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){2,2})$", "C3"), "") AS C3
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){3,3})$", "C4"), "") AS C4
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){4,4})$", "C5"), "") AS C5
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){5,5})$", "C6"), "") AS C6
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){6,6})$", "C7"), "") AS C7
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){7,7})$", "C8"), "") AS C8
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){8,})$", "C9"), "") AS C9


FLATTEN C0 + choice(C1="C1", "C1", "") + choice(C2="C2", "C2", "") + choice(C3="C3", "C3", "") +
        choice(C4="C4", "C4", "") + choice(C5="C5", "C5", "") + choice(C6="C6", "C6", "") + 
        choice(C7="C7", "C7", "") + choice(C8="C8", "C8", "") + choice(C9="C9", "C9", "") 
        AS CN


FLATTEN "&ensp;&ensp;" AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation


SORT file.folder ASC
GROUP BY SubFolderWithPath AS G_SubFolderWithPath


FLATTEN rows.SomeIndentation[0] AS P_SomeIndentation
FLATTEN rows.SubFolderName[0] AS P_SubFolderName
```

Screenshots(DQL10):


Conclusion

Summary
  • Althought the FROM expression in DQL doesn’t support FROM this.file.folder, the mDVJS01 does.
  • For best performance, use the mDVJS01 instead of the DQL10, which the FROM expression is removed.

Reference

Summary

Emojis

Z Notation Spot

Vertical Line

Dingbat Circled Sans-Serif Digit

Q83_FolderNote: Regular Expressions

Q88_header: DQL30

Q78_MediumCat: mDVJS01

How to reuse user-defined functions, a DVJS code, or a DQL query?

Summary

1 Like

Topic : 2/2

Summary
  • How to create an indented line for a subfolder within the grouped folder in list view?
    • DQL10
    • mDVJS01 + Q30_DQL10a_JS.js + Q30_ParentFolder_Config_a.md: It supports three different use cases.

mDVJS01_reuse_Q30_DQL10a_JS_and_maintain_One_customizable_variable

Summary

Main DVJS + a View + a Config

Example Code Name Relations What to maintain in the configuration file Purposes Remark
A m1:
mDVJS01
_reuse_Q30_DQL10a_JS
_and_maintain
_One_customizable_variable

v1:
Q30_DQL10a_JS.js

c1:
Q30_ParentFolder_Config_a.md
Q30_DQL10 = m1 + v1 + c1 fields: Q30_DQL10a_JS_path 1.To reuse the Q30_DQL10a_JS (“v1”)

2.To maintain only one customizable variable, defined in the configuration file “c1”
1.The scripts such as m1 and v1 never require any maintenance.
2.The configuration filename, used by many scripts, never requires any maintenance.
3.The field name Q30_DQL10a_JS_path, used by many scripts, never requires any maintenance.

4.All that needs to be maintained is the content of the configuration file.

Code m1: mDVJS01

NOTE:

  1. The path of the m1 is defined as any location as you like.
  2. The scripts such as m1 and v1 never require any maintenance.
Summary_code
title: mDVJS01_reuse_Q30_DQL10a_JS_and_maintain_One_customizable_variable => 0.Q30_DQL10 = Q30_DQL10a = m1 + v1 + c1 1.To reuse the Q30_DQL10a_JS ("v1") 2.To maintain only one customizable variable, defined in the configuration file "c1"
collapse: open
icon: 
color: 
```dataviewjs
// M11. define Q30_ParentFolder_Config_a: [[Q30_ParentFolder_Config_a]]
// #####################################################################
let Q30_ParentFolder_Config_a = dv.page("Q30_ParentFolder_Config_a");


// M13. define Q30_ParentFolder_Config_curPage: the current page
// #####################################################################
let Q30_ParentFolder_Config_current = dv.current();


// M31. run the Q30_DQL10b_JS.js with the argument, {Config_a: Q30_ParentFolder_Config_a, Config_current: Q30_ParentFolder_Config_current,}: 
// run "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data_CFG/02_Views/DQL10a_VIEW/Q30_DQL10a_JS.js";
// #####################################################################
await dv.view(Q30_ParentFolder_Config_a.Q30_DQL10a_JS_path, {
    Config_a: Q30_ParentFolder_Config_a,
    Config_current: Q30_ParentFolder_Config_current,
});

```

View v1: Q30_DQL10a_JS.js (Mainly use dv.query)

NOTE:

  1. The path of the v1 is defined in the c1.
  2. The file name Q30_DQL10a_JS, used by many scripts, never requires any maintenance.
  3. The scripts such as m1 and v1 never require any maintenance.
  4. The content of the v1 :
    4.1 The content of the v1 contains neither ```dataviewjs nor ```.
    4.2 The content of the v1 should be edited by Notepad++ or any text editor.
    4.3 The file extrension of the v1 is “.js”.
Summary_View
```javascript
// ##################################################################### 
// v1: Q30_DQL10a_JS.js (Mainly use dv.query)
// The view file consists of the PART01 and PART02.
// 
// PART01:
// The view, also known as the subroutine, is called by the mDVJS01.
// The steps starting with "V", such as "V11", are from the "View" file v1.
// # Purpose :
// 1.get the page [[Q30_ParentFolder_Config_a]] from the argument, defined in the main program
// 2.define one customizable variable in the Q30_DQL10a_JS
//   with the SourcePath_from_CFG
// 
// PART02:
// The value of the s_DQL_multiline_with_newlines in the step "V51"
// is from the original "Main" program Q30_DQL10a.
// # Purpose :
// 1.replace one customizable variable in the Q30_DQL10a with one local variable in the v1
// 
// One customizable variable in different expressions:
// FROM "${SourcePath_from_CFG}"
// FLATTEN "${SourcePath_from_CFG}" AS C0_Parent
// 
// 2.run the s_DQL_multiline_with_newlines via dv.query
// 
// Note: 
// 1.m1 = mDVJS01 = mDVJS01_reuse_Q30_DQL10a_JS_and_maintain_One_customizable_variable
// 2.v1 = Q30_DQL10a_JS.js
// 3.c1 = Q30_ParentFolder_Config_a.md
// 4.Q30_DQL10 = Q30_DQL10a = m1 + v1 + c1
// ##################################################################### 



// #####################################################################
// ###                                                               ###
// ### PART01: the beginning                                         ###
// ###                                                               ### 
// #####################################################################


// V10.JavaScript Object Destructuring Assignment
// RIGHT expression:
// input.Config_a: get the page [[Q30_ParentFolder_Config_a]]
// 
// LEFT expression:
// 1.get three fields from the page [[Q30_ParentFolder_Config_a]] 
//   via the argument, defined in the main program
//   original fields: SourcePath, medium_category_of, and today
// 2.assign them as three local variables in the Q78_DQL10a_JS.js
//   local variables:Use_Case_from_CFG, filename_of_unique_page_in_Parent_from_CFG, and C0_Parent_from_CFG
// 
// #####################################################################
let {
    Use_Case: Use_Case_from_CFG,
    filename_of_unique_page_in_Parent: filename_of_unique_page_in_Parent_from_CFG,
    C0_Parent: C0_Parent_from_CFG
} = input.Config_a;



// V11. define Q30_ParentFolder_Config_current: the current page
// #####################################################################
// USE_CASE_11_read_one_file: Use one mDVJS01 in any location to query 
//                            any path by reading one file, which exists 
//                            in a C0_Parent folder. 
// let Q30_ParentFolder_Config_current = dv.page("20230328_Q30_001_C0");
// 
// USE_CASE_12_read_one_YAML: Use one mDVJS01 in any location to query 
//                            any path by reading one YAML, which is the path 
//                            for a C0_Parent folder. 
// let Q30_ParentFolder_Config_current = dv.current();
// 
// USE_CASE_13_many_copies: Many mDVJS01 copies exist in different index files
//                          , which exists in different C0_Parent folders.
let Q30_ParentFolder_Config_current = input.Config_current;


// V21. define SourcePath_from_CFG:
// #####################################################################
// USE_CASE_11_read_one_file:
// inDQL:  `=[[Q30_index_C0]].file.folder`
// inDVJS: `$=dv.page("Q30_index_C0").file.folder`
// DVJS  : dv.span(dv.page("Q30_index_C0").file.folder);
//=>"100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"
// let SourcePath_from_CFG = dv.page(
//     Q30_ParentFolder_Config_a.filename_of_unique_page_in_Parent
// ).file.folder;
//
// USE_CASE_12_read_one_YAML:
// C0_Parent = "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent";
// let SourcePath_from_CFG = Q30_ParentFolder_Config_a.C0_Parent;
//
// USE_CASE_13_many_copies  :
// =>"100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"
// let SourcePath_from_CFG = Q30_ParentFolder_Config_current.file.folder;
let SourcePath_from_CFG = "";
switch (Use_Case_from_CFG) {
    case "USE_CASE_11_read_one_file":
        SourcePath_from_CFG = dv.page(
            filename_of_unique_page_in_Parent_from_CFG
        ).file.folder;
        break;
    case "USE_CASE_12_read_one_YAML":
        SourcePath_from_CFG = C0_Parent_from_CFG;
        break;
    case "USE_CASE_13_many_copies":
        SourcePath_from_CFG = Q30_ParentFolder_Config_current.file.folder;
        break;
    default:
    // do nothing
}


// #####################################################################
// ###                                                               ###
// ### PART02: the beginning                                         ###
// ###                                                               ### 
// #####################################################################


// #####################################################################
// V51. define s_DQL_multiline_with_newlines: a multiline string with newlines
// the Q30_DQL10a with one customizable variable
// 
// One customizable variable in different expressions:
// FROM "${SourcePath_from_CFG}"
// FLATTEN "${SourcePath_from_CFG}" AS C0_Parent
// #####################################################################
let s_DQL_multiline_with_newlines =`

LIST WITHOUT ID
     P_SomeIndentation + 
     P_SubFolderName + 
     map(rows.file.link, (e) =>  "<br>" + P_SomeIndentation + "⦁ " + e)

FROM "${SourcePath_from_CFG}"
FLATTEN "${SourcePath_from_CFG}" AS C0_Parent
WHERE startswith(file.folder, C0_Parent)


FLATTEN regexreplace(file.folder, "^.*\/([^/]+)$", "$1") AS SubFolderName
FLATTEN regexreplace(file.folder, C0_Parent + "\/", "") AS SubFolderWithPathRelativeToParent
FLATTEN regexreplace(C0_Parent, "^.*\/([^/]+)$", "$1") AS ParentFolderName



FLATTEN SubFolderWithPathRelativeToParent AS SubFolderWithPath
FLATTEN ParentFolderName AS pName
FLATTEN SubFolderName AS sName


FLATTEN choice(sName = pName, "C0", "") AS C0
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+)$", "C1"), "") AS C1
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){1,1})$", "C2"), "") AS C2
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){2,2})$", "C3"), "") AS C3
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){3,3})$", "C4"), "") AS C4
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){4,4})$", "C5"), "") AS C5
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){5,5})$", "C6"), "") AS C6
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){6,6})$", "C7"), "") AS C7
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){7,7})$", "C8"), "") AS C8
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){8,})$", "C9"), "") AS C9


FLATTEN C0 + choice(C1="C1", "C1", "") + choice(C2="C2", "C2", "") + choice(C3="C3", "C3", "") +
        choice(C4="C4", "C4", "") + choice(C5="C5", "C5", "") + choice(C6="C6", "C6", "") + 
        choice(C7="C7", "C7", "") + choice(C8="C8", "C8", "") + choice(C9="C9", "C9", "") 
        AS CN


FLATTEN "&ensp;&ensp;" AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation


SORT file.folder ASC
GROUP BY SubFolderWithPath AS G_SubFolderWithPath


FLATTEN rows.SomeIndentation[0] AS P_SomeIndentation
FLATTEN rows.SubFolderName[0] AS P_SubFolderName


`;



// V53. define h_result:
// run the s_DQL_multiline_with_newlines via dv.query and assign the result to h_result
// #####################################################################
let h_result = await dv.query(s_DQL_multiline_with_newlines);


// V55. output h_result:
// #####################################################################
if (h_result.successful) {
    
    // Display the original data according to h_result.value.type
    switch (h_result.value.type) {
        case "table":
            // TABLE:
            dv.table(h_result.value.headers, h_result.value.values);
            break;
        case "list":
            // LIST:
            dv.list(h_result.value.values);
            break;
        case "task":
            // TASK:
            dv.taskList(h_result.value.values);
            break;
        case "calendar":
            // CALENDAR: run a Q78_DQL10c
            dv.execute(Q78_DQL10c);
            break;
        default:
            // do nothing
    }
    
} else {
    dv.span(h_result.error);
}

```

Config c1: Q30_ParentFolder_Config_a.md (fields: Q30_DQL10a_JS_path)

NOTE:

  1. The path of the c1 is defined as any location as you like.
  2. The configuration filename, used by many scripts, never requires any maintenance.
  3. The field name Q30_DQL10a_JS_path, used by many scripts, never requires any maintenance.
  4. All that needs to be maintained is the content of the configuration file.
Summary_Config
````md
---
# c1: Q30_ParentFolder_Config_a.md
# Tip: The config filename, used by many scripts, never requires any maintenance.

# The config is used by the view of the mDVJS01 in the Q30_ParentFolder.
# Q30_ParentFolder/Q30_test_data_CFG/02_Views/DQL10a_VIEW/Q30_DQL10a_JS.js
# The Q30_DQL10a_JS.js is called by the 
# mDVJS01_reuse_Q30_DQL10a_JS_and_maintain_One_customizable_variable.



#####################################################################
# Use_Case :
# Define which use case to use.
# 1."USE_CASE_11_read_one_file"
# 2."USE_CASE_12_read_one_YAML"
# 3."USE_CASE_13_many_copies"
#####################################################################
Use_Case: "USE_CASE_13_many_copies"



# USE_CASE_11_read_one_file :
# Use one mDVJS01 in any location to query any path by reading one file,
# which exists in a C0_Parent folder. 
# The unique page which exists in the C0_Parent
filename_of_unique_page_in_Parent: "Q30_index_C0"


# USE_CASE_12_read_one_YAML :
# Use one mDVJS01 in any location to query any path by reading one YAML, 
# which is the path to a C0_Parent folder.
# The C0_Parent folder path
C0_Parent: "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"


# USE_CASE_13_many_copies :
# Many mDVJS01 copies exist in different index files, 
# which exists in different C0_Parent folders.
# The folder path is `this.file.folder` in DQL query.
# This USE_CASE requires no YAML.



#####################################################################
# The path where the Q30_DQL10a_JS.js is doesn't contain the file extension ".js"
# Tip: The field name, used by many scripts, never requires any maintenance. 
#####################################################################
Q30_DQL10a_JS_path : "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data_CFG/02_Views/DQL10a_VIEW/Q30_DQL10a_JS"


---

````

Screenshots(mDVJS01)

Summary_Screenshots
Part 1/2 :

Part 2/2 :


Notes(Config c1)

Summary

Q1: How to modify the Config c1 to use “USE_CASE_11_read_one_file”?

Summary_Q1
Original Example: Q1 (To be modified)
```dataviewjs
#####################################################################
# Use_Case :
# Define which use case to use.
# 1."USE_CASE_11_read_one_file"
# 2."USE_CASE_12_read_one_YAML"
# 3."USE_CASE_13_many_copies"
#####################################################################
Use_Case: "USE_CASE_13_many_copies"



# USE_CASE_11_read_one_file :
# Use one mDVJS01 in any location to query any path by reading one file,
# which exists in a C0_Parent folder. 
# The unique page which exists in the C0_Parent
filename_of_unique_page_in_Parent: "Q30_index_C0"


# USE_CASE_12_read_one_YAML :
# Use one mDVJS01 in any location to query any path by reading one YAML, 
# which is the path to a C0_Parent folder.
# The C0_Parent folder path
C0_Parent: "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"


# USE_CASE_13_many_copies :
# Many mDVJS01 copies exist in different index files, 
# which exists in different C0_Parent folders.
# The folder path is `this.file.folder` in DQL query.
# This USE_CASE requires no YAML.


```

A1_11: “USE_CASE_11_read_one_file”

Another Example: A1_11

NOTE:

  1. Modify the Use_Case with “USE_CASE_11_read_one_file”.
  2. Modify the filename_of_unique_page_in_Parent with “Q30_index_C0”. (For example)
```dataviewjs
#####################################################################
# Use_Case :
# Define which use case to use.
# 1."USE_CASE_11_read_one_file"
# 2."USE_CASE_12_read_one_YAML"
# 3."USE_CASE_13_many_copies"
#####################################################################
Use_Case: "USE_CASE_11_read_one_file"



# USE_CASE_11_read_one_file :
# Use one mDVJS01 in any location to query any path by reading one file,
# which exists in a C0_Parent folder. 
# The unique page which exists in the C0_Parent
filename_of_unique_page_in_Parent: "Q30_index_C0"


# USE_CASE_12_read_one_YAML :
# Use one mDVJS01 in any location to query any path by reading one YAML, 
# which is the path to a C0_Parent folder.
# The C0_Parent folder path
C0_Parent: "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"


# USE_CASE_13_many_copies :
# Many mDVJS01 copies exist in different index files, 
# which exists in different C0_Parent folders.
# The folder path is `this.file.folder` in DQL query.
# This USE_CASE requires no YAML.


```

Q2: How to modify the Config c1 to use “USE_CASE_12_read_one_YAML”?

Summary_Q2
Original Example: Q2 (To be modified)
```dataviewjs
#####################################################################
# Use_Case :
# Define which use case to use.
# 1."USE_CASE_11_read_one_file"
# 2."USE_CASE_12_read_one_YAML"
# 3."USE_CASE_13_many_copies"
#####################################################################
Use_Case: "USE_CASE_13_many_copies"



# USE_CASE_11_read_one_file :
# Use one mDVJS01 in any location to query any path by reading one file,
# which exists in a C0_Parent folder. 
# The unique page which exists in the C0_Parent
filename_of_unique_page_in_Parent: "Q30_index_C0"


# USE_CASE_12_read_one_YAML :
# Use one mDVJS01 in any location to query any path by reading one YAML, 
# which is the path to a C0_Parent folder.
# The C0_Parent folder path
C0_Parent: "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"


# USE_CASE_13_many_copies :
# Many mDVJS01 copies exist in different index files, 
# which exists in different C0_Parent folders.
# The folder path is `this.file.folder` in DQL query.
# This USE_CASE requires no YAML.

```

A2_21: “USE_CASE_12_read_one_YAML”

Another Example: A2_21

NOTE:

  1. Modify the Use_Case with “USE_CASE_12_read_one_YAML”.
  2. Modify the C0_Parent with “100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent”. (For example)
```dataviewjs
#####################################################################
# Use_Case :
# Define which use case to use.
# 1."USE_CASE_11_read_one_file"
# 2."USE_CASE_12_read_one_YAML"
# 3."USE_CASE_13_many_copies"
#####################################################################
Use_Case: "USE_CASE_12_read_one_YAML"



# USE_CASE_11_read_one_file :
# Use one mDVJS01 in any location to query any path by reading one file,
# which exists in a C0_Parent folder. 
# The unique page which exists in the C0_Parent
filename_of_unique_page_in_Parent: "Q30_index_C0"


# USE_CASE_12_read_one_YAML :
# Use one mDVJS01 in any location to query any path by reading one YAML, 
# which is the path to a C0_Parent folder.
# The C0_Parent folder path
C0_Parent: "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"


# USE_CASE_13_many_copies :
# Many mDVJS01 copies exist in different index files, 
# which exists in different C0_Parent folders.
# The folder path is `this.file.folder` in DQL query.
# This USE_CASE requires no YAML.

```

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.