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

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.

```