From 5d7c6d47bfee7444b1c5abd77696b5f4498b6e46 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Mon, 10 Jul 2023 23:21:04 +0800
Subject: [PATCH 1/6] :art: Add kernel API `/api/network/forwardProxy`
https://github.com/siyuan-note/siyuan/issues/8724
---
API.md | 48 +++++++++++++++++++++++++++++++++++++++++++
API_zh_CN.md | 48 +++++++++++++++++++++++++++++++++++++++++++
kernel/api/network.go | 19 +++++++++--------
3 files changed, 106 insertions(+), 9 deletions(-)
diff --git a/API.md b/API.md
index cf8a907f5..c3b5cc76f 100644
--- a/API.md
+++ b/API.md
@@ -52,6 +52,8 @@
* [Notification](#Notification)
* [Push message](#Push-message)
* [Push error message](#Push-error-message)
+* [Network](#Network)
+ * [Forward proxy](#Forward-proxy)
* [System](#System)
* [Get boot progress](#Get-boot-progress)
* [Get system version](#Get-system-version)
@@ -1207,6 +1209,52 @@ View API token in Settings - About, request header: `Authorization: T
```
* `id`: Message ID
+## Network
+
+### Forward proxy
+
+* `/api/network/forkProxy`
+* Parameters
+
+ ```json
+ {
+ "url": "https://b3log.org/siyuan/",
+ "method": "GET",
+ "timeout": 7000,
+ "contentType": "text/html",
+ "headers": [
+ {
+ "Cookie": ""
+ }
+ ],
+ "payload": {}
+ }
+ ```
+
+ * `url`: URL to forward
+ * `method`: HTTP method, default is `POST`
+ * `timeout`: timeout in milliseconds, default is `7000`
+ * `contentType`: Content-Type, default is `application/json`
+ * `headers`: HTTP headers
+ * `payload`: HTTP payload, object or string
+* Return value
+
+ ```json
+ {
+ "code": 0,
+ "msg": "",
+ "data": {
+ "body": "",
+ "contentType": "text/html",
+ "elapsed": 1976,
+ "headers": {
+ },
+ "status": 200,
+ "url": "https://b3log.org/siyuan"
+ }
+ }
+ ```
+
## System
### Get boot progress
diff --git a/API_zh_CN.md b/API_zh_CN.md
index b92555012..2278b0dd8 100644
--- a/API_zh_CN.md
+++ b/API_zh_CN.md
@@ -52,6 +52,8 @@
* [通知](#通知)
* [推送消息](#推送消息)
* [推送报错消息](#推送报错消息)
+* [网络](#网络)
+ * [正向代理](#正向代理)
* [系统](#系统)
* [获取启动进度](#获取启动进度)
* [获取系统版本](#获取系统版本)
@@ -1197,6 +1199,52 @@
```
* `id`:消息 ID
+## 网络
+
+### 正向代理
+
+* `/api/network/forkProxy`
+* 参数
+
+ ```json
+ {
+ "url": "https://b3log.org/siyuan/",
+ "method": "GET",
+ "timeout": 7000,
+ "contentType": "text/html",
+ "headers": [
+ {
+ "Cookie": ""
+ }
+ ],
+ "payload": {}
+ }
+ ```
+
+ * `url`:转发的 URL
+ * `method`:HTTP 方法,默认为 `GET`
+ * `timeout`:超时时间,单位为毫秒,默认为 `7000` 毫秒
+ * `contentType`:HTTP Content-Type,默认为 `application/json`
+ * `headers`:HTTP 请求标头
+ * `payload`:HTTP 请求体,对象或者是字符串
+* 返回值
+
+ ```json
+ {
+ "code": 0,
+ "msg": "",
+ "data": {
+ "body": "",
+ "contentType": "text/html",
+ "elapsed": 1976,
+ "headers": {
+ },
+ "status": 200,
+ "url": "https://b3log.org/siyuan"
+ }
+ }
+ ```
+
## 系统
### 获取启动进度
diff --git a/kernel/api/network.go b/kernel/api/network.go
index f4854ddc2..eadfd528d 100644
--- a/kernel/api/network.go
+++ b/kernel/api/network.go
@@ -46,10 +46,12 @@ func forwardProxy(c *gin.Context) {
return
}
- method := strings.ToUpper(arg["method"].(string))
- timeoutArg := arg["timeout"]
+ method := "POST"
+ if methodArg := arg["method"]; nil != methodArg {
+ method = strings.ToUpper(methodArg.(string))
+ }
timeout := 7 * 1000
- if nil != timeoutArg {
+ if timeoutArg := arg["timeout"]; nil != timeoutArg {
timeout = int(timeoutArg.(float64))
if 1 > timeout {
timeout = 7 * 1000
@@ -66,14 +68,13 @@ func forwardProxy(c *gin.Context) {
}
}
- contentType := arg["contentType"]
- if nil != contentType && "" != contentType {
- request.SetHeader("Content-Type", contentType.(string))
+ contentType := "application/json"
+ if contentTypeArg := arg["contentType"]; nil != contentTypeArg {
+ contentType = contentTypeArg.(string)
}
+ request.SetHeader("Content-Type", contentType)
- if "POST" == method {
- request.SetBody(arg["payload"])
- }
+ request.SetBody(arg["payload"])
started := time.Now()
resp, err := request.Send(method, destURL)
From 5e4f2fb1f82e69ab39b5e62f3dd89bf15efb3c19 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Mon, 10 Jul 2023 23:23:06 +0800
Subject: [PATCH 2/6] :bookmark: Release v2.9.5
---
app/changelogs/v2.9.5/v2.9.5.md | 1 +
app/changelogs/v2.9.5/v2.9.5_zh_CHT.md | 1 +
app/changelogs/v2.9.5/v2.9.5_zh_CN.md | 1 +
3 files changed, 3 insertions(+)
diff --git a/app/changelogs/v2.9.5/v2.9.5.md b/app/changelogs/v2.9.5/v2.9.5.md
index 16f50780d..2de5dc07c 100644
--- a/app/changelogs/v2.9.5/v2.9.5.md
+++ b/app/changelogs/v2.9.5/v2.9.5.md
@@ -25,6 +25,7 @@ Below are the detailed changes in this version.
* [Improve create workspace interaction](https://github.com/siyuan-note/siyuan/issues/8700)
* [Support for saving .sy files in the single-line format](https://github.com/siyuan-note/siyuan/issues/8712)
* [Adjacent inline element in the same para but different line](https://github.com/siyuan-note/siyuan/issues/8713)
+* [Add kernel API `/api/network/forwardProxy`](https://github.com/siyuan-note/siyuan/issues/8724)
### Bugfix
diff --git a/app/changelogs/v2.9.5/v2.9.5_zh_CHT.md b/app/changelogs/v2.9.5/v2.9.5_zh_CHT.md
index 312ed0f16..ad87b3495 100644
--- a/app/changelogs/v2.9.5/v2.9.5_zh_CHT.md
+++ b/app/changelogs/v2.9.5/v2.9.5_zh_CHT.md
@@ -25,6 +25,7 @@
* [改進桌面端創建工作空間交互](https://github.com/siyuan-note/siyuan/issues/8700)
* [支持以單行 JSON 格式保存 .sy 文件](https://github.com/siyuan-note/siyuan/issues/8712)
* [不再自動合併相鄰換行的行級元素](https://github.com/siyuan-note/siyuan/issues/8713)
+* [添加內核 API `/api/network/forwardProxy`](https://github.com/siyuan-note/siyuan/issues/8724)
### 修復缺陷
diff --git a/app/changelogs/v2.9.5/v2.9.5_zh_CN.md b/app/changelogs/v2.9.5/v2.9.5_zh_CN.md
index b92f7dcc9..d88b9c615 100644
--- a/app/changelogs/v2.9.5/v2.9.5_zh_CN.md
+++ b/app/changelogs/v2.9.5/v2.9.5_zh_CN.md
@@ -25,6 +25,7 @@
* [改进桌面端创建工作空间交互](https://github.com/siyuan-note/siyuan/issues/8700)
* [支持以单行 JSON 格式保存 .sy 文件](https://github.com/siyuan-note/siyuan/issues/8712)
* [不再自动合并相邻换行的行级元素](https://github.com/siyuan-note/siyuan/issues/8713)
+* [添加内核 API `/api/network/forwardProxy`](https://github.com/siyuan-note/siyuan/issues/8724)
### 修复缺陷
From 0c6c80ffbdb1936b01f6ebfea79a3d19c9f32f12 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Mon, 10 Jul 2023 23:23:41 +0800
Subject: [PATCH 3/6] :bookmark: Release v2.9.5
---
app/changelogs/v2.9.5/v2.9.5.md | 2 +-
app/changelogs/v2.9.5/v2.9.5_zh_CHT.md | 2 +-
app/changelogs/v2.9.5/v2.9.5_zh_CN.md | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/app/changelogs/v2.9.5/v2.9.5.md b/app/changelogs/v2.9.5/v2.9.5.md
index 2de5dc07c..8e90277d8 100644
--- a/app/changelogs/v2.9.5/v2.9.5.md
+++ b/app/changelogs/v2.9.5/v2.9.5.md
@@ -25,7 +25,6 @@ Below are the detailed changes in this version.
* [Improve create workspace interaction](https://github.com/siyuan-note/siyuan/issues/8700)
* [Support for saving .sy files in the single-line format](https://github.com/siyuan-note/siyuan/issues/8712)
* [Adjacent inline element in the same para but different line](https://github.com/siyuan-note/siyuan/issues/8713)
-* [Add kernel API `/api/network/forwardProxy`](https://github.com/siyuan-note/siyuan/issues/8724)
### Bugfix
@@ -48,3 +47,4 @@ Below are the detailed changes in this version.
* [Add text type column to Attribute View](https://github.com/siyuan-note/siyuan/issues/8693)
* [Add select type column to Attribute View](https://github.com/siyuan-note/siyuan/issues/8694)
* [Block data sync to Attribute View](https://github.com/siyuan-note/siyuan/issues/8696)
+* [Add kernel API `/api/network/forwardProxy`](https://github.com/siyuan-note/siyuan/issues/8724)
diff --git a/app/changelogs/v2.9.5/v2.9.5_zh_CHT.md b/app/changelogs/v2.9.5/v2.9.5_zh_CHT.md
index ad87b3495..f5cfcd519 100644
--- a/app/changelogs/v2.9.5/v2.9.5_zh_CHT.md
+++ b/app/changelogs/v2.9.5/v2.9.5_zh_CHT.md
@@ -25,7 +25,6 @@
* [改進桌面端創建工作空間交互](https://github.com/siyuan-note/siyuan/issues/8700)
* [支持以單行 JSON 格式保存 .sy 文件](https://github.com/siyuan-note/siyuan/issues/8712)
* [不再自動合併相鄰換行的行級元素](https://github.com/siyuan-note/siyuan/issues/8713)
-* [添加內核 API `/api/network/forwardProxy`](https://github.com/siyuan-note/siyuan/issues/8724)
### 修復缺陷
@@ -48,3 +47,4 @@
* [屬性視圖添加文本類型列](https://github.com/siyuan-note/siyuan/issues/8693)
* [屬性視圖添加選擇類型列](https://github.com/siyuan-note/siyuan/issues/8694)
* [塊數據同步至屬性視圖](https://github.com/siyuan-note/siyuan/issues/8696)
+* [添加內核 API `/api/network/forwardProxy`](https://github.com/siyuan-note/siyuan/issues/8724)
diff --git a/app/changelogs/v2.9.5/v2.9.5_zh_CN.md b/app/changelogs/v2.9.5/v2.9.5_zh_CN.md
index d88b9c615..37e864f36 100644
--- a/app/changelogs/v2.9.5/v2.9.5_zh_CN.md
+++ b/app/changelogs/v2.9.5/v2.9.5_zh_CN.md
@@ -25,7 +25,6 @@
* [改进桌面端创建工作空间交互](https://github.com/siyuan-note/siyuan/issues/8700)
* [支持以单行 JSON 格式保存 .sy 文件](https://github.com/siyuan-note/siyuan/issues/8712)
* [不再自动合并相邻换行的行级元素](https://github.com/siyuan-note/siyuan/issues/8713)
-* [添加内核 API `/api/network/forwardProxy`](https://github.com/siyuan-note/siyuan/issues/8724)
### 修复缺陷
@@ -48,3 +47,4 @@
* [属性视图添加文本类型列](https://github.com/siyuan-note/siyuan/issues/8693)
* [属性视图添加选择类型列](https://github.com/siyuan-note/siyuan/issues/8694)
* [块数据同步至属性视图](https://github.com/siyuan-note/siyuan/issues/8696)
+* [添加内核 API `/api/network/forwardProxy`](https://github.com/siyuan-note/siyuan/issues/8724)
From 9578e55446b50b9234744b5a14eb34ed372a9f06 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Mon, 10 Jul 2023 23:35:24 +0800
Subject: [PATCH 4/6] :art: Add multi-select type column to Attribute View
https://github.com/siyuan-note/siyuan/issues/8695
---
kernel/av/av.go | 115 --------------------------------------------
kernel/av/cell.go | 20 ++------
kernel/av/filter.go | 78 ++++++++++++++++++++++++++++++
kernel/av/sort.go | 72 +++++++++++++++++++++++++++
4 files changed, 154 insertions(+), 131 deletions(-)
create mode 100644 kernel/av/filter.go
create mode 100644 kernel/av/sort.go
diff --git a/kernel/av/av.go b/kernel/av/av.go
index 5c370aeef..fbf581e07 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -22,7 +22,6 @@ import (
"database/sql"
"os"
"path/filepath"
- "sort"
"strings"
"github.com/88250/gulu"
@@ -190,117 +189,3 @@ func RebuildAttributeViewTable(tx *sql.Tx, av *AttributeView) (err error) {
}
return
}
-
-type AttributeViewSort struct {
- Column string `json:"column"` // 列 ID
- Order SortOrder `json:"order"` // 排序顺序
-}
-
-type SortOrder string
-
-const (
- SortOrderAsc SortOrder = "ASC"
- SortOrderDesc SortOrder = "DESC"
-)
-
-func (av *AttributeView) SortRows() {
- if 1 > len(av.Sorts) {
- return
- }
-
- type ColIndexSort struct {
- Index int
- Order SortOrder
- }
-
- var colIndexSorts []*ColIndexSort
- for _, s := range av.Sorts {
- for i, c := range av.Columns {
- if c.ID == s.Column {
- colIndexSorts = append(colIndexSorts, &ColIndexSort{Index: i, Order: s.Order})
- break
- }
- }
- }
-
- sort.Slice(av.Rows, func(i, j int) bool {
- for _, colIndexSort := range colIndexSorts {
- c := av.Columns[colIndexSort.Index]
- if c.Type == ColumnTypeBlock {
- continue
- }
-
- result := av.Rows[i].Cells[colIndexSort.Index].Value.Compare(av.Rows[j].Cells[colIndexSort.Index].Value)
- if 0 == result {
- continue
- }
-
- if colIndexSort.Order == SortOrderAsc {
- return 0 > result
- }
- return 0 < result
- }
- return false
- })
-}
-
-type AttributeViewFilter struct {
- Column string `json:"column"`
- Operator FilterOperator `json:"operator"`
- Value *Value `json:"value"`
-}
-
-type FilterOperator string
-
-const (
- FilterOperatorIsEqual FilterOperator = "="
- FilterOperatorIsNotEqual FilterOperator = "!="
- FilterOperatorIsGreater FilterOperator = ">"
- FilterOperatorIsGreaterOrEqual FilterOperator = ">="
- FilterOperatorIsLess FilterOperator = "<"
- FilterOperatorIsLessOrEqual FilterOperator = "<="
- FilterOperatorContains FilterOperator = "Contains"
- FilterOperatorDoesNotContain FilterOperator = "Does not contains"
- FilterOperatorIsEmpty FilterOperator = "Is empty"
- FilterOperatorIsNotEmpty FilterOperator = "Is not empty"
- FilterOperatorStartsWith FilterOperator = "Starts with"
- FilterOperatorEndsWith FilterOperator = "Ends with"
- FilterOperatorIsBetween FilterOperator = "Is between"
- FilterOperatorIsRelativeToToday FilterOperator = "Is relative to today"
-)
-
-func (av *AttributeView) FilterRows() {
- if 1 > len(av.Filters) {
- return
- }
-
- var colIndexes []int
- for _, f := range av.Filters {
- for i, c := range av.Columns {
- if c.ID == f.Column {
- colIndexes = append(colIndexes, i)
- break
- }
- }
- }
-
- rows := []*Row{}
- for _, row := range av.Rows {
- pass := true
- for j, index := range colIndexes {
- c := av.Columns[index]
- if c.Type == ColumnTypeBlock {
- continue
- }
-
- if !row.Cells[index].Value.CompareOperator(av.Filters[j].Value, av.Filters[j].Operator) {
- pass = false
- break
- }
- }
- if pass {
- rows = append(rows, row)
- }
- }
- av.Rows = rows
-}
diff --git a/kernel/av/cell.go b/kernel/av/cell.go
index 412cb598b..597f74b03 100644
--- a/kernel/av/cell.go
+++ b/kernel/av/cell.go
@@ -35,7 +35,6 @@ type Value struct {
Text *ValueText `json:"text,omitempty"`
Number *ValueNumber `json:"number,omitempty"`
Date *ValueDate `json:"date,omitempty"`
- Select *ValueSelect `json:"select,omitempty"`
MSelect []*ValueSelect `json:"mSelect,omitempty"`
}
@@ -78,9 +77,7 @@ func (value *Value) Compare(other *Value) int {
return 0
}
}
- if nil != value.Select && nil != other.Select {
- return strings.Compare(value.Select.Content, other.Select.Content)
- }
+
if nil != value.MSelect && nil != other.MSelect {
var v1 string
for _, v := range value.MSelect {
@@ -172,21 +169,12 @@ func (value *Value) CompareOperator(other *Value, operator FilterOperator) bool
}
}
- if nil != value.Select && nil != other.Select {
+ if nil != value.MSelect && nil != other.MSelect && 0 < len(value.MSelect) && 0 < len(other.MSelect) {
switch operator {
case FilterOperatorIsEqual:
- return value.Select.Content == other.Select.Content
+ return value.MSelect[0].Content == other.MSelect[0].Content
case FilterOperatorIsNotEqual:
- return value.Select.Content != other.Select.Content
- case FilterOperatorIsEmpty:
- return "" == strings.TrimSpace(value.Select.Content)
- case FilterOperatorIsNotEmpty:
- return "" != strings.TrimSpace(value.Select.Content)
- }
- }
-
- if nil != value.MSelect && nil != other.MSelect {
- switch operator {
+ return value.MSelect[0].Content != other.MSelect[0].Content
case FilterOperatorContains:
for _, v := range value.MSelect {
if v.Content == other.MSelect[0].Content {
diff --git a/kernel/av/filter.go b/kernel/av/filter.go
new file mode 100644
index 000000000..89525bc17
--- /dev/null
+++ b/kernel/av/filter.go
@@ -0,0 +1,78 @@
+// SiYuan - Refactor your thinking
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package av
+
+type AttributeViewFilter struct {
+ Column string `json:"column"`
+ Operator FilterOperator `json:"operator"`
+ Value *Value `json:"value"`
+}
+
+type FilterOperator string
+
+const (
+ FilterOperatorIsEqual FilterOperator = "="
+ FilterOperatorIsNotEqual FilterOperator = "!="
+ FilterOperatorIsGreater FilterOperator = ">"
+ FilterOperatorIsGreaterOrEqual FilterOperator = ">="
+ FilterOperatorIsLess FilterOperator = "<"
+ FilterOperatorIsLessOrEqual FilterOperator = "<="
+ FilterOperatorContains FilterOperator = "Contains"
+ FilterOperatorDoesNotContain FilterOperator = "Does not contains"
+ FilterOperatorIsEmpty FilterOperator = "Is empty"
+ FilterOperatorIsNotEmpty FilterOperator = "Is not empty"
+ FilterOperatorStartsWith FilterOperator = "Starts with"
+ FilterOperatorEndsWith FilterOperator = "Ends with"
+ FilterOperatorIsBetween FilterOperator = "Is between"
+ FilterOperatorIsRelativeToToday FilterOperator = "Is relative to today"
+)
+
+func (av *AttributeView) FilterRows() {
+ if 1 > len(av.Filters) {
+ return
+ }
+
+ var colIndexes []int
+ for _, f := range av.Filters {
+ for i, c := range av.Columns {
+ if c.ID == f.Column {
+ colIndexes = append(colIndexes, i)
+ break
+ }
+ }
+ }
+
+ rows := []*Row{}
+ for _, row := range av.Rows {
+ pass := true
+ for j, index := range colIndexes {
+ c := av.Columns[index]
+ if c.Type == ColumnTypeBlock {
+ continue
+ }
+
+ if !row.Cells[index].Value.CompareOperator(av.Filters[j].Value, av.Filters[j].Operator) {
+ pass = false
+ break
+ }
+ }
+ if pass {
+ rows = append(rows, row)
+ }
+ }
+ av.Rows = rows
+}
diff --git a/kernel/av/sort.go b/kernel/av/sort.go
new file mode 100644
index 000000000..fe0061a89
--- /dev/null
+++ b/kernel/av/sort.go
@@ -0,0 +1,72 @@
+// SiYuan - Refactor your thinking
+// Copyright (c) 2020-present, b3log.org
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package av
+
+import "sort"
+
+type AttributeViewSort struct {
+ Column string `json:"column"` // 列 ID
+ Order SortOrder `json:"order"` // 排序顺序
+}
+
+type SortOrder string
+
+const (
+ SortOrderAsc SortOrder = "ASC"
+ SortOrderDesc SortOrder = "DESC"
+)
+
+func (av *AttributeView) SortRows() {
+ if 1 > len(av.Sorts) {
+ return
+ }
+
+ type ColIndexSort struct {
+ Index int
+ Order SortOrder
+ }
+
+ var colIndexSorts []*ColIndexSort
+ for _, s := range av.Sorts {
+ for i, c := range av.Columns {
+ if c.ID == s.Column {
+ colIndexSorts = append(colIndexSorts, &ColIndexSort{Index: i, Order: s.Order})
+ break
+ }
+ }
+ }
+
+ sort.Slice(av.Rows, func(i, j int) bool {
+ for _, colIndexSort := range colIndexSorts {
+ c := av.Columns[colIndexSort.Index]
+ if c.Type == ColumnTypeBlock {
+ continue
+ }
+
+ result := av.Rows[i].Cells[colIndexSort.Index].Value.Compare(av.Rows[j].Cells[colIndexSort.Index].Value)
+ if 0 == result {
+ continue
+ }
+
+ if colIndexSort.Order == SortOrderAsc {
+ return 0 > result
+ }
+ return 0 < result
+ }
+ return false
+ })
+}
From ec566692c84a570e196b0915a93c1cea7b9e6e56 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Mon, 10 Jul 2023 23:42:06 +0800
Subject: [PATCH 5/6] :art: Add multi-select type column to Attribute View
https://github.com/siyuan-note/siyuan/issues/8695
---
kernel/av/column.go | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/kernel/av/column.go b/kernel/av/column.go
index f02a52f60..46bf529dd 100644
--- a/kernel/av/column.go
+++ b/kernel/av/column.go
@@ -186,7 +186,7 @@ func (av *AttributeView) calcColSelect(col *Column, colIndex int) {
case CalcOperatorCountValues:
countValues := 0
for _, row := range av.Rows {
- if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Select && "" != row.Cells[colIndex].Value.Select.Content {
+ if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
countValues++
}
}
@@ -195,8 +195,8 @@ func (av *AttributeView) calcColSelect(col *Column, colIndex int) {
countUniqueValues := 0
uniqueValues := map[string]bool{}
for _, row := range av.Rows {
- if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Select && "" != row.Cells[colIndex].Value.Select.Content {
- uniqueValues[row.Cells[colIndex].Value.Select.Content] = true
+ if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
+ uniqueValues[row.Cells[colIndex].Value.MSelect[0].Content] = true
countUniqueValues++
}
}
@@ -204,7 +204,7 @@ func (av *AttributeView) calcColSelect(col *Column, colIndex int) {
case CalcOperatorCountEmpty:
countEmpty := 0
for _, row := range av.Rows {
- if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Select || "" == row.Cells[colIndex].Value.Select.Content {
+ if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.MSelect || 1 > len(row.Cells[colIndex].Value.MSelect) || nil == row.Cells[colIndex].Value.MSelect[0] || "" == row.Cells[colIndex].Value.MSelect[0].Content {
countEmpty++
}
}
@@ -212,7 +212,7 @@ func (av *AttributeView) calcColSelect(col *Column, colIndex int) {
case CalcOperatorCountNotEmpty:
countNotEmpty := 0
for _, row := range av.Rows {
- if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Select && "" != row.Cells[colIndex].Value.Select.Content {
+ if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
countNotEmpty++
}
}
@@ -220,7 +220,7 @@ func (av *AttributeView) calcColSelect(col *Column, colIndex int) {
case CalcOperatorPercentEmpty:
countEmpty := 0
for _, row := range av.Rows {
- if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.Select || "" == row.Cells[colIndex].Value.Select.Content {
+ if nil == row.Cells[colIndex] || nil == row.Cells[colIndex].Value || nil == row.Cells[colIndex].Value.MSelect || 1 > len(row.Cells[colIndex].Value.MSelect) || nil == row.Cells[colIndex].Value.MSelect[0] || "" == row.Cells[colIndex].Value.MSelect[0].Content {
countEmpty++
}
}
@@ -228,7 +228,7 @@ func (av *AttributeView) calcColSelect(col *Column, colIndex int) {
case CalcOperatorPercentNotEmpty:
countNotEmpty := 0
for _, row := range av.Rows {
- if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.Select && "" != row.Cells[colIndex].Value.Select.Content {
+ if nil != row.Cells[colIndex] && nil != row.Cells[colIndex].Value && nil != row.Cells[colIndex].Value.MSelect && 0 < len(row.Cells[colIndex].Value.MSelect) && nil != row.Cells[colIndex].Value.MSelect[0] && "" != row.Cells[colIndex].Value.MSelect[0].Content {
countNotEmpty++
}
}
From 36d0c558e31d4347f567b5326a2d9389f7156397 Mon Sep 17 00:00:00 2001
From: Daniel <845765@qq.com>
Date: Mon, 10 Jul 2023 23:44:00 +0800
Subject: [PATCH 6/6] :art: Add multi-select type column to Attribute View
https://github.com/siyuan-note/siyuan/issues/8695
---
kernel/model/attribute_view.go | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 01b1e18db..eb1569707 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -364,10 +364,10 @@ func updateAttributeViewColumnOption(operation *Operation) (err error) {
continue
}
- if nil != cell.Value.Select {
- if oldName == cell.Value.Select.Content {
- cell.Value.Select.Content = newName
- cell.Value.Select.Color = newColor
+ if nil != cell.Value.MSelect && 0 < len(cell.Value.MSelect) && nil != cell.Value.MSelect[0] {
+ if oldName == cell.Value.MSelect[0].Content {
+ cell.Value.MSelect[0].Content = newName
+ cell.Value.MSelect[0].Color = newColor
break
}
} else if nil != cell.Value.MSelect {
@@ -433,8 +433,8 @@ func removeAttributeViewColumnOption(operation *Operation) (err error) {
}
if nil != cell.Value {
- if nil != cell.Value.Select {
- if optName == cell.Value.Select.Content {
+ if nil != cell.Value.MSelect && 0 < len(cell.Value.MSelect) && nil != cell.Value.MSelect[0] {
+ if optName == cell.Value.MSelect[0].Content {
cell.Value = nil
break
}